Search in sources :

Example 26 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class BuilderInventory method onInventoryClick.

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (!inventoryManager.checkIfValidClick(event, "worldeditor_builders_title")) {
        return;
    }
    Player player = (Player) event.getWhoClicked();
    BuildWorld buildWorld = plugin.getPlayerManager().getSelectedWorld().get(player.getUniqueId());
    if (buildWorld == null) {
        player.closeInventory();
        player.sendMessage(plugin.getString("worlds_addbuilder_error"));
        return;
    }
    ItemStack itemStack = event.getCurrentItem();
    ItemMeta itemMeta = itemStack.getItemMeta();
    if (itemMeta == null) {
        return;
    }
    Material material = itemStack.getType();
    if (material != XMaterial.PLAYER_HEAD.parseMaterial()) {
        XSound.BLOCK_CHEST_OPEN.play(player);
        plugin.getEditInventory().openInventory(player, buildWorld);
        return;
    }
    int slot = event.getSlot();
    switch(slot) {
        case 18:
            decrementInv(player);
            break;
        case 22:
            XSound.ENTITY_CHICKEN_EGG.play(player);
            plugin.getWorldsCommand().getAddBuilderInput(player, false);
            return;
        case 26:
            incrementInv(player);
            break;
        default:
            if (slot == 4) {
                return;
            }
            if (!itemMeta.hasDisplayName()) {
                return;
            }
            if (!event.isShiftClick()) {
                return;
            }
            String builderName = ChatColor.stripColor(itemMeta.getDisplayName());
            UUID builderId = UUIDFetcher.getUUID(builderName);
            buildWorld.removeBuilder(builderId);
            XSound.ENTITY_ENDERMAN_TELEPORT.play(player);
            player.sendMessage(plugin.getString("worlds_removebuilder_removed").replace("%builder%", builderName));
    }
    XSound.ENTITY_CHICKEN_EGG.play(player);
    player.openInventory(getInventory(buildWorld, player));
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) XMaterial(com.cryptomorin.xseries.XMaterial) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) UUID(java.util.UUID) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Example 27 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class DeleteInventory method onInventoryClick.

@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (!inventoryManager.checkIfValidClick(event, "delete_title")) {
        return;
    }
    Player player = (Player) event.getWhoClicked();
    BuildWorld buildWorld = plugin.getPlayerManager().getSelectedWorld().get(player.getUniqueId());
    if (buildWorld == null) {
        player.sendMessage(plugin.getString("worlds_delete_error"));
        player.closeInventory();
        return;
    }
    int slot = event.getSlot();
    if (slot == 11) {
        XSound.ENTITY_PLAYER_LEVELUP.play(player);
        player.closeInventory();
        plugin.getWorldManager().deleteWorld(player, buildWorld);
    } else if (slot == 15) {
        XSound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR.play(player);
        player.closeInventory();
        player.sendMessage(plugin.getString("worlds_delete_canceled").replace("%world%", buildWorld.getName()));
    }
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Example 28 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class SpawnManager method teleport.

public boolean teleport(Player player) {
    if (!spawnExists()) {
        return false;
    }
    BuildWorld buildWorld = worldManager.getBuildWorld(spawnName);
    if (buildWorld != null) {
        if (!buildWorld.isLoaded()) {
            buildWorld.load(player);
        }
    }
    player.setFallDistance(0);
    player.teleport(spawn);
    Titles.clearTitle(player);
    return true;
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld)

Example 29 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class WorldManager method loadWorld.

public BuildWorld loadWorld(String worldName) {
    FileConfiguration configuration = worldConfig.getFile();
    if (configuration == null) {
        return null;
    }
    String creator = configuration.isString("worlds." + worldName + ".creator") ? configuration.getString("worlds." + worldName + ".creator") : "-";
    UUID creatorId = parseCreatorId(configuration, worldName, creator);
    WorldType worldType = configuration.isString("worlds." + worldName + ".type") ? WorldType.valueOf(configuration.getString("worlds." + worldName + ".type")) : WorldType.UNKNOWN;
    boolean privateWorld = configuration.isBoolean("worlds." + worldName + ".private") && configuration.getBoolean("worlds." + worldName + ".private");
    XMaterial material = parseMaterial(configuration, worldName);
    WorldStatus worldStatus = WorldStatus.valueOf(configuration.getString("worlds." + worldName + ".status"));
    String project = configuration.getString("worlds." + worldName + ".project");
    String permission = configuration.getString("worlds." + worldName + ".permission");
    long date = configuration.isLong("worlds." + worldName + ".date") ? configuration.getLong("worlds." + worldName + ".date") : -1;
    boolean physics = configuration.getBoolean("worlds." + worldName + ".physics");
    boolean explosions = !configuration.isBoolean("worlds." + worldName + ".explosions") || configuration.getBoolean("worlds." + worldName + ".explosions");
    boolean mobAI = !configuration.isBoolean("worlds." + worldName + ".mobai") || configuration.getBoolean("worlds." + worldName + ".mobai");
    String customSpawn = configuration.getString("worlds." + worldName + ".spawn");
    boolean blockBreaking = !configuration.isBoolean("worlds." + worldName + ".block-breaking") || configuration.getBoolean("worlds." + worldName + ".block-breaking");
    boolean blockPlacement = !configuration.isBoolean("worlds." + worldName + ".block-placement") || configuration.getBoolean("worlds." + worldName + ".block-placement");
    boolean blockInteractions = !configuration.isBoolean("worlds." + worldName + ".block-interactions") || configuration.getBoolean("worlds." + worldName + ".block-interactions");
    boolean buildersEnabled = configuration.isBoolean("worlds." + worldName + ".builders-enabled") && configuration.getBoolean("worlds." + worldName + ".builders-enabled");
    List<Builder> builders = parseBuilders(configuration, worldName);
    String chunkGeneratorString = configuration.getString("worlds." + worldName + ".chunk-generator");
    ChunkGenerator chunkGenerator = parseChunkGenerator(configuration, worldName);
    if (worldType == WorldType.PRIVATE) {
        privateWorld = true;
        worldType = WorldType.FLAT;
    }
    BuildWorld buildWorld = new BuildWorld(plugin, worldName, creator, creatorId, worldType, privateWorld, material, worldStatus, project, permission, date, physics, explosions, mobAI, customSpawn, blockBreaking, blockPlacement, blockInteractions, buildersEnabled, builders, chunkGenerator, chunkGeneratorString);
    buildWorlds.add(buildWorld);
    return buildWorld;
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) WorldType(com.eintosti.buildsystem.object.world.data.WorldType) Builder(com.eintosti.buildsystem.object.world.Builder) UUID(java.util.UUID) XMaterial(com.cryptomorin.xseries.XMaterial) ChunkGenerator(org.bukkit.generator.ChunkGenerator) WorldStatus(com.eintosti.buildsystem.object.world.data.WorldStatus)

Example 30 with BuildWorld

use of com.eintosti.buildsystem.object.world.BuildWorld in project BuildSystem by einTosti.

the class WorldManager method createTemplateWorld.

/**
 * Generate a {@link BuildWorld} with a template.
 *
 * @param player       The player who is creating the world
 * @param worldName    The name of the world
 * @param template     The name of the template world
 * @param privateWorld Is world going to be a private world?
 * @return {@code true} if the world was successfully created, {@code false otherwise}
 */
private boolean createTemplateWorld(Player player, String worldName, String template, boolean privateWorld) {
    boolean worldExists = getBuildWorld(worldName) != null;
    File worldFile = new File(Bukkit.getWorldContainer(), worldName);
    if (worldExists || worldFile.exists()) {
        player.sendMessage(plugin.getString("worlds_world_exists"));
        return false;
    }
    File templateFile = new File(plugin.getDataFolder() + File.separator + "templates" + File.separator + template);
    if (!templateFile.exists()) {
        player.sendMessage(plugin.getString("worlds_template_does_not_exist"));
        return false;
    }
    BuildWorld buildWorld = new BuildWorld(plugin, worldName, player.getName(), player.getUniqueId(), WorldType.TEMPLATE, System.currentTimeMillis(), privateWorld);
    buildWorlds.add(buildWorld);
    player.sendMessage(plugin.getString("worlds_template_creation_started").replace("%world%", buildWorld.getName()).replace("%template%", template));
    FileUtils.copy(templateFile, worldFile);
    Bukkit.createWorld(WorldCreator.name(worldName).type(org.bukkit.WorldType.FLAT).generateStructures(false));
    player.sendMessage(plugin.getString("worlds_creation_finished"));
    return true;
}
Also used : BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) File(java.io.File)

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