diff --git a/.gitignore b/.gitignore index fba4f52..79ecb72 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ hs_err_pid* *.classpath bin /.classpath +.idea diff --git a/.project b/.project deleted file mode 100644 index 3a3127b..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - HungerArena_Jeppa - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..99e9f42 --- /dev/null +++ b/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + groupId + HungerArena_Jeppa + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + vault-repo + http://nexus.hc.to/content/repositories/pub_releases + + + engine-hub-repo + https://maven.enginehub.org/repo/ + + + + + + org.spigotmc + spigot-api + 1.19-R0.1-SNAPSHOT + provided + + + net.milkbowl.vault + VaultAPI + 1.7 + provided + + + com.sk89q.worldedit + worldedit-bukkit + 7.2.7 + provided + + + + \ No newline at end of file diff --git a/src/Data.yml b/src/Data.yml deleted file mode 100644 index 8f72185..0000000 --- a/src/Data.yml +++ /dev/null @@ -1,3 +0,0 @@ -# Stores all blocks to reset! -Blocks_Destroyed: [] -Blocks_Placed: [] \ No newline at end of file diff --git a/src/main/java/me/Travja/HungerArena/Chests.java b/src/main/java/me/Travja/HungerArena/Chests.java new file mode 100644 index 0000000..78ca833 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Chests.java @@ -0,0 +1,81 @@ +package me.Travja.HungerArena; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; + +public class Chests implements Listener { + public Main plugin; + + public Chests(Main m) { + this.plugin = m; + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void ChestBreak(BlockBreakEvent event) { + Player p = event.getPlayer(); + Block block = event.getBlock(); + if (p.hasPermission("HungerArena.Chest.Break")) { + Location blocklocation = block.getLocation(); + int blockx = blocklocation.getBlockX(); + int blocky = blocklocation.getBlockY(); + int blockz = blocklocation.getBlockZ(); + if (plugin.getChests().getConfigurationSection("Storage").getKeys(false).contains(blockx + "," + blocky + "," + blockz)) { + if (p.hasPermission("HungerArena.Chest.Break") && plugin.getArena(p) == null) { + plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz, null); + plugin.saveChests(); + p.sendMessage("[HungerArena] Chest Removed!"); + } else { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "[HungerArena] That's a storage! You don't have permission to break it!"); + } + } + } + } + + @EventHandler + public void ChestSaves(PlayerInteractEvent event) { + Block block = event.getClickedBlock(); + Player p = event.getPlayer(); + if (plugin.getArena(p) != null) { + int a = plugin.getArena(p); + if (plugin.Playing.get(a).contains(p.getName()) && plugin.canjoin.get(a)) { + if (!plugin.restricted || (plugin.restricted && plugin.worldsNames.values().contains(p.getWorld().getName()))) { + if (block != null) { + if (block.getState() instanceof InventoryHolder) { + ItemStack[] itemsinchest = ((InventoryHolder) block.getState()).getInventory().getContents().clone(); + int blockx = block.getX(); + int blocky = block.getY(); + int blockz = block.getZ(); + String blockw = block.getWorld().getName().toString(); + if (!plugin.getChests().contains("Storage." + blockx + "," + blocky + "," + blockz)) { + plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X", blockx); + plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky); + plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z", blockz); + plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw); + plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest); + plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Arena", a); + plugin.saveChests(); + p.sendMessage(ChatColor.GREEN + "Thank you for finding this undiscovered item Storage, it has been stored!!"); + if (plugin.config.getBoolean("ChestPay.enabled")) { + for (ItemStack Rewards : plugin.ChestPay) { + p.getInventory().addItem(Rewards); + } + } + } + plugin.reloadChests(); + } + } + } + } + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/CommandBlock.java b/src/main/java/me/Travja/HungerArena/CommandBlock.java new file mode 100644 index 0000000..c7d4f60 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/CommandBlock.java @@ -0,0 +1,107 @@ +package me.Travja.HungerArena; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class CommandBlock implements Listener { + public Main plugin; + + public CommandBlock(Main m) { + this.plugin = m; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void CatchCommand(PlayerCommandPreprocessEvent event) { + String cmd = event.getMessage(); + Player p = event.getPlayer(); + String pname = p.getName(); + for (int x : plugin.Watching.keySet()) { + if (plugin.Watching.get(x).contains(p.getName())) { + if (handleIngameCommands(p, cmd) == true) { + event.setCancelled(true); + } + } + } + if (plugin.getArena(p) != null) { + if (handleIngameCommands(p, cmd) == true) { + event.setCancelled(true); + } + } else if (cmd.toLowerCase().trim().equals("/back")) { + for (int u : plugin.Dead.keySet()) { + if (plugin.Dead.get(u).contains(pname) && plugin.canjoin.get(u)) { + plugin.Tele.add(p); + } + } + } + if (cmd.startsWith("/tp") || cmd.startsWith("/telep") || cmd.contains(":tp") || cmd.contains(":telep")) { + String[] args = cmd.split(" "); + Player player1 = null; + Player player2 = null; + if (args.length >= 2) { + if (Bukkit.getPlayer(args[1]) != null) { + player1 = Bukkit.getPlayer(args[1]); + if (args.length >= 3 && Bukkit.getPlayer(args[2]) != null) { + player2 = Bukkit.getPlayer(args[2]); + } + if (plugin.isSpectating(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "Invalid command for spectating, using /ha tp " + (player2 != null ? player2 : player1)); + p.performCommand("/ha tp " + (player2 != null ? player2 : player1)); + } else if (plugin.getArena(player1) != null || (args.length == 2 && plugin.getArena(p) != null) || (args.length >= 3 && plugin.getArena(player2) != null)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You can't teleport to other tributes!"); + } + } + } + } + } + + private boolean handleIngameCommands(Player p, String cmd) { + if (!p.hasPermission("HungerArena.UseCommands")) { + if (!plugin.management.getStringList("commands.whitelist").isEmpty()) { + for (String whitelist : plugin.management.getStringList("commands.whitelist")) { + if (cmd.toLowerCase().startsWith(whitelist.toLowerCase())) { + return false; + } + } + } + if (!cmd.toLowerCase().startsWith("/ha")) { + p.sendMessage(ChatColor.RED + "You are only allowed to perform the following commands:"); + for (String whitelistfull : plugin.management.getStringList("commands.whitelist")) { + p.sendMessage(ChatColor.AQUA + whitelistfull); + } + p.sendMessage(ChatColor.AQUA + "/ha"); + p.sendMessage(ChatColor.AQUA + "/ha close"); + p.sendMessage(ChatColor.AQUA + "/ha help"); + p.sendMessage(ChatColor.AQUA + "/ha join"); + p.sendMessage(ChatColor.AQUA + "/ha kick [Player]"); + p.sendMessage(ChatColor.AQUA + "/ha leave"); + p.sendMessage(ChatColor.AQUA + "/ha list"); + p.sendMessage(ChatColor.AQUA + "/ha open"); + p.sendMessage(ChatColor.AQUA + "/ha ready"); + p.sendMessage(ChatColor.AQUA + "/ha refill"); + p.sendMessage(ChatColor.AQUA + "/ha reload"); + p.sendMessage(ChatColor.AQUA + "/ha restart"); + p.sendMessage(ChatColor.AQUA + "/ha rlist"); + //p.sendMessage(ChatColor.AQUA + "/ha newarena"); //not during game... + p.sendMessage(ChatColor.AQUA + "/ha setspawn"); + p.sendMessage(ChatColor.AQUA + "/ha start"); + p.sendMessage(ChatColor.AQUA + "/ha tp"); + p.sendMessage(ChatColor.AQUA + "/ha watch"); + p.sendMessage(ChatColor.AQUA + "/ha warpall"); + return true; + } + } else if (!cmd.toLowerCase().startsWith("/ha")) { + if (cmd.toLowerCase().startsWith("/spawn") || cmd.toLowerCase().startsWith("/back")) { + p.sendMessage("You have perms for all commands except this one!"); + return true; + } + } + return false; + } +} diff --git a/src/main/java/me/Travja/HungerArena/HaCommands.java b/src/main/java/me/Travja/HungerArena/HaCommands.java new file mode 100644 index 0000000..5bc9696 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/HaCommands.java @@ -0,0 +1,1222 @@ +package me.Travja.HungerArena; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.BukkitPlayer; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.session.SessionManager; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.attribute.Attribute; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Damageable; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; + +public class HaCommands implements CommandExecutor { + public Main plugin; + + public HaCommands(Main m) { + this.plugin = m; + } + + int i = 0; + int a = 1; + boolean NoPlayerSpawns = true; + + private void clearInv(Player p) { + p.getInventory().clear(); + p.getInventory().setBoots(null); + p.getInventory().setChestplate(null); + p.getInventory().setHelmet(null); + p.getInventory().setLeggings(null); + p.updateInventory(); + } + + private Location getArenaSpawn() { + String[] Spawncoords; + if (plugin.spawns.getString("Spawn_coords." + a) != null) { + Spawncoords = plugin.spawns.getString("Spawn_coords." + a).split(","); + } else { + Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); + } + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + String spawnworld = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(spawnworld); + Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + return Spawn; + } + + @Override + public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, String[] args) { + + boolean console = false; + boolean playr = false; + if (sender instanceof ConsoleCommandSender) { + console = true; + } else if (sender instanceof Player) { + playr = true; + } + + if (playr) { + final Player p = (Player) sender; + final String pname = p.getName(); + String ThisWorld = p.getWorld().getName(); + for (int i : plugin.worldsNames.keySet()) { + if (plugin.worldsNames.get(i) != null) { + if (plugin.worldsNames.get(i).equals(ThisWorld)) { + a = i; + NoPlayerSpawns = false; + } + } + } + + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + NoPlayerSpawns = false; + } + if (cmd.getName().equalsIgnoreCase("Ha")) { + if (args.length == 0) { + sender.sendMessage(ChatColor.GREEN + "[HungerArena] by " + ChatColor.AQUA + "travja! Version: " + plugin.getDescription().getVersion()); + sender.sendMessage(ChatColor.GREEN + "[HungerArena] Update by " + ChatColor.AQUA + "Jeppa ! "); + return false; + } else if (args[0].equalsIgnoreCase("NewArena")) { + if (p.hasPermission("HungerArena.StartPoint")) { + if (args.length < 2) { + p.sendMessage(ChatColor.AQUA + "You have to enter the arena number as 2nd argument"); + } else { + try { + a = Integer.parseInt(args[1]); + } catch (Exception e) { + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return false; + } + if (plugin.worldsNames.values().contains(ThisWorld)) { + p.sendMessage(ChatColor.RED + "This world already has an areana! \n (only one arena per world possible, yet!)"); + return false; + } + ((Player) sender).performCommand("startpoint " + a); + } + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } else if (args[0].equalsIgnoreCase("SetSpawn")) { + if (p.hasPermission("HungerArena.SetSpawn")) { + if ((NoPlayerSpawns) && (args.length < 2)) { + p.sendMessage(ChatColor.AQUA + "You have to set the playerspawns first! Use /ha newarena \nOr enter the arena number as 2nd argument, \n0 is default/fallback!"); + } else { + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + if (plugin.spawns.getString("Spawn_coords.0") == null) { + plugin.spawns.set("Spawn_coords.0", x + "," + y + "," + z + "," + ThisWorld); + plugin.spawns.set("Spawns_set.0", "true"); + } + if (args.length >= 2) { + try { + a = Integer.parseInt(args[1]); + } catch (Exception e) { + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return false; + } + } + plugin.spawns.set("Spawn_coords." + a, x + "," + y + "," + z + "," + ThisWorld); + plugin.spawns.set("Spawns_set." + a, "true"); + plugin.saveSpawns(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn for dead tributes!"); + } + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } else if (args[0].equalsIgnoreCase("SetTorch")) { + if (p.hasPermission("HungerArena.SetSpawn")) { + if (args.length < 2) { + p.sendMessage(ChatColor.AQUA + "You have to enter the arena number as 2nd argument"); + } else { + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + if (args.length >= 2) { + try { + a = Integer.parseInt(args[1]); + } catch (Exception e) { + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return true; + } + } + plugin.spawns.set("Start_torch." + a, x + "," + y + "," + z + "," + ThisWorld); + plugin.saveSpawns(); + p.sendMessage(ChatColor.AQUA + "You have set the start redstone torch for arena " + a + "!"); + } + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + + } else if (args[0].equalsIgnoreCase("Help")) { + help_sub(sender, playr, console); + + } else if (plugin.restricted && !plugin.worldsNames.values().contains(ThisWorld)) { + p.sendMessage(ChatColor.RED + "That can't be run in this world!"); + } else if (!plugin.restricted || plugin.restricted && plugin.worldsNames.values().contains(ThisWorld)) { + //////////////////////////////////////// LISTING /////////////////////////////////////////////// + if (args[0].equalsIgnoreCase("List")) { + if (p.hasPermission("HungerArena.GameMaker") || plugin.Watching.get(a).contains(pname) || p.hasPermission("HungerArena.List")) { + list_sub(p, sender, playr, console, args); + + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } else if (args[0].equalsIgnoreCase("rList")) { + if (p.hasPermission("HungerArena.GameMaker")) { + rList_sub(sender, args); + + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + //////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// JOINING/LEAVING ////////////////////////////////////////// + } else if (args[0].equalsIgnoreCase("Join")) { + if (p.hasPermission("HungerArena.Join")) { + boolean needconfirm = false; + for (int i : plugin.NeedConfirm.keySet()) { + if (plugin.NeedConfirm.get(i).contains(pname)) { + needconfirm = true; + p.sendMessage(ChatColor.GOLD + "You need to run /ha confirm"); + } + } + if (!needconfirm) { + if ((args.length >= 2) && checkarena(args[1], sender)) { + a = Integer.parseInt(args[1]); + } else { + if (NoPlayerSpawns) { + for (int i : plugin.Playing.keySet()) { + if (plugin.Playing.get(i).size() < plugin.maxPlayers.get(i)) { + a = i; + p.sendMessage(ChatColor.RED + "Found free slots in Arena " + a + " !"); + } else if (i == plugin.Playing.size()) { + p.sendMessage(ChatColor.RED + "No free slots found / All games are full!"); + } + } + } + + } + if ((plugin.Playing.get(a) != null) && (plugin.location.get(a).size() != 0)) { + ; + if (plugin.Playing.get(a).contains(pname)) { + p.sendMessage(ChatColor.RED + "You are already playing!"); + } else if (plugin.Dead.get(a).contains(pname) || plugin.Quit.get(a).contains(pname)) { + p.sendMessage(ChatColor.RED + "You DIED/QUIT! You can't join again!"); + } else if (plugin.Playing.get(a).size() == plugin.maxPlayers.get(a)) { + p.sendMessage(ChatColor.RED + "There are already " + plugin.maxPlayers.get(a) + " Tributes in that Arena!"); + } else if (plugin.canjoin.get(a) == true) { + p.sendMessage(ChatColor.RED + "That game is in progress!"); + } else if (!plugin.open.get(a)) { + p.sendMessage(ChatColor.RED + "That game is closed!"); + } else if ((plugin.spawns.getString("Spawns_set." + a) == null) || (plugin.spawns.getString("Spawns_set." + a).equalsIgnoreCase("false"))) { + p.sendMessage(ChatColor.RED + "/ha setspawn for Arena " + a + " hasn't been run!"); + } else if (plugin.getArena(p) != null) { + p.sendMessage(ChatColor.RED + "You are already in an arena!"); + } else if (plugin.config.getString("Need_Confirm").equalsIgnoreCase("true")) { + if (plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")) { + if (!(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost"))) { + i = 0; + for (ItemStack fee : plugin.Fee) { + int total = plugin.Fee.size(); + if (p.getInventory().containsAtLeast(fee, fee.getAmount())) { + i = i + 1; + if (total == i) { + plugin.NeedConfirm.get(a).add(pname); + p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); + } + } + } + if (plugin.Fee.size() > i) { + p.sendMessage(ChatColor.RED + "You are missing some items and can't join the games..."); + } + } else { + p.sendMessage(ChatColor.RED + "You don't have enough money to join!"); + } + } else if (plugin.config.getBoolean("EntryFee.enabled") && !plugin.config.getBoolean("EntryFee.eco")) { + i = 0; + for (ItemStack fee : plugin.Fee) { + int total = plugin.Fee.size(); + if (p.getInventory().containsAtLeast(fee, fee.getAmount())) { + i = i + 1; + if (total == i) { + plugin.NeedConfirm.get(a).add(pname); + p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); + } + } + } + if (plugin.Fee.size() > i) { + p.sendMessage(ChatColor.RED + "You are missing some items and can't join the games..."); + } + } else if (!plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")) { + if (!(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost"))) { + plugin.NeedConfirm.get(a).add(pname); + p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); + } else { + p.sendMessage(ChatColor.RED + "You don't have enough money to join!"); + } + } else { + plugin.NeedConfirm.get(a).add(pname); + p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); + } + } else if (plugin.config.getString("Need_Confirm").equalsIgnoreCase("false")) { + confirmSub(p, pname, ThisWorld); + } + + } else { + p.sendMessage(ChatColor.RED + "That arena doesn't exist!"); + } + } + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + //////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////// CONFIRMATION /////////////////////////////////////////////// + } else if (args[0].equalsIgnoreCase("Confirm")) { + for (int v : plugin.NeedConfirm.keySet()) { + if (plugin.NeedConfirm.get(v).contains(pname)) { + a = v; + confirmSub(p, pname, ThisWorld); + } else if ((v == plugin.NeedConfirm.size()) && (plugin.config.getString("Need_Confirm").equalsIgnoreCase("true"))) { + p.sendMessage(ChatColor.RED + "You haven't joined any games!"); + } + } + } else if (args[0].equalsIgnoreCase("Ready")) { + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + if (plugin.Playing.get(a).contains(pname)) { + if (plugin.Ready.get(a).contains(pname)) { + p.sendMessage(ChatColor.RED + "You're already ready!"); + } else if (plugin.Playing.get(a).size() == 1) { + p.sendMessage(ChatColor.RED + "You can't be ready when no one else is playing!"); + } else { + plugin.Ready.get(a).add(pname); + if (plugin.config.getBoolean("broadcastAll")) { + plugin.getServer().broadcastMessage(ChatColor.AQUA + "[HungerArena] Game " + a + ": " + ChatColor.GRAY + String.valueOf(plugin.Ready.get(a).size()) + "/" + plugin.maxPlayers.get(a) + " Players ready!"); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(ChatColor.GRAY + String.valueOf(plugin.Ready.get(a).size()) + "/" + plugin.maxPlayers.get(a) + " Players ready!"); + } + } + p.sendMessage(ChatColor.AQUA + "You have marked yourself as READY!"); + if (plugin.config.getBoolean("Auto_Warp")) { + if (((double) plugin.Playing.get(a).size()) % 60 <= plugin.Ready.get(a).size() || plugin.Playing.get(a).size() == plugin.Ready.get(a).size()) { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha warpall " + a); + } + } + } + } + } else { + p.sendMessage(ChatColor.RED + "You aren't playing in any games!"); + } + } else if (args[0].equalsIgnoreCase("Leave")) { + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + if (plugin.canjoin.get(a) == true) { + clearInv(p); + p.teleport(getArenaSpawn()); + if (plugin.Frozen.get(a).contains(pname)) { + plugin.Frozen.get(a).remove(pname); + } + + if (plugin.Playing.get(a).size() != 1) { + plugin.RestoreInv(p, pname); + } + + plugin.winner(a); + } else { + clearInv(p); + p.teleport(getArenaSpawn()); + + plugin.RestoreInv(p, pname); + + if (plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")) { + plugin.econ.depositPlayer(p, plugin.config.getDouble("EntryFee.cost")); + p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + "$" + plugin.config.getDouble("EntryFee.cost") + " has been added to your account!"); + for (ItemStack fees : plugin.Fee) { + p.getInventory().addItem(fees); + p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees.getType().toString().toLowerCase().replace("_", " ") + " was refunded because you left the games."); + } + } else if (plugin.config.getBoolean("EntryFee.enabled") && !plugin.config.getBoolean("EntryFee.eco")) { + for (ItemStack fees : plugin.Fee) { + p.getInventory().addItem(fees); + p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees.getType().toString().toLowerCase().replace("_", " ") + " was refunded because you left the games."); + } + } else if (!plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")) { + plugin.econ.depositPlayer(p, plugin.config.getDouble("EntryFee.cost")); + p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + "$" + plugin.config.getDouble("EntryFee.cost") + " has added to your account!"); + } + } + } else { + p.sendMessage(ChatColor.RED + "You aren't in any games!"); + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////// SPECTATOR RELATED ////////////////////////////////// + } else if (args[0].equalsIgnoreCase("Watch")) { + if (sender.hasPermission("HungerArena.Watch")) { + if (args.length >= 2) { + if (checkarena(args[1], sender)) { + a = Integer.parseInt(args[1]); + if (!plugin.Watching.get(a).contains(pname) && plugin.getArena(p) == null && plugin.canjoin.get(a) == true) { + plugin.Watching.get(a).add(pname); + p.teleport(Bukkit.getPlayer(plugin.Playing.get(a).get(0))); + for (Player online : plugin.getServer().getOnlinePlayers()) { + online.hidePlayer(plugin, p); + } + p.setAllowFlight(true); + p.sendMessage(ChatColor.AQUA + "You can now spectate!"); + Scoreboard scoreboard = plugin.getServer().getScoreboardManager().getNewScoreboard(); + Objective sobj; + try { + sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting"); + } catch (NoSuchMethodError e) { + sobj = scoreboard.registerNewObjective("HA", "HAData"); + sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); + } + Score sdeaths = sobj.getScore((ChatColor.RED + "Spectators")); + sdeaths.setScore(0); + Score splayers = sobj.getScore((ChatColor.RED + "Players")); + splayers.setScore(0); + sobj.setDisplaySlot(DisplaySlot.SIDEBAR); + p.setScoreboard(scoreboard); + plugin.scoreboards.put(p.getName(), p.getScoreboard()); + } else if (plugin.canjoin.get(a) == false) { + p.sendMessage(ChatColor.RED + "That game isn't in progress!"); + } else if (plugin.Playing.get(a).contains(pname)) { + p.sendMessage(ChatColor.RED + "You can't watch while you're playing!"); + } else if (plugin.Watching.get(a).contains(pname)) { + plugin.Watching.get(a).remove(pname); + for (Player online : plugin.getServer().getOnlinePlayers()) { + online.showPlayer(plugin, p); + } + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + plugin.scoreboards.remove(p.getName()); + p.teleport(getArenaSpawn()); + p.setAllowFlight(false); + p.sendMessage(ChatColor.AQUA + "You are not spectating any more"); + } + } + } else { + p.sendMessage(ChatColor.RED + "Too few arguments!"); + } + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } else if (args[0].equalsIgnoreCase("tp")) { + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i).contains(pname)) { + if (plugin.getArena(Bukkit.getServer().getPlayer(args[1])) != null) { + Player target = Bukkit.getServer().getPlayer(args[1]); + p.teleport(target); + p.sendMessage(ChatColor.AQUA + "You've been teleported to " + target.getName()); + return true; + } else { + p.sendMessage(ChatColor.RED + "That person isn't in game!"); + return true; + } + } else { + if (i == plugin.Watching.size()) { + p.sendMessage(ChatColor.RED + "You have to be spectating first!"); + return true; + } + } + } + ///////////////////////////////////////////////////////////////////////////////// + } else if (args[0].equalsIgnoreCase("addArena")) { + if (plugin.hookWE() != null) { + if (args.length != 2) { + return false; + } + if (p.hasPermission("HungerArena.AddArena")) { + SessionManager manager = WorldEdit.getInstance().getSessionManager(); + BukkitPlayer actor = BukkitAdapter.adapt(p); + LocalSession localSession = manager.get(actor); + Region region; + com.sk89q.worldedit.world.World selectionWorld = localSession.getSelectionWorld(); + try { + if (selectionWorld == null) { + throw new IncompleteRegionException(); + } + region = localSession.getSelection(selectionWorld); + + + Location min = BukkitAdapter.adapt(p.getWorld(), region.getMinimumPoint()); + Location max = BukkitAdapter.adapt(p.getWorld(), region.getMaximumPoint()); + plugin.spawns.set("Arenas." + args[1] + ".Max", max.getWorld().getName() + "," + max.getX() + "," + + max.getY() + "," + max.getZ()); + plugin.spawns.set("Arenas." + args[1] + ".Min", min.getWorld().getName() + "," + min.getX() + "," + + min.getY() + "," + min.getZ()); + plugin.saveConfig(); + p.sendMessage(ChatColor.GREEN + "Arena " + ChatColor.DARK_AQUA + args[1] + + ChatColor.GREEN + " created with WorldEdit!"); + return true; + } catch (IncompleteRegionException ex) { + p.sendMessage(ChatColor.DARK_RED + "You must make a WorldEdit selection first!"); + return false; + } + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + } else { + p.sendMessage(ChatColor.RED + "You don't have WorldEdit enabled for HungerArena!"); + return true; + } + } else if (args[0].equalsIgnoreCase("Kick")) { + return kick_sub(sender, args, playr, console, getArenaSpawn()); + + } else if (args[0].equalsIgnoreCase("Refill")) { + if (p.hasPermission("HungerArena.Refill")) { + ReFill_sub(sender, args); + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + } else if (args[0].equalsIgnoreCase("Restart")) { + if (p.hasPermission("HungerArena.Restart")) { + Restart_Close_sub(sender, args, playr, false); + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + /////////////////////////////////// Toggle ////////////////////////////////////////////////// + } else if (args[0].equalsIgnoreCase("close")) { + if (p.hasPermission("HungerArena.toggle")) { + Restart_Close_sub(sender, args, playr, true); + } else { + p.sendMessage(ChatColor.RED + "No Perms!"); + } + } else if (args[0].equalsIgnoreCase("open")) { + if (p.hasPermission("HungerArena.toggle")) { + open_sub(sender, args); + } else { + p.sendMessage(ChatColor.RED + "No Perms!"); + } + //////////////////////////////////////////////////////////////////////////////////////////// + } else if (args[0].equalsIgnoreCase("Reload")) { + if (p.hasPermission("HungerArena.Reload")) { + reload_sub(sender); + } else { + p.sendMessage(ChatColor.RED + "You don't have permission"); + } + } else if (args[0].equalsIgnoreCase("WarpAll")) { + if (p.hasPermission("HungerArena.Warpall")) { + warpall_sub(sender, args); + } else { + p.sendMessage(ChatColor.RED + "You don't have permission"); + } + } else if (args[0].equalsIgnoreCase("Start")) { + if (p.hasPermission("HungerArena.Start")) { + start_sub(sender, args); + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } else { + p.sendMessage(ChatColor.RED + "Unknown command, type /ha help for a list of commands"); + } + } + } + +// Console /////////////////////////////////// + } else if (sender instanceof ConsoleCommandSender) { + if (cmd.getName().equalsIgnoreCase("Ha")) { + if (args.length == 0) { + sender.sendMessage(ChatColor.GREEN + "[HungerArena] by " + ChatColor.AQUA + "travja! Version: " + plugin.getDescription().getVersion()); + sender.sendMessage(ChatColor.GREEN + "[HungerArena] Update by " + ChatColor.AQUA + "Jeppa ! "); + return false; + } + if (args[0].equalsIgnoreCase("Help")) { + help_sub(sender, playr, console); + return false; + } else if (args[0].equalsIgnoreCase("List")) { + list_sub(null, sender, playr, console, args); + + } else if (args[0].equalsIgnoreCase("rList")) { + rList_sub(sender, args); + + } else if (args[0].equalsIgnoreCase("SetSpawn") || args[0].equalsIgnoreCase("Join") || args[0].equalsIgnoreCase("Confirm") || args[0].equalsIgnoreCase("Ready") || args[0].equalsIgnoreCase("Leave") || args[0].equalsIgnoreCase("Watch") || args[0].equalsIgnoreCase("NewArena")) { + sender.sendMessage(ChatColor.RED + "That can only be run by a player!"); + } else if (args[0].equalsIgnoreCase("Kick")) { + return kick_sub(sender, args, playr, console, getArenaSpawn()); + + } else if (args[0].equalsIgnoreCase("Refill")) { + ReFill_sub(sender, args); + + } else if (args[0].equalsIgnoreCase("Restart")) { + Restart_Close_sub(sender, args, playr, false); + + /////////////////////////////////// Toggle ////////////////////////////////////////////////// + } else if (args[0].equalsIgnoreCase("close")) { + Restart_Close_sub(sender, args, playr, true); + + } else if (args[0].equalsIgnoreCase("open")) { + open_sub(sender, args); + + //////////////////////////////////////////////////////////////////////////////////////////// + } else if (args[0].equalsIgnoreCase("Reload")) { + reload_sub(sender); + + } else if (args[0].equalsIgnoreCase("WarpAll")) { + warpall_sub(sender, args); + + } else if (args[0].equalsIgnoreCase("Start")) { + start_sub(sender, args); + + } else { + sender.sendMessage(ChatColor.RED + "Unknown command, type /ha help to see all commands!"); + } + } + } + return false; + } + + ///////////////////////////// Subroutines ////////////////////////////////// + + private void help_sub(CommandSender sender, boolean playr, boolean console) { + ChatColor c = ChatColor.AQUA; + sender.sendMessage(ChatColor.GREEN + "----HungerArena Help----"); + sender.sendMessage(c + "/ha - Displays author message!"); + sender.sendMessage(c + "/sponsor [Player] [ItemID] [Amount] - Lets you sponsor someone!"); + sender.sendMessage(c + "/startpoint [1,2,3,4,etc] [1,2,3,4,etc] - Sets the starting points of tributes in a specific arena!"); + sender.sendMessage(c + "/ha newarena [1,2,3,4,etc] - Add a new arena to the server and start setting up the starting points of tributes!\n Use the spawnsTool for setting up all starting points!"); + if (playr && plugin.hookWE() != null) { + sender.sendMessage(c + "/ha addArena [1,2,3,4,etc] - Creates an arena using your current WorldEdit selection."); + } + sender.sendMessage(c + "/ha close (1,2,3,4,etc) - Prevents anyone from joining that arena! Numbers are optional"); + sender.sendMessage(c + "/ha help - Displays this screen!"); + sender.sendMessage(c + "/ha join [1,2,3,4,etc] - Makes you join the game!"); + sender.sendMessage(c + "/ha kick [Player] - Kicks a player from the arena!"); + sender.sendMessage(c + "/ha leave - Makes you leave the game!"); + sender.sendMessage(c + "/ha list (1,2,3,4,etc) - Shows a list of players in the game and their health! Numbers are optional."); + sender.sendMessage(c + "/ha open (1,2,3,4,etc) - Opens the game allowing people to join! Numbers are optional"); + sender.sendMessage(c + "/ha ready - Votes for the game to start!"); + sender.sendMessage(c + "/ha refill (1,2,3,4,etc) - Refills all chests! Numbers are optional"); + sender.sendMessage(c + "/ha reload - Reloads the config!"); + sender.sendMessage(c + "/ha restart (1,2,3,4,etc) - Restarts the game! Numbers are optional"); + sender.sendMessage(c + "/ha rlist (1,2,3,4,etc) - See who's ready! Numbers are optional"); + sender.sendMessage(c + "/ha setspawn - Sets the spawn for dead tributes! You can add the arena # to this command: /setspawn [1,2,3,4,etc.]"); + sender.sendMessage(c + "/ha settorch - Sets the location for a redstone torch in an arena that will be placed at match start!"); + sender.sendMessage(c + "/ha tp [player] - Teleports you to a tribute!"); + sender.sendMessage(c + "/ha start [1,2,3,4,etc] - Unfreezes tributes allowing them to fight!"); + sender.sendMessage(c + "/ha watch [1,2,3,4,etc] - Lets you watch the tributes!"); + sender.sendMessage(c + "/ha warpall [1,2,3,4,etc] - Warps all tribute into position!"); + sender.sendMessage(ChatColor.GREEN + "----------------------"); + } + + private void list_sub(Player p, CommandSender sender, boolean playr, boolean console, String[] args) { + if (args.length >= 2) { + if (checkarena(args[1], sender)) { + a = Integer.parseInt(args[1]); + list_subsub(p, sender, console); + } + } else { + if (console || (p != null && plugin.getArena(p) == null)) { + a = 1; + list_subsub(p, sender, console); + } else { + a = plugin.getArena(p); + list_subsub(p, sender, console); + } + } + } + + private void list_subsub(Player p, CommandSender sender, boolean console) { + sender.sendMessage(ChatColor.AQUA + "----- Arena " + a + " -----"); + if (!plugin.Playing.get(a).isEmpty() && plugin.Playing.containsKey(a)) { + for (String playernames : plugin.Playing.get(a)) { + Player players = plugin.getServer().getPlayerExact(playernames); + if (console || (p != null && p.hasPermission("HungerArena.GameMaker"))) { + double maxh; + try { + maxh = players.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + } catch (Exception e) { + maxh = ((Damageable) players).getMaxHealth(); + } + sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + ((Damageable) players).getHealth() + "/" + maxh); + } else if (console || (p != null && p.hasPermission("HungerArena.List"))) { + sender.sendMessage(ChatColor.GREEN + playernames); + } + } + } else { + sender.sendMessage(ChatColor.GRAY + "No one is playing!"); + } + sender.sendMessage(ChatColor.AQUA + "-------------------"); + } + + private void rList_sub(CommandSender sender, String[] args) { + if (args.length >= 2) { + if (checkarena(args[1], sender)) { + a = Integer.parseInt(args[1]); + sender.sendMessage(ChatColor.AQUA + "----- Arena " + a + " -----"); + if (!plugin.Ready.get(a).isEmpty() && plugin.Ready.containsKey(a)) { + for (String playernames : plugin.Ready.get(a)) { + sender.sendMessage(ChatColor.GREEN + playernames); + } + } else { + sender.sendMessage(ChatColor.GRAY + "No one is ready!"); + } + sender.sendMessage(ChatColor.AQUA + "-------------------"); + } + } else { + sender.sendMessage(ChatColor.AQUA + "----- Arena 1 -----"); + if (!plugin.Ready.get(1).isEmpty() && plugin.Ready.containsKey(1)) { + for (String playernames : plugin.Ready.get(1)) { + sender.sendMessage(ChatColor.GREEN + playernames); + } + } else { + sender.sendMessage(ChatColor.GRAY + "No one is ready!"); + } + sender.sendMessage(ChatColor.AQUA + "-------------------"); + } + } + + private boolean kick_sub(CommandSender sender, String[] args, boolean playr, boolean console, Location Spawn) { + if (args.length != 2) { + sender.sendMessage(ChatColor.RED + "/ha kick [playername]!"); + return false; + } + Player target = Bukkit.getServer().getPlayer(args[1]); + if (target == null) { + sender.sendMessage(ChatColor.RED + "Use playername !"); + return false; + } + if (console || (playr && ((Player) sender).hasPermission("HungerArena.Kick"))) { + if (plugin.getArena(target) != null) { + a = plugin.getArena(target); + plugin.Playing.get(a).remove(target.getName()); + if (!plugin.config.getBoolean("broadcastAll")) { + plugin.getServer().broadcastMessage(ChatColor.RED + target.getName() + " was kicked from arena " + a + "!"); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(ChatColor.RED + target.getName() + " was kicked from the game!"); + } + } + clearInv(target); + target.teleport(Spawn); + plugin.Quit.get(a).add(target.getName()); + plugin.RestoreInv(target, target.getName()); + plugin.winner(a); + return true; + } else { + sender.sendMessage(ChatColor.RED + "That player isn't in the game!"); + return true; + } + } else { + sender.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + } + + private void ReFill_sub(CommandSender sender, String[] args) { + plugin.reloadChests(); + int arena = 0; + if (args.length >= 2) { + if (checkarena(args[1], sender)) { + arena = Integer.parseInt(args[1]); + } + } + + Set StorList = plugin.getChests().getConfigurationSection("Storage").getKeys(false); + for (String xyz2 : StorList) { + int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X"); + int chesty = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Y"); + int chestz = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Z"); + int chesta = plugin.getChests().getInt("Storage." + xyz2 + ".Arena"); + String chestw = plugin.getChests().getString("Storage." + xyz2 + ".Location.W"); + Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz); + plugin.exists = false; + if (chesta == arena || arena == 0) { + if (blockatlocation.getState() instanceof InventoryHolder chest) { + plugin.exists = true; + int ChunkX = ((Double) (blockatlocation.getX() / 16.0)).intValue(); + int ChunkZ = ((Double) (blockatlocation.getZ() / 16.0)).intValue(); + if (!blockatlocation.getWorld().isChunkLoaded(ChunkX, ChunkZ)) { + blockatlocation.getWorld().loadChunk(ChunkX, ChunkZ, true); + } + chest.getInventory().clear(); + ItemStack[] itemsinchest = null; + Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage"); + if (o instanceof ItemStack[]) { + itemsinchest = (ItemStack[]) o; + } else if (o instanceof List) { + itemsinchest = ((List) o).toArray(new ItemStack[]{}); + } + if (chest.getInventory().getSize() == itemsinchest.length) { + chest.getInventory().setContents(itemsinchest); + } else { + for (ItemStack item : itemsinchest) { + if ((item != null) && (item.getType() != null)) { + chest.getInventory().addItem(item); + } + } + } + } + } + } + if (arena != 0) { + sender.sendMessage(ChatColor.GREEN + "All for arena " + arena + " refilled!"); + } else { + sender.sendMessage(ChatColor.GREEN + "All chests refilled!"); + } + } + + private void Restart_Close_sub(CommandSender sender, String[] args, boolean playr, boolean closeit) { + Set list = plugin.open.keySet(); + if (args.length >= 2) { + list = new HashSet<>(); + if (checkarena(args[1], sender)) { + list.add(Integer.parseInt(args[1])); + } + } + for (int a : list) { + if (!closeit || (closeit && plugin.open.get(a))) { + if (plugin.deathtime.get(a) != null) { + plugin.getServer().getScheduler().cancelTask(plugin.deathtime.get(a)); + plugin.deathtime.put(a, null); + } + if (plugin.grace.get(a) != null) { + plugin.getServer().getScheduler().cancelTask(plugin.grace.get(a)); + plugin.grace.put(a, null); + } + if (plugin.start.get(a) != null) { + plugin.getServer().getScheduler().cancelTask(plugin.start.get(a)); + plugin.start.put(a, null); + } + + if (plugin.timetodeath.get(a) != null) { + plugin.timetodeath.remove(a); + } + plugin.Frozen.get(a).clear(); + if (plugin.Playing.get(a) != null) { + for (String players : plugin.Playing.get(a)) { + Player tributes = plugin.getServer().getPlayerExact(players); + clearInv(tributes); + tributes.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + tributes.teleport(tributes.getWorld().getSpawnLocation()); + plugin.scoreboards.remove(players); + plugin.Kills.remove(players); + plugin.Frozen.get(a).add(players); + } + } + if (plugin.Kills.containsKey("__SuM__")) { + plugin.Kills.remove("__SuM__"); + } + if (plugin.Watching.get(a) != null) { + for (String sname : plugin.Watching.get(a)) { + Player spectators = plugin.getServer().getPlayerExact(sname); + spectators.teleport(spectators.getWorld().getSpawnLocation()); + spectators.setAllowFlight(false); + spectators.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + for (Player online : plugin.getServer().getOnlinePlayers()) { + online.showPlayer(plugin, spectators); + } + plugin.scoreboards.remove(sname); + } + } + if (plugin.Frozen.get(a) != null) { + for (String sname : plugin.Frozen.get(a)) { + Player player = plugin.getServer().getPlayerExact(sname); + plugin.RestoreInv(player, sname); + } + } + plugin.Dead.get(a).clear(); + plugin.Quit.get(a).clear(); + plugin.Watching.get(a).clear(); + plugin.Frozen.get(a).clear(); + plugin.Ready.get(a).clear(); + plugin.NeedConfirm.get(a).clear(); + plugin.Out.get(a).clear(); + plugin.Playing.get(a).clear(); + plugin.inArena.get(a).clear(); + + if (closeit) { + plugin.open.put(a, false); + } else { + plugin.canjoin.put(a, false); + plugin.open.put(a, true); + } + + plugin.MatchRunning.put(a, null); + List blocksbroken = plugin.data.getStringList("Blocks_Destroyed"); + List blocksplaced = plugin.data.getStringList("Blocks_Placed"); + ArrayList toremove = new ArrayList(); + ArrayList toremove2 = new ArrayList(); + for (String blocks : blocksplaced) { + String[] coords = blocks.split(","); + World w = plugin.getServer().getWorld(coords[0]); + double x = Double.parseDouble(coords[1]); + double y = Double.parseDouble(coords[2]); + double z = Double.parseDouble(coords[3]); + int arena = Integer.parseInt(coords[4]); + Location blockl = new Location(w, x, y, z); + Block block = w.getBlockAt(blockl); + if (arena == a) { + block.setType(Material.AIR); + block.getState().update(); + toremove.add(blocks); + } + } + for (String blocks : blocksbroken) { + String[] coords = blocks.split(blocks.contains(";") ? ";" : ","); + World w = plugin.getServer().getWorld(coords[0]); + double x = Double.parseDouble(coords[1]); + double y = Double.parseDouble(coords[2]); + double z = Double.parseDouble(coords[3]); + String d = coords[4]; + byte m = 0; + BlockData newBlData = null; + try { + m = Byte.parseByte(coords[5]); + } catch (NumberFormatException Ex) { + newBlData = Bukkit.createBlockData(coords[5]); + } + int arena = Integer.parseInt(coords[6]); + Location blockl = new Location(w, x, y, z); + Block block = w.getBlockAt(blockl); + if (arena == a) { + if (newBlData == null) { + try { + int d2 = Integer.parseInt(d); + Method setD = Class.forName("org.bukkit.block.Block").getDeclaredMethod("setTypeIdAndData", int.class, byte.class, boolean.class); + setD.setAccessible(true); + setD.invoke(block, d2, m, true); + } catch (Exception | NoSuchMethodError e) { + if (d.replaceAll("[0-9]", "").equals("")) { + int d2 = Integer.parseInt(d); + d = plugin.findOldMaterial(d2, m).name(); + } + block.setType(Material.getMaterial(d), true); + try { + Method setD = Class.forName("org.bukkit.block.Block").getDeclaredMethod("setData", byte.class, boolean.class); + setD.setAccessible(true); + setD.invoke(block, m, true); + } catch (Exception | NoSuchMethodError ee) { + try { + BlockData BlData = block.getBlockData(); + if (BlData instanceof org.bukkit.block.data.type.Snow) { + if (m > 0) { + ((org.bukkit.block.data.type.Snow) BlData).setLayers(m + 1); + } + } + if (BlData instanceof org.bukkit.block.data.type.Cake) { + ((org.bukkit.block.data.type.Cake) BlData).setBites(m); + } + if (coords.length > 7 && (coords[7] != null || coords[7].isEmpty())) { + String BlDir = coords[7]; + if (BlData instanceof org.bukkit.block.data.Directional) { + ((org.bukkit.block.data.Directional) BlData).setFacing(BlockFace.valueOf(BlDir)); + } + } + block.setBlockData(BlData); + } catch (Exception | NoSuchMethodError xx) { + } + } + } + } else { + block.setBlockData(newBlData); + } + block.getState().update(); + toremove2.add(blocks); + } + } + for (String blocks : toremove) { + blocksplaced.remove(blocks); + } + for (String blocks : toremove2) { + blocksbroken.remove(blocks); + } + toremove.clear(); + toremove2.clear(); + plugin.data.set("Blocks_Destroyed", blocksbroken); + plugin.data.set("Blocks_Placed", blocksplaced); + plugin.data.options().copyDefaults(); + plugin.saveData(); + + plugin.setTorch(a, false); + + if (playr) { + ((Player) sender).performCommand("ha refill " + a); + } else { + plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "ha refill " + a); + } + + if (closeit) { + sender.sendMessage(ChatColor.GOLD + "Arena " + a + " Closed!"); + } else { + sender.sendMessage(ChatColor.AQUA + "Arena " + a + " has been reset!"); + } + + } else { + sender.sendMessage(ChatColor.RED + "Arena " + a + " already closed, type /ha open to re-open them!"); + } + } + } + + private void open_sub(CommandSender sender, String[] args) { + Set list = plugin.open.keySet(); + if (args.length >= 2) { + list = new HashSet(); + if (checkarena(args[1], sender)) { + list.add(Integer.parseInt(args[1])); + } + } + for (int i : list) { + if (!plugin.open.get(i)) { + plugin.open.put(i, true); + sender.sendMessage(ChatColor.GOLD + "Arena " + i + " Open!"); + } else { + sender.sendMessage(ChatColor.RED + "Arena " + i + " already open, type /ha close to close them!"); + } + } + } + + private void reload_sub(CommandSender sender) { + for (Player online : plugin.getServer().getOnlinePlayers()) { + if (plugin.getArena(online) != null) { + a = plugin.getArena(online); + plugin.RestoreInv(online, online.getName()); + online.teleport(getArenaSpawn()); + } + } + + plugin.location.clear(); + plugin.Reward.clear(); + plugin.Cost.clear(); + plugin.Fee.clear(); + plugin.ChestPay.clear(); + plugin.spawns = null; + plugin.worldsNames.clear(); + plugin.data = null; + plugin.management = null; + plugin.MyChests = null; + HandlerList.unregisterAll(plugin); + plugin.reloadConfig(); + plugin.onEnable(); + sender.sendMessage(ChatColor.AQUA + "HungerArena Reloaded!"); + System.out.println(ChatColor.GREEN + sender.getName() + " reloaded HungerArena!"); + } + + private void warpall_sub(final CommandSender sender, String[] args) { + if ((plugin.spawns.getString("Spawns_set.0") == null) || plugin.spawns.getString("Spawns_set.0").equalsIgnoreCase("false")) { + sender.sendMessage(ChatColor.RED + "/ha setspawn hasn't ever been run!"); + } else { + if (args.length >= 2) { + if (checkarena(args[1], sender)) { + a = Integer.parseInt(args[1]); + if ((plugin.spawns.getString("Spawns_set." + a) == null) || (plugin.spawns.getString("Spawns_set." + a).equalsIgnoreCase("false"))) { + sender.sendMessage(ChatColor.RED + "/ha setspawn for Arena " + a + " hasn't been run!"); + } else { + if (plugin.Playing.get(a).size() <= 1) { + sender.sendMessage(ChatColor.RED + "There are not enough players!"); + + } else if (plugin.canjoin.get(a) == true) { + sender.sendMessage(ChatColor.RED + "Game already in progress!"); + + } else { + plugin.setTorch(a, false); + + if (plugin.config.getString("Auto_Start").equalsIgnoreCase("true")) { + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha start " + a); + } + }, 20L); + } + List shuffle = new ArrayList(); + for (i = 1; i <= plugin.location.get(a).size(); shuffle.add(i++)) { + } + Collections.shuffle(shuffle); + i = 1; + for (String playing : plugin.Playing.get(a)) { + Player tribute = plugin.getServer().getPlayerExact(playing); + plugin.Frozen.get(a).add(tribute.getName()); + Location toLoc = plugin.location.get(a).get(shuffle.get(i)); + tribute.setHealth(20); + tribute.setFoodLevel(20); + tribute.setSaturation(20); + tribute.setLevel(0); + clearInv(tribute); + for (PotionEffect pe : tribute.getActivePotionEffects()) { + PotionEffectType potion = pe.getType(); + tribute.removePotionEffect(potion); + } + if (tribute.getAllowFlight()) { + tribute.setAllowFlight(false); + } + Location opposite = toLoc.clone(); + double dist = 0; + double dist2; + for (Location loc : plugin.location.get(a).values()) { + dist2 = loc.distance(toLoc); + if (dist2 > dist) { + dist = dist2; + opposite = loc.clone(); + } + } + toLoc.setDirection(opposite.toVector().subtract(toLoc.toVector())); + MetadataValue MdV_Location = new FixedMetadataValue(plugin, toLoc); + tribute.setMetadata("HA-Location", MdV_Location); + tribute.teleport(toLoc); + i += 1; + } + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + sender.sendMessage(ChatColor.AQUA + "All Tributes warped!"); + plugin.MatchRunning.put(a, "warped"); + } + }, 10L); + } + } + } + } else { + sender.sendMessage(ChatColor.RED + "Too few arguments, specify an arena"); + } + } + } + + private void start_sub(CommandSender sender, String[] args) { + if (args.length != 2) { + sender.sendMessage(ChatColor.RED + "You need to specify the arena to start!"); + } else { + if (checkarena(args[1], sender)) { + a = Integer.parseInt(args[1]); + if (plugin.canjoin.get(a) == true) { + sender.sendMessage(ChatColor.RED + "Game already in progress!"); + } else if (plugin.Playing.get(a).size() == 1) { + sender.sendMessage(ChatColor.RED + "There are not enough players!"); + } else if (plugin.Playing.get(a).isEmpty()) { + sender.sendMessage(ChatColor.RED + "No one is in that game!"); + } else if ((plugin.MatchRunning.get(a) != null) && (plugin.MatchRunning.get(a).equals("warped"))) { + plugin.startGames(a); + } else { + sender.sendMessage(ChatColor.RED + "First all players must be warped!"); + } + } + } + } + + private boolean checkarena(String Int, CommandSender sender) { + a = 0; + try { + a = Integer.parseInt(Int); + } catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + "You have to enter the Arena number!"); + return false; + } + if (a > 0) { + if (plugin.canjoin.containsKey(a)) { + return true; + } + } + sender.sendMessage(ChatColor.RED + "That arena doesn't exist!"); + return false; + } + + private void confirmSub(Player p, String pname, String ThisWorld) { + if (plugin.config.getBoolean("EntryFee.enabled")) { + if ((!plugin.config.getBoolean("EntryFee.eco")) || (plugin.config.getBoolean("EntryFee.eco") && !(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost")))) { + i = 0; + for (ItemStack fee : plugin.Fee) { + int total = plugin.Fee.size(); + if (p.getInventory().containsAtLeast(fee, fee.getAmount())) { + i += 1; + if (total == i) { + if (plugin.config.getBoolean("EntryFee.eco")) { + plugin.econ.withdrawPlayer(p, plugin.config.getDouble("EntryFee.cost")); + p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + "$" + plugin.config.getDouble("EntryFee.cost") + " has been taken from your account!"); + } + for (ItemStack fees : plugin.Fee) { + String beginning = fees.getType().toString().substring(0, 1); + String item = beginning.toUpperCase() + fees.getType().toString().substring(1).toLowerCase().replace("_", " "); + int amount = fees.getAmount(); + p.getInventory().removeItem(fees); + if (amount > 1) { + p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + amount + " " + item + "s was paid to join the games."); + } else { + p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + amount + " " + item + " was paid to join the games."); + } + } + preparePlayer(p, pname, ThisWorld); + } + } + } + if (plugin.Fee.size() > i) { + p.sendMessage(ChatColor.RED + "You are missing some items and can't join the games..."); + } + } else { + p.sendMessage(ChatColor.RED + "You don't have enough money to join!"); + } + } else if (plugin.config.getBoolean("EntryFee.eco")) { + if (!(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost"))) { + plugin.econ.withdrawPlayer(p, plugin.config.getDouble("EntryFee.cost")); + p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + "$" + plugin.config.getDouble("EntryFee.cost") + " has been taken from your account!"); + preparePlayer(p, pname, ThisWorld); + } else { + p.sendMessage(ChatColor.RED + "You don't have enough money to join!"); + } + } else { + preparePlayer(p, pname, ThisWorld); + } + } + + private void preparePlayer(Player p, String pname, String ThisWorld) { + plugin.Playing.get(a).add(pname); + plugin.NeedConfirm.get(a).remove(pname); + p.sendMessage(ChatColor.GREEN + "Do /ha ready to vote to start the games!"); + FileConfiguration pinfo = plugin.getPConfig(pname); + pinfo.set("inv", p.getInventory().getContents()); + pinfo.set("armor", p.getInventory().getArmorContents()); + pinfo.set("world", ThisWorld); + pinfo.set("player", pname); + plugin.savePFile(pname); + clearInv(p); + plugin.needInv.add(pname); + if (plugin.config.getBoolean("broadcastAll")) { + plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "! " + ChatColor.GRAY + plugin.Playing.get(a).size() + "/" + plugin.maxPlayers.get(a)); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(ChatColor.AQUA + pname + " has Joined the Game! " + ChatColor.GRAY + plugin.Playing.get(a).size() + "/" + plugin.maxPlayers.get(a)); + } + } + if (plugin.Playing.get(a).size() == plugin.maxPlayers.get(a)) { + plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "ha warpall " + a); + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/BlockStorage.java b/src/main/java/me/Travja/HungerArena/Listeners/BlockStorage.java new file mode 100644 index 0000000..2bffdb1 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/BlockStorage.java @@ -0,0 +1,282 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.material.MaterialData; + +import java.util.List; + +public class BlockStorage implements Listener { + public Main plugin; + + public BlockStorage(Main m) { + this.plugin = m; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void BlockBreak(BlockBreakEvent event) { + Block b = event.getBlock(); + Player p = event.getPlayer(); + String pname = p.getName(); + boolean protall = false; + if (!p.hasPermission("HungerArena.arena")) { + protall = protall(); //true = protect allways!! + } + if ((plugin.getArena(p) != null) || (protall)) { + //Jeppa: get a default arena if protall is true... (but use getArena if set...) + int a = 1; + if (protall) { + String ThisWorld = p.getWorld().getName(); + for (int z : plugin.worldsNames.keySet()) { + if (plugin.worldsNames.get(z) != null) { + if (plugin.worldsNames.get(z).equals(ThisWorld)) { + a = z; + } + } + } + } + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + } + if ((!event.isCancelled()) && (((plugin.Playing.get(a)).contains(pname)) || (protall))) { + if (plugin.config.getString("Protected_Arena").equalsIgnoreCase("True")) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You can't break blocks while playing!"); + } else if ((plugin.canjoin.get(a) || protall) && ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.values().contains(p.getWorld().getName()))))) { + if (((plugin.management.getStringList("blocks.whitelist").isEmpty()) || ((!plugin.management.getStringList("blocks.whitelist").isEmpty()) && (!plugin.management.getStringList("blocks.whitelist").contains(String.valueOf(b.getType().name()))))) ^ (plugin.management.getBoolean("blocks.useWhitelistAsBlacklist"))) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "That is an illegal block!"); + } else { + String w = b.getWorld().getName(); + addDestroyedBlockToList(b, w, a); + } + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void Explosion(EntityExplodeEvent event) { + List blocksd = event.blockList(); + Entity e = event.getEntity(); + if (!event.isCancelled()) { + for (int i : plugin.canjoin.keySet()) { + if (plugin.canjoin.get(i) || protall()) { + String ThisWorld = e.getWorld().getName(); + if ((!plugin.restricted) || ((plugin.restricted) && plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(ThisWorld))) { + if (e.getType() == EntityType.PRIMED_TNT) { + e.getLocation().getBlock().setType(Material.TNT); + Block TNT = e.getLocation().getBlock(); + addDestroyedBlockToList(TNT, ThisWorld, i); + TNT.setType(Material.AIR); + } + for (Block b : blocksd) { + if (!b.getType().name().equalsIgnoreCase("AIR")) { + addDestroyedBlockToList(b, ThisWorld, i); + } + } + } + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void burningBlocks(BlockBurnEvent event) { + Block b = event.getBlock(); + if (!event.isCancelled()) { + for (int i : plugin.canjoin.keySet()) { + if (plugin.canjoin.get(i) || protall()) { + if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(b.getWorld().getName())))) { + String w = b.getWorld().getName(); + addDestroyedBlockToList(b, w, i); + } + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void blockPlace(BlockPlaceEvent event) { + Block b = event.getBlock(); + Player p = event.getPlayer(); + boolean protall = false; + if (!p.hasPermission("HungerArena.arena")) { + protall = protall(); + } + if ((plugin.getArena(p) != null) || (protall)) { + int a = 1; + if (protall) { + String ThisWorld = p.getWorld().getName(); + for (int z : plugin.worldsNames.keySet()) { + if (plugin.worldsNames.get(z) != null) { + if (plugin.worldsNames.get(z).equals(ThisWorld)) { + a = z; + } + } + } + } + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + } + if (!event.isCancelled()) { + if (((plugin.Playing.get(a)).contains(p.getName())) || (protall)) { + if ((plugin.canjoin.get(a)) || (protall)) { + if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.values().contains(b.getWorld().getName())))) { + if ((b.getType() == Material.SAND || b.getType() == Material.GRAVEL) && (b.getRelative(BlockFace.DOWN).getType() == Material.AIR || b.getRelative(BlockFace.DOWN).getType() == Material.WATER || b.getRelative(BlockFace.DOWN).getType() == Material.LAVA)) { + int n = b.getY() - 1; + while (b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.LAVA) { + n = n - 1; + event.getPlayer().sendMessage(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType().toString().toLowerCase()); + if (b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() != Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() != Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() != Material.LAVA) { + int l = n + 1; + Block br = b.getWorld().getBlockAt(b.getX(), l, b.getZ()); + String w = br.getWorld().getName(); + + addPlacedBlockToList(br, w, a); + } + } + } else { + if (b.getType() != Material.SAND && b.getType() != Material.GRAVEL) { + String w = b.getWorld().getName(); + + addPlacedBlockToList(b, w, a); + } + } + } + } + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void bucketEmpty(PlayerBucketEmptyEvent event) { + if (plugin.getArena(event.getPlayer()) != null) { + int a = plugin.getArena(event.getPlayer()); + if (!event.isCancelled()) { + if (plugin.canjoin.get(a)) { + if (plugin.Playing.get(a).contains(event.getPlayer().getName())) { + if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.values().contains(event.getPlayer().getWorld().getName())))) { + Block b = event.getBlockClicked().getRelative(event.getBlockFace()); + String w = b.getWorld().getName(); + addPlacedBlockToList(b, w, a); + } + } + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void bucketFill(PlayerBucketFillEvent event) { + if (plugin.getArena(event.getPlayer()) != null) { + int a = plugin.getArena(event.getPlayer()); + if (!event.isCancelled()) { + if (plugin.canjoin.get(a)) { + if (plugin.Playing.get(a).contains(event.getPlayer().getName())) { + if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.values().contains(event.getPlayer().getWorld().getName())))) { + Block b = event.getBlockClicked().getRelative(event.getBlockFace()); + String w = b.getWorld().getName(); + addDestroyedBlockToList(b, w, a); + } + } + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void blockMelt(BlockFadeEvent event) { + if (!event.isCancelled()) { + for (int i : plugin.canjoin.keySet()) { + if (plugin.canjoin.get(i) || protall()) { + if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(event.getBlock().getWorld().getName())))) { + Block b = event.getBlock(); + String w = b.getWorld().getName(); + String d = b.getType().name(); + if (d.equalsIgnoreCase("FIRE") || d.equalsIgnoreCase("AIR")) { + continue; + } + addDestroyedBlockToList(b, w, i); + } + } + } + } + } + + //SubRoutines: + private boolean protall() { + if (plugin.config.getString("Protected_Arena_Always").equalsIgnoreCase("True")) { + return true; + } + return false; + } + + + private void addDestroyedBlockToList(Block b, String w, int a) { + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + String d = b.getType().name(); + byte m = 0; + String BlDataString = null; + String sp = ";"; + + String dir = ""; + try { + if (b.getState().getBlockData() instanceof BlockData) { + BlDataString = b.getBlockData().getAsString(); + } + } catch (Exception | NoSuchMethodError ex) { + m = b.getData(); + sp = ","; + MaterialData mData = b.getState().getData(); + if (mData instanceof org.bukkit.material.Directional) { + BlockFace Dir = ((org.bukkit.material.Directional) mData).getFacing(); + if (Dir != null) { + dir = sp + (Dir.name()); + } + } + } + String data = BlDataString != null ? BlDataString : String.valueOf(m); + String coords = w + sp + x + sp + y + sp + z + sp + d + sp + data + sp + a + dir; + List blocks = plugin.data.getStringList("Blocks_Destroyed"); + if (!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + a)) { + blocks.add(coords); + plugin.data.set("Blocks_Destroyed", blocks); + plugin.saveData(); + } + } + + private void addPlacedBlockToList(Block br, String w, int a) { + int x = br.getX(); + int y = br.getY(); + int z = br.getZ(); + String coords = w + "," + x + "," + y + "," + z + "," + a; + List blocks = plugin.data.getStringList("Blocks_Placed"); + if (!blocks.contains(coords)) { + blocks.add(coords); + plugin.data.set("Blocks_Placed", blocks); + plugin.saveData(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/me/Travja/HungerArena/Listeners/Boundaries.java b/src/main/java/me/Travja/HungerArena/Listeners/Boundaries.java new file mode 100644 index 0000000..0412149 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/Boundaries.java @@ -0,0 +1,84 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerMoveEvent; + +import java.util.Map; +import java.util.Map.Entry; + +public class Boundaries implements Listener { + public Main plugin; + + public Boundaries(Main m) { + this.plugin = m; + } + + @EventHandler + public void boundsCheck(PlayerMoveEvent event) { + Player p = event.getPlayer(); + Boolean inGame = plugin.getArena(p) != null; + Boolean spectating = plugin.isSpectating(p); + if (plugin.config.getBoolean("WorldEdit")) { + if (insideBounds(p.getLocation()) && (inGame || spectating) || (!insideBounds(p.getLocation()) && inGame)) { + event.setCancelled(true); + } + } + } + + @EventHandler + public void blockBounds(BlockBreakEvent event) { + Player p = event.getPlayer(); + if (plugin.getArena(p) == null) { + if (plugin.config.getBoolean("WorldEdit")) { + if (insideBounds(event.getBlock().getLocation())) { + p.sendMessage(ChatColor.RED + "That block is protected by HungerArena!"); + event.setCancelled(true); + } + } + } + } + + public boolean insideBounds(Location l) { + Location minl = null; + Location maxl = null; + if (plugin.spawns.get("Arena") != null) { + Map temp = plugin.spawns.getConfigurationSection("Arena").getValues(false); + for (Entry entry : temp.entrySet()) { + if (plugin.spawns.getConfigurationSection("Arena." + entry.getKey()) != null) { + String[] min = ((String) plugin.spawns.get("Arena." + entry.getKey()) + ".Min").split(","); + String[] max = ((String) plugin.spawns.get("Arena." + entry.getKey()) + ".Max").split(","); + try { + World world = Bukkit.getWorld(min[0]); + double x = Double.parseDouble(min[1]); + double y = Double.parseDouble(min[2]); + double z = Double.parseDouble(min[3]); + minl = new Location(world, x, y, z); + World world2 = Bukkit.getWorld(max[0]); + double x2 = Double.parseDouble(max[1]); + double y2 = Double.parseDouble(max[2]); + double z2 = Double.parseDouble(max[3]); + minl = new Location(world2, x2, y2, z2); + } catch (Exception e) { + System.out.println(e); + return false; + } + if (minl != null && maxl != null) { + return l.getX() >= minl.getBlockX() + && l.getX() < maxl.getBlockX() + 1 && l.getY() >= minl.getBlockY() + && l.getY() < maxl.getBlockY() + 1 && l.getZ() >= minl.getBlockZ() + && l.getZ() < maxl.getBlockZ() + 1; + } + } + } + } + return false; + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/ChatListener.java b/src/main/java/me/Travja/HungerArena/Listeners/ChatListener.java new file mode 100644 index 0000000..210d9be --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/ChatListener.java @@ -0,0 +1,54 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.ChatColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.List; + +public class ChatListener implements Listener { + public Main plugin; + + public ChatListener(Main m) { + this.plugin = m; + } + + @EventHandler + public void TributeChat(AsyncPlayerChatEvent event) { + Player p = event.getPlayer(); + String pname = p.getName(); + if (plugin.getArena(p) != null) { + String msg = "<" + ChatColor.RED + "[Tribute] " + ChatColor.WHITE + pname + ">" + " " + event.getMessage(); + if (plugin.config.getString("ChatClose").equalsIgnoreCase("True")) { + double radius = plugin.config.getDouble("ChatClose_Radius"); + List near = p.getNearbyEntities(radius, radius, radius); + event.setCancelled(true); + if (!(near.size() == 0)) { + p.sendMessage(msg); + for (Entity e : near) { + if (e instanceof Player) { + ((Player) e).sendMessage(msg); + } + } + } else if (near.size() == 0) { + p.sendMessage(msg); + p.sendMessage(ChatColor.YELLOW + "No one near!"); + } else if (!(near.size() == 0)) { + for (Entity en : near) { + if (!(en instanceof Player)) { + p.sendMessage(msg); + p.sendMessage(ChatColor.YELLOW + "No one near!"); + } + } + } + } else { + event.setCancelled(true); + plugin.getServer().broadcastMessage(msg); + } + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/DeathListener.java b/src/main/java/me/Travja/HungerArena/Listeners/DeathListener.java new file mode 100644 index 0000000..a2fdedc --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/DeathListener.java @@ -0,0 +1,221 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.scoreboard.DisplaySlot; + +public class DeathListener implements Listener { + public Main plugin; + + public DeathListener(Main m) { + this.plugin = m; + } + + public FileConfiguration config; + int i = 0; + int a = 0; + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerRespawn(PlayerRespawnEvent event) { + final Player p = event.getPlayer(); + String pname = p.getName(); + + //get the arena the player has died in... (may be not the one he joined...) + String ThisWorld = p.getWorld().getName(); + for (int z : plugin.worldsNames.keySet()) { + if (plugin.worldsNames.get(z) != null) { + if (plugin.worldsNames.get(z).equals(ThisWorld)) { + a = z; + } + } + } + + //Jeppa: Fix for lonely players :) + for (int i : plugin.Dead.keySet()) { + if ((plugin.Dead.get(i) != null) && (plugin.Dead.get(i).contains(pname)) && (plugin.MatchRunning.get(i) == null)) { + plugin.Dead.get(i).clear(); + } + } + + for (int i = 0; i < plugin.needInv.size(); i++) { + if (plugin.needInv.contains(pname)) { + RespawnDeadPlayer(p, a); + } + } + } + + private void RespawnDeadPlayer(Player p, int a) { + final Player player = p; + String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + a).split(","); + World spawnw = plugin.getServer().getWorld(Spawncoords[3]); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + player.teleport(Spawn); + plugin.RestoreInv(player, player.getName()); + } + }, 10L); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerDeath(PlayerDeathEvent event) { + Player p = event.getEntity(); + Server s = p.getServer(); + String pname = p.getName(); + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + int players = plugin.Playing.get(a).size() - 1; + String leftmsg = null; + clearInv(p); + event.getDrops().clear(); + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + plugin.scoreboards.remove(p.getName()); + if (!plugin.Frozen.get(a).isEmpty()) { + if (plugin.Frozen.get(a).contains(pname)) { + if (!(p.getKiller() instanceof Player)) { + players = plugin.Playing.get(a).size() - 1; + leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!"; + if (plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")) { + double y = p.getLocation().getY(); + double newy = y + 200; + double x = p.getLocation().getX(); + double z = p.getLocation().getZ(); + Location strike = new Location(p.getWorld(), x, newy, z); + p.getWorld().strikeLightning(strike); + } + event.setDeathMessage(""); + if (plugin.config.getBoolean("broadcastAll")) { + p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); + } + } + plugin.Frozen.get(a).remove(pname); + plugin.Playing.get(a).remove(pname); + if (plugin.config.getBoolean("broadcastAll")) { + p.getServer().broadcastMessage(leftmsg); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(leftmsg); + } + } + plugin.winner(a); + } + } + } else { + players = plugin.Playing.get(a).size() - 1; + leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!"; + if (plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")) { + double y = p.getLocation().getY(); + double newy = y + 200; + double x = p.getLocation().getX(); + double z = p.getLocation().getZ(); + Location strike = new Location(p.getWorld(), x, newy, z); + p.getWorld().strikeLightning(strike); + } + plugin.Dead.get(a).add(pname); + plugin.Playing.get(a).remove(pname); + if (p.getKiller() instanceof Player) { + if (p.getKiller().getInventory().getItemInMainHand().getType() == Material.AIR) { + Player killer = p.getKiller(); + String killername = killer.getName(); + event.setDeathMessage(""); + if (plugin.config.getBoolean("broadcastAll")) { + s.broadcastMessage(ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with their FIST!"); + s.broadcastMessage(leftmsg); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with their FIST!"); + g.sendMessage(leftmsg); + } + } + if (plugin.Kills.containsKey(killername)) { + plugin.Kills.put(killername, plugin.Kills.get(killername) + 1); + } else { + plugin.Kills.put(killername, 1); + } + if (plugin.Kills.containsKey("__SuM__")) { + plugin.Kills.put("__SuM__", plugin.Kills.get("__SuM__") + 1); + } else { + plugin.Kills.put("__SuM__", 1); + } + plugin.winner(a); + } else { + Player killer = p.getKiller(); + String killername = killer.getName(); + String weapon = "a(n) " + killer.getInventory().getItemInMainHand().getType().name().replace('_', ' '); + if (killer.getInventory().getItemInMainHand().hasItemMeta()) { + if (killer.getInventory().getItemInMainHand().getItemMeta().hasDisplayName()) { + weapon = killer.getInventory().getItemInMainHand().getItemMeta().getDisplayName(); + } + } + String msg = ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with " + weapon; + event.setDeathMessage(""); + if (plugin.config.getBoolean("broadcastAll")) { + s.broadcastMessage(msg); + s.broadcastMessage(leftmsg); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(msg); + g.sendMessage(leftmsg); + } + } + if (plugin.Kills.containsKey(killername)) { + plugin.Kills.put(killername, plugin.Kills.get(killername) + 1); + } else { + plugin.Kills.put(killername, 1); + } + if (plugin.Kills.containsKey("__SuM__")) { + plugin.Kills.put("__SuM__", plugin.Kills.get("__SuM__") + 1); + } else { + plugin.Kills.put("__SuM__", 1); + } + plugin.winner(a); + } + } else { + event.setDeathMessage(""); + if (plugin.config.getBoolean("broadcastAll")) { + s.broadcastMessage(ChatColor.LIGHT_PURPLE + pname + " died of natural causes!"); + s.broadcastMessage(leftmsg); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(ChatColor.LIGHT_PURPLE + pname + " died of " + ChatColor.ITALIC + " probably " + ChatColor.LIGHT_PURPLE + "natural causes!"); + g.sendMessage(leftmsg); + } + } + plugin.winner(a); + } + } + } + } + + private void clearInv(Player p) { + p.getInventory().clear(); + p.getInventory().setBoots(null); + p.getInventory().setChestplate(null); + p.getInventory().setHelmet(null); + p.getInventory().setLeggings(null); + p.updateInventory(); + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/FreezeListener.java b/src/main/java/me/Travja/HungerArena/Listeners/FreezeListener.java new file mode 100644 index 0000000..2293c8b --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/FreezeListener.java @@ -0,0 +1,123 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.metadata.MetadataValue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class FreezeListener implements Listener { + public Main plugin; + + public FreezeListener(Main m) { + this.plugin = m; + } + + int i = 0; + int a = 0; + private HashMap timeUp = new HashMap(); + private ArrayList timing = new ArrayList(); + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Player p = event.getPlayer(); + String pname = p.getName(); + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + if (plugin.Frozen.get(a).contains(pname) && plugin.config.getString("Frozen_Teleport").equalsIgnoreCase("True")) { + if (plugin.config.getString("Explode_on_Move").equalsIgnoreCase("true")) { + timeUp.put(a, false); + for (String players : plugin.Playing.get(a)) { + Player playing = plugin.getServer().getPlayerExact(players); + i = plugin.Playing.get(a).indexOf(players) + 1; + if (!timeUp.get(a) && !timing.contains(a)) { + timing.add(a); + if (!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())) { + playing.teleport(plugin.location.get(a).get(i)); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + if (!timeUp.get(a)) { + timeUp.put(a, true); + timing.remove(a); + } + } + }, 30L); + } + } else { + if (!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())) { + if (!plugin.Dead.get(a).contains(playing.getName())) { + plugin.Dead.get(a).add(playing.getName()); + World world = playing.getLocation().getWorld(); + world.createExplosion(playing.getLocation(), 0.0F, false); + playing.setHealth(0.0D); + } + } + } + } + if (plugin.Dead.get(a).contains(pname) && plugin.Playing.get(a).contains(pname)) { + int players = plugin.Playing.get(a).size() - 1; + String leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!"; + if (plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")) { + double y = p.getLocation().getY(); + double newy = y + 200; + double x = p.getLocation().getX(); + double z = p.getLocation().getZ(); + Location strike = new Location(p.getWorld(), x, newy, z); + p.getWorld().strikeLightning(strike); + } + if (plugin.config.getBoolean("broadcastAll")) { + p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); + } + } + plugin.Frozen.get(a).remove(pname); + plugin.Playing.get(a).remove(pname); + if (plugin.config.getBoolean("broadcastAll")) { + p.getServer().broadcastMessage(leftmsg); + } else { + for (String gn : plugin.Playing.get(a)) { + Player g = plugin.getServer().getPlayer(gn); + g.sendMessage(leftmsg); + } + } + plugin.winner(a); + } + } else { + i = plugin.Playing.get(a).indexOf(pname) + 1; + Location pLoc = null; + if (p.hasMetadata("HA-Location")) { + List l = p.getMetadata("HA-Location"); + if (l != null && l.size() != 0) { + try { + pLoc = (Location) l.get(0).value(); + } catch (Exception e) { + } + } + if (pLoc != null) { + if (p.getLocation().getBlockX() != (pLoc.getBlockX()) || p.getLocation().getBlockZ() != (pLoc.getBlockZ())) { + pLoc.setX(pLoc.getBlock().getLocation().getX() + .5); + pLoc.setZ(pLoc.getBlock().getLocation().getZ() + .5); + p.teleport(pLoc); + } + } else { + if (!p.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())) { + p.teleport(plugin.location.get(a).get(i)); + } + } + } + } + } + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java b/src/main/java/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java new file mode 100644 index 0000000..64323fc --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java @@ -0,0 +1,204 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.HaCommands; +import me.Travja.HungerArena.Main; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scoreboard.DisplaySlot; + +public class JoinAndQuitListener implements Listener { + public Main plugin; + + public JoinAndQuitListener(Main m) { + this.plugin = m; + } + + public HaCommands commands; + + public JoinAndQuitListener(HaCommands h) { + this.commands = h; + } + + int a = 0; + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + final Player p = event.getPlayer(); + final String pname = p.getName(); + boolean pfound = false; + for (int i : plugin.Watching.keySet()) { + for (String s : plugin.Watching.get(i)) { + Player spectator = plugin.getServer().getPlayerExact(s); + p.hidePlayer(plugin, spectator); + } + } + for (int i : plugin.Out.keySet()) { + if (plugin.Out.get(i).contains(pname)) { + plugin.Playing.get(i).add(pname); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + p.sendMessage(ChatColor.AQUA + "You have saved yourself from being ejected from the arena!"); + } + }, 40L); + plugin.Out.get(i).remove(pname); + pfound = true; + } + } + + for (final int i : plugin.Quit.keySet()) { + if (plugin.Quit.get(i).contains(pname)) { + String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + i).split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + p.teleport(Spawn); + p.sendMessage(ChatColor.RED + "You have been teleported to last spawn because you quit/forfeited!"); + plugin.RestoreInv(p, p.getName()); + if (plugin.Quit.get(i) != null) { + plugin.Quit.get(i).remove(p.getName()); + } + } + }, 40L); + pfound = true; + } + } + for (final int i : plugin.Dead.keySet()) { + if (plugin.Dead.get(i).contains(pname)) { + String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + i).split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + p.teleport(Spawn); + p.sendMessage(ChatColor.RED + "You have been teleported to spawn because you quit/died/forfeited!!"); + plugin.RestoreInv(p, p.getName()); + if (plugin.Dead.get(i) != null) { + plugin.Dead.get(i).remove(p.getName()); + } + } + }, 40L); + pfound = true; + } + } + for (final int i : plugin.inArena.keySet()) { + if (plugin.inArena.get(i) != null) { + if (plugin.inArena.get(i).contains(pname)) { + String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + i).split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + p.teleport(Spawn); + p.getInventory().clear(); + p.getInventory().setBoots(null); + p.getInventory().setLeggings(null); + p.getInventory().setChestplate(null); + p.getInventory().setHelmet(null); + plugin.inArena.remove(pname); + p.sendMessage(ChatColor.RED + "You were still in the arena when you left and now the games are over."); + plugin.RestoreInv(p, p.getName()); + if (plugin.inArena.get(i) != null) { + plugin.inArena.get(i).remove(p.getName()); + } + } + }, 40L); + pfound = true; + } + } + } + if ((plugin.restricted && plugin.worldsNames.values().contains(p.getWorld().getName())) || !plugin.restricted) { + if (!pfound && plugin.config.getString("Force_Players_toSpawn").equalsIgnoreCase("True") && (plugin.spawns.getString("Spawn_coords.0") != null)) { + String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + plugin.RestoreInv(p, p.getName()); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + p.teleport(Spawn); + p.sendMessage(ChatColor.RED + "You have been teleported to spawn!!"); + } + }, 40L); + } + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent evt) { + Player p = evt.getPlayer(); + String pname = p.getName(); + for (int i : plugin.Frozen.keySet()) { + if (plugin.Frozen.get(i).contains(pname)) { + plugin.Frozen.remove(pname); + String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + p.teleport(Spawn); + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + if (plugin.scoreboards.containsKey(p.getName())) { + plugin.scoreboards.remove(p.getName()); + } + if (plugin.Kills.containsKey(p.getName())) { + plugin.Kills.remove(p.getName()); + } + } + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + final Player p = event.getPlayer(); + final String pname = p.getName(); + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + plugin.Out.get(a).add(pname); + plugin.Playing.get(a).remove(pname); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + if (plugin.Out.get(a).contains(pname)) { + plugin.Quit.get(a).add(pname); + plugin.Out.get(a).remove(pname); + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + if (plugin.scoreboards.containsKey(p.getName())) { + plugin.scoreboards.remove(p.getName()); + } + if (plugin.Kills.containsKey(p.getName())) { + plugin.Kills.remove(p.getName()); + } + plugin.winner(a); + plugin.inArena.get(a).add(pname); + } else if (plugin.getArena(p) == null) { + plugin.Quit.get(a).add(pname); + } + } + }, 1200L); + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/PvP.java b/src/main/java/me/Travja/HungerArena/Listeners/PvP.java new file mode 100644 index 0000000..473f45d --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/PvP.java @@ -0,0 +1,106 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.Skeleton; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; + +public class PvP implements Listener { + public Main plugin; + + public PvP(Main m) { + this.plugin = m; + } + + int a = 0; + + @EventHandler(priority = EventPriority.MONITOR) + public void PlayerPvP(EntityDamageByEntityEvent event) { + Entity pl = event.getEntity(); + Entity dl = event.getDamager(); + if (pl instanceof Player && dl instanceof Player) { + Player p = (Player) pl; + Player d = (Player) dl; + if (plugin.getArena(p) != null && plugin.getArena(d) != null) { + a = plugin.getArena(p); + if (plugin.canjoin.get(a)) { + if (event.isCancelled()) { + event.setCancelled(false); + } + if (plugin.gp.get(plugin.getArena(p)) != null) { + if (plugin.gp.get(plugin.getArena(p)) != 0) { + event.setCancelled(true); + } + } + } + } + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + if (!plugin.canjoin.get(a)) { + if (!event.isCancelled()) { + event.setCancelled(true); + } + } + } + if (plugin.getArena(p) == null && plugin.getArena(d) != null) { + if (!event.isCancelled()) { + event.setCancelled(true); + } + } + } else if (pl instanceof Player && dl instanceof Projectile) { + Projectile projectile = (Projectile) dl; + Player p = (Player) pl; + if (projectile.getShooter() instanceof Player) { + if (plugin.getArena(p) != null) { + Player shooter = (Player) projectile.getShooter(); + if (plugin.getArena(shooter) != null) { + if (plugin.gp.get(plugin.getArena(p)) != null) { + if (plugin.gp.get(plugin.getArena(p)) != 0) { + event.setCancelled(true); + } else { + event.setCancelled(false); + } + } + } + } + } else if (projectile.getShooter() instanceof Entity) { + Entity e = (Entity) projectile.getShooter(); + if (e instanceof Skeleton) { + if (plugin.getArena(p) != null) { + if (plugin.gp.get(plugin.getArena((Player) e)) != null) { + if (plugin.gp.get(plugin.getArena(p)) != 0) { + event.setCancelled(true); + } else { + event.setCancelled(false); + } + } + } + } + } + } + } + + @EventHandler + public void PlayerDamage(EntityDamageEvent event) { + Entity e = event.getEntity(); + if (e instanceof Player) { + Player p = (Player) e; + if (plugin.getArena(p) != null) { + a = plugin.getArena(p); + if (plugin.gp.get(a) != null && plugin.gp.get(a) != 0) { + event.setCancelled(true); + } + if (plugin.Frozen.get(a) != null && plugin.Frozen.get(a).contains(p.getName())) { + event.setCancelled(true); + } + } + } + } + +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/SignsAndBeds.java b/src/main/java/me/Travja/HungerArena/Listeners/SignsAndBeds.java new file mode 100644 index 0000000..006ebc5 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/SignsAndBeds.java @@ -0,0 +1,94 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.ChatColor; +import org.bukkit.Tag; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class SignsAndBeds implements Listener { + public Main plugin; + + public SignsAndBeds(Main m) { + this.plugin = m; + } + + @EventHandler + public void Sign(PlayerInteractEvent event) { + Player p = event.getPlayer(); + Block b = event.getClickedBlock(); + if (b == null) { + return; + } + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + //2019 1.14 Translate Materials: + boolean foundSign = false; + try { + if (b.getState() instanceof org.bukkit.block.Sign) { + foundSign = true; + } + } catch (Exception e) { + if (!foundSign) { + foundSign = Tag.SIGNS.isTagged(b.getType()); + } + } + if (foundSign) { + org.bukkit.block.Sign sign = (org.bukkit.block.Sign) b.getState(); + String line1 = sign.getLine(0); + String line2 = sign.getLine(1); + String line3 = sign.getLine(2); + String line4 = sign.getLine(3); + if (line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[HungerArena]") || line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[HA]")) { + if (!line2.equals("") && line3.equals("")) { + p.performCommand("ha " + line2); + } else if (line2.equals("") && !line3.equals("")) { + p.performCommand("ha " + line3); + } else if (!line2.equals("") && !line3.equals("")) { + String commands = "close,join,kick,leave,list,open,ready,refill,reload,restart,rlist,tp,start,watch,warpall"; + if (commands.contains(line3.trim().toLowerCase())) { + p.performCommand("ha " + line2); + p.performCommand("ha " + line3); + } else { + p.performCommand("ha " + line2 + " " + line3); + } + } else { + p.performCommand("ha"); + } + } + if (line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[Sponsor]")) { + p.performCommand("sponsor " + line2 + " " + line3 + " " + line4); + } + } + + if (plugin.config.getString("DenyBedUsage").equalsIgnoreCase("True")) { + boolean foundBed = false; + try { + if (b.getState() instanceof org.bukkit.block.Bed) { + foundBed = true; + } + } catch (Exception e) { + if (!foundBed) { + foundBed = Tag.BEDS.isTagged(b.getType()); + } + } + if (foundBed) { + event.setCancelled(true); + } + } + } + } + + @EventHandler + public void Create(SignChangeEvent event) { + String top = event.getLine(0); + if (top.equalsIgnoreCase("[HungerArena]") || top.equalsIgnoreCase("[HA]") || top.equalsIgnoreCase("[Sponsor]")) { + event.setLine(0, ChatColor.BLUE + top); + } + } +} + diff --git a/src/main/java/me/Travja/HungerArena/Listeners/SignsAndBedsOld.java b/src/main/java/me/Travja/HungerArena/Listeners/SignsAndBedsOld.java new file mode 100644 index 0000000..f1653f1 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/SignsAndBedsOld.java @@ -0,0 +1,72 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.ChatColor; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class SignsAndBedsOld implements Listener { + public Main plugin; + + public SignsAndBedsOld(Main m) { + this.plugin = m; + } + + @SuppressWarnings("deprecation") + @EventHandler + public void Sign(PlayerInteractEvent event) { + Player p = event.getPlayer(); + Block b = event.getClickedBlock(); + if (b == null) { + return; + } + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (b.getState() instanceof org.bukkit.block.Sign) { + org.bukkit.block.Sign sign = (org.bukkit.block.Sign) b.getState(); + String line1 = sign.getLine(0); + String line2 = sign.getLine(1); + String line3 = sign.getLine(2); + String line4 = sign.getLine(3); + if (line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[HungerArena]") || line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[HA]")) { + if (!line2.equals("") && line3.equals("")) { + p.performCommand("ha " + line2); + } else if (line2.equals("") && !line3.equals("")) { + p.performCommand("ha " + line3); + } else if (!line2.equals("") && !line3.equals("")) { + String commands = "close,join,kick,leave,list,open,ready,refill,reload,restart,rlist,tp,start,watch,warpall"; + if (commands.contains(line3.trim().toLowerCase())) { + p.performCommand("ha " + line2); + p.performCommand("ha " + line3); + } else { + p.performCommand("ha " + line2 + " " + line3); + } + } else { + p.performCommand("ha"); + } + } + if (line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[Sponsor]")) { + p.performCommand("sponsor " + line2 + " " + line3 + " " + line4); + } + } + + if (plugin.config.getString("DenyBedUsage").trim().equalsIgnoreCase("true")) { + if (b.getState().getData() instanceof org.bukkit.material.Bed) { + event.setCancelled(true); + } + } + } + } + + @EventHandler + public void Create(SignChangeEvent event) { + String top = event.getLine(0); + if (top.equalsIgnoreCase("[HungerArena]") || top.equalsIgnoreCase("[HA]") || top.equalsIgnoreCase("[Sponsor]")) { + event.setLine(0, ChatColor.BLUE + top); + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/SpectatorListener.java b/src/main/java/me/Travja/HungerArena/Listeners/SpectatorListener.java new file mode 100644 index 0000000..8ef6261 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/SpectatorListener.java @@ -0,0 +1,195 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityPickupItemEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.projectiles.ProjectileSource; +import org.bukkit.scoreboard.DisplaySlot; + +public class SpectatorListener implements Listener { + public Main plugin; + + public SpectatorListener(Main m) { + this.plugin = m; + } + + int i = 0; + + @EventHandler + public void SpectatorDrops(PlayerDropItemEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorInteractBlock(PlayerInteractEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorInteractEntity(PlayerInteractEntityEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorItems(EntityPickupItemEvent event) { + if (event.getEntity() instanceof Player) { + Player p = (Player) event.getEntity(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + } + + @EventHandler + public void SpectatorPvP(EntityDamageByEntityEvent event) { + Entity offense = event.getDamager(); + if (offense instanceof Player) { + Player Attacker = (Player) event.getDamager(); + String attackerName = Attacker.getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(attackerName)) { + event.setCancelled(true); + Attacker.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + return; + } + } + } + for (int i : plugin.Playing.keySet()) { + if (plugin.Playing.get(i) != null) { + if (plugin.Playing.get(i).contains(attackerName)) { + event.setCancelled(true); + } + } + } + } else if (event.getDamager() instanceof Projectile) { + Projectile arrow = (Projectile) offense; + ProjectileSource shooter = arrow.getShooter(); + if (shooter instanceof Player) { + Player BowMan = (Player) shooter; + String bowManName = BowMan.getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(bowManName)) { + event.setCancelled(true); + BowMan.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + return; + } + } + } + for (int i : plugin.Playing.keySet()) { + if (plugin.Playing.get(i) != null) { + if (plugin.Playing.get(i).contains(bowManName)) { + event.setCancelled(true); + } + } + } + } + } + } + + @EventHandler + public void SpectatorBlockBreak(BlockBreakEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorBlockPlace(BlockPlaceEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorQuit(PlayerQuitEvent event) { + Player p = event.getPlayer(); + String pname = p.getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(pname)) { + plugin.Watching.get(i).remove(pname); + String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + p.teleport(Spawn); + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + if (plugin.scoreboards.containsKey(p.getName())) { + plugin.scoreboards.remove(p.getName()); + } + if (plugin.Kills.containsKey(p.getName())) { + plugin.Kills.remove(p.getName()); + } + } + } + } + } + + @EventHandler + public void MobNerf(EntityTargetEvent event) { + Entity target = event.getTarget(); + Entity e = event.getEntity(); + if (e instanceof Player) { + return; + } + if (target instanceof Player) { + String targetName = ((Player) target).getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(targetName)) { + event.setTarget(null); + } + } + } + } + } + + private boolean denyInteraction(Player p) { + String pname = p.getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(pname)) { + return true; + } + } + } + return false; + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/SpectatorListenerOld.java b/src/main/java/me/Travja/HungerArena/Listeners/SpectatorListenerOld.java new file mode 100644 index 0000000..d02b1f7 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/SpectatorListenerOld.java @@ -0,0 +1,193 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.player.*; +import org.bukkit.projectiles.ProjectileSource; +import org.bukkit.scoreboard.DisplaySlot; + +public class SpectatorListenerOld implements Listener { + public Main plugin; + + public SpectatorListenerOld(Main m) { + this.plugin = m; + } + + int i = 0; + + @EventHandler + public void SpectatorDrops(PlayerDropItemEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorInteractBlock(PlayerInteractEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorInteractEntity(PlayerInteractEntityEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @SuppressWarnings("deprecation") + @EventHandler + public void SpectatorItems(PlayerPickupItemEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + + } + + private boolean denyInteraction(Player p) { + String pname = p.getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(pname)) { + return true; + } + } + } + return false; + } + + + @EventHandler + public void SpectatorPvP(EntityDamageByEntityEvent event) { + Entity offense = event.getDamager(); + if (offense instanceof Player) { + Player Attacker = (Player) event.getDamager(); + String attackerName = Attacker.getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(attackerName)) { + event.setCancelled(true); + Attacker.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + return; + } + } + } + for (int i : plugin.Playing.keySet()) { + if (plugin.Playing.get(i) != null) { + if (plugin.Playing.get(i).contains(attackerName)) { + event.setCancelled(true); + } + } + } + } else if (event.getDamager() instanceof Projectile) { + Projectile arrow = (Projectile) offense; + ProjectileSource shooter = arrow.getShooter(); + if (shooter instanceof Player) { + Player BowMan = (Player) shooter; + String bowManName = BowMan.getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(bowManName)) { + event.setCancelled(true); + BowMan.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + return; + } + } + } + for (int i : plugin.Playing.keySet()) { + if (plugin.Playing.get(i) != null) { + if (plugin.Playing.get(i).contains(bowManName)) { + event.setCancelled(true); + } + } + } + } + } + } + + @EventHandler + public void SpectatorBlockBreak(BlockBreakEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorBlockPlace(BlockPlaceEvent event) { + Player p = event.getPlayer(); + if (denyInteraction(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorQuit(PlayerQuitEvent event) { + Player p = event.getPlayer(); + String pname = p.getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(pname)) { + plugin.Watching.get(i).remove(pname); + String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + p.teleport(Spawn); + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + if (plugin.scoreboards.containsKey(p.getName())) { + plugin.scoreboards.remove(p.getName()); + } + if (plugin.Kills.containsKey(p.getName())) { + plugin.Kills.remove(p.getName()); + } + } + } + } + } + + @EventHandler + public void MobNerf(EntityTargetEvent event) { + Entity target = event.getTarget(); + Entity e = event.getEntity(); + if (e instanceof Player) { + return; + } + if (target instanceof Player) { + String targetName = ((Player) target).getName(); + for (int i : plugin.Watching.keySet()) { + if (plugin.Watching.get(i) != null) { + if (plugin.Watching.get(i).contains(targetName)) { + event.setTarget(null); + } + } + } + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/TeleportListener.java b/src/main/java/me/Travja/HungerArena/Listeners/TeleportListener.java new file mode 100644 index 0000000..0d76d01 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/TeleportListener.java @@ -0,0 +1,33 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class TeleportListener implements Listener { + + public Main plugin; + + public TeleportListener(Main m) { + this.plugin = m; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onTP(PlayerTeleportEvent event) { + Player p = event.getPlayer(); + if (plugin.worldsNames.values().contains(event.getTo().getWorld().getName()) && plugin.Tele.contains(p)) { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are a dead tribute... How are you supposed to get back into the arena...."); + plugin.Tele.remove(p); + } else if (plugin.Tele.contains(p)) { + if (event.isCancelled()) { + event.setCancelled(false); + plugin.Tele.remove(p); + } + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/WorldChange.java b/src/main/java/me/Travja/HungerArena/Listeners/WorldChange.java new file mode 100644 index 0000000..b8cc454 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/WorldChange.java @@ -0,0 +1,58 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChangedWorldEvent; + +public class WorldChange implements Listener { + public Main plugin; + + public WorldChange(Main m) { + plugin = m; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void worldChangeLow(PlayerChangedWorldEvent event) { + Player p = event.getPlayer(); + String pname = p.getName(); + String ThisWorld = p.getWorld().getName(); + String FromWorld = event.getFrom().getName(); + if (!plugin.worldsNames.values().contains(ThisWorld) && plugin.worldsNames.values().contains(FromWorld)) { + plugin.RestoreInv(p, pname); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void worldChangeHigh(PlayerChangedWorldEvent event) { + Player p = event.getPlayer(); + String pname = p.getName(); + String ThisWorld = p.getWorld().getName(); + int a = 0; + for (int i : plugin.worldsNames.keySet()) { + if (plugin.worldsNames.get(i) != null) { + if (plugin.worldsNames.get(i).equals(ThisWorld)) { + a = i; + if (plugin.Frozen.get(a) != null && plugin.Frozen.get(a).contains(pname)) { + return; + } else { + plugin.RestoreInv(p, pname); + if (plugin.config.getString("joinTeleport").equalsIgnoreCase("true")) { + String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + a).split(","); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + Location Spawn = new Location(p.getWorld(), spawnx, spawny, spawnz); + if (!p.getLocation().getBlock().equals(Spawn.getBlock())) { + p.teleport(Spawn); + } + } + } + } + } + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/Listeners/spawnsListener.java b/src/main/java/me/Travja/HungerArena/Listeners/spawnsListener.java new file mode 100644 index 0000000..1d9c880 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Listeners/spawnsListener.java @@ -0,0 +1,61 @@ +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import java.util.Collection; + +public class spawnsListener implements Listener { + public Main plugin; + + public spawnsListener(Main m) { + this.plugin = m; + } + + @EventHandler + public void interact(PlayerInteractEvent event) { + Player p = event.getPlayer(); + if (plugin.setting.containsKey(p.getName())) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Location l = event.getClickedBlock().getLocation(); + String HandItem; + try { + HandItem = p.getInventory().getItemInMainHand().getType().name(); + } catch (Exception e) { + HandItem = p.getItemInHand().getType().name(); + } + if (HandItem == plugin.config.getString("spawnsTool")) { + String[] info = plugin.setting.get(p.getName()).split("-"); + if (Integer.parseInt(info[1]) != plugin.config.getInt("maxPlayers") + 1) { + String coords = l.getWorld().getName() + " " + ((double) l.getX() + .5) + " " + ((double) l.getY() + 1) + " " + ((double) l.getZ() + .5); + + int arena = Integer.parseInt(info[0]); + if (plugin.spawns.get("Spawns." + arena) != null) { + Collection temp = plugin.spawns.getConfigurationSection("Spawns." + arena).getValues(false).values(); + if (temp.contains(coords.trim().replace(' ', ','))) { + event.setCancelled(true); + return; + } + } + + p.performCommand("startpoint " + info[0] + " " + info[1] + " " + coords); + + if (Integer.parseInt(info[1]) >= plugin.config.getInt("maxPlayers")) { + p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "All spawns set!"); + plugin.setting.remove(p.getName()); + } else { + plugin.setting.put(p.getName(), info[0] + "-" + (Integer.parseInt(info[1]) + 1)); + p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Next starting point: " + (Integer.parseInt(info[1]) + 1)); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/me/Travja/HungerArena/Main.java b/src/main/java/me/Travja/HungerArena/Main.java new file mode 100644 index 0000000..c3192c3 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/Main.java @@ -0,0 +1,1258 @@ +package me.Travja.HungerArena; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Collection; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import me.Travja.HungerArena.Listeners.BlockStorage; +import me.Travja.HungerArena.Listeners.WorldChange; +import me.Travja.HungerArena.Listeners.Boundaries; +import me.Travja.HungerArena.Listeners.ChatListener; +import me.Travja.HungerArena.Listeners.DeathListener; +import me.Travja.HungerArena.Listeners.FreezeListener; +import me.Travja.HungerArena.Listeners.JoinAndQuitListener; +import me.Travja.HungerArena.Listeners.PvP; +import me.Travja.HungerArena.Listeners.SignsAndBeds; +import me.Travja.HungerArena.Listeners.SignsAndBedsOld; +import me.Travja.HungerArena.Listeners.SpectatorListener; +import me.Travja.HungerArena.Listeners.SpectatorListenerOld; +import me.Travja.HungerArena.Listeners.TeleportListener; +import me.Travja.HungerArena.Listeners.spawnsListener; +import net.milkbowl.vault.economy.Economy; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.FireworkEffect.Type; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandExecutor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.material.MaterialData; +import org.bukkit.material.Torch; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +public class Main extends JavaPlugin { + static Logger log; + public HashMap> Playing = new HashMap>(); + public HashMap> Ready = new HashMap>(); + public HashMap> Dead = new HashMap>(); + public HashMap MatchRunning = new HashMap(); + public HashMap canjoin = new HashMap(); + public HashMap open = new HashMap(); + private HashMap CountT = new HashMap(); + public HashMap> Quit = new HashMap>(); + public HashMap> Out = new HashMap>(); + public HashMap> Watching = new HashMap>(); + public HashMap Kills = new HashMap(); + public HashMap> NeedConfirm = new HashMap>(); + public HashMap> location = new HashMap>(); + public HashMap> inArena = new HashMap>(); + public HashMap> Frozen = new HashMap>(); + public HashMap> arena = new HashMap>(); + public HashMap maxPlayers = new HashMap(); + public HashMap setting = new HashMap(); + public HashMap gp = new HashMap(); + public ArrayList Tele = new ArrayList(); + public ArrayList needInv = new ArrayList(); + public HashMap worldsNames = new HashMap(); + + public HashMap scoreboards = new HashMap(); + + Listener DeathListener = new DeathListener(this); + Listener SpectatorListener = null; + Listener SpectatorListenerOld = null; + Listener FreezeListener = new FreezeListener(this); + Listener JoinAndQuitListener = new JoinAndQuitListener(this); + Listener ChatListener = new ChatListener(this); + Listener Chests = new Chests(this); + Listener PvP = new PvP(this); + Listener CommandBlock = new CommandBlock(this); + Listener Teleport = new TeleportListener(this); + SignsAndBeds SignsAndBeds = null; + SignsAndBedsOld SignsAndBedsOld = null; + Listener BlockStorage = new BlockStorage(this); + //Listener WinGames = new WinGamesListener(this); + Listener WorldChange = new WorldChange(this); + Listener Boundaries = new Boundaries(this); + Listener spawnsListener = new spawnsListener(this); + CommandExecutor HaCommands = new HaCommands(this); + CommandExecutor SponsorCommands = new SponsorCommands(this); + CommandExecutor SpawnsCommand = new SpawnsCommand(this); + + public boolean exists; + public boolean restricted; + + public FileConfiguration config; + public FileConfiguration spawns = null; + public File spawnsFile = null; + public FileConfiguration data = null; + public File dataFile = null; + public FileConfiguration management = null; + public File managementFile = null; + + public FileConfiguration MyChests = null; + public File ChestsFile = null; + + public ArrayList Reward = new ArrayList(); + public ArrayList Cost = new ArrayList(); + public ArrayList Fee = new ArrayList(); + public ArrayList ChestPay = new ArrayList(); + + public boolean vault = false; + public boolean eco = false; + public Economy econ = null; + + int i = 0; + int v = 0; + int a = 0; + + File PFilePath = new File(getDataFolder(), "/inventories"); + + public void onEnable() { + log = this.getLogger(); + + getConfig().options().copyDefaults(true); + getConfig().options().copyHeader(true); + saveDefaultConfig(); + saveConfig(); + config = getConfig(); + spawns = getSpawns(); + data = getData(); + data.options().copyDefaults(true); + if (!new File(this.getDataFolder(), "Data.yml").exists()) { + this.saveData(); + } + management = this.getManagement(); + management.options().copyDefaults(true); + if (!new File(this.getDataFolder(), "commandAndBlockManagement.yml").exists()) { + this.saveManagement(); + } + MyChests = this.getChests(); + MyChests.options().copyDefaults(true); + if (!new File(this.getDataFolder(), "Chests.yml").exists()) { + this.saveChests(); + } + getServer().getPluginManager().registerEvents(DeathListener, this); + getServer().getPluginManager().registerEvents(FreezeListener, this); + getServer().getPluginManager().registerEvents(JoinAndQuitListener, this); + getServer().getPluginManager().registerEvents(ChatListener, this); + getServer().getPluginManager().registerEvents(Chests, this); + getServer().getPluginManager().registerEvents(PvP, this); + getServer().getPluginManager().registerEvents(CommandBlock, this); + + try { + Class.forName("org.bukkit.Tag"); + SignsAndBeds = new SignsAndBeds(this); + getServer().getPluginManager().registerEvents(SignsAndBeds, this); + SpectatorListener = new SpectatorListener(this); + getServer().getPluginManager().registerEvents(SpectatorListener, this); + getLogger().info("Events 1.13+ enabled!"); + } catch (NoClassDefFoundError | ClassNotFoundException exp) { + SignsAndBedsOld = new SignsAndBedsOld(this); + getServer().getPluginManager().registerEvents(SignsAndBedsOld, this); + SpectatorListenerOld = new SpectatorListenerOld(this); + getServer().getPluginManager().registerEvents(SpectatorListenerOld, this); + getLogger().info("Events 1.12- enabled!"); + } + getServer().getPluginManager().registerEvents(BlockStorage, this); + //getServer().getPluginManager().registerEvents(WinGames, this); + getServer().getPluginManager().registerEvents(WorldChange, this); + getServer().getPluginManager().registerEvents(Boundaries, this); + getServer().getPluginManager().registerEvents(spawnsListener, this); + + getCommand("Ha").setExecutor(HaCommands); + getCommand("Sponsor").setExecutor(SponsorCommands); + getCommand("Startpoint").setExecutor(SpawnsCommand); + + if (!PFilePath.exists()) { + PFilePath.mkdirs(); + } + for (File file : PFilePath.listFiles()) { + String filename = file.getName(); + int lastIndex = filename.lastIndexOf('.'); + filename = filename.substring(0, lastIndex >= 0 ? lastIndex : 0); + needInv.add(filename); + } + + i = 1; + + this.reloadSpawnpoints(true); + + if (setupEconomy()) { + log.info("Found Vault! Hooking in for economy!"); + } + if (config.getDouble("config.version") != 1.4) { + config.set("config.version", 1.4); + config.set("rewardEco.enabled", false); + config.set("rewardEco.reward", 100); + } + if (config.getBoolean("rewardEco.enabled", true) || config.getBoolean("sponsorEco.enabled", true) || config.getBoolean("EntryFee.eco", true)) { + if (vault == true) { + log.info("Economy hook deployed."); + eco = true; + } else { + log.info("You want economy support... yet you either don't have Vault or don't have an economy plugin. Sorry, can't give you it."); + } + } + if (!eco) { + if (vault == true) { + log.info("We see that you have Vault on your server. To set economy support to true, enable it in the config."); + } + } + try { + List RewardItemList = new ArrayList(); + List SponsorItemList = new ArrayList(); + List EntryfeeItemList = new ArrayList(); + List PayForChests = new ArrayList(); + + for (String rewards : config.getStringList("Reward")) { + String[] rinfo = rewards.split(","); + Material NewMat = getNewMaterial(rinfo[0], 0); + if (NewMat != null) { + Reward.add(new ItemStack(NewMat, Integer.parseInt(rinfo[1]))); + RewardItemList.add(NewMat.name() + "," + Integer.parseInt(rinfo[1])); + } + } + config.set("Reward", RewardItemList); + + for (String scost : config.getStringList("Sponsor_Cost")) { + String[] sinfo = scost.split(","); + Material NewMat = getNewMaterial(sinfo[0], 0); + if (NewMat != null) { + Cost.add(new ItemStack(NewMat, Integer.parseInt(sinfo[1]))); + SponsorItemList.add(NewMat.name() + "," + Integer.parseInt(sinfo[1])); + } + } + config.set("Sponsor_Cost", SponsorItemList); + + if (config.getBoolean("EntryFee.enabled")) { + for (String fee : config.getStringList("EntryFee.fee")) { + String[] finfo = fee.split(","); + Material NewMat = getNewMaterial(finfo[0], 0); + if (NewMat != null) { + Fee.add(new ItemStack(NewMat, Integer.parseInt(finfo[1]))); + EntryfeeItemList.add(NewMat.name() + "," + Integer.parseInt(finfo[1])); + } + } + config.set("EntryFee.fee", EntryfeeItemList); + } + + if (config.getBoolean("ChestPay.enabled")) { + for (String paychests : config.getStringList("ChestPay.items")) { + String[] rew = paychests.split(","); + Material NewMat = getNewMaterial(rew[0], 0); + if (NewMat != null) { + ChestPay.add(new ItemStack(NewMat, Integer.parseInt(rew[1]))); + PayForChests.add(NewMat.name() + "," + Integer.parseInt(rew[1])); + } + } + config.set("ChestPay.items", PayForChests); + } + + ArrayList newList = new ArrayList(); + for (String block : management.getStringList("blocks.whitelist")) { + Material NewMat = getNewMaterial(block, 0); + if (NewMat != null) { + newList.add(NewMat.name()); + } + } + management.set("blocks.whitelist", newList); + this.saveManagement(); + } catch (Exception e) { + log.warning("Could not add a reward/sponsor/entry cost or whitelist/blacklist! One of them is wrong!"); + } + + try { + String spt = config.getString("spawnsTool"); + if (!spt.trim().toLowerCase().contains("[a-z]")) { + config.set("spawnsTool", getNewMaterial(spt, 0).name()); + } + } catch (Exception e) { + } + restricted = config.getBoolean("Restricted"); + saveConfig(); + scoreboardInit(); + log.info("Enabled v" + getDescription().getVersion()); + } + + public Material getNewMaterial(String base, int data) { + Material NewMat = null; + if (Material.getMaterial(base) != null) { + NewMat = Material.getMaterial(base); + } else if (base.replaceAll("[0-9]", "").equals("")) { + NewMat = findOldMaterial(Integer.parseInt(base), (byte) data); + } else { + try { + NewMat = Material.getMaterial(base, true); + } catch (NoSuchMethodError n) { + } + } + return NewMat; + } + + public Material findOldMaterial(int typeId, byte dataValue) { + for (Material i : EnumSet.allOf(Material.class)) { + try { + if (i.getId() == typeId) { + return Bukkit.getUnsafe().fromLegacy(new MaterialData(i, dataValue)); + } + } catch (IllegalArgumentException | NoSuchMethodError e) { + try { + if (i.getId() == typeId) { + return new MaterialData(i, dataValue).getItemType(); + } + } catch (IllegalArgumentException ee) { + } + } + } + return null; + } + + + public void onDisable() { + log.info("Disabled v" + getDescription().getVersion()); + } + + public void reloadSpawnpoints(boolean verbose) { + if (spawns.getConfigurationSection("Spawns") != null) { + Map temp = spawns.getConfigurationSection("Spawns").getValues(false); + for (Entry entry : temp.entrySet()) { + if (spawns.getConfigurationSection("Spawns." + entry.getKey()) != null) { + Integer a = Integer.parseInt(entry.getKey()); + worldsNames.put(a, "none_meening_this_is_not_a_map"); + if (location.get(a) == null) { + location.put(a, new HashMap()); + } + Map temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false); + for (Map.Entry e : temp2.entrySet()) { + if (spawns.get("Spawns." + entry.getKey() + "" + e.getKey()) != null) { + if (!e.getKey().equals("Max") || !e.getKey().equals("Min")) { + String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "" + e.getKey())).split(","); + Integer s = Integer.parseInt(e.getKey()); + location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3]))); + worldsNames.put(a, coords[0]); + } + } + } + } + } + } + + for (int i : location.keySet()) { + if (location.get(i).size() != 0) { + if (verbose) { + log.info("Loaded " + location.get(i).size() + " tribute spawns for arena " + i + "!"); + } + Playing.put(i, new ArrayList()); + Ready.put(i, new ArrayList()); + Dead.put(i, new ArrayList()); + MatchRunning.put(i, null); + Quit.put(i, new ArrayList()); + Out.put(i, new ArrayList()); + Watching.put(i, new ArrayList()); + NeedConfirm.put(i, new ArrayList()); + inArena.put(i, new ArrayList()); + Frozen.put(i, new ArrayList()); + arena.put(i, new ArrayList()); + canjoin.put(i, false); + maxPlayers.put(i, location.get(i).size()); + open.put(i, true); + } + } + } + + public WorldEditPlugin hookWE() { + Plugin wPlugin = getServer().getPluginManager().getPlugin("WorldEdit"); + + if ((wPlugin == null) || (!(wPlugin instanceof WorldEditPlugin))) { + return null; + } + + return (WorldEditPlugin) wPlugin; + } + + public boolean setupEconomy() { + if (getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + econ = rsp.getProvider(); + vault = true; + return econ != null; + } + + public void reloadSpawns() { + if (spawnsFile == null) { + spawnsFile = new File(getDataFolder(), "spawns.yml"); + } + if (!spawnsFile.exists()) { + this.saveResource("spawns.yml", false); + } + + spawns = YamlConfiguration.loadConfiguration(spawnsFile); + + InputStream defConfigStream = this.getResource("spawns.yml"); + if (defConfigStream != null) { + YamlConfiguration defConfig = loadConfigStream(defConfigStream); + if (defConfig != null) { + spawns.addDefaults(defConfig); + spawns.options().copyHeader(true); + spawns.options().copyDefaults(true); + saveSpawns(); + } + } + if (spawns.getString("Spawns_set") != null && (spawns.getString("Spawns_set").equalsIgnoreCase("false") || spawns.getString("Spawns_set").equalsIgnoreCase("true"))) { + String temp = spawns.getString("Spawns_set"); + spawns.set("Spawns_set", null); + spawns.set("Spawns_set.0", temp); + temp = spawns.getString("Spawn_coords"); + spawns.set("Spawn_coords", null); + spawns.set("Spawn_coords.0", temp); + if (spawns.getConfigurationSection("Spawns") != null) { + Set temp2 = spawns.getConfigurationSection("Spawns").getValues(false).keySet(); + for (String entry : temp2) { + if (spawns.getString("Spawns_set_" + entry) != null) { + spawns.set("Spawns_set." + entry, spawns.getString("Spawns_set_" + entry)); + spawns.set("Spawns_set_" + entry, null); + } + if (spawns.getString("Spawn_coords_" + entry) != null) { + spawns.set("Spawn_coords." + entry, spawns.getString("Spawn_coords_" + entry)); + spawns.set("Spawn_coords_" + entry, null); + } + } + } + saveSpawns(); + } + } + + public FileConfiguration getSpawns() { + if (spawns == null) { + this.reloadSpawns(); + } + return spawns; + } + + public void saveSpawns() { + if (spawns == null || spawnsFile == null) { + return; + } + try { + getSpawns().save(spawnsFile); + } catch (IOException ex) { + this.getLogger().log(Level.SEVERE, "Could not save config to " + spawnsFile, ex); + } + } + + public void reloadData() { + if (dataFile == null) { + dataFile = new File(getDataFolder(), "Data.yml"); + } + if (!dataFile.exists()) { + this.saveResource("Data.yml", false); + } + + data = YamlConfiguration.loadConfiguration(dataFile); + + InputStream defConfigStream = this.getResource("Data.yml"); + if (defConfigStream != null) { + YamlConfiguration defConfig = loadConfigStream(defConfigStream); + if (defConfig != null) { + data.addDefaults(defConfig); + data.options().copyHeader(true); + data.options().copyDefaults(true); + saveData(); + } + } + } + + public FileConfiguration getData() { + if (data == null) { + this.reloadData(); + } + return data; + } + + public void saveData() { + if (data == null || dataFile == null) { + return; + } + try { + getData().save(dataFile); + } catch (IOException ex) { + this.getLogger().log(Level.SEVERE, "Could not save config to " + dataFile, ex); + } + } + + public void reloadManagement() { + if (managementFile == null) { + managementFile = new File(getDataFolder(), "commandAndBlockManagement.yml"); + } + if (!managementFile.exists()) { + this.saveResource("commandAndBlockManagement.yml", false); + } + + management = YamlConfiguration.loadConfiguration(managementFile); + + InputStream defConfigStream = this.getResource("commandAndBlockManagement.yml"); + if (defConfigStream != null) { + YamlConfiguration defConfig = loadConfigStream(defConfigStream); + if (defConfig != null) { + management.addDefaults(defConfig); + management.options().copyHeader(true); + management.options().copyDefaults(true); + saveManagement(); + } + } + } + + public FileConfiguration getManagement() { + if (management == null) { + this.reloadManagement(); + } + return management; + } + + public void saveManagement() { + if (management == null || managementFile == null) { + return; + } + try { + getManagement().save(managementFile); + } catch (IOException ex) { + this.getLogger().log(Level.SEVERE, "Could not save config to " + managementFile, ex); + } + } + + public void reloadChests() { + if (ChestsFile == null) { + ChestsFile = new File(getDataFolder(), "Chests.yml"); + } + MyChests = YamlConfiguration.loadConfiguration(ChestsFile); + } + + public FileConfiguration getChests() { + if (MyChests == null) { + this.reloadChests(); + } + return MyChests; + } + + public void saveChests() { + if (MyChests == null || ChestsFile == null) { + return; + } + try { + getChests().save(ChestsFile); + } catch (IOException ex) { + this.getLogger().log(Level.SEVERE, "Could not save config to " + ChestsFile, ex); + } + } + + File PFile = null; + FileConfiguration PConfig = null; + + public void reloadPFile(String pname) { + if (PFile == null) { + PFile = new File(PFilePath, pname + ".yml"); + } + PConfig = YamlConfiguration.loadConfiguration(PFile); + InputStream defConfigStream = this.getResource("Player.yml"); + if (defConfigStream != null) { + YamlConfiguration defConfig = loadConfigStream(defConfigStream); + if (defConfig != null) { + this.PConfig.setDefaults(defConfig); + } + } + } + + private YamlConfiguration loadConfigStream(InputStream defConfigStream) { + Reader defaultConfigReader = null; + YamlConfiguration defConfig = null; + if (defConfigStream != null) { + try { + defaultConfigReader = new java.io.InputStreamReader(defConfigStream, "UTF-8"); + } catch (UnsupportedEncodingException e) { + log.info("The embedded resource contained in the plugin jar file has an unsupported encoding.It should be encoded with UTF-8."); + } + } + + if (defaultConfigReader != null) { + defConfig = YamlConfiguration.loadConfiguration(defaultConfigReader); + } else { + log.warning("A default resource in the plugin jar could not be read."); + } + try { + if (defaultConfigReader != null) { + defaultConfigReader.close(); + } + } catch (IOException e) { + log.warning("An error occured while trying to close the resource file."); + } + return defConfig; + } + + public FileConfiguration getPConfig(String pname) { + PFile = null; + this.reloadPFile(pname); + return PConfig; + } + + public void savePFile(String pname) { + if (PConfig.getString("player").equals(pname)) { + try { + this.PConfig.save(PFile); + } catch (IOException ex) { + this.getLogger().log(Level.SEVERE, "Could not save config to " + PFile, ex); + } + } else { + this.getLogger().log(Level.SEVERE, "Could not save config to " + pname + ".yml ! It's not this players inventory!?"); + } + } + + @SuppressWarnings("unchecked") + public void RestoreInv(Player p, String pname) { + for (int u : Playing.keySet()) { + if (Playing.get(u) != null) { + if (Playing.get(u).contains(pname)) { + Playing.get(u).remove(pname); + p.sendMessage(ChatColor.AQUA + "You have left the game!"); + if (config.getBoolean("broadcastAll")) { + p.getServer().broadcastMessage(ChatColor.RED + pname + " Left Arena " + u + "!"); + } else { + for (String gn : Playing.get(u)) { + Player g = getServer().getPlayer(gn); + g.sendMessage(ChatColor.RED + pname + " Quit!"); + } + } + if (canjoin.get(u) == true) { + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + scoreboards.remove(p.getName()); + Kills.remove(p.getName()); + } + + } + } + if (Ready.get(u) != null) { + if (Ready.get(u).contains(pname)) { + Ready.get(u).remove(pname); + } + } + } + if (new File(PFilePath, pname + ".yml").exists()) { + FileConfiguration pinfo = this.getPConfig(pname); + if ((pinfo.getString("player").equals(pname)) && (this.needInv.contains(pname))) { + try { + ItemStack[] pinv = null; + Object o = pinfo.get("inv"); + if (o instanceof ItemStack[]) { + pinv = (ItemStack[]) o; + } else if (o instanceof List) { + pinv = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); + } + p.getInventory().setContents(pinv); + p.updateInventory(); + + ItemStack[] parmor = null; + o = pinfo.get("armor"); + if (o instanceof ItemStack[]) { + parmor = (ItemStack[]) o; + } else if (o instanceof List) { + parmor = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); + } + p.getInventory().setArmorContents(parmor); + p.updateInventory(); + + p.sendMessage(ChatColor.GOLD + "[HA] " + ChatColor.GREEN + "Your inventory has been restored!"); + new File(PFilePath, pname + ".yml").delete(); + + while (needInv.contains(pname)) { + needInv.remove(pname); + } + + } catch (Exception e) { + p.sendMessage(ChatColor.RED + "Something went wrong when trying to restore your inv, please contact an administrator."); + this.getLogger().warning("Error occured when trying to restore the inv of " + pname + ":"); + System.out.println(e); + } + } + } + if (p.hasMetadata("HA-Location")) { + p.removeMetadata("HA-Location", this); + } + } + + public void winner(final Integer a) { + if (Playing.get(a).size() == 1) { + String[] Spawncoords; + if (spawns.getString("Spawn_coords." + a) != null) { + Spawncoords = spawns.getString("Spawn_coords." + a).split(","); + } else { + Spawncoords = spawns.getString("Spawn_coords.0").split(","); + } + World spawnw = getServer().getWorld(Spawncoords[3]); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + + for (i = 0; i < Playing.get(a).size(); i++) { + String winnername = Playing.get(a).get(i); + final Player winner = getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + if (canjoin.get(a) == true) { + getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); + } + winner.getInventory().clear(); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.setLevel(0); + for (PotionEffect pe : winner.getActivePotionEffects()) { + PotionEffectType potion = pe.getType(); + winner.removePotionEffect(potion); + } + Tele.add(winner); + needInv.add(winnername2); + + winner.teleport(Spawn); + + this.RestoreInv(winner, winnername2); + + if (canjoin.get(a) == true) { + winner.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + if (scoreboards.containsKey(winner.getName())) { + scoreboards.remove(winner.getName()); + } + if (Kills.containsKey(winner.getName())) { + Kills.remove(winner.getName()); + } + + //////////////////////////////////////////////////////// + //////////////////// FIREWORKS /////////////////////// + //////////////////////////////////////////////////////// + + + for (i = 0; i < 10; i++) { + Bukkit.getScheduler().runTaskLater(this, new Runnable() { + public void run() { + //Spawn the Fireworks, get the FireworkMeta. + Firework fw = (Firework) winner.getWorld().spawnEntity(winner.getLocation(), EntityType.FIREWORK); + FireworkMeta fwm = fw.getFireworkMeta(); + + //Our random generator + Random r = new Random(); + + //Get the type + int rt = r.nextInt(4) + 1; + Type type = Type.BALL; + if (rt == 1) { + type = Type.BALL; + } + if (rt == 2) { + type = Type.BALL_LARGE; + } + if (rt == 3) { + type = Type.BURST; + } + if (rt == 4) { + type = Type.CREEPER; + } + if (rt == 5) { + type = Type.STAR; + } + + //Get our random colours + int r1i = r.nextInt(17) + 1; + int r2i = r.nextInt(17) + 1; + Color c1 = getColor(r1i); + Color c2 = getColor(r2i); + + //Create our effect with this + FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build(); + + //Then apply the effect to the meta + fwm.addEffect(effect); + + //Generate some random power and set it + int rp = r.nextInt(2) + 1; + fwm.setPower(rp); + + //Then apply this to our rocket + fw.setFireworkMeta(fwm); + } + }, 20 + i * 20L); + } + + + //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////// + + if (!config.getBoolean("rewardEco.enabled")) { + for (ItemStack Rewards : Reward) { + winner.getInventory().addItem(Rewards); + } + } else { + for (ItemStack Rewards : Reward) { + winner.getInventory().addItem(Rewards); + } + econ.depositPlayer(winner, config.getDouble("rewardEco.reward")); + } + } + + if (deathtime.get(a) != null) { + getServer().getScheduler().cancelTask(deathtime.get(a)); + deathtime.put(a, null); + } + if (grace.get(a) != null) { + getServer().getScheduler().cancelTask(grace.get(a)); + grace.put(a, null); + } + if (start.get(a) != null) { + getServer().getScheduler().cancelTask(start.get(a)); + start.put(a, null); + } + } + Playing.get(a).clear(); + Quit.get(a).clear(); + Dead.get(a).clear(); + + //Show spectators + for (String s1 : Watching.get(a)) { + Player spectator = getServer().getPlayerExact(s1); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for (Player online : getServer().getOnlinePlayers()) { + online.showPlayer(this, spectator); + } + } + if (config.getString("Auto_Restart").equalsIgnoreCase("True")) { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + public void run() { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart " + a); + } + }, 220L); + } + MatchRunning.put(a, null); + } + } + + private Color getColor(int i) { + if (i == 1) { + return Color.AQUA; + } else if (i == 2) { + return Color.BLACK; + } else if (i == 3) { + return Color.BLUE; + } else if (i == 4) { + return Color.FUCHSIA; + } else if (i == 5) { + return Color.GRAY; + } else if (i == 6) { + return Color.GREEN; + } else if (i == 7) { + return Color.LIME; + } else if (i == 8) { + return Color.MAROON; + } else if (i == 9) { + return Color.NAVY; + } else if (i == 10) { + return Color.OLIVE; + } else if (i == 11) { + return Color.ORANGE; + } else if (i == 12) { + return Color.PURPLE; + } else if (i == 13) { + return Color.RED; + } else if (i == 14) { + return Color.SILVER; + } else if (i == 15) { + return Color.TEAL; + } else if (i == 16) { + return Color.WHITE; + } else { + return Color.YELLOW; + } + } + + private void scoreboardInit() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { + public void run() { + Collection online = getServer().getOnlinePlayers(); + for (Player pl : online) { + updateScoreboard(pl); + } + } + }, 20L, 10L); + } + + public void updateScoreboard(Player p) { + if (getArena(p) != null || isSpectating(p)) { + if (getArena(p) != null) { + a = getArena(p); + } else if (getSpectating(p) != null) { + a = getSpectating(p); + } + if (scoreboards.get(p.getName()) != null && scoreboards.get(p.getName()).getObjective("HA") != null) { + Scoreboard sb = scoreboards.get(p.getName()); + Objective obj = sb.getObjective("HA"); + if (obj != null) { + Score kills = obj.getScore(ChatColor.RED + "Kills"); + Score players = obj.getScore(ChatColor.RED + "Players"); + Score spectators = obj.getScore(ChatColor.RED + "Spectators"); + Score allkills = obj.getScore(ChatColor.RED + "Deaths"); + players.setScore(Playing.get(a).size()); + if (Kills.containsKey(p.getName())) { + kills.setScore(Kills.get(p.getName())); + } + if (Kills.containsKey("__SuM__")) { + allkills.setScore(Kills.get("__SuM__")); + } + + if (Watching.get(a) != null) { + spectators.setScore(Watching.get(a).size()); + } + if (config.getInt("DeathMatch") != 0) { + if (timetodeath.get(a) != null) { + if (timetodeath.get(a) > 0) { + int ttd = Integer.valueOf(timetodeath.get(a) - timetodeath.get(a) / 60 * 60); + String secs = String.valueOf((ttd < 10) ? "0" + ttd : ttd); + obj.setDisplayName(ChatColor.GREEN + "HA - DMTime: " + ChatColor.AQUA + Integer.valueOf(timetodeath.get(a) / 60) + ":" + secs); + } else { + obj.setDisplayName(ChatColor.GREEN + "HA - " + ChatColor.RED + "DEATHMATCH"); + } + } + } else { + obj.setDisplayName(ChatColor.GREEN + "HungerArena"); + } + p.setScoreboard(sb); + } + } + } + } + + public HashMap grace = new HashMap(); + public HashMap start = new HashMap(); + public HashMap deathtime = new HashMap(); + public HashMap timetodeath = new HashMap(); + + public void startGames(final int a) { + if ((MatchRunning.get(a) != null) && (MatchRunning.get(a).equals("true"))) { + return; + } + + final String msg = ChatColor.translateAlternateColorCodes('&', config.getString("Start_Message")); + for (String gn : Playing.get(a)) { + Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard(); + Objective sobj; + try { + sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting"); + } catch (NoSuchMethodError e) { + sobj = scoreboard.registerNewObjective("HA", "HAData"); + sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); + } + Score skills = sobj.getScore(ChatColor.RED + "Kills"); + skills.setScore(0); + Score sdeaths = sobj.getScore(ChatColor.RED + "Spectators"); + sdeaths.setScore(0); + Score splayers = sobj.getScore(ChatColor.RED + "Players"); + splayers.setScore(0); + Score allkills = sobj.getScore(ChatColor.RED + "Deaths"); + allkills.setScore(0); + sobj.setDisplaySlot(DisplaySlot.SIDEBAR); + Bukkit.getPlayer(gn).setScoreboard(scoreboard); + scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard()); + } + getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + a); + MatchRunning.put(a, "true"); + if (start.get(a) != null) { + getServer().getScheduler().cancelTask(start.get(a)); + } + if (config.getString("Countdown").equalsIgnoreCase("true")) { + CountT.put(a, (config.getInt("Countdown_Timer") != 0 ? config.getInt("Countdown_Timer") : 10)); + start.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { + public void run() { + if (CountT.get(a) > 0) { + if (!restricted) { + if (config.getBoolean("broadcastAll")) { + getServer().broadcastMessage(ChatColor.AQUA + "Game " + a + " starting in: " + String.valueOf(CountT.get(a))); + } else { + for (String gn : Playing.get(a)) { + Player g = getServer().getPlayer(gn); + g.sendMessage(ChatColor.AQUA + "Game starting in: " + String.valueOf(CountT.get(a))); + } + } + } else { + if (config.getBoolean("broadcastAll")) { + for (String world : worldsNames.values()) { + World w = getServer().getWorld(world); + for (Player wp : w.getPlayers()) { + wp.sendMessage(String.valueOf(CountT.get(a))); + } + } + } else { + for (String gn : Playing.get(a)) { + Player g = getServer().getPlayer(gn); + g.sendMessage(String.valueOf(CountT.get(a))); + } + } + } + } + CountT.put(a, CountT.get(a) - 1); + if (CountT.get(a) == -1) { + for (String gn : Playing.get(a)) { + Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard(); + Objective sobj; + try { + sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting"); + } catch (NoSuchMethodError e) { + sobj = scoreboard.registerNewObjective("HA", "HAData"); + sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); + } + Score skills = sobj.getScore(ChatColor.RED + "Kills"); + skills.setScore(0); + Score sdeaths = sobj.getScore(ChatColor.RED + "Spectators"); + sdeaths.setScore(0); + Score splayers = sobj.getScore(ChatColor.RED + "Players"); + splayers.setScore(0); + Score allkills = sobj.getScore(ChatColor.RED + "Deaths"); + allkills.setScore(0); + sobj.setDisplaySlot(DisplaySlot.SIDEBAR); + Bukkit.getPlayer(gn).setScoreboard(scoreboard); + scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard()); + } + if (Frozen.get(a) != null) { + Frozen.get(a).clear(); + } + if (config.getBoolean("broadcastAll")) { + getServer().broadcastMessage(msg); + } else { + for (String gn : Playing.get(a)) { + Player g = getServer().getPlayer(gn); + g.sendMessage(msg); + } + } + if (config.getInt("Grace_Period") != 0) { + gp.put(a, config.getInt("Grace_Period")); + if (grace.get(a) == null) { + grace.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable() { + public void run() { + gp.put(a, gp.get(a) - 1); + if (gp.get(a) == 30 || gp.get(a) == 15 || (gp.get(a) < 11 && gp.get(a) != 0)) { + if (config.getBoolean("broadcastAll")) { + for (Player wp : location.get(a).get(1).getWorld().getPlayers()) { + wp.sendMessage(ChatColor.GREEN + "Grace period ends in " + gp.get(a) + " seconds!"); + } + } else { + getServer().broadcastMessage(ChatColor.GREEN + "Grace period ends in " + gp.get(a) + " seconds!"); + } + } + if (gp.get(a) <= 0) { + if (config.getBoolean("broadcastAll")) { + for (Player wp : location.get(a).get(1).getWorld().getPlayers()) { + wp.sendMessage(ChatColor.GREEN + "Grace period is over, FIGHT!"); + } + } else { + getServer().broadcastMessage(ChatColor.GREEN + "Grace period is over, FIGHT!"); + } + getServer().getScheduler().cancelTask(grace.get(a)); + grace.put(a, null); + } + } + }, 20L, 20L)); + } + } + if (config.getInt("DeathMatch") != 0) { + int death = config.getInt("DeathMatch"); + timetodeath.put(a, death * 60); + if (deathtime.get(a) == null) { + deathtime.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable() { + public void run() { + timetodeath.put(a, timetodeath.get(a) - 1); + if (Integer.valueOf(timetodeath.get(a)) % 300 == 0) { + if (config.getBoolean("broadcastAll")) { + for (Player wp : location.get(a).get(1).getWorld().getPlayers()) { + if (timetodeath.get(a) != 0) { + wp.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a) / 60) + ChatColor.RED + " mins till the death match!"); + } + } + } else { + for (String gn : Playing.get(a)) { + Player g = getServer().getPlayer(gn); + g.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a)) + ChatColor.RED + " mins till the death match!"); + } + } + } + if (timetodeath.get(a) <= 0) { + int i = 1; + for (String playing : Playing.get(a)) { + Player tribute = getServer().getPlayerExact(playing); + + Location pLoc = null; + if (tribute.hasMetadata("HA-Location")) { + List l = tribute.getMetadata("HA-Location"); + if (l != null && l.size() != 0) { + try { + pLoc = (Location) l.get(0).value(); + } catch (Exception e) { + } + } + if (pLoc != null) { + tribute.teleport(pLoc); //random + } else { + tribute.teleport(location.get(a).get(i)); //row + } + } + i += 1; + for (PotionEffect pe : tribute.getActivePotionEffects()) { + PotionEffectType potion = pe.getType(); + tribute.removePotionEffect(potion); + } + if (tribute.getAllowFlight()) { + tribute.setAllowFlight(false); + } + } + if (config.getBoolean("broadcastAll")) { + for (Player wp : location.get(a).get(1).getWorld().getPlayers()) { + wp.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!"); + } + } else { + for (String gn : Playing.get(a)) { + Player g = getServer().getPlayer(gn); + g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!"); + } + } + StopTasksDelayed(deathtime.get(a)); + deathtime.put(a, null); + } + } + }, 20L, 20L)); + } + } + setTorch(a, true); + StopTasksDelayed(start.get(a)); + } + } + }, 20L, 20L)); + } else { + setTorch(a, true); + Frozen.get(a).clear(); + if (config.getBoolean("broadcastAll")) { + getServer().broadcastMessage(msg); + } else { + for (String gn : Playing.get(a)) { + Player g = getServer().getPlayer(gn); + g.sendMessage(msg); + } + } + } + canjoin.put(a, true); + } + + private void StopTasksDelayed(final int task) { + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + public void run() { + Bukkit.getScheduler().cancelTask(task); + } + }, 10L); + } + + public Integer getArena(Player p) { + for (int x : Playing.keySet()) { + if (Playing.get(x).contains(p.getName())) { + return x; + } + } + return null; + } + + public Integer getSpectating(Player p) { + for (int x : Watching.keySet()) { + if (Watching.get(x).contains(p.getName())) { + return x; + } + } + return null; + } + + public boolean isSpectating(Player p) { + for (int x : Watching.keySet()) { + if (Watching.get(x).contains(p.getName())) { + return true; + } + } + return false; + } + + public void setTorch(int a, boolean set) { + String arena = String.valueOf(a); + if (spawns.getString("Start_torch." + arena) != null) { + String[] Torchcoords = spawns.getString("Start_torch." + arena).split(","); + double torchx = Double.parseDouble(Torchcoords[0]); + double torchy = Double.parseDouble(Torchcoords[1]); + double torchz = Double.parseDouble(Torchcoords[2]); + String torchworld = Torchcoords[3]; + World torchw = getServer().getWorld(torchworld); + Location TorchLoc = new Location(torchw, torchx, torchy, torchz); + if (set) { + SetTorch(TorchLoc); + } else { + TorchLoc.getBlock().setType(Material.AIR); + } + } + } + + private void SetTorch(Location Baseblock) { + Block TorchBlock = Baseblock.getBlock(); + try { + Material Torch = (org.bukkit.Material.valueOf("REDSTONE_TORCH")); + if (Torch != null) { + TorchBlock.setType(Torch); + } + } catch (Exception ex) { + TorchBlock.setType(Material.REDSTONE_TORCH); + } + } +} diff --git a/src/main/java/me/Travja/HungerArena/SpawnsCommand.java b/src/main/java/me/Travja/HungerArena/SpawnsCommand.java new file mode 100644 index 0000000..e749459 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/SpawnsCommand.java @@ -0,0 +1,180 @@ +package me.Travja.HungerArena; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SpawnsCommand implements CommandExecutor { + public Main plugin; + int i = 0; + int a = 0; + boolean NoPlayerSpawns; + + public SpawnsCommand(Main m) { + this.plugin = m; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + String ThisWorld = p.getWorld().getName(); + NoPlayerSpawns = true; + for (int i : plugin.worldsNames.keySet()) { + if (plugin.worldsNames.get(i) != null) { + if (plugin.worldsNames.get(i).equals(ThisWorld)) { + a = i; + NoPlayerSpawns = false; + break; + } + } + } + if (cmd.getName().equalsIgnoreCase("StartPoint")) { + if (p.hasPermission("HungerArena.StartPoint")) { + Location loc = null; + double x; + double y; + double z; + if (args.length == 6) { + try { + i = Integer.valueOf(args[1]); + a = Integer.valueOf(args[0]); + } catch (Exception e) { + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return true; + } + + String world = args[2]; + x = Double.parseDouble(args[3]); + y = Double.parseDouble(args[4]); + z = Double.parseDouble(args[5]); + loc = new Location(Bukkit.getWorld(world), x, y, z); + if (plugin.location.get(a) != null) { + plugin.location.get(a).put(i, loc); + } else { + plugin.location.put(a, new HashMap()); + plugin.location.get(a).put(i, loc); + plugin.Playing.put(a, new ArrayList()); + plugin.Ready.put(a, new ArrayList()); + plugin.Dead.put(a, new ArrayList()); + plugin.Quit.put(a, new ArrayList()); + plugin.Out.put(a, new ArrayList()); + plugin.Watching.put(a, new ArrayList()); + plugin.NeedConfirm.put(a, new ArrayList()); + plugin.inArena.put(a, new ArrayList()); + plugin.Frozen.put(a, new ArrayList()); + plugin.arena.put(a, new ArrayList()); + plugin.canjoin.put(a, false); + plugin.MatchRunning.put(a, null); + plugin.open.put(a, true); + } + String coords = loc.getWorld().getName() + "," + (loc.getX()) + "," + loc.getY() + "," + (loc.getZ()); + p.sendMessage(coords); + plugin.spawns.set("Spawns." + a + "" + i, coords); + plugin.worldsNames.put(a, loc.getWorld().getName()); + plugin.saveSpawns(); + plugin.maxPlayers.put(a, plugin.location.get(a).size()); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + a + "!"); + this.plugin.reloadSpawnpoints(false); + return true; + } + if (args.length >= 2) { + try { + i = Integer.valueOf(args[1]); + a = Integer.valueOf(args[0]); + } catch (Exception e) { + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return true; + } + if (i >= 1 && i <= plugin.config.getInt("maxPlayers")) { + if (!plugin.worldsNames.values().contains(p.getWorld().getName())) { + p.sendMessage(ChatColor.GOLD + "You've added this world to the config ..."); + } + loc = p.getLocation().getBlock().getLocation(); + x = loc.getX() + .5; + y = loc.getY(); + z = loc.getZ() + .5; + loc = new Location(loc.getWorld(), x, y, z); + if (plugin.location.get(a) != null) { + plugin.location.get(a).put(i, loc); + } else { + plugin.location.put(a, new HashMap()); + plugin.location.get(a).put(i, loc); + plugin.Playing.put(a, new ArrayList()); + plugin.Ready.put(a, new ArrayList()); + plugin.Dead.put(a, new ArrayList()); + plugin.Quit.put(a, new ArrayList()); + plugin.Out.put(a, new ArrayList()); + plugin.Watching.put(a, new ArrayList()); + plugin.NeedConfirm.put(a, new ArrayList()); + plugin.inArena.put(a, new ArrayList()); + plugin.Frozen.put(a, new ArrayList()); + plugin.arena.put(a, new ArrayList()); + plugin.canjoin.put(a, false); + plugin.MatchRunning.put(a, null); + plugin.open.put(a, true); + } + String coords = loc.getWorld().getName() + "," + (loc.getX()) + "," + loc.getY() + "," + (loc.getZ()); + p.sendMessage(coords); + plugin.spawns.set("Spawns." + a + "" + i, coords); + plugin.worldsNames.put(a, loc.getWorld().getName()); + plugin.saveSpawns(); + plugin.maxPlayers.put(a, plugin.location.get(a).size()); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + a + "!"); + this.plugin.reloadSpawnpoints(false); + } else { + p.sendMessage(ChatColor.RED + "You can't go past " + plugin.config.getInt("maxPlayers") + " players!"); + } + } else if (args.length == 1) { + if (sender instanceof Player) { + p = (Player) sender; + if (NoPlayerSpawns) { + try { + a = Integer.parseInt(args[0]); + } catch (Exception e) { + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return true; + } + } + if (plugin.spawns.get("Spawns." + a) != null) { + int start = 1; + while (start < plugin.config.getInt("maxPlayers") + 2) { + if (plugin.spawns.get("Spawns." + a + "" + start) != null) { + start = start + 1; + if (start == plugin.config.getInt("maxPlayers") + 1) { + p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.GREEN + "All spawns set, type /startpoint [Arena #] [Spawn #] to over-ride previous points!"); + return true; + } + } else { + int sloc = start; + start = plugin.config.getInt("maxPlayers") + 1; + p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Begin Setting For Arena " + a + " Starting From Point " + sloc); + plugin.setting.put(p.getName(), a + "-" + sloc); + return true; + } + } + } + p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Begin Setting For Arena " + a + " Starting From Point " + 1); + plugin.setting.put(p.getName(), a + "-" + 1); + return true; + } else { + sender.sendMessage(ChatColor.BLUE + "This Can Only Be Sent As A Player"); + } + } else { + p.sendMessage(ChatColor.RED + "No argument given! \nUse command like this:\n/startpoint [Arena #] [Startpoint #] for setting your position as a startpoint.\n/startpoint [Arena #] [Startpoint #] [Mapname] [x] [y] [z] \nOr you can use /startpoint [Arena #] to use the 'spawntool': ID" + plugin.config.getInt("spawnsTool") + " for setting the startpoints!"); + return false; + } + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } + return false; + } + +} diff --git a/src/main/java/me/Travja/HungerArena/SponsorCommands.java b/src/main/java/me/Travja/HungerArena/SponsorCommands.java new file mode 100644 index 0000000..440bfc9 --- /dev/null +++ b/src/main/java/me/Travja/HungerArena/SponsorCommands.java @@ -0,0 +1,152 @@ +package me.Travja.HungerArena; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class SponsorCommands implements CommandExecutor { + public Main plugin; + + public SponsorCommands(Main m) { + this.plugin = m; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + if (cmd.getName().equalsIgnoreCase("Sponsor")) { + if (sender instanceof Player) { + Player p = (Player) sender; + if (p.hasPermission("HungerArena.Sponsor")) { + if (plugin.getArena(p) == null) { + if (args.length == 0) { + p.sendMessage(ChatColor.RED + "You didn't specify a tribute!"); + return false; + } + if (args.length == 1) { + p.sendMessage(ChatColor.RED + "You didn't specify an item!"); + } + if (args.length == 2) { + p.sendMessage(ChatColor.RED + "You didn't specify an amount!"); + } + if (args.length >= 3) { + Player target = Bukkit.getServer().getPlayer(args[0]); + if (target == null || (target != null && plugin.getArena(target) == null)) { + p.sendMessage(ChatColor.RED + "That person isn't playing!"); + } else { + try { + String ID = args[1].toUpperCase().trim(); + int amount = Integer.parseInt(args[2]); + if ((!plugin.management.getStringList("sponsors.blacklist").isEmpty() && !plugin.management.getStringList("sponsors.blacklist").contains(ID)) || plugin.management.getStringList("sponsors.blacklist").isEmpty()) { + handleItemsAndEco(p, args, ID, amount, target); + } else { + p.sendMessage(ChatColor.RED + "You can't sponsor that item!"); + p.sendMessage(ChatColor.GREEN + "Other items you can't sponsor are:"); + for (String blacklist : plugin.management.getStringList("sponsors.blacklist")) { + p.sendMessage(ChatColor.AQUA + blacklist); + } + } + } catch (Exception e) { + p.sendMessage(ChatColor.RED + "Something went wrong there... Make sure that you do like this /sponsor [name] [item] [number]"); + } + } + } + } else { + p.sendMessage(ChatColor.RED + "You are playing, you can't sponsor yourself!"); + } + } else { + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } else if (sender instanceof ConsoleCommandSender) { + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "You didn't specify a tribute!"); + return false; + } + if (args.length == 1) { + sender.sendMessage(ChatColor.RED + "You didn't specify an item!"); + } + if (args.length == 2) { + sender.sendMessage(ChatColor.RED + "You didn't specify an amount!"); + } + if (args.length >= 3) { + Player target = Bukkit.getPlayer(args[0]); + String ID = args[1].toUpperCase().trim(); + int Amount = Integer.parseInt(args[2]); + try { + if ((!plugin.management.getStringList("sponsors.blacklist").isEmpty() && !plugin.management.getStringList("sponsors.blacklist").contains(ID)) || plugin.management.getStringList("sponsors.blacklist").isEmpty()) { + ItemStack sponsoritem = new ItemStack(org.bukkit.Material.getMaterial(ID), Amount); + if (plugin.getArena(target) == null) { + sender.sendMessage(ChatColor.RED + "That person isn't playing!"); + } else { + sender.sendMessage(ChatColor.RED + "You can't sponsor yourself!"); + target.sendMessage(ChatColor.AQUA + "You have been Sponsored!"); + target.getInventory().addItem(sponsoritem); + sender.sendMessage("You have sponsored " + target.getName() + "!"); + } + } else { + sender.sendMessage(ChatColor.RED + "You can't sponsor that item!"); + sender.sendMessage(ChatColor.GREEN + "Other items you can't sponsor are:"); + for (String blacklist : plugin.management.getStringList("sponsors.blacklist")) { + sender.sendMessage(ChatColor.AQUA + blacklist); + } + } + } catch (Exception e) { + sender.sendMessage(ChatColor.RED + "Something went wrong there... Make sure that you do like this /sponsor [name] [number] [number]"); + } + } + } + } + return false; + } + + private void handleItemsAndEco(Player p, String[] args, String ID, int amount, Player target) { + Material sponsMat = plugin.getNewMaterial(ID, 0); + ItemStack sponsoritem; + boolean done = false; + if (sponsMat != null) { + sponsoritem = new ItemStack(sponsMat, amount); + } else { + p.sendMessage(ChatColor.RED + "That item does not exist !!"); + return; + } + for (ItemStack Costs : plugin.Cost) { + if (!p.getInventory().containsAtLeast(Costs, Costs.getAmount() * amount)) { + p.sendMessage(ChatColor.RED + "You don't have the necessary items to sponsor!"); + return; + } + } + if (args[0].equalsIgnoreCase(p.getName())) { + p.sendMessage(ChatColor.RED + "You can't sponsor yourself!"); + } else { + if (plugin.config.getBoolean("sponsorEco.enabled")) { + if (!(plugin.econ.getBalance(p) < (plugin.config.getDouble("sponsorEco.cost") * amount))) { + plugin.econ.withdrawPlayer(p, plugin.config.getDouble("sponsorEco.cost") * amount); + done = true; + } else { + p.sendMessage(ChatColor.RED + "You don't have enough money to do that!"); + return; + } + } + if (!plugin.Cost.isEmpty()) { + for (ItemStack aCosts : plugin.Cost) { + for (int x = 1; x <= amount; x++) { + p.getInventory().removeItem(aCosts); + done = true; + } + } + } + if (done) { + target.getInventory().addItem(sponsoritem); + target.sendMessage(ChatColor.AQUA + "You have been Sponsored!"); + p.sendMessage("You have sponsored " + target.getName() + "!"); + } else { + p.sendMessage(ChatColor.RED + "Sponsoring is disabled!"); + } + } + } +} diff --git a/src/main/resources/Data.yml b/src/main/resources/Data.yml new file mode 100644 index 0000000..c240132 --- /dev/null +++ b/src/main/resources/Data.yml @@ -0,0 +1,3 @@ +# Stores all blocks to reset! +Blocks_Destroyed: [ ] +Blocks_Placed: [ ] \ No newline at end of file diff --git a/src/Player.yml b/src/main/resources/Player.yml similarity index 86% rename from src/Player.yml rename to src/main/resources/Player.yml index 4a7d85f..799968d 100644 --- a/src/Player.yml +++ b/src/main/resources/Player.yml @@ -1,6 +1,6 @@ # This is the default inventory file for storing players inventory during matches ! # DO not Edit anything in here!!! -inv: [] -armor: [] +inv: [ ] +armor: [ ] world: world diff --git a/src/commandAndBlockManagement.yml b/src/main/resources/commandAndBlockManagement.yml similarity index 80% rename from src/commandAndBlockManagement.yml rename to src/main/resources/commandAndBlockManagement.yml index 18c063b..eedbdd2 100644 --- a/src/commandAndBlockManagement.yml +++ b/src/main/resources/commandAndBlockManagement.yml @@ -5,9 +5,9 @@ # Anything not in the whitelist will be counted as blacklist! commands: - whitelist: [] + whitelist: [ ] blocks: useWhitelistAsBlacklist: false - whitelist: [] + whitelist: [ ] sponsors: - blacklist: [] \ No newline at end of file + blacklist: [ ] \ No newline at end of file diff --git a/src/config.yml b/src/main/resources/config.yml similarity index 97% rename from src/config.yml rename to src/main/resources/config.yml index e366a32..ae87bf5 100644 --- a/src/config.yml +++ b/src/main/resources/config.yml @@ -85,15 +85,15 @@ spawnsTool: GOLDEN_AXE # What the reward for winning is Reward: -- DIAMOND,10 + - DIAMOND,10 Sponsor_Cost: -- DIAMOND,1 + - DIAMOND,1 EntryFee: enabled: false eco: false cost: 50 fee: - - IRON_INGOT,1 + - IRON_INGOT,1 # True means give money to winner, false means don't. # How much money to give the winner. rewardEco: @@ -107,7 +107,7 @@ sponsorEco: ChestPay: enabled: false items: - - COOKED_BEEF,2 + - COOKED_BEEF,2 ################################ ################################ ################################ diff --git a/src/plugin.yml b/src/main/resources/plugin.yml similarity index 90% rename from src/plugin.yml rename to src/main/resources/plugin.yml index 775d153..384aaa5 100644 --- a/src/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,9 @@ name: HungerArena main: me.Travja.HungerArena.Main version: 1.6_Jeppa -api-version: 1.13 +api-version: 1.18 description: A lightweight and powerful plugin to help with playing The Hunger Games! -softdepend: [Vault, WorldEdit, Multiverse-Core] +softdepend: [ Vault, WorldEdit, Multiverse-Core ] commands: Ha: description: Makes you join a game or start the game! diff --git a/src/spawns.yml b/src/main/resources/spawns.yml similarity index 87% rename from src/spawns.yml rename to src/main/resources/spawns.yml index 6cd7a2c..5234eeb 100644 --- a/src/spawns.yml +++ b/src/main/resources/spawns.yml @@ -1,5 +1,5 @@ # This file stores all of the spawns! -Spawn_coords: [] +Spawn_coords: [ ] # If /ha setspawn has been run Spawns_set: 0: 'false' diff --git a/src/me/Travja/HungerArena/Chests.java b/src/me/Travja/HungerArena/Chests.java deleted file mode 100644 index 0f489a9..0000000 --- a/src/me/Travja/HungerArena/Chests.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.Travja.HungerArena; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -public class Chests implements Listener { - public Main plugin; - public Chests(Main m) { - this.plugin = m; - } - @EventHandler(priority = EventPriority.HIGHEST) - public void ChestBreak(BlockBreakEvent event){ - Player p = event.getPlayer(); - Block block = event.getBlock(); - if(p.hasPermission("HungerArena.Chest.Break")){ - Location blocklocation = block.getLocation(); - int blockx = blocklocation.getBlockX(); - int blocky = blocklocation.getBlockY(); - int blockz = blocklocation.getBlockZ(); - if (plugin.getChests().getConfigurationSection("Storage").getKeys(false).contains(blockx + "," + blocky + "," + blockz)) { - if(p.hasPermission("HungerArena.Chest.Break") && plugin.getArena(p)== null){ - plugin.getChests().set("Storage." + blockx + "," + blocky+ "," + blockz, null); - plugin.saveChests(); - p.sendMessage("[HungerArena] Chest Removed!"); - } else { - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "[HungerArena] That's a storage! You don't have permission to break it!"); - } - } - } - } - @EventHandler - public void ChestSaves(PlayerInteractEvent event){ - Block block = event.getClickedBlock(); - Player p = event.getPlayer(); - if(plugin.getArena(p)!= null){ - int a = plugin.getArena(p); - if(plugin.Playing.get(a).contains(p.getName()) && plugin.canjoin.get(a)){ - if(!plugin.restricted || (plugin.restricted && plugin.worldsNames.values().contains(p.getWorld().getName()))){ - if(block!= null){ - if(block.getState() instanceof InventoryHolder){ - ItemStack[] itemsinchest = ((InventoryHolder) block.getState()).getInventory().getContents().clone(); - int blockx = block.getX(); - int blocky = block.getY(); - int blockz = block.getZ(); - String blockw = block.getWorld().getName().toString(); - if(!plugin.getChests().contains("Storage." + blockx + "," + blocky + "," + blockz)){ - plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X", blockx); - plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky); - plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z",blockz); - plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw); - plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest); - plugin.getChests().set("Storage." + blockx + "," + blocky + "," + blockz + ".Arena", a); - plugin.saveChests(); - p.sendMessage(ChatColor.GREEN + "Thank you for finding this undiscovered item Storage, it has been stored!!"); - if (plugin.config.getBoolean("ChestPay.enabled")){ - for(ItemStack Rewards: plugin.ChestPay){ - p.getInventory().addItem(Rewards); - } - } - } - plugin.reloadChests(); - } - } - } - } - } - } -} diff --git a/src/me/Travja/HungerArena/CommandBlock.java b/src/me/Travja/HungerArena/CommandBlock.java deleted file mode 100644 index f5b3fc7..0000000 --- a/src/me/Travja/HungerArena/CommandBlock.java +++ /dev/null @@ -1,98 +0,0 @@ -package me.Travja.HungerArena; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -public class CommandBlock implements Listener { - public Main plugin; - public CommandBlock(Main m) { - this.plugin = m; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void CatchCommand(PlayerCommandPreprocessEvent event){ - String cmd = event.getMessage(); - Player p = event.getPlayer(); - String pname = p.getName(); - for(int x : plugin.Watching.keySet()){ - if(plugin.Watching.get(x).contains(p.getName())){ - if (handleIngameCommands(p, cmd)==true) event.setCancelled(true); - } - } - if(plugin.getArena(p)!= null){ - if (handleIngameCommands(p, cmd)==true) event.setCancelled(true); - }else if(cmd.toLowerCase().trim().equals("/back")){ - for(int u : plugin.Dead.keySet()){ - if(plugin.Dead.get(u).contains(pname) && plugin.canjoin.get(u)) - plugin.Tele.add(p); - } - } - if(cmd.startsWith("/tp") || cmd.startsWith("/telep") || cmd.contains(":tp") || cmd.contains(":telep")){ - String[] args = cmd.split(" "); - Player player1 = null; - Player player2 = null; - if(args.length >= 2){ - if(Bukkit.getPlayer(args[1]) != null){ - player1 = Bukkit.getPlayer(args[1]); - if (args.length >= 3 && Bukkit.getPlayer(args[2]) != null) player2 = Bukkit.getPlayer(args[2]); - if(plugin.isSpectating(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "Invalid command for spectating, using /ha tp " + (player2!=null?player2:player1)); - p.performCommand("/ha tp " + (player2!=null?player2:player1)); - }else if(plugin.getArena(player1)!=null || (args.length == 2 && plugin.getArena(p)!=null) || (args.length >= 3 && plugin.getArena(player2)!= null)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You can't teleport to other tributes!"); - } - } - } - } - } - private boolean handleIngameCommands(Player p, String cmd){ - if(!p.hasPermission("HungerArena.UseCommands")){ - if(!plugin.management.getStringList("commands.whitelist").isEmpty()){ - for(String whitelist: plugin.management.getStringList("commands.whitelist")){ - if(cmd.toLowerCase().startsWith(whitelist.toLowerCase())){ - return false; - } - } - } - if(!cmd.toLowerCase().startsWith("/ha")){ - p.sendMessage(ChatColor.RED + "You are only allowed to perform the following commands:"); - for(String whitelistfull: plugin.management.getStringList("commands.whitelist")){ - p.sendMessage(ChatColor.AQUA + whitelistfull); - } - p.sendMessage(ChatColor.AQUA + "/ha"); - p.sendMessage(ChatColor.AQUA + "/ha close"); - p.sendMessage(ChatColor.AQUA + "/ha help"); - p.sendMessage(ChatColor.AQUA + "/ha join"); - p.sendMessage(ChatColor.AQUA + "/ha kick [Player]"); - p.sendMessage(ChatColor.AQUA + "/ha leave"); - p.sendMessage(ChatColor.AQUA + "/ha list"); - p.sendMessage(ChatColor.AQUA + "/ha open"); - p.sendMessage(ChatColor.AQUA + "/ha ready"); - p.sendMessage(ChatColor.AQUA + "/ha refill"); - p.sendMessage(ChatColor.AQUA + "/ha reload"); - p.sendMessage(ChatColor.AQUA + "/ha restart"); - p.sendMessage(ChatColor.AQUA + "/ha rlist"); - //p.sendMessage(ChatColor.AQUA + "/ha newarena"); //not during game... - p.sendMessage(ChatColor.AQUA + "/ha setspawn"); - p.sendMessage(ChatColor.AQUA + "/ha start"); - p.sendMessage(ChatColor.AQUA + "/ha tp"); - p.sendMessage(ChatColor.AQUA + "/ha watch"); - p.sendMessage(ChatColor.AQUA + "/ha warpall"); - return true; - } - }else if(!cmd.toLowerCase().startsWith("/ha")){ - if(cmd.toLowerCase().startsWith("/spawn") || cmd.toLowerCase().startsWith("/back")){ - p.sendMessage("You have perms for all commands except this one!"); - return true; - } - } - return false; - } -} diff --git a/src/me/Travja/HungerArena/HaCommands.java b/src/me/Travja/HungerArena/HaCommands.java deleted file mode 100644 index 55b6937..0000000 --- a/src/me/Travja/HungerArena/HaCommands.java +++ /dev/null @@ -1,1161 +0,0 @@ -package me.Travja.HungerArena; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.attribute.Attribute; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Damageable; -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Score; -import org.bukkit.scoreboard.Scoreboard; - -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.bukkit.selections.Selection; - -public class HaCommands implements CommandExecutor { - public Main plugin; - public HaCommands(Main m) { - this.plugin = m; - } - int i = 0; - int a = 1; - boolean NoPlayerSpawns = true; - - private void clearInv(Player p){ - p.getInventory().clear(); - p.getInventory().setBoots(null); - p.getInventory().setChestplate(null); - p.getInventory().setHelmet(null); - p.getInventory().setLeggings(null); - p.updateInventory(); - } - private Location getArenaSpawn(){ - String[] Spawncoords; - if (plugin.spawns.getString("Spawn_coords." + a) != null){ - Spawncoords = plugin.spawns.getString("Spawn_coords."+ a).split(","); - } else { - Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); - } - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - String spawnworld = Spawncoords[3]; - World spawnw = plugin.getServer().getWorld(spawnworld); - Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - return Spawn; - } - @Override - public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, String[] args){ - - boolean console = false; - boolean playr = false; - if(sender instanceof ConsoleCommandSender)console=true; - else if(sender instanceof Player)playr=true; - - if(playr){ - final Player p = (Player) sender; - final String pname = p.getName(); - String ThisWorld = p.getWorld().getName(); - for(int i : plugin.worldsNames.keySet()){ - if(plugin.worldsNames.get(i)!= null){ - if (plugin.worldsNames.get(i).equals(ThisWorld)){ - a=i; - NoPlayerSpawns = false; - } - } - } - - if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - NoPlayerSpawns = false; - } - if(cmd.getName().equalsIgnoreCase("Ha")){ - if(args.length== 0){ - sender.sendMessage(ChatColor.GREEN + "[HungerArena] by " + ChatColor.AQUA + "travja! Version: " + plugin.getDescription().getVersion()); - sender.sendMessage(ChatColor.GREEN + "[HungerArena] Update by " + ChatColor.AQUA + "Jeppa ! "); - return false; - }else if(args[0].equalsIgnoreCase("NewArena")){ - if(p.hasPermission("HungerArena.StartPoint")){ - if (args.length<2) { - p.sendMessage(ChatColor.AQUA + "You have to enter the arena number as 2nd argument"); - }else{ - try { a = Integer.parseInt(args[1]); - }catch(Exception e){ - p.sendMessage(ChatColor.RED + "Argument not an integer!"); - return false; - } - if (plugin.worldsNames.values().contains(ThisWorld)){ - p.sendMessage(ChatColor.RED + "This world already has an areana! \n (only one arena per world possible, yet!)"); - return false; - } - ((Player)sender).performCommand("startpoint " + a); - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - }else if(args[0].equalsIgnoreCase("SetSpawn")){ - if(p.hasPermission("HungerArena.SetSpawn")){ - if ((NoPlayerSpawns) && (args.length<2)) { - p.sendMessage(ChatColor.AQUA + "You have to set the playerspawns first! Use /ha newarena \nOr enter the arena number as 2nd argument, \n0 is default/fallback!"); - }else{ - double x = p.getLocation().getX(); - double y = p.getLocation().getY(); - double z = p.getLocation().getZ(); - if (plugin.spawns.getString("Spawn_coords.0")== null){ - plugin.spawns.set("Spawn_coords.0", x + "," + y + "," + z + "," + ThisWorld); - plugin.spawns.set("Spawns_set.0", "true"); - } - if (args.length>=2) { - try { a = Integer.parseInt(args[1]); - }catch(Exception e){ - p.sendMessage(ChatColor.RED + "Argument not an integer!"); - return false; - } - } - plugin.spawns.set("Spawn_coords."+a, x + "," + y + "," + z + "," + ThisWorld); - plugin.spawns.set("Spawns_set."+a, "true"); - plugin.saveSpawns(); - p.sendMessage(ChatColor.AQUA + "You have set the spawn for dead tributes!"); - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - }else if(args[0].equalsIgnoreCase("SetTorch")){ - if(p.hasPermission("HungerArena.SetSpawn")){ - if (args.length<2) { - p.sendMessage(ChatColor.AQUA + "You have to enter the arena number as 2nd argument"); - }else{ - double x = p.getLocation().getX(); - double y = p.getLocation().getY(); - double z = p.getLocation().getZ(); - if (args.length>=2) { - try { a = Integer.parseInt(args[1]); - }catch(Exception e){ - p.sendMessage(ChatColor.RED + "Argument not an integer!"); - return true; - } - } - plugin.spawns.set("Start_torch."+a, x + "," + y + "," + z + "," + ThisWorld); - plugin.saveSpawns(); - p.sendMessage(ChatColor.AQUA + "You have set the start redstone torch for arena "+a+"!"); - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - - }else if(args[0].equalsIgnoreCase("Help")){ - help_sub(sender,playr,console); - - }else if(plugin.restricted && !plugin.worldsNames.values().contains(ThisWorld)){ - p.sendMessage(ChatColor.RED + "That can't be run in this world!"); - }else if(!plugin.restricted || plugin.restricted && plugin.worldsNames.values().contains(ThisWorld)){ - //////////////////////////////////////// LISTING /////////////////////////////////////////////// - if(args[0].equalsIgnoreCase("List")){ - if(p.hasPermission("HungerArena.GameMaker") || plugin.Watching.get(a).contains(pname) || p.hasPermission("HungerArena.List")){ - list_sub(p,sender,playr,console,args); - - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - }else if(args[0].equalsIgnoreCase("rList")){ - if(p.hasPermission("HungerArena.GameMaker")){ - rList_sub(sender, args); - - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - //////////////////////////////////////////////////////////////////////////////////////////////// - ///////////////////////////////////// JOINING/LEAVING ////////////////////////////////////////// - }else if(args[0].equalsIgnoreCase("Join")){ - if(p.hasPermission("HungerArena.Join")){ - boolean needconfirm = false; - for(int i : plugin.NeedConfirm.keySet()){ - if(plugin.NeedConfirm.get(i).contains(pname)){ - needconfirm = true; - p.sendMessage(ChatColor.GOLD + "You need to run /ha confirm"); - } - } - if(!needconfirm){ - if ((args.length>= 2) && checkarena(args[1], sender)){ - a = Integer.parseInt(args[1]); - }else{ - if (NoPlayerSpawns){ - for(int i : plugin.Playing.keySet()){ - if(plugin.Playing.get(i).size()< plugin.maxPlayers.get(i)){ - a = i; - p.sendMessage(ChatColor.RED + "Found free slots in Arena "+a+" !"); - } - else if(i == plugin.Playing.size()){ - p.sendMessage(ChatColor.RED + "No free slots found / All games are full!"); - } - } - } - - } - if((plugin.Playing.get(a)!=null) && (plugin.location.get(a).size()!=0)){; - if(plugin.Playing.get(a).contains(pname)) - p.sendMessage(ChatColor.RED + "You are already playing!"); - else if(plugin.Dead.get(a).contains(pname) || plugin.Quit.get(a).contains(pname)) - p.sendMessage(ChatColor.RED + "You DIED/QUIT! You can't join again!"); - else if(plugin.Playing.get(a).size()== plugin.maxPlayers.get(a)) - p.sendMessage(ChatColor.RED + "There are already " + plugin.maxPlayers.get(a) + " Tributes in that Arena!"); - else if(plugin.canjoin.get(a)== true) - p.sendMessage(ChatColor.RED + "That game is in progress!"); - else if(!plugin.open.get(a)) - p.sendMessage(ChatColor.RED + "That game is closed!"); - else if((plugin.spawns.getString("Spawns_set."+a)==null) || (plugin.spawns.getString("Spawns_set."+a).equalsIgnoreCase("false"))) - p.sendMessage(ChatColor.RED + "/ha setspawn for Arena "+ a +" hasn't been run!"); - else if(plugin.getArena(p)!= null) - p.sendMessage(ChatColor.RED + "You are already in an arena!"); - else if(plugin.config.getString("Need_Confirm").equalsIgnoreCase("true")){ - if(plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ - if(!(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost"))){ - i = 0; - for(ItemStack fee: plugin.Fee){ - int total = plugin.Fee.size(); - if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ - i = i+1; - if(total == i){ - plugin.NeedConfirm.get(a).add(pname); - p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); - } - } - } - if(plugin.Fee.size() > i){ - p.sendMessage(ChatColor.RED + "You are missing some items and can't join the games..."); - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have enough money to join!"); - } - }else if(plugin.config.getBoolean("EntryFee.enabled") && !plugin.config.getBoolean("EntryFee.eco")){ - i = 0; - for(ItemStack fee: plugin.Fee){ - int total = plugin.Fee.size(); - if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ - i = i+1; - if(total == i){ - plugin.NeedConfirm.get(a).add(pname); - p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); - } - } - } - if(plugin.Fee.size() > i){ - p.sendMessage(ChatColor.RED + "You are missing some items and can't join the games..."); - } - }else if(!plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ - if(!(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost"))){ - plugin.NeedConfirm.get(a).add(pname); - p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); - }else{ - p.sendMessage(ChatColor.RED + "You don't have enough money to join!"); - } - }else{ - plugin.NeedConfirm.get(a).add(pname); - p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); - } - }else if(plugin.config.getString("Need_Confirm").equalsIgnoreCase("false")){ - confirmSub(p, pname, ThisWorld); - } - - }else{ - p.sendMessage(ChatColor.RED + "That arena doesn't exist!"); - } - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - //////////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////// CONFIRMATION /////////////////////////////////////////////// - }else if(args[0].equalsIgnoreCase("Confirm")){ - for(int v : plugin.NeedConfirm.keySet()){ - if(plugin.NeedConfirm.get(v).contains(pname)){ - a = v; - confirmSub(p, pname, ThisWorld); - } - else if((v== plugin.NeedConfirm.size()) && (plugin.config.getString("Need_Confirm").equalsIgnoreCase("true"))){ - p.sendMessage(ChatColor.RED + "You haven't joined any games!"); - } - } - }else if(args[0].equalsIgnoreCase("Ready")){ - if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - if(plugin.Playing.get(a).contains(pname)){ - if(plugin.Ready.get(a).contains(pname)){ - p.sendMessage(ChatColor.RED + "You're already ready!"); - }else if(plugin.Playing.get(a).size()== 1){ - p.sendMessage(ChatColor.RED + "You can't be ready when no one else is playing!"); - }else{ - plugin.Ready.get(a).add(pname); - if(plugin.config.getBoolean("broadcastAll")){ - plugin.getServer().broadcastMessage(ChatColor.AQUA + "[HungerArena] Game " + a + ": " + ChatColor.GRAY + String.valueOf(plugin.Ready.get(a).size()) + "/" + plugin.maxPlayers.get(a) + " Players ready!"); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(ChatColor.GRAY + String.valueOf(plugin.Ready.get(a).size()) + "/" + plugin.maxPlayers.get(a) + " Players ready!"); - } - } - p.sendMessage(ChatColor.AQUA + "You have marked yourself as READY!"); - if(plugin.config.getBoolean("Auto_Warp")){ - if(((double) plugin.Playing.get(a).size())%60<= plugin.Ready.get(a).size() || plugin.Playing.get(a).size()==plugin.Ready.get(a).size()){ - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha warpall " + a); - } - } - } - } - }else{ - p.sendMessage(ChatColor.RED + "You aren't playing in any games!"); - } - }else if(args[0].equalsIgnoreCase("Leave")){ - if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - if(plugin.canjoin.get(a)== true){ - clearInv(p); - p.teleport(getArenaSpawn()); - if(plugin.Frozen.get(a).contains(pname)){ - plugin.Frozen.get(a).remove(pname); - } - - if(plugin.Playing.get(a).size()!=1) plugin.RestoreInv(p, pname); - - plugin.winner(a); - }else{ - clearInv(p); - p.teleport(getArenaSpawn()); - - plugin.RestoreInv(p, pname); - - if(plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ - plugin.econ.depositPlayer(p, plugin.config.getDouble("EntryFee.cost")); - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + "$" + plugin.config.getDouble("EntryFee.cost") + " has been added to your account!"); - for(ItemStack fees: plugin.Fee){ - p.getInventory().addItem(fees); - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees.getType().toString().toLowerCase().replace("_", " ") + " was refunded because you left the games."); - } - }else if(plugin.config.getBoolean("EntryFee.enabled") && !plugin.config.getBoolean("EntryFee.eco")){ - for(ItemStack fees: plugin.Fee){ - p.getInventory().addItem(fees); - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees.getType().toString().toLowerCase().replace("_", " ") + " was refunded because you left the games."); - } - }else if(!plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ - plugin.econ.depositPlayer(p, plugin.config.getDouble("EntryFee.cost")); - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + "$" + plugin.config.getDouble("EntryFee.cost") + " has added to your account!"); - } - } - }else{ - p.sendMessage(ChatColor.RED + "You aren't in any games!"); - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////// SPECTATOR RELATED ////////////////////////////////// - }else if(args[0].equalsIgnoreCase("Watch")){ - if(sender.hasPermission("HungerArena.Watch")){ - if(args.length>= 2){ - if (checkarena(args[1], sender)){ - a = Integer.parseInt(args[1]); - if(!plugin.Watching.get(a).contains(pname) && plugin.getArena(p)== null && plugin.canjoin.get(a)== true){ - plugin.Watching.get(a).add(pname); - p.teleport(Bukkit.getPlayer(plugin.Playing.get(a).get(0))); - for(Player online:plugin.getServer().getOnlinePlayers()){ - online.hidePlayer(plugin,p); - } - p.setAllowFlight(true); - p.sendMessage(ChatColor.AQUA + "You can now spectate!"); - Scoreboard scoreboard = plugin.getServer().getScoreboardManager().getNewScoreboard(); - Objective sobj; - try{ - sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting"); - } catch (NoSuchMethodError e){ - sobj = scoreboard.registerNewObjective("HA", "HAData"); - sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); - } - Score sdeaths = sobj.getScore((ChatColor.RED + "Spectators")); - sdeaths.setScore(0); - Score splayers = sobj.getScore((ChatColor.RED + "Players")); - splayers.setScore(0); - sobj.setDisplaySlot(DisplaySlot.SIDEBAR); - p.setScoreboard(scoreboard); - plugin.scoreboards.put(p.getName(), p.getScoreboard()); - }else if(plugin.canjoin.get(a)== false){ - p.sendMessage(ChatColor.RED + "That game isn't in progress!"); - }else if(plugin.Playing.get(a).contains(pname)){ - p.sendMessage(ChatColor.RED + "You can't watch while you're playing!"); - }else if(plugin.Watching.get(a).contains(pname)){ - plugin.Watching.get(a).remove(pname); - for(Player online:plugin.getServer().getOnlinePlayers()){ - online.showPlayer(plugin,p); - } - p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - plugin.scoreboards.remove(p.getName()); - p.teleport(getArenaSpawn()); - p.setAllowFlight(false); - p.sendMessage(ChatColor.AQUA + "You are not spectating any more"); - } - } - }else{ - p.sendMessage(ChatColor.RED + "Too few arguments!"); - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - }else if(args[0].equalsIgnoreCase("tp")){ - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i).contains(pname)){ - if(plugin.getArena(Bukkit.getServer().getPlayer(args[1])) != null){ - Player target = Bukkit.getServer().getPlayer(args[1]); - p.teleport(target); - p.sendMessage(ChatColor.AQUA + "You've been teleported to " + target.getName()); - return true; - }else{ - p.sendMessage(ChatColor.RED + "That person isn't in game!"); - return true; - } - }else{ - if(i== plugin.Watching.size()){ - p.sendMessage(ChatColor.RED + "You have to be spectating first!"); - return true; - } - } - } - ///////////////////////////////////////////////////////////////////////////////// - }else if(args[0].equalsIgnoreCase("addArena")){ - if(plugin.hookWE() != null){ - if(args.length != 2) - return false; - if(p.hasPermission("HungerArena.AddArena")){ - WorldEditPlugin worldedit = plugin.hookWE(); - Selection sel = worldedit.getSelection(p); - if(sel== null) - p.sendMessage(ChatColor.DARK_RED + "You must make a WorldEdit selection first!"); - else{ - Location min = sel.getMinimumPoint(); - Location max = sel.getMaximumPoint(); - plugin.spawns.set("Arenas." + args[1] + ".Max", max.getWorld().getName() + "," + max.getX() + "," - + max.getY() + "," + max.getZ()); - plugin.spawns.set("Arenas." + args[1] + ".Min", min.getWorld().getName() + "," + min.getX() + "," - + min.getY() + "," + min.getZ()); - plugin.saveConfig(); - p.sendMessage(ChatColor.GREEN + "Arena " + ChatColor.DARK_AQUA + args[1] - + ChatColor.GREEN + " created with WorldEdit!"); - return true; - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - return true; - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have WorldEdit enabled for HungerArena!"); - return true; - } - }else if(args[0].equalsIgnoreCase("Kick")){ - return kick_sub(sender, args, playr, console, getArenaSpawn()); - - }else if(args[0].equalsIgnoreCase("Refill")){ - if(p.hasPermission("HungerArena.Refill")){ - ReFill_sub(sender,args); - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - return true; - } - }else if(args[0].equalsIgnoreCase("Restart")){ - if(p.hasPermission("HungerArena.Restart")){ - Restart_Close_sub(sender, args, playr, false); - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - /////////////////////////////////// Toggle ////////////////////////////////////////////////// - }else if(args[0].equalsIgnoreCase("close")){ - if(p.hasPermission("HungerArena.toggle")){ - Restart_Close_sub(sender,args,playr, true); - }else{ - p.sendMessage(ChatColor.RED + "No Perms!"); - } - }else if(args[0].equalsIgnoreCase("open")){ - if(p.hasPermission("HungerArena.toggle")){ - open_sub(sender,args); - }else{ - p.sendMessage(ChatColor.RED + "No Perms!"); - } - //////////////////////////////////////////////////////////////////////////////////////////// - }else if(args[0].equalsIgnoreCase("Reload")){ - if(p.hasPermission("HungerArena.Reload")){ - reload_sub(sender); - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission"); - } - }else if(args[0].equalsIgnoreCase("WarpAll")){ - if(p.hasPermission("HungerArena.Warpall")){ - warpall_sub(sender,args); - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission"); - } - }else if(args[0].equalsIgnoreCase("Start")){ - if(p.hasPermission("HungerArena.Start")){ - start_sub(sender,args); - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - }else{ - p.sendMessage(ChatColor.RED + "Unknown command, type /ha help for a list of commands"); - } - } - } - -// Console /////////////////////////////////// - }else if(sender instanceof ConsoleCommandSender){ - if(cmd.getName().equalsIgnoreCase("Ha")){ - if(args.length== 0){ - sender.sendMessage(ChatColor.GREEN + "[HungerArena] by " + ChatColor.AQUA + "travja! Version: " + plugin.getDescription().getVersion()); - sender.sendMessage(ChatColor.GREEN + "[HungerArena] Update by " + ChatColor.AQUA + "Jeppa ! "); - return false; - } - if(args[0].equalsIgnoreCase("Help")){ - help_sub(sender,playr,console); - return false; - }else if(args[0].equalsIgnoreCase("List")){ - list_sub(null,sender,playr,console,args); - - }else if(args[0].equalsIgnoreCase("rList")){ - rList_sub(sender, args); - - }else if(args[0].equalsIgnoreCase("SetSpawn") || args[0].equalsIgnoreCase("Join") || args[0].equalsIgnoreCase("Confirm") || args[0].equalsIgnoreCase("Ready") || args[0].equalsIgnoreCase("Leave") || args[0].equalsIgnoreCase("Watch") || args[0].equalsIgnoreCase("NewArena")){ - sender.sendMessage(ChatColor.RED + "That can only be run by a player!"); - }else if(args[0].equalsIgnoreCase("Kick")){ - return kick_sub(sender, args, playr, console, getArenaSpawn()); - - }else if(args[0].equalsIgnoreCase("Refill")){ - ReFill_sub(sender,args); - - }else if(args[0].equalsIgnoreCase("Restart")){ - Restart_Close_sub(sender, args, playr, false); - - /////////////////////////////////// Toggle ////////////////////////////////////////////////// - }else if(args[0].equalsIgnoreCase("close")){ - Restart_Close_sub(sender, args, playr, true); - - }else if(args[0].equalsIgnoreCase("open")){ - open_sub(sender, args); - - //////////////////////////////////////////////////////////////////////////////////////////// - }else if(args[0].equalsIgnoreCase("Reload")){ - reload_sub(sender); - - }else if(args[0].equalsIgnoreCase("WarpAll")){ - warpall_sub(sender, args); - - }else if(args[0].equalsIgnoreCase("Start")){ - start_sub(sender,args); - - }else{ - sender.sendMessage(ChatColor.RED + "Unknown command, type /ha help to see all commands!"); - } - } - } - return false; - } - - ///////////////////////////// Subroutines ////////////////////////////////// - - private void help_sub(CommandSender sender, boolean playr, boolean console) { - ChatColor c = ChatColor.AQUA; - sender.sendMessage(ChatColor.GREEN + "----HungerArena Help----"); - sender.sendMessage(c + "/ha - Displays author message!"); - sender.sendMessage(c + "/sponsor [Player] [ItemID] [Amount] - Lets you sponsor someone!"); - sender.sendMessage(c + "/startpoint [1,2,3,4,etc] [1,2,3,4,etc] - Sets the starting points of tributes in a specific arena!"); - sender.sendMessage(c + "/ha newarena [1,2,3,4,etc] - Add a new arena to the server and start setting up the starting points of tributes!\n Use the spawnsTool for setting up all starting points!"); - if(playr && plugin.hookWE() != null) - sender.sendMessage(c + "/ha addArena [1,2,3,4,etc] - Creates an arena using your current WorldEdit selection."); - sender.sendMessage(c + "/ha close (1,2,3,4,etc) - Prevents anyone from joining that arena! Numbers are optional"); - sender.sendMessage(c + "/ha help - Displays this screen!"); - sender.sendMessage(c + "/ha join [1,2,3,4,etc] - Makes you join the game!"); - sender.sendMessage(c + "/ha kick [Player] - Kicks a player from the arena!"); - sender.sendMessage(c + "/ha leave - Makes you leave the game!"); - sender.sendMessage(c + "/ha list (1,2,3,4,etc) - Shows a list of players in the game and their health! Numbers are optional."); - sender.sendMessage(c + "/ha open (1,2,3,4,etc) - Opens the game allowing people to join! Numbers are optional"); - sender.sendMessage(c + "/ha ready - Votes for the game to start!"); - sender.sendMessage(c + "/ha refill (1,2,3,4,etc) - Refills all chests! Numbers are optional"); - sender.sendMessage(c + "/ha reload - Reloads the config!"); - sender.sendMessage(c + "/ha restart (1,2,3,4,etc) - Restarts the game! Numbers are optional"); - sender.sendMessage(c + "/ha rlist (1,2,3,4,etc) - See who's ready! Numbers are optional"); - sender.sendMessage(c + "/ha setspawn - Sets the spawn for dead tributes! You can add the arena # to this command: /setspawn [1,2,3,4,etc.]"); - sender.sendMessage(c + "/ha settorch - Sets the location for a redstone torch in an arena that will be placed at match start!"); - sender.sendMessage(c + "/ha tp [player] - Teleports you to a tribute!"); - sender.sendMessage(c + "/ha start [1,2,3,4,etc] - Unfreezes tributes allowing them to fight!"); - sender.sendMessage(c + "/ha watch [1,2,3,4,etc] - Lets you watch the tributes!"); - sender.sendMessage(c + "/ha warpall [1,2,3,4,etc] - Warps all tribute into position!"); - sender.sendMessage(ChatColor.GREEN + "----------------------"); - } - private void list_sub(Player p, CommandSender sender, boolean playr, boolean console, String[] args){ - if(args.length>= 2){ - if (checkarena(args[1], sender)){ - a = Integer.parseInt(args[1]); - list_subsub(p, sender, console); - } - }else{ - if(console || (p!=null && plugin.getArena(p)==null)){ - a=1; - list_subsub(p, sender, console); - }else{ - a = plugin.getArena(p); - list_subsub(p, sender, console); - } - } - } - private void list_subsub(Player p, CommandSender sender, boolean console){ - sender.sendMessage(ChatColor.AQUA + "----- Arena " + a + " -----"); - if(!plugin.Playing.get(a).isEmpty() && plugin.Playing.containsKey(a)){ - for(String playernames: plugin.Playing.get(a)){ - Player players = plugin.getServer().getPlayerExact(playernames); - if(console || (p!=null && p.hasPermission("HungerArena.GameMaker"))){ - double maxh; - try { - maxh = players.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); - } catch (Exception e){ - maxh = ((Damageable)players).getMaxHealth(); - } - sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + ((Damageable)players).getHealth() + "/" + maxh); - }else if(console || (p!=null && p.hasPermission("HungerArena.List"))){ - sender.sendMessage(ChatColor.GREEN + playernames); - } - } - }else{ - sender.sendMessage(ChatColor.GRAY + "No one is playing!"); - } - sender.sendMessage(ChatColor.AQUA + "-------------------"); - } - private void rList_sub (CommandSender sender,String[] args){ - if(args.length>= 2){ - if (checkarena(args[1], sender)){ - a = Integer.parseInt(args[1]); - sender.sendMessage(ChatColor.AQUA + "----- Arena " + a + " -----"); - if(!plugin.Ready.get(a).isEmpty() && plugin.Ready.containsKey(a)){ - for(String playernames: plugin.Ready.get(a)){ - sender.sendMessage(ChatColor.GREEN + playernames); - } - }else{ - sender.sendMessage(ChatColor.GRAY + "No one is ready!"); - } - sender.sendMessage(ChatColor.AQUA + "-------------------"); - } - }else{ - sender.sendMessage(ChatColor.AQUA + "----- Arena 1 -----"); - if(!plugin.Ready.get(1).isEmpty() && plugin.Ready.containsKey(1)){ - for(String playernames: plugin.Ready.get(1)){ - sender.sendMessage(ChatColor.GREEN + playernames); - } - }else{ - sender.sendMessage(ChatColor.GRAY + "No one is ready!"); - } - sender.sendMessage(ChatColor.AQUA + "-------------------"); - } - } - private boolean kick_sub(CommandSender sender, String[] args, boolean playr, boolean console, Location Spawn){ - if (args.length != 2) { - sender.sendMessage(ChatColor.RED + "/ha kick [playername]!"); - return false; - } - Player target = Bukkit.getServer().getPlayer(args[1]); - if(target == null){ - sender.sendMessage(ChatColor.RED + "Use playername !"); - return false; - } - if(console || (playr && ((Player)sender).hasPermission("HungerArena.Kick"))){ - if(plugin.getArena(target) != null){ - a = plugin.getArena(target); - plugin.Playing.get(a).remove(target.getName()); - if(!plugin.config.getBoolean("broadcastAll")){ - plugin.getServer().broadcastMessage(ChatColor.RED + target.getName() + " was kicked from arena " + a + "!"); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(ChatColor.RED + target.getName() + " was kicked from the game!"); - } - } - clearInv(target); - target.teleport(Spawn); - plugin.Quit.get(a).add(target.getName()); - plugin.RestoreInv(target, target.getName()); - plugin.winner(a); - return true; - }else{ - sender.sendMessage(ChatColor.RED + "That player isn't in the game!"); - return true; - } - }else{ - sender.sendMessage(ChatColor.RED + "You don't have permission!"); - return true; - } - } - private void ReFill_sub(CommandSender sender, String[]args){ - plugin.reloadChests(); - int arena = 0; - if(args.length>=2) if(checkarena(args[1],sender)) arena=Integer.parseInt(args[1]); - - Set StorList = plugin.getChests().getConfigurationSection("Storage").getKeys(false); - for (String xyz2:StorList){ - int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X"); - int chesty = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Y"); - int chestz = plugin.getChests().getInt("Storage." + xyz2 + ".Location.Z"); - int chesta = plugin.getChests().getInt("Storage." + xyz2 + ".Arena"); - String chestw = plugin.getChests().getString("Storage." + xyz2 + ".Location.W"); - Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz); - plugin.exists = false; - if(chesta == arena || arena == 0){ - if(blockatlocation.getState() instanceof InventoryHolder){ - plugin.exists = true; - int ChunkX= ((new Double(blockatlocation.getX()/16).intValue())); - int ChunkZ= ((new Double(blockatlocation.getZ()/16).intValue())); - if (!blockatlocation.getWorld().isChunkLoaded(ChunkX,ChunkZ)){ - blockatlocation.getWorld().loadChunk(ChunkX,ChunkZ,true); - } - InventoryHolder chest = (InventoryHolder) blockatlocation.getState(); - chest.getInventory().clear(); - ItemStack[] itemsinchest = null; - Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage"); - if(o instanceof ItemStack[]){ - itemsinchest = (ItemStack[]) o; - }else if(o instanceof List){ - itemsinchest = (ItemStack[]) ((List) o).toArray(new ItemStack[]{}); - } - if (chest.getInventory().getSize()==itemsinchest.length){ - chest.getInventory().setContents(itemsinchest); - } else { - for (ItemStack item:itemsinchest){ - if ((item !=null) && (item.getType()!=null)) chest.getInventory().addItem(item); - } - } - } - } - } - if (arena != 0)sender.sendMessage(ChatColor.GREEN + "All for arena " + arena + " refilled!"); - else sender.sendMessage(ChatColor.GREEN + "All chests refilled!"); - } - private void Restart_Close_sub(CommandSender sender, String[]args, boolean playr, boolean closeit){ - Set list = plugin.open.keySet(); - if(args.length>= 2){ - list = new HashSet(); - if (checkarena(args[1], sender)) - list.add(Integer.parseInt(args[1])); - } - for(int a : list){ - if(!closeit || (closeit && plugin.open.get(a))){ - if(plugin.deathtime.get(a)!= null){ - plugin.getServer().getScheduler().cancelTask(plugin.deathtime.get(a)); - plugin.deathtime.put(a, null); - } - if(plugin.grace.get(a)!= null){ - plugin.getServer().getScheduler().cancelTask(plugin.grace.get(a)); - plugin.grace.put(a, null); - } - if(plugin.start.get(a)!= null){ - plugin.getServer().getScheduler().cancelTask(plugin.start.get(a)); - plugin.start.put(a, null); - } - - if(plugin.timetodeath.get(a)!= null) - plugin.timetodeath.remove(a); - plugin.Frozen.get(a).clear(); - if(plugin.Playing.get(a)!= null){ - for(String players: plugin.Playing.get(a)){ - Player tributes = plugin.getServer().getPlayerExact(players); - clearInv(tributes); - tributes.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - tributes.teleport(tributes.getWorld().getSpawnLocation()); - plugin.scoreboards.remove(players); - plugin.Kills.remove(players); - plugin.Frozen.get(a).add(players); - } - } - if (plugin.Kills.containsKey("__SuM__")) plugin.Kills.remove("__SuM__"); - if(plugin.Watching.get(a)!= null){ - for(String sname: plugin.Watching.get(a)){ - Player spectators = plugin.getServer().getPlayerExact(sname); - spectators.teleport(spectators.getWorld().getSpawnLocation()); - spectators.setAllowFlight(false); - spectators.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - for(Player online:plugin.getServer().getOnlinePlayers()){ - online.showPlayer(plugin,spectators); - } - plugin.scoreboards.remove(sname); - } - } - if(plugin.Frozen.get(a)!= null){ - for(String sname: plugin.Frozen.get(a)){ - Player player = plugin.getServer().getPlayerExact(sname); - plugin.RestoreInv(player, sname); - } - } - plugin.Dead.get(a).clear(); - plugin.Quit.get(a).clear(); - plugin.Watching.get(a).clear(); - plugin.Frozen.get(a).clear(); - plugin.Ready.get(a).clear(); - plugin.NeedConfirm.get(a).clear(); - plugin.Out.get(a).clear(); - plugin.Playing.get(a).clear(); - plugin.inArena.get(a).clear(); - - if (closeit) { - plugin.open.put(a, false); - } else { - plugin.canjoin.put(a, false); - plugin.open.put(a, true); - } - - plugin.MatchRunning.put(a, null); - List blocksbroken = plugin.data.getStringList("Blocks_Destroyed"); - List blocksplaced = plugin.data.getStringList("Blocks_Placed"); - ArrayList toremove = new ArrayList(); - ArrayList toremove2 = new ArrayList(); - for(String blocks:blocksplaced){ - String[] coords = blocks.split(","); - World w = plugin.getServer().getWorld(coords[0]); - double x = Double.parseDouble(coords[1]); - double y = Double.parseDouble(coords[2]); - double z = Double.parseDouble(coords[3]); - int arena = Integer.parseInt(coords[4]); - Location blockl = new Location(w, x, y, z); - Block block = w.getBlockAt(blockl); - if(arena==a){ - block.setType(Material.AIR); - block.getState().update(); - toremove.add(blocks); - } - } - for(String blocks:blocksbroken){ - String[] coords = blocks.split(blocks.contains(";")?";":","); - World w = plugin.getServer().getWorld(coords[0]); - double x = Double.parseDouble(coords[1]); - double y = Double.parseDouble(coords[2]); - double z = Double.parseDouble(coords[3]); - String d = coords[4]; - byte m=0; - BlockData newBlData=null; - try{ - m = Byte.parseByte(coords[5]); - } catch (NumberFormatException Ex) { - newBlData = Bukkit.createBlockData(coords[5]); - } - int arena = Integer.parseInt(coords[6]); - Location blockl = new Location(w, x, y, z); - Block block = w.getBlockAt(blockl); - if(arena==a){ - if (newBlData==null) { - try{ - int d2 = Integer.parseInt(d); - Method setD = Class.forName("org.bukkit.block.Block").getDeclaredMethod("setTypeIdAndData",int.class,byte.class,boolean.class); - setD.setAccessible(true); - setD.invoke(block, d2,m,true); - } catch (Exception | NoSuchMethodError e){ - if (d.replaceAll("[0-9]","").equals("")){ - int d2 = Integer.parseInt(d); - d = plugin.findOldMaterial(d2,m).name(); - } - block.setType(Material.getMaterial(d), true); - try{ - Method setD = Class.forName("org.bukkit.block.Block").getDeclaredMethod("setData",byte.class,boolean.class); - setD.setAccessible(true); - setD.invoke(block, m,true); - } catch (Exception | NoSuchMethodError ee){ - try { - BlockData BlData = block.getBlockData(); - if (BlData instanceof org.bukkit.block.data.type.Snow ){ - if (m>0)((org.bukkit.block.data.type.Snow)BlData).setLayers(m+1); - } - if (BlData instanceof org.bukkit.block.data.type.Cake ){ - ((org.bukkit.block.data.type.Cake)BlData).setBites(m); - } - if (coords.length>7 && (coords[7]!=null || coords[7].isEmpty())){ - String BlDir = coords[7]; - if (BlData instanceof org.bukkit.block.data.Directional) { - ((org.bukkit.block.data.Directional)BlData).setFacing(BlockFace.valueOf(BlDir)); - } - } - block.setBlockData(BlData); - } catch (Exception | NoSuchMethodError xx){} - } - } - } else { - block.setBlockData(newBlData); - } - block.getState().update(); - toremove2.add(blocks); - } - } - for(String blocks: toremove){ - blocksplaced.remove(blocks); - } - for(String blocks: toremove2){ - blocksbroken.remove(blocks); - } - toremove.clear(); - toremove2.clear(); - plugin.data.set("Blocks_Destroyed", blocksbroken); - plugin.data.set("Blocks_Placed", blocksplaced); - plugin.data.options().copyDefaults(); - plugin.saveData(); - - plugin.setTorch(a, false); - - if (playr) ((Player)sender).performCommand("ha refill " + a); - else plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "ha refill " + a); - - if (closeit){ - sender.sendMessage(ChatColor.GOLD + "Arena " + a + " Closed!"); - } else { - sender.sendMessage(ChatColor.AQUA + "Arena " + a + " has been reset!"); - } - - }else{ - sender.sendMessage(ChatColor.RED + "Arena " + a + " already closed, type /ha open to re-open them!"); - } - } - } - - private void open_sub(CommandSender sender, String[] args){ - Set list = plugin.open.keySet(); - if(args.length>= 2){ - list = new HashSet(); - if (checkarena(args[1], sender)) - list.add(Integer.parseInt(args[1])); - } - for(int i : list){ - if(!plugin.open.get(i)){ - plugin.open.put(i, true); - sender.sendMessage(ChatColor.GOLD + "Arena " + i + " Open!"); - }else{ - sender.sendMessage(ChatColor.RED + "Arena " + i + " already open, type /ha close to close them!"); - } - } - } - private void reload_sub(CommandSender sender){ - for(Player online:plugin.getServer().getOnlinePlayers()){ - if(plugin.getArena(online)!= null){ - a=plugin.getArena(online); - plugin.RestoreInv(online, online.getName()); - online.teleport(getArenaSpawn()); - } - } - - plugin.location.clear(); - plugin.Reward.clear(); - plugin.Cost.clear(); - plugin.Fee.clear(); - plugin.ChestPay.clear(); - plugin.spawns = null; - plugin.worldsNames.clear(); - plugin.data = null; - plugin.management = null; - plugin.MyChests = null; - HandlerList.unregisterAll(plugin); - plugin.reloadConfig(); - plugin.onEnable(); - sender.sendMessage(ChatColor.AQUA + "HungerArena Reloaded!"); - System.out.println(ChatColor.GREEN + sender.getName() + " reloaded HungerArena!"); - } - private void warpall_sub(final CommandSender sender, String[] args){ - if((plugin.spawns.getString("Spawns_set.0")==null) || plugin.spawns.getString("Spawns_set.0").equalsIgnoreCase("false")){ - sender.sendMessage(ChatColor.RED + "/ha setspawn hasn't ever been run!"); - }else{ - if(args.length>= 2){ - if (checkarena(args[1], sender)){ - a = Integer.parseInt(args[1]); - if((plugin.spawns.getString("Spawns_set."+a)==null) || (plugin.spawns.getString("Spawns_set."+a).equalsIgnoreCase("false"))){ - sender.sendMessage(ChatColor.RED + "/ha setspawn for Arena "+ a +" hasn't been run!"); - }else{ - if(plugin.Playing.get(a).size()<= 1){ - sender.sendMessage(ChatColor.RED + "There are not enough players!"); - - }else if (plugin.canjoin.get(a)== true) { - sender.sendMessage(ChatColor.RED + "Game already in progress!"); - - }else{ - plugin.setTorch(a, false); - - if(plugin.config.getString("Auto_Start").equalsIgnoreCase("true")){ - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha start " + a); - } - }, 20L); - } - List shuffle = new ArrayList(); - for (i=1;i<=plugin.location.get(a).size();shuffle.add(i++)){} - Collections.shuffle(shuffle); - i=1; - for(String playing:plugin.Playing.get(a)){ - Player tribute = plugin.getServer().getPlayerExact(playing); - plugin.Frozen.get(a).add(tribute.getName()); - Location toLoc = plugin.location.get(a).get(shuffle.get(i)); - tribute.setHealth(20); - tribute.setFoodLevel(20); - tribute.setSaturation(20); - tribute.setLevel(0); - clearInv(tribute); - for(PotionEffect pe: tribute.getActivePotionEffects()){ - PotionEffectType potion = pe.getType(); - tribute.removePotionEffect(potion); - } - if(tribute.getAllowFlight()){ - tribute.setAllowFlight(false); - } - Location opposite = toLoc.clone(); - double dist=0; - double dist2; - for (Location loc:plugin.location.get(a).values()){ - dist2=loc.distance(toLoc); - if (dist2>dist){ - dist = dist2; - opposite = loc.clone(); - } - } - toLoc.setDirection(opposite.toVector().subtract(toLoc.toVector())); - MetadataValue MdV_Location = new FixedMetadataValue(plugin,toLoc); - tribute.setMetadata("HA-Location", MdV_Location); - tribute.teleport(toLoc); - i+=1; - } - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - sender.sendMessage(ChatColor.AQUA + "All Tributes warped!"); - plugin.MatchRunning.put(a, "warped"); - } - }, 10L); - } - } - } - }else{ - sender.sendMessage(ChatColor.RED + "Too few arguments, specify an arena"); - } - } - } - private void start_sub(CommandSender sender, String[] args){ - if(args.length!= 2){ - sender.sendMessage(ChatColor.RED + "You need to specify the arena to start!"); - }else{ - if (checkarena(args[1], sender)){ - a = Integer.parseInt(args[1]); - if(plugin.canjoin.get(a)== true) - sender.sendMessage(ChatColor.RED + "Game already in progress!"); - else if(plugin.Playing.get(a).size()== 1){ - sender.sendMessage(ChatColor.RED + "There are not enough players!"); - } - else if(plugin.Playing.get(a).isEmpty()) - sender.sendMessage(ChatColor.RED + "No one is in that game!"); - else if ((plugin.MatchRunning.get(a)!=null) && (plugin.MatchRunning.get(a).equals("warped"))) - plugin.startGames(a); - else sender.sendMessage(ChatColor.RED + "First all players must be warped!"); - } - } - } - private boolean checkarena(String Int, CommandSender sender){ - a=0; - try { - a = Integer.parseInt(Int); - } catch (NumberFormatException e){ - sender.sendMessage(ChatColor.RED + "You have to enter the Arena number!"); - return false; - } - if (a>0){ - if (plugin.canjoin.containsKey(a)){ - return true; - } - } - sender.sendMessage(ChatColor.RED + "That arena doesn't exist!"); - return false; - } - - private void confirmSub(Player p, String pname, String ThisWorld){ - if(plugin.config.getBoolean("EntryFee.enabled")){ - if((!plugin.config.getBoolean("EntryFee.eco")) || (plugin.config.getBoolean("EntryFee.eco") && !(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost")))){ - i = 0; - for(ItemStack fee: plugin.Fee){ - int total = plugin.Fee.size(); - if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ - i += 1; - if(total == i){ - if (plugin.config.getBoolean("EntryFee.eco")) { - plugin.econ.withdrawPlayer(p, plugin.config.getDouble("EntryFee.cost")); - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + "$" + plugin.config.getDouble("EntryFee.cost") + " has been taken from your account!"); - } - for(ItemStack fees: plugin.Fee){ - String beginning = fees.getType().toString().substring(0, 1); - String item = beginning.toUpperCase() + fees.getType().toString().substring(1).toLowerCase().replace("_", " "); - int amount = fees.getAmount(); - p.getInventory().removeItem(fees); - if(amount> 1) - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + amount + " " + item + "s was paid to join the games."); - else - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + amount + " " + item + " was paid to join the games."); - } - preparePlayer(p, pname, ThisWorld); - } - } - } - if(plugin.Fee.size() > i){ - p.sendMessage(ChatColor.RED + "You are missing some items and can't join the games..."); - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have enough money to join!"); - } - }else if(plugin.config.getBoolean("EntryFee.eco")){ - if(!(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost"))){ - plugin.econ.withdrawPlayer(p, plugin.config.getDouble("EntryFee.cost")); - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + "$" + plugin.config.getDouble("EntryFee.cost") + " has been taken from your account!"); - preparePlayer(p, pname, ThisWorld); - }else{ - p.sendMessage(ChatColor.RED + "You don't have enough money to join!"); - } - }else{ - preparePlayer(p, pname, ThisWorld); - } - } - private void preparePlayer(Player p, String pname, String ThisWorld){ - plugin.Playing.get(a).add(pname); - plugin.NeedConfirm.get(a).remove(pname); - p.sendMessage(ChatColor.GREEN + "Do /ha ready to vote to start the games!"); - FileConfiguration pinfo = plugin.getPConfig(pname); - pinfo.set("inv", p.getInventory().getContents()); - pinfo.set("armor", p.getInventory().getArmorContents()); - pinfo.set("world", ThisWorld); - pinfo.set("player", pname); - plugin.savePFile(pname); - clearInv(p); - plugin.needInv.add(pname); - if(plugin.config.getBoolean("broadcastAll")){ - plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "! " + ChatColor.GRAY + plugin.Playing.get(a).size() + "/" + plugin.maxPlayers.get(a)); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(ChatColor.AQUA + pname + " has Joined the Game! " + ChatColor.GRAY + plugin.Playing.get(a).size() + "/" + plugin.maxPlayers.get(a)); - } - } - if(plugin.Playing.get(a).size()== plugin.maxPlayers.get(a)){ - plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "ha warpall " + a); - } - } -} diff --git a/src/me/Travja/HungerArena/Listeners/BlockStorage.java b/src/me/Travja/HungerArena/Listeners/BlockStorage.java deleted file mode 100644 index 4c6b55f..0000000 --- a/src/me/Travja/HungerArena/Listeners/BlockStorage.java +++ /dev/null @@ -1,274 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import java.util.List; - -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockFadeEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.material.MaterialData; - -public class BlockStorage implements Listener { - public Main plugin; - public BlockStorage(Main m) { - this.plugin = m; - } - - @EventHandler(priority=EventPriority.MONITOR) - public void BlockBreak(BlockBreakEvent event) { - Block b = event.getBlock(); - Player p = event.getPlayer(); - String pname = p.getName(); - boolean protall = false; - if(!p.hasPermission("HungerArena.arena")){ - protall = protall(); //true = protect allways!! - } - if ((plugin.getArena(p) != null) || (protall)) { - //Jeppa: get a default arena if protall is true... (but use getArena if set...) - int a = 1; - if (protall) { - String ThisWorld = p.getWorld().getName(); - for(int z : plugin.worldsNames.keySet()){ - if(plugin.worldsNames.get(z)!= null){ - if (plugin.worldsNames.get(z).equals(ThisWorld)){ - a=z; - } - } - } - } - if (plugin.getArena(p) != null) a = plugin.getArena(p); - if ((!event.isCancelled()) && (((plugin.Playing.get(a)).contains(pname)) || (protall))) - { - if (plugin.config.getString("Protected_Arena").equalsIgnoreCase("True")) { - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You can't break blocks while playing!"); - } else if ( (plugin.canjoin.get(a) || protall) && ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.values().contains(p.getWorld().getName()))))) { - if (((plugin.management.getStringList("blocks.whitelist").isEmpty()) || ((!plugin.management.getStringList("blocks.whitelist").isEmpty()) && (!plugin.management.getStringList("blocks.whitelist").contains(String.valueOf(b.getType().name()))))) ^ (plugin.management.getBoolean("blocks.useWhitelistAsBlacklist"))) { - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "That is an illegal block!"); - } else { - String w = b.getWorld().getName(); - addDestroyedBlockToList(b, w, a); - } - } - } - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void Explosion(EntityExplodeEvent event){ - List blocksd = event.blockList(); - Entity e = event.getEntity(); - if(!event.isCancelled()){ - for(int i : plugin.canjoin.keySet()){ - if(plugin.canjoin.get(i) || protall()){ - String ThisWorld = e.getWorld().getName(); - if ((!plugin.restricted) || ((plugin.restricted) && plugin.worldsNames.get(i)!=null && plugin.worldsNames.get(i).equalsIgnoreCase(ThisWorld))) { - if(e.getType()== EntityType.PRIMED_TNT){ - e.getLocation().getBlock().setType(Material.TNT); - Block TNT = e.getLocation().getBlock(); - addDestroyedBlockToList(TNT, ThisWorld, i); - TNT.setType(Material.AIR); - } - for(Block b:blocksd){ - if (!b.getType().name().equalsIgnoreCase("AIR")){ - addDestroyedBlockToList(b, ThisWorld, i); - } - } - } - } - } - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void burningBlocks(BlockBurnEvent event){ - Block b = event.getBlock(); - if(!event.isCancelled()){ - for(int i : plugin.canjoin.keySet()){ - if(plugin.canjoin.get(i) || protall()){ - if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.get(i)!=null && plugin.worldsNames.get(i).equalsIgnoreCase(b.getWorld().getName())))) { - String w = b.getWorld().getName(); - addDestroyedBlockToList(b, w, i); - } - } - } - } - } - @EventHandler(priority = EventPriority.MONITOR) - public void blockPlace(BlockPlaceEvent event){ - Block b = event.getBlock(); - Player p = event.getPlayer(); - boolean protall = false; - if(!p.hasPermission("HungerArena.arena")){ - protall = protall(); - } - if ((plugin.getArena(p) != null) || (protall)) { - int a = 1; - if (protall) { - String ThisWorld = p.getWorld().getName(); - for(int z : plugin.worldsNames.keySet()){ - if(plugin.worldsNames.get(z)!= null){ - if (plugin.worldsNames.get(z).equals(ThisWorld)){ - a=z; - } - } - } - } - if (plugin.getArena(p) != null) a = plugin.getArena(p); - if(!event.isCancelled()){ - if (((plugin.Playing.get(a)).contains(p.getName())) || (protall)) { - if((plugin.canjoin.get(a)) || (protall)){ - if ( (!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.values().contains(b.getWorld().getName())))) { - if((b.getType()== Material.SAND || b.getType()== Material.GRAVEL) && (b.getRelative(BlockFace.DOWN).getType()== Material.AIR || b.getRelative(BlockFace.DOWN).getType()== Material.WATER || b.getRelative(BlockFace.DOWN).getType()== Material.LAVA)){ - int n = b.getY() -1; - while(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.LAVA){ - n = n -1; - event.getPlayer().sendMessage(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType().toString().toLowerCase()); - if(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.LAVA){ - int l = n +1; - Block br = b.getWorld().getBlockAt(b.getX(), l, b.getZ()); - String w = br.getWorld().getName(); - - addPlacedBlockToList(br, w, a); - } - } - }else{ - if(b.getType()!= Material.SAND && b.getType()!= Material.GRAVEL){ - String w = b.getWorld().getName(); - - addPlacedBlockToList(b, w, a); - } - } - } - } - } - } - } - } - @EventHandler(priority = EventPriority.MONITOR) - public void bucketEmpty(PlayerBucketEmptyEvent event){ - if(plugin.getArena(event.getPlayer())!= null){ - int a = plugin.getArena(event.getPlayer()); - if(!event.isCancelled()){ - if(plugin.canjoin.get(a)){ - if(plugin.Playing.get(a).contains(event.getPlayer().getName())){ - if ( (!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.values().contains(event.getPlayer().getWorld().getName())))) { - Block b = event.getBlockClicked().getRelative(event.getBlockFace()); - String w = b.getWorld().getName(); - addPlacedBlockToList(b, w, a); - } - } - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void bucketFill(PlayerBucketFillEvent event){ - if(plugin.getArena(event.getPlayer())!= null){ - int a = plugin.getArena(event.getPlayer()); - if(!event.isCancelled()){ - if(plugin.canjoin.get(a)){ - if(plugin.Playing.get(a).contains(event.getPlayer().getName())){ - if ( (!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.values().contains(event.getPlayer().getWorld().getName())))) { - Block b = event.getBlockClicked().getRelative(event.getBlockFace()); - String w = b.getWorld().getName(); - addDestroyedBlockToList(b, w, a); - } - } - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void blockMelt(BlockFadeEvent event){ - if(!event.isCancelled()){ - for(int i:plugin.canjoin.keySet()){ - if(plugin.canjoin.get(i) || protall()){ - if ( (!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.get(i)!=null && plugin.worldsNames.get(i).equalsIgnoreCase(event.getBlock().getWorld().getName())))) { - Block b = event.getBlock(); - String w = b.getWorld().getName(); - String d = b.getType().name(); - if (d.equalsIgnoreCase("FIRE") || d.equalsIgnoreCase("AIR")) continue; - addDestroyedBlockToList(b, w, i); - } - } - } - } - } - - //SubRoutines: - private boolean protall(){ - if (plugin.config.getString("Protected_Arena_Always").equalsIgnoreCase("True")) { - return true; - } - return false; - } - - - private void addDestroyedBlockToList(Block b, String w, int a){ - int x = b.getX(); - int y = b.getY(); - int z = b.getZ(); - String d = b.getType().name(); - byte m=0; - String BlDataString=null; - String sp = ";"; - - String dir=""; - try { - if (b.getState().getBlockData() instanceof BlockData){ - BlDataString = b.getBlockData().getAsString(); - } - } catch (Exception | NoSuchMethodError ex){ - m = b.getData(); - sp=","; - MaterialData mData = b.getState().getData(); - if (mData instanceof org.bukkit.material.Directional) { - BlockFace Dir = ((org.bukkit.material.Directional)mData).getFacing(); - if (Dir !=null) { - dir=sp+(Dir.name()); - } - } - } - String data = BlDataString!=null?BlDataString:String.valueOf(m); - String coords = w + sp + x + sp + y + sp + z + sp + d + sp + data + sp + a + dir; - List blocks = plugin.data.getStringList("Blocks_Destroyed"); - if (!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + a)) { - blocks.add(coords); - plugin.data.set("Blocks_Destroyed", blocks); - plugin.saveData(); - } - } - private void addPlacedBlockToList(Block br, String w, int a){ - int x = br.getX(); - int y = br.getY(); - int z = br.getZ(); - String coords = w + "," + x + "," + y + "," + z + "," + a; - List blocks = plugin.data.getStringList("Blocks_Placed"); - if (!blocks.contains(coords)){ - blocks.add(coords); - plugin.data.set("Blocks_Placed", blocks); - plugin.saveData(); - } - } - -} \ No newline at end of file diff --git a/src/me/Travja/HungerArena/Listeners/Boundaries.java b/src/me/Travja/HungerArena/Listeners/Boundaries.java deleted file mode 100644 index 244d676..0000000 --- a/src/me/Travja/HungerArena/Listeners/Boundaries.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import java.util.Map; -import java.util.Map.Entry; - -import me.Travja.HungerArena.Main; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.player.PlayerMoveEvent; - -public class Boundaries implements Listener{ - public Main plugin; - public Boundaries(Main m){ - this.plugin = m; - } - - @EventHandler - public void boundsCheck(PlayerMoveEvent event){ - Player p = event.getPlayer(); - Boolean inGame = plugin.getArena(p) != null; - Boolean spectating = plugin.isSpectating(p); - if(plugin.config.getBoolean("WorldEdit")) - if(insideBounds(p.getLocation()) && (inGame || spectating) || (!insideBounds(p.getLocation()) && inGame)) - event.setCancelled(true); - } - @EventHandler - public void blockBounds(BlockBreakEvent event){ - Player p = event.getPlayer(); - if(plugin.getArena(p)== null) - if(plugin.config.getBoolean("WorldEdit")) - if(insideBounds(event.getBlock().getLocation())){ - p.sendMessage(ChatColor.RED + "That block is protected by HungerArena!"); - event.setCancelled(true); - } - } - public boolean insideBounds(Location l){ - Location minl = null; - Location maxl = null; - if(plugin.spawns.get("Arena")!= null){ - Map temp = plugin.spawns.getConfigurationSection("Arena").getValues(false); - for(Entry entry: temp.entrySet()){ - if(plugin.spawns.getConfigurationSection("Arena." + entry.getKey())!= null){ - String[] min = ((String) plugin.spawns.get("Arena." + entry.getKey()) + ".Min").split(","); - String[] max = ((String) plugin.spawns.get("Arena." + entry.getKey()) + ".Max").split(","); - try{ - World world = Bukkit.getWorld(min[0]); - double x = Double.parseDouble(min[1]); - double y = Double.parseDouble(min[2]); - double z = Double.parseDouble(min[3]); - minl = new Location(world, x, y, z); - World world2 = Bukkit.getWorld(max[0]); - double x2 = Double.parseDouble(max[1]); - double y2 = Double.parseDouble(max[2]); - double z2 = Double.parseDouble(max[3]); - minl = new Location(world2, x2, y2, z2); - }catch(Exception e){ - System.out.println(e); - return false; - } - if(minl!= null && maxl!= null){ - return l.getX() >= minl.getBlockX() - && l.getX() < maxl.getBlockX() + 1 && l.getY() >= minl.getBlockY() - && l.getY() < maxl.getBlockY() + 1 && l.getZ() >= minl.getBlockZ() - && l.getZ() < maxl.getBlockZ() + 1; - } - } - } - } - return false; - } -} diff --git a/src/me/Travja/HungerArena/Listeners/ChatListener.java b/src/me/Travja/HungerArena/Listeners/ChatListener.java deleted file mode 100644 index 1e4eb9d..0000000 --- a/src/me/Travja/HungerArena/Listeners/ChatListener.java +++ /dev/null @@ -1,52 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import java.util.List; - -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; - -public class ChatListener implements Listener { - public Main plugin; - public ChatListener(Main m) { - this.plugin = m; - } - @EventHandler - public void TributeChat(AsyncPlayerChatEvent event){ - Player p = event.getPlayer(); - String pname = p.getName(); - if(plugin.getArena(p)!= null){ - String msg = "<" + ChatColor.RED + "[Tribute] " + ChatColor.WHITE + pname + ">" + " " + event.getMessage(); - if(plugin.config.getString("ChatClose").equalsIgnoreCase("True")){ - double radius = plugin.config.getDouble("ChatClose_Radius"); - List near = p.getNearbyEntities(radius, radius, radius); - event.setCancelled(true); - if(!(near.size()== 0)){ - p.sendMessage(msg); - for(Entity e:near){ - if(e instanceof Player) - ((Player) e).sendMessage(msg); - } - }else if(near.size()== 0){ - p.sendMessage(msg); - p.sendMessage(ChatColor.YELLOW + "No one near!"); - }else if(!(near.size()== 0)){ - for(Entity en:near){ - if(!(en instanceof Player)){ - p.sendMessage(msg); - p.sendMessage(ChatColor.YELLOW + "No one near!"); - } - } - } - }else{ - event.setCancelled(true); - plugin.getServer().broadcastMessage(msg); - } - } - } -} diff --git a/src/me/Travja/HungerArena/Listeners/DeathListener.java b/src/me/Travja/HungerArena/Listeners/DeathListener.java deleted file mode 100644 index 80517c2..0000000 --- a/src/me/Travja/HungerArena/Listeners/DeathListener.java +++ /dev/null @@ -1,207 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.Main; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.scoreboard.DisplaySlot; - -public class DeathListener implements Listener{ - public Main plugin; - public DeathListener(Main m){ - this.plugin = m; - } - public FileConfiguration config; - int i = 0; - int a = 0; - @EventHandler (priority = EventPriority.HIGHEST) - public void onPlayerRespawn(PlayerRespawnEvent event){ - final Player p = event.getPlayer(); - String pname = p.getName(); - - //get the arena the player has died in... (may be not the one he joined...) - String ThisWorld = p.getWorld().getName(); - for(int z : plugin.worldsNames.keySet()){ - if(plugin.worldsNames.get(z)!= null){ - if (plugin.worldsNames.get(z).equals(ThisWorld)){ - a=z; - } - } - } - - //Jeppa: Fix for lonely players :) - for(int i : plugin.Dead.keySet()){ - if ((plugin.Dead.get(i) != null) && (plugin.Dead.get(i).contains(pname)) && (plugin.MatchRunning.get(i) == null)) { - plugin.Dead.get(i).clear(); - } - } - - for(int i = 0; i < plugin.needInv.size(); i++){ - if(plugin.needInv.contains(pname)){ - RespawnDeadPlayer(p,a); - } - } - } - private void RespawnDeadPlayer(Player p, int a){ - final Player player = p; - String[] Spawncoords = plugin.spawns.getString("Spawn_coords."+a).split(","); - World spawnw = plugin.getServer().getWorld(Spawncoords[3]); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - player.teleport(Spawn); - plugin.RestoreInv(player, player.getName()); - } - }, 10L); - } - - @EventHandler (priority = EventPriority.HIGHEST) - public void onPlayerDeath(PlayerDeathEvent event){ - Player p = event.getEntity(); - Server s = p.getServer(); - String pname = p.getName(); - if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - int players = plugin.Playing.get(a).size()-1; - String leftmsg = null; - clearInv(p); - event.getDrops().clear(); - p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - plugin.scoreboards.remove(p.getName()); - if(!plugin.Frozen.get(a).isEmpty()){ - if(plugin.Frozen.get(a).contains(pname)){ - if(!(p.getKiller() instanceof Player)){ - players = plugin.Playing.get(a).size()-1; - leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!"; - if(plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")){ - double y = p.getLocation().getY(); - double newy = y+200; - double x = p.getLocation().getX(); - double z = p.getLocation().getZ(); - Location strike = new Location(p.getWorld(), x, newy, z); - p.getWorld().strikeLightning(strike); - } - event.setDeathMessage(""); - if(plugin.config.getBoolean("broadcastAll")){ - p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); - } - } - plugin.Frozen.get(a).remove(pname); - plugin.Playing.get(a).remove(pname); - if(plugin.config.getBoolean("broadcastAll")){ - p.getServer().broadcastMessage(leftmsg); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(leftmsg); - } - } - plugin.winner(a); - } - } - }else{ - players = plugin.Playing.get(a).size()-1; - leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!"; - if(plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")){ - double y = p.getLocation().getY(); - double newy = y+200; - double x = p.getLocation().getX(); - double z = p.getLocation().getZ(); - Location strike = new Location(p.getWorld(), x, newy, z); - p.getWorld().strikeLightning(strike); - } - plugin.Dead.get(a).add(pname); - plugin.Playing.get(a).remove(pname); - if(p.getKiller() instanceof Player){ - if(p.getKiller().getInventory().getItemInMainHand().getType()== Material.AIR){ - Player killer = p.getKiller(); - String killername = killer.getName(); - event.setDeathMessage(""); - if(plugin.config.getBoolean("broadcastAll")){ - s.broadcastMessage(ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with their FIST!"); - s.broadcastMessage(leftmsg); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with their FIST!"); - g.sendMessage(leftmsg); - } - } - if(plugin.Kills.containsKey(killername)) - plugin.Kills.put(killername, plugin.Kills.get(killername)+1); - else plugin.Kills.put(killername, 1); - if(plugin.Kills.containsKey("__SuM__")) - plugin.Kills.put("__SuM__", plugin.Kills.get("__SuM__")+1); - else plugin.Kills.put("__SuM__", 1); - plugin.winner(a); - }else{ - Player killer = p.getKiller(); - String killername = killer.getName(); - String weapon = "a(n) " + killer.getInventory().getItemInMainHand().getType().name().replace('_', ' '); - if(killer.getInventory().getItemInMainHand().hasItemMeta()) - if(killer.getInventory().getItemInMainHand().getItemMeta().hasDisplayName()) - weapon = killer.getInventory().getItemInMainHand().getItemMeta().getDisplayName(); - String msg = ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with " + weapon; - event.setDeathMessage(""); - if(plugin.config.getBoolean("broadcastAll")){ - s.broadcastMessage(msg); - s.broadcastMessage(leftmsg); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(msg); - g.sendMessage(leftmsg); - } - } - if(plugin.Kills.containsKey(killername)) - plugin.Kills.put(killername, plugin.Kills.get(killername)+1); - else plugin.Kills.put(killername, 1); - if(plugin.Kills.containsKey("__SuM__")) - plugin.Kills.put("__SuM__", plugin.Kills.get("__SuM__")+1); - else plugin.Kills.put("__SuM__", 1); - plugin.winner(a); - } - }else{ - event.setDeathMessage(""); - if(plugin.config.getBoolean("broadcastAll")){ - s.broadcastMessage(ChatColor.LIGHT_PURPLE + pname + " died of natural causes!"); - s.broadcastMessage(leftmsg); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(ChatColor.LIGHT_PURPLE + pname + " died of " + ChatColor.ITALIC + " probably " + ChatColor.LIGHT_PURPLE + "natural causes!"); - g.sendMessage(leftmsg); - } - } - plugin.winner(a); - } - } - } - } - private void clearInv(Player p){ - p.getInventory().clear(); - p.getInventory().setBoots(null); - p.getInventory().setChestplate(null); - p.getInventory().setHelmet(null); - p.getInventory().setLeggings(null); - p.updateInventory(); - } -} diff --git a/src/me/Travja/HungerArena/Listeners/FreezeListener.java b/src/me/Travja/HungerArena/Listeners/FreezeListener.java deleted file mode 100644 index 65b122b..0000000 --- a/src/me/Travja/HungerArena/Listeners/FreezeListener.java +++ /dev/null @@ -1,121 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.metadata.MetadataValue; - -public class FreezeListener implements Listener { - public Main plugin; - public FreezeListener(Main m) { - this.plugin = m; - } - int i = 0; - int a = 0; - private HashMap timeUp= new HashMap(); - private ArrayList timing = new ArrayList(); - - @EventHandler - public void onPlayerMove(PlayerMoveEvent event){ - Player p = event.getPlayer(); - String pname = p.getName(); - if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - if(plugin.Frozen.get(a).contains(pname) && plugin.config.getString("Frozen_Teleport").equalsIgnoreCase("True")){ - if(plugin.config.getString("Explode_on_Move").equalsIgnoreCase("true")){ - timeUp.put(a, false); - for(String players: plugin.Playing.get(a)){ - Player playing = plugin.getServer().getPlayerExact(players); - i = plugin.Playing.get(a).indexOf(players)+1; - if(!timeUp.get(a) && !timing.contains(a)){ - timing.add(a); - if(!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())){ - playing.teleport(plugin.location.get(a).get(i)); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - if(!timeUp.get(a)){ - timeUp.put(a, true); - timing.remove(a); - } - } - },30L); - } - }else{ - if(!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())){ - if(!plugin.Dead.get(a).contains(playing.getName())){ - plugin.Dead.get(a).add(playing.getName()); - World world = playing.getLocation().getWorld(); - world.createExplosion(playing.getLocation(), 0.0F, false); - playing.setHealth(0.0D); - } - } - } - } - if(plugin.Dead.get(a).contains(pname) && plugin.Playing.get(a).contains(pname)){ - int players = plugin.Playing.get(a).size()-1; - String leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!"; - if(plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")){ - double y = p.getLocation().getY(); - double newy = y+200; - double x = p.getLocation().getX(); - double z = p.getLocation().getZ(); - Location strike = new Location(p.getWorld(), x, newy, z); - p.getWorld().strikeLightning(strike); - } - if(plugin.config.getBoolean("broadcastAll")){ - p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); - } - } - plugin.Frozen.get(a).remove(pname); - plugin.Playing.get(a).remove(pname); - if(plugin.config.getBoolean("broadcastAll")){ - p.getServer().broadcastMessage(leftmsg); - }else{ - for(String gn: plugin.Playing.get(a)){ - Player g = plugin.getServer().getPlayer(gn); - g.sendMessage(leftmsg); - } - } - plugin.winner(a); - } - }else{ - i = plugin.Playing.get(a).indexOf(pname)+1; - Location pLoc=null; - if (p.hasMetadata("HA-Location")){ - List l=p.getMetadata("HA-Location"); - if (l !=null && l.size()!=0 ){ - try { - pLoc=(Location) l.get(0).value(); - } catch (Exception e){} - } - if (pLoc!=null) { - if(p.getLocation().getBlockX()!=(pLoc.getBlockX()) || p.getLocation().getBlockZ()!=(pLoc.getBlockZ())){ - pLoc.setX(pLoc.getBlock().getLocation().getX()+.5); - pLoc.setZ(pLoc.getBlock().getLocation().getZ()+.5); - p.teleport(pLoc); - } - } else { - if(!p.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())){ - p.teleport(plugin.location.get(a).get(i)); - } - } - } - } - } - } - } -} diff --git a/src/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java b/src/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java deleted file mode 100644 index 5f115ca..0000000 --- a/src/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java +++ /dev/null @@ -1,188 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.HaCommands; -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.scoreboard.DisplaySlot; - -public class JoinAndQuitListener implements Listener { - public Main plugin; - public JoinAndQuitListener(Main m) { - this.plugin = m; - } - public HaCommands commands; - public JoinAndQuitListener(HaCommands h){ - this.commands = h; - } - int a = 0; - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event){ - final Player p = event.getPlayer(); - final String pname = p.getName(); - boolean pfound = false; - for(int i : plugin.Watching.keySet()){ - for(String s: plugin.Watching.get(i)){ - Player spectator = plugin.getServer().getPlayerExact(s); - p.hidePlayer(plugin,spectator); - } - } - for(int i : plugin.Out.keySet()){ - if(plugin.Out.get(i).contains(pname)){ - plugin.Playing.get(i).add(pname); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - p.sendMessage(ChatColor.AQUA + "You have saved yourself from being ejected from the arena!"); - } - }, 40L); - plugin.Out.get(i).remove(pname); - pfound = true; - } - } - - for(final int i : plugin.Quit.keySet()){ - if(plugin.Quit.get(i).contains(pname)){ - String[] Spawncoords = plugin.spawns.getString("Spawn_coords."+i).split(","); - String w = Spawncoords[3]; - World spawnw = plugin.getServer().getWorld(w); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - p.teleport(Spawn); - p.sendMessage(ChatColor.RED + "You have been teleported to last spawn because you quit/forfeited!"); - plugin.RestoreInv(p, p.getName()); - if (plugin.Quit.get(i)!= null) plugin.Quit.get(i).remove(p.getName()); - } - }, 40L); - pfound = true; - } - } - for(final int i : plugin.Dead.keySet()){ - if(plugin.Dead.get(i).contains(pname)){ - String[] Spawncoords = plugin.spawns.getString("Spawn_coords."+i).split(","); - String w = Spawncoords[3]; - World spawnw = plugin.getServer().getWorld(w); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - p.teleport(Spawn); - p.sendMessage(ChatColor.RED + "You have been teleported to spawn because you quit/died/forfeited!!"); - plugin.RestoreInv(p, p.getName()); - if (plugin.Dead.get(i)!= null) plugin.Dead.get(i).remove(p.getName()); - } - }, 40L); - pfound = true; - } - } - for(final int i : plugin.inArena.keySet()){ - if(plugin.inArena.get(i)!= null){ - if(plugin.inArena.get(i).contains(pname)){ - String[] Spawncoords = plugin.spawns.getString("Spawn_coords."+i).split(","); - String w = Spawncoords[3]; - World spawnw = plugin.getServer().getWorld(w); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - p.teleport(Spawn); - p.getInventory().clear(); - p.getInventory().setBoots(null); - p.getInventory().setLeggings(null); - p.getInventory().setChestplate(null); - p.getInventory().setHelmet(null); - plugin.inArena.remove(pname); - p.sendMessage(ChatColor.RED + "You were still in the arena when you left and now the games are over."); - plugin.RestoreInv(p, p.getName()); - if (plugin.inArena.get(i)!= null) plugin.inArena.get(i).remove(p.getName()); - } - }, 40L); - pfound = true; - } - } - } - if((plugin.restricted && plugin.worldsNames.values().contains(p.getWorld().getName())) || !plugin.restricted){ - if (!pfound && plugin.config.getString("Force_Players_toSpawn").equalsIgnoreCase("True") && (plugin.spawns.getString("Spawn_coords.0")!=null)) { - String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); - String w = Spawncoords[3]; - World spawnw = plugin.getServer().getWorld(w); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - plugin.RestoreInv(p, p.getName()); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - p.teleport(Spawn); - p.sendMessage(ChatColor.RED + "You have been teleported to spawn!!"); - } - }, 40L); - } - } - } - @EventHandler - public void onQuit(PlayerQuitEvent evt) { - Player p = evt.getPlayer(); - String pname = p.getName(); - for(int i : plugin.Frozen.keySet()){ - if (plugin.Frozen.get(i).contains(pname)) { - plugin.Frozen.remove(pname); - String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); - String w = Spawncoords[3]; - World spawnw = plugin.getServer().getWorld(w); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - p.teleport(Spawn); - p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - if(plugin.scoreboards.containsKey(p.getName())) - plugin.scoreboards.remove(p.getName()); - if(plugin.Kills.containsKey(p.getName())) - plugin.Kills.remove(p.getName()); - } - } - } - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event){ - final Player p = event.getPlayer(); - final String pname = p.getName(); - if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - plugin.Out.get(a).add(pname); - plugin.Playing.get(a).remove(pname); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - if(plugin.Out.get(a).contains(pname)){ - plugin.Quit.get(a).add(pname); - plugin.Out.get(a).remove(pname); - p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - if(plugin.scoreboards.containsKey(p.getName())) - plugin.scoreboards.remove(p.getName()); - if(plugin.Kills.containsKey(p.getName())) - plugin.Kills.remove(p.getName()); - plugin.winner(a); - plugin.inArena.get(a).add(pname); - }else if(plugin.getArena(p)== null){ - plugin.Quit.get(a).add(pname); - } - } - }, 1200L); - } - } -} diff --git a/src/me/Travja/HungerArena/Listeners/PvP.java b/src/me/Travja/HungerArena/Listeners/PvP.java deleted file mode 100644 index d226c49..0000000 --- a/src/me/Travja/HungerArena/Listeners/PvP.java +++ /dev/null @@ -1,97 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.Main; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.Skeleton; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -public class PvP implements Listener { - public Main plugin; - public PvP(Main m) { - this.plugin = m; - } - int a = 0; - @EventHandler(priority= EventPriority.MONITOR) - public void PlayerPvP(EntityDamageByEntityEvent event){ - Entity pl = event.getEntity(); - Entity dl = event.getDamager(); - if(pl instanceof Player && dl instanceof Player){ - Player p = (Player) pl; - Player d = (Player) dl; - if(plugin.getArena(p)!= null && plugin.getArena(d)!= null){ - a = plugin.getArena(p); - if(plugin.canjoin.get(a)){ - if(event.isCancelled()){ - event.setCancelled(false); - } - if(plugin.gp.get(plugin.getArena(p))!= null){ - if(plugin.gp.get(plugin.getArena(p))!= 0){ - event.setCancelled(true); - } - } - } - } - if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - if(!plugin.canjoin.get(a)){ - if(!event.isCancelled()){ - event.setCancelled(true); - } - } - } - if(plugin.getArena(p)== null && plugin.getArena(d)!= null){ - if(!event.isCancelled()){ - event.setCancelled(true); - } - } - }else if(pl instanceof Player && dl instanceof Projectile){ - Projectile projectile = (Projectile) dl; - Player p = (Player) pl; - if(projectile.getShooter() instanceof Player){ - if(plugin.getArena(p) != null){ - Player shooter = (Player) projectile.getShooter(); - if(plugin.getArena(shooter)!= null){ - if(plugin.gp.get(plugin.getArena(p))!= null) - if(plugin.gp.get(plugin.getArena(p))!= 0) - event.setCancelled(true); - else - event.setCancelled(false); - } - } - }else if(projectile.getShooter() instanceof Entity){ - Entity e = (Entity) projectile.getShooter(); - if(e instanceof Skeleton){ - if(plugin.getArena(p)!= null){ - if(plugin.gp.get(plugin.getArena((Player) e))!= null) - if(plugin.gp.get(plugin.getArena(p))!= 0) - event.setCancelled(true); - else - event.setCancelled(false); - } - } - } - } - } - @EventHandler - public void PlayerDamage(EntityDamageEvent event){ - Entity e = event.getEntity(); - if(e instanceof Player) { - Player p = (Player)e; - if(plugin.getArena(p)!=null){ - a = plugin.getArena(p); - if(plugin.gp.get(a)!= null && plugin.gp.get(a)!= 0) - event.setCancelled(true); - if (plugin.Frozen.get(a)!=null && plugin.Frozen.get(a).contains(p.getName())){ - event.setCancelled(true); - } - } - } - } - -} diff --git a/src/me/Travja/HungerArena/Listeners/SignsAndBeds.java b/src/me/Travja/HungerArena/Listeners/SignsAndBeds.java deleted file mode 100644 index 30198ab..0000000 --- a/src/me/Travja/HungerArena/Listeners/SignsAndBeds.java +++ /dev/null @@ -1,87 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.Main; -import org.bukkit.ChatColor; -import org.bukkit.Tag; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.player.PlayerInteractEvent; - -public class SignsAndBeds implements Listener { - public Main plugin; - public SignsAndBeds(Main m) { - this.plugin = m; - } - @EventHandler - public void Sign(PlayerInteractEvent event){ - Player p = event.getPlayer(); - Block b = event.getClickedBlock(); - if (b == null) { - return; - } - if(event.getAction()== Action.RIGHT_CLICK_BLOCK){ - //2019 1.14 Translate Materials: - boolean foundSign=false; - try { - if (b.getState() instanceof org.bukkit.block.Sign){ - foundSign=true; - } - } catch (Exception e){ - if (!foundSign) { - foundSign = Tag.SIGNS.isTagged(b.getType()); - } - } - if (foundSign) { - org.bukkit.block.Sign sign = (org.bukkit.block.Sign) b.getState(); - String line1 = sign.getLine(0); - String line2 = sign.getLine(1); - String line3 = sign.getLine(2); - String line4 = sign.getLine(3); - if(line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[HungerArena]") || line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[HA]")){ - if(!line2.equals("") && line3.equals("")) - p.performCommand("ha " + line2); - else if(line2.equals("") && !line3.equals("")) - p.performCommand("ha " + line3); - else if(!line2.equals("") && !line3.equals("")) { - String commands = "close,join,kick,leave,list,open,ready,refill,reload,restart,rlist,tp,start,watch,warpall"; - if (commands.contains(line3.trim().toLowerCase())) { - p.performCommand("ha " + line2); - p.performCommand("ha " + line3); - } else p.performCommand("ha " + line2 + " " + line3); - } - else - p.performCommand("ha"); - } - if(line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[Sponsor]")){ - p.performCommand("sponsor " + line2 + " " + line3 + " " + line4); - } - } - - if (plugin.config.getString("DenyBedUsage").equalsIgnoreCase("True")){ - boolean foundBed=false; - try { - if (b.getState() instanceof org.bukkit.block.Bed) { - foundBed=true; - } - } catch (Exception e){ - if (!foundBed) foundBed = Tag.BEDS.isTagged(b.getType()); - } - if (foundBed) { - event.setCancelled(true); - } - } - } - } - @EventHandler - public void Create(SignChangeEvent event){ - String top = event.getLine(0); - if(top.equalsIgnoreCase("[HungerArena]") || top.equalsIgnoreCase("[HA]") || top.equalsIgnoreCase("[Sponsor]")){ - event.setLine(0, ChatColor.BLUE + top); - } - } -} - diff --git a/src/me/Travja/HungerArena/Listeners/SignsAndBedsOld.java b/src/me/Travja/HungerArena/Listeners/SignsAndBedsOld.java deleted file mode 100644 index f81424b..0000000 --- a/src/me/Travja/HungerArena/Listeners/SignsAndBedsOld.java +++ /dev/null @@ -1,67 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.player.PlayerInteractEvent; -public class SignsAndBedsOld implements Listener { - public Main plugin; - public SignsAndBedsOld(Main m) { - this.plugin = m; - } - @SuppressWarnings("deprecation") - @EventHandler - public void Sign(PlayerInteractEvent event){ - Player p = event.getPlayer(); - Block b = event.getClickedBlock(); - if (b == null) { - return; - } - if(event.getAction()== Action.RIGHT_CLICK_BLOCK){ - if (b.getState() instanceof org.bukkit.block.Sign){ - org.bukkit.block.Sign sign = (org.bukkit.block.Sign) b.getState(); - String line1 = sign.getLine(0); - String line2 = sign.getLine(1); - String line3 = sign.getLine(2); - String line4 = sign.getLine(3); - if(line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[HungerArena]") || line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[HA]")){ - if(!line2.equals("") && line3.equals("")) - p.performCommand("ha " + line2); - else if(line2.equals("") && !line3.equals("")) - p.performCommand("ha " + line3); - else if(!line2.equals("") && !line3.equals("")) { - String commands = "close,join,kick,leave,list,open,ready,refill,reload,restart,rlist,tp,start,watch,warpall"; - if (commands.contains(line3.trim().toLowerCase())) { - p.performCommand("ha " + line2); - p.performCommand("ha " + line3); - } else p.performCommand("ha " + line2 + " " + line3); - } - else - p.performCommand("ha"); - } - if(line1.trim().equalsIgnoreCase(ChatColor.BLUE + "[Sponsor]")){ - p.performCommand("sponsor " + line2 + " " + line3 + " " + line4); - } - } - - if (plugin.config.getString("DenyBedUsage").trim().equalsIgnoreCase("true")){ - if (b.getState().getData() instanceof org.bukkit.material.Bed) { - event.setCancelled(true); - } - } - } - } - @EventHandler - public void Create(SignChangeEvent event){ - String top = event.getLine(0); - if(top.equalsIgnoreCase("[HungerArena]") || top.equalsIgnoreCase("[HA]") || top.equalsIgnoreCase("[Sponsor]")){ - event.setLine(0, ChatColor.BLUE + top); - } - } -} diff --git a/src/me/Travja/HungerArena/Listeners/SpectatorListener.java b/src/me/Travja/HungerArena/Listeners/SpectatorListener.java deleted file mode 100644 index 54209c9..0000000 --- a/src/me/Travja/HungerArena/Listeners/SpectatorListener.java +++ /dev/null @@ -1,183 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityPickupItemEvent; -import org.bukkit.event.entity.EntityTargetEvent; -import org.bukkit.event.player.*; -import org.bukkit.projectiles.ProjectileSource; -import org.bukkit.scoreboard.DisplaySlot; - -public class SpectatorListener implements Listener { - public Main plugin; - public SpectatorListener(Main m){ - this.plugin = m; - } - int i = 0; - @EventHandler - public void SpectatorDrops(PlayerDropItemEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - @EventHandler - public void SpectatorInteractBlock(PlayerInteractEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - - @EventHandler - public void SpectatorInteractEntity(PlayerInteractEntityEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - @EventHandler - public void SpectatorItems(EntityPickupItemEvent event){ - if (event.getEntity() instanceof Player) { - Player p = (Player)event.getEntity(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - } - - @EventHandler - public void SpectatorPvP(EntityDamageByEntityEvent event){ - Entity offense = event.getDamager(); - if(offense instanceof Player){ - Player Attacker = (Player) event.getDamager(); - String attackerName = Attacker.getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(attackerName)){ - event.setCancelled(true); - Attacker.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - return; - } - } - } - for(int i : plugin.Playing.keySet()){ - if(plugin.Playing.get(i)!= null){ - if(plugin.Playing.get(i).contains(attackerName)){ - event.setCancelled(true); - } - } - } - }else if(event.getDamager() instanceof Projectile){ - Projectile arrow = (Projectile) offense; - ProjectileSource shooter = arrow.getShooter(); - if(shooter instanceof Player){ - Player BowMan = (Player) shooter; - String bowManName = BowMan.getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(bowManName)){ - event.setCancelled(true); - BowMan.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - return; - } - } - } - for(int i : plugin.Playing.keySet()){ - if(plugin.Playing.get(i)!= null){ - if(plugin.Playing.get(i).contains(bowManName)){ - event.setCancelled(true); - } - } - } - } - } - } - @EventHandler - public void SpectatorBlockBreak(BlockBreakEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - @EventHandler - public void SpectatorBlockPlace(BlockPlaceEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - @EventHandler - public void SpectatorQuit(PlayerQuitEvent event){ - Player p = event.getPlayer(); - String pname = p.getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(pname)){ - plugin.Watching.get(i).remove(pname); - String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); - String w = Spawncoords[3]; - World spawnw = plugin.getServer().getWorld(w); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - p.teleport(Spawn); - p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - if(plugin.scoreboards.containsKey(p.getName())) - plugin.scoreboards.remove(p.getName()); - if(plugin.Kills.containsKey(p.getName())) - plugin.Kills.remove(p.getName()); - } - } - } - } - - @EventHandler - public void MobNerf(EntityTargetEvent event){ - Entity target = event.getTarget(); - Entity e = event.getEntity(); - if (e instanceof Player) { - return; - } - if(target instanceof Player){ - String targetName = ((Player) target).getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(targetName)){ - event.setTarget(null); - } - } - } - } - } - - private boolean denyInteraction(Player p){ - String pname = p.getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(pname)){ - return true; - } - } - } - return false; - } -} diff --git a/src/me/Travja/HungerArena/Listeners/SpectatorListenerOld.java b/src/me/Travja/HungerArena/Listeners/SpectatorListenerOld.java deleted file mode 100644 index bd21432..0000000 --- a/src/me/Travja/HungerArena/Listeners/SpectatorListenerOld.java +++ /dev/null @@ -1,182 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityTargetEvent; -import org.bukkit.event.player.*; -import org.bukkit.projectiles.ProjectileSource; -import org.bukkit.scoreboard.DisplaySlot; - -public class SpectatorListenerOld implements Listener { - public Main plugin; - public SpectatorListenerOld(Main m){ - this.plugin = m; - } - int i = 0; - @EventHandler - public void SpectatorDrops(PlayerDropItemEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - @EventHandler - public void SpectatorInteractBlock(PlayerInteractEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - - @EventHandler - public void SpectatorInteractEntity(PlayerInteractEntityEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - @SuppressWarnings("deprecation") - @EventHandler - public void SpectatorItems(PlayerPickupItemEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - - } - private boolean denyInteraction(Player p){ - String pname = p.getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(pname)){ - return true; - } - } - } - return false; - } - - - @EventHandler - public void SpectatorPvP(EntityDamageByEntityEvent event){ - Entity offense = event.getDamager(); - if(offense instanceof Player){ - Player Attacker = (Player) event.getDamager(); - String attackerName = Attacker.getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(attackerName)){ - event.setCancelled(true); - Attacker.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - return; - } - } - } - for(int i : plugin.Playing.keySet()){ - if(plugin.Playing.get(i)!= null){ - if(plugin.Playing.get(i).contains(attackerName)){ - event.setCancelled(true); - } - } - } - }else if(event.getDamager() instanceof Projectile){ - Projectile arrow = (Projectile) offense; - ProjectileSource shooter = arrow.getShooter(); - if(shooter instanceof Player){ - Player BowMan = (Player) shooter; - String bowManName = BowMan.getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(bowManName)){ - event.setCancelled(true); - BowMan.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - return; - } - } - } - for(int i : plugin.Playing.keySet()){ - if(plugin.Playing.get(i)!= null){ - if(plugin.Playing.get(i).contains(bowManName)){ - event.setCancelled(true); - } - } - } - } - } - } - @EventHandler - public void SpectatorBlockBreak(BlockBreakEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - @EventHandler - public void SpectatorBlockPlace(BlockPlaceEvent event){ - Player p = event.getPlayer(); - if (denyInteraction(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); - } - } - @EventHandler - public void SpectatorQuit(PlayerQuitEvent event){ - Player p = event.getPlayer(); - String pname = p.getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(pname)){ - plugin.Watching.get(i).remove(pname); - String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(","); - String w = Spawncoords[3]; - World spawnw = plugin.getServer().getWorld(w); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - p.teleport(Spawn); - p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - if(plugin.scoreboards.containsKey(p.getName())) - plugin.scoreboards.remove(p.getName()); - if(plugin.Kills.containsKey(p.getName())) - plugin.Kills.remove(p.getName()); - } - } - } - } - - @EventHandler - public void MobNerf(EntityTargetEvent event){ - Entity target = event.getTarget(); - Entity e = event.getEntity(); - if (e instanceof Player) { - return; - } - if(target instanceof Player){ - String targetName = ((Player) target).getName(); - for(int i : plugin.Watching.keySet()){ - if(plugin.Watching.get(i)!= null){ - if(plugin.Watching.get(i).contains(targetName)){ - event.setTarget(null); - } - } - } - } - } -} diff --git a/src/me/Travja/HungerArena/Listeners/TeleportListener.java b/src/me/Travja/HungerArena/Listeners/TeleportListener.java deleted file mode 100644 index 70d8220..0000000 --- a/src/me/Travja/HungerArena/Listeners/TeleportListener.java +++ /dev/null @@ -1,32 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerTeleportEvent; - -public class TeleportListener implements Listener { - - public Main plugin; - public TeleportListener(Main m) { - this.plugin = m; - } - @EventHandler(priority = EventPriority.MONITOR) - public void onTP(PlayerTeleportEvent event){ - Player p = event.getPlayer(); - if(plugin.worldsNames.values().contains(event.getTo().getWorld().getName()) && plugin.Tele.contains(p)){ - event.setCancelled(true); - p.sendMessage(ChatColor.RED + "You are a dead tribute... How are you supposed to get back into the arena...."); - plugin.Tele.remove(p); - }else if(plugin.Tele.contains(p)){ - if(event.isCancelled()){ - event.setCancelled(false); - plugin.Tele.remove(p); - } - } - } -} diff --git a/src/me/Travja/HungerArena/Listeners/WorldChange.java b/src/me/Travja/HungerArena/Listeners/WorldChange.java deleted file mode 100644 index b86425b..0000000 --- a/src/me/Travja/HungerArena/Listeners/WorldChange.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import me.Travja.HungerArena.Main; - -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerChangedWorldEvent; - -public class WorldChange implements Listener { - public Main plugin; - public WorldChange(Main m) { - plugin = m; - } - - @EventHandler(priority = EventPriority.LOWEST) - public void worldChangeLow(PlayerChangedWorldEvent event){ - Player p = event.getPlayer(); - String pname = p.getName(); - String ThisWorld = p.getWorld().getName(); - String FromWorld = event.getFrom().getName(); - if (!plugin.worldsNames.values().contains(ThisWorld) && plugin.worldsNames.values().contains(FromWorld)) { - plugin.RestoreInv(p, pname); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void worldChangeHigh(PlayerChangedWorldEvent event){ - Player p = event.getPlayer(); - String pname = p.getName(); - String ThisWorld = p.getWorld().getName(); - int a=0; - for(int i : plugin.worldsNames.keySet()){ - if(plugin.worldsNames.get(i)!= null){ - if (plugin.worldsNames.get(i).equals(ThisWorld)){ - a=i; - if(plugin.Frozen.get(a)!=null && plugin.Frozen.get(a).contains(pname)){ - return; - }else{ - plugin.RestoreInv(p, pname); - if (plugin.config.getString("joinTeleport").equalsIgnoreCase("true")) { - String[] Spawncoords = plugin.spawns.getString("Spawn_coords."+a).split(","); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - Location Spawn = new Location(p.getWorld(), spawnx, spawny, spawnz); - if (!p.getLocation().getBlock().equals(Spawn.getBlock())){ - p.teleport(Spawn); - } - } - } - } - } - } - } -} diff --git a/src/me/Travja/HungerArena/Listeners/spawnsListener.java b/src/me/Travja/HungerArena/Listeners/spawnsListener.java deleted file mode 100644 index befded0..0000000 --- a/src/me/Travja/HungerArena/Listeners/spawnsListener.java +++ /dev/null @@ -1,61 +0,0 @@ -package me.Travja.HungerArena.Listeners; - -import java.util.Collection; - -import me.Travja.HungerArena.Main; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; - -public class spawnsListener implements Listener{ - public Main plugin; - public spawnsListener(Main m){ - this.plugin = m; - } - - @EventHandler - public void interact(PlayerInteractEvent event){ - Player p = event.getPlayer(); - if(plugin.setting.containsKey(p.getName())){ - if(event.getAction()==Action.RIGHT_CLICK_BLOCK){ - Location l = event.getClickedBlock().getLocation(); - String HandItem; - try { - HandItem=p.getInventory().getItemInMainHand().getType().name(); - } catch (Exception e){ - HandItem=p.getItemInHand().getType().name(); - } - if(HandItem == plugin.config.getString("spawnsTool")){ - String[] info = plugin.setting.get(p.getName()).split("-"); - if(Integer.parseInt(info[1])!= plugin.config.getInt("maxPlayers")+1){ - String coords = l.getWorld().getName() + " " + ((double)l.getX()+.5) + " " + ((double)l.getY()+1) + " " + ((double)l.getZ()+.5); - - int arena = Integer.parseInt(info[0]); - if (plugin.spawns.get("Spawns." + arena) != null){ - Collection temp = plugin.spawns.getConfigurationSection("Spawns."+arena).getValues(false).values(); - if (temp.contains(coords.trim().replace(' ', ','))){ - event.setCancelled(true); - return; - } - } - - p.performCommand("startpoint " + info[0] + " " + info[1] + " " + coords); - - if(Integer.parseInt(info[1])>= plugin.config.getInt("maxPlayers")){ - p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "All spawns set!"); - plugin.setting.remove(p.getName()); - }else{ - plugin.setting.put(p.getName(), info[0] + "-" + (Integer.parseInt(info[1])+1)); - p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Next starting point: " + (Integer.parseInt(info[1])+1)); - } - } - } - } - } - } -} \ No newline at end of file diff --git a/src/me/Travja/HungerArena/Main.java b/src/me/Travja/HungerArena/Main.java deleted file mode 100644 index 594a22b..0000000 --- a/src/me/Travja/HungerArena/Main.java +++ /dev/null @@ -1,1180 +0,0 @@ -package me.Travja.HungerArena; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Random; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -import me.Travja.HungerArena.Listeners.BlockStorage; -import me.Travja.HungerArena.Listeners.WorldChange; -import me.Travja.HungerArena.Listeners.Boundaries; -import me.Travja.HungerArena.Listeners.ChatListener; -import me.Travja.HungerArena.Listeners.DeathListener; -import me.Travja.HungerArena.Listeners.FreezeListener; -import me.Travja.HungerArena.Listeners.JoinAndQuitListener; -import me.Travja.HungerArena.Listeners.PvP; -import me.Travja.HungerArena.Listeners.SignsAndBeds; -import me.Travja.HungerArena.Listeners.SignsAndBedsOld; -import me.Travja.HungerArena.Listeners.SpectatorListener; -import me.Travja.HungerArena.Listeners.SpectatorListenerOld; -import me.Travja.HungerArena.Listeners.TeleportListener; -import me.Travja.HungerArena.Listeners.spawnsListener; -import net.milkbowl.vault.economy.Economy; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.FireworkEffect.Type; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandExecutor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Firework; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.FireworkMeta; -import org.bukkit.material.MaterialData; -import org.bukkit.material.Torch; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Score; -import org.bukkit.scoreboard.Scoreboard; - -import com.sk89q.worldedit.bukkit.WorldEditPlugin; - -public class Main extends JavaPlugin{ - static Logger log; - public HashMap> Playing = new HashMap>(); - public HashMap> Ready = new HashMap>(); - public HashMap> Dead = new HashMap>(); - public HashMap MatchRunning = new HashMap(); - public HashMap canjoin = new HashMap(); - public HashMap open = new HashMap(); - private HashMap CountT = new HashMap(); - public HashMap> Quit = new HashMap>(); - public HashMap> Out = new HashMap>(); - public HashMap> Watching = new HashMap>(); - public HashMap Kills = new HashMap(); - public HashMap> NeedConfirm = new HashMap>(); - public HashMap> location = new HashMap>(); - public HashMap> inArena = new HashMap>(); - public HashMap> Frozen = new HashMap>(); - public HashMap> arena = new HashMap>(); - public HashMap maxPlayers = new HashMap(); - public HashMap setting = new HashMap(); - public HashMap gp = new HashMap(); - public ArrayList Tele = new ArrayList(); - public ArrayList needInv = new ArrayList(); - public HashMap worldsNames = new HashMap(); - - public HashMap scoreboards = new HashMap(); - - Listener DeathListener = new DeathListener(this); - Listener SpectatorListener = null; - Listener SpectatorListenerOld = null; - Listener FreezeListener = new FreezeListener(this); - Listener JoinAndQuitListener = new JoinAndQuitListener(this); - Listener ChatListener = new ChatListener(this); - Listener Chests = new Chests(this); - Listener PvP = new PvP(this); - Listener CommandBlock = new CommandBlock(this); - Listener Teleport = new TeleportListener(this); - SignsAndBeds SignsAndBeds = null; - SignsAndBedsOld SignsAndBedsOld = null; - Listener BlockStorage = new BlockStorage(this); - //Listener WinGames = new WinGamesListener(this); - Listener WorldChange = new WorldChange(this); - Listener Boundaries = new Boundaries(this); - Listener spawnsListener = new spawnsListener(this); - CommandExecutor HaCommands = new HaCommands(this); - CommandExecutor SponsorCommands = new SponsorCommands(this); - CommandExecutor SpawnsCommand = new SpawnsCommand(this); - - public boolean exists; - public boolean restricted; - - public FileConfiguration config; - public FileConfiguration spawns = null; - public File spawnsFile = null; - public FileConfiguration data = null; - public File dataFile = null; - public FileConfiguration management = null; - public File managementFile = null; - - public FileConfiguration MyChests = null; - public File ChestsFile = null; - - public ArrayList Reward = new ArrayList(); - public ArrayList Cost = new ArrayList(); - public ArrayList Fee = new ArrayList(); - public ArrayList ChestPay = new ArrayList(); - - public boolean vault = false; - public boolean eco = false; - public Economy econ = null; - - int i = 0; - int v = 0; - int a = 0; - - File PFilePath = new File(getDataFolder(), "/inventories"); - - public void onEnable(){ - log = this.getLogger(); - - getConfig().options().copyDefaults(true); - getConfig().options().copyHeader(true); - saveDefaultConfig(); - saveConfig(); - config = getConfig(); - spawns = getSpawns(); - data = getData(); - data.options().copyDefaults(true); - if(!new File(this.getDataFolder(), "Data.yml").exists()) - this.saveData(); - management = this.getManagement(); - management.options().copyDefaults(true); - if(!new File(this.getDataFolder(), "commandAndBlockManagement.yml").exists()) - this.saveManagement(); - MyChests = this.getChests(); - MyChests.options().copyDefaults(true); - if(!new File(this.getDataFolder(), "Chests.yml").exists()) - this.saveChests(); - getServer().getPluginManager().registerEvents(DeathListener, this); - getServer().getPluginManager().registerEvents(FreezeListener, this); - getServer().getPluginManager().registerEvents(JoinAndQuitListener, this); - getServer().getPluginManager().registerEvents(ChatListener, this); - getServer().getPluginManager().registerEvents(Chests, this); - getServer().getPluginManager().registerEvents(PvP, this); - getServer().getPluginManager().registerEvents(CommandBlock, this); - - try { - Class.forName("org.bukkit.Tag"); - SignsAndBeds = new SignsAndBeds(this); - getServer().getPluginManager().registerEvents(SignsAndBeds, this); - SpectatorListener = new SpectatorListener(this); - getServer().getPluginManager().registerEvents(SpectatorListener, this); - getLogger().info("Events 1.13+ enabled!"); - } catch (NoClassDefFoundError | ClassNotFoundException exp) { - SignsAndBedsOld = new SignsAndBedsOld(this); - getServer().getPluginManager().registerEvents(SignsAndBedsOld, this); - SpectatorListenerOld = new SpectatorListenerOld(this); - getServer().getPluginManager().registerEvents(SpectatorListenerOld, this); - getLogger().info("Events 1.12- enabled!"); - } - getServer().getPluginManager().registerEvents(BlockStorage, this); - //getServer().getPluginManager().registerEvents(WinGames, this); - getServer().getPluginManager().registerEvents(WorldChange, this); - getServer().getPluginManager().registerEvents(Boundaries, this); - getServer().getPluginManager().registerEvents(spawnsListener, this); - - getCommand("Ha").setExecutor(HaCommands); - getCommand("Sponsor").setExecutor(SponsorCommands); - getCommand("Startpoint").setExecutor(SpawnsCommand); - - if (!PFilePath.exists()) { - PFilePath.mkdirs(); - } - for(File file: PFilePath.listFiles()){ - String filename = file.getName(); - int lastIndex = filename.lastIndexOf('.'); - filename = filename.substring(0, lastIndex >= 0 ? lastIndex : 0); - needInv.add(filename); - } - - i = 1; - - this.reloadSpawnpoints(true); - - if (setupEconomy()) { - log.info("Found Vault! Hooking in for economy!"); - } - if (config.getDouble("config.version") != 1.4) { - config.set("config.version", 1.4); - config.set("rewardEco.enabled", false); - config.set("rewardEco.reward", 100); - } - if (config.getBoolean("rewardEco.enabled", true) || config.getBoolean("sponsorEco.enabled", true) || config.getBoolean("EntryFee.eco", true)) { - if (vault == true) { - log.info("Economy hook deployed."); - eco = true; - }else{ - log.info("You want economy support... yet you either don't have Vault or don't have an economy plugin. Sorry, can't give you it."); - } - } - if (!eco) { - if (vault == true) { - log.info("We see that you have Vault on your server. To set economy support to true, enable it in the config."); - } - } - try{ - List RewardItemList = new ArrayList(); - List SponsorItemList = new ArrayList(); - List EntryfeeItemList = new ArrayList(); - List PayForChests = new ArrayList(); - - for(String rewards: config.getStringList("Reward")){ - String[] rinfo = rewards.split(","); - Material NewMat = getNewMaterial(rinfo[0],0); - if (NewMat != null) { - Reward.add(new ItemStack(NewMat, Integer.parseInt(rinfo[1]))); - RewardItemList.add(NewMat.name()+","+Integer.parseInt(rinfo[1])); - } - } - config.set("Reward", RewardItemList); - - for(String scost: config.getStringList("Sponsor_Cost")){ - String[] sinfo = scost.split(","); - Material NewMat = getNewMaterial(sinfo[0],0); - if (NewMat != null) { - Cost.add(new ItemStack(NewMat, Integer.parseInt(sinfo[1]))); - SponsorItemList.add(NewMat.name()+","+Integer.parseInt(sinfo[1])); - } - } - config.set("Sponsor_Cost", SponsorItemList); - - if(config.getBoolean("EntryFee.enabled")){ - for(String fee: config.getStringList("EntryFee.fee")){ - String[] finfo = fee.split(","); - Material NewMat = getNewMaterial(finfo[0],0); - if (NewMat != null) { - Fee.add(new ItemStack(NewMat, Integer.parseInt(finfo[1]))); - EntryfeeItemList.add(NewMat.name()+","+Integer.parseInt(finfo[1])); - } - } - config.set("EntryFee.fee", EntryfeeItemList); - } - - if (config.getBoolean("ChestPay.enabled")){ - for(String paychests: config.getStringList("ChestPay.items")){ - String[] rew = paychests.split(","); - Material NewMat = getNewMaterial(rew[0],0); - if (NewMat != null) { - ChestPay.add(new ItemStack(NewMat, Integer.parseInt(rew[1]))); - PayForChests.add(NewMat.name()+","+Integer.parseInt(rew[1])); - } - } - config.set("ChestPay.items", PayForChests); - } - - ArrayList newList = new ArrayList(); - for (String block: management.getStringList("blocks.whitelist")){ - Material NewMat = getNewMaterial(block,0); - if (NewMat != null) newList.add(NewMat.name()); - } - management.set("blocks.whitelist", newList); - this.saveManagement(); - }catch(Exception e){ - log.warning("Could not add a reward/sponsor/entry cost or whitelist/blacklist! One of them is wrong!"); - } - - try { - String spt = config.getString("spawnsTool"); - if (!spt.trim().toLowerCase().contains("[a-z]")) config.set("spawnsTool",getNewMaterial(spt,0).name()); - } catch (Exception e){} - restricted = config.getBoolean("Restricted"); - saveConfig(); - scoreboardInit(); - log.info("Enabled v" + getDescription().getVersion()); - } - public Material getNewMaterial(String base,int data){ - Material NewMat=null; - if (Material.getMaterial(base)!=null){ - NewMat = Material.getMaterial(base); - } - else if (base.replaceAll("[0-9]","").equals("")){ - NewMat = findOldMaterial(Integer.parseInt(base),(byte)data); - } else { - try { - NewMat = Material.getMaterial(base,true); - } catch (NoSuchMethodError n) { - } - } - return NewMat; - } - - public Material findOldMaterial(int typeId, byte dataValue) { - for(Material i : EnumSet.allOf(Material.class)) { - try { - if(i.getId() == typeId) return Bukkit.getUnsafe().fromLegacy(new MaterialData(i, dataValue)); - } catch (IllegalArgumentException | NoSuchMethodError e){ - try { - if(i.getId() == typeId) { - return new MaterialData(i, dataValue).getItemType(); - } - } catch (IllegalArgumentException ee) {} - } - } - return null; - } - - - public void onDisable(){ - log.info("Disabled v" + getDescription().getVersion()); - } - - public void reloadSpawnpoints(boolean verbose){ - if(spawns.getConfigurationSection("Spawns")!= null){ - Map temp = spawns.getConfigurationSection("Spawns").getValues(false); - for(Entry entry: temp.entrySet()){ - if(spawns.getConfigurationSection("Spawns." + entry.getKey())!= null){ - Integer a = Integer.parseInt(entry.getKey()); - worldsNames.put(a, "none_meening_this_is_not_a_map"); - if(location.get(a)== null) location.put(a, new HashMap()); - Map temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false); - for(Map.Entry e: temp2.entrySet()){ - if(spawns.get("Spawns." + entry.getKey() + "." + e.getKey())!= null){ - if(!e.getKey().equals("Max") || !e.getKey().equals("Min")){ - String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "." + e.getKey())).split(","); - Integer s = Integer.parseInt(e.getKey()); - location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3]))); - worldsNames.put(a, coords[0]); - } - } - } - } - } - } - - for(int i : location.keySet()){ - if(location.get(i).size()!= 0){ - if (verbose) log.info("Loaded " + location.get(i).size() + " tribute spawns for arena " + i + "!"); - Playing.put(i, new ArrayList()); - Ready.put(i, new ArrayList()); - Dead.put(i, new ArrayList()); - MatchRunning.put(i, null); - Quit.put(i, new ArrayList()); - Out.put(i, new ArrayList()); - Watching.put(i, new ArrayList()); - NeedConfirm.put(i, new ArrayList()); - inArena.put(i, new ArrayList()); - Frozen.put(i, new ArrayList()); - arena.put(i, new ArrayList()); - canjoin.put(i, false); - maxPlayers.put(i, location.get(i).size()); - open.put(i, true); - } - } - } - - public WorldEditPlugin hookWE() { - Plugin wPlugin = getServer().getPluginManager().getPlugin("WorldEdit"); - - if ((wPlugin == null) || (!(wPlugin instanceof WorldEditPlugin))) - return null; - - return (WorldEditPlugin) wPlugin; - } - - public boolean setupEconomy() { - if (getServer().getPluginManager().getPlugin("Vault") == null) { - return false; - } - RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); - if (rsp == null) { - return false; - } - econ = rsp.getProvider(); - vault = true; - return econ != null; - } - public void reloadSpawns() { - if (spawnsFile == null) { - spawnsFile = new File(getDataFolder(), "spawns.yml"); - } - if (!spawnsFile.exists()) { - this.saveResource("spawns.yml", false); - } - - spawns = YamlConfiguration.loadConfiguration(spawnsFile); - - InputStream defConfigStream = this.getResource("spawns.yml"); - if (defConfigStream != null) { - YamlConfiguration defConfig = loadConfigStream(defConfigStream); - if (defConfig != null){ - spawns.addDefaults(defConfig); - spawns.options().copyHeader(true); - spawns.options().copyDefaults(true); - saveSpawns() ; - } - } - if (spawns.getString("Spawns_set")!=null && (spawns.getString("Spawns_set").equalsIgnoreCase("false") || spawns.getString("Spawns_set").equalsIgnoreCase("true"))) { - String temp = spawns.getString("Spawns_set"); - spawns.set("Spawns_set", null); - spawns.set("Spawns_set.0", temp); - temp = spawns.getString("Spawn_coords"); - spawns.set("Spawn_coords", null); - spawns.set("Spawn_coords.0", temp); - if(spawns.getConfigurationSection("Spawns")!= null){ - Set temp2 = spawns.getConfigurationSection("Spawns").getValues(false).keySet(); - for(String entry: temp2){ - if (spawns.getString("Spawns_set_"+entry)!=null) { - spawns.set("Spawns_set."+entry, spawns.getString("Spawns_set_"+entry)); - spawns.set("Spawns_set_"+entry, null); - } - if (spawns.getString("Spawn_coords_"+entry)!=null) { - spawns.set("Spawn_coords."+entry, spawns.getString("Spawn_coords_"+entry)); - spawns.set("Spawn_coords_"+entry, null); - } - } - } - saveSpawns() ; - } - } - public FileConfiguration getSpawns() { - if (spawns == null) { - this.reloadSpawns(); - } - return spawns; - } - public void saveSpawns() { - if (spawns == null || spawnsFile == null) { - return; - } - try { - getSpawns().save(spawnsFile); - } catch (IOException ex) { - this.getLogger().log(Level.SEVERE, "Could not save config to " + spawnsFile, ex); - } - } - public void reloadData() { - if (dataFile == null) { - dataFile = new File(getDataFolder(), "Data.yml"); - } - if (!dataFile.exists()) { - this.saveResource("Data.yml", false); - } - - data = YamlConfiguration.loadConfiguration(dataFile); - - InputStream defConfigStream = this.getResource("Data.yml"); - if (defConfigStream != null) { - YamlConfiguration defConfig = loadConfigStream(defConfigStream); - if (defConfig != null) { - data.addDefaults(defConfig); - data.options().copyHeader(true); - data.options().copyDefaults(true); - saveData(); - } - } - } - public FileConfiguration getData() { - if (data == null) { - this.reloadData(); - } - return data; - } - public void saveData() { - if (data == null || dataFile == null) { - return; - } - try { - getData().save(dataFile); - } catch (IOException ex) { - this.getLogger().log(Level.SEVERE, "Could not save config to " + dataFile, ex); - } - } - public void reloadManagement() { - if (managementFile == null) { - managementFile = new File(getDataFolder(), "commandAndBlockManagement.yml"); - } - if (!managementFile.exists()) { - this.saveResource("commandAndBlockManagement.yml", false); - } - - management = YamlConfiguration.loadConfiguration(managementFile); - - InputStream defConfigStream = this.getResource("commandAndBlockManagement.yml"); - if (defConfigStream != null) { - YamlConfiguration defConfig = loadConfigStream(defConfigStream); - if (defConfig != null) { - management.addDefaults(defConfig); - management.options().copyHeader(true); - management.options().copyDefaults(true); - saveManagement(); - } - } - } - public FileConfiguration getManagement() { - if (management == null) { - this.reloadManagement(); - } - return management; - } - public void saveManagement() { - if (management == null || managementFile == null) { - return; - } - try { - getManagement().save(managementFile); - } catch (IOException ex) { - this.getLogger().log(Level.SEVERE, "Could not save config to " + managementFile, ex); - } - } - public void reloadChests() { - if (ChestsFile == null) { - ChestsFile = new File(getDataFolder(), "Chests.yml"); - } - MyChests = YamlConfiguration.loadConfiguration(ChestsFile); - } - public FileConfiguration getChests() { - if (MyChests == null) { - this.reloadChests(); - } - return MyChests; - } - public void saveChests() { - if (MyChests == null || ChestsFile == null) { - return; - } - try { - getChests().save(ChestsFile); - } catch (IOException ex) { - this.getLogger().log(Level.SEVERE, "Could not save config to " + ChestsFile, ex); - } - } - File PFile = null; - FileConfiguration PConfig= null; - public void reloadPFile(String pname) { - if (PFile == null) { - PFile = new File(PFilePath, pname + ".yml"); - } - PConfig = YamlConfiguration.loadConfiguration(PFile); - InputStream defConfigStream = this.getResource("Player.yml"); - if (defConfigStream != null) { - YamlConfiguration defConfig = loadConfigStream(defConfigStream); - if (defConfig != null) this.PConfig.setDefaults(defConfig); - } - } - - private YamlConfiguration loadConfigStream(InputStream defConfigStream) { - Reader defaultConfigReader = null; - YamlConfiguration defConfig = null; - if (defConfigStream != null) { - try { - defaultConfigReader = new java.io.InputStreamReader(defConfigStream, "UTF-8"); - } catch (UnsupportedEncodingException e) { - log.info("The embedded resource contained in the plugin jar file has an unsupported encoding.It should be encoded with UTF-8."); - } - } - - if (defaultConfigReader != null) { - defConfig = YamlConfiguration.loadConfiguration(defaultConfigReader); - } else { - log.warning("A default resource in the plugin jar could not be read."); - } - try { - if (defaultConfigReader != null) { - defaultConfigReader.close(); - } - } catch (IOException e) { - log.warning("An error occured while trying to close the resource file."); - } - return defConfig; - } - - public FileConfiguration getPConfig(String pname) { - PFile = null; - this.reloadPFile(pname); - return PConfig; - } - public void savePFile(String pname) { - if (PConfig.getString("player").equals(pname)){ - try { - this.PConfig.save(PFile); - } catch (IOException ex) { - this.getLogger().log(Level.SEVERE, "Could not save config to " + PFile, ex); - } - }else this.getLogger().log(Level.SEVERE, "Could not save config to " + pname + ".yml ! It's not this players inventory!?"); - } - - @SuppressWarnings("unchecked") - public void RestoreInv(Player p, String pname){ - for(int u:Playing.keySet()){ - if(Playing.get(u)!=null){ - if(Playing.get(u).contains(pname)){ - Playing.get(u).remove(pname); - p.sendMessage(ChatColor.AQUA + "You have left the game!"); - if(config.getBoolean("broadcastAll")){ - p.getServer().broadcastMessage(ChatColor.RED + pname + " Left Arena " + u + "!"); - }else{ - for(String gn: Playing.get(u)){ - Player g = getServer().getPlayer(gn); - g.sendMessage(ChatColor.RED + pname + " Quit!"); - } - } - if(canjoin.get(u)== true){ - p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - scoreboards.remove(p.getName()); - Kills.remove(p.getName()); - } - - } - } - if(Ready.get(u)!=null){ - if(Ready.get(u).contains(pname)) Ready.get(u).remove(pname); - } - } - if(new File(PFilePath, pname + ".yml").exists()){ - FileConfiguration pinfo = this.getPConfig(pname); - if((pinfo.getString("player").equals(pname)) && (this.needInv.contains(pname))){ - try{ - ItemStack[] pinv = null; - Object o = pinfo.get("inv"); - if(o instanceof ItemStack[]){ - pinv = (ItemStack[]) o; - }else if(o instanceof List){ - pinv = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); - } - p.getInventory().setContents(pinv); - p.updateInventory(); - - ItemStack[] parmor = null; - o = pinfo.get("armor"); - if(o instanceof ItemStack[]){ - parmor = (ItemStack[]) o; - }else if(o instanceof List){ - parmor = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); - } - p.getInventory().setArmorContents(parmor); - p.updateInventory(); - - p.sendMessage(ChatColor.GOLD + "[HA] " + ChatColor.GREEN + "Your inventory has been restored!"); - new File(PFilePath, pname + ".yml").delete(); - - while(needInv.contains(pname)){ - needInv.remove(pname); - } - - }catch(Exception e){ - p.sendMessage(ChatColor.RED + "Something went wrong when trying to restore your inv, please contact an administrator."); - this.getLogger().warning("Error occured when trying to restore the inv of " + pname + ":"); - System.out.println(e); - } - } - } - if (p.hasMetadata("HA-Location")) p.removeMetadata("HA-Location", this); - } - - public void winner(final Integer a){ - if(Playing.get(a).size()== 1){ - String[] Spawncoords; - if (spawns.getString("Spawn_coords." + a) != null){ - Spawncoords = spawns.getString("Spawn_coords."+ a).split(","); - } else { - Spawncoords = spawns.getString("Spawn_coords.0").split(","); - } - World spawnw = getServer().getWorld(Spawncoords[3]); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - - for(i = 0; i < Playing.get(a).size(); i++){ - String winnername = Playing.get(a).get(i); - final Player winner = getServer().getPlayerExact(winnername); - String winnername2 = winner.getName(); - if(canjoin.get(a)== true) getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); - winner.getInventory().clear(); - winner.getInventory().setBoots(null); - winner.getInventory().setChestplate(null); - winner.getInventory().setHelmet(null); - winner.getInventory().setLeggings(null); - winner.setLevel(0); - for(PotionEffect pe: winner.getActivePotionEffects()){ - PotionEffectType potion = pe.getType(); - winner.removePotionEffect(potion); - } - Tele.add(winner); - needInv.add(winnername2); - - winner.teleport(Spawn); - - this.RestoreInv(winner, winnername2); - - if(canjoin.get(a)== true){ - winner.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - if(scoreboards.containsKey(winner.getName())) - scoreboards.remove(winner.getName()); - if(Kills.containsKey(winner.getName())) - Kills.remove(winner.getName()); - - //////////////////////////////////////////////////////// - //////////////////// FIREWORKS /////////////////////// - //////////////////////////////////////////////////////// - - - for(i = 0; i < 10; i++){ - Bukkit.getScheduler().runTaskLater(this, new Runnable(){ - public void run(){ - //Spawn the Fireworks, get the FireworkMeta. - Firework fw = (Firework) winner.getWorld().spawnEntity(winner.getLocation(), EntityType.FIREWORK); - FireworkMeta fwm = fw.getFireworkMeta(); - - //Our random generator - Random r = new Random(); - - //Get the type - int rt = r.nextInt(4) + 1; - Type type = Type.BALL; - if (rt == 1) type = Type.BALL; - if (rt == 2) type = Type.BALL_LARGE; - if (rt == 3) type = Type.BURST; - if (rt == 4) type = Type.CREEPER; - if (rt == 5) type = Type.STAR; - - //Get our random colours - int r1i = r.nextInt(17) + 1; - int r2i = r.nextInt(17) + 1; - Color c1 = getColor(r1i); - Color c2 = getColor(r2i); - - //Create our effect with this - FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build(); - - //Then apply the effect to the meta - fwm.addEffect(effect); - - //Generate some random power and set it - int rp = r.nextInt(2) + 1; - fwm.setPower(rp); - - //Then apply this to our rocket - fw.setFireworkMeta(fwm); - } - },20 + i*20L); - } - - - //////////////////////////////////////////////////////// - //////////////////////////////////////////////////////// - //////////////////////////////////////////////////////// - - if(!config.getBoolean("rewardEco.enabled")){ - for(ItemStack Rewards: Reward){ - winner.getInventory().addItem(Rewards); - } - }else{ - for(ItemStack Rewards: Reward){ - winner.getInventory().addItem(Rewards); - } - econ.depositPlayer(winner, config.getDouble("rewardEco.reward")); - } - } - - if(deathtime.get(a)!= null){ - getServer().getScheduler().cancelTask(deathtime.get(a)); - deathtime.put(a, null); - } - if(grace.get(a)!= null){ - getServer().getScheduler().cancelTask(grace.get(a)); - grace.put(a, null); - } - if(start.get(a)!= null){ - getServer().getScheduler().cancelTask(start.get(a)); - start.put(a, null); - } - } - Playing.get(a).clear(); - Quit.get(a).clear(); - Dead.get(a).clear(); - - //Show spectators - for(String s1: Watching.get(a)){ - Player spectator = getServer().getPlayerExact(s1); - spectator.setAllowFlight(false); - spectator.teleport(Spawn); - for(Player online:getServer().getOnlinePlayers()){ - online.showPlayer(this,spectator); - } - } - if(config.getString("Auto_Restart").equalsIgnoreCase("True")){ - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ - public void run(){ - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart " + a); - } - }, 220L); - } - MatchRunning.put(a, null); - } - } - - private Color getColor(int i) { - if(i==1) - return Color.AQUA; - else if(i==2) - return Color.BLACK; - else if(i==3) - return Color.BLUE; - else if(i==4) - return Color.FUCHSIA; - else if(i==5) - return Color.GRAY; - else if(i==6) - return Color.GREEN; - else if(i==7) - return Color.LIME; - else if(i==8) - return Color.MAROON; - else if(i==9) - return Color.NAVY; - else if(i==10) - return Color.OLIVE; - else if(i==11) - return Color.ORANGE; - else if(i==12) - return Color.PURPLE; - else if(i==13) - return Color.RED; - else if(i==14) - return Color.SILVER; - else if(i==15) - return Color.TEAL; - else if(i==16) - return Color.WHITE; - else - return Color.YELLOW; - } - private void scoreboardInit(){ - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ - public void run(){ - Collection online = getServer().getOnlinePlayers(); - for(Player pl: online) { - updateScoreboard(pl); - } - } - }, 20L, 10L); - } - - public void updateScoreboard(Player p){ - if(getArena(p)!= null || isSpectating(p)){ - if (getArena(p) !=null) a = getArena(p); - else if (getSpectating(p) !=null) a = getSpectating(p); - if(scoreboards.get(p.getName())!= null && scoreboards.get(p.getName()).getObjective("HA")!= null){ - Scoreboard sb = scoreboards.get(p.getName()); - Objective obj = sb.getObjective("HA"); - if(obj!= null){ - Score kills = obj.getScore(ChatColor.RED + "Kills"); - Score players = obj.getScore(ChatColor.RED + "Players"); - Score spectators = obj.getScore(ChatColor.RED + "Spectators"); - Score allkills = obj.getScore(ChatColor.RED + "Deaths"); - players.setScore(Playing.get(a).size()); - if(Kills.containsKey(p.getName())) { - kills.setScore(Kills.get(p.getName())); - } - if (Kills.containsKey("__SuM__")) - allkills.setScore(Kills.get("__SuM__")); - - if(Watching.get(a)!= null) - spectators.setScore(Watching.get(a).size()); - if(config.getInt("DeathMatch")!= 0){ - if(timetodeath.get(a)!= null){ - if(timetodeath.get(a)> 0){ - int ttd = Integer.valueOf(timetodeath.get(a)-timetodeath.get(a)/60*60); - String secs = String.valueOf((ttd< 10) ? "0" + ttd : ttd); - obj.setDisplayName(ChatColor.GREEN + "HA - DMTime: " + ChatColor.AQUA + Integer.valueOf(timetodeath.get(a)/60) + ":" + secs); - }else{ - obj.setDisplayName(ChatColor.GREEN + "HA - " + ChatColor.RED + "DEATHMATCH"); - } - } - }else{ - obj.setDisplayName(ChatColor.GREEN + "HungerArena"); - } - p.setScoreboard(sb); - } - } - } - } - - public HashMap grace = new HashMap(); - public HashMap start = new HashMap(); - public HashMap deathtime = new HashMap(); - public HashMap timetodeath = new HashMap(); - - public void startGames(final int a){ - if ((MatchRunning.get(a)!=null) && (MatchRunning.get(a).equals("true"))){ - return; - } - - final String msg = ChatColor.translateAlternateColorCodes('&', config.getString("Start_Message")); - for(String gn: Playing.get(a)){ - Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard(); - Objective sobj; - try{ - sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting"); - } catch (NoSuchMethodError e){ - sobj = scoreboard.registerNewObjective("HA", "HAData"); - sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); - } - Score skills = sobj.getScore(ChatColor.RED + "Kills"); - skills.setScore(0); - Score sdeaths = sobj.getScore(ChatColor.RED + "Spectators"); - sdeaths.setScore(0); - Score splayers = sobj.getScore(ChatColor.RED + "Players"); - splayers.setScore(0); - Score allkills = sobj.getScore(ChatColor.RED + "Deaths"); - allkills.setScore(0); - sobj.setDisplaySlot(DisplaySlot.SIDEBAR); - Bukkit.getPlayer(gn).setScoreboard(scoreboard); - scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard()); - } - getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + a); - MatchRunning.put(a, "true"); - if(start.get(a)!= null) getServer().getScheduler().cancelTask(start.get(a)); - if(config.getString("Countdown").equalsIgnoreCase("true")){ - CountT.put(a,(config.getInt("Countdown_Timer")!=0 ? config.getInt("Countdown_Timer"):10)); - start.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ - public void run(){ - if(CountT.get(a) > 0){ - if (!restricted){ - if(config.getBoolean("broadcastAll")){ - getServer().broadcastMessage(ChatColor.AQUA + "Game " + a + " starting in: " + String.valueOf(CountT.get(a))); - }else{ - for(String gn: Playing.get(a)){ - Player g = getServer().getPlayer(gn); - g.sendMessage(ChatColor.AQUA + "Game starting in: " + String.valueOf(CountT.get(a))); - } - } - }else{ - if(config.getBoolean("broadcastAll")){ - for(String world: worldsNames.values()){ - World w = getServer().getWorld(world); - for(Player wp: w.getPlayers()){ - wp.sendMessage(String.valueOf(CountT.get(a))); - } - } - }else{ - for(String gn: Playing.get(a)){ - Player g = getServer().getPlayer(gn); - g.sendMessage(String.valueOf(CountT.get(a))); - } - } - } - } - CountT.put(a, CountT.get(a)-1); - if(CountT.get(a)== -1){ - for(String gn: Playing.get(a)){ - Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard(); - Objective sobj; - try{ - sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting"); - } catch (NoSuchMethodError e){ - sobj = scoreboard.registerNewObjective("HA", "HAData"); - sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); - } - Score skills = sobj.getScore(ChatColor.RED + "Kills"); - skills.setScore(0); - Score sdeaths = sobj.getScore(ChatColor.RED + "Spectators"); - sdeaths.setScore(0); - Score splayers = sobj.getScore(ChatColor.RED + "Players"); - splayers.setScore(0); - Score allkills = sobj.getScore(ChatColor.RED + "Deaths"); - allkills.setScore(0); - sobj.setDisplaySlot(DisplaySlot.SIDEBAR); - Bukkit.getPlayer(gn).setScoreboard(scoreboard); - scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard()); - } - if(Frozen.get(a)!= null) - Frozen.get(a).clear(); - if(config.getBoolean("broadcastAll")){ - getServer().broadcastMessage(msg); - }else{ - for(String gn: Playing.get(a)){ - Player g = getServer().getPlayer(gn); - g.sendMessage(msg); - } - } - if(config.getInt("Grace_Period")!= 0){ - gp.put(a, config.getInt("Grace_Period")); - if(grace.get(a)== null) grace.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable(){ - public void run(){ - gp.put(a, gp.get(a)-1); - if(gp.get(a) == 30 || gp.get(a) == 15 || (gp.get(a) < 11 && gp.get(a) != 0)){ - if(config.getBoolean("broadcastAll")){ - for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ - wp.sendMessage(ChatColor.GREEN + "Grace period ends in " + gp.get(a) + " seconds!"); - } - }else - getServer().broadcastMessage(ChatColor.GREEN + "Grace period ends in " + gp.get(a) + " seconds!"); - } - if(gp.get(a) <= 0){ - if(config.getBoolean("broadcastAll")){ - for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ - wp.sendMessage(ChatColor.GREEN + "Grace period is over, FIGHT!"); - } - }else - getServer().broadcastMessage(ChatColor.GREEN + "Grace period is over, FIGHT!"); - getServer().getScheduler().cancelTask(grace.get(a)); - grace.put(a, null); - } - } - },20L, 20L)); - } - if(config.getInt("DeathMatch")!= 0){ - int death = config.getInt("DeathMatch"); - timetodeath.put(a, death*60); - if(deathtime.get(a)== null) deathtime.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable(){ - public void run(){ - timetodeath.put(a, timetodeath.get(a)-1); - if(Integer.valueOf(timetodeath.get(a))%300== 0){ - if(config.getBoolean("broadcastAll")){ - for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ - if(timetodeath.get(a)!= 0){ - wp.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a)/60) + ChatColor.RED + " mins till the death match!"); - } - } - }else{ - for(String gn: Playing.get(a)){ - Player g = getServer().getPlayer(gn); - g.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a)) + ChatColor.RED + " mins till the death match!"); - } - } - } - if(timetodeath.get(a)<= 0){ - int i = 1; - for(String playing: Playing.get(a)){ - Player tribute = getServer().getPlayerExact(playing); - - Location pLoc=null; - if (tribute.hasMetadata("HA-Location")){ - List l=tribute.getMetadata("HA-Location"); - if (l !=null && l.size()!=0 ){ - try { - pLoc=(Location) l.get(0).value(); - } catch (Exception e){} - } - if (pLoc!=null) { - tribute.teleport(pLoc); //random - } else { - tribute.teleport(location.get(a).get(i)); //row - } - } - i+=1; - for(PotionEffect pe: tribute.getActivePotionEffects()){ - PotionEffectType potion = pe.getType(); - tribute.removePotionEffect(potion); - } - if(tribute.getAllowFlight()){ - tribute.setAllowFlight(false); - } - } - if(config.getBoolean("broadcastAll")){ - for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ - wp.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!"); - } - }else{ - for(String gn: Playing.get(a)){ - Player g = getServer().getPlayer(gn); - g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!"); - } - } - StopTasksDelayed(deathtime.get(a)); - deathtime.put(a, null); - } - } - }, 20L, 20L)); - } - setTorch(a, true); - StopTasksDelayed(start.get(a)); - } - } - }, 20L, 20L)); - }else{ - setTorch(a, true); - Frozen.get(a).clear(); - if(config.getBoolean("broadcastAll")){ - getServer().broadcastMessage(msg); - }else{ - for(String gn: Playing.get(a)){ - Player g = getServer().getPlayer(gn); - g.sendMessage(msg); - } - } - } - canjoin.put(a, true); - } - private void StopTasksDelayed(final int task) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - public void run() { - Bukkit.getScheduler().cancelTask(task); - } - }, 10L); - } - - public Integer getArena(Player p){ - for (int x: Playing.keySet()) { - if (Playing.get(x).contains(p.getName())){ - return x; - } - } - return null; - } - public Integer getSpectating(Player p){ - for(int x : Watching.keySet()){ - if(Watching.get(x).contains(p.getName())){ - return x; - } - } - return null; - } - public boolean isSpectating(Player p){ - for(int x : Watching.keySet()){ - if(Watching.get(x).contains(p.getName())){ - return true; - } - } - return false; - } - public void setTorch(int a, boolean set){ - String arena = String.valueOf(a); - if (spawns.getString("Start_torch."+arena)!=null) { - String[] Torchcoords = spawns.getString("Start_torch."+ arena).split(","); - double torchx = Double.parseDouble(Torchcoords[0]); - double torchy = Double.parseDouble(Torchcoords[1]); - double torchz = Double.parseDouble(Torchcoords[2]); - String torchworld = Torchcoords[3]; - World torchw = getServer().getWorld(torchworld); - Location TorchLoc = new Location(torchw, torchx, torchy, torchz); - if (set) SetTorch(TorchLoc); - else TorchLoc.getBlock().setType(Material.AIR); - } - } - private void SetTorch(Location Baseblock){ - Block TorchBlock = Baseblock.getBlock(); - try{ - Material Torch = (org.bukkit.Material.valueOf("REDSTONE_TORCH")); - if (Torch != null) { - TorchBlock.setType(Torch); - } - }catch (Exception ex) { - TorchBlock.setType(Material.REDSTONE_TORCH); - } - } -} diff --git a/src/me/Travja/HungerArena/SpawnsCommand.java b/src/me/Travja/HungerArena/SpawnsCommand.java deleted file mode 100644 index be4a4c5..0000000 --- a/src/me/Travja/HungerArena/SpawnsCommand.java +++ /dev/null @@ -1,178 +0,0 @@ -package me.Travja.HungerArena; - -import java.util.ArrayList; -import java.util.HashMap; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class SpawnsCommand implements CommandExecutor { - public Main plugin; - int i = 0; - int a = 0; - boolean NoPlayerSpawns; - public SpawnsCommand(Main m) { - this.plugin = m; - } - @Override - public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { - Player p = (Player) sender; - String ThisWorld = p.getWorld().getName(); - NoPlayerSpawns = true; - for(int i : plugin.worldsNames.keySet()){ - if(plugin.worldsNames.get(i)!= null){ - if (plugin.worldsNames.get(i).equals(ThisWorld)){ - a=i; - NoPlayerSpawns = false; - break; - } - } - } - if(cmd.getName().equalsIgnoreCase("StartPoint")){ - if(p.hasPermission("HungerArena.StartPoint")){ - Location loc = null; - double x; - double y; - double z; - if(args.length == 6){ - try{ - i = Integer.valueOf(args[1]); - a = Integer.valueOf(args[0]); - }catch(Exception e){ - p.sendMessage(ChatColor.RED + "Argument not an integer!"); - return true; - } - - String world = args[2]; - x = Double.parseDouble(args[3]); - y = Double.parseDouble(args[4]); - z = Double.parseDouble(args[5]); - loc = new Location(Bukkit.getWorld(world), x, y, z); - if(plugin.location.get(a)!= null){ - plugin.location.get(a).put(i, loc); - }else{ - plugin.location.put(a, new HashMap()); - plugin.location.get(a).put(i, loc); - plugin.Playing.put(a, new ArrayList()); - plugin.Ready.put(a, new ArrayList()); - plugin.Dead.put(a, new ArrayList()); - plugin.Quit.put(a, new ArrayList()); - plugin.Out.put(a, new ArrayList()); - plugin.Watching.put(a, new ArrayList()); - plugin.NeedConfirm.put(a, new ArrayList()); - plugin.inArena.put(a, new ArrayList()); - plugin.Frozen.put(a, new ArrayList()); - plugin.arena.put(a, new ArrayList()); - plugin.canjoin.put(a, false); - plugin.MatchRunning.put(a, null); - plugin.open.put(a, true); - } - String coords = loc.getWorld().getName() + "," + (loc.getX()) + "," + loc.getY() + "," + (loc.getZ()); - p.sendMessage(coords); - plugin.spawns.set("Spawns." + a + "." + i, coords); - plugin.worldsNames.put(a, loc.getWorld().getName()); - plugin.saveSpawns(); - plugin.maxPlayers.put(a, plugin.location.get(a).size()); - p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + a + "!"); - this.plugin.reloadSpawnpoints(false); - return true; - } - if(args.length>= 2){ - try{ - i = Integer.valueOf(args[1]); - a = Integer.valueOf(args[0]); - }catch(Exception e){ - p.sendMessage(ChatColor.RED + "Argument not an integer!"); - return true; - } - if(i >= 1 && i <= plugin.config.getInt("maxPlayers")){ - if(!plugin.worldsNames.values().contains(p.getWorld().getName())){ - p.sendMessage(ChatColor.GOLD + "You've added this world to the config ..."); - } - loc = p.getLocation().getBlock().getLocation(); - x = loc.getX()+.5; - y = loc.getY(); - z = loc.getZ()+.5; - loc = new Location(loc.getWorld(), x, y, z); - if(plugin.location.get(a)!= null){ - plugin.location.get(a).put(i, loc); - }else{ - plugin.location.put(a, new HashMap()); - plugin.location.get(a).put(i, loc); - plugin.Playing.put(a, new ArrayList()); - plugin.Ready.put(a, new ArrayList()); - plugin.Dead.put(a, new ArrayList()); - plugin.Quit.put(a, new ArrayList()); - plugin.Out.put(a, new ArrayList()); - plugin.Watching.put(a, new ArrayList()); - plugin.NeedConfirm.put(a, new ArrayList()); - plugin.inArena.put(a, new ArrayList()); - plugin.Frozen.put(a, new ArrayList()); - plugin.arena.put(a, new ArrayList()); - plugin.canjoin.put(a, false); - plugin.MatchRunning.put(a, null); - plugin.open.put(a, true); - } - String coords = loc.getWorld().getName() + "," + (loc.getX()) + "," + loc.getY() + "," + (loc.getZ()); - p.sendMessage(coords); - plugin.spawns.set("Spawns." + a + "." + i, coords); - plugin.worldsNames.put(a, loc.getWorld().getName()); - plugin.saveSpawns(); - plugin.maxPlayers.put(a, plugin.location.get(a).size()); - p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + a + "!"); - this.plugin.reloadSpawnpoints(false); - }else{ - p.sendMessage(ChatColor.RED + "You can't go past " + plugin.config.getInt("maxPlayers") + " players!"); - } - }else if(args.length == 1){ - if (sender instanceof Player){ - p = (Player) sender; - if(NoPlayerSpawns){ - try{ - a = Integer.parseInt(args[0]); - }catch(Exception e){ - p.sendMessage(ChatColor.RED + "Argument not an integer!"); - return true; - } - } - if (plugin.spawns.get("Spawns." + a) != null){ - int start = 1; - while(start= 3){ - Player target = Bukkit.getServer().getPlayer(args[0]); - if(target==null || (target!=null && plugin.getArena(target)== null)){ - p.sendMessage(ChatColor.RED + "That person isn't playing!"); - }else{ - try{ - String ID = args[1].toUpperCase().trim(); - int amount = Integer.parseInt(args[2]); - if((!plugin.management.getStringList("sponsors.blacklist").isEmpty() && !plugin.management.getStringList("sponsors.blacklist").contains(ID)) || plugin.management.getStringList("sponsors.blacklist").isEmpty()){ - handleItemsAndEco(p,args,ID,amount,target); - }else{ - p.sendMessage(ChatColor.RED + "You can't sponsor that item!"); - p.sendMessage(ChatColor.GREEN + "Other items you can't sponsor are:"); - for(String blacklist: plugin.management.getStringList("sponsors.blacklist")){ - p.sendMessage(ChatColor.AQUA + blacklist); - } - } - }catch(Exception e){ - p.sendMessage(ChatColor.RED + "Something went wrong there... Make sure that you do like this /sponsor [name] [item] [number]"); - } - } - } - }else{ - p.sendMessage(ChatColor.RED + "You are playing, you can't sponsor yourself!"); - } - }else{ - p.sendMessage(ChatColor.RED + "You don't have permission!"); - } - }else if(sender instanceof ConsoleCommandSender){ - if(args.length== 0){ - sender.sendMessage(ChatColor.RED + "You didn't specify a tribute!"); - return false; - } - if(args.length== 1){ - sender.sendMessage(ChatColor.RED + "You didn't specify an item!"); - } - if(args.length== 2){ - sender.sendMessage(ChatColor.RED + "You didn't specify an amount!"); - } - if(args.length>= 3){ - Player target = Bukkit.getPlayer(args[0]); - String ID = args[1].toUpperCase().trim(); - int Amount = Integer.parseInt(args[2]); - try{ - if((!plugin.management.getStringList("sponsors.blacklist").isEmpty() && !plugin.management.getStringList("sponsors.blacklist").contains(ID)) || plugin.management.getStringList("sponsors.blacklist").isEmpty()){ - ItemStack sponsoritem = new ItemStack(org.bukkit.Material.getMaterial(ID), Amount); - if(plugin.getArena(target)== null){ - sender.sendMessage(ChatColor.RED + "That person isn't playing!"); - }else{ - sender.sendMessage(ChatColor.RED + "You can't sponsor yourself!"); - target.sendMessage(ChatColor.AQUA + "You have been Sponsored!"); - target.getInventory().addItem(sponsoritem); - sender.sendMessage("You have sponsored " + target.getName() + "!"); - } - }else{ - sender.sendMessage(ChatColor.RED + "You can't sponsor that item!"); - sender.sendMessage(ChatColor.GREEN + "Other items you can't sponsor are:"); - for(String blacklist: plugin.management.getStringList("sponsors.blacklist")){ - sender.sendMessage(ChatColor.AQUA + blacklist); - } - } - }catch(Exception e){ - sender.sendMessage(ChatColor.RED + "Something went wrong there... Make sure that you do like this /sponsor [name] [number] [number]"); - } - } - } - } - return false; - } - private void handleItemsAndEco(Player p,String[] args,String ID,int amount,Player target){ - Material sponsMat = plugin.getNewMaterial(ID,0); - ItemStack sponsoritem; - boolean done = false; - if (sponsMat !=null) { - sponsoritem = new ItemStack(sponsMat,amount); - } else { - p.sendMessage(ChatColor.RED + "That item does not exist !!"); - return; - } - for(ItemStack Costs: plugin.Cost){ - if(!p.getInventory().containsAtLeast(Costs, Costs.getAmount()*amount)){ - p.sendMessage(ChatColor.RED + "You don't have the necessary items to sponsor!"); - return; - } - } - if(args[0].equalsIgnoreCase(p.getName())){ - p.sendMessage(ChatColor.RED + "You can't sponsor yourself!"); - }else{ - if(plugin.config.getBoolean("sponsorEco.enabled")) { - if(!(plugin.econ.getBalance(p) < (plugin.config.getDouble("sponsorEco.cost")*amount))){ - plugin.econ.withdrawPlayer(p, plugin.config.getDouble("sponsorEco.cost")*amount); - done = true; - } else { - p.sendMessage(ChatColor.RED + "You don't have enough money to do that!"); - return; - } - } - if(!plugin.Cost.isEmpty()){ - for(ItemStack aCosts: plugin.Cost){ - for (int x=1;x<=amount;x++){ - p.getInventory().removeItem(aCosts); - done = true; - } - } - } - if (done){ - target.getInventory().addItem(sponsoritem); - target.sendMessage(ChatColor.AQUA + "You have been Sponsored!"); - p.sendMessage("You have sponsored " + target.getName() + "!"); - } else p.sendMessage(ChatColor.RED + "Sponsoring is disabled!"); - } - } -}