use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class SettingsManager method injectPlaceholders.
private String injectPlaceholders(String originalString, Player player) {
if (!originalString.matches(".*%*%.*")) {
return originalString;
}
String worldName = player.getWorld().getName();
BuildWorld buildWorld = worldManager.getBuildWorld(worldName);
return originalString.replace("%world%", worldName).replace("%status%", parseWorldInformation(buildWorld, "%status%")).replace("%permission%", parseWorldInformation(buildWorld, "%permission%")).replace("%project%", parseWorldInformation(buildWorld, "%project%")).replace("%creator%", parseWorldInformation(buildWorld, "%creator%")).replace("%creation%", parseWorldInformation(buildWorld, "%creation%"));
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class SpawnManager method load.
public void load() {
FileConfiguration configuration = spawnConfig.getFile();
String string = configuration.getString("spawn");
if (string == null || string.trim().equals("")) {
return;
}
String[] parts = string.split(":");
if (parts.length != 6) {
return;
}
String worldName = parts[0];
double x = Double.parseDouble(parts[1]);
double y = Double.parseDouble(parts[2]);
double z = Double.parseDouble(parts[3]);
float yaw = Float.parseFloat(parts[4]);
float pitch = Float.parseFloat(parts[5]);
BuildWorld buildWorld = worldManager.getBuildWorld(worldName);
if (buildWorld == null) {
buildWorld = worldManager.loadWorld(worldName);
}
buildWorld.load();
this.spawnName = worldName;
this.spawn = new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldManager method generateBukkitWorld.
/**
* Generate the {@link World} linked to a {@link BuildWorld}.
*
* @param worldName The name of the world
* @param worldType The world type
* @param chunkGenerators Custom chunk generator to be used, if any
* @return The world object
*/
public World generateBukkitWorld(String worldName, WorldType worldType, ChunkGenerator... chunkGenerators) {
WorldCreator worldCreator = new WorldCreator(worldName);
org.bukkit.WorldType bukkitWorldType;
switch(worldType) {
case VOID:
worldCreator.generateStructures(false);
bukkitWorldType = org.bukkit.WorldType.FLAT;
if (XMaterial.supports(17)) {
worldCreator.generator(new ModernVoidGenerator());
} else if (XMaterial.supports(13)) {
worldCreator.generator(new DeprecatedVoidGenerator());
} else {
worldCreator.generatorSettings("2;0;1");
}
break;
case FLAT:
case PRIVATE:
worldCreator.generateStructures(false);
bukkitWorldType = org.bukkit.WorldType.FLAT;
break;
case NETHER:
worldCreator.generateStructures(true);
bukkitWorldType = org.bukkit.WorldType.NORMAL;
worldCreator.environment(Environment.NETHER);
break;
case END:
worldCreator.generateStructures(true);
bukkitWorldType = org.bukkit.WorldType.NORMAL;
worldCreator.environment(Environment.THE_END);
break;
case CUSTOM:
if (chunkGenerators != null && chunkGenerators.length > 0) {
worldCreator.generator(chunkGenerators[0]);
}
default:
worldCreator.generateStructures(true);
bukkitWorldType = org.bukkit.WorldType.NORMAL;
worldCreator.environment(Environment.NORMAL);
break;
}
worldCreator.type(bukkitWorldType);
World bukkitWorld = Bukkit.createWorld(worldCreator);
if (bukkitWorld != null) {
bukkitWorld.setDifficulty(configValues.getWorldDifficulty());
bukkitWorld.setTime(configValues.getNoonTime());
bukkitWorld.getWorldBorder().setSize(configValues.getWorldBorderSize());
bukkitWorld.setKeepSpawnInMemory(configValues.isTeleportAfterCreation());
configValues.getDefaultGameRules().forEach(bukkitWorld::setGameRuleValue);
}
return bukkitWorld;
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldManager method importWorld.
/**
* Import a {@link BuildWorld} from a world directory.
*
* @param player The player who is creating the world
* @param worldName Name of the world that the chunk generator should be applied to.
* @param generator The generator type used by the world
* @param generatorName The name of the custom generator if generator type is {@link Generator#CUSTOM}
*/
public void importWorld(Player player, String worldName, Generator generator, String... generatorName) {
for (String charString : worldName.split("")) {
if (charString.matches("[^A-Za-z0-9/_-]")) {
player.sendMessage(plugin.getString("worlds_import_invalid_character").replace("%world%", worldName).replace("%char%", charString));
return;
}
}
File file = new File(Bukkit.getWorldContainer(), worldName);
if (!file.exists() || !file.isDirectory()) {
player.sendMessage(plugin.getString("worlds_import_unknown_world"));
return;
}
ChunkGenerator chunkGenerator = null;
if (generator == Generator.CUSTOM) {
List<String> genArray;
if (generatorName[0].contains(":")) {
genArray = Arrays.asList(generatorName[0].split(":"));
} else {
genArray = Arrays.asList(generatorName[0], generatorName[0]);
}
chunkGenerator = getChunkGenerator(genArray.get(0), genArray.get(1), worldName);
if (chunkGenerator == null) {
player.sendMessage(plugin.getString("worlds_import_unknown_generator"));
return;
}
}
player.sendMessage(plugin.getString("worlds_import_started").replace("%world%", worldName));
BuildWorld buildWorld = new BuildWorld(plugin, worldName, "-", null, WorldType.IMPORTED, FileUtils.getDirectoryCreation(file), false);
buildWorlds.add(buildWorld);
generateBukkitWorld(worldName, generator.getWorldType(), chunkGenerator);
player.sendMessage(plugin.getString("worlds_import_finished"));
if (configValues.isTeleportAfterCreation()) {
teleport(player, buildWorld);
}
}
use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.
the class WorldManager method renameWorld.
/**
* Change the name of a {@link BuildWorld} to a given name.
*
* @param player The player who issued the world rename
* @param buildWorld The build world object
* @param newName The name the world should be renamed to
*/
public void renameWorld(Player player, BuildWorld buildWorld, String newName) {
String oldName = buildWorld.getName();
if (oldName.equalsIgnoreCase(newName)) {
player.sendMessage(plugin.getString("worlds_rename_same_name"));
return;
}
for (String charString : newName.split("")) {
if (charString.matches("[^A-Za-z0-9/_-]")) {
player.sendMessage(plugin.getString("worlds_world_creation_invalid_characters"));
break;
}
}
player.closeInventory();
newName = newName.replaceAll("[^A-Za-z0-9/_-]", "").replace(" ", "_").trim();
if (newName.isEmpty()) {
player.sendMessage(plugin.getString("worlds_world_creation_name_bank"));
return;
}
File oldWorldFile = new File(Bukkit.getWorldContainer(), buildWorld.getName());
File newWorldFile = new File(Bukkit.getWorldContainer(), newName);
World oldWorld = Bukkit.getWorld(buildWorld.getName());
if (oldWorld == null) {
player.sendMessage(plugin.getString("worlds_rename_unknown_world"));
return;
}
oldWorld.save();
FileUtils.copy(oldWorldFile, newWorldFile);
String finalName = newName;
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
worldConfig.getFile().set("worlds." + finalName, worldConfig.getFile().getConfigurationSection("worlds." + buildWorld.getName()));
worldConfig.getFile().set("worlds." + buildWorld.getName(), null);
});
List<Player> players = new ArrayList<>();
SpawnManager spawnManager = plugin.getSpawnManager();
Location defaultSpawn = Bukkit.getWorlds().get(0).getSpawnLocation().add(0.5, 0, 0.5);
oldWorld.getPlayers().forEach(pl -> {
players.add(pl);
if (spawnManager.spawnExists()) {
if (!Objects.equals(spawnManager.getSpawn().getWorld(), pl.getWorld())) {
spawnManager.teleport(pl);
} else {
pl.teleport(defaultSpawn);
}
} else {
pl.teleport(defaultSpawn);
}
pl.sendMessage(plugin.getString("worlds_rename_players_world"));
});
Bukkit.getServer().unloadWorld(oldWorld, false);
File deleteFolder = oldWorld.getWorldFolder();
FileUtils.deleteDirectory(deleteFolder);
buildWorld.setName(newName);
World newWorld = generateBukkitWorld(buildWorld.getName(), buildWorld.getType());
Location spawnLocation = oldWorld.getSpawnLocation();
spawnLocation.setWorld(newWorld);
players.forEach(pl -> {
if (pl != null) {
pl.teleport(spawnLocation.add(0.5, 0, 0.5));
}
});
players.clear();
if (spawnManager.spawnExists() && Objects.equals(spawnManager.getSpawnWorld(), oldWorld)) {
Location oldSpawn = spawnManager.getSpawn();
Location newSpawn = new Location(spawnLocation.getWorld(), oldSpawn.getX(), oldSpawn.getY(), oldSpawn.getZ(), oldSpawn.getYaw(), oldSpawn.getPitch());
spawnManager.set(newSpawn, newSpawn.getWorld().getName());
}
player.sendMessage(plugin.getString("worlds_rename_set").replace("%oldName%", oldName).replace("%newName%", newName));
}
Aggregations