Search in sources :

Example 31 with BuildWorld

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

Example 32 with BuildWorld

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

Example 33 with BuildWorld

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

Example 34 with BuildWorld

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);
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) File(java.io.File)

Example 35 with BuildWorld

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

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