Search in sources :

Example 96 with BuildWorld

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%"));
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld)

Example 97 with BuildWorld

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);
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Location(org.bukkit.Location)

Example 98 with BuildWorld

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;
}
Also used : DeprecatedVoidGenerator(com.eintosti.buildsystem.object.world.generator.DeprecatedVoidGenerator) WorldCreator(org.bukkit.WorldCreator) World(org.bukkit.World) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) ModernVoidGenerator(com.eintosti.buildsystem.object.world.generator.ModernVoidGenerator)

Example 99 with BuildWorld

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);
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) ChunkGenerator(org.bukkit.generator.ChunkGenerator) File(java.io.File)

Example 100 with 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));
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) World(org.bukkit.World) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) File(java.io.File) Location(org.bukkit.Location)

Aggregations

BuildWorld (com.eintosti.buildsystem.object.world.BuildWorld)143 EventHandler (org.bukkit.event.EventHandler)58 Player (org.bukkit.entity.Player)52 World (org.bukkit.World)40 Block (org.bukkit.block.Block)20 ItemStack (org.bukkit.inventory.ItemStack)18 XMaterial (com.cryptomorin.xseries.XMaterial)16 PlayerChatInput (com.eintosti.buildsystem.util.external.PlayerChatInput)16 UUID (java.util.UUID)14 Location (org.bukkit.Location)14 File (java.io.File)12 ArrayList (java.util.ArrayList)9 BuildSystem (com.eintosti.buildsystem.BuildSystem)6 Builder (com.eintosti.buildsystem.object.world.Builder)6 List (java.util.List)6 Bukkit (org.bukkit.Bukkit)6 Material (org.bukkit.Material)6 ChunkGenerator (org.bukkit.generator.ChunkGenerator)6 Inventory (org.bukkit.inventory.Inventory)6 ItemMeta (org.bukkit.inventory.meta.ItemMeta)6