Search in sources :

Example 1 with ArenaInitializer1_11_R1

use of pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1 in project Village_Defense by Plajer.

the class SetupInventoryEvents method onClick.

@EventHandler
public void onClick(InventoryClickEvent event) {
    if (event.getWhoClicked().getType() != EntityType.PLAYER)
        return;
    Player player = (Player) event.getWhoClicked();
    if (!player.hasPermission(PermissionsManager.getEditGames()))
        return;
    if (!event.getInventory().getName().contains("Arena:"))
        return;
    if (event.getInventory().getHolder() != null)
        return;
    if (event.getCurrentItem() == null)
        return;
    if (!event.getCurrentItem().hasItemMeta())
        return;
    if (!event.getCurrentItem().getItemMeta().hasDisplayName())
        return;
    String name = event.getCurrentItem().getItemMeta().getDisplayName();
    name = ChatColor.stripColor(name);
    Arena arena = ArenaRegistry.getArena(event.getInventory().getName().replace("Arena: ", ""));
    if (event.getCurrentItem().getType() == Material.NAME_TAG && event.getCursor().getType() == Material.NAME_TAG) {
        event.setCancelled(true);
        if (!event.getCursor().hasItemMeta()) {
            player.sendMessage(ChatColor.RED + "This item doesn't has a name!");
            return;
        }
        if (!event.getCursor().getItemMeta().hasDisplayName()) {
            player.sendMessage(ChatColor.RED + "This item doesn't has a name!");
            return;
        }
        player.performCommand("vd " + arena.getID() + " set MAPNAME " + event.getCursor().getItemMeta().getDisplayName());
        event.getCurrentItem().getItemMeta().setDisplayName(ChatColor.GOLD + "Set a mapname (currently: " + event.getCursor().getItemMeta().getDisplayName());
        return;
    }
    ClickType clickType = event.getClick();
    if (name.contains("ending location")) {
        event.setCancelled(true);
        player.closeInventory();
        player.performCommand("vd " + arena.getID() + " set ENDLOC");
        return;
    }
    if (name.contains("starting location")) {
        event.setCancelled(true);
        player.closeInventory();
        player.performCommand("vd " + arena.getID() + " set STARTLOC");
        return;
    }
    if (name.contains("lobby location")) {
        event.setCancelled(true);
        player.closeInventory();
        player.performCommand("vd " + arena.getID() + " set LOBBYLOC");
        return;
    }
    if (name.contains("maximum players")) {
        event.setCancelled(true);
        if (clickType.isRightClick()) {
            event.getCurrentItem().setAmount(event.getCurrentItem().getAmount() + 1);
            player.performCommand("vd " + arena.getID() + " set MAXPLAYERS " + event.getCurrentItem().getAmount());
        }
        if (clickType.isLeftClick()) {
            event.getCurrentItem().setAmount(event.getCurrentItem().getAmount() - 1);
            player.performCommand("vd " + arena.getID() + " set MAXPLAYERS " + event.getCurrentItem().getAmount());
        }
        player.closeInventory();
        player.openInventory(new SetupInventory(arena).getInventory());
    }
    if (name.contains("minimum players")) {
        event.setCancelled(true);
        if (clickType.isRightClick()) {
            event.getCurrentItem().setAmount(event.getCurrentItem().getAmount() + 1);
            player.performCommand("vd " + arena.getID() + " set MINPLAYERS " + event.getCurrentItem().getAmount());
        }
        if (clickType.isLeftClick()) {
            event.getCurrentItem().setAmount(event.getCurrentItem().getAmount() - 1);
            player.performCommand("vd " + arena.getID() + " set MINPLAYERS " + event.getCurrentItem().getAmount());
        }
        player.closeInventory();
        player.openInventory(new SetupInventory(arena).getInventory());
    }
    if (name.contains("Add game sign")) {
        event.setCancelled(true);
        player.performCommand("vda addsign " + arena.getID());
        return;
    }
    if (event.getCurrentItem().getType() != Material.NAME_TAG) {
        event.setCancelled(true);
    }
    if (name.contains("Add villager spawn")) {
        event.setCancelled(true);
        player.performCommand("vd " + arena.getID() + " addspawn villager");
        player.closeInventory();
        return;
    }
    if (name.contains("Add zombie spawn")) {
        event.setCancelled(true);
        player.performCommand("vd " + arena.getID() + " addspawn zombie");
        player.closeInventory();
    }
    if (name.contains("Add doors")) {
        event.setCancelled(true);
        player.performCommand("vd " + arena.getID() + " addspawn doors");
        player.closeInventory();
        return;
    }
    if (name.contains("Set chest shop")) {
        event.setCancelled(true);
        Block targetBlock;
        targetBlock = player.getTargetBlock(null, 100);
        if (targetBlock == null || targetBlock.getType() != Material.CHEST) {
            player.sendMessage(ChatColor.RED + "Look at the chest! You are targeting something else!");
            return;
        }
        Util.saveLoc("instances." + arena.getID() + ".shop", targetBlock.getLocation(), false);
        ShopManager.registerShop(arena);
        player.sendMessage(ChatColor.GREEN + "shop for chest set!");
    }
    if (name.contains("Register arena")) {
        event.setCancelled(true);
        event.getWhoClicked().closeInventory();
        if (ArenaRegistry.getArena(arena.getID()).isReady()) {
            event.getWhoClicked().sendMessage(ChatColor.GREEN + "This arena was already validated and is ready to use!");
            return;
        }
        String[] locations = new String[] { "lobbylocation", "Startlocation", "Endlocation" };
        String[] spawns = new String[] { "zombiespawns", "villagerspawns" };
        for (String s : locations) {
            if (!ConfigurationManager.getConfig("arenas").isSet("instances." + arena.getID() + "." + s) || ConfigurationManager.getConfig("arenas").getString("instances." + arena.getID() + "." + s).equals(Util.locationToString(Bukkit.getWorlds().get(0).getSpawnLocation()))) {
                event.getWhoClicked().sendMessage(ChatColor.RED + "Arena validation failed! Please configure following spawn properly: " + s + " (cannot be world spawn location)");
                return;
            }
        }
        for (String s : spawns) {
            if (!ConfigurationManager.getConfig("arenas").isSet("instances." + arena.getID() + "." + s) || ConfigurationManager.getConfig("arenas").getConfigurationSection("instances." + arena.getID() + "." + s).getKeys(false).size() < 2) {
                event.getWhoClicked().sendMessage(ChatColor.RED + "Arena validation failed! Please configure following mob spawns properly: " + s + " (must be minimum 2 spawns)");
                return;
            }
        }
        if (ConfigurationManager.getConfig("arenas").getConfigurationSection("instances." + arena.getID() + ".doors") == null) {
            event.getWhoClicked().sendMessage(ChatColor.RED + "Arena validation failed! Please configure doors properly");
            return;
        }
        event.getWhoClicked().sendMessage(ChatColor.GREEN + "Validation succeeded! Registering new arena instance: " + arena.getID());
        FileConfiguration config = ConfigurationManager.getConfig("arenas");
        config.set("instances." + arena.getID() + ".isdone", true);
        ConfigurationManager.saveConfig(config, "arenas");
        List<Sign> signsToUpdate = new ArrayList<>();
        ArenaRegistry.unregisterArena(arena);
        if (plugin.getSignManager().getLoadedSigns().containsValue(arena)) {
            for (Sign s : plugin.getSignManager().getLoadedSigns().keySet()) {
                if (plugin.getSignManager().getLoadedSigns().get(s).equals(arena)) {
                    signsToUpdate.add(s);
                }
            }
        }
        if (plugin.is1_8_R3()) {
            arena = new ArenaInitializer1_8_R3(arena.getID(), plugin);
        } else if (plugin.is1_9_R1()) {
            arena = new ArenaInitializer1_9_R1(arena.getID(), plugin);
        } else if (plugin.is1_11_R1()) {
            arena = new ArenaInitializer1_11_R1(arena.getID(), plugin);
        } else {
            arena = new ArenaInitializer1_12_R1(arena.getID(), plugin);
        }
        arena.setReady(true);
        arena.setMinimumPlayers(ConfigurationManager.getConfig("arenas").getInt("instances." + arena.getID() + ".minimumplayers"));
        arena.setMaximumPlayers(ConfigurationManager.getConfig("arenas").getInt("instances." + arena.getID() + ".maximumplayers"));
        arena.setMapName(ConfigurationManager.getConfig("arenas").getString("instances." + arena.getID() + ".mapname"));
        arena.setLobbyLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString("instances." + arena.getID() + ".lobbylocation")));
        arena.setStartLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString("instances." + arena.getID() + ".Startlocation")));
        arena.setEndLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString("instances." + arena.getID() + ".Endlocation")));
        for (String string : ConfigurationManager.getConfig("arenas").getConfigurationSection("instances." + arena.getID() + ".zombiespawns").getKeys(false)) {
            String path = "instances." + arena.getID() + ".zombiespawns." + string;
            arena.addZombieSpawn(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path)));
        }
        for (String string : ConfigurationManager.getConfig("arenas").getConfigurationSection("instances." + arena.getID() + ".villagerspawns").getKeys(false)) {
            String path = "instances." + arena.getID() + ".villagerspawns." + string;
            arena.addVillagerSpawn(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path)));
        }
        for (String string : ConfigurationManager.getConfig("arenas").getConfigurationSection("instances." + arena.getID() + ".doors").getKeys(false)) {
            String path = "instances." + arena.getID() + ".doors." + string + ".";
            arena.addDoor(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path + "location")), (byte) ConfigurationManager.getConfig("arenas").getInt(path + "byte"));
        }
        ArenaRegistry.registerArena(arena);
        arena.start();
        for (Sign s : signsToUpdate) {
            plugin.getSignManager().getLoadedSigns().put(s, arena);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) ArenaInitializer1_8_R3(pl.plajer.villagedefense3.arena.ArenaInitializer1_8_R3) Arena(pl.plajer.villagedefense3.arena.Arena) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ArenaInitializer1_11_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1) ClickType(org.bukkit.event.inventory.ClickType) ArenaInitializer1_9_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_9_R1) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) ArenaInitializer1_12_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_12_R1) SetupInventory(pl.plajer.villagedefense3.utils.SetupInventory) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ArenaInitializer1_11_R1

use of pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1 in project Village_Defense by Plajer.

the class GolemFriendKit method giveKitItems.

@Override
public void giveKitItems(Player player) {
    player.getInventory().addItem(WeaponHelper.getUnBreakingSword(WeaponHelper.ResourceType.STONE, 10));
    ArmorHelper.setColouredArmor(Color.WHITE, player);
    player.getInventory().addItem(new ItemStack(Material.GRILLED_PORK, 8));
    Arena arena = ArenaRegistry.getArena(player);
    if (arena == null)
        return;
    if (plugin.is1_8_R3()) {
        ArenaInitializer1_8_R3 initializer = (ArenaInitializer1_8_R3) arena;
        initializer.spawnGolem(initializer.getStartLocation(), player);
    } else if (plugin.is1_9_R1()) {
        ArenaInitializer1_9_R1 initializer = (ArenaInitializer1_9_R1) arena;
        initializer.spawnGolem(initializer.getStartLocation(), player);
    } else if (plugin.is1_11_R1()) {
        ArenaInitializer1_11_R1 initializer = (ArenaInitializer1_11_R1) arena;
        initializer.spawnGolem(initializer.getStartLocation(), player);
    } else if (plugin.is1_12_R1()) {
        ArenaInitializer1_12_R1 initializer = (ArenaInitializer1_12_R1) arena;
        initializer.spawnGolem(initializer.getStartLocation(), player);
    }
}
Also used : ArenaInitializer1_11_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1) ArenaInitializer1_9_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_9_R1) ArenaInitializer1_8_R3(pl.plajer.villagedefense3.arena.ArenaInitializer1_8_R3) ItemStack(org.bukkit.inventory.ItemStack) ArenaInitializer1_12_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_12_R1) Arena(pl.plajer.villagedefense3.arena.Arena)

Example 3 with ArenaInitializer1_11_R1

use of pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1 in project Village_Defense by Plajer.

the class GolemFriendKit method reStock.

@Override
public void reStock(Player player) {
    Arena arena = ArenaRegistry.getArena(player);
    if (arena.getWave() % 5 == 0) {
        if (plugin.is1_8_R3()) {
            ArenaInitializer1_8_R3 initializer = (ArenaInitializer1_8_R3) arena;
            initializer.spawnGolem(initializer.getStartLocation(), player);
        } else if (plugin.is1_9_R1()) {
            ArenaInitializer1_9_R1 initializer = (ArenaInitializer1_9_R1) arena;
            initializer.spawnGolem(initializer.getStartLocation(), player);
        } else if (plugin.is1_11_R1()) {
            ArenaInitializer1_11_R1 initializer = (ArenaInitializer1_11_R1) arena;
            initializer.spawnGolem(initializer.getStartLocation(), player);
        } else if (plugin.is1_12_R1()) {
            ArenaInitializer1_12_R1 initializer = (ArenaInitializer1_12_R1) arena;
            initializer.spawnGolem(initializer.getStartLocation(), player);
        }
    }
}
Also used : ArenaInitializer1_11_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1) ArenaInitializer1_9_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_9_R1) ArenaInitializer1_8_R3(pl.plajer.villagedefense3.arena.ArenaInitializer1_8_R3) ArenaInitializer1_12_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_12_R1) Arena(pl.plajer.villagedefense3.arena.Arena)

Example 4 with ArenaInitializer1_11_R1

use of pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1 in project Village_Defense by Plajer.

the class Main method registerArenas.

public void registerArenas() {
    if (ArenaRegistry.getArenas() != null) {
        if (ArenaRegistry.getArenas().size() > 0) {
            for (Arena arena : ArenaRegistry.getArenas()) {
                arena.clearZombies();
                arena.clearVillagers();
                arena.clearWolfs();
                arena.clearGolems();
            }
        }
    }
    ArenaRegistry.getArenas().clear();
    if (!ConfigurationManager.getConfig("arenas").contains("instances")) {
        Bukkit.getConsoleSender().sendMessage(ChatManager.colorMessage("Validator.No-Instances-Created"));
        return;
    }
    for (String ID : ConfigurationManager.getConfig("arenas").getConfigurationSection("instances").getKeys(false)) {
        Arena arena;
        String s = "instances." + ID + ".";
        if (s.contains("default"))
            continue;
        if (is1_8_R3()) {
            arena = new ArenaInitializer1_8_R3(ID, this);
        } else if (is1_9_R1()) {
            arena = new ArenaInitializer1_9_R1(ID, this);
        } else if (is1_11_R1()) {
            arena = new ArenaInitializer1_11_R1(ID, this);
        } else {
            arena = new ArenaInitializer1_12_R1(ID, this);
        }
        arena.setMinimumPlayers(ConfigurationManager.getConfig("arenas").getInt(s + "minimumplayers"));
        arena.setMaximumPlayers(ConfigurationManager.getConfig("arenas").getInt(s + "maximumplayers"));
        arena.setMapName(ConfigurationManager.getConfig("arenas").getString(s + "mapname"));
        arena.setLobbyLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(s + "lobbylocation")));
        arena.setStartLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(s + "Startlocation")));
        arena.setEndLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(s + "Endlocation")));
        if (!ConfigurationManager.getConfig("arenas").getBoolean(s + "isdone")) {
            Bukkit.getConsoleSender().sendMessage(ChatManager.colorMessage("Validator.Invalid-Arena-Configuration").replaceAll("%arena%", ID).replaceAll("%error%", "NOT VALIDATED"));
            arena.setReady(false);
            ArenaRegistry.registerArena(arena);
            continue;
        }
        if (ConfigurationManager.getConfig("arenas").contains(s + "zombiespawns")) {
            for (String string : ConfigurationManager.getConfig("arenas").getConfigurationSection(s + "zombiespawns").getKeys(false)) {
                String path = s + "zombiespawns." + string;
                arena.addZombieSpawn(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path)));
            }
        } else {
            Bukkit.getConsoleSender().sendMessage(ChatManager.colorMessage("Validator.Invalid-Arena-Configuration").replaceAll("%arena%", ID).replaceAll("%error%", "ZOMBIE SPAWNS"));
            arena.setReady(false);
            ArenaRegistry.registerArena(arena);
            continue;
        }
        if (ConfigurationManager.getConfig("arenas").contains(s + "villagerspawns")) {
            for (String string : ConfigurationManager.getConfig("arenas").getConfigurationSection(s + "villagerspawns").getKeys(false)) {
                String path = s + "villagerspawns." + string;
                arena.addVillagerSpawn(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path)));
            }
        } else {
            Bukkit.getConsoleSender().sendMessage(ChatManager.colorMessage("Validator.Invalid-Arena-Configuration").replaceAll("%arena%", ID).replaceAll("%error%", "VILLAGER SPAWNS"));
            arena.setReady(false);
            ArenaRegistry.registerArena(arena);
            continue;
        }
        if (ConfigurationManager.getConfig("arenas").contains(s + "doors")) {
            for (String string : ConfigurationManager.getConfig("arenas").getConfigurationSection(s + "doors").getKeys(false)) {
                String path = s + "doors." + string + ".";
                arena.addDoor(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path + "location")), (byte) ConfigurationManager.getConfig("arenas").getInt(path + "byte"));
            }
        } else {
            Bukkit.getConsoleSender().sendMessage(ChatManager.colorMessage("Validator.Invalid-Arena-Configuration").replaceAll("%arena%", ID).replaceAll("%error%", "DOORS"));
            arena.setReady(false);
            ArenaRegistry.registerArena(arena);
            continue;
        }
        ArenaRegistry.registerArena(arena);
        arena.start();
        Bukkit.getConsoleSender().sendMessage(ChatManager.colorMessage("Validator.Instance-Started").replaceAll("%arena%", ID));
    }
    new ShopManager();
}
Also used : ArenaInitializer1_11_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1) ArenaInitializer1_9_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_9_R1) ArenaInitializer1_8_R3(pl.plajer.villagedefense3.arena.ArenaInitializer1_8_R3) ShopManager(pl.plajer.villagedefense3.handlers.ShopManager) ArenaInitializer1_12_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_12_R1) Arena(pl.plajer.villagedefense3.arena.Arena)

Example 5 with ArenaInitializer1_11_R1

use of pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1 in project Village_Defense by Plajer.

the class MainCommand method createInstanceInConfig.

private void createInstanceInConfig(String ID, String worldName) {
    String path = "instances." + ID + ".";
    Util.saveLoc(path + "lobbylocation", Bukkit.getServer().getWorlds().get(0).getSpawnLocation(), false);
    Util.saveLoc(path + "Startlocation", Bukkit.getServer().getWorlds().get(0).getSpawnLocation(), false);
    Util.saveLoc(path + "Endlocation", Bukkit.getServer().getWorlds().get(0).getSpawnLocation(), false);
    FileConfiguration config = ConfigurationManager.getConfig("arenas");
    config.set(path + "minimumplayers", 1);
    config.set(path + "maximumplayers", 10);
    config.set(path + "mapname", ID);
    config.set(path + "signs", new ArrayList<>());
    config.set(path + "isdone", false);
    config.set(path + "world", worldName);
    ConfigurationManager.saveConfig(config, "arenas");
    Arena arena;
    if (plugin.is1_8_R3()) {
        arena = new ArenaInitializer1_8_R3(ID, plugin);
    } else if (plugin.is1_9_R1()) {
        arena = new ArenaInitializer1_9_R1(ID, plugin);
    } else if (plugin.is1_11_R1()) {
        arena = new ArenaInitializer1_11_R1(ID, plugin);
    } else {
        arena = new ArenaInitializer1_12_R1(ID, plugin);
    }
    arena.setMinimumPlayers(ConfigurationManager.getConfig("arenas").getInt(path + "minimumplayers"));
    arena.setMaximumPlayers(ConfigurationManager.getConfig("arenas").getInt(path + "maximumplayers"));
    arena.setMapName(ConfigurationManager.getConfig("arenas").getString(path + "mapname"));
    arena.setLobbyLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path + "lobbylocation")));
    arena.setStartLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path + "Startlocation")));
    arena.setEndLocation(Util.getLocation(false, ConfigurationManager.getConfig("arenas").getString(path + "Endlocation")));
    arena.setReady(false);
    ArenaRegistry.registerArena(arena);
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ArenaInitializer1_11_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1) ArenaInitializer1_9_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_9_R1) ArenaInitializer1_8_R3(pl.plajer.villagedefense3.arena.ArenaInitializer1_8_R3) ArenaInitializer1_12_R1(pl.plajer.villagedefense3.arena.ArenaInitializer1_12_R1) Arena(pl.plajer.villagedefense3.arena.Arena)

Aggregations

Arena (pl.plajer.villagedefense3.arena.Arena)7 ArenaInitializer1_11_R1 (pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1)7 ArenaInitializer1_12_R1 (pl.plajer.villagedefense3.arena.ArenaInitializer1_12_R1)7 ArenaInitializer1_8_R3 (pl.plajer.villagedefense3.arena.ArenaInitializer1_8_R3)7 ArenaInitializer1_9_R1 (pl.plajer.villagedefense3.arena.ArenaInitializer1_9_R1)7 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 ItemStack (org.bukkit.inventory.ItemStack)2 ArrayList (java.util.ArrayList)1 Block (org.bukkit.block.Block)1 Sign (org.bukkit.block.Sign)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ClickType (org.bukkit.event.inventory.ClickType)1 ShopManager (pl.plajer.villagedefense3.handlers.ShopManager)1 SetupInventory (pl.plajer.villagedefense3.utils.SetupInventory)1