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