Search in sources :

Example 1 with SetupInventory

use of pl.plajer.villagedefense3.utils.SetupInventory 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 SetupInventory

use of pl.plajer.villagedefense3.utils.SetupInventory in project Village_Defense by Plajer.

the class MainCommand method performSetup.

void performSetup(Player player, String[] args) {
    if (args[1].equalsIgnoreCase("setup") || args[1].equals("edit")) {
        if (ArenaRegistry.getArena(args[0]) == null) {
            player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("Commands.No-Arena-Like-That"));
            return;
        }
        new SetupInventory(ArenaRegistry.getArena(args[0])).openInventory(player);
        return;
    }
    if (!(args.length > 2))
        return;
    FileConfiguration config = ConfigurationManager.getConfig("arenas");
    if (!config.contains("instances." + args[0])) {
        player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatManager.colorMessage("Commands.No-Arena-Like-That"));
        player.sendMessage(ChatColor.RED + "Usage: /vd < ARENA ID > set <MINPLAYRS | MAXPLAYERS | MAPNAME | SCHEMATIC | LOBBYLOCATION | EndLOCATION | STARTLOCATION  >  < VALUE>");
        return;
    }
    if (args[1].equalsIgnoreCase("addspawn")) {
        if (args[2].equalsIgnoreCase("zombie")) {
            int i;
            if (!config.contains("instances." + args[0] + ".zombiespawns")) {
                i = 0;
            } else {
                i = config.getConfigurationSection("instances." + args[0] + ".zombiespawns").getKeys(false).size();
            }
            i++;
            Util.saveLoc("instances." + args[0] + ".zombiespawns." + i, player.getLocation(), false);
            player.sendMessage(ChatColor.GREEN + "Zombie spawn added!");
            return;
        }
        if (args[2].equalsIgnoreCase("villager")) {
            int i;
            if (!config.contains("instances." + args[0] + ".villagerspawns")) {
                i = 0;
            } else {
                i = config.getConfigurationSection("instances." + args[0] + ".villagerspawns").getKeys(false).size();
            }
            i++;
            Util.saveLoc("instances." + args[0] + ".villagerspawns." + i, player.getLocation(), false);
            player.sendMessage(ChatColor.GREEN + "Villager spawn added!");
            return;
        }
        if (args[2].equalsIgnoreCase("doors")) {
            String ID = args[0];
            int counter = 0;
            int i;
            if (plugin.getWorldEditPlugin().getSelection(player) == null)
                return;
            if (!config.contains("instances." + ID + ".doors")) {
                i = 0;
            } else {
                i = config.getConfigurationSection("instances." + ID + ".doors").getKeys(false).size();
            }
            i++;
            Selection selection = plugin.getWorldEditPlugin().getSelection(player);
            if (selection instanceof CuboidSelection) {
                CuboidSelection cuboidSelection = (CuboidSelection) selection;
                Vector min = cuboidSelection.getNativeMinimumPoint();
                Vector max = cuboidSelection.getNativeMaximumPoint();
                for (int x = min.getBlockX(); x <= max.getBlockX(); x = x + 1) {
                    for (int y = min.getBlockY(); y <= max.getBlockY(); y = y + 1) {
                        for (int z = min.getBlockZ(); z <= max.getBlockZ(); z = z + 1) {
                            Location temporaryBlock = new Location(player.getWorld(), x, y, z);
                            if (temporaryBlock.getBlock().getType() == Material.WOODEN_DOOR) {
                                String location = temporaryBlock.getWorld().getName() + "," + temporaryBlock.getX() + "," + temporaryBlock.getY() + "," + temporaryBlock.getZ() + "," + temporaryBlock.getYaw() + "," + temporaryBlock.getPitch();
                                config.set("instances." + ID + ".doors." + i + ".location", location);
                                config.set("instances." + ID + ".doors." + i + ".byte", temporaryBlock.getBlock().getData());
                                counter++;
                                i++;
                            }
                        }
                    }
                }
            } else {
                if (selection.getMaximumPoint().getBlock().getType() == Material.WOODEN_DOOR) {
                    String location = selection.getMaximumPoint().getWorld().getName() + "," + selection.getMaximumPoint().getX() + "," + selection.getMaximumPoint().getY() + "," + selection.getMaximumPoint().getZ() + "," + selection.getMaximumPoint().getYaw() + "," + selection.getMaximumPoint().getPitch();
                    config.set("instances." + ID + ".doors." + i + ".location", location);
                    config.set("instances." + ID + ".doors." + i + ".byte", selection.getMaximumPoint().getBlock().getData());
                    counter++;
                    i++;
                }
                if (selection.getMinimumPoint().getBlock().getType() == Material.WOODEN_DOOR) {
                    String location = selection.getMaximumPoint().getWorld().getName() + "," + selection.getMaximumPoint().getX() + "," + selection.getMaximumPoint().getY() + "," + selection.getMaximumPoint().getZ() + "," + selection.getMaximumPoint().getYaw() + "," + selection.getMaximumPoint().getPitch();
                    config.set("instances." + ID + ".doors." + i + ".location", location);
                    config.set("instances." + ID + ".doors." + i + ".byte", selection.getMinimumPoint().getBlock().getData());
                    counter++;
                    i++;
                }
            }
            player.sendMessage(ChatColor.GREEN + "" + (int) Math.ceil(counter / 2) + " doors were added!");
        }
        ConfigurationManager.saveConfig(config, "arenas");
        return;
    }
    if (!(args[1].equalsIgnoreCase("set")))
        return;
    if (args.length == 3) {
        if (args[2].equalsIgnoreCase("lobbylocation") || args[2].equalsIgnoreCase("lobbyloc")) {
            String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
            config.set("instances." + args[0] + ".lobbylocation", location);
            player.sendMessage("VillageDefense: Lobby location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
        } else if (args[2].equalsIgnoreCase("Startlocation") || args[2].equalsIgnoreCase("Startloc")) {
            String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
            config.set("instances." + args[0] + ".Startlocation", location);
            player.sendMessage("VillageDefense: Start location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
        } else if (args[2].equalsIgnoreCase("Endlocation") || args[2].equalsIgnoreCase("Endloc")) {
            String location = player.getLocation().getWorld().getName() + "," + player.getLocation().getX() + "," + player.getLocation().getY() + "," + player.getLocation().getZ() + "," + player.getLocation().getYaw() + "," + player.getLocation().getPitch();
            config.set("instances." + args[0] + ".Endlocation", location);
            player.sendMessage("VillageDefense: End location for arena/instance " + args[0] + " set to " + Util.locationToString(player.getLocation()));
        } else {
            player.sendMessage(ChatColor.RED + "Invalid Command!");
            player.sendMessage(ChatColor.RED + "Usage: /vd <ARENA > set <StartLOCTION | LOBBYLOCATION | EndLOCATION>");
        }
    } else if (args.length == 4) {
        if (args[2].equalsIgnoreCase("MAXPLAYERS") || args[2].equalsIgnoreCase("maximumplayers")) {
            config.set("instances." + args[0] + ".maximumplayers", Integer.parseInt(args[3]));
            player.sendMessage("VillageDefense: Maximum players for arena/instance " + args[0] + " set to " + Integer.parseInt(args[3]));
        } else if (args[2].equalsIgnoreCase("MINPLAYERS") || args[2].equalsIgnoreCase("minimumplayers")) {
            config.set("instances." + args[0] + ".minimumplayers", Integer.parseInt(args[3]));
            player.sendMessage("VillageDefense: Minimum players for arena/instance " + args[0] + " set to " + Integer.parseInt(args[3]));
        } else if (args[2].equalsIgnoreCase("MAPNAME") || args[2].equalsIgnoreCase("NAME")) {
            config.set("instances." + args[0] + ".mapname", args[3]);
            player.sendMessage("VillageDefense: Map name for arena/instance " + args[0] + " set to " + args[3]);
        } else if (args[2].equalsIgnoreCase("WORLD") || args[2].equalsIgnoreCase("MAP")) {
            boolean exists = false;
            for (World world : Bukkit.getWorlds()) {
                if (world.getName().equalsIgnoreCase(args[3]))
                    exists = true;
            }
            if (!exists) {
                player.sendMessage(ChatManager.PLUGIN_PREFIX + ChatColor.RED + "That world doesn't exists!");
                return;
            }
            config.set("instances." + args[0] + ".world", args[3]);
            player.sendMessage("VillageDefense: World for arena/instance " + args[0] + " set to " + args[3]);
        } else {
            player.sendMessage(ChatColor.RED + "Invalid Command!");
            player.sendMessage(ChatColor.RED + "Usage: /vd set <MINPLAYERS | MAXPLAYERS> <value>");
        }
    }
    ConfigurationManager.saveConfig(config, "arenas");
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) Selection(com.sk89q.worldedit.bukkit.selections.Selection) World(org.bukkit.World) SetupInventory(pl.plajer.villagedefense3.utils.SetupInventory) Vector(com.sk89q.worldedit.Vector) Location(org.bukkit.Location)

Aggregations

FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 SetupInventory (pl.plajer.villagedefense3.utils.SetupInventory)2 Vector (com.sk89q.worldedit.Vector)1 CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)1 Selection (com.sk89q.worldedit.bukkit.selections.Selection)1 ArrayList (java.util.ArrayList)1 Location (org.bukkit.Location)1 World (org.bukkit.World)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 Arena (pl.plajer.villagedefense3.arena.Arena)1 ArenaInitializer1_11_R1 (pl.plajer.villagedefense3.arena.ArenaInitializer1_11_R1)1 ArenaInitializer1_12_R1 (pl.plajer.villagedefense3.arena.ArenaInitializer1_12_R1)1 ArenaInitializer1_8_R3 (pl.plajer.villagedefense3.arena.ArenaInitializer1_8_R3)1 ArenaInitializer1_9_R1 (pl.plajer.villagedefense3.arena.ArenaInitializer1_9_R1)1