From eeda111f5722cdba0cc4f0d34f23bf0f9e356c87 Mon Sep 17 00:00:00 2001 From: Jeppa Date: Sat, 24 Jan 2015 13:29:05 +0100 Subject: [PATCH] Big Update !!! 1st: updated to latest source from Travja ! 2nd: lots of changes and fixes: - MultiArena working and multispawns! (now 20 default worlds in no order possible, if more are needed keep them in correct order!) - the defaultspawnpoint always is the last spawnpoint set, or edit the configfile (spawns.yml). - setting spawnpoint working now. - HA commands extended, fixed and with help..., some commands now have default worldrecognition - saving and restore of player inventories !!!! - fixed join/leave/dead-behaviour - fixed gracetimer and made each map have its own timer! - lots more i'm not remembering right now... --- Player.yml | 6 + README | 20 +- config.yml | 13 +- plugin.yml | 12 +- spawns.yml | 57 ++ src/me/Travja/HungerArena/Chests.java | 24 +- src/me/Travja/HungerArena/CommandBlock.java | 1 + src/me/Travja/HungerArena/ConfigManager.java | 92 ++ src/me/Travja/HungerArena/DeathListener.java | 151 ---- src/me/Travja/HungerArena/FreezeListener.java | 63 -- src/me/Travja/HungerArena/HaCommands.java | 800 +++++++++++++----- .../{ => Listeners}/BlockStorage.java | 38 +- .../HungerArena/Listeners/Boundaries.java | 78 ++ .../{ => Listeners}/ChatListener.java | 4 +- .../HungerArena/Listeners/DeathListener.java | 282 ++++++ .../{ => Listeners}/DmgListener.java | 4 +- .../HungerArena/Listeners/FreezeListener.java | 105 +++ .../{ => Listeners}/JoinAndQuitListener.java | 54 +- .../HungerArena/{ => Listeners}/PvP.java | 31 +- .../HungerArena/{ => Listeners}/Signs.java | 4 +- .../{ => Listeners}/SpectatorListener.java | 26 +- .../{ => Listeners}/TeleportListener.java | 4 +- .../HungerArena/Listeners/spawnsListener.java | 49 ++ src/me/Travja/HungerArena/Main.java | 768 +++++++++++++---- src/me/Travja/HungerArena/SpawnsCommand.java | 125 ++- .../Travja/HungerArena/SponsorCommands.java | 1 + src/me/Travja/HungerArena/WorldChange.java | 44 + 27 files changed, 2189 insertions(+), 667 deletions(-) create mode 100644 Player.yml create mode 100644 src/me/Travja/HungerArena/ConfigManager.java delete mode 100644 src/me/Travja/HungerArena/DeathListener.java delete mode 100644 src/me/Travja/HungerArena/FreezeListener.java rename src/me/Travja/HungerArena/{ => Listeners}/BlockStorage.java (92%) create mode 100644 src/me/Travja/HungerArena/Listeners/Boundaries.java rename src/me/Travja/HungerArena/{ => Listeners}/ChatListener.java (94%) create mode 100644 src/me/Travja/HungerArena/Listeners/DeathListener.java rename src/me/Travja/HungerArena/{ => Listeners}/DmgListener.java (89%) create mode 100644 src/me/Travja/HungerArena/Listeners/FreezeListener.java rename src/me/Travja/HungerArena/{ => Listeners}/JoinAndQuitListener.java (74%) rename src/me/Travja/HungerArena/{ => Listeners}/PvP.java (66%) rename src/me/Travja/HungerArena/{ => Listeners}/Signs.java (95%) rename src/me/Travja/HungerArena/{ => Listeners}/SpectatorListener.java (87%) rename src/me/Travja/HungerArena/{ => Listeners}/TeleportListener.java (95%) create mode 100644 src/me/Travja/HungerArena/Listeners/spawnsListener.java create mode 100644 src/me/Travja/HungerArena/WorldChange.java diff --git a/Player.yml b/Player.yml new file mode 100644 index 0000000..4a7d85f --- /dev/null +++ b/Player.yml @@ -0,0 +1,6 @@ +# This is the default inventory file for storing players inventory during matches ! +# DO not Edit anything in here!!! + +inv: [] +armor: [] +world: world diff --git a/README b/README index 1fbc15b..154912d 100644 --- a/README +++ b/README @@ -1,6 +1,24 @@ +Orig README by Travja: http://dev.bukkit.org/server-mods/hungerarena +Working on a rewrite :D Going to be EPIC https://github.com/travja/HungerArena-Reloaded /\ | | | -Go there for more info! \ No newline at end of file +Go there for more info! +==================================== + +README by Jeppa: +This version was fixed by Jeppa to have safe maps (block-protection) +and more than one spawnpoint (one spawnpoint per arena!) +You may have to edit the config.yml! +The worlds order is the corresponding worlds-number !!! +First world ist world #1 etc... +The worlds/arenas numbers should start with #1 and count up... +There are default-values for arenas in the configfile +so you will see up to 20 arenas after first spawns set. +This is just done to avoid some bugs if arenas are not in a row starting by 1 :/ +You may have arena numbers like 2,4,6 with this, +but still should count them like 1,2,3,4... !!! +With this in your mind: don't have arena-numbers bigger +than 20 until you realy have that amount! diff --git a/config.yml b/config.yml index 5427976..19686aa 100644 --- a/config.yml +++ b/config.yml @@ -14,7 +14,7 @@ config: # worlds: # - world # - world_nether -worlds: +worlds: {} # If left at 0 there will be no death match, fill in a time in minutes DeathMatch: 0 @@ -50,10 +50,10 @@ Grace_Period: 60 Protected_Arena: 'true' # Whether or not players (not playing) can break blocks while waiting -Protected_Arena_Always: 'false' +Protected_Arena_Always: 'true' # Whether new or unknown players on HA-maps should be forced to the spawn or not. -Force_Players_toSpawn: 'false' +Force_Players_toSpawn: 'true' # Whether or not players will be frozen when they are teleported to their positions Frozen_Teleport: 'true' @@ -63,6 +63,13 @@ Explode_on_Move: 'false' # Whether or not thunder will sound upon a players death Cannon_Death: 'true' + +# Whether or not to have the arena be the world or the WorldEdit selection +WorldEdit: false + +# What item should be used to set spawns after /startpoint [arena#] +spawnsTool: 286 + ###################################### ###################################### ###################################### diff --git a/plugin.yml b/plugin.yml index 25bb667..5b95d8e 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,12 +1,18 @@ name: HungerArena main: me.Travja.HungerArena.Main -version: 1.4Dev +version: 1.5C_Jeppa description: A lightweight and powerful plugin to help with playing The Hunger Games! -softdepend: [Vault] +softdepend: [Vault, WorldEdit] commands: Ha: description: Makes you join a game or start the game! StartPoint: description: Sets the starting point of a tribute. + usage: /startpoint [arenanumber] [startpointnumber] + permission: HungerArena.StartPoint + permission-message: §4[HungerArena]§rYou don't have permission!!!! Sponsor: - description: Sponsors a Tribute \ No newline at end of file + description: Sponsors a Tribute + usage: /sponsor [tribute] [item] [amount] + permission: HungerArena.Sponsor + permission-message: §4[HungerArena]§rYou don't have permission!!!! diff --git a/spawns.yml b/spawns.yml index 11fbf10..bf87b10 100644 --- a/spawns.yml +++ b/spawns.yml @@ -7,5 +7,62 @@ Spawns: 1: 2: 2: + 1: + 2: + 3: + 1: + 2: + 4: + 1: + 2: + 5: + 1: + 2: + 6: + 1: + 2: + 7: + 1: + 2: + 8: + 1: + 2: + 9: + 1: + 2: + 10: + 1: + 2: + 11: + 1: + 2: + 12: + 1: + 2: + 13: + 1: + 2: + 14: + 1: + 2: + 15: + 1: + 2: + 16: + 1: + 2: + 17: + 1: + 2: + 17: + 1: + 2: + 18: + 1: + 2: + 19: + 1: + 2: + 20: 1: 2: \ No newline at end of file diff --git a/src/me/Travja/HungerArena/Chests.java b/src/me/Travja/HungerArena/Chests.java index db99c1b..e027d1d 100644 --- a/src/me/Travja/HungerArena/Chests.java +++ b/src/me/Travja/HungerArena/Chests.java @@ -4,6 +4,7 @@ import java.util.List; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.entity.Player; @@ -22,7 +23,6 @@ public class Chests implements Listener { @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(); @@ -35,7 +35,6 @@ public class Chests implements Listener { list2.remove(blockx + "," + blocky + "," + blockz); plugin.getChests().set("Storage." + blockx + "," + blocky+ "," + blockz, null); plugin.getChests().set("StorageXYZ", list2); - plugin.getChests().options().copyDefaults(true); plugin.saveChests(); p.sendMessage("[HungerArena] Chest Removed!"); } else { @@ -54,28 +53,29 @@ public class Chests implements Listener { if(plugin.Playing.get(a).contains(p.getName()) && plugin.canjoin.get(a)){ if(!plugin.restricted || (plugin.restricted && plugin.worlds.contains(p.getWorld().getName()))){ if(block!= null){ - if(block.getState() instanceof Chest){ - ItemStack[] itemsinchest = ((Chest) block.getState()).getInventory().getContents(); + if(block.getType()== Material.CHEST){ + ItemStack[] itemsinchest = ((Chest) 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 + ".Location.X")){ //getConfig greift auf normale cfg zu.. -> eigene Routine - plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X", blockx); - plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky); - plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z",blockz); - plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw); - plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest); - plugin.getChests().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Arena", a); + 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(); } List list2 = plugin.getChests().getStringList("StorageXYZ"); if(!list2.contains(blockx + "," + blocky + "," + blockz)){ list2.add(blockx + "," + blocky + "," + blockz); plugin.getChests().set("StorageXYZ", list2); - plugin.getChests().options().copyDefaults(true); plugin.saveChests(); p.sendMessage(ChatColor.GREEN + "Thank you for finding this undiscovered chest, it has been stored!!"); } + plugin.reloadChests(); } } } diff --git a/src/me/Travja/HungerArena/CommandBlock.java b/src/me/Travja/HungerArena/CommandBlock.java index e3626e0..5c2dd52 100644 --- a/src/me/Travja/HungerArena/CommandBlock.java +++ b/src/me/Travja/HungerArena/CommandBlock.java @@ -13,6 +13,7 @@ public class CommandBlock implements Listener { public CommandBlock(Main m) { this.plugin = m; } + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR) public void CatchCommand(PlayerCommandPreprocessEvent event){ String cmd = event.getMessage(); diff --git a/src/me/Travja/HungerArena/ConfigManager.java b/src/me/Travja/HungerArena/ConfigManager.java new file mode 100644 index 0000000..4d74091 --- /dev/null +++ b/src/me/Travja/HungerArena/ConfigManager.java @@ -0,0 +1,92 @@ +package me.Travja.HungerArena; + +public class ConfigManager { + public static Main plugin; + public ConfigManager(Main m){ + ConfigManager.plugin = m; + } + + public void setup(){ + System.out.println("Setting up!"); + if(!plugin.config.contains("worlds")) + plugin.config.addDefault("worlds", "{}"); + if(!plugin.config.contains("DeathMatch")) + plugin.config.addDefault("DeathMatch", "0"); + if(!plugin.config.contains("broadcastAll")) + plugin.config.addDefault("broadcastAll", true); + if(!plugin.config.contains("maxPlayers")) + plugin.config.addDefault("maxPlayers", "24"); + if(!plugin.config.contains("Start_Message")) + plugin.config.addDefault("Start_Message", "&bLet The Games Begin!"); + if(!plugin.config.contains("Auto_Restart")) + plugin.config.addDefault("Auto_Restart", false); + if(!plugin.config.contains("Auto_Start")) + plugin.config.addDefault("Auto_Start", false); + if(!plugin.config.contains("Need_Confirm")) + plugin.config.addDefault("Need_Confirm", true); + if(!plugin.config.contains("Countdown")) + plugin.config.addDefault("Countdown", true); + if(!plugin.config.contains("Countdown_Timer")) + plugin.config.addDefault("Countdown_Timer", "15"); + if(!plugin.config.contains("Grace_Period")) + plugin.config.addDefault("Grace_Period", "60"); + if(!plugin.config.contains("Protected_Arena")) + plugin.config.addDefault("Protected_Arena", true); + if(!plugin.config.contains("Protected_Arena_Always")) + plugin.config.addDefault("Protected_Arena_Always", true); + if(!plugin.config.contains("Force_Players_toSpawn")) + plugin.config.addDefault("Force_Players_toSpawn", true); + if(!plugin.config.contains("Frozen_Teleport")) + plugin.config.addDefault("Frozen_Teleport", true); + if(!plugin.config.contains("Explode_on_Move")) + plugin.config.addDefault("Explode_on_Move", false); + if(!plugin.config.contains("Cannon_Death")) + plugin.config.addDefault("Cannon_Death", true); + if(!plugin.config.contains("Reward")) + plugin.config.addDefault("Reward", "- 264,10"); + if(!plugin.config.contains("Sponsor_Cost")) + plugin.config.addDefault("Sponsor_Cost", "- 264,1"); + if(!plugin.config.contains("EntryFee")){ + plugin.config.addDefault("EntryFee.enabled", false); + plugin.config.addDefault("EntryFee.eco", false); + plugin.config.addDefault("EntryFee.cost", "50"); + plugin.config.addDefault("EntryFee.fee", "- 265,1"); + }else{ + if(!plugin.config.contains("EntryFee.enabled")) + plugin.config.addDefault("EntryFee.enabled", false); + if(!plugin.config.contains("EntryFee.eco")) + plugin.config.addDefault("EntryFee.eco", false); + if(!plugin.config.contains("EntryFee.cost")) + plugin.config.addDefault("EntryFee.cost", "50"); + if(!plugin.config.contains("EntryFee.fee")) + plugin.config.addDefault("EntryFee.fee", "- 265,1"); + } + if(!plugin.config.contains("rewardEco")){ + plugin.config.addDefault("rewardEco.enabled", false); + plugin.config.addDefault("rewardEco.reward", "100"); + }else{ + if(!plugin.config.contains("rewardEco.enabled")) + plugin.config.addDefault("rewardEco.enabled", false); + if(!plugin.config.contains("rewardEco.reward")) + plugin.config.addDefault("rewardEco.reward", "100"); + } + if(!plugin.config.contains("sponsorEco")){ + plugin.config.addDefault("sponsorEco.enabled", false); + plugin.config.addDefault("sponsorEco.cost", "50"); + }else{ + if(!plugin.config.contains("sponsorEco.enabled")) + plugin.config.addDefault("sponsorEco.enabled", false); + if(!plugin.config.contains("sponsorEco.cost")) + plugin.config.addDefault("sponsorEco.cost", "50"); + } + if(!plugin.config.contains("ChatClose")) + plugin.config.addDefault("ChatClose", true); + if(!plugin.config.contains("ChatClose_Radius")) + plugin.config.addDefault("ChatClose_Radius", "10"); + if(!plugin.config.contains("WorldEdit")) + plugin.config.addDefault("WorldEdit", false); + if(!plugin.config.contains("spawnsTool")) + plugin.config.addDefault("spawnsTool", "286"); + plugin.saveConfig(); + } +} \ No newline at end of file diff --git a/src/me/Travja/HungerArena/DeathListener.java b/src/me/Travja/HungerArena/DeathListener.java deleted file mode 100644 index 15d653d..0000000 --- a/src/me/Travja/HungerArena/DeathListener.java +++ /dev/null @@ -1,151 +0,0 @@ -package me.Travja.HungerArena; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -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.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerRespawnEvent; - -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 - public void onPlayerRespawn(PlayerRespawnEvent event){ - final Player p = event.getPlayer(); - String pname = p.getName(); - for(i = 1; i < plugin.Dead.size(); i++){ - if(plugin.Dead.get(i).contains(pname)){ - String[] Spawncoords = plugin.spawns.getString("Spawn_coords").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(){ - p.teleport(Spawn); - } - }, 10L); - } - } - } - @EventHandler - public void onPlayerDeath(PlayerDeathEvent event){ - Player p = event.getEntity(); - Server s = p.getServer(); - String pname = p.getName(); - int players = plugin.Playing.size()-1; - String leftmsg = null; - for(i = 1; i < plugin.Frozen.size(); i++){ - if(plugin.Frozen.get(i).contains(pname)){ - if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - 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); - plugin.Dead.get(a).add(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 if(plugin.getArena(p)!= null){ - a = plugin.getArena(p); - 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().getItemInHand().getType().getId()== 0){ - 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); - } - } - plugin.winner(a); - }else{ - Player killer = p.getKiller(); - String killername = killer.getName(); - String weapon = killer.getItemInHand().getType().toString().replace('_', ' '); - String msg = ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with a(n) " + 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); - } - } - 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 natural causes!"); - g.sendMessage(leftmsg); - } - } - plugin.winner(a); - } - } - } - } -} diff --git a/src/me/Travja/HungerArena/FreezeListener.java b/src/me/Travja/HungerArena/FreezeListener.java deleted file mode 100644 index 1ab1197..0000000 --- a/src/me/Travja/HungerArena/FreezeListener.java +++ /dev/null @@ -1,63 +0,0 @@ -package me.Travja.HungerArena; - -import java.util.HashMap; - -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; - -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(); - @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")){ - for(String players: plugin.Playing.get(a)){ - final Player playing = plugin.getServer().getPlayerExact(players); - i = plugin.Playing.get(a).indexOf(players); - if(!timeUp.get(a)){ - if(!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i))){ - 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); - } - } - },30L); - } - }else{ - if(!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i))){ - if(!plugin.Dead.get(a).contains(playing.getName())){ - World world = playing.getLocation().getWorld(); - world.createExplosion(playing.getLocation(), 0.0F, false); - playing.setHealth(0); - } - } - } - } - }else{ - for(String players:plugin.Playing.get(a)){ - Player playing = plugin.getServer().getPlayerExact(players); - i = plugin.Playing.get(a).indexOf(players)+1; - if(!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i))){ - playing.teleport(plugin.location.get(a).get(i)); - } - } - } - } - } - } -} diff --git a/src/me/Travja/HungerArena/HaCommands.java b/src/me/Travja/HungerArena/HaCommands.java index d0ff92d..ce788d2 100644 --- a/src/me/Travja/HungerArena/HaCommands.java +++ b/src/me/Travja/HungerArena/HaCommands.java @@ -2,10 +2,13 @@ package me.Travja.HungerArena; import java.util.ArrayList; import java.util.List; +//import java.util.Map; +//import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Chest; @@ -13,11 +16,20 @@ 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; //Jeppa : add for eventremoval... +import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.bukkit.selections.Selection; public class HaCommands implements CommandExecutor { public Main plugin; @@ -26,6 +38,7 @@ public class HaCommands implements CommandExecutor { } int i = 0; int a = 1; + boolean NoPlayerSpawns = true; // Jeppa : default for setspawn command... @SuppressWarnings("deprecation") private void clearInv(Player p){ p.getInventory().clear(); @@ -35,19 +48,41 @@ public class HaCommands implements CommandExecutor { p.getInventory().setLeggings(null); p.updateInventory(); } - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings({ "unchecked", "deprecation" }) @Override public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, String[] args){ - String[] Spawncoords = plugin.spawns.getString("Spawn_coords").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); + if(sender instanceof Player){ final Player p = (Player) sender; final String pname = p.getName(); + String ThisWorld = p.getWorld().getName(); + for(i = 1; i <= plugin.worldsNames.size(); i++){ + if(plugin.worldsNames.get(i)!= null){ + if (plugin.worldsNames.get(i).equals(ThisWorld)){ + a=i; //Jeppa: now 'a' is the arenanumber of THIS(current) map. Will be default for some commands! + NoPlayerSpawns = false; //mapname found -> there are PlayerSpawns...--> map seems playable + } + } + } + + if(plugin.getArena(p)!= null){ + a = plugin.getArena(p); // Now let's look if we already know what map to 'work' on... + NoPlayerSpawns = false; // Jeppa: there may be no playerspawns, but the arenanumber seems valid... thats enough + } + + 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").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); + // nun ist Spawn Map-abhängig! ChatColor c = ChatColor.AQUA; if(cmd.getName().equalsIgnoreCase("Ha")){ if(args.length== 0){ @@ -55,14 +90,29 @@ public class HaCommands implements CommandExecutor { return false; }else if(args[0].equalsIgnoreCase("SetSpawn")){ if(p.hasPermission("HungerArena.SetSpawn")){ - double x = p.getLocation().getX(); - double y = p.getLocation().getY(); - double z = p.getLocation().getZ(); - String w = p.getWorld().getName(); - plugin.spawns.set("Spawn_coords", x + "," + y + "," + z + "," + w); - plugin.spawns.set("Spawns_set", "true"); - plugin.saveSpawns(); - p.sendMessage(ChatColor.AQUA + "You have set the spawn for dead tributes!"); + if ((NoPlayerSpawns) && (args.length<2)) { + p.sendMessage(ChatColor.AQUA + "You have to set the playerspawns first! Use /startpoint . Or enter the arena number as 2nd argument"); + }else{ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.spawns.set("Spawn_coords", x + "," + y + "," + z + "," + w); // Jeppa: keep this as default + plugin.spawns.set("Spawns_set", "true"); + //Jeppa: set the arenas spawn now + if (args.length>=2) { + try { a = Integer.parseInt(args[1]); // Jeppa: replace a (arenanumber from arenalist(current map) or from joined-list) with given argument + }catch(Exception e){ + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return false; // true ?? false ?? + } + } + plugin.spawns.set("Spawn_coords_"+a, x + "," + y + "," + z + "," + w); + 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!"); } @@ -71,6 +121,8 @@ public class HaCommands implements CommandExecutor { 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!"); + if(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!"); @@ -83,7 +135,7 @@ public class HaCommands implements CommandExecutor { 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!"); + 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 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!"); @@ -103,7 +155,7 @@ public class HaCommands implements CommandExecutor { for(String playernames: plugin.Playing.get(a)){ Player players = plugin.getServer().getPlayerExact(playernames); if(p.hasPermission("HungerArena.GameMaker")){ - sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + players.getHealth() + "/20"); + sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + ((Damageable)players).getHealth() + "/" + ((Damageable)players).getMaxHealth()); }else if(p.hasPermission("HungerArena.List")){ sender.sendMessage(ChatColor.GREEN + playernames); } @@ -122,7 +174,7 @@ public class HaCommands implements CommandExecutor { for(String playernames: plugin.Playing.get(1)){ Player players = plugin.getServer().getPlayerExact(playernames); if(p.hasPermission("HungerArena.GameMaker")){ - sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + players.getHealth() + "/20"); + sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + ((Damageable)players).getHealth() + "/" + ((Damageable)players).getMaxHealth()); }else if(p.hasPermission("HungerArena.List")){ sender.sendMessage(ChatColor.GREEN + playernames); } @@ -137,7 +189,7 @@ public class HaCommands implements CommandExecutor { for(String playernames: plugin.Playing.get(a)){ Player players = plugin.getServer().getPlayerExact(playernames); if(p.hasPermission("HungerArena.GameMaker")){ - sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + players.getHealth() + "/20"); + sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + ((Damageable)players).getHealth() + "/" + ((Damageable)players).getMaxHealth()); }else if(p.hasPermission("HungerArena.List")){ sender.sendMessage(ChatColor.GREEN + playernames); } @@ -187,7 +239,7 @@ public class HaCommands implements CommandExecutor { }else if(args[0].equalsIgnoreCase("Join")){ if(p.hasPermission("HungerArena.Join")){ boolean needconfirm = false; - for(i= 1; i< plugin.NeedConfirm.size(); i++){ + for(i= 1; i< plugin.NeedConfirm.size()+1; i++){ if(plugin.NeedConfirm.get(i).contains(pname)){ needconfirm = true; p.sendMessage(ChatColor.GOLD + "You need to run /ha confirm"); @@ -195,48 +247,49 @@ public class HaCommands implements CommandExecutor { } if(!needconfirm){ try{ - a = Integer.parseInt(args[1]); + a = Integer.parseInt(args[1]); }catch(Exception e){ - i = 1; - while(i <= plugin.Playing.size()){ - if(plugin.Playing.get(i).size()< plugin.maxPlayers.get(i)){ - a = i; - i = plugin.Playing.size()+1; + if (NoPlayerSpawns){ //Jeppa: only if there's no usable argument AND this(THIS!, where the player is standing) is not a playable map (not in the list...). else keep 'a' as it is (arenanumber of current map) + i = 1; + while(i <= plugin.Playing.size()){ + if(plugin.Playing.get(i).size()< plugin.maxPlayers.get(i)){ + a = i; + i = plugin.Playing.size()+1; + } + if(plugin.Playing.size()== i){ + p.sendMessage(ChatColor.RED + "No free slots found / All games are full!"); + } + i++; } - if(plugin.Playing.size()== i){ - p.sendMessage(ChatColor.RED + "All games are full!"); - } - i++; } + } - if(plugin.Playing.get(a)!= null){ - if(plugin.Playing.get(a).contains(pname)){ + if((plugin.Playing.get(a)!=null) && (plugin.location.get(a).size()!=0)){; //Jeppa: Arena must exist in Playing and must have spawnpoints + 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)){ + 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)){ + 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){ + else if(plugin.canjoin.get(a)== true) p.sendMessage(ChatColor.RED + "That game is in progress!"); - }else if(!plugin.open.get(a)){ + else if(!plugin.open.get(a)) p.sendMessage(ChatColor.RED + "That game is closed!"); - }else if(plugin.spawns.getString("Spawns_set").equalsIgnoreCase("false")){ - p.sendMessage(ChatColor.RED + "/ha setspawn hasn't been run!"); - }else if(plugin.NeedConfirm.get(a).contains(pname)){ - p.sendMessage(ChatColor.RED + "You need to do /ha confirm"); - }else if(plugin.getArena(p)!= null){ + else if((plugin.spawns.getString("Spawns_set_"+a)==null) || (plugin.spawns.getString("Spawns_set_"+a).equalsIgnoreCase("false"))) // Jeppa: no respawnpoint? + 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")){ + else if(plugin.config.getString("Need_Confirm").equalsIgnoreCase("true")){ if(plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ if(!(plugin.econ.getBalance(pname) < plugin.config.getDouble("EntryFee.cost"))){ i = 0; for(ItemStack fee: plugin.Fee){ int total = plugin.Fee.size(); - if(p.getInventory().contains(fee)){ + if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ i = i+1; if(total == i){ plugin.NeedConfirm.get(a).add(pname); - p.sendMessage(ChatColor.GOLD + "You're inventory will be cleared! Type /ha confirm to procede"); + p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); } } } @@ -250,11 +303,11 @@ public class HaCommands implements CommandExecutor { i = 0; for(ItemStack fee: plugin.Fee){ int total = plugin.Fee.size(); - if(p.getInventory().contains(fee)){ + if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ i = i+1; if(total == i){ plugin.NeedConfirm.get(a).add(pname); - p.sendMessage(ChatColor.GOLD + "You're inventory will be cleared! Type /ha confirm to procede"); + p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); } } } @@ -264,13 +317,13 @@ public class HaCommands implements CommandExecutor { }else if(!plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ if(!(plugin.econ.getBalance(pname) < plugin.config.getDouble("EntryFee.cost"))){ plugin.NeedConfirm.get(a).add(pname); - p.sendMessage(ChatColor.GOLD + "You're inventory will be cleared! Type /ha confirm to procede"); + 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 + "You're inventory will be cleared! Type /ha confirm to procede"); + p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede"); } }else if(plugin.config.getString("Need_Confirm").equalsIgnoreCase("false")){ if(plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ @@ -278,24 +331,37 @@ public class HaCommands implements CommandExecutor { i = 0; for(ItemStack fee: plugin.Fee){ int total = plugin.Fee.size(); - if(p.getInventory().contains(fee)){ + if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ i = i+1; if(total == i){ plugin.econ.withdrawPlayer(pname, 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){ - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees + " was paid to join the games."); + String beginning = fees.getType().toString().substring(0, 1); + String item = beginning + fees.getType().toString().substring(1).toLowerCase().replace("_", " "); + int amount = fees.getAmount(); + 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."); } 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); //Jeppa: get default config and save inv + pinfo.set("inv", p.getInventory().getContents()); + pinfo.set("armor", p.getInventory().getArmorContents()); + pinfo.set("world", p.getLocation().getWorld().getName()); + pinfo.set("player", p.getName()); // Jeppa : used to identify player ... + plugin.savePFile(pname); // Jeppa: Save inventoty to file clearInv(p); + plugin.needInv.add(pname); //Jeppa: mark this player as inventory cleared... if(plugin.config.getBoolean("broadcastAll")){ - plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "!"); + 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!"); + 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)){ @@ -314,22 +380,35 @@ public class HaCommands implements CommandExecutor { i = 0; for(ItemStack fee: plugin.Fee){ int total = plugin.Fee.size(); - if(p.getInventory().contains(fee)){ + if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ i = i+1; if(total == i){ for(ItemStack fees: plugin.Fee){ - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees + " was paid to join the games."); + String beginning = fees.getType().toString().substring(0, 1); + String item = beginning + fees.getType().toString().substring(1).toLowerCase().replace("_", " "); + int amount = fees.getAmount(); + 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."); } 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", p.getLocation().getWorld().getName()); + pinfo.set("player", p.getName()); // Jeppa : used to identify player ... + plugin.savePFile(pname); clearInv(p); + plugin.needInv.add(pname); //Jeppa: mark this player as inventory cleared... if(plugin.config.getBoolean("broadcastAll")){ - plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "!"); + 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!"); + 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)){ @@ -348,13 +427,20 @@ public class HaCommands implements CommandExecutor { 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", p.getLocation().getWorld().getName()); + pinfo.set("player", p.getName()); // Jeppa : used to identify player ... + plugin.savePFile(pname); clearInv(p); + plugin.needInv.add(pname); //Jeppa: mark this player as inventory cleared... if(plugin.config.getBoolean("broadcastAll")){ - plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "!"); + 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!"); + 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)){ @@ -367,13 +453,20 @@ public class HaCommands implements CommandExecutor { 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", p.getLocation().getWorld().getName()); + pinfo.set("player", p.getName()); // Jeppa : used to identify player ... + plugin.savePFile(pname); clearInv(p); + plugin.needInv.add(pname); //Jeppa: mark this player as inventory cleared... if(plugin.config.getBoolean("broadcastAll")){ - plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "!"); + 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!"); + 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)){ @@ -392,26 +485,40 @@ public class HaCommands implements CommandExecutor { ////////////////////////////////// CONFIRMATION /////////////////////////////////////////////// }else if(args[0].equalsIgnoreCase("Confirm")){ int v = 0; - for(v = 1; v < plugin.NeedConfirm.size(); v++){ + for(v = 1; v < plugin.NeedConfirm.size()+1; v++){ if(plugin.NeedConfirm.get(v).contains(pname)){ + a = v; v = plugin.NeedConfirm.size()+1; if(plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ if(!(plugin.econ.getBalance(pname) < plugin.config.getDouble("EntryFee.cost"))){ i = 0; for(ItemStack fee: plugin.Fee){ int total = plugin.Fee.size(); - if(p.getInventory().contains(fee)){ + if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ i = i+1; if(total == i){ plugin.econ.withdrawPlayer(pname, 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){ - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees + " was paid to join the games."); + String beginning = fees.getType().toString().substring(0, 1); + String item = beginning + fees.getType().toString().substring(1).toLowerCase().replace("_", " "); + int amount = fees.getAmount(); + 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."); } 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", p.getLocation().getWorld().getName()); + pinfo.set("player", p.getName()); // Jeppa : used to identify player ... + plugin.savePFile(pname); clearInv(p); + plugin.needInv.add(pname); //Jeppa: mark this player as inventory cleared... if(plugin.config.getBoolean("broadcastAll")){ plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "!"); }else{ @@ -436,16 +543,29 @@ public class HaCommands implements CommandExecutor { i = 0; for(ItemStack fee: plugin.Fee){ int total = plugin.Fee.size(); - if(p.getInventory().contains(fee)){ + if(p.getInventory().containsAtLeast(fee, fee.getAmount())){ i = i+1; if(total == i){ for(ItemStack fees: plugin.Fee){ - p.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees + " was paid to join the games."); + String beginning = fees.getType().toString().substring(0, 1); + String item = beginning + fees.getType().toString().substring(1).toLowerCase().replace("_", " "); + int amount = fees.getAmount(); + 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."); } 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", p.getLocation().getWorld().getName()); + pinfo.set("player", p.getName()); // Jeppa : used to identify player ... + plugin.savePFile(pname); clearInv(p); + plugin.needInv.add(pname); //Jeppa: mark this player as inventory cleared... if(plugin.config.getBoolean("broadcastAll")){ plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "!"); }else{ @@ -470,7 +590,14 @@ public class HaCommands implements CommandExecutor { 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", p.getLocation().getWorld().getName()); + pinfo.set("player", p.getName()); // Jeppa : used to identify player ... + plugin.savePFile(pname); clearInv(p); + plugin.needInv.add(pname); //Jeppa: mark this player as inventory cleared... if(plugin.config.getBoolean("broadcastAll")){ plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "!"); }else{ @@ -489,7 +616,14 @@ public class HaCommands implements CommandExecutor { 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", p.getLocation().getWorld().getName()); + pinfo.set("player", p.getName()); // Jeppa : used to identify player ... + plugin.savePFile(pname); clearInv(p); + plugin.needInv.add(pname); //Jeppa: mark this player as inventory cleared... if(plugin.config.getBoolean("broadcastAll")){ plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "!"); }else{ @@ -503,16 +637,13 @@ public class HaCommands implements CommandExecutor { } } } - if(v== plugin.NeedConfirm.size()){ + 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")){ - // p.sendMessage("debug: Arena: " + String.valueOf(plugin.getArena(p))); // Jeppa: das ist debug! if(plugin.getArena(p)!= null){ a = plugin.getArena(p); - // for(String s:plugin.Playing.get(a)) // Jeppa: das ist debug! - // p.sendMessage("Debug: Player:"+a+" : " + s); // Jeppa: das ist debug! if(plugin.Playing.get(a).contains(pname)){ if(plugin.Ready.get(a).contains(pname)){ p.sendMessage(ChatColor.RED + "You're already ready!"); @@ -520,8 +651,16 @@ public class HaCommands implements CommandExecutor { 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.Playing.get(a).size()-4== plugin.Ready.get(a).size() || plugin.Playing.get(a).size()==plugin.Ready.get(a).size()){ + 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); } } @@ -530,8 +669,10 @@ public class HaCommands implements CommandExecutor { p.sendMessage(ChatColor.RED + "You aren't playing in any games!"); } }else if(args[0].equalsIgnoreCase("Leave")){ + //TODO **Give inv back if they enter the correct world.** Jeppa: -> inv is given back when player respawns now! if(plugin.getArena(p)!= null){ a = plugin.getArena(p); + //plugin.needInv.add(pname); // Jeppa: not when leaving but at join! if(plugin.canjoin.get(a)== true){ plugin.Playing.get(a).remove(pname); p.sendMessage(ChatColor.AQUA + "You have left the game!"); @@ -543,13 +684,19 @@ public class HaCommands implements CommandExecutor { g.sendMessage(ChatColor.RED + pname + " Quit!"); } } + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + plugin.scoreboards.remove(p.getName()); + plugin.Kills.remove(p.getName()); clearInv(p); p.teleport(Spawn); if(plugin.Frozen.get(a).contains(pname)){ plugin.Frozen.get(a).remove(pname); } - plugin.winner(a); - }else{ + + plugin.RestoreInv(p, pname); // Jeppa: call for restore inventory of leaving player!! + + plugin.winner(a); + }else{ plugin.Playing.get(a).remove(pname); p.sendMessage(ChatColor.AQUA + "You have left the game!"); if(plugin.config.getBoolean("broadcastAll")){ @@ -562,15 +709,18 @@ public class HaCommands implements CommandExecutor { } clearInv(p); p.teleport(Spawn); + + plugin.RestoreInv(p, pname); // Jeppa: call for restore inventory of leaving player!! + if(plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")){ plugin.econ.depositPlayer(pname, 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.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees + " was refunded because you left the games."); + 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.sendMessage(ChatColor.GOLD + "[HungerArena] " + ChatColor.GREEN + fees + " was refunded because you left the games."); + 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(pname, plugin.config.getDouble("EntryFee.cost")); @@ -588,11 +738,22 @@ public class HaCommands implements CommandExecutor { 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(p); } p.setAllowFlight(true); p.sendMessage(ChatColor.AQUA + "You can now spectate!"); + Scoreboard scoreboard = plugin.getServer().getScoreboardManager().getNewScoreboard(); + Objective sobj = scoreboard.registerNewObjective("HA", "HAData"); + sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); + Score sdeaths = sobj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Spectators")); + sdeaths.setScore(0); + Score splayers = sobj.getScore(Bukkit.getOfflinePlayer(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)){ @@ -602,6 +763,8 @@ public class HaCommands implements CommandExecutor { for(Player online:plugin.getServer().getOnlinePlayers()){ online.showPlayer(p); } + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + plugin.scoreboards.remove(p.getName()); p.teleport(Spawn); p.setAllowFlight(false); p.sendMessage(ChatColor.AQUA + "You are not spectating any more"); @@ -620,23 +783,60 @@ public class HaCommands implements CommandExecutor { 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{ b = b+1; if(b== plugin.Watching.size()){ p.sendMessage(ChatColor.RED + "You have to be spectating first!"); + return true; } } } ///////////////////////////////////////////////////////////////////////////////// + }else if(args[0].equalsIgnoreCase("addArena")){ + if(plugin.hookWE() != null){ + if(args.length != 2) + return false; + if(p.hasPermission("HungerArena.AddArena")){ + WorldEditPlugin worldedit = plugin.hookWE(); + Selection sel = worldedit.getSelection(p); + if(sel== null) + p.sendMessage(ChatColor.DARK_RED + "You must make a WorldEdit selection first!"); + else{ + Location min = sel.getMinimumPoint(); + Location max = sel.getMaximumPoint(); + plugin.spawns.set("Arenas." + args[1] + ".Max", max.getWorld().getName() + "," + max.getX() + "," + + max.getY() + "," + max.getZ()); + plugin.spawns.set("Arenas." + args[1] + ".Min", min.getWorld().getName() + "," + min.getX() + "," + + min.getY() + "," + min.getZ()); + plugin.saveConfig(); + p.sendMessage(ChatColor.GREEN + "Arena " + ChatColor.DARK_AQUA + args[1] + + ChatColor.GREEN + " created with WorldEdit!"); + return true; + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have WorldEdit enabled for HungerArena!"); + return true; + } }else if(args[0].equalsIgnoreCase("Kick")){ if (args.length != 2) { + sender.sendMessage(ChatColor.RED + "/ha kick [playername]!"); return false; } Player target = Bukkit.getServer().getPlayer(args[1]); - if(sender.hasPermission("HungerArena.Kick")){ + if(target == null){ + sender.sendMessage(ChatColor.RED + "Use playername !"); + return false; + } + if(p.hasPermission("HungerArena.Kick")){ if(plugin.getArena(target) != null){ a = plugin.getArena(target); plugin.Playing.get(a).remove(target.getName()); @@ -651,20 +851,25 @@ public class HaCommands implements CommandExecutor { clearInv(target); target.teleport(Spawn); plugin.Quit.get(a).add(target.getName()); + plugin.RestoreInv(target, target.getName()); // Jeppa: call for restore inventory of leaving player!! 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; } }else if(args[0].equalsIgnoreCase("Refill")){ if(p.hasPermission("HungerArena.Refill")){ + plugin.reloadChests(); if(args.length>= 2){ a = Integer.parseInt(args[1]); int list056; list056 = 0; - int limit = plugin.MyChests.getStringList("StorageXYZ").size(); + int limit = plugin.getChests().getStringList("StorageXYZ").size(); while(limit > list056){ String xyz2 = plugin.getChests().getStringList("StorageXYZ").get(list056); int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X"); @@ -675,22 +880,20 @@ public class HaCommands implements CommandExecutor { Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz); plugin.exists = false; if(chesta== a){ - if(blockatlocation.getState() instanceof Chest){ + if(blockatlocation.getType()== Material.CHEST){ plugin.exists = true; Chest chest = (Chest) blockatlocation.getState(); - if(chesta== a){ - chest.getInventory().clear(); - ItemStack[] itemsinchest = null; - Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage"); - if(o instanceof ItemStack[]){ - itemsinchest = (ItemStack[]) o; - }else if(o instanceof List){ - itemsinchest = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); - } - list056 = list056+1; - chest.getInventory().setContents(itemsinchest); - chest.update(); + chest.getInventory().clear(); + ItemStack[] itemsinchest = null; + Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage"); + if(o instanceof ItemStack[]){ + itemsinchest = (ItemStack[]) o; + }else if(o instanceof List){ + itemsinchest = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); } + list056 = list056+1; + chest.getInventory().setContents(itemsinchest); + chest.update(true); } }else{ list056 = list056+1; @@ -702,7 +905,7 @@ public class HaCommands implements CommandExecutor { }else{ int list056; list056 = 0; - int limit = plugin.MyChests.getStringList("StorageXYZ").size(); + int limit = plugin.getChests().getStringList("StorageXYZ").size(); while(limit > list056){ String xyz2 = plugin.getChests().getStringList("StorageXYZ").get(list056); int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X"); @@ -711,7 +914,7 @@ public class HaCommands implements CommandExecutor { String chestw = plugin.getChests().getString("Storage." + xyz2 + ".Location.W"); Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz); plugin.exists = false; - if(blockatlocation.getState() instanceof Chest){ + if(blockatlocation.getType()== Material.CHEST){ plugin.exists = true; Chest chest = (Chest) blockatlocation.getState(); chest.getInventory().clear(); @@ -724,48 +927,72 @@ public class HaCommands implements CommandExecutor { } list056 = list056+1; chest.getInventory().setContents(itemsinchest); - chest.update(); + chest.update(true); } } if(limit== list056){ sender.sendMessage(ChatColor.GREEN + "All chests refilled!"); } + return true; } }else{ p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; } - }else if(args[0].equalsIgnoreCase("Restart")){ //Jeppa: fixed reopen , merged routines, added respawn - int b = 0; + }else if(args[0].equalsIgnoreCase("Restart")){ if(p.hasPermission("HungerArena.Restart")){ - // Jeppa: merged the two routines and fixed reopen bug... - i = 1; // default first arena - int e = plugin.open.size(); // default amount number of arenas + i = 1; + int e = plugin.open.size(); if(args.length>= 2){ - i = Integer.parseInt(args[1]); // replace i with commandvalue - if(i > e) i=e; // dirty fix for wrong args in command... - if(i < 1) i=1; // dirty fix for wrong args in command... - e = i; // loop i to i ;) + i = Integer.parseInt(args[1]); + if(i > e) i=e; + if(i < 1) i=1; + e = i; } for(a = i; a <= e; a++){ - //Jeppa: Routine dazu: erweitert um Teleport der Player!!!!! - if(plugin.Playing.get(a).size() > 0){ // Jeppa: fix - for(b = 0; b < plugin.Playing.get(a).size(); b++){ - String s = plugin.Playing.get(a).get(b); - Player tributes = plugin.getServer().getPlayerExact(s); + 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();//Clear this , just to be sure.. gets used and cleared again! + 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);//Jeppa: Temporarly move player there } } - // ^^ - if(plugin.Watching.get(a).size() > 0){ // Jeppa: fix - for(b = 0; b < plugin.Watching.get(a).size(); b++){ - String s = plugin.Watching.get(a).get(b); - Player spectator = plugin.getServer().getPlayerExact(s); - spectator.setAllowFlight(false); - spectator.teleport(Spawn); + 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(spectator); + online.showPlayer(spectators); } + plugin.scoreboards.remove(sname); + } + } + if(plugin.Frozen.get(a)!= null){// Jeppa: use this temp. List to restore the players inventory + for(String sname: plugin.Frozen.get(a)){ + Player player = plugin.getServer().getPlayerExact(sname); + plugin.RestoreInv(player, sname); } } plugin.Dead.get(a).clear(); @@ -838,23 +1065,41 @@ public class HaCommands implements CommandExecutor { /////////////////////////////////// Toggle ////////////////////////////////////////////////// }else if(args[0].equalsIgnoreCase("close")){ if(p.hasPermission("HungerArena.toggle")){ - // Jeppa: merged the two routines and fixed reopen bug... - i = 1; // default first arena - int e = plugin.open.size(); // default amount number of arenas + i = 1; + int e = plugin.open.size(); if(args.length>= 2){ - i = Integer.parseInt(args[1]); // replace i with commandvalue - if(i > e) i=e; // dirty fix for wrong args in command... - if(i < 1) i=1; // dirty fix for wrong args in command... - e = i; // loop i to i ;) + i = Integer.parseInt(args[1]); + if(i > e) i=e; + if(i < 1) i=1; + e = i; } for(a = i; a <= e; a++){ if(plugin.open.get(a)){ plugin.open.put(a, false); + 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();//Clear this , just to be sure.. gets used and cleared again! 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);//Jeppa: Temporarly move player there } } if(plugin.Watching.get(a)!= null){ @@ -862,9 +1107,17 @@ public class HaCommands implements CommandExecutor { 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(spectators); } + plugin.scoreboards.remove(sname); + } + } + if(plugin.Frozen.get(a)!= null){// Jeppa: use this temp. List to restore the players inventory + for(String sname: plugin.Frozen.get(a)){ + Player player = plugin.getServer().getPlayerExact(sname); + plugin.RestoreInv(player, sname); } } plugin.Dead.get(a).clear(); @@ -900,10 +1153,8 @@ public class HaCommands implements CommandExecutor { if(!plugin.open.get(i)){ plugin.open.put(i, true); p.sendMessage(ChatColor.GOLD + "Arena " + i + " Open!"); - // i = i+1; // Jeppa: ??? }else{ p.sendMessage(ChatColor.RED + "Arena " + i + " already open, type /ha close to close them!"); - // i = i+1; } } } @@ -918,7 +1169,8 @@ public class HaCommands implements CommandExecutor { plugin.Cost.clear(); plugin.Fee.clear(); HandlerList.unregisterAll(plugin); //Jeppa: Close all running Listeners before reopening them! - plugin.onEnable(); //Jeppa: with this in here all Listeners get re-registered again each "reload"! so f.e the Block-break will result in multiple lines in Data.yml ... + plugin.reloadConfig(); + plugin.onEnable(); p.sendMessage(ChatColor.AQUA + "HungerArena Reloaded!"); System.out.println(ChatColor.GREEN + pname + " reloaded HungerArena!"); }else{ @@ -927,44 +1179,50 @@ public class HaCommands implements CommandExecutor { }else if(args[0].equalsIgnoreCase("WarpAll")){ if(p.hasPermission("HungerArena.Warpall")){ if(plugin.spawns.getString("Spawns_set").equalsIgnoreCase("false")){ - sender.sendMessage(ChatColor.RED + "/ha setspawn hasn't been run!"); + sender.sendMessage(ChatColor.RED + "/ha setspawn hasn't ever been run!"); }else{ if(args.length>= 2){ a = Integer.parseInt(args[1]); - if(plugin.Playing.get(a).size()== 1){ - sender.sendMessage(ChatColor.RED + "There are not enough players!"); - }else{ - if(plugin.config.getString("Auto_Start").equalsIgnoreCase("true")){ + //Jeppa: get that maps respawn... + if((plugin.spawns.getString("Spawns_set_"+a)==null) || (plugin.spawns.getString("Spawns_set_"+a).equalsIgnoreCase("false"))){ // Mapbezogen, a ist hier angegebene Arena + 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.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); + } + i = 1; + for(String playing:plugin.Playing.get(a)){ + Player tribute = plugin.getServer().getPlayerExact(playing); + plugin.Frozen.get(a).add(tribute.getName()); //Jeppa: moved here to prevent giving back the players inventory at mapchange if this is because of moving to 'playground'! + tribute.teleport(plugin.location.get(a).get(i)); + tribute.setHealth(20); + tribute.setFoodLevel(20); + tribute.setSaturation(20); + tribute.setLevel(0); + clearInv(tribute); //Jeppa: obsolete? + for(PotionEffect pe: tribute.getActivePotionEffects()){ + PotionEffectType potion = pe.getType(); + tribute.removePotionEffect(potion); + } + if(tribute.getAllowFlight()){ + tribute.setAllowFlight(false); + } + i = i+1; + } plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ public void run(){ - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha start " + a); + p.sendMessage(ChatColor.AQUA + "All Tributes warped!"); } }, 20L); } - i = 1; - for(String playing:plugin.Playing.get(a)){ - Player tribute = plugin.getServer().getPlayerExact(playing); - tribute.teleport(plugin.location.get(a).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); - } - plugin.Frozen.get(a).add(tribute.getName()); - i = i+1; - } - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - p.sendMessage(ChatColor.AQUA + "All Tributes warped!"); - } - }, 20L); } }else{ p.sendMessage(ChatColor.RED + "Too few arguments, specify an arena"); @@ -992,7 +1250,7 @@ public class HaCommands implements CommandExecutor { } } } - }else if(sender instanceof ConsoleCommandSender){ + }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()); @@ -1031,7 +1289,7 @@ public class HaCommands implements CommandExecutor { if(!plugin.Playing.get(a).isEmpty() && plugin.Playing.containsKey(a)){ for(String playernames: plugin.Playing.get(a)){ Player players = plugin.getServer().getPlayerExact(playernames); - sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + players.getHealth() + "/20"); + sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + ((Damageable)players).getHealth() + "/20"); } }else{ sender.sendMessage(ChatColor.GRAY + "No one is playing!"); @@ -1045,7 +1303,7 @@ public class HaCommands implements CommandExecutor { if(!plugin.Playing.get(1).isEmpty() && plugin.Playing.containsKey(1)){ for(String playernames: plugin.Playing.get(1)){ Player players = plugin.getServer().getPlayerExact(playernames); - sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + players.getHealth() + "/20"); + sender.sendMessage(ChatColor.GREEN + playernames + " Life: " + ((Damageable)players).getHealth() + "/20"); } }else{ sender.sendMessage(ChatColor.GRAY + "No one is playing!"); @@ -1084,6 +1342,10 @@ public class HaCommands implements CommandExecutor { }else if(args[0].equalsIgnoreCase("Kick")){ if(args.length>= 2){ Player target = Bukkit.getPlayer(args[1]); + if(target == null){ + sender.sendMessage(ChatColor.RED + "Use playername !"); + return false; + } if(plugin.getArena(target) != null){ a = plugin.getArena(target); plugin.Playing.get(a).remove(target.getName()); @@ -1096,8 +1358,22 @@ public class HaCommands implements CommandExecutor { } } clearInv(target); + 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").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); + //^^ target.teleport(Spawn); plugin.Quit.get(a).add(target.getName()); + plugin.RestoreInv(target, target.getName()); // Jeppa: call for restore inventory of leaving player!! plugin.winner(a); }else{ sender.sendMessage(ChatColor.RED + "That player isn't in the game!"); @@ -1106,11 +1382,12 @@ public class HaCommands implements CommandExecutor { sender.sendMessage(ChatColor.RED + "Too few arguments"); } }else if(args[0].equalsIgnoreCase("Refill")){ + plugin.reloadChests(); if(args.length>= 2){ a = Integer.parseInt(args[1]); int list056; list056 = 0; - int limit = plugin.MyChests.getStringList("StorageXYZ").size(); + int limit = plugin.getChests().getStringList("StorageXYZ").size(); while(limit > list056){ String xyz2 = plugin.getChests().getStringList("StorageXYZ").get(list056); int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X"); @@ -1121,22 +1398,20 @@ public class HaCommands implements CommandExecutor { Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz); plugin.exists = false; if(chesta== a){ - if(blockatlocation.getState() instanceof Chest){ + if(blockatlocation.getType()== Material.CHEST){ plugin.exists = true; Chest chest = (Chest) blockatlocation.getState(); - if(chesta== a){ - chest.getInventory().clear(); - ItemStack[] itemsinchest = null; - Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage"); - if(o instanceof ItemStack[]){ - itemsinchest = (ItemStack[]) o; - }else if(o instanceof List){ - itemsinchest = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); - } - list056 = list056+1; - chest.getInventory().setContents(itemsinchest); - chest.update(); + chest.getInventory().clear(); + ItemStack[] itemsinchest = null; + Object o = plugin.getChests().get("Storage." + xyz2 + ".ItemsInStorage"); + if(o instanceof ItemStack[]){ + itemsinchest = (ItemStack[]) o; + }else if(o instanceof List){ + itemsinchest = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); } + list056 = list056+1; + chest.getInventory().setContents(itemsinchest); + chest.update(true); } }else{ list056 = list056+1; @@ -1148,7 +1423,7 @@ public class HaCommands implements CommandExecutor { }else{ int list056; list056 = 0; - int limit = plugin.MyChests.getStringList("StorageXYZ").size(); + int limit = plugin.getChests().getStringList("StorageXYZ").size(); while(limit > list056){ String xyz2 = plugin.getChests().getStringList("StorageXYZ").get(list056); int chestx = plugin.getChests().getInt("Storage." + xyz2 + ".Location.X"); @@ -1157,7 +1432,7 @@ public class HaCommands implements CommandExecutor { String chestw = plugin.getChests().getString("Storage." + xyz2 + ".Location.W"); Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz); plugin.exists = false; - if(blockatlocation.getState() instanceof Chest){ + if(blockatlocation.getType()== Material.CHEST){ plugin.exists = true; Chest chest = (Chest) blockatlocation.getState(); chest.getInventory().clear(); @@ -1170,44 +1445,66 @@ public class HaCommands implements CommandExecutor { } list056 = list056+1; chest.getInventory().setContents(itemsinchest); - chest.update(); + chest.update(true); } } if(limit== list056){ sender.sendMessage(ChatColor.GREEN + "All chests refilled!"); } } - }else if(args[0].equalsIgnoreCase("Restart")){ //Jeppa: merged , fixed - int b = 0; - // Jeppa: merged the two routines and fixed reopen bug... - i = 1; // default first arena - int e = plugin.open.size(); // default amount number of arenas + }else if(args[0].equalsIgnoreCase("Restart")){ + //int b = 0; + i = 1; + int e = plugin.open.size(); if(args.length>= 2){ - i = Integer.parseInt(args[1]); // replace i with commandvalue - if(i > e) i=e; // dirty fix for wrong args in command... - if(i < 1) i=1; // dirty fix for wrong args in command... - e = i; // loop i to i ;) + i = Integer.parseInt(args[1]); + if(i > e) i=e; + if(i < 1) i=1; + e = i; } for(a = i; a <= e; a++){ - //Jeppa: Routine dazu: erweitert um Teleport der Player!!!!! - if(!plugin.Playing.get(a).isEmpty()){ - for(b = 0; b < plugin.Playing.get(a).size(); b++){ - String s = plugin.Playing.get(a).get(b); - Player tributes = plugin.getServer().getPlayerExact(s); + 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();//Clear this , just to be sure.. gets used and cleared again! + 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);//Jeppa: Temporarly move player there } } - // ^^ - if(!plugin.Watching.get(a).isEmpty()){ - for(b = 0; b < plugin.Watching.get(a).size(); b++){ - String s = plugin.Watching.get(a).get(b); - Player spectator = plugin.getServer().getPlayerExact(s); - spectator.setAllowFlight(false); - spectator.teleport(Spawn); + 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(spectator); + online.showPlayer(spectators); } + plugin.scoreboards.remove(sname); + } + } + if(plugin.Frozen.get(a)!= null){// Jeppa: use this temp. list to restore the players inventory + for(String sname: plugin.Frozen.get(a)){ + Player player = plugin.getServer().getPlayerExact(sname); + plugin.RestoreInv(player, sname); } } plugin.Dead.get(a).clear(); @@ -1276,23 +1573,41 @@ public class HaCommands implements CommandExecutor { } /////////////////////////////////// Toggle ////////////////////////////////////////////////// }else if(args[0].equalsIgnoreCase("close")){ - // Jeppa: merged the two routines and fixed reopen bug... - i = 1; // default first arena - int e = plugin.open.size(); // default amount number of arenas + i = 1; + int e = plugin.open.size(); if(args.length>= 2){ - i = Integer.parseInt(args[1]); // replace i with commandvalue - if(i > e) i=e; // dirty fix for wrong args in command... - if(i < 1) i=1; // dirty fix for wrong args in command... - e = i; // loop i to i ;) + i = Integer.parseInt(args[1]); + if(i > e) i=e; + if(i < 1) i=1; + e = i; } for(a = i; a <= e; a++){ if(plugin.open.get(a)){ plugin.open.put(a, false); + 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();//Clear this , just to be sure.. gets used and cleared again! 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);//Jeppa: Temporarly move player there } } if(plugin.Watching.get(a)!= null){ @@ -1300,9 +1615,17 @@ public class HaCommands implements CommandExecutor { 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(spectators); } + plugin.scoreboards.remove(sname); + } + } + if(plugin.Frozen.get(a)!= null){// Jeppa: use this temp. List to restore the players inventory + for(String sname: plugin.Frozen.get(a)){ + Player player = plugin.getServer().getPlayerExact(sname); + plugin.RestoreInv(player, sname); } } plugin.Dead.get(a).clear(); @@ -1346,48 +1669,55 @@ public class HaCommands implements CommandExecutor { plugin.Cost.clear(); plugin.Fee.clear(); HandlerList.unregisterAll(plugin); //Jeppa: Close all running Listeners before reopening them! + plugin.reloadConfig(); plugin.onEnable(); sender.sendMessage(ChatColor.AQUA + "HungerArena Reloaded!"); }else if(args[0].equalsIgnoreCase("WarpAll")){ if(plugin.spawns.getString("Spawns_set").equalsIgnoreCase("false")){ - sender.sendMessage(ChatColor.RED + "/ha setspawn hasn't been run!"); + sender.sendMessage(ChatColor.RED + "/ha setspawn hasn't ever been run!"); }else{ if(args.length>= 2){ a = Integer.parseInt(args[1]); - if(plugin.Playing.get(a).size()== 1){ - sender.sendMessage(ChatColor.RED + "There are not enough players!"); - }else{ - if(plugin.config.getString("Auto_Start").equalsIgnoreCase("true")){ + //Jeppa: ... + 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.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); + } + i = 1; + for(String playing: plugin.Playing.get(a)){ + Player tribute = plugin.getServer().getPlayerExact(playing); + plugin.Frozen.get(a).add(tribute.getName()); //Jeppa: moved here to prevent restoring inv at teleport when moving to fightplace ;) + tribute.teleport(plugin.location.get(a).get(i)); + tribute.setHealth(20); + tribute.setFoodLevel(20); + tribute.setSaturation(20); + tribute.setLevel(0); + clearInv(tribute); //Jeppa: obsolete? + for(PotionEffect pe: tribute.getActivePotionEffects()){ + PotionEffectType potion = pe.getType(); + tribute.removePotionEffect(potion); + } + if(tribute.getAllowFlight()){ + tribute.setAllowFlight(false); + } + i = i+1; + } plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ public void run(){ - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha start " + a); + sender.sendMessage(ChatColor.AQUA + "All Tributes warped!"); } }, 20L); } - i = 1; - for(String playing: plugin.Playing.get(a)){ - Player tribute = plugin.getServer().getPlayerExact(playing); - tribute.teleport(plugin.location.get(a).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); - } - plugin.Frozen.get(a).add(tribute.getName()); - i = i+1; - } - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - sender.sendMessage(ChatColor.AQUA + "All Tributes warped!"); - } - }, 20L); } }else{ sender.sendMessage(ChatColor.RED + "Too few arguments, specify an arena"); diff --git a/src/me/Travja/HungerArena/BlockStorage.java b/src/me/Travja/HungerArena/Listeners/BlockStorage.java similarity index 92% rename from src/me/Travja/HungerArena/BlockStorage.java rename to src/me/Travja/HungerArena/Listeners/BlockStorage.java index 3fa0673..f43e544 100644 --- a/src/me/Travja/HungerArena/BlockStorage.java +++ b/src/me/Travja/HungerArena/Listeners/BlockStorage.java @@ -1,7 +1,9 @@ -package me.Travja.HungerArena; +package me.Travja.HungerArena.Listeners; import java.util.List; +import me.Travja.HungerArena.Main; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; @@ -25,6 +27,7 @@ public class BlockStorage implements Listener { public BlockStorage(Main m) { this.plugin = m; } + @SuppressWarnings("deprecation") @EventHandler(priority=EventPriority.MONITOR) public void BlockBreak(BlockBreakEvent event) { Block b = event.getBlock(); @@ -38,7 +41,19 @@ public class BlockStorage implements Listener { } if ((plugin.getArena(p) != null) || (protall)) { /* Bug1a */ //int a = this.plugin.getArena(p).intValue(); - int a = 1; //Jeppa: define a default (may be needed if protall is true) + //Jeppa: get a default arena if protall is true... (but use getArena if set...) + int a = 1; + if (protall) { + String ThisWorld = p.getWorld().getName(); + int z=0; + for(z = 1; z <= plugin.worldsNames.size(); z++){ + if(plugin.worldsNames.get(z)!= null){ + if (plugin.worldsNames.get(z).equals(ThisWorld)){ + a=z; // now 'a' is the arenanumber of THIS(current) map -->may still be wrong if there are more than one arena on this map... + } + } + } + } if (plugin.getArena(p) != null) a = plugin.getArena(p); if ((!event.isCancelled()) && (((plugin.Playing.get(a)).contains(pname)) || (protall))) /* Bug1a */ { @@ -68,6 +83,7 @@ public class BlockStorage implements Listener { } } } + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR) public void Explosion(EntityExplodeEvent event){ List blocksd = event.blockList(); @@ -106,6 +122,7 @@ public class BlockStorage implements Listener { } } } + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR) public void burningBlocks(BlockBurnEvent event){ Block b = event.getBlock(); @@ -144,7 +161,19 @@ public class BlockStorage implements Listener { } } if ((plugin.getArena(p) != null) || (protall)) { /* Bug1a */ - int a = 1; //Jeppa: define a default (may be needed if protall is true) + //Jeppa: get a default arena if protall is true... (but use getArena if set...) + int a = 1; + if (protall) { + String ThisWorld = p.getWorld().getName(); + int z=0; + for(z = 1; z <= plugin.worldsNames.size(); z++){ + if(plugin.worldsNames.get(z)!= null){ + if (plugin.worldsNames.get(z).equals(ThisWorld)){ + a=z; // now 'a' is the arenanumber of THIS(current) map -->may still be wrong if there are more than one arena on this map... + } + } + } + } if (plugin.getArena(p) != null) a = plugin.getArena(p); if(!event.isCancelled()){ if (((plugin.Playing.get(a)).contains(p.getName())) || (protall)) { @@ -163,7 +192,6 @@ public class BlockStorage implements Listener { int y = br.getY(); int z = br.getZ(); String coords = w + "," + x + "," + y + "," + z + "," + a; - p.sendMessage(ChatColor.GREEN + "Sand/Gravel will land at " + coords); List blocks = plugin.data.getStringList("Blocks_Placed"); blocks.add(coords); plugin.data.set("Blocks_Placed", blocks); @@ -213,6 +241,7 @@ public class BlockStorage implements Listener { } } } + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR) public void bucketFill(PlayerBucketFillEvent event){ if(plugin.getArena(event.getPlayer())!= null){ @@ -241,6 +270,7 @@ public class BlockStorage implements Listener { } } } + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR) public void blockMelt(BlockFadeEvent event){ int i = 0; diff --git a/src/me/Travja/HungerArena/Listeners/Boundaries.java b/src/me/Travja/HungerArena/Listeners/Boundaries.java new file mode 100644 index 0000000..244d676 --- /dev/null +++ b/src/me/Travja/HungerArena/Listeners/Boundaries.java @@ -0,0 +1,78 @@ +package me.Travja.HungerArena.Listeners; + +import java.util.Map; +import java.util.Map.Entry; + +import me.Travja.HungerArena.Main; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerMoveEvent; + +public class Boundaries implements Listener{ + public Main plugin; + public Boundaries(Main m){ + this.plugin = m; + } + + @EventHandler + public void boundsCheck(PlayerMoveEvent event){ + Player p = event.getPlayer(); + Boolean inGame = plugin.getArena(p) != null; + Boolean spectating = plugin.isSpectating(p); + if(plugin.config.getBoolean("WorldEdit")) + if(insideBounds(p.getLocation()) && (inGame || spectating) || (!insideBounds(p.getLocation()) && inGame)) + event.setCancelled(true); + } + @EventHandler + public void blockBounds(BlockBreakEvent event){ + Player p = event.getPlayer(); + if(plugin.getArena(p)== null) + if(plugin.config.getBoolean("WorldEdit")) + if(insideBounds(event.getBlock().getLocation())){ + p.sendMessage(ChatColor.RED + "That block is protected by HungerArena!"); + event.setCancelled(true); + } + } + public boolean insideBounds(Location l){ + Location minl = null; + Location maxl = null; + if(plugin.spawns.get("Arena")!= null){ + Map temp = plugin.spawns.getConfigurationSection("Arena").getValues(false); + for(Entry entry: temp.entrySet()){ + if(plugin.spawns.getConfigurationSection("Arena." + entry.getKey())!= null){ + String[] min = ((String) plugin.spawns.get("Arena." + entry.getKey()) + ".Min").split(","); + String[] max = ((String) plugin.spawns.get("Arena." + entry.getKey()) + ".Max").split(","); + try{ + World world = Bukkit.getWorld(min[0]); + double x = Double.parseDouble(min[1]); + double y = Double.parseDouble(min[2]); + double z = Double.parseDouble(min[3]); + minl = new Location(world, x, y, z); + World world2 = Bukkit.getWorld(max[0]); + double x2 = Double.parseDouble(max[1]); + double y2 = Double.parseDouble(max[2]); + double z2 = Double.parseDouble(max[3]); + minl = new Location(world2, x2, y2, z2); + }catch(Exception e){ + System.out.println(e); + return false; + } + if(minl!= null && maxl!= null){ + return l.getX() >= minl.getBlockX() + && l.getX() < maxl.getBlockX() + 1 && l.getY() >= minl.getBlockY() + && l.getY() < maxl.getBlockY() + 1 && l.getZ() >= minl.getBlockZ() + && l.getZ() < maxl.getBlockZ() + 1; + } + } + } + } + return false; + } +} diff --git a/src/me/Travja/HungerArena/ChatListener.java b/src/me/Travja/HungerArena/Listeners/ChatListener.java similarity index 94% rename from src/me/Travja/HungerArena/ChatListener.java rename to src/me/Travja/HungerArena/Listeners/ChatListener.java index b225ab4..1e4eb9d 100644 --- a/src/me/Travja/HungerArena/ChatListener.java +++ b/src/me/Travja/HungerArena/Listeners/ChatListener.java @@ -1,7 +1,9 @@ -package me.Travja.HungerArena; +package me.Travja.HungerArena.Listeners; import java.util.List; +import me.Travja.HungerArena.Main; + import org.bukkit.ChatColor; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; diff --git a/src/me/Travja/HungerArena/Listeners/DeathListener.java b/src/me/Travja/HungerArena/Listeners/DeathListener.java new file mode 100644 index 0000000..780670b --- /dev/null +++ b/src/me/Travja/HungerArena/Listeners/DeathListener.java @@ -0,0 +1,282 @@ +package me.Travja.HungerArena.Listeners; + +//import java.util.ArrayList; + +import me.Travja.HungerArena.Main; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; +//import org.bukkit.entity.Entity; +//import org.bukkit.entity.Damageable; +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.EntityDamageByEntityEvent; +//import org.bukkit.event.entity.EntityDamageEvent; +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(); + + //Jeppa: get the arena the player has died in... (may be not the one he joined...) + String ThisWorld = p.getWorld().getName(); + int z=0; + for(z = 1; z <= plugin.worldsNames.size(); z++){ + if(plugin.worldsNames.get(z)!= null){ + if (plugin.worldsNames.get(z).equals(ThisWorld)){ + a=z; // now 'a' is the arenanumber of THIS(current) map + } + } + } + + //Jeppa: Fix for lonely players :) + for(i = 1; i < plugin.Dead.size(); i++){ // find the dead player and the arena he has joined(if any) + if ((plugin.Dead.get(i) != null) && (plugin.Dead.get(i).contains(pname)) && (plugin.MatchRunning.get(i) == null)) { // Jeppa: the match has not started yet ! if someone joined a game and suicided before any game started ;) -> reset the dead-list + plugin.Dead.get(i).clear(); + } + } + + //Jeppa: respawn per needInv! + for(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(","); //Jeppa: spawn to correct respawn! Dies ist der Respawn nach "Natural causes"... -> erst HIER Inv wiedergeben...??? + 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); + //Jeppa: restore inv + plugin.RestoreInv(player, player.getName()); // Jeppa: call for restore inventory of leaving player!! + } + }, 10L); + } + + + /* //Jeppa: theese routines are not used anymore... (obsolete!!!?!) + @EventHandler (priority = EventPriority.HIGHEST) + public void damage(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.Playing.get(a).size()== 2){ + if(event.getDamage()>= ((Damageable)p).getHealth()){ + event.setCancelled(true); + 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); + p.setHealth((double) 20); + p.setFoodLevel(20); + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + plugin.scoreboards.remove(p.getName()); + plugin.Kills.remove(p.getName()); + clearInv(p); + p.teleport(Spawn); + plugin.Frozen.get(a).remove(p.getName()); + plugin.Playing.get(a).remove(p.getName()); + plugin.winner(a); + } + } + } + } + } + @EventHandler (priority = EventPriority.HIGHEST) + public void damage(EntityDamageByEntityEvent event){ + Entity e = event.getEntity(); + Entity d = event.getEntity(); + if(e instanceof Player){ + Player p = (Player) e; + if(plugin.getArena(p)!= null){ + a = plugin.getArena(p); + if(plugin.Playing.get(a).size()== 2){ + if(event.getDamage()>= ((Damageable)p).getHealth()){ + event.setCancelled(true); + 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); + p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + plugin.scoreboards.remove(p.getName()); + plugin.Kills.remove(p.getName()); + clearInv(p); + p.setHealth((double) 20); + p.setFoodLevel(20); + p.teleport(Spawn); + if(d instanceof Player){ + Player k = (Player) d; + if(plugin.getArena(k)!= null){ + if(plugin.Kills.containsKey(k.getName())) + plugin.Kills.put(k.getName(), plugin.Kills.get(k.getName())+1); + } + } + plugin.Frozen.get(a).remove(p.getName()); + plugin.Playing.get(a).remove(p.getName()); + plugin.winner(a); + } + } + } + } + } + */ + + @SuppressWarnings("deprecation") + @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); + 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().getItemInHand().getType().getId()== 0){ + 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); + plugin.winner(a); + }else{ + Player killer = p.getKiller(); + String killername = killer.getName(); + String weapon = "a(n) " + killer.getItemInHand().getType().toString().replace('_', ' '); + if(killer.getItemInHand().hasItemMeta()) + if(killer.getItemInHand().getItemMeta().hasDisplayName()) + weapon = killer.getItemInHand().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); + 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); + } + } + } + } + @SuppressWarnings("deprecation") + private void clearInv(Player p){ + p.getInventory().clear(); + p.getInventory().setBoots(null); + p.getInventory().setChestplate(null); + p.getInventory().setHelmet(null); + p.getInventory().setLeggings(null); + p.updateInventory(); + } +} diff --git a/src/me/Travja/HungerArena/DmgListener.java b/src/me/Travja/HungerArena/Listeners/DmgListener.java similarity index 89% rename from src/me/Travja/HungerArena/DmgListener.java rename to src/me/Travja/HungerArena/Listeners/DmgListener.java index 41cfe93..daf9c89 100644 --- a/src/me/Travja/HungerArena/DmgListener.java +++ b/src/me/Travja/HungerArena/Listeners/DmgListener.java @@ -1,4 +1,6 @@ -package me.Travja.HungerArena; +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; diff --git a/src/me/Travja/HungerArena/Listeners/FreezeListener.java b/src/me/Travja/HungerArena/Listeners/FreezeListener.java new file mode 100644 index 0000000..b40145f --- /dev/null +++ b/src/me/Travja/HungerArena/Listeners/FreezeListener.java @@ -0,0 +1,105 @@ +package me.Travja.HungerArena.Listeners; + +import java.util.ArrayList; +import java.util.HashMap; + +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; + +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(); + @SuppressWarnings("deprecation") + @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{ + for(String players:plugin.Playing.get(a)){ + Player playing = plugin.getServer().getPlayerExact(players); + i = plugin.Playing.get(a).indexOf(players)+1; + if(!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())){ + playing.teleport(plugin.location.get(a).get(i)); + } + } + } + } + } + } +} diff --git a/src/me/Travja/HungerArena/JoinAndQuitListener.java b/src/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java similarity index 74% rename from src/me/Travja/HungerArena/JoinAndQuitListener.java rename to src/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java index 2af7cc6..86ae49d 100644 --- a/src/me/Travja/HungerArena/JoinAndQuitListener.java +++ b/src/me/Travja/HungerArena/Listeners/JoinAndQuitListener.java @@ -1,4 +1,7 @@ -package me.Travja.HungerArena; +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.HaCommands; +import me.Travja.HungerArena.Main; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -9,6 +12,7 @@ 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; @@ -21,6 +25,7 @@ public class JoinAndQuitListener implements Listener { } int i = 0; int a = 0; + @SuppressWarnings("deprecation") @EventHandler public void onJoin(PlayerJoinEvent evt) { Player p = evt.getPlayer(); @@ -32,6 +37,7 @@ public class JoinAndQuitListener implements Listener { } } + @SuppressWarnings("deprecation") @EventHandler public void onPlayerJoin(PlayerJoinEvent event){ final Player p = event.getPlayer(); @@ -57,7 +63,7 @@ public class JoinAndQuitListener implements Listener { } for(i = 1; i <= plugin.Quit.size(); i++){ if(plugin.Quit.get(i).contains(pname)){ - String[] Spawncoords = plugin.spawns.getString("Spawn_coords").split(","); + String[] Spawncoords = plugin.spawns.getString("Spawn_coords_"+i).split(","); // Jeppa: move the player where he belongs.... String w = Spawncoords[3]; World spawnw = plugin.getServer().getWorld(w); double spawnx = Double.parseDouble(Spawncoords[0]); @@ -67,16 +73,17 @@ public class JoinAndQuitListener implements Listener { 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/forfeited!"); + p.sendMessage(ChatColor.RED + "You have been teleported to last spawn because you quit/forfeited!"); + plugin.RestoreInv(p, p.getName()); // Jeppa: call for restore inventory of leaving player!! + if (plugin.Quit.get(i)!= null) plugin.Quit.get(i).remove(p.getName()); //Jeppa: fix } }, 40L); - plugin.Quit.get(i).remove(pname); //Jeppa: fix pfound = true; } } for(i = 1; i <= plugin.Dead.size(); i++){ if(plugin.Dead.get(i).contains(pname)){ - String[] Spawncoords = plugin.spawns.getString("Spawn_coords").split(","); + String[] Spawncoords = plugin.spawns.getString("Spawn_coords_"+i).split(","); // Jeppa: move the player where he belongs.... String w = Spawncoords[3]; World spawnw = plugin.getServer().getWorld(w); double spawnx = Double.parseDouble(Spawncoords[0]); @@ -86,17 +93,18 @@ public class JoinAndQuitListener implements Listener { 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/forfeited!!"); + p.sendMessage(ChatColor.RED + "You have been teleported to spawn because you quit/died/forfeited!!"); + plugin.RestoreInv(p, p.getName()); // Jeppa: call for restore inventory of leaving player!! + if (plugin.Dead.get(i)!= null) plugin.Dead.get(i).remove(p.getName()); //Jeppa: fix //This may throw an error as it is cleared meanwhile... } }, 40L); - plugin.Dead.get(i).remove(pname); //Jeppa: fix pfound = true; } } for(i = 1; i <= plugin.inArena.size(); i++){ if(plugin.inArena.get(i)!= null){ if(plugin.inArena.get(i).contains(pname)){ - String[] Spawncoords = plugin.spawns.getString("Spawn_coords").split(","); + String[] Spawncoords = plugin.spawns.getString("Spawn_coords_"+i).split(","); // Jeppa: move the player where he belongs.... String w = Spawncoords[3]; World spawnw = plugin.getServer().getWorld(w); double spawnx = Double.parseDouble(Spawncoords[0]); @@ -113,32 +121,34 @@ public class JoinAndQuitListener implements Listener { 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()); // Jeppa: call for restore inventory of leaving player!! + if (plugin.inArena.get(i)!= null) plugin.inArena.get(i).remove(p.getName()); //Jeppa: fix } }, 40L); - plugin.inArena.get(i).remove(pname); //Jeppa: fix pfound = true; } } } -//Jeppa: New routine to check if the player reconnected and is unknown to the server! + //Jeppa: New routine to check if the player reconnected and is unknown to the server! if((plugin.restricted && plugin.worlds.contains(p.getWorld().getName())) || !plugin.restricted){ if (!pfound && plugin.config.getString("Force_Players_toSpawn").equalsIgnoreCase("True")) { //Jeppa: Player is in non of the obove lists.. so he is new to the server due to restart of the server and reconnect of the player...(something like that...) - String[] Spawncoords = plugin.spawns.getString("Spawn_coords").split(","); + String[] Spawncoords = plugin.spawns.getString("Spawn_coords").split(","); //Jeppa: Spawn_coords_# may be used .. but default-spawn seems to be more usable ! (can be used as default waitingroom...) 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()); // Jeppa: call for restore inventory of leaving player!! -> this is restore inv by restart of server ... plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ public void run(){ p.teleport(Spawn); - p.sendMessage(ChatColor.RED + "You have been teleported to spawn !!"); + p.sendMessage(ChatColor.RED + "You have been teleported to spawn!!"); } }, 40L); } } -//^^ + //^^ } @EventHandler @@ -148,7 +158,7 @@ public class JoinAndQuitListener implements Listener { for(i = 1; i <= plugin.Frozen.size(); i++){ if (plugin.Frozen.get(i).contains(pname)) { plugin.Frozen.remove(pname); - String[] Spawncoords = plugin.spawns.getString("Spawn_coords").split(","); + String[] Spawncoords = plugin.spawns.getString("Spawn_coords").split(","); String w = Spawncoords[3]; World spawnw = plugin.getServer().getWorld(w); double spawnx = Double.parseDouble(Spawncoords[0]); @@ -156,24 +166,34 @@ public class JoinAndQuitListener implements Listener { 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){ + public void onPlayerQuit(PlayerQuitEvent event){ // delay zum setzen ob Player in der Arena bleibt oder fliegt bei disconnect... 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(){ // Jeppa: how long is this delay? + 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); //Jeppa: fix + 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); //Jeppa: add him to Quit and to inArena ? + plugin.inArena.get(a).add(pname); }else if(plugin.getArena(p)== null){ plugin.Quit.get(a).add(pname); } diff --git a/src/me/Travja/HungerArena/PvP.java b/src/me/Travja/HungerArena/Listeners/PvP.java similarity index 66% rename from src/me/Travja/HungerArena/PvP.java rename to src/me/Travja/HungerArena/Listeners/PvP.java index 3b34c2f..2f1b9f6 100644 --- a/src/me/Travja/HungerArena/PvP.java +++ b/src/me/Travja/HungerArena/Listeners/PvP.java @@ -1,4 +1,6 @@ -package me.Travja.HungerArena; +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -29,6 +31,11 @@ public class PvP implements Listener { 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){ @@ -51,14 +58,23 @@ public class PvP implements Listener { if(plugin.getArena(p) != null){ Player shooter = (Player) projectile.getShooter(); if(plugin.getArena(shooter)!= null){ - event.setCancelled(false); + 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 = projectile.getShooter(); +// Entity e = (Entity) projectile.getShooter(); // war in 1.5 zuvor so, ursprünglich aber ohne (Entity), in 1.5.1 wieder ohne??? if(e instanceof Skeleton){ if(plugin.getArena(p)!= null){ - event.setCancelled(false); + if(plugin.gp.get(plugin.getArena((Player) e))!= null) + if(plugin.gp.get(plugin.getArena(p))!= 0) + event.setCancelled(true); + else + event.setCancelled(false); } } } @@ -67,9 +83,10 @@ public class PvP implements Listener { @EventHandler public void PlayerDamage(EntityDamageEvent event){ Entity e = event.getEntity(); - if(e instanceof Player){ - if(plugin.gp!= 0) - event.setCancelled(true); - } + if(e instanceof Player) + if(plugin.getArena((Player) e)!= null) + if(plugin.gp.get(plugin.getArena((Player) e))!= null) + if(plugin.gp.get(plugin.getArena((Player) e))!= 0) + event.setCancelled(true); } } diff --git a/src/me/Travja/HungerArena/Signs.java b/src/me/Travja/HungerArena/Listeners/Signs.java similarity index 95% rename from src/me/Travja/HungerArena/Signs.java rename to src/me/Travja/HungerArena/Listeners/Signs.java index e1ff7d5..81a8f47 100644 --- a/src/me/Travja/HungerArena/Signs.java +++ b/src/me/Travja/HungerArena/Listeners/Signs.java @@ -1,4 +1,6 @@ -package me.Travja.HungerArena; +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/src/me/Travja/HungerArena/SpectatorListener.java b/src/me/Travja/HungerArena/Listeners/SpectatorListener.java similarity index 87% rename from src/me/Travja/HungerArena/SpectatorListener.java rename to src/me/Travja/HungerArena/Listeners/SpectatorListener.java index a9c6ec3..15c0984 100644 --- a/src/me/Travja/HungerArena/SpectatorListener.java +++ b/src/me/Travja/HungerArena/Listeners/SpectatorListener.java @@ -1,4 +1,6 @@ -package me.Travja.HungerArena; +package me.Travja.HungerArena.Listeners; + +import me.Travja.HungerArena.Main; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -13,6 +15,7 @@ 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.scoreboard.DisplaySlot; public class SpectatorListener implements Listener { public Main plugin; @@ -84,6 +87,14 @@ public class SpectatorListener implements Listener { 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(i = 0; i < plugin.Playing.size(); i++){ + if(plugin.Playing.get(i)!= null){ + if(plugin.Playing.get(i).contains(attackerName)){ + event.setCancelled(true); } } } @@ -97,6 +108,14 @@ public class SpectatorListener implements Listener { 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(i = 0; i < plugin.Playing.size(); i++){ + if(plugin.Playing.get(i)!= null){ + if(plugin.Playing.get(i).contains(bowManName)){ + event.setCancelled(true); } } } @@ -145,6 +164,11 @@ public class SpectatorListener implements Listener { 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()); } } } diff --git a/src/me/Travja/HungerArena/TeleportListener.java b/src/me/Travja/HungerArena/Listeners/TeleportListener.java similarity index 95% rename from src/me/Travja/HungerArena/TeleportListener.java rename to src/me/Travja/HungerArena/Listeners/TeleportListener.java index 819d5c2..0176546 100644 --- a/src/me/Travja/HungerArena/TeleportListener.java +++ b/src/me/Travja/HungerArena/Listeners/TeleportListener.java @@ -1,7 +1,9 @@ -package me.Travja.HungerArena; +package me.Travja.HungerArena.Listeners; import java.util.List; +import me.Travja.HungerArena.Main; + import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/me/Travja/HungerArena/Listeners/spawnsListener.java b/src/me/Travja/HungerArena/Listeners/spawnsListener.java new file mode 100644 index 0000000..bfbc0df --- /dev/null +++ b/src/me/Travja/HungerArena/Listeners/spawnsListener.java @@ -0,0 +1,49 @@ +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; + +public class spawnsListener implements Listener{ + public Main plugin; + public spawnsListener(Main m){ + this.plugin = m; + } + + @SuppressWarnings("deprecation") + @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(); + if(p.getItemInHand().getTypeId()== plugin.config.getInt("spawnsTool")){ + String[] info = plugin.setting.get(p.getName()).split("-"); + if(Integer.parseInt(info[1])!= plugin.config.getInt("maxPlayers")+1){ + String coords = l.getWorld().getName() + " " + (l.getX()+.5) + " " + (l.getY()+1) + " " + (l.getZ()+.5); // fixed (.getName() + + //Jeppa: Hier das Command anpassen!!!??? oder die Daten vorher bearbeiten die übergeben werden? ->done + //p.sendMessage(ChatColor.DARK_AQUA + "[ÜbergebeneWerte:] " + ChatColor.RED + "Setting For Arena " + info[0] + " Starting From Point " + info[1]); + //p.sendMessage(ChatColor.DARK_AQUA + "[ÜbergebeneWerte:] " + ChatColor.RED + "Coords: " + coords); + + p.performCommand("startpoint " + info[0] + " " + info[1] + " " + coords); + + if(Integer.parseInt(info[1])>= plugin.config.getInt("maxPlayers")){ + p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "All spawns set!"); + plugin.setting.remove(p.getName()); + }else{ + plugin.setting.put(p.getName(), info[0] + "-" + (Integer.parseInt(info[1])+1)); + p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Next starting point: " + (Integer.parseInt(info[1])+1)); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/me/Travja/HungerArena/Main.java b/src/me/Travja/HungerArena/Main.java index e9dd1a7..763a92b 100644 --- a/src/me/Travja/HungerArena/Main.java +++ b/src/me/Travja/HungerArena/Main.java @@ -8,45 +8,79 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Random; import java.util.logging.Level; import java.util.logging.Logger; +import me.Travja.HungerArena.Listeners.BlockStorage; +import me.Travja.HungerArena.Listeners.Boundaries; +import me.Travja.HungerArena.Listeners.ChatListener; +import me.Travja.HungerArena.Listeners.DeathListener; +import me.Travja.HungerArena.Listeners.DmgListener; +import me.Travja.HungerArena.Listeners.FreezeListener; +import me.Travja.HungerArena.Listeners.JoinAndQuitListener; +import me.Travja.HungerArena.Listeners.PvP; +import me.Travja.HungerArena.Listeners.Signs; +import me.Travja.HungerArena.Listeners.SpectatorListener; +import me.Travja.HungerArena.Listeners.TeleportListener; +import me.Travja.HungerArena.Listeners.spawnsListener; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.FireworkEffect.Type; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.WorldCreator; import org.bukkit.command.CommandExecutor; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; +import org.bukkit.scoreboard.Scoreboard; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; public class Main extends JavaPlugin{ static Logger log; public HashMap> Playing = new HashMap>(); public HashMap> Ready = new HashMap>(); public HashMap> Dead = new HashMap>(); + public HashMap MatchRunning = new HashMap(); // Jeppa: Marker for the running arenas public HashMap> Quit = new HashMap>(); public HashMap> Out = new HashMap>(); public HashMap> Watching = new HashMap>(); + public HashMap Kills = new HashMap(); public HashMap> NeedConfirm = new HashMap>(); public HashMap> location = new HashMap>(); - public ArrayList Tele = new ArrayList(); public HashMap> inArena = new HashMap>(); public HashMap> Frozen = new HashMap>(); public HashMap> arena = new HashMap>(); public HashMap canjoin = new HashMap(); public HashMap maxPlayers = new HashMap(); public HashMap open = new HashMap(); - public List worlds; + public HashMap setting = new HashMap(); + public HashMap gp = new HashMap(); + public ArrayList Tele = new ArrayList(); + public ArrayList needInv = new ArrayList();// Jeppa: this is used as a marker now for players that joined an arena (for respawning and restoring inv) + public List worlds = new ArrayList(); + public HashMap worldsNames = new HashMap(); //Jeppa: for storing the worlds names ... + + public HashMap scoreboards = new HashMap(); + public Listener DeathListener = new DeathListener(this); public Listener SpectatorListener = new SpectatorListener(this); public Listener FreezeListener = new FreezeListener(this); @@ -60,11 +94,18 @@ public class Main extends JavaPlugin{ public Listener Signs = new Signs(this); public Listener BlockStorage = new BlockStorage(this); public Listener WinGames = new WinGamesListener(this); + public Listener WorldChange = new WorldChange(this); + public Listener Boundaries = new Boundaries(this); + public Listener spawnsListener = new spawnsListener(this); public CommandExecutor HaCommands = new HaCommands(this); public CommandExecutor SponsorCommands = new SponsorCommands(this); public CommandExecutor SpawnsCommand = new SpawnsCommand(this); + + public me.Travja.HungerArena.ConfigManager ConfigManager = new ConfigManager(this); + public boolean exists; public boolean restricted; + public FileConfiguration config; public FileConfiguration spawns = null; public File spawnsFile = null; @@ -79,34 +120,42 @@ public class Main extends JavaPlugin{ public ArrayList Reward = new ArrayList(); public ArrayList Cost = new ArrayList(); public ArrayList Fee = new ArrayList(); + public boolean vault = false; public boolean eco = false; public Economy econ = null; + int i = 0; int v = 0; - int start = 0; - int deathtime = 0; - int timetodeath = 0; int a = 0; - public int gp = 0; - int grace = 0; + //int grace = 0; //Jeppa: it's no int anymore + //int start = 0; //Jeppa: it's not int anymore... + File PFilePath = new File(getDataFolder(), "/inventories"); + + @SuppressWarnings("deprecation") public void onEnable(){ log = this.getLogger(); + config = this.getConfig(); config.options().copyDefaults(true); - this.saveDefaultConfig(); + if(!new File(this.getDataFolder(), "config.yml").exists()) + this.saveDefaultConfig(); spawns = this.getSpawns(); spawns.options().copyDefaults(true); - this.saveSpawns(); + if(!new File(this.getDataFolder(), "spawns.yml").exists()) + this.saveSpawns(); data = this.getData(); data.options().copyDefaults(true); - this.saveData(); + if(!new File(this.getDataFolder(), "Data.yml").exists()) + this.saveData(); management = this.getManagement(); management.options().copyDefaults(true); - this.saveManagement(); + if(!new File(this.getDataFolder(), "commandAndBlockManagement.yml").exists()) + this.saveManagement(); MyChests = this.getChests(); MyChests.options().copyDefaults(true); - this.saveChests(); + if(!new File(this.getDataFolder(), "Chests.yml").exists()) + this.saveChests(); getServer().getPluginManager().registerEvents(DeathListener, this); getServer().getPluginManager().registerEvents(SpectatorListener, this); getServer().getPluginManager().registerEvents(FreezeListener, this); @@ -119,52 +168,29 @@ public class Main extends JavaPlugin{ getServer().getPluginManager().registerEvents(BlockStorage, this); getServer().getPluginManager().registerEvents(WinGames, this); getServer().getPluginManager().registerEvents(Damage, this); + getServer().getPluginManager().registerEvents(WorldChange, this); + getServer().getPluginManager().registerEvents(Boundaries, this); + getServer().getPluginManager().registerEvents(spawnsListener, this); + getCommand("Ha").setExecutor(HaCommands); getCommand("Sponsor").setExecutor(SponsorCommands); getCommand("Startpoint").setExecutor(SpawnsCommand); + + // Jeppa: create path if not exists + if (!PFilePath.exists()) { + PFilePath.mkdirs(); + } + for(File file: PFilePath.listFiles()){ // Jeppa: use changed path + String filename = file.getName(); + int lastIndex = filename.lastIndexOf('.'); + filename = filename.substring(0, lastIndex >= 0 ? lastIndex : 0); //Jeppa: remove .yml from filename + needInv.add(filename); // Mark player as "lost child" :) + } + i = 1; - if(spawns.getConfigurationSection("Spawns")!= null){ - Map temp = spawns.getConfigurationSection("Spawns").getValues(false); - for(Entry entry: temp.entrySet()){ - if(spawns.getConfigurationSection("Spawns." + entry.getKey())!= null){ - Map temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false); - for(Map.Entry e: temp2.entrySet()){ - if(spawns.get("Spawns." + entry.getKey() + "." + e.getKey())!= null){ - String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "." + e.getKey())).split(","); - Integer a = Integer.parseInt(entry.getKey()); - Integer s = Integer.parseInt(e.getKey()); - if(location.get(a)== null) - location.put(a, new HashMap()); - log.info("Added spawn number " + s + " in arena " + a + "!"); - location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3]))); - } - } - } - } - } - for(i = 1; i <= location.size(); i++){ - log.info("Loaded " + location.get(i).size() + " tribute spawns for arena " + i + "!"); - Playing.put(i, new ArrayList()); - Ready.put(i, new ArrayList()); - Dead.put(i, new ArrayList()); - Quit.put(i, new ArrayList()); - Out.put(i, new ArrayList()); - Watching.put(i, new ArrayList()); - NeedConfirm.put(i, new ArrayList()); - inArena.put(i, new ArrayList()); - Frozen.put(i, new ArrayList()); - arena.put(i, new ArrayList()); - canjoin.put(i, false); - if(location.get(i).size()== config.getInt("maxPlayers")){ - maxPlayers.put(i, location.get(i).size()); - }else if(location.size()< config.getInt("maxPlayers")){ - maxPlayers.put(i, location.get(i).size()); - }else if(location.size()> config.getInt("maxPlayers")){ - maxPlayers.put(i, config.getInt("maxPlayers")); - } - log.info("Max players is for arena " + i + " is " + maxPlayers.get(i)); - open.put(i, true); - } + + this.reloadSpawnpoints(); //Jeppa: loading of spawnpoints and fill of areas now moved to subroutine... + if (setupEconomy()) { log.info("Found Vault! Hooking in for economy!"); } @@ -210,6 +236,8 @@ public class Main extends JavaPlugin{ }else if(!worlds.isEmpty()){ restricted = true; } + ConfigManager.setup(); + scoreboardInit(); log.info("Enabled v" + getDescription().getVersion()); } @@ -217,6 +245,85 @@ public class Main extends JavaPlugin{ log.info("Disabled v" + getDescription().getVersion()); } + //Jeppa: routine to reload the spawns and fill arrays as subroutine... will be needed elsewhere... + public void reloadSpawnpoints(){ + if(spawns.getConfigurationSection("Spawns")!= null){ + Map temp = spawns.getConfigurationSection("Spawns").getValues(false); + for(Entry entry: temp.entrySet()){ + if(spawns.getConfigurationSection("Spawns." + entry.getKey())!= null){ + Integer a = Integer.parseInt(entry.getKey()); + worldsNames.put(a, "none_meening_this_is_not_a_map"); // Jeppa: placeholder + if(location.get(a)== null) location.put(a, new HashMap()); // Jeppa: this was only set when real spawnpoints were found.. now we need it to get things work... + Map temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false); + for(Map.Entry e: temp2.entrySet()){ + if(spawns.get("Spawns." + entry.getKey() + "." + e.getKey())!= null){ + if(!e.getKey().equals("Max") || !e.getKey().equals("Min")){ + String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "." + e.getKey())).split(","); + Integer s = Integer.parseInt(e.getKey()); + log.info("Added spawn number " + s + " in arena " + a + "!"); + location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3]))); + worldsNames.put(a, coords[0]); // Jeppa: remember arena# and name...! + } + } + } + } + } + } + + for(i = 1; i <= location.size(); i++){ //Jeppa: location is arenanumber now!! Count can be changed in defaultconfig !! + if(location.get(i).size()!= 0){ + log.info("Loaded " + location.get(i).size() + " tribute spawns for arena " + i + "!"); + Playing.put(i, new ArrayList()); + Ready.put(i, new ArrayList()); + Dead.put(i, new ArrayList()); + MatchRunning.put(i, null); + Quit.put(i, new ArrayList()); + Out.put(i, new ArrayList()); + Watching.put(i, new ArrayList()); + NeedConfirm.put(i, new ArrayList()); + inArena.put(i, new ArrayList()); + Frozen.put(i, new ArrayList()); + arena.put(i, new ArrayList()); + canjoin.put(i, false); + if(location.get(i).size()== config.getInt("maxPlayers")){ + maxPlayers.put(i, location.get(i).size()); + }else if(location.size()< config.getInt("maxPlayers")){ + maxPlayers.put(i, location.get(i).size()); + }else if(location.size()> config.getInt("maxPlayers")){ + maxPlayers.put(i, config.getInt("maxPlayers")); + } + log.info("Max players is for arena " + i + " is " + maxPlayers.get(i)); + open.put(i, true); + }else{ // Jeppa: this maps/arenas are unused... but still they need some values :( (it's a bugfix for some 'for'-loops..) -> usable arenas 1 - 20 with the new default configuration-file! if more are needed they must count up.. 21 22... + //log.info("If you miss some arenas, f.e. arena #" + i + " make sure arenas are numbered 1 to n !"); + log.info("Arena #" + i + " is unused and has no spawns !"); + Playing.put(i, new ArrayList()); + Ready.put(i, new ArrayList()); + Dead.put(i, new ArrayList()); + MatchRunning.put(i, null); + Quit.put(i, new ArrayList()); + Out.put(i, new ArrayList()); + Watching.put(i, new ArrayList()); + NeedConfirm.put(i, new ArrayList()); + inArena.put(i, new ArrayList()); + Frozen.put(i, new ArrayList()); + arena.put(i, new ArrayList()); + canjoin.put(i, false); // false = free, true = game in action.. + maxPlayers.put(i, 0); + open.put(i, false); + } + } + } + + public WorldEditPlugin hookWE() { + Plugin wPlugin = getServer().getPluginManager().getPlugin("WorldEdit"); + + if ((wPlugin == null) || (!(wPlugin instanceof WorldEditPlugin))) + return null; + + return (WorldEditPlugin) wPlugin; + } + public boolean setupEconomy() { if (getServer().getPluginManager().getPlugin("Vault") == null) { return false; @@ -235,7 +342,6 @@ public class Main extends JavaPlugin{ } spawns = YamlConfiguration.loadConfiguration(spawnsFile); - // Look for defaults in the jar InputStream defConfigStream = this.getResource("spawns.yml"); if (defConfigStream != null) { YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); @@ -264,7 +370,6 @@ public class Main extends JavaPlugin{ } data = YamlConfiguration.loadConfiguration(dataFile); - // Look for defaults in the jar InputStream defConfigStream = this.getResource("Data.yml"); if (defConfigStream != null) { YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); @@ -293,7 +398,6 @@ public class Main extends JavaPlugin{ } management = YamlConfiguration.loadConfiguration(managementFile); - // Look for defaults in the jar InputStream defConfigStream = this.getResource("commandAndBlockManagement.yml"); if (defConfigStream != null) { YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); @@ -316,19 +420,11 @@ public class Main extends JavaPlugin{ this.getLogger().log(Level.SEVERE, "Could not save config to " + managementFile, ex); } } -//Jeppa: Add routine like the others for loading Chests with their very own file.. public void reloadChests() { if (ChestsFile == null) { ChestsFile = new File(getDataFolder(), "Chests.yml"); } MyChests = YamlConfiguration.loadConfiguration(ChestsFile); - - // Look for defaults in the jar - InputStream defConfigStream = this.getResource("Chests.yml"); - if (defConfigStream != null) { - YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); - MyChests.setDefaults(defConfig); - } } public FileConfiguration getChests() { if (MyChests == null) { @@ -346,95 +442,438 @@ public class Main extends JavaPlugin{ this.getLogger().log(Level.SEVERE, "Could not save config to " + ChestsFile, ex); } } -//^^ - public void winner(final Integer a){ - String[] Spawncoords = spawns.getString("Spawn_coords").split(","); - World spawnw = getServer().getWorld(Spawncoords[3]); - double spawnx = Double.parseDouble(Spawncoords[0]); - double spawny = Double.parseDouble(Spawncoords[1]); - double spawnz = Double.parseDouble(Spawncoords[2]); - Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); - //final String a2 = String.valueOf(a); // Jeppa Test - if(Playing.get(a).size()== 1 && canjoin.get(a)== true){ - //Announce winner - for(i = 0; i < Playing.get(a).size(); i++){ - String winnername = Playing.get(a).get(i); - Player winner = getServer().getPlayerExact(winnername); - String winnername2 = winner.getName(); - getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); - winner.getInventory().clear(); - winner.getInventory().setBoots(null); - winner.getInventory().setChestplate(null); - winner.getInventory().setHelmet(null); - winner.getInventory().setLeggings(null); - winner.setLevel(0); - for(PotionEffect pe: winner.getActivePotionEffects()){ - PotionEffectType potion = pe.getType(); - winner.removePotionEffect(potion); + File PFile = null; + FileConfiguration PConfig= null; + public void reloadPFile(String pname) { + if (PFile == null) { + PFile = new File(PFilePath, pname + ".yml"); // Jeppa: set the new playerfile... or the existing one... + } + PConfig = YamlConfiguration.loadConfiguration(PFile); + InputStream defConfigStream = this.getResource("Player.yml"); + if (defConfigStream != null) { + YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); + PConfig.setDefaults(defConfig); + } + } + public FileConfiguration getPConfig(String pname) { + PFile = null; //Jeppa: must get cleared , else a file from another player could (will) be used at save..!!! + this.reloadPFile(pname); //Jeppa: load/set file + return PConfig; + } + public void savePFile(String pname) { + if (PConfig.getString("player").equals(pname)){ // Jeppa: check if the 'calling' player still is the one who started this... + try { + this.PConfig.save(PFile); + } catch (IOException ex) { + this.getLogger().log(Level.SEVERE, "Could not save config to " + PFile, ex); + } + }else this.getLogger().log(Level.SEVERE, "Could not save config to " + pname + ".yml ! It's not this players inventory!?"); + } + + @SuppressWarnings("unchecked") + public void RestoreInv(Player p, String pname){ // Jeppa: moved here from 'WorldChange' to make it available for calls from other routines... and lots of changes... + int u=0; + for(u=1;u) o).toArray(new ItemStack[0]); + } + p.getInventory().setContents(pinv); + p.updateInventory(); //Jeppa: is this still necessary ??? seems to work without.. but... + + ItemStack[] parmor = null; + o = pinfo.get("armor"); + if(o instanceof ItemStack[]){ + parmor = (ItemStack[]) o; + }else if(o instanceof List){ + parmor = (ItemStack[]) ((List) o).toArray(new ItemStack[0]); + } + p.getInventory().setArmorContents(parmor); + p.updateInventory(); + + p.sendMessage(ChatColor.GOLD + "[HA] " + ChatColor.GREEN + "Your inventory has been restored!"); + new File(PFilePath, pname + ".yml").delete(); + + //Jeppa: maybe there is more than one entry in needInv from disconnection or whatever ... remove them all! + for(i = 0; i < needInv.size(); i++){ + String name2 = needInv.get(i);{ + if (name2.equals(pname)) needInv.remove(pname); + } + } + }catch(Exception e){ + p.sendMessage(ChatColor.RED + "Something went wrong when trying to restore your inv, please contact an administrator."); + System.out.println("Error occured when trying to restore the inv of " + pname + ":"); + System.out.println(e); + } + }//else p.sendMessage(ChatColor.RED + "This is not your inventory! :)..."); //DEBUG + } + } + + @SuppressWarnings("deprecation") + public void winner(final Integer a){ + if(Playing.get(a).size()== 1){ + //Jeppa: check if the Arena-respawn is available. + String[] Spawncoords; + if (spawns.getString("Spawn_coords_" + a) != null){ + Spawncoords = spawns.getString("Spawn_coords_"+ a).split(","); + } else { + Spawncoords = spawns.getString("Spawn_coords").split(","); + } + World spawnw = getServer().getWorld(Spawncoords[3]); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + + if(canjoin.get(a)== true){ + //Announce winner + for(i = 0; i < Playing.get(a).size(); i++){ + String winnername = Playing.get(a).get(i); + final Player winner = getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.setLevel(0); + for(PotionEffect pe: winner.getActivePotionEffects()){ + PotionEffectType potion = pe.getType(); + winner.removePotionEffect(potion); + } + Tele.add(winner); + needInv.add(winnername2); + winner.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + if(scoreboards.containsKey(winner.getName())) + scoreboards.remove(winner.getName()); + if(Kills.containsKey(winner.getName())) + Kills.remove(winner.getName()); + //final World w = winner.getWorld(); + winner.teleport(Spawn); + + + //////////////////////////////////////////////////////// + //////////////////// FIREWORKS /////////////////////// + //////////////////////////////////////////////////////// + + + for(i = 0; i < 10; i++){ + Bukkit.getScheduler().runTaskLater(this, new Runnable(){ + public void run(){ + //Spawn the Fireworks, get the FireworkMeta. + Firework fw = (Firework) winner.getWorld().spawnEntity(winner.getLocation(), EntityType.FIREWORK); + FireworkMeta fwm = fw.getFireworkMeta(); + + //Our random generator + Random r = new Random(); + + //Get the type + int rt = r.nextInt(4) + 1; + Type type = Type.BALL; + if (rt == 1) type = Type.BALL; + if (rt == 2) type = Type.BALL_LARGE; + if (rt == 3) type = Type.BURST; + if (rt == 4) type = Type.CREEPER; + if (rt == 5) type = Type.STAR; + + //Get our random colours + int r1i = r.nextInt(17) + 1; + int r2i = r.nextInt(17) + 1; + Color c1 = getColor(r1i); + Color c2 = getColor(r2i); + + //Create our effect with this + FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build(); + + //Then apply the effect to the meta + fwm.addEffect(effect); + + //Generate some random power and set it + int rp = r.nextInt(2) + 1; + fwm.setPower(rp); + + //Then apply this to our rocket + fw.setFireworkMeta(fwm); + } + },20 + i*20L); + } + + + //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////// + + + /*if(config.getBoolean("reloadWorld")){ getServer().unloadWorld(w, false); getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ public void run(){ getServer().createWorld(new WorldCreator(w.getName())); } },200L); - } - if(!config.getBoolean("rewardEco.enabled")){ - for(ItemStack Rewards: Reward){ - winner.getInventory().addItem(Rewards); + }*/ + + //Jeppa: restore the winners inventory + this.RestoreInv(winner, winnername2); + + if(!config.getBoolean("rewardEco.enabled")){ + for(ItemStack Rewards: Reward){ + winner.getInventory().addItem(Rewards); + } + }else{ + for(ItemStack Rewards: Reward){ + winner.getInventory().addItem(Rewards); + } + econ.depositPlayer(winner.getName(), config.getDouble("rewardEco.reward")); } - }else{ - for(ItemStack Rewards: Reward){ - winner.getInventory().addItem(Rewards); + if(deathtime.get(a)!= null){ + getServer().getScheduler().cancelTask(deathtime.get(a)); + deathtime.put(a, null); + } + if(grace.get(a)!= null){ + getServer().getScheduler().cancelTask(grace.get(a)); + grace.put(a, null); + } + if(start.get(a)!= null){ + getServer().getScheduler().cancelTask(start.get(a)); + start.put(a, null); } - econ.depositPlayer(winner.getName(), config.getDouble("rewardEco.reward")); } Playing.get(a).clear(); - getServer().getScheduler().cancelTask(deathtime); - } - //Show spectators - for(String s1: Watching.get(a)){ - Player spectator = getServer().getPlayerExact(s1); - spectator.setAllowFlight(false); - spectator.teleport(Spawn); - for(Player online:getServer().getOnlinePlayers()){ - online.showPlayer(spectator); - } - } - if(config.getString("Auto_Restart").equalsIgnoreCase("True")){ - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ - public void run(){ - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart " + a); + //Jeppa: clear the other Lists , too! Game is over! + Quit.get(a).clear(); + Dead.get(a).clear(); + + //Show spectators + for(String s1: Watching.get(a)){ + Player spectator = getServer().getPlayerExact(s1); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:getServer().getOnlinePlayers()){ + online.showPlayer(spectator); } - }, 220L); + } + if(config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ + public void run(){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart " + a); + } + }, 220L); + } + //Jeppa: new List that marks arenas as started! + MatchRunning.put(a, null);//Jeppa: no, i'm not using boolean ;) this is the marker for the arenas + }else{ + //no real winner + for(i = 0; i < Playing.get(a).size(); i++){ + String winnername = Playing.get(a).get(i); + Player winner = getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + winner.getInventory().clear(); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.setLevel(0); + for(PotionEffect pe: winner.getActivePotionEffects()){ + PotionEffectType potion = pe.getType(); + winner.removePotionEffect(potion); + } + Tele.add(winner); + needInv.add(winnername2); + //final World w = winner.getWorld(); + winner.teleport(Spawn); + /*if(config.getBoolean("reloadWorld")){ + getServer().unloadWorld(w, false); + getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ + public void run(){ + getServer().createWorld(new WorldCreator(w.getName())); + } + },200L); + }*/ + + //Jeppa: restore the winners inventory + this.RestoreInv(winner, winnername2); + + Playing.get(a).clear(); + //Jeppa :Fix + if(deathtime.get(a)!= null){ + getServer().getScheduler().cancelTask(deathtime.get(a)); + deathtime.put(a, null); + } + //Jeppa: clear the other lists too! Game is over! + Quit.get(a).clear(); + Dead.get(a).clear(); + } + //Show spectators + for(String s1: Watching.get(a)){ + Player spectator = getServer().getPlayerExact(s1); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + if(config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ + public void run(){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart " + a); + } + }, 220L); + } } } } + + private Color getColor(int i) { + if(i==1) + return Color.AQUA; + else if(i==2) + return Color.BLACK; + else if(i==3) + return Color.BLUE; + else if(i==4) + return Color.FUCHSIA; + else if(i==5) + return Color.GRAY; + else if(i==6) + return Color.GREEN; + else if(i==7) + return Color.LIME; + else if(i==8) + return Color.MAROON; + else if(i==9) + return Color.NAVY; + else if(i==10) + return Color.OLIVE; + else if(i==11) + return Color.ORANGE; + else if(i==12) + return Color.PURPLE; + else if(i==13) + return Color.RED; + else if(i==14) + return Color.SILVER; + else if(i==15) + return Color.TEAL; + else if(i==16) + return Color.WHITE; + else + return Color.YELLOW; + } + + + + private void scoreboardInit(){ + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ + public void run(){ + for(Player pl: getServer().getOnlinePlayers()){ + updateScoreboard(pl); + } + } + }, 20L, 10L); + } + + @SuppressWarnings("deprecation") + public void updateScoreboard(Player p){ + if(getArena(p)!= null){ + a = getArena(p); + if(scoreboards.get(p.getName())!= null && scoreboards.get(p.getName()).getObjective("HA")!= null){ + Scoreboard sb = scoreboards.get(p.getName()); + Objective obj = sb.getObjective("HA"); + if(obj!= null){ + Score kills = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Kills")); + Score players = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Players")); + Score spectators = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Spectators")); + players.setScore(Playing.get(a).size()); + if(Kills.containsKey(p.getName())) + kills.setScore(Kills.get(p.getName())); + if(Watching.get(a)!= null) + spectators.setScore(Watching.get(a).size()); + if(config.getInt("DeathMatch")!= 0){ + if(timetodeath.get(a)!= null){ + if(timetodeath.get(a)> 0){ + String secs = String.valueOf((Integer.valueOf(timetodeath.get(a)-timetodeath.get(a)/60*60)< 10) ? "0" + Integer.valueOf(timetodeath.get(a)-timetodeath.get(a)/60*60) : Integer.valueOf(timetodeath.get(a)-timetodeath.get(a)/60*60)); + obj.setDisplayName(ChatColor.GREEN + "HA - DMTime: " + ChatColor.AQUA + Integer.valueOf(timetodeath.get(a)/60) + ":" + secs); + }else{ + obj.setDisplayName(ChatColor.GREEN + "HA - " + ChatColor.RED + "DEATHMATCH"); + } + } + }else{ + obj.setDisplayName(ChatColor.GREEN + "HungerArena"); + } + p.setScoreboard(sb); + } + } + } + } + + public HashMap grace = new HashMap(); + public HashMap start = new HashMap(); + public HashMap deathtime = new HashMap(); + public HashMap timetodeath = new HashMap(); + @SuppressWarnings("deprecation") public void startGames(final Integer a){ - String begin = config.getString("Start_Message"); - begin = begin.replaceAll("(&([a-f0-9]))", "\u00A7$2"); + String begin = ChatColor.translateAlternateColorCodes('&', config.getString("Start_Message")); final String msg = begin; - /* Jeppa add : */ if(config.getInt("Countdown_Timer") != 0) { i = config.getInt("Countdown_Timer") ; } else { i = 10; } + for(String gn: Playing.get(a)){ + Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard(); + Objective sobj = scoreboard.registerNewObjective("HA", "HAData"); + sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); + Score skills = sobj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Kills")); + skills.setScore(0); + Score sdeaths = sobj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Spectators")); + sdeaths.setScore(0); + Score splayers = sobj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Players")); + splayers.setScore(0); + sobj.setDisplaySlot(DisplaySlot.SIDEBAR); + Bukkit.getPlayer(gn).setScoreboard(scoreboard); + scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard()); + } + getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + a); + //Jeppa: new List that marks the arenas as started! + MatchRunning.put(a, "true");//Jeppa: no, i'm not using boolean ;) + if(start.get(a)!= null) getServer().getScheduler().cancelTask(start.get(a)); + //start.put(a, null); if(config.getString("Countdown").equalsIgnoreCase("true")){ - start = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ + start.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ public void run(){ if(i > 0){ if(worlds.isEmpty()){ if(config.getBoolean("broadcastAll")){ - getServer().broadcastMessage(String.valueOf(i)); + getServer().broadcastMessage(ChatColor.AQUA + "Game " + a + " starting in: " + String.valueOf(i)); }else{ for(String gn: Playing.get(a)){ Player g = getServer().getPlayer(gn); - g.sendMessage(String.valueOf(i)); + g.sendMessage(ChatColor.AQUA + "Game starting in: " + String.valueOf(i)); } } }else{ @@ -454,8 +893,22 @@ public class Main extends JavaPlugin{ } } i = i-1; - canjoin.put(a, true); + canjoin.put(a, true); // Jeppa: this was the reason for players not being able to join when the timer task was broken (counting below 0)... if(i== -1){ + for(String gn: Playing.get(a)){ + Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard(); + Objective sobj = scoreboard.registerNewObjective("HA", "HAData"); + sobj.setDisplayName(ChatColor.GREEN + "HA - Starting"); + Score skills = sobj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Kills")); + skills.setScore(0); + Score sdeaths = sobj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Spectators")); + sdeaths.setScore(0); + Score splayers = sobj.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Players")); + splayers.setScore(0); + sobj.setDisplaySlot(DisplaySlot.SIDEBAR); + Bukkit.getPlayer(gn).setScoreboard(scoreboard); + scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard()); + } if(Frozen.get(a)!= null) Frozen.get(a).clear(); if(config.getBoolean("broadcastAll")){ @@ -466,52 +919,54 @@ public class Main extends JavaPlugin{ g.sendMessage(msg); } } - getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + a); - getServer().getScheduler().cancelTask(start); if(config.getInt("Grace_Period")!= 0){ - gp = config.getInt("Grace_Period"); - grace = getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable(){ + gp.put(a, config.getInt("Grace_Period")); + if(grace.get(a)== null) grace.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable(){ public void run(){ - gp = gp-1; - if(gp == 30 || gp == 15 || (gp < 11 && gp != 0)){ + gp.put(a, gp.get(a)-1); + if(gp.get(a) == 30 || gp.get(a) == 15 || (gp.get(a) < 11 && gp.get(a) != 0)){ if(config.getBoolean("broadcastAll")){ for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ - wp.sendMessage(ChatColor.GREEN + "Grace period ends in " + gp + " seconds!"); + wp.sendMessage(ChatColor.GREEN + "Grace period ends in " + gp.get(a) + " seconds!"); } }else - getServer().broadcastMessage(ChatColor.GREEN + "Grace period ends in " + gp + " seconds!"); + getServer().broadcastMessage(ChatColor.GREEN + "Grace period ends in " + gp.get(a) + " seconds!"); } - if(gp == 0){ + if(gp.get(a) <= 0){ if(config.getBoolean("broadcastAll")){ for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ wp.sendMessage(ChatColor.GREEN + "Grace period is over, FIGHT!"); } }else getServer().broadcastMessage(ChatColor.GREEN + "Grace period is over, FIGHT!"); - getServer().getScheduler().cancelTask(grace); + getServer().getScheduler().cancelTask(grace.get(a)); + grace.put(a, null); } } - },20L, 20L); + },20L, 20L)); } if(config.getInt("DeathMatch")!= 0){ int death = config.getInt("DeathMatch"); - timetodeath = death; - deathtime = getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable(){ + timetodeath.put(a, death*60); + if(deathtime.get(a)== null) deathtime.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable(){ public void run(){ - timetodeath = timetodeath-1; - if(config.getBoolean("broadcastAll")){ - for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ - if(timetodeath!= 0){ - wp.sendMessage(ChatColor.RED + String.valueOf(timetodeath) + " mins till the death match!"); + timetodeath.put(a, timetodeath.get(a)-1); + if(Integer.valueOf(timetodeath.get(a))%300== 0){ + if(config.getBoolean("broadcastAll")){ + for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ + if(timetodeath.get(a)!= 0){ + wp.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a)/60) + ChatColor.RED + " mins till the death match!"); + } + } + }else{ + for(String gn: Playing.get(a)){ + Player g = getServer().getPlayer(gn); + g.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a)) + ChatColor.RED + " mins till the death match!"); } } - }else{ - for(String gn: Playing.get(a)){ - Player g = getServer().getPlayer(gn); - g.sendMessage(ChatColor.RED + String.valueOf(timetodeath) + " mins till the death match!"); - } } - if(timetodeath== 0){ + if(timetodeath.get(a)<= 0){ + i = 1; for(String playing: Playing.get(a)){ Player tribute = getServer().getPlayerExact(playing); tribute.teleport(location.get(a).get(i)); @@ -525,23 +980,24 @@ public class Main extends JavaPlugin{ } } if(config.getBoolean("broadcastAll")){ - for(Player wp: location.get(a).get(0).getWorld().getPlayers()){ - wp.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.size() + " tributes will be facing off!"); + for(Player wp: location.get(a).get(1).getWorld().getPlayers()){ + wp.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!"); } }else{ for(String gn: Playing.get(a)){ Player g = getServer().getPlayer(gn); - g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.size() + " tributes will be facing off!"); + g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!"); } } - getServer().getScheduler().cancelTask(deathtime); + getServer().getScheduler().cancelTask(deathtime.get(a)); + deathtime.put(a, null); } } - }, 1200L, 1200L); + }, 20L, 20L)); } } } - }, 20L, 20L); + }, 20L, 20L)); }else{ Frozen.get(a).clear(); if(config.getBoolean("broadcastAll")){ diff --git a/src/me/Travja/HungerArena/SpawnsCommand.java b/src/me/Travja/HungerArena/SpawnsCommand.java index e50335d..ebe0d02 100644 --- a/src/me/Travja/HungerArena/SpawnsCommand.java +++ b/src/me/Travja/HungerArena/SpawnsCommand.java @@ -3,6 +3,7 @@ package me.Travja.HungerArena; import java.util.ArrayList; import java.util.HashMap; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.Command; @@ -14,40 +15,101 @@ public class SpawnsCommand implements CommandExecutor { public Main plugin; int i = 0; int a = 0; + boolean NoPlayerSpawns = true; // Jeppa : default public SpawnsCommand(Main m) { this.plugin = m; } @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player p = (Player) sender; + String ThisWorld = p.getWorld().getName(); + for(i = 1; i <= plugin.worldsNames.size(); i++){ //worldsNames-Inhalt (integer) entspricht der Arenanummer !! + if(plugin.worldsNames.get(i)!= null){ //Jeppa: damit das so geht müssen die Arenen aber wirklich durchgezählt sein!! + if (plugin.worldsNames.get(i).equals(ThisWorld)){ + a=i; // now 'a' is the arenanumber of THIS(current) map , only available if this map already has min. one startpoint! + //p.sendMessage(ChatColor.GREEN + "[HungerArena]: Diese Map[KurzeAbfrage!! in startpoint]: "+ ThisWorld + " ist nummer: "+ a); + NoPlayerSpawns = false; // mapname found -> there are PlayerSpawns...--> map seems playable + } + } + } if(cmd.getName().equalsIgnoreCase("StartPoint")){ if(p.hasPermission("HungerArena.StartPoint")){ if(!plugin.restricted || (plugin.restricted && plugin.worlds.contains(p.getWorld().getName()))){ - if(args.length>= 2){ + Location loc = null; + double x; + double y; + double z; + if(args.length == 6){ + try{ // was missing..... + i = Integer.valueOf(args[1]); + a = Integer.valueOf(args[0]); + }catch(Exception e){ + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return true; //Jeppa: true??? false ??? + } + + String world = args[2]; + x = Double.parseDouble(args[3]); + y = Double.parseDouble(args[4]); + z = Double.parseDouble(args[5]); + loc = new Location(Bukkit.getWorld(world), x, y, z); + if(plugin.location.get(a)!= null){ + if(plugin.location.get(a).size()>= i){ + plugin.location.get(a).put(i, new Location(loc.getWorld(), x, y, z)); + }else{ + plugin.location.get(a).put(i, new Location(loc.getWorld(), x, y, z)); + } + }else{ + plugin.location.put(a, new HashMap()); + plugin.location.get(a).put(i, new Location(loc.getWorld(), x, y, z)); + plugin.Playing.put(a, new ArrayList()); + plugin.Ready.put(a, new ArrayList()); + plugin.Dead.put(a, new ArrayList()); + plugin.Quit.put(a, new ArrayList()); + plugin.Out.put(a, new ArrayList()); + plugin.Watching.put(a, new ArrayList()); + plugin.NeedConfirm.put(a, new ArrayList()); + plugin.inArena.put(a, new ArrayList()); + plugin.Frozen.put(a, new ArrayList()); + plugin.arena.put(a, new ArrayList()); + plugin.canjoin.put(a, false); + plugin.open.put(a, true); + } + String coords = plugin.location.get(a).get(i).getWorld().getName() + "," + (plugin.location.get(a).get(i).getX()+.5) + "," + plugin.location.get(a).get(i).getY() + "," + (plugin.location.get(a).get(i).getZ()+.5); + p.sendMessage(coords); + plugin.spawns.set("Spawns." + a + "." + i, coords); + plugin.saveSpawns(); + plugin.maxPlayers.put(a, plugin.location.get(a).size()); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + a + "!"); + this.plugin.reloadSpawnpoints(); // Jeppa: fix the check-routines looking for arenas in the HashMaps... -> muss in jede routine vor den return!!! + return true; + } + if(args.length>= 2){ // Welt und Pos Startummer angegeben try{ i = Integer.valueOf(args[1]); a = Integer.valueOf(args[0]); }catch(Exception e){ p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return true; //Jeppa: wieso true??? } if(i >= 1 && i <= plugin.config.getInt("maxPlayers")){ if(plugin.restricted && !plugin.worlds.contains(p.getWorld().getName())){ p.sendMessage(ChatColor.GOLD + "We ran the command, however, this isn't a world you defined in the config..."); p.sendMessage(ChatColor.GOLD + "If this is the right world, please disregard this message."); } - Location ploc = p.getLocation().getBlock().getLocation(); - double x = ploc.getX(); - double y = ploc.getY(); - double z = ploc.getZ(); + loc = p.getLocation().getBlock().getLocation(); + x = loc.getX(); + y = loc.getY(); + z = loc.getZ(); if(plugin.location.get(a)!= null){ if(plugin.location.get(a).size()>= i){ - plugin.location.get(a).put(i, new Location(ploc.getWorld(), x, y, z)); + plugin.location.get(a).put(i, new Location(loc.getWorld(), x, y, z)); }else{ - plugin.location.get(a).put(i, new Location(ploc.getWorld(), x, y, z)); + plugin.location.get(a).put(i, new Location(loc.getWorld(), x, y, z)); } }else{ plugin.location.put(a, new HashMap()); - plugin.location.get(a).put(i, new Location(ploc.getWorld(), x, y, z)); + plugin.location.get(a).put(i, new Location(loc.getWorld(), x, y, z)); plugin.Playing.put(a, new ArrayList()); plugin.Ready.put(a, new ArrayList()); plugin.Dead.put(a, new ArrayList()); @@ -61,14 +123,57 @@ public class SpawnsCommand implements CommandExecutor { plugin.canjoin.put(a, false); plugin.open.put(a, true); } - String coords = plugin.location.get(a).get(i).getWorld().getName() + "," + plugin.location.get(a).get(i).getX() + "," + plugin.location.get(a).get(i).getY() + "," + plugin.location.get(a).get(i).getZ(); + String coords = plugin.location.get(a).get(i).getWorld().getName() + "," + (plugin.location.get(a).get(i).getX()+.5) + "," + plugin.location.get(a).get(i).getY() + "," + (plugin.location.get(a).get(i).getZ()+.5); + p.sendMessage(coords); plugin.spawns.set("Spawns." + a + "." + i, coords); plugin.saveSpawns(); plugin.maxPlayers.put(a, plugin.location.get(a).size()); p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + a + "!"); + this.plugin.reloadSpawnpoints(); // Jeppa: fix for the check-routines looking for arenas in the HashMaps... -> muss in jede routine vor den return!!! }else{ - p.sendMessage(ChatColor.RED + "You can't go past " + plugin.maxPlayers + " players!"); + p.sendMessage(ChatColor.RED + "You can't go past " + plugin.config.getInt("maxPlayers") + " players!"); } + }else if(args.length == 1){ + if (sender instanceof Player){ + p = (Player) sender; + if(NoPlayerSpawns){ // oben wurde keine Welt gefunden! --> this is for changing the arenanumber to correct value ! If this arena already has playerspawns use that arenanumber , ignore the given number + try{ + a = Integer.parseInt(args[0]); // kein Int = Fehler, Nicht vorhanden = Fehler + }catch(Exception e){ + p.sendMessage(ChatColor.RED + "Argument not an integer!"); + return true; + } + } + if (plugin.spawns.get("Spawns." + a) != null){ + int start = 1; + while(start Mit angabe der Arena wird NICHT der erste punkt gesetzt oder weitergemacht, sondern das Wekzeug aktiviert! + //dem player hier noch das "Werkzeug" per Befehl in die Hand drücken??? TODO + return true; + } + } + } + p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Begin Setting For Arena " + a + " Starting From Point " + 1); + plugin.setting.put(p.getName(), a + "-" + 1); + //dem player hier noch das "Werkzeug" per Befehl in die Hand drücken??? TODO + return true; + }else{ + sender.sendMessage(ChatColor.BLUE + "This Can Only Be Sent As A Player"); + } + } else { + p.sendMessage(ChatColor.RED + "No argument given! \nUse command like this:\n/startpoint [Arena #] [Startpoint #] for setting your position as a startpoint.\n/startpoint [Arena #] [Startpoint #] [Mapname] [x] [y] [z] \nOr you can use /startpoint [Arena #] to use the 'spawntool': ID"+ plugin.config.getInt("spawnsTool") +" for setting the startpoints!"); // \n If this map already has startpoints you can use /startpoint without any arguments !"); + return false; } } }else{ diff --git a/src/me/Travja/HungerArena/SponsorCommands.java b/src/me/Travja/HungerArena/SponsorCommands.java index b7cfdbd..bfa11f8 100644 --- a/src/me/Travja/HungerArena/SponsorCommands.java +++ b/src/me/Travja/HungerArena/SponsorCommands.java @@ -15,6 +15,7 @@ public class SponsorCommands implements CommandExecutor { this.plugin = m; } + @SuppressWarnings("deprecation") @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if(cmd.getName().equalsIgnoreCase("Sponsor")){ diff --git a/src/me/Travja/HungerArena/WorldChange.java b/src/me/Travja/HungerArena/WorldChange.java new file mode 100644 index 0000000..7824e46 --- /dev/null +++ b/src/me/Travja/HungerArena/WorldChange.java @@ -0,0 +1,44 @@ +package me.Travja.HungerArena; + +//import java.io.File; +//import java.util.List; + +//import org.bukkit.ChatColor; +//import org.bukkit.configuration.file.FileConfiguration; +//import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChangedWorldEvent; +//import org.bukkit.inventory.ItemStack; + +public class WorldChange implements Listener { + public Main plugin; + public WorldChange(Main m) { + plugin = m; + } + + //@SuppressWarnings({ "deprecation", "unchecked" }) + @EventHandler + public void worldChange(PlayerChangedWorldEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + String ThisWorld = p.getWorld().getName(); + int i=0; + int a=0; + for(i = 1; i <= plugin.worldsNames.size(); i++){ //Jeppa: get the number of arena the player is moving in! + if(plugin.worldsNames.get(i)!= null){ + if (plugin.worldsNames.get(i).equals(ThisWorld)){ + a=i; //now 'a' is the HA-arena the player has moved in now --> can be (or not) the one he joined, !! + } + } + } +//Jeppa: + if(plugin.Frozen.get(a)!=null){ //Dont't call it when changing to non-HA-map! + if(!plugin.Frozen.get(a).contains(pname)){ //Only give back the players inventory at mapchange if this mapchange is NOT a teleport from waitingarea to playgroud!! And don't remove him from "Playing" and "Ready" in this case!!! + //Jeppa : This may collide with other tools like MultiInv oder Multiverse Inv !!!???? but shouldn't ! + plugin.RestoreInv(p, pname); //Jeppa: This will also do a check thru all available arenas and remove the player from the lists as he is NOT playing... + } + } + } +}