Skip to content

Instantly share code, notes, and snippets.

@NightSling
Created December 28, 2020 02:47
Show Gist options
  • Save NightSling/12be8ff491ba510bbbeb167a02554ef1 to your computer and use it in GitHub Desktop.
Save NightSling/12be8ff491ba510bbbeb167a02554ef1 to your computer and use it in GitHub Desktop.
package net.crackpixel.daysling.generator;
import com.grinderwolf.swm.api.SlimePlugin;
import com.grinderwolf.swm.api.exceptions.*;
import com.grinderwolf.swm.api.loaders.SlimeLoader;
import com.grinderwolf.swm.api.world.SlimeWorld;
import com.grinderwolf.swm.api.world.properties.SlimeProperties;
import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.io.IOException;
public class Generator implements Listener {
private SlimePlugin generator = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
private SlimeLoader loader = generator.getLoader("file");
private SlimePropertyMap propertyMap = new SlimePropertyMap();
private SlimeWorld world;
public SlimeWorld getLoadedWorld(SlimeLoader loader, String worldname, boolean bool, SlimePropertyMap properties) throws NewerFormatException, CorruptedWorldException, WorldInUseException, UnknownWorldException, IOException {
this.world = this.generator.loadWorld(loader, worldname, bool, properties);
return this.world;
}
public boolean isWorldAvaiable(){
if(world.isLocked() || world.isReadOnly()) return false;
return true;
}
public SlimeWorld world() {
return this.world;
}
public SlimeLoader getLoader() {
return loader;
}
public SlimePlugin getGenerator(){
return this.generator;
}
public SlimeWorld worldClone(String worldname, boolean bool) throws IOException, WorldAlreadyExistsException {
return world.clone(worldname, getLoader(), bool);
}
public void teleportPlayer(World world2, double x, double y, double z, Player player){
Location location = new Location(world2, x, y, z);
player.teleport(location);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) throws UnknownWorldException, WorldInUseException, IOException, CorruptedWorldException, NewerFormatException, WorldAlreadyExistsException {
Player player = e.getPlayer();
if(!player.hasPlayedBefore()){
if(isWorldAvaiable()){
world = getLoadedWorld(loader, "housingplot", false, propertyMap);
SlimeWorld clonedWorld = worldClone(String.format("%s_plot", player.getUniqueId().toString()), true);
generator.generateWorld(clonedWorld);
double x = (double) clonedWorld.getPropertyMap().getInt(SlimeProperties.SPAWN_X);
double y = (double) clonedWorld.getPropertyMap().getInt(SlimeProperties.SPAWN_X);
double z = (double) clonedWorld.getPropertyMap().getInt(SlimeProperties.SPAWN_X);
World teleportingworld = (World) world;
teleportPlayer(teleportingworld, x, y, z, player);
}
}
SlimeWorld clonedWorld = worldClone(String.format("%s_plot", player.getUniqueId().toString()), true);
generator.generateWorld(clonedWorld);
double x = (double) clonedWorld.getPropertyMap().getInt(SlimeProperties.SPAWN_X);
double y = (double) clonedWorld.getPropertyMap().getInt(SlimeProperties.SPAWN_X);
double z = (double) clonedWorld.getPropertyMap().getInt(SlimeProperties.SPAWN_X);
World teleportingworld = (World) world;
teleportPlayer(teleportingworld, x, y, z, player);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment