use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldManager method createCustomWorld.
/**
* Generate a {@link BuildWorld} with a custom generator.
*
* @param player The player who is creating the world
* @param worldName The name of the world
* @param privateWorld Is world going to be a private world?
* @return {@code true} if the world was successfully created, {@code false otherwise}
* @author Ein_Jojo
*/
public boolean createCustomWorld(Player player, String worldName, boolean privateWorld) {
if (worldExists(player, worldName)) {
return false;
}
new PlayerChatInput(plugin, player, "enter_generator_name", input -> {
List<String> genArray;
if (input.contains(":")) {
genArray = Arrays.asList(input.split(":"));
} else {
genArray = Arrays.asList(input, input);
}
ChunkGenerator chunkGenerator = getChunkGenerator(genArray.get(0), genArray.get(1), worldName);
if (chunkGenerator == null) {
player.sendMessage(plugin.getString("worlds_import_unknown_generator"));
XSound.ENTITY_ITEM_BREAK.play(player);
return;
} else {
plugin.getLogger().info("Using custom world generator: " + input);
}
BuildWorld buildWorld = new BuildWorld(plugin, worldName, player.getName(), player.getUniqueId(), WorldType.CUSTOM, System.currentTimeMillis(), privateWorld, input);
buildWorlds.add(buildWorld);
player.sendMessage(plugin.getString("worlds_world_creation_started").replace("%world%", buildWorld.getName()).replace("%type%", buildWorld.getTypeName()));
generateBukkitWorld(worldName, buildWorld.getType(), chunkGenerator);
player.sendMessage(plugin.getString("worlds_creation_finished"));
});
return true;
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldManager method createWorld.
/**
* Generate a {@link BuildWorld} with a predefined generator.
*
* @param player The player who is creating the world
* @param worldName The name of the world
* @param worldType The world type
* @param privateWorld Is world going to be a private world?
* @return {@code true} if the world was successfully created, {@code false otherwise}
*/
public boolean createWorld(Player player, String worldName, WorldType worldType, boolean privateWorld) {
if (worldExists(player, worldName)) {
return false;
}
BuildWorld buildWorld = new BuildWorld(plugin, worldName, player.getName(), player.getUniqueId(), worldType, System.currentTimeMillis(), privateWorld);
buildWorlds.add(buildWorld);
player.sendMessage(plugin.getString("worlds_world_creation_started").replace("%world%", worldName).replace("%type%", buildWorld.getTypeName()));
finishPreparationsAndGenerate(buildWorld);
player.sendMessage(plugin.getString("worlds_creation_finished"));
return true;
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldManager method teleport.
/**
* Teleport a player to a {@link BuildWorld}.
*
* @param player The player to be teleported
* @param buildWorld The build world object
*/
public void teleport(Player player, BuildWorld buildWorld) {
boolean hadToLoad = false;
if (configValues.isUnloadWorlds() && !buildWorld.isLoaded()) {
buildWorld.load(player);
hadToLoad = true;
}
World bukkitWorld = Bukkit.getServer().getWorld(buildWorld.getName());
if (bukkitWorld == null) {
player.sendMessage(plugin.getString("worlds_tp_unknown_world"));
return;
}
Location location = bukkitWorld.getSpawnLocation().add(0.5, 0, 0.5);
if (buildWorld.getCustomSpawn() == null) {
switch(buildWorld.getType()) {
case NETHER:
case END:
Location blockLocation = null;
for (int y = 0; y < bukkitWorld.getMaxHeight(); y++) {
Block block = bukkitWorld.getBlockAt(location.getBlockX(), y, location.getBlockZ());
if (isSafeLocation(block.getLocation())) {
blockLocation = block.getLocation();
break;
}
}
if (blockLocation != null) {
location = new Location(bukkitWorld, blockLocation.getBlockX() + 0.5, blockLocation.getBlockY() + 1, blockLocation.getBlockZ() + 0.5);
}
break;
default:
break;
}
} else {
String[] spawnString = buildWorld.getCustomSpawn().split(";");
location = new Location(bukkitWorld, Double.parseDouble(spawnString[0]), Double.parseDouble(spawnString[1]), Double.parseDouble(spawnString[2]), Float.parseFloat(spawnString[3]), Float.parseFloat(spawnString[4]));
}
Location finalLocation = location;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
player.teleport(finalLocation);
Titles.clearTitle(player);
XSound.ENTITY_ENDERMAN_TELEPORT.play(player);
}, hadToLoad ? 20L : 0L);
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldManager method importWorlds.
/**
* Import all {@link BuildWorld} from a given list of world names.
*
* @param player The player who is creating the world
* @param worldList The list of world to be imported
*/
public void importWorlds(Player player, String[] worldList) {
int worlds = worldList.length;
int delay = configValues.getImportDelay();
player.sendMessage(plugin.getString("worlds_importall_started").replace("%amount%", String.valueOf(worlds)));
player.sendMessage(plugin.getString("worlds_importall_delay").replace("%delay%", String.valueOf(delay)));
AtomicInteger worldsImported = new AtomicInteger(0);
new BukkitRunnable() {
@Override
public void run() {
int i = worldsImported.getAndIncrement();
String worldName = worldList[i];
for (String charString : worldName.split("")) {
if (charString.matches("[^A-Za-z0-9/_-]")) {
player.sendMessage(plugin.getString("worlds_importall_invalid_character").replace("%world%", worldName).replace("%char%", charString));
return;
}
}
long creation = FileUtils.getDirectoryCreation(new File(Bukkit.getWorldContainer(), worldName));
buildWorlds.add(new BuildWorld(plugin, worldName, "-", null, WorldType.IMPORTED, creation, false));
generateBukkitWorld(worldName, WorldType.VOID);
player.sendMessage(plugin.getString("worlds_importall_world_imported").replace("%world%", worldName));
if (!(worldsImported.get() < worlds)) {
this.cancel();
player.sendMessage(plugin.getString("worlds_importall_finished"));
}
}
}.runTaskTimer(plugin, 0, 20L * delay);
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class PhysicsCommand method togglePhysics.
private void togglePhysics(Player player, World bukkitWorld) {
if (bukkitWorld == null) {
player.sendMessage(plugin.getString("physics_unknown_world"));
return;
}
BuildWorld buildWorld = worldManager.getBuildWorld(bukkitWorld.getName());
if (buildWorld == null) {
player.sendMessage(plugin.getString("physics_world_not_imported"));
return;
}
if (!buildWorld.isPhysics()) {
buildWorld.setPhysics(true);
player.sendMessage(plugin.getString("physics_activated").replace("%world%", buildWorld.getName()));
} else {
buildWorld.setPhysics(false);
player.sendMessage(plugin.getString("physics_deactivated").replace("%world%", buildWorld.getName()));
}
}
Aggregations