From de44f825be59d96da77136bf1dd2b26fc23d09b7 Mon Sep 17 00:00:00 2001 From: YoshiGenius Date: Wed, 18 Jul 2012 07:14:50 +1000 Subject: [PATCH] Updated code. --- config.yml | 66 + plugin.yml | 12 + src/me/travja/hungerarena/BlockStorage.java | 289 ++++ src/me/travja/hungerarena/Blocks.java | 25 + src/me/travja/hungerarena/ChatListener.java | 51 + src/me/travja/hungerarena/Chests.java | 84 + src/me/travja/hungerarena/CommandBlock.java | 27 + src/me/travja/hungerarena/DeathListener.java | 167 ++ src/me/travja/hungerarena/DmgListener.java | 32 + src/me/travja/hungerarena/FreezeListener.java | 24 + src/me/travja/hungerarena/HaCommands.java | 1402 +++++++++++++++++ .../hungerarena/JoinAndQuitListener.java | 137 ++ src/me/travja/hungerarena/Main.java | 109 ++ .../hungerarena/PlayerWinGamesEvent.java | 27 + src/me/travja/hungerarena/PvP.java | 24 + src/me/travja/hungerarena/Signs.java | 52 + src/me/travja/hungerarena/SpawnsCommand.java | 243 +++ .../travja/hungerarena/SpectatorListener.java | 132 ++ .../travja/hungerarena/SponsorCommands.java | 102 ++ .../travja/hungerarena/TeleportListener.java | 36 + .../travja/hungerarena/WinGamesListener.java | 24 + 21 files changed, 3065 insertions(+) create mode 100644 config.yml create mode 100644 plugin.yml create mode 100644 src/me/travja/hungerarena/BlockStorage.java create mode 100644 src/me/travja/hungerarena/Blocks.java create mode 100644 src/me/travja/hungerarena/ChatListener.java create mode 100644 src/me/travja/hungerarena/Chests.java create mode 100644 src/me/travja/hungerarena/CommandBlock.java create mode 100644 src/me/travja/hungerarena/DeathListener.java create mode 100644 src/me/travja/hungerarena/DmgListener.java create mode 100644 src/me/travja/hungerarena/FreezeListener.java create mode 100644 src/me/travja/hungerarena/HaCommands.java create mode 100644 src/me/travja/hungerarena/JoinAndQuitListener.java create mode 100644 src/me/travja/hungerarena/Main.java create mode 100644 src/me/travja/hungerarena/PlayerWinGamesEvent.java create mode 100644 src/me/travja/hungerarena/PvP.java create mode 100644 src/me/travja/hungerarena/Signs.java create mode 100644 src/me/travja/hungerarena/SpawnsCommand.java create mode 100644 src/me/travja/hungerarena/SpectatorListener.java create mode 100644 src/me/travja/hungerarena/SponsorCommands.java create mode 100644 src/me/travja/hungerarena/TeleportListener.java create mode 100644 src/me/travja/hungerarena/WinGamesListener.java diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..f01ab54 --- /dev/null +++ b/config.yml @@ -0,0 +1,66 @@ +# default config.yml +#config version for us devs. DONT CHANGE THIS, or it will screw up some things PRETTY badly. +config: + version: 1.3 +# Message to display when the games start +Start_Message: '&bLet The Games Begin!' +# If the games should automatically restart at the end +Auto_Restart: 'false' +# If it should automatically start the countdown on warping +Auto_Start: 'false' +# If tributes need to type /ha confirm to join +Need_Confirm: 'true' +# What the reward for winning is +Reward: + ID: 264 + Amount: 10 +# What sponsors have to pay to sponsor tributes +Sponsor_Cost: + ID: 264 + Amount: 1 +# Whether or not the countdown will start upon warping. +Countdown: 'true' +Spawn_coords: 100,100,100,world +# If players will only talk to close players of the whole server +ChatClose: 'false' +# How close the players have to be to talk to them +ChatClose_Radius: 10 +# Whether or not players can break blocks while playing +Protected_Arena: 'true' +# Whether or not players will be frozen when they are teleported to their positions +Frozen_Teleport: 'true' +# Whether or not thunder will sound upon a players death +Cannon_Death: 'true' +Tribute_one_spawn: 100,100,100 +Tribute_two_spawn: 100,100,100 +Tribute_three_spawn: 100,100,100 +Tribute_four_spawn: 100,100,100 +Tribute_five_spawn: 100,100,100 +Tribute_six_spawn: 100,100,100 +Tribute_seven_spawn: 100,100,100 +Tribute_eight_spawn: 100,100,100 +Tribute_nine_spawn: 100,100,100 +Tribute_ten_spawn: 100,100,100 +Tribute_eleven_spawn: 100,100,100 +Tribute_twelve_spawn: 100,100,100 +Tribute_thirteen_spawn: 100,100,100 +Tribute_fourteen_spawn: 100,100,100 +Tribute_fifteen_spawn: 100,100,100 +Tribute_sixteen_spawn: 100,100,100 +Tribute_seventeen_spawn: 100,100,100 +Tribute_eighteen_spawn: 100,100,100 +Tribute_nineteen_spawn: 100,100,100 +Tribute_twenty_spawn: 100,100,100 +Tribute_twentyone_spawn: 100,100,100 +Tribute_twentytwo_spawn: 100,100,100 +Tribute_twentythree_spawn: 100,100,100 +Tribute_twentyfour_spawn: 100,100,100 +# If /ha setspawn has been run +Spawn_set: 'false' +# True means give money to winner, false means don't. +eco: + enabled: false + reward: 100 +# How much money to give the winner. +# Leave this. :) +Blocks_Destroyed: \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..21fcc45 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,12 @@ +name: HungerArena +main: me.travja.hungerarena.Main +version: 1.3alpha +description: A lightweight and powerful plugin to help with playing The Hunger Games! +softdepend: [Vault] +commands: + Ha: + description: Base command for HungerArena! + StartPoint: + description: Set the starting points for tributes. + Sponsor: + description: Sponsor a tribute. \ No newline at end of file diff --git a/src/me/travja/hungerarena/BlockStorage.java b/src/me/travja/hungerarena/BlockStorage.java new file mode 100644 index 0000000..589581b --- /dev/null +++ b/src/me/travja/hungerarena/BlockStorage.java @@ -0,0 +1,289 @@ +package me.travja.hungerarena; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockGrowEvent; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; + +public class BlockStorage implements Listener { + public Main plugin; + public BlockStorage(Main m) { + this.plugin = m; + } + /*@EventHandler + public void creeperExplosion(EntityExplodeEvent event){ + if(plugin.canjoin== true){ + for(Block b:event.blockList()){ + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Explode: " + coords); + List blocks = plugin.config.getStringList("Blocks_Destroyed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + } + @EventHandler + public void burningBlocks(BlockBurnEvent event){ + if(plugin.canjoin== true){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Burn: " + coords); + List blocks = plugin.config.getStringList("Blocks_Destroyed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + @EventHandler + public void leafDecay(LeavesDecayEvent event){ + if(plugin.canjoin== true){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Decay: " + coords); + List blocks = plugin.config.getStringList("Blocks_Destroyed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + @EventHandler + public void blockPlace(BlockPlaceEvent event){ + if(plugin.canjoin== true){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + if(!(d== 51) && !(d==12){ + System.out.println("Place: " + coords); + List blocks = plugin.config.getStringList("Blocks_Placed"); + blocks.add(coords); + plugin.config.set("Blocks_Placed", blocks); + plugin.saveConfig(); + } + Location location = b.getLocation(); + if (b.getType() == Material.SAND || b.getType() == Material.GRAVEL) { + if (location.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) { + int i = 0; + for (i = location.getBlockY(); i > -1; i --) { + location = new Location(location.getWorld(), location.getBlockX(), i, location.getBlockZ()); + if (location.getBlock().getType() != Material.AIR && location.getBlock().getType() != Material.WATER && location.getBlock().getType() != Material.LAVA) { + break; + } + event.getPlayer().sendMessage("Block will land at: " + location); + System.out.println("Sand Place: " + coords); + List blocks = plugin.config.getStringList("Blocks_Destroyed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + } + } + } + @EventHandler + public void bucketEmpty(PlayerBucketEmptyEvent event){ + if(plugin.canjoin== true){ + Block clicked = event.getBlockClicked(); + BlockFace face = event.getBlockFace(); + Block b = clicked.getRelative(face); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Bucket Empty: " + coords); + List blocks = plugin.config.getStringList("Blocks_Placed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + @EventHandler + public void bucketFill(PlayerBucketFillEvent event){ + if(plugin.canjoin== true){ + Block b = event.getBlockClicked(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Bucket Fill: " + coords); + List blocks = plugin.config.getStringList("Blocks_Destroyed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + @EventHandler + public void blockBreak(BlockBreakEvent event){ + if(plugin.canjoin== true){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Break: " + coords); + List blocks = plugin.config.getStringList("Blocks_Destroyed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + @EventHandler + public void blockMelt(BlockFadeEvent event){ + if(plugin.canjoin== true){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Fade: " + coords); + List blocks = plugin.config.getStringList("Blocks_Destroyed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + @EventHandler + public void blockGrow(BlockGrowEvent event){ + if(plugin.canjoin== true){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Grow: " + coords); + List blocks = plugin.config.getStringList("Blocks_Placed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + @EventHandler + public void blockForm(BlockFormEvent event){ + if(plugin.canjoin== true){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Snowfall: " + coords); + List blocks = plugin.config.getStringList("Blocks_Placed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + @EventHandler + public void pistonPush(BlockPistonExtendEvent event){ + if(plugin.canjoin== true){ + for(Block b:event.getBlocks()){ + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Piston: " + coords); + List blocks = plugin.config.getStringList("Blocks_Destroyed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + } + @EventHandler + public void onChange(BlockPhysicsEvent event){ + Block block = event.getBlock(); + Material changed = event.getChangedType(); + if (block.getType() == Material.LAVA){ + if (changed == Material.LAVA){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Lava Change: " + coords); + List blocks = plugin.config.getStringList("Blocks_Placed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + }else if(changed == Material.WATER){ + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Water Change: " + coords); + List blocks = plugin.config.getStringList("Blocks_Placed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + }else if (block.getType() == Material.SAND || block.getType() == Material.GRAVEL) { + if (changed == Material.AIR) { + Block b = event.getBlock(); + String w = b.getWorld().getName(); + int x = b.getX(); + int y = b.getY(); + int z = b.getZ(); + int d = b.getTypeId(); + String coords = w + "," + x + "," + y + "," + z + "," + d; + System.out.println("Sand/Gravel Fall: " + coords); + List blocks = plugin.config.getStringList("Blocks_Placed"); + blocks.add(coords); + plugin.config.set("Blocks_Destroyed", blocks); + plugin.saveConfig(); + } + } + }*/ +} \ No newline at end of file diff --git a/src/me/travja/hungerarena/Blocks.java b/src/me/travja/hungerarena/Blocks.java new file mode 100644 index 0000000..c4081c8 --- /dev/null +++ b/src/me/travja/hungerarena/Blocks.java @@ -0,0 +1,25 @@ +package me.travja.hungerarena; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; + +public class Blocks implements Listener { + public Main plugin; + public Blocks(Main m) { + this.plugin = m; + } + @EventHandler + public void BreakBlock(BlockBreakEvent event){ + Player p = event.getPlayer(); + String pname = p.getDisplayName(); + if(plugin.Playing.contains(pname)){ + if(plugin.config.getString("Protected_Arena").equalsIgnoreCase("True")){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You can't break blocks when you're playing!"); + } + } + } +} diff --git a/src/me/travja/hungerarena/ChatListener.java b/src/me/travja/hungerarena/ChatListener.java new file mode 100644 index 0000000..bb64d81 --- /dev/null +++ b/src/me/travja/hungerarena/ChatListener.java @@ -0,0 +1,51 @@ +package me.travja.hungerarena; + +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChatEvent; + +public class ChatListener implements Listener { + public Main plugin; + public ChatListener(Main m) { + this.plugin = m; + } + @EventHandler + public void TributeChat(PlayerChatEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Playing.contains(pname)){ + String msg = "<" + ChatColor.RED + "[Tribute] " + ChatColor.WHITE + p.getName() + ">" + " " + event.getMessage(); + if(plugin.config.getString("ChatClose").equalsIgnoreCase("True")){ + double radius = plugin.config.getDouble("ChatClose_Radius"); + List near = p.getNearbyEntities(radius, radius, radius); + event.setCancelled(true); + if(!(near.size()== 0)){ + p.sendMessage(msg); + for(Entity e:near){ + if(e instanceof Player){ + ((Player) e).sendMessage(msg); + } + } + }else if(near.size()== 0){ + p.sendMessage(msg); + p.sendMessage(ChatColor.YELLOW + "No one near!"); + }else if(!(near.size()== 0)){ + for(Entity en:near){ + if(!(en instanceof Player)){ + p.sendMessage(msg); + p.sendMessage(ChatColor.YELLOW + "No one near!"); + } + } + } + }else{ + event.setCancelled(true); + plugin.getServer().broadcastMessage(msg); + } + } + } +} diff --git a/src/me/travja/hungerarena/Chests.java b/src/me/travja/hungerarena/Chests.java new file mode 100644 index 0000000..25dae27 --- /dev/null +++ b/src/me/travja/hungerarena/Chests.java @@ -0,0 +1,84 @@ +package me.travja.hungerarena; + +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; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class Chests implements Listener { + public Main plugin; + public Chests(Main m) { + this.plugin = m; + } + @EventHandler + public void ChestSaves(PlayerInteractEvent event){ + Block block = event.getClickedBlock(); + Player p = event.getPlayer(); + if(p.getItemInHand().getType()== Material.BLAZE_ROD && event.getAction() == Action.LEFT_CLICK_BLOCK){ + if(block.getState() instanceof Chest){ + if(p.hasPermission("HungerArena.Chest.Store")){ + ItemStack[] itemsinchest = ((Chest) block.getState()).getInventory().getContents(); + int blockx = block.getX(); + int blocky = block.getY(); + int blockz = block.getZ(); + String blockw = block.getWorld().getName().toString(); + if(!plugin.getConfig().contains("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X")){ + plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.X", blockx); + plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky); + plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z",blockz); + plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw); + plugin.getConfig().addDefault("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest); + }else{ + plugin.getConfig().set("Storage." + blockx + "," + blocky+ "," + blockz + ".Location.X",blockx); + plugin.getConfig().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Y", blocky); + plugin.getConfig().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.Z", blockz); + plugin.getConfig().set("Storage." + blockx + "," + blocky + "," + blockz + ".Location.W", blockw); + plugin.getConfig().set("Storage." + blockx + "," + blocky + "," + blockz + ".ItemsInStorage", itemsinchest); + } + List list2 = plugin.getConfig().getStringList("StorageXYZ"); + list2.add(blockx + "," + blocky + "," + blockz); + plugin.getConfig().set("StorageXYZ", list2); + plugin.getConfig().options().copyDefaults(true); + plugin.saveConfig(); + p.sendMessage(ChatColor.GREEN + "Chest Stored!"); + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission to store chests!"); + } + } + } + } + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + Player p = event.getPlayer(); + Block block = event.getBlock(); + Location blocklocation = event.getBlock().getLocation(); + if (block.getState() instanceof Chest && !plugin.Playing.contains(p.getDisplayName())) { + int blockx = blocklocation.getBlockX(); + int blocky = blocklocation.getBlockY(); + int blockz = blocklocation.getBlockZ(); + if (plugin.getConfig().getStringList("StorageXYZ").contains(blockx + "," + blocky + "," + blockz)) { + if(p.hasPermission("HungerArena.Chest.Break")){ + List list2 = plugin.getConfig().getStringList("StorageXYZ"); + list2.remove(blockx + "," + blocky + "," + blockz); + plugin.getConfig().set("StorageXYZ", list2); + plugin.getConfig().options().copyDefaults(true); + plugin.saveConfig(); + p.sendMessage("Chest Removed!"); + } else { + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "[HungerArena] That's a storage chest! You don't have permission to break it!"); + } + } + } + } +} diff --git a/src/me/travja/hungerarena/CommandBlock.java b/src/me/travja/hungerarena/CommandBlock.java new file mode 100644 index 0000000..9e4ccfb --- /dev/null +++ b/src/me/travja/hungerarena/CommandBlock.java @@ -0,0 +1,27 @@ +package me.travja.hungerarena; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class CommandBlock implements Listener { + public Main plugin; + public CommandBlock(Main m) { + this.plugin = m; + } + @EventHandler(priority = EventPriority.HIGHEST) + public void CatchCommand(PlayerCommandPreprocessEvent event){ + String cmd = event.getMessage(); + Player p = event.getPlayer(); + String pname = p.getName(); + if(!cmd.contains("/ha") && plugin.Playing.contains(pname) && plugin.canjoin== true){ + if(!p.hasPermission("HungerArena.UseCommands")){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are only allowed to use /ha commands!"); + } + } + } +} diff --git a/src/me/travja/hungerarena/DeathListener.java b/src/me/travja/hungerarena/DeathListener.java new file mode 100644 index 0000000..2ce35fd --- /dev/null +++ b/src/me/travja/hungerarena/DeathListener.java @@ -0,0 +1,167 @@ +package me.travja.hungerarena; + +import org.bukkit.*; +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; + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Dead.contains(pname)){ + String[] Spawncoords = plugin.config.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]); + Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + event.setRespawnLocation(Spawn); + } + } + @EventHandler + @SuppressWarnings("SizeReplaceableByIsEmpty") + public void onPlayerDeath(PlayerDeathEvent event){ + Player p = event.getEntity(); + Server s = p.getServer(); + String pname = p.getName(); + String[] Spawncoords = plugin.config.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]); + Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + if(plugin.Playing.contains(pname)){ + 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.add(pname); + plugin.Playing.remove(pname); + String leftmsg = ChatColor.BLUE + "There are now " + plugin.Playing.size() + " tributes left!"; + if(p.getKiller() instanceof Player){ + if(p.getKiller().getItemInHand().getType().getId()== 0){ + Player killer = p.getKiller(); + String killername = killer.getName(); + event.setDeathMessage(""); + s.broadcastMessage(ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with their FIST!"); + s.broadcastMessage(leftmsg); + if(plugin.Playing.size()== 1 && plugin.canjoin== true){ + //Announce winner + String winnername = plugin.Playing.get(i++); + Player winner = plugin.getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + plugin.getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.teleport(Spawn); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.getInventory().addItem(plugin.Reward); + plugin.Playing.clear(); + //Show spectators + if(!plugin.Watching.isEmpty()){ + String s1 = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s1); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart"); + } + } + }else{ + Player killer = p.getKiller(); + String killername = killer.getName(); + Material weapon = killer.getItemInHand().getType(); + String msg = ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with a(n) " + weapon; + event.setDeathMessage(""); + s.broadcastMessage(msg); + s.broadcastMessage(leftmsg); + if(plugin.Playing.size()== 1 && plugin.canjoin== true){ + //Announce winner + String winnername = plugin.Playing.get(i++); + Player winner = plugin.getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + plugin.getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.teleport(Spawn); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.getInventory().addItem(plugin.Reward); + plugin.Playing.clear(); + //Show spectators + if(plugin.Watching.size() != 0){ + String s1 = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s1); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart"); + } + } + } + }else{ + event.setDeathMessage(""); + s.broadcastMessage(ChatColor.LIGHT_PURPLE + pname + " died of natural causes!"); + s.broadcastMessage(leftmsg); + if(plugin.Playing.size()== 1 && plugin.canjoin== true){ + //Announce winner + String winnername = plugin.Playing.get(i++); + Player winner = plugin.getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + plugin.getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.teleport(Spawn); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.getInventory().addItem(plugin.Reward); + // Create the event here + PlayerWinGamesEvent winevent = new PlayerWinGamesEvent(winner); + // Call the event + Bukkit.getServer().getPluginManager().callEvent(winevent); + plugin.Playing.clear(); + //Show spectators + if(!plugin.Watching.isEmpty()){ + String s1 = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s1); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart"); + } + } + } + } + } +} diff --git a/src/me/travja/hungerarena/DmgListener.java b/src/me/travja/hungerarena/DmgListener.java new file mode 100644 index 0000000..6b4f61a --- /dev/null +++ b/src/me/travja/hungerarena/DmgListener.java @@ -0,0 +1,32 @@ +package me.travja.hungerarena; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; + +/** + * + * @author YoshiGenius + */ +public class DmgListener implements Listener { + + public Main plugin; + public DmgListener(Main m) { + this.plugin = m; + } + + @EventHandler + public void onDmg(EntityDamageEvent evt) { + Entity e = evt.getEntity(); + if (e instanceof Player) { + Player p = (Player) e; + String pn = p.getName(); + if (plugin.Frozen.contains(pn)) { + evt.setCancelled(true); + } + } + } + +} diff --git a/src/me/travja/hungerarena/FreezeListener.java b/src/me/travja/hungerarena/FreezeListener.java new file mode 100644 index 0000000..1526b3e --- /dev/null +++ b/src/me/travja/hungerarena/FreezeListener.java @@ -0,0 +1,24 @@ +package me.travja.hungerarena; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; + +public class FreezeListener implements Listener { + public Main plugin; + public FreezeListener(Main m) { + this.plugin = m; + } + @EventHandler + public void onPlayerMove(PlayerMoveEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Frozen.contains(pname) && plugin.config.getString("Frozen_Teleport").equalsIgnoreCase("True")){ + Location from = event.getFrom(); + p.teleport(from, TeleportCause.ENDER_PEARL); + } + } +} diff --git a/src/me/travja/hungerarena/HaCommands.java b/src/me/travja/hungerarena/HaCommands.java new file mode 100644 index 0000000..42e353b --- /dev/null +++ b/src/me/travja/hungerarena/HaCommands.java @@ -0,0 +1,1402 @@ +package me.travja.hungerarena; + +import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class HaCommands implements CommandExecutor { + public Main plugin; + public HaCommands(Main m) { + this.plugin = m; + } + int i = 0; + @Override + public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, String[] args){ + String[] Spawncoords = plugin.config.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(); + ChatColor c = ChatColor.AQUA; + if(cmd.getName().equalsIgnoreCase("Ha")){ + if(args.length== 0){ + p.sendMessage(ChatColor.GREEN + "[HungerArena] by " + ChatColor.AQUA + "travja!"); + return false; + } + if(args[0].equalsIgnoreCase("Help")){ + p.sendMessage(ChatColor.GREEN + "----HungerArena Help----"); + p.sendMessage(c + "/ha - Displays author message!"); + sender.sendMessage(c + "/ha help - Displays this screen!"); + sender.sendMessage(c + "/ha join - Makes you join the game!"); + sender.sendMessage(c + "/ha ready - Votes for the game to start!"); + sender.sendMessage(c + "/ha leave - Makes you leave the game!"); + sender.sendMessage(c + "/ha watch - Lets you watch the tributes!"); + sender.sendMessage(c + "/sponsor [Player] [ItemID] [Amount] - Lets you sponsor someone!"); + sender.sendMessage(c + "/ha setspawn - Sets the spawn for dead tributes!"); + sender.sendMessage(c + "/ha kick [Player] - Kicks a player from the arena!"); + sender.sendMessage(c + "/ha restart - Makes it so dead tributes can join again!"); + sender.sendMessage(c + "/ha warpall - Warps all tribute into position!"); + sender.sendMessage(c + "/ha reload - Reloads the config!"); + sender.sendMessage(c + "/ha refill - Refills all chests!"); + sender.sendMessage(c + "/ha start - Unfreezes tributes allowing them to fight!"); + sender.sendMessage(c + "/ha list - Shows a list of players in the game and their health!"); + sender.sendMessage(c + "/ha rlist - See who's ready!"); + sender.sendMessage(c + "/startpoint [1,2,3,4,etc] - Sets the starting points of tributes!"); + sender.sendMessage(ChatColor.GREEN + "----------------------"); + return true; + }else if(args[0].equalsIgnoreCase("List")){ + if(p.hasPermission("HungerArena.GameMaker")){ + sender.sendMessage(ChatColor.AQUA + "-----People Playing-----"); + if(!plugin.Playing.isEmpty()){ + for(String playernames: plugin.Playing){ + Player players = plugin.getServer().getPlayerExact(playernames); + p.sendMessage(ChatColor.GREEN + playernames + " Life: " + players.getHealth() + "/20"); + return true; + } + }else if(plugin.Playing.isEmpty()){ + p.sendMessage(ChatColor.GRAY + "No one is playing!"); + } + p.sendMessage(ChatColor.AQUA + "----------------------"); + return true; + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + }else if(args[0].equalsIgnoreCase("rList")){ + if(p.hasPermission("HungerArena.GameMaker")){ + p.sendMessage(ChatColor.AQUA + "-----People Ready-----"); + if(!plugin.Ready.isEmpty()){ + for(String readyname: plugin.Ready){ + Player ready = plugin.getServer().getPlayerExact(readyname); + p.sendMessage(ChatColor.GREEN + readyname + " Life: " + ready.getHealth() + "/20"); + } + }else if(plugin.Ready.isEmpty()){ + p.sendMessage(ChatColor.GRAY + "No one is ready!"); + } + p.sendMessage(ChatColor.AQUA + "---------------------"); + return true; + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + }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.config.set("Spawn_coords", x + "," + y + "," + z + "," + w); + plugin.config.set("Spawns_set", "true"); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn for dead tributes!"); + return true; + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + }else if(args[0].equalsIgnoreCase("Join")){ + if(p.hasPermission("HungerArena.Join")){ + if(plugin.Playing.contains(pname)){ + p.sendMessage(ChatColor.RED + "You are already playing!"); + return true; + }else if(plugin.Dead.contains(pname) || plugin.Quit.contains(pname)){ + p.sendMessage(ChatColor.RED + "You DIED/QUIT! You can't join again!"); + return true; + }else if(plugin.Playing.size()== 24){ + p.sendMessage(ChatColor.RED + "There are already 24 Tributes!"); + return true; + }else if(plugin.canjoin== true){ + p.sendMessage(ChatColor.RED + "The game is in progress!"); + return true; + }else if(plugin.config.getString("Spawns_set").equalsIgnoreCase("false")){ + p.sendMessage(ChatColor.RED + "/ha setspawn hasn't been run!"); + return true; + }else if(plugin.NeedConfirm.contains(pname)){ + p.sendMessage(ChatColor.RED + "You need to do /ha confirm"); + return true; + }else if(plugin.config.getString("Need_Confirm").equalsIgnoreCase("true")){ + plugin.NeedConfirm.add(pname); + p.sendMessage(ChatColor.GOLD + "You're inventory will be cleared! Type /ha confirm to procede"); + return true; + }else{ + plugin.Playing.add(pname); + p.getInventory().clear(); + p.getInventory().setBoots(null); + p.getInventory().setChestplate(null); + p.getInventory().setHelmet(null); + p.getInventory().setLeggings(null); + plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined the Game!"); + if(plugin.Playing.size()== 24){ + p.performCommand("ha warpall"); + } + return true; + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + }else if(args[0].equalsIgnoreCase("Confirm")){ + if(plugin.NeedConfirm.contains(pname)){ + plugin.Playing.add(pname); + plugin.NeedConfirm.remove(pname); + p.sendMessage(ChatColor.GREEN + "Do /ha ready to vote to start the games!"); + p.getInventory().clear(); + p.getInventory().setBoots(null); + p.getInventory().setChestplate(null); + p.getInventory().setHelmet(null); + p.getInventory().setLeggings(null); + plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined the Game!"); + if(plugin.Playing.size()== 24){ + p.performCommand("ha warpall"); + } + return true; + } + }else if(args[0].equalsIgnoreCase("Ready")){ + if(plugin.Playing.contains(pname)){ + if(plugin.Ready.contains(pname)){ + p.sendMessage(ChatColor.RED + "You're already ready!"); + return true; + }else if(plugin.Playing.size()== 1){ + p.sendMessage(ChatColor.RED + "You can't be ready when no one else is playing!"); + return true; + }else{ + plugin.Ready.add(pname); + p.sendMessage(ChatColor.AQUA + "You have marked yourself as READY!"); + if(plugin.Playing.size()-4== plugin.Ready.size()){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha warpall"); + return true; + } + } + }else if(!plugin.Playing.contains(pname)){ + p.sendMessage(ChatColor.RED + "You aren't playing!"); + return true; + } + }else if(args[0].equalsIgnoreCase("Leave")){ + if(!plugin.Playing.contains(pname)){ + p.sendMessage(ChatColor.RED + "You aren't playing!"); + return true; + }else if(plugin.canjoin== false){ + plugin.Playing.remove(pname); + p.sendMessage(ChatColor.AQUA + "You have left the game!"); + p.getServer().broadcastMessage(ChatColor.RED + pname + " Quit!"); + p.getInventory().clear(); + p.teleport(Spawn); + p.getInventory().setBoots(null); + p.getInventory().setChestplate(null); + p.getInventory().setHelmet(null); + p.getInventory().setLeggings(null); + if(plugin.Frozen.contains(pname)){ + plugin.Frozen.remove(pname); + } + return true; + }else{ + plugin.Playing.remove(pname); + plugin.Quit.add(pname); + p.sendMessage(ChatColor.AQUA + "You have left the game!"); + p.getServer().broadcastMessage(ChatColor.RED + pname + " Quit!"); + p.getInventory().clear(); + p.getInventory().setBoots(null); + p.getInventory().setChestplate(null); + p.getInventory().setHelmet(null); + p.getInventory().setLeggings(null); + p.teleport(Spawn); + if(plugin.Frozen.contains(pname)){ + plugin.Frozen.remove(pname); + } + if(plugin.Playing.size()== 1){ + //Announce the Winner + String winnername = plugin.Playing.get(i++); + Player winner = plugin.getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + plugin.getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.teleport(Spawn); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.getInventory().addItem(plugin.Reward); + Bukkit.getServer().getPluginManager().callEvent(new PlayerWinGamesEvent(winner)); + plugin.Playing.clear(); + //Show spectators + String s = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart"); + } + } + return true; + } + }else if(args[0].equalsIgnoreCase("Watch")){ + if(sender.hasPermission("HungerArena.Watch")){ + if(!plugin.Watching.contains(pname) && !plugin.Playing.contains(pname) && plugin.canjoin== true){ + plugin.Watching.add(pname); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.hidePlayer(p); + } + p.setAllowFlight(true); + p.sendMessage(ChatColor.AQUA + "You can now spectate!"); + return true; + }else if(plugin.canjoin== false){ + p.sendMessage(ChatColor.RED + "The game isn't in progress!"); + return true; + }else if(plugin.Playing.contains(pname)){ + p.sendMessage(ChatColor.RED + "You can't watch while you're playing!"); + return true; + }else if(plugin.Watching.contains(pname)){ + plugin.Watching.remove(pname); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(p); + } + p.teleport(Spawn); + p.setAllowFlight(false); + p.sendMessage(ChatColor.AQUA + "You are not spectating any more"); + return true; + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + return true; + } + }else if(args[0].equalsIgnoreCase("Kick")){ + if (args.length != 2) { + return false; + } + Player target = plugin.getServer().getPlayer(args[1]); + if(sender.hasPermission("HungerArena.Kick")){ + if(plugin.Playing.contains(target.getName())){ + plugin.Playing.remove(target.getName()); + plugin.getServer().broadcastMessage(ChatColor.RED + target.getName() + " was kicked from the game!"); + target.teleport(Spawn); + target.getInventory().clear(); + target.getInventory().setBoots(null); + target.getInventory().setChestplate(null); + target.getInventory().setHelmet(null); + target.getInventory().setLeggings(null); + plugin.Quit.add(target.getName()); + if(plugin.Playing.size()== 1 && plugin.canjoin== true){ + String winnername = plugin.Playing.get(i++); + Player winner = plugin.getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + plugin.getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.teleport(Spawn); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.getInventory().addItem(plugin.Reward); + Bukkit.getServer().getPluginManager().callEvent(new PlayerWinGamesEvent(winner)); + plugin.Playing.clear(); + if(!plugin.Watching.isEmpty()){ + String s = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart"); + } + } + }else{ + sender.sendMessage(ChatColor.RED + "That player isn't in the game!"); + } + }else{ + sender.sendMessage(ChatColor.RED + "You don't have permission!"); + } + }else if(args[0].equalsIgnoreCase("Refill")){ + if(p.hasPermission("HungerArena.Refill")){ + int list056; + list056 = 0; + int limit = plugin.config.getStringList("StorageXYZ").size(); + while(limit > list056){ + String xyz2 = plugin.getConfig().getStringList("StorageXYZ").get(list056); + int chestx = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.X"); + int chesty = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Y"); + int chestz = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Z"); + String chestw = plugin.getConfig().getString("Storage." + xyz2 + ".Location.W"); + Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz); + plugin.exists = false; + if(blockatlocation.getState() instanceof Chest){ + plugin.exists = true; + Chest chest = (Chest) blockatlocation.getState(); + chest.getInventory().clear(); + ItemStack[] itemsinchest = null; + Object o = plugin.getConfig().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); + } + } + if(limit== list056){ + sender.sendMessage(ChatColor.GREEN + "All chests refilled!"); + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + }else if(args[0].equalsIgnoreCase("Restart")){ + if(p.hasPermission("HungerArena.Restart")){ + if(!plugin.Watching.isEmpty()){ + String s = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + plugin.Dead.clear(); + plugin.Quit.clear(); + plugin.Watching.clear(); + plugin.Frozen.clear(); + plugin.Ready.clear(); + plugin.NeedConfirm.clear(); + plugin.Out.clear(); + plugin.Playing.clear(); + plugin.canjoin = false; + p.performCommand("ha refill"); + p.sendMessage(ChatColor.AQUA + "The games have been reset!"); + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + }else if(args[0].equalsIgnoreCase("Reload")){ + plugin.reloadConfig(); + p.sendMessage(ChatColor.AQUA + "HungerArena Reloaded!"); + }else if(args[0].equalsIgnoreCase("WarpAll")){ + if(p.hasPermission("HungerArena.Warpall")){ + if(plugin.config.getString("Spawns_set").equalsIgnoreCase("false")){ + sender.sendMessage(ChatColor.RED + "/ha setspawn hasn't been run!"); + }else{ + if(plugin.Playing.size()== 1){ + sender.sendMessage(ChatColor.RED + "There are not enough players!"); + } + if(plugin.Playing.size()>= 2){ + plugin.config.getString("Tribute_one_spawn"); + String[] onecoords = plugin.config.getString("Tribute_one_spawn").split(","); + Player Tribute_one = plugin.getServer().getPlayerExact(plugin.Playing.get(0)); + double x = Double.parseDouble(onecoords[0]); + double y = Double.parseDouble(onecoords[1]); + double z = Double.parseDouble(onecoords[2]); + String world = onecoords[3]; + World w = plugin.getServer().getWorld(world); + Location oneloc = new Location(w, x, y, z); + Tribute_one.teleport(oneloc); + plugin.Frozen.add(Tribute_one.getName()); + Tribute_one.setFoodLevel(20); + plugin.config.getString("Tribute_two_spawn"); + String[] twocoords = plugin.config.getString("Tribute_two_spawn").split(","); + Player Tribute_two = plugin.getServer().getPlayerExact(plugin.Playing.get(1)); + double twox = Double.parseDouble(twocoords[0]); + double twoy = Double.parseDouble(twocoords[1]); + double twoz = Double.parseDouble(twocoords[2]); + String twoworld = twocoords[3]; + World twow = plugin.getServer().getWorld(twoworld); + Location twoloc = new Location(twow, twox, twoy, twoz); + Tribute_two.teleport(twoloc); + plugin.Frozen.add(Tribute_two.getName()); + Tribute_two.setFoodLevel(20); + p.getWorld().setTime(0); + 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"); + } + }, 20L); + } + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + p.sendMessage(ChatColor.AQUA + "All Tributes warped!"); + } + }, 20L); + } + if(plugin.Playing.size()>= 3){ + plugin.config.getString("Tribute_three_spawn"); + String[] coords = plugin.config.getString("Tribute_three_spawn").split(","); + Player Tribute_three = plugin.getServer().getPlayerExact(plugin.Playing.get(2)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_three.teleport(loc); + plugin.Frozen.add(Tribute_three.getName()); + Tribute_three.setFoodLevel(20); + } + if(plugin.Playing.size()>= 4){ + plugin.config.getString("Tribute_four_spawn"); + String[] coords = plugin.config.getString("Tribute_four_spawn").split(","); + Player Tribute_four = plugin.getServer().getPlayerExact(plugin.Playing.get(3)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_four.teleport(loc); + plugin.Frozen.add(Tribute_four.getName()); + Tribute_four.setFoodLevel(20); + } + if(plugin.Playing.size()>= 5){ + plugin.config.getString("Tribute_five_spawn"); + String[] coords = plugin.config.getString("Tribute_five_spawn").split(","); + Player Tribute_five = plugin.getServer().getPlayerExact(plugin.Playing.get(4)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_five.teleport(loc); + plugin.Frozen.add(Tribute_five.getName()); + Tribute_five.setFoodLevel(20); + } + if(plugin.Playing.size()>= 6){ + plugin.config.getString("Tribute_six_spawn"); + String[] coords = plugin.config.getString("Tribute_six_spawn").split(","); + Player Tribute_six = plugin.getServer().getPlayerExact(plugin.Playing.get(5)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_six.teleport(loc); + plugin.Frozen.add(Tribute_six.getName()); + Tribute_six.setFoodLevel(20); + } + if(plugin.Playing.size()>= 7){ + plugin.config.getString("Tribute_seven_spawn"); + String[] coords = plugin.config.getString("Tribute_seven_spawn").split(","); + Player Tribute_seven = plugin.getServer().getPlayerExact(plugin.Playing.get(6)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_seven.teleport(loc); + plugin.Frozen.add(Tribute_seven.getName()); + Tribute_seven.setFoodLevel(20); + } + if(plugin.Playing.size()>= 8){ + plugin.config.getString("Tribute_eight_spawn"); + String[] coords = plugin.config.getString("Tribute_eight_spawn").split(","); + Player Tribute_eight = plugin.getServer().getPlayerExact(plugin.Playing.get(7)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_eight.teleport(loc); + plugin.Frozen.add(Tribute_eight.getName()); + Tribute_eight.setFoodLevel(20); + } + if(plugin.Playing.size()>= 9){ + plugin.config.getString("Tribute_nine_spawn"); + String[] coords = plugin.config.getString("Tribute_nine_spawn").split(","); + Player Tribute_nine = plugin.getServer().getPlayerExact(plugin.Playing.get(8)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_nine.teleport(loc); + plugin.Frozen.add(Tribute_nine.getName()); + Tribute_nine.setFoodLevel(20); + } + if(plugin.Playing.size()>= 10){ + plugin.config.getString("Tribute_ten_spawn"); + String[] coords = plugin.config.getString("Tribute_ten_spawn").split(","); + Player Tribute_ten = plugin.getServer().getPlayerExact(plugin.Playing.get(9)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_ten.teleport(loc); + plugin.Frozen.add(Tribute_ten.getName()); + Tribute_ten.setFoodLevel(20); + } + if(plugin.Playing.size()>= 11){ + plugin.config.getString("Tribute_eleven_spawn"); + String[] coords = plugin.config.getString("Tribute_eleven_spawn").split(","); + Player Tribute_eleven = plugin.getServer().getPlayerExact(plugin.Playing.get(10)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_eleven.teleport(loc); + plugin.Frozen.add(Tribute_eleven.getName()); + Tribute_eleven.setFoodLevel(20); + } + if(plugin.Playing.size()>= 12){ + plugin.config.getString("Tribute_twelve_spawn"); + String[] coords = plugin.config.getString("Tribute_twelve_spawn").split(","); + Player Tribute_twelve = plugin.getServer().getPlayerExact(plugin.Playing.get(11)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twelve.teleport(loc); + plugin.Frozen.add(Tribute_twelve.getName()); + Tribute_twelve.setFoodLevel(20); + } + if(plugin.Playing.size()>= 13){ + plugin.config.getString("Tribute_thirteen_spawn"); + String[] coords = plugin.config.getString("Tribute_thirteen_spawn").split(","); + Player Tribute_thirteen = plugin.getServer().getPlayerExact(plugin.Playing.get(12)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_thirteen.teleport(loc); + plugin.Frozen.add(Tribute_thirteen.getName()); + Tribute_thirteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 14){ + plugin.config.getString("Tribute_fourteen_spawn"); + String[] coords = plugin.config.getString("Tribute_fourteen_spawn").split(","); + Player Tribute_fourteen = plugin.getServer().getPlayerExact(plugin.Playing.get(13)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_fourteen.teleport(loc); + plugin.Frozen.add(Tribute_fourteen.getName()); + Tribute_fourteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 15){ + plugin.config.getString("Tribute_fifteen_spawn"); + String[] coords = plugin.config.getString("Tribute_fifteen_spawn").split(","); + Player Tribute_fifteen = plugin.getServer().getPlayerExact(plugin.Playing.get(14)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_fifteen.teleport(loc); + plugin.Frozen.add(Tribute_fifteen.getName()); + Tribute_fifteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 16){ + plugin.config.getString("Tribute_sixteen_spawn"); + String[] coords = plugin.config.getString("Tribute_sixteen_spawn").split(","); + Player Tribute_sixteen = plugin.getServer().getPlayerExact(plugin.Playing.get(15)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_sixteen.teleport(loc); + plugin.Frozen.add(Tribute_sixteen.getName()); + Tribute_sixteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 17){ + plugin.config.getString("Tribute_seventeen_spawn"); + String[] coords = plugin.config.getString("Tribute_seventeen_spawn").split(","); + Player Tribute_seventeen = plugin.getServer().getPlayerExact(plugin.Playing.get(16)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_seventeen.teleport(loc); + plugin.Frozen.add(Tribute_seventeen.getName()); + Tribute_seventeen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 18){ + plugin.config.getString("Tribute_eighteen_spawn"); + String[] coords = plugin.config.getString("Tribute_eighteen_spawn").split(","); + Player Tribute_eighteen = plugin.getServer().getPlayerExact(plugin.Playing.get(17)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_eighteen.teleport(loc); + plugin.Frozen.add(Tribute_eighteen.getName()); + Tribute_eighteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 19){ + plugin.config.getString("Tribute_nineteen_spawn"); + String[] coords = plugin.config.getString("Tribute_nineteen_spawn").split(","); + Player Tribute_nineteen = plugin.getServer().getPlayerExact(plugin.Playing.get(18)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_nineteen.teleport(loc); + plugin.Frozen.add(Tribute_nineteen.getName()); + Tribute_nineteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 20){ + plugin.config.getString("Tribute_twenty_spawn"); + String[] coords = plugin.config.getString("Tribute_twenty_spawn").split(","); + Player Tribute_twenty = plugin.getServer().getPlayerExact(plugin.Playing.get(19)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twenty.teleport(loc); + plugin.Frozen.add(Tribute_twenty.getName()); + Tribute_twenty.setFoodLevel(20); + } + if(plugin.Playing.size()>= 21){ + plugin.config.getString("Tribute_twentyone_spawn"); + String[] coords = plugin.config.getString("Tribute_twentyone_spawn").split(","); + Player Tribute_twentyone = plugin.getServer().getPlayerExact(plugin.Playing.get(20)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twentyone.teleport(loc); + plugin.Frozen.add(Tribute_twentyone.getName()); + Tribute_twentyone.setFoodLevel(20); + } + if(plugin.Playing.size()>= 22){ + plugin.config.getString("Tribute_twentytwo_spawn"); + String[] coords = plugin.config.getString("Tribute_twentytwo_spawn").split(","); + Player Tribute_twentytwo = plugin.getServer().getPlayerExact(plugin.Playing.get(21)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twentytwo.teleport(loc); + plugin.Frozen.add(Tribute_twentytwo.getName()); + Tribute_twentytwo.setFoodLevel(20); + } + if(plugin.Playing.size()>= 23){ + plugin.config.getString("Tribute_twentythree_spawn"); + String[] coords = plugin.config.getString("Tribute_twentythree_spawn").split(","); + Player Tribute_twentythree = plugin.getServer().getPlayerExact(plugin.Playing.get(22)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twentythree.teleport(loc); + plugin.Frozen.add(Tribute_twentythree.getName()); + Tribute_twentythree.setFoodLevel(20); + } + if(plugin.Playing.size()>= 24){ + plugin.config.getString("Tribute_twentyfour_spawn"); + String[] coords = plugin.config.getString("Tribute_twentyfour_spawn").split(","); + Player Tribute_twentyfour = plugin.getServer().getPlayerExact(plugin.Playing.get(23)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twentyfour.teleport(loc); + plugin.Frozen.add(Tribute_twentyfour.getName()); + Tribute_twentyfour.setFoodLevel(20); + } + } + } + }else if(args[0].equalsIgnoreCase("Start")){ + String begin = plugin.config.getString("Start_Message"); + begin = begin.replaceAll("(&([a-f0-9]))", "\u00A7$2"); + final String msg = begin; + if(p.hasPermission("HungerArena.Start")){ + if(plugin.config.getString("Countdown").equalsIgnoreCase("true")){ + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("10"); + } + }, 20L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("9"); + } + }, 40L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("8"); + } + }, 60L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("7"); + } + }, 80L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("6"); + } + }, 100L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("5"); + } + }, 120L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("4"); + } + }, 140L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("3"); + } + }, 160L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("2"); + } + }, 180L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("1"); + } + }, 200L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.Frozen.clear(); + plugin.getServer().broadcastMessage(msg); + plugin.canjoin = true; + } + }, 220L); + }else{ + plugin.Frozen.clear(); + p.getServer().broadcastMessage(msg); + plugin.canjoin = true; + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + }else{ + p.sendMessage(ChatColor.RED + "Unknown command, type /ha help for a list of commands"); + } + } + }else if(sender instanceof ConsoleCommandSender){ + if(cmd.getName().equalsIgnoreCase("Ha")){ + if(args.length== 0){ + sender.sendMessage(ChatColor.GREEN + "[HungerArena] by " + ChatColor.AQUA + "travja!"); + return false; + } + if(args[0].equalsIgnoreCase("Help")){ + ChatColor c = ChatColor.AQUA; + sender.sendMessage(ChatColor.GREEN + "----HungerArena Help----"); + sender.sendMessage(c + "/ha - Displays author message!"); + sender.sendMessage(c + "/ha help - Displays this screen!"); + sender.sendMessage(c + "/ha join - Makes you join the game!"); + sender.sendMessage(c + "/ha ready - Votes for the game to start!"); + sender.sendMessage(c + "/ha leave - Makes you leave the game!"); + sender.sendMessage(c + "/ha watch - Lets you watch the tributes!"); + sender.sendMessage(c + "/sponsor [Player] [ItemID] [Amount] - Lets you sponsor someone!"); + sender.sendMessage(c + "/ha setspawn - Sets the spawn for dead tributes!"); + sender.sendMessage(c + "/ha kick [Player] - Kicks a player from the arena!"); + sender.sendMessage(c + "/ha restart - Makes it so dead tributes can join again!"); + sender.sendMessage(c + "/ha warpall - Warps all tribute into position!"); + sender.sendMessage(c + "/ha reload - Reloads the config!"); + sender.sendMessage(c + "/ha refill - Refills all chests!"); + sender.sendMessage(c + "/ha start - Unfreezes tributes allowing them to fight!"); + sender.sendMessage(c + "/ha list - Shows a list of players in the game and their health!"); + sender.sendMessage(c + "/ha rlist - See who's ready!"); + sender.sendMessage(c + "/startpoint [1,2,3,4,etc] - Sets the starting points of tributes!"); + sender.sendMessage(ChatColor.GREEN + "----------------------"); + return false; + }else if(args[0].equalsIgnoreCase("List")){ + sender.sendMessage(ChatColor.AQUA + "-----People Playing-----"); + if(!plugin.Playing.isEmpty()){ + for(String playernames: plugin.Playing){ + Player players = plugin.getServer().getPlayerExact(playernames); + sender.sendMessage(ChatColor.GREEN + players.getName() + " Life: " + players.getHealth() + "/20"); + } + }else if(plugin.Playing.isEmpty()){ + sender.sendMessage(ChatColor.GRAY + "No one is playing!"); + } + sender.sendMessage(ChatColor.AQUA + "----------------------"); + }else if(args[0].equalsIgnoreCase("rList")){ + sender.sendMessage(ChatColor.AQUA + "-----People Ready-----"); + if(!plugin.Ready.isEmpty()){ + for(String readyname: plugin.Ready){ + Player ready = plugin.getServer().getPlayerExact(readyname); + sender.sendMessage(ChatColor.GREEN + readyname + " Life: " + ready.getHealth() + "/20"); + } + }else if(plugin.Ready.isEmpty()){ + sender.sendMessage(ChatColor.GRAY + "No one is ready!"); + } + sender.sendMessage(ChatColor.AQUA + "---------------------"); + }else if(args[0].equalsIgnoreCase("SetSpawn") || args[0].equalsIgnoreCase("Join") || args[0].equalsIgnoreCase("Confirm") || args[0].equalsIgnoreCase("Ready") || args[0].equalsIgnoreCase("Leave") || args[0].equalsIgnoreCase("Watch")){ + sender.sendMessage(ChatColor.RED + "That can only be run by a player!"); + }else if(args[0].equalsIgnoreCase("Kick")){ + Player target = plugin.getServer().getPlayer(args[1]); + if(plugin.Playing.contains(target.getName())){ + plugin.Playing.remove(target.getName()); + plugin.getServer().broadcastMessage(ChatColor.RED + target.getName() + " was kicked from the game!"); + target.teleport(Spawn); + target.getInventory().clear(); + target.getInventory().setBoots(null); + target.getInventory().setChestplate(null); + target.getInventory().setHelmet(null); + target.getInventory().setLeggings(null); + plugin.Quit.add(target.getName()); + if(plugin.Playing.size()== 1 && plugin.canjoin== true){ + //Announce winner + String winnername = plugin.Playing.get(i++); + Player winner = plugin.getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + plugin.getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.teleport(Spawn); + winner.getInventory().setBoots(null); + winner.getInventory().setChestplate(null); + winner.getInventory().setHelmet(null); + winner.getInventory().setLeggings(null); + winner.getInventory().addItem(plugin.Reward); + Bukkit.getServer().getPluginManager().callEvent(new PlayerWinGamesEvent(winner)); + plugin.Playing.clear(); + //Make spectators visible + if(!plugin.Watching.isEmpty()){ + String s = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart"); + } + } + }else{ + sender.sendMessage(ChatColor.RED + "That player isn't in the game!"); + } + }else if(args[0].equalsIgnoreCase("Refill")){ + int list056; + list056 = 0; + int limit = plugin.getConfig().getStringList("StorageXYZ").size(); + while(limit > list056){ + String xyz2 = plugin.getConfig().getStringList("StorageXYZ").get(list056); + int chestx = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.X"); + int chesty = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Y"); + int chestz = plugin.getConfig().getInt("Storage." + xyz2 + ".Location.Z"); + String chestw = plugin.getConfig().getString("Storage." + xyz2 + ".Location.W"); + Block blockatlocation = Bukkit.getWorld(chestw).getBlockAt(chestx, chesty, chestz); + plugin.exists = false; + if(blockatlocation.getState() instanceof Chest){ + plugin.exists = true; + Chest chest = (Chest) blockatlocation.getState(); + chest.getInventory().clear(); + ItemStack[] itemsinchest = null; + Object o = plugin.getConfig().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); + } + } + if(limit== list056){ + sender.sendMessage(ChatColor.GREEN + "All chests refilled!"); + } + }else if(args[0].equalsIgnoreCase("Restart")){ + if(!plugin.Watching.isEmpty()){ + String s = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + plugin.Dead.clear(); + plugin.Quit.clear(); + plugin.Watching.clear(); + plugin.Frozen.clear(); + plugin.Ready.clear(); + plugin.NeedConfirm.clear(); + plugin.Out.clear(); + plugin.Playing.clear(); + plugin.canjoin = false; + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha refill"); + sender.sendMessage(ChatColor.AQUA + "The games have been reset!"); + }else if(args[0].equalsIgnoreCase("Reload")){ + plugin.reloadConfig(); + sender.sendMessage(ChatColor.AQUA + "HungerArena Reloaded!"); + }else if(args[0].equalsIgnoreCase("WarpAll")){ + if(plugin.config.getString("Spawns_set").equalsIgnoreCase("false")){ + sender.sendMessage(ChatColor.RED + "/ha setspawn hasn't been run!"); + }else{ + if(plugin.Playing.size()<= 1){ + sender.sendMessage(ChatColor.RED + "There are not enough players!"); + } + if(plugin.Playing.size()>= 2){ + plugin.config.getString("Tribute_one_spawn"); + String[] onecoords = plugin.config.getString("Tribute_one_spawn").split(","); + Player Tribute_one = plugin.getServer().getPlayerExact(plugin.Playing.get(0)); + double x = Double.parseDouble(onecoords[0]); + double y = Double.parseDouble(onecoords[1]); + double z = Double.parseDouble(onecoords[2]); + String world = onecoords[3]; + World w = plugin.getServer().getWorld(world); + Location oneloc = new Location(w, x, y, z); + Tribute_one.teleport(oneloc); + plugin.Frozen.add(Tribute_one.getName()); + Tribute_one.setFoodLevel(20); + plugin.config.getString("Tribute_two_spawn"); + String[] twocoords = plugin.config.getString("Tribute_two_spawn").split(","); + Player Tribute_two = plugin.getServer().getPlayerExact(plugin.Playing.get(1)); + double twox = Double.parseDouble(twocoords[0]); + double twoy = Double.parseDouble(twocoords[1]); + double twoz = Double.parseDouble(twocoords[2]); + String twoworld = twocoords[3]; + World twow = plugin.getServer().getWorld(twoworld); + Location twoloc = new Location(twow, twox, twoy, twoz); + Tribute_two.teleport(twoloc); + plugin.Frozen.add(Tribute_two.getName()); + Tribute_two.setFoodLevel(20); + Tribute_one.getWorld().setTime(0); + 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"); + } + }, 20L); + } + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + sender.sendMessage(ChatColor.AQUA + "All Tributes warped!"); + } + }, 20L); + } + if(plugin.Playing.size()>= 3){ + plugin.config.getString("Tribute_three_spawn"); + String[] coords = plugin.config.getString("Tribute_three_spawn").split(","); + Player Tribute_three = plugin.getServer().getPlayerExact(plugin.Playing.get(2)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_three.teleport(loc); + plugin.Frozen.add(Tribute_three.getName()); + Tribute_three.setFoodLevel(20); + } + if(plugin.Playing.size()>= 4){ + plugin.config.getString("Tribute_four_spawn"); + String[] coords = plugin.config.getString("Tribute_four_spawn").split(","); + Player Tribute_four = plugin.getServer().getPlayerExact(plugin.Playing.get(3)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_four.teleport(loc); + plugin.Frozen.add(Tribute_four.getName()); + Tribute_four.setFoodLevel(20); + } + if(plugin.Playing.size()>= 5){ + plugin.config.getString("Tribute_five_spawn"); + String[] coords = plugin.config.getString("Tribute_five_spawn").split(","); + Player Tribute_five = plugin.getServer().getPlayerExact(plugin.Playing.get(4)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_five.teleport(loc); + plugin.Frozen.add(Tribute_five.getName()); + Tribute_five.setFoodLevel(20); + } + if(plugin.Playing.size()>= 6){ + plugin.config.getString("Tribute_six_spawn"); + String[] coords = plugin.config.getString("Tribute_six_spawn").split(","); + Player Tribute_six = plugin.getServer().getPlayerExact(plugin.Playing.get(5)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_six.teleport(loc); + plugin.Frozen.add(Tribute_six.getName()); + Tribute_six.setFoodLevel(20); + } + if(plugin.Playing.size()>= 7){ + plugin.config.getString("Tribute_seven_spawn"); + String[] coords = plugin.config.getString("Tribute_seven_spawn").split(","); + Player Tribute_seven = plugin.getServer().getPlayerExact(plugin.Playing.get(6)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_seven.teleport(loc); + plugin.Frozen.add(Tribute_seven.getName()); + Tribute_seven.setFoodLevel(20); + } + if(plugin.Playing.size()>= 8){ + plugin.config.getString("Tribute_eight_spawn"); + String[] coords = plugin.config.getString("Tribute_eight_spawn").split(","); + Player Tribute_eight = plugin.getServer().getPlayerExact(plugin.Playing.get(7)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_eight.teleport(loc); + plugin.Frozen.add(Tribute_eight.getName()); + Tribute_eight.setFoodLevel(20); + } + if(plugin.Playing.size()>= 9){ + plugin.config.getString("Tribute_nine_spawn"); + String[] coords = plugin.config.getString("Tribute_nine_spawn").split(","); + Player Tribute_nine = plugin.getServer().getPlayerExact(plugin.Playing.get(8)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_nine.teleport(loc); + plugin.Frozen.add(Tribute_nine.getName()); + Tribute_nine.setFoodLevel(20); + } + if(plugin.Playing.size()>= 10){ + plugin.config.getString("Tribute_ten_spawn"); + String[] coords = plugin.config.getString("Tribute_ten_spawn").split(","); + Player Tribute_ten = plugin.getServer().getPlayerExact(plugin.Playing.get(9)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_ten.teleport(loc); + plugin.Frozen.add(Tribute_ten.getName()); + Tribute_ten.setFoodLevel(20); + } + if(plugin.Playing.size()>= 11){ + plugin.config.getString("Tribute_eleven_spawn"); + String[] coords = plugin.config.getString("Tribute_eleven_spawn").split(","); + Player Tribute_eleven = plugin.getServer().getPlayerExact(plugin.Playing.get(10)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_eleven.teleport(loc); + plugin.Frozen.add(Tribute_eleven.getName()); + Tribute_eleven.setFoodLevel(20); + } + if(plugin.Playing.size()>= 12){ + plugin.config.getString("Tribute_twelve_spawn"); + String[] coords = plugin.config.getString("Tribute_twelve_spawn").split(","); + Player Tribute_twelve = plugin.getServer().getPlayerExact(plugin.Playing.get(11)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twelve.teleport(loc); + plugin.Frozen.add(Tribute_twelve.getName()); + Tribute_twelve.setFoodLevel(20); + } + if(plugin.Playing.size()>= 13){ + plugin.config.getString("Tribute_thirteen_spawn"); + String[] coords = plugin.config.getString("Tribute_thirteen_spawn").split(","); + Player Tribute_thirteen = plugin.getServer().getPlayerExact(plugin.Playing.get(12)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_thirteen.teleport(loc); + plugin.Frozen.add(Tribute_thirteen.getName()); + Tribute_thirteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 14){ + plugin.config.getString("Tribute_fourteen_spawn"); + String[] coords = plugin.config.getString("Tribute_fourteen_spawn").split(","); + Player Tribute_fourteen = plugin.getServer().getPlayerExact(plugin.Playing.get(13)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_fourteen.teleport(loc); + plugin.Frozen.add(Tribute_fourteen.getName()); + Tribute_fourteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 15){ + plugin.config.getString("Tribute_fifteen_spawn"); + String[] coords = plugin.config.getString("Tribute_fifteen_spawn").split(","); + Player Tribute_fifteen = plugin.getServer().getPlayerExact(plugin.Playing.get(14)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_fifteen.teleport(loc); + plugin.Frozen.add(Tribute_fifteen.getName()); + Tribute_fifteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 16){ + plugin.config.getString("Tribute_sixteen_spawn"); + String[] coords = plugin.config.getString("Tribute_sixteen_spawn").split(","); + Player Tribute_sixteen = plugin.getServer().getPlayerExact(plugin.Playing.get(15)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_sixteen.teleport(loc); + plugin.Frozen.add(Tribute_sixteen.getName()); + Tribute_sixteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 17){ + plugin.config.getString("Tribute_seventeen_spawn"); + String[] coords = plugin.config.getString("Tribute_seventeen_spawn").split(","); + Player Tribute_seventeen = plugin.getServer().getPlayerExact(plugin.Playing.get(16)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_seventeen.teleport(loc); + plugin.Frozen.add(Tribute_seventeen.getName()); + Tribute_seventeen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 18){ + plugin.config.getString("Tribute_eighteen_spawn"); + String[] coords = plugin.config.getString("Tribute_eighteen_spawn").split(","); + Player Tribute_eighteen = plugin.getServer().getPlayerExact(plugin.Playing.get(17)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_eighteen.teleport(loc); + plugin.Frozen.add(Tribute_eighteen.getName()); + Tribute_eighteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 19){ + plugin.config.getString("Tribute_nineteen_spawn"); + String[] coords = plugin.config.getString("Tribute_nineteen_spawn").split(","); + Player Tribute_nineteen = plugin.getServer().getPlayerExact(plugin.Playing.get(18)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_nineteen.teleport(loc); + plugin.Frozen.add(Tribute_nineteen.getName()); + Tribute_nineteen.setFoodLevel(20); + } + if(plugin.Playing.size()>= 20){ + plugin.config.getString("Tribute_twenty_spawn"); + String[] coords = plugin.config.getString("Tribute_twenty_spawn").split(","); + Player Tribute_twenty = plugin.getServer().getPlayerExact(plugin.Playing.get(19)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twenty.teleport(loc); + plugin.Frozen.add(Tribute_twenty.getName()); + Tribute_twenty.setFoodLevel(20); + } + if(plugin.Playing.size()>= 21){ + plugin.config.getString("Tribute_twentyone_spawn"); + String[] coords = plugin.config.getString("Tribute_twentyone_spawn").split(","); + Player Tribute_twentyone = plugin.getServer().getPlayerExact(plugin.Playing.get(20)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twentyone.teleport(loc); + plugin.Frozen.add(Tribute_twentyone.getName()); + Tribute_twentyone.setFoodLevel(20); + } + if(plugin.Playing.size()>= 22){ + plugin.config.getString("Tribute_twentytwo_spawn"); + String[] coords = plugin.config.getString("Tribute_twentytwo_spawn").split(","); + Player Tribute_twentytwo = plugin.getServer().getPlayerExact(plugin.Playing.get(21)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twentytwo.teleport(loc); + plugin.Frozen.add(Tribute_twentytwo.getName()); + Tribute_twentytwo.setFoodLevel(20); + } + if(plugin.Playing.size()>= 23){ + plugin.config.getString("Tribute_twentythree_spawn"); + String[] coords = plugin.config.getString("Tribute_twentythree_spawn").split(","); + Player Tribute_twentythree = plugin.getServer().getPlayerExact(plugin.Playing.get(22)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twentythree.teleport(loc); + plugin.Frozen.add(Tribute_twentythree.getName()); + Tribute_twentythree.setFoodLevel(20); + } + if(plugin.Playing.size()>= 24){ + plugin.config.getString("Tribute_twentyfour_spawn"); + String[] coords = plugin.config.getString("Tribute_twentyfour_spawn").split(","); + Player Tribute_twentyfour = plugin.getServer().getPlayerExact(plugin.Playing.get(23)); + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + String world = coords[3]; + World w = plugin.getServer().getWorld(world); + Location loc = new Location(w, x, y, z); + Tribute_twentyfour.teleport(loc); + plugin.Frozen.add(Tribute_twentyfour.getName()); + Tribute_twentyfour.setFoodLevel(20); + } + } + }else if(args[0].equalsIgnoreCase("Start")){ + String begin = plugin.config.getString("Start_Message"); + begin = begin.replaceAll("(&([a-f0-9]))", "\u00A7$2"); + final String msg = begin; + if(plugin.config.getString("Countdown").equalsIgnoreCase("true")){ + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("10"); + } + }, 20L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("9"); + } + }, 40L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("8"); + } + }, 60L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("7"); + } + }, 80L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("6"); + } + }, 100L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("5"); + } + }, 120L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("4"); + } + }, 140L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("3"); + } + }, 160L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("2"); + } + }, 180L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.getServer().broadcastMessage("1"); + } + }, 200L); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + plugin.Frozen.clear(); + plugin.getServer().broadcastMessage(msg); + plugin.canjoin = true; + } + }, 220L); + }else{ + plugin.Frozen.clear(); + plugin.getServer().broadcastMessage(msg); + plugin.canjoin = true; + } + }else{ + sender.sendMessage(ChatColor.RED + "Unknown command, type /ha help to see all commands!"); + } + } + } + return false; + } +} diff --git a/src/me/travja/hungerarena/JoinAndQuitListener.java b/src/me/travja/hungerarena/JoinAndQuitListener.java new file mode 100644 index 0000000..4e7af97 --- /dev/null +++ b/src/me/travja/hungerarena/JoinAndQuitListener.java @@ -0,0 +1,137 @@ +package me.travja.hungerarena; + +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.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class JoinAndQuitListener implements Listener { + public Main plugin; + public JoinAndQuitListener(Main m) { + this.plugin = m; + } + int i = 0; + + @EventHandler + public void onJoin(PlayerJoinEvent evt) { + Player p = evt.getPlayer(); + for (String s : plugin.Watching) { + Player spectator = Bukkit.getServer().getPlayerExact(s); + p.hidePlayer(spectator); + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event){ + final Player p = event.getPlayer(); + String pname = p.getName(); + if(!plugin.Watching.isEmpty()){ + String s = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s); + p.hidePlayer(spectator); + } + if(plugin.Out.contains(pname)){ + plugin.Playing.add(pname); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + p.sendMessage(ChatColor.AQUA + "You have saved yourself from being ejected from the arena!"); + } + }, 40L); + plugin.Out.remove(pname); + } + if(plugin.Quit.contains(pname) || plugin.Dead.contains(pname)){ + String[] Spawncoords = plugin.config.getString("Spawn_coords").split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + p.teleport(Spawn); + p.sendMessage(ChatColor.RED + "You have been teleported to spawn because you quit/forfeited!"); + } + }, 40L); + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent evt) { + Player p = evt.getPlayer(); + String pname = p.getName(); + if (plugin.Frozen.contains(pname)) { + plugin.Frozen.remove(pname); + String[] Spawncoords = plugin.config.getString("Spawn_coords").split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + p.teleport(Spawn); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event){ + final Player p = event.getPlayer(); + final String pname = p.getName(); + String[] Spawncoords = plugin.config.getString("Spawn_coords").split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + if(plugin.Playing.contains(pname)){ + plugin.Out.add(pname); + plugin.Playing.remove(pname); + } + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + if(plugin.Out.contains(pname)){ + if(plugin.canjoin== true){ + plugin.Quit.add(pname); + plugin.Out.remove(pname); + if(plugin.Playing.size()== 1){ + //Announce Winner + String winnername = plugin.Playing.get(i++); + Player winner = plugin.getServer().getPlayerExact(winnername); + String winnername2 = winner.getName(); + p.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.getInventory().addItem(plugin.Reward); + PlayerWinGamesEvent evt = new PlayerWinGamesEvent(winner); + Bukkit.getServer().getPluginManager().callEvent(evt); + //Make spectators visible + if(!plugin.Watching.isEmpty()){ + String s = plugin.Watching.get(i++); + Player spectator = plugin.getServer().getPlayerExact(s); + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(spectator); + } + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart"); + } + } + } + }else{ + plugin.Quit.add(pname); + } + } + }, 1200L); + } +} diff --git a/src/me/travja/hungerarena/Main.java b/src/me/travja/hungerarena/Main.java new file mode 100644 index 0000000..be909f8 --- /dev/null +++ b/src/me/travja/hungerarena/Main.java @@ -0,0 +1,109 @@ +package me.travja.hungerarena; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.logging.Logger; +import net.milkbowl.vault.economy.Economy; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandExecutor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + +public class Main extends JavaPlugin{ + static final Logger log = Logger.getLogger("Minecraft"); + public ArrayList Playing = new ArrayList(); + public ArrayList Ready = new ArrayList(); + public ArrayList Dead = new ArrayList(); + public ArrayList Quit = new ArrayList(); + public ArrayList Out = new ArrayList(); + public ArrayList Watching = new ArrayList(); + public ArrayList NeedConfirm = new ArrayList(); + public HashSet Frozen = new HashSet(); + public Listener DeathListener = new DeathListener(this); + public Listener SpectatorListener = new SpectatorListener(this); + public Listener FreezeListener = new FreezeListener(this); + public Listener JoinAndQuitListener = new JoinAndQuitListener(this); + public Listener ChatListener = new ChatListener(this); + public Listener Chests = new Chests(this); + public Listener PvP = new PvP(this); + public Listener Blocks = new Blocks(this); + public Listener CommandBlock = new CommandBlock(this); + public Listener Damage = new DmgListener(this); + public Listener Teleport = new TeleportListener(this); + public Listener Signs = new Signs(this); + public Listener BlockStorage = new BlockStorage(this); + public Listener WinGames = new WinGamesListener(this); + public CommandExecutor HaCommands = new HaCommands(this); + public CommandExecutor SponsorCommands = new SponsorCommands(this); + public CommandExecutor SpawnsCommand = new SpawnsCommand(this); + public boolean canjoin; + public boolean exists; + public FileConfiguration config = getConfig(); + public ItemStack Reward; + public ItemStack Cost; + public boolean vault = false; + public Economy econ = null; + public void onEnable(){ + log.info("[HungerArena] enabled v" + getDescription().getVersion()); + config.options().copyDefaults(true); + this.saveDefaultConfig(); + getServer().getPluginManager().registerEvents(DeathListener, this); + getServer().getPluginManager().registerEvents(SpectatorListener, this); + getServer().getPluginManager().registerEvents(FreezeListener, this); + getServer().getPluginManager().registerEvents(JoinAndQuitListener, this); + getServer().getPluginManager().registerEvents(ChatListener, this); + getServer().getPluginManager().registerEvents(Chests, this); + getServer().getPluginManager().registerEvents(PvP, this); + getServer().getPluginManager().registerEvents(Blocks, this); + getServer().getPluginManager().registerEvents(CommandBlock, this); + getServer().getPluginManager().registerEvents(Signs, this); + getServer().getPluginManager().registerEvents(BlockStorage, this); + getServer().getPluginManager().registerEvents(WinGames, this); + getServer().getPluginManager().registerEvents(Damage, this); + getCommand("Ha").setExecutor(HaCommands); + getCommand("Sponsor").setExecutor(SponsorCommands); + getCommand("Startpoint").setExecutor(SpawnsCommand); + if (setupEconomy()) { + log.info(ChatColor.AQUA + "[HungerArena] Found Vault! Hooking in for economy!"); + } + if (config.getDouble("config.version") != 1.3) { + config.set("config.version", 1.3); + config.set("eco.enabled", false); + config.set("eco.reward", 100); + } + if (config.getBoolean("eco.enabled", true)) { + if (vault == true) { + log.info(ChatColor.AQUA + "Economy hook deployed."); + } else { + log.info(ChatColor.RED + "You want economy support... yet you don't have Vault. Sorry, can't give you it."); + } + } + if (config.getBoolean("eco.enabled", false)) { + if (vault == true) { + log.info(ChatColor.GREEN + "We see that you have Vault on your server. To set economy support to true, enable it in the config."); + } + } + Reward = new ItemStack(config.getInt("Reward.ID"), config.getInt("Reward.Amount")); + Cost = new ItemStack(config.getInt("Sponsor_Cost.ID"), config.getInt("Sponsor_Cost.Amount")); + } + + public void onDisable(){ + log.info("[HungerArena] disabled v" + getDescription().getVersion()); + } + + public boolean setupEconomy() { + if (getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + econ = rsp.getProvider(); + vault = true; + return econ != null; + } +} diff --git a/src/me/travja/hungerarena/PlayerWinGamesEvent.java b/src/me/travja/hungerarena/PlayerWinGamesEvent.java new file mode 100644 index 0000000..246f93d --- /dev/null +++ b/src/me/travja/hungerarena/PlayerWinGamesEvent.java @@ -0,0 +1,27 @@ +package me.travja.hungerarena; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +/** + * + * @author YoshiGenius + */ +public class PlayerWinGamesEvent extends PlayerEvent { + + private static final HandlerList handlers = new HandlerList(); + + public PlayerWinGamesEvent(final Player p) { + super(p); + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/src/me/travja/hungerarena/PvP.java b/src/me/travja/hungerarena/PvP.java new file mode 100644 index 0000000..d6228ab --- /dev/null +++ b/src/me/travja/hungerarena/PvP.java @@ -0,0 +1,24 @@ +package me.travja.hungerarena; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +public class PvP implements Listener { + public Main plugin; + public PvP(Main m) { + this.plugin = m; + } + @EventHandler + public void PlayerPvP(EntityDamageByEntityEvent event){ + Entity p = event.getEntity(); + if(p instanceof Player){ + String pname = ((Player) p).getName(); + if(plugin.Playing.contains(pname) && plugin.canjoin== false){ + event.setCancelled(true); + } + } + } +} diff --git a/src/me/travja/hungerarena/Signs.java b/src/me/travja/hungerarena/Signs.java new file mode 100644 index 0000000..aca030d --- /dev/null +++ b/src/me/travja/hungerarena/Signs.java @@ -0,0 +1,52 @@ +package me.travja.hungerarena; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Signs implements Listener { + public Main plugin; + public Signs(Main m) { + this.plugin = m; + } + @EventHandler + public void Sign(PlayerInteractEvent event){ + Player p = event.getPlayer(); + Block b = event.getClickedBlock(); + if (b == null) { + return; + } + if(event.getAction()== Action.RIGHT_CLICK_BLOCK){ + if(b.getType()== Material.SIGN || b.getType()==Material.SIGN_POST || b.getType()==Material.WALL_SIGN){ + org.bukkit.block.Sign sign = (org.bukkit.block.Sign) b.getState(); + String line1 = sign.getLine(0); + String line2 = sign.getLine(1); + String line3 = sign.getLine(2); + String line4 = sign.getLine(3); + if(line1.equalsIgnoreCase(ChatColor.BLUE + "[HungerArena]") || line1.equalsIgnoreCase(ChatColor.BLUE + "[HA]")){ + if(line2.equals("")){ + p.performCommand("ha"); + }else{ + p.performCommand("ha " + line2); + } + } + if(line1.equalsIgnoreCase(ChatColor.BLUE + "[Sponsor]")){ + p.performCommand("sponsor " + line2 + " " + line3 + " " + line4); + } + } + } + } + @EventHandler + public void Create(SignChangeEvent event){ + String top = event.getLine(0); + if(top.equalsIgnoreCase("[HungerArena]") || top.equalsIgnoreCase("[HA]") || top.equalsIgnoreCase("[Sponsor]")){ + event.setLine(0, ChatColor.BLUE + top); + } + } +} diff --git a/src/me/travja/hungerarena/SpawnsCommand.java b/src/me/travja/hungerarena/SpawnsCommand.java new file mode 100644 index 0000000..9e21cbd --- /dev/null +++ b/src/me/travja/hungerarena/SpawnsCommand.java @@ -0,0 +1,243 @@ +package me.travja.hungerarena; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SpawnsCommand implements CommandExecutor { + public Main plugin; + public SpawnsCommand(Main m) { + this.plugin = m; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + if(cmd.getName().equalsIgnoreCase("StartPoint")){ + if(p.hasPermission("HungerArena.StartPoint")){ + if(args[0].equalsIgnoreCase("1")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_one_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute one!"); + } + if(args[0].equalsIgnoreCase("2")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_two_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute two!"); + } + if(args[0].equalsIgnoreCase("3")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_three_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute three!"); + } + if(args[0].equalsIgnoreCase("4")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_four_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute four!"); + } + if(args[0].equalsIgnoreCase("5")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_five_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute five!"); + } + if(args[0].equalsIgnoreCase("6")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_six_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute six!"); + } + if(args[0].equalsIgnoreCase("7")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_seven_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute seven!"); + } + if(args[0].equalsIgnoreCase("8")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_eight_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute eight!"); + } + if(args[0].equalsIgnoreCase("9")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_nine_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute nine!"); + } + if(args[0].equalsIgnoreCase("10")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_ten_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute ten!"); + } + if(args[0].equalsIgnoreCase("11")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_eleven_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute eleven!"); + } + if(args[0].equalsIgnoreCase("12")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_twelve_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute twelve!"); + } + if(args[0].equalsIgnoreCase("13")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_thirteen_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute thirteen!"); + } + if(args[0].equalsIgnoreCase("14")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_fourteen_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute fourteen!"); + } + if(args[0].equalsIgnoreCase("15")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_fifteen_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute fifteen!"); + } + if(args[0].equalsIgnoreCase("16")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_sixteen_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute sixteen!"); + } + if(args[0].equalsIgnoreCase("17")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_seventeen_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute seventeen!"); + } + if(args[0].equalsIgnoreCase("18")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_eighteen_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute eighteen!"); + } + if(args[0].equalsIgnoreCase("19")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_nineteen_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute nineteen!"); + } + if(args[0].equalsIgnoreCase("20")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_twenty_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute twenty!"); + } + if(args[0].equalsIgnoreCase("21")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_twentyone_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute twentyone!"); + } + if(args[0].equalsIgnoreCase("22")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_twentytwo_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute twentytwo!"); + } + if(args[0].equalsIgnoreCase("23")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_twentythree_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute twentythree!"); + } + if(args[0].equalsIgnoreCase("24")){ + double x = p.getLocation().getX(); + double y = p.getLocation().getY(); + double z = p.getLocation().getZ(); + String w = p.getWorld().getName(); + plugin.config.set("Tribute_twentyfour_spawn", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute twentyfour!"); + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } + return false; + } + +} diff --git a/src/me/travja/hungerarena/SpectatorListener.java b/src/me/travja/hungerarena/SpectatorListener.java new file mode 100644 index 0000000..ff40587 --- /dev/null +++ b/src/me/travja/hungerarena/SpectatorListener.java @@ -0,0 +1,132 @@ +package me.travja.hungerarena; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.player.*; + +public class SpectatorListener implements Listener { + public Main plugin; + public SpectatorListener(Main m){ + this.plugin = m; + } + @EventHandler + public void SpectatorDrops(PlayerDropItemEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Watching.contains(pname)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + @EventHandler + public void SpectatorInteractBlock(PlayerInteractEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Watching.contains(pname)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorInteractEntity(PlayerInteractEntityEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Watching.contains(pname)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + @EventHandler + public void SpectatorItems(PlayerPickupItemEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Watching.contains(pname)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + @EventHandler + public void SpectatorPvP(EntityDamageByEntityEvent event){ + Entity offense = event.getDamager(); + if(offense instanceof Player){ + Player Attacker = (Player) event.getDamager(); + String attackerName = Attacker.getName(); + if(plugin.Watching.contains(attackerName)){ + event.setCancelled(true); + Attacker.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + }else if(event.getDamager() instanceof Projectile){ + Projectile arrow = (Projectile) offense; + if(arrow.getShooter() instanceof Player){ + Player BowMan = (Player) arrow.getShooter(); + String bowManName = BowMan.getName(); + if(plugin.Watching.contains(bowManName)){ + event.setCancelled(true); + BowMan.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + } + } + @EventHandler + public void SpectatorBlockBreak(BlockBreakEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Watching.contains(pname)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorBlockPlace(BlockPlaceEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Watching.contains(pname)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + + @EventHandler + public void SpectatorQuit(PlayerQuitEvent event){ + Player p = event.getPlayer(); + String pname = p.getName(); + if(plugin.Watching.contains(pname)){ + plugin.Watching.remove(pname); + String[] Spawncoords = plugin.config.getString("Spawn_coords").split(","); + String w = Spawncoords[3]; + World spawnw = plugin.getServer().getWorld(w); + double spawnx = Double.parseDouble(Spawncoords[0]); + double spawny = Double.parseDouble(Spawncoords[1]); + double spawnz = Double.parseDouble(Spawncoords[2]); + final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); + p.teleport(Spawn); + } + } + + @EventHandler + public void MobNerf(EntityTargetEvent event){ + Entity target = event.getTarget(); + Entity e = event.getEntity(); + if (e instanceof Player) { + return; + } + if(target instanceof Player){ + String targetName = ((Player) target).getName(); + if(plugin.Watching.contains(targetName)){ + event.setTarget(null); + } + } + } +} diff --git a/src/me/travja/hungerarena/SponsorCommands.java b/src/me/travja/hungerarena/SponsorCommands.java new file mode 100644 index 0000000..e1d3e76 --- /dev/null +++ b/src/me/travja/hungerarena/SponsorCommands.java @@ -0,0 +1,102 @@ +package me.travja.hungerarena; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class SponsorCommands implements CommandExecutor { + public Main plugin; + public SponsorCommands(Main m) { + this.plugin = m; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + if(cmd.getName().equalsIgnoreCase("Sponsor")){ + if(sender instanceof Player){ + Player p = (Player) sender; + String pname = p.getName(); + String epname = p.getName(); + if(p.hasPermission("HungerArena.Sponsor")){ + if(!plugin.Playing.contains(epname)){ + if(args.length== 0){ + p.sendMessage(ChatColor.RED + "You didn't specify a tribute!"); + return false; + } + if(args.length== 1){ + p.sendMessage(ChatColor.RED + "You didn't specify an item!"); + } + if(args.length== 2){ + p.sendMessage(ChatColor.RED + "You didn't specify an amount!"); + } + if(args.length== 3){ + Player target = Bukkit.getServer().getPlayer(args[0]); + if(args[1].equalsIgnoreCase("57") || args[1].equalsIgnoreCase("7")){ + p.sendMessage(ChatColor.RED + "You can't sponsor that item!"); + }else{ + int ID = Integer.parseInt(args[1]); + int Amount = Integer.parseInt(args[2]); + ItemStack sponsoritem = new ItemStack(ID, Amount); + if(p.getInventory().contains(plugin.config.getInt("Sponsor_Cost.ID"), plugin.config.getInt("Sponsor_Cost.Amount")*Amount)){ + if(!plugin.Playing.contains(target.getName())){ + p.sendMessage(ChatColor.RED + "That person isn't playing!"); + }else{ + if(args[0].equalsIgnoreCase(pname)){ + p.sendMessage(ChatColor.RED + "You can't sponsor yourself!"); + }else{ + target.sendMessage(ChatColor.AQUA + "You have been Sponsored!"); + target.getInventory().addItem(sponsoritem); + p.sendMessage("You have sponsored " + target.getName() + "!"); + p.getInventory().removeItem(plugin.Cost); + } + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have the necessary items to sponsor!"); + } + } + } + }else{ + p.sendMessage(ChatColor.RED + "You are playing, you can't sponsor yourself!"); + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + }else if(sender instanceof ConsoleCommandSender){ + if(args.length== 0){ + sender.sendMessage(ChatColor.RED + "You didn't specify a tribute!"); + return false; + } + if(args.length== 1){ + sender.sendMessage(ChatColor.RED + "You didn't specify an item!"); + } + if(args.length== 2){ + sender.sendMessage(ChatColor.RED + "You didn't specify an amount!"); + } + if(args.length== 3){ + Player target = Bukkit.getPlayer(args[0]); + if(args[1].equalsIgnoreCase("57") || args[1].equalsIgnoreCase("7")){ + sender.sendMessage(ChatColor.RED + "You can't sponsor that item!"); + }else{ + int ID = Integer.parseInt(args[1]); + int Amount = Integer.parseInt(args[2]); + ItemStack sponsoritem = new ItemStack(ID, Amount); + if(!plugin.Playing.contains(target.getName())){ + sender.sendMessage(ChatColor.RED + "That person isn't playing!"); + }else{ + sender.sendMessage(ChatColor.RED + "You can't sponsor yourself!"); + target.sendMessage(ChatColor.AQUA + "You have been Sponsored!"); + target.getInventory().addItem(sponsoritem); + sender.sendMessage("You have sponsored " + target.getName() + "!"); + } + } + } + } + } + return false; + } +} diff --git a/src/me/travja/hungerarena/TeleportListener.java b/src/me/travja/hungerarena/TeleportListener.java new file mode 100644 index 0000000..e486bc7 --- /dev/null +++ b/src/me/travja/hungerarena/TeleportListener.java @@ -0,0 +1,36 @@ +package me.travja.hungerarena; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; + +/** + * + * @author YoshiGenius + */ +public class TeleportListener implements Listener { + + public Main plugin; + public TeleportListener(Main m) { + this.plugin = m; + } + + @EventHandler + public void onTP(PlayerTeleportEvent evt) { + Player p = evt.getPlayer(); + TeleportCause tc = evt.getCause(); + if (tc == TeleportCause.ENDER_PEARL) { + return; + } + if (tc == TeleportCause.END_PORTAL) { + return; + } + if (tc == TeleportCause.NETHER_PORTAL) { + return; + } + evt.setCancelled(true); + } + +} diff --git a/src/me/travja/hungerarena/WinGamesListener.java b/src/me/travja/hungerarena/WinGamesListener.java new file mode 100644 index 0000000..b68f95f --- /dev/null +++ b/src/me/travja/hungerarena/WinGamesListener.java @@ -0,0 +1,24 @@ +package me.travja.hungerarena; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +/** + * + * @author YoshiGenius + */ +public class WinGamesListener implements Listener { + + public Main plugin; + public WinGamesListener(Main m) { + this.plugin = m; + } + + @EventHandler + public void onWin(PlayerWinGamesEvent evt) { + Player p = evt.getPlayer(); + plugin.econ.depositPlayer(p.getName(), plugin.config.getDouble("EcoReward")); + } + +}