diff --git a/bin/me/Travja/HungerArena/Blocks.class b/bin/me/Travja/HungerArena/Blocks.class new file mode 100644 index 0000000..2fb165f Binary files /dev/null and b/bin/me/Travja/HungerArena/Blocks.class differ diff --git a/bin/me/Travja/HungerArena/ChatListener.class b/bin/me/Travja/HungerArena/ChatListener.class new file mode 100644 index 0000000..c6d6cbb Binary files /dev/null and b/bin/me/Travja/HungerArena/ChatListener.class differ diff --git a/bin/me/Travja/HungerArena/Chests.class b/bin/me/Travja/HungerArena/Chests.class new file mode 100644 index 0000000..06eec5b Binary files /dev/null and b/bin/me/Travja/HungerArena/Chests.class differ diff --git a/bin/me/Travja/HungerArena/DeathListener.class b/bin/me/Travja/HungerArena/DeathListener.class index 8c0e667..6851298 100644 Binary files a/bin/me/Travja/HungerArena/DeathListener.class and b/bin/me/Travja/HungerArena/DeathListener.class differ diff --git a/bin/me/Travja/HungerArena/FreezeListener.class b/bin/me/Travja/HungerArena/FreezeListener.class new file mode 100644 index 0000000..502047b Binary files /dev/null and b/bin/me/Travja/HungerArena/FreezeListener.class differ diff --git a/bin/me/Travja/HungerArena/HaCommands.class b/bin/me/Travja/HungerArena/HaCommands.class new file mode 100644 index 0000000..351b961 Binary files /dev/null and b/bin/me/Travja/HungerArena/HaCommands.class differ diff --git a/bin/me/Travja/HungerArena/JoinAndQuitListener$1.class b/bin/me/Travja/HungerArena/JoinAndQuitListener$1.class new file mode 100644 index 0000000..c60b55a Binary files /dev/null and b/bin/me/Travja/HungerArena/JoinAndQuitListener$1.class differ diff --git a/bin/me/Travja/HungerArena/JoinAndQuitListener$2.class b/bin/me/Travja/HungerArena/JoinAndQuitListener$2.class new file mode 100644 index 0000000..d3a91f1 Binary files /dev/null and b/bin/me/Travja/HungerArena/JoinAndQuitListener$2.class differ diff --git a/bin/me/Travja/HungerArena/JoinAndQuitListener$3.class b/bin/me/Travja/HungerArena/JoinAndQuitListener$3.class new file mode 100644 index 0000000..597e870 Binary files /dev/null and b/bin/me/Travja/HungerArena/JoinAndQuitListener$3.class differ diff --git a/bin/me/Travja/HungerArena/JoinAndQuitListener.class b/bin/me/Travja/HungerArena/JoinAndQuitListener.class new file mode 100644 index 0000000..b513fb6 Binary files /dev/null and b/bin/me/Travja/HungerArena/JoinAndQuitListener.class differ diff --git a/bin/me/Travja/HungerArena/Main.class b/bin/me/Travja/HungerArena/Main.class index 0920fda..c5009cf 100644 Binary files a/bin/me/Travja/HungerArena/Main.class and b/bin/me/Travja/HungerArena/Main.class differ diff --git a/bin/me/Travja/HungerArena/PvP.class b/bin/me/Travja/HungerArena/PvP.class new file mode 100644 index 0000000..356db6c Binary files /dev/null and b/bin/me/Travja/HungerArena/PvP.class differ diff --git a/bin/me/Travja/HungerArena/SpectatorListener$1.class b/bin/me/Travja/HungerArena/SpectatorListener$1.class new file mode 100644 index 0000000..c6a50c8 Binary files /dev/null and b/bin/me/Travja/HungerArena/SpectatorListener$1.class differ diff --git a/bin/me/Travja/HungerArena/SpectatorListener.class b/bin/me/Travja/HungerArena/SpectatorListener.class new file mode 100644 index 0000000..9ccfe91 Binary files /dev/null and b/bin/me/Travja/HungerArena/SpectatorListener.class differ diff --git a/src/me/Travja/HungerArena/Blocks.java b/src/me/Travja/HungerArena/Blocks.java new file mode 100644 index 0000000..5ed5a2a --- /dev/null +++ b/src/me/Travja/HungerArena/Blocks.java @@ -0,0 +1,24 @@ +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(); + if(plugin.Playing.contains(p)){ + 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..32867ba --- /dev/null +++ b/src/me/Travja/HungerArena/ChatListener.java @@ -0,0 +1,48 @@ +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(); + if(plugin.Playing.contains(p)){ + 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); + 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{ + for(Entity e:near){ + if(e instanceof Player){ + ((Player) e).sendMessage(msg); + } + } + } + }else{ + 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..9edcaf7 --- /dev/null +++ b/src/me/Travja/HungerArena/Chests.java @@ -0,0 +1,54 @@ +package me.Travja.HungerArena; + +import java.util.List; + +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.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(); + //currently crashes the server when refilling.... + //Kinda glitchy through all here... + if(p.getItemInHand().getType()== Material.BLAZE_ROD && event.getAction() == Action.LEFT_CLICK_BLOCK){ + if(block.getState() instanceof Chest){ + 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(); + } + } + } +} diff --git a/src/me/Travja/HungerArena/DeathListener.java b/src/me/Travja/HungerArena/DeathListener.java new file mode 100644 index 0000000..4728782 --- /dev/null +++ b/src/me/Travja/HungerArena/DeathListener.java @@ -0,0 +1,143 @@ +package me.Travja.HungerArena; + +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.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; + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent event){ + Player p = event.getPlayer(); + if(plugin.Dead.contains(p)){ + String[] Spawncoords = plugin.config.getString("Spawn_coords").split(","); + World spawnw = p.getWorld(); + 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 + public void onPlayerDeath(PlayerDeathEvent event){ + Player p = event.getEntity(); + Server s = p.getServer(); + String pname = p.getName(); + if(plugin.Playing.contains(p)){ + if(plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")){ + p.getWorld().playEffect(p.getLocation(), Effect.ZOMBIE_CHEW_WOODEN_DOOR, 0, 300); + } + plugin.Dead.add(p); + plugin.Playing.remove(p); + 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){ + for(Player winner:plugin.Playing){ + String winnername = winner.getName(); + s.broadcastMessage(ChatColor.GREEN + winnername + " 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); + } + for(Player spectator:plugin.Watching){ + spectator.setAllowFlight(false); + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + plugin.Dead.clear(); + plugin.Playing.clear(); + plugin.Quit.clear(); + plugin.Watching.clear(); + plugin.Frozen.clear(); + plugin.canjoin = false; + } + } + }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){ + for(Player winner:plugin.Playing){ + String winnername = winner.getName(); + s.broadcastMessage(ChatColor.GREEN + winnername + " 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); + } + for(Player spectator:plugin.Watching){ + spectator.setAllowFlight(false); + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + plugin.Dead.clear(); + plugin.Playing.clear(); + plugin.Quit.clear(); + plugin.Watching.clear(); + plugin.Frozen.clear(); + plugin.canjoin = false; + } + } + } + }else{ + event.setDeathMessage(""); + s.broadcastMessage(ChatColor.LIGHT_PURPLE + pname + " died of natural causes!"); + s.broadcastMessage(leftmsg); + if(plugin.Playing.size()== 1){ + for(Player winner:plugin.Playing){ + String winnername = winner.getName(); + s.broadcastMessage(ChatColor.GREEN + winnername + " 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); + } + for(Player spectator:plugin.Watching){ + spectator.setAllowFlight(false); + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + plugin.Dead.clear(); + plugin.Playing.clear(); + plugin.Quit.clear(); + plugin.Watching.clear(); + plugin.Frozen.clear(); + plugin.canjoin = false; + } + } + } + } + if(plugin.Watching.contains(p)){ + for(Player online:plugin.getServer().getOnlinePlayers()) + online.showPlayer(p); + } + } +} diff --git a/src/me/Travja/HungerArena/FreezeListener.java b/src/me/Travja/HungerArena/FreezeListener.java new file mode 100644 index 0000000..c35c62d --- /dev/null +++ b/src/me/Travja/HungerArena/FreezeListener.java @@ -0,0 +1,20 @@ +package me.Travja.HungerArena; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +public class FreezeListener implements Listener { + public Main plugin; + public FreezeListener(Main m) { + this.plugin = m; + } + @EventHandler + public void onPlayerMove(PlayerMoveEvent event){ + Player p = event.getPlayer(); + if(plugin.Frozen.contains(p) && plugin.config.getString("Frozen_Teleport").equalsIgnoreCase("True")){ + event.setCancelled(true); + } + } +} diff --git a/src/me/Travja/HungerArena/HaCommands.java b/src/me/Travja/HungerArena/HaCommands.java new file mode 100644 index 0000000..9943b8d --- /dev/null +++ b/src/me/Travja/HungerArena/HaCommands.java @@ -0,0 +1,626 @@ +package me.Travja.HungerArena; + +import java.util.ArrayList; +import java.util.HashSet; +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.configuration.file.FileConfiguration; +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; + } + public FileConfiguration config = plugin.config; + public ArrayList Playing = plugin.Playing; + public ArrayList Ready = plugin.Ready; + public ArrayList Dead = plugin.Dead; + public ArrayList Quit = plugin.Quit; + public ArrayList Out = plugin.Out; + public ArrayList Watching = plugin.Watching; + public ArrayList NeedConfirm = plugin.NeedConfirm; + public HashSet Frozen = plugin.Frozen; + public boolean canjoin = plugin.canjoin; + public boolean exists = plugin.exists; + public ItemStack Reward = plugin.Reward; + @SuppressWarnings("unchecked") + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ + Player p = (Player) sender; + String pname = p.getName(); + if(cmd.getName().equalsIgnoreCase("Ha")){ + if(config.getString("Spawns_set").equalsIgnoreCase("false")){ + p.sendMessage(ChatColor.RED + "/ha setspawn hasn't been run!"); + } + if(args.length== 0){ + p.sendMessage(ChatColor.GREEN + "[HungerArena] by " + ChatColor.AQUA + "travja!"); + return false; + } + if(args[0].equalsIgnoreCase("List")){ + if(p.hasPermission("HungerArena.GameMaker")){ + p.sendMessage(ChatColor.AQUA + "-----People Playing-----"); + for(Player players:Playing){ + p.sendMessage(ChatColor.GREEN + players.getDisplayName() + " Life: " + players.getHealth() + "/20"); + } + if(Playing.size()== 0){ + p.sendMessage(ChatColor.GRAY + "No one is playing!"); + } + p.sendMessage(ChatColor.AQUA + "----------------------"); + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } + 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(); + config.set("Spawn_coords", x + "," + y + "," + z + "," + w); + plugin.saveConfig(); + config.set("Spawns_set", "true"); + p.sendMessage(ChatColor.AQUA + "You have set the spawn for dead tributes!"); + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } + String[] Spawncoords = 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(args[0].equalsIgnoreCase("Join")){ + if(p.hasPermission("HungerArena.Join")){ + if(Playing.contains(p)){ + p.sendMessage(ChatColor.RED + "You are already playing!"); + }else if(Dead.contains(p) || Quit.contains(p)){ + p.sendMessage(ChatColor.RED + "You DIED/QUIT! You can't join again!"); + }else if(Playing.size()== 24){ + p.sendMessage(ChatColor.RED + "There are already 24 Tributes!"); + }else if(canjoin== true){ + p.sendMessage(ChatColor.RED + "The game is in progress!"); + }else{ + NeedConfirm.add(p); + p.sendMessage(ChatColor.GOLD + "You're inventory will be cleared! Type /ha confirm to procede"); + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } + if(args[0].equalsIgnoreCase("Confirm")){ + if(NeedConfirm.contains(p)){ + Playing.add(p); + NeedConfirm.remove(p); + 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(Playing.size()== 24){ + p.performCommand("ha warpall"); + } + } + } + if(args[0].equalsIgnoreCase("Ready")){ + if(Playing.contains(p)){ + Ready.add(p); + p.sendMessage(ChatColor.AQUA + "You have marked yourself as READY!"); + if(Playing.size()== Ready.size()){ + p.performCommand("Ha Warpall"); + } + }else if(!Playing.contains(p)){ + p.sendMessage(ChatColor.RED + "You aren't playing!"); + } + } + if(args[0].equalsIgnoreCase("Leave")){ + if(!Playing.contains(p)){ + p.sendMessage(ChatColor.RED + "You aren't playing!"); + }else{ + Playing.remove(p); + Quit.add(p); + 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(Frozen.contains(p)){ + Frozen.remove(p); + } + if(Playing.size()== 1 && canjoin== true){ + for(Player winner:Playing){ + String winnername = winner.getName(); + p.getServer().broadcastMessage(ChatColor.GREEN + winnername + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.getInventory().addItem(Reward); + } + for(Player spectator:Watching){ + spectator.setAllowFlight(false); + } + canjoin= false; + Watching.clear(); + } + } + } + if(args[0].equalsIgnoreCase("Watch")){ + if(p.hasPermission("HungerArena.Watch")){ + if(!Watching.contains(p) && !Playing.contains(p) && canjoin== true){ + Watching.add(p); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.hidePlayer(p); + } + p.setAllowFlight(true); + p.sendMessage(ChatColor.AQUA + "You can now spectate!"); + }else if(canjoin == false){ + p.sendMessage(ChatColor.RED + "The game isn't in progress!"); + }else if(Playing.contains(p)){ + p.sendMessage(ChatColor.RED + "You can't watch while you're playing!"); + }else if(Watching.contains(p)){ + Watching.remove(p); + for(Player online:plugin.getServer().getOnlinePlayers()){ + online.showPlayer(p); + } + p.teleport(Spawn); + p.setAllowFlight(false); + p.sendMessage(ChatColor.AQUA + "You are not spectating anymore"); + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } + if(args[0].equalsIgnoreCase("Kick")){ + Player target = plugin.getServer().getPlayer(args[1]); + if(p.hasPermission("HungerArena.Kick")){ + if(Playing.contains(target)){ + if(p.isOnline()){ + Playing.remove(target); + 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); + Quit.add(target); + if(Playing.size()== 1 && canjoin== true){ + for(Player winner:Playing){ + String winnername = winner.getName(); + p.getServer().broadcastMessage(ChatColor.GREEN + winnername + " is the victor of this Hunger Games!"); + winner.getInventory().clear(); + winner.getInventory().addItem(Reward); + } + for(Player spectator:Watching){ + spectator.setAllowFlight(false); + } + canjoin= false; + Watching.clear(); + }else{ + Playing.remove(target); + Quit.add(target); + } + } + }else{ + p.sendMessage(ChatColor.RED + "That player isn't in the game!"); + } + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } + if(args[0].equalsIgnoreCase("Refill")){ + int list056; + list056 = 0; + int limit; + 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); + exists = false; + if(blockatlocation.getState() instanceof Chest){ + 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]); + }else{ + try{ + throw new Exception(); + }catch (Exception e) { + e.printStackTrace(); + } + chest.getInventory().setContents(itemsinchest); + } + } + } + } + if(args[0].equalsIgnoreCase("Restart")){ + if(p.hasPermission("HungerArena.Restart")){ + for(Player spectator:Watching){ + spectator.setAllowFlight(false); + } + Dead.clear(); + Playing.clear(); + Quit.clear(); + Watching.clear(); + Frozen.clear(); + canjoin = false; + p.sendMessage(ChatColor.AQUA + "The games have been reset!"); + }else{ + p.sendMessage(ChatColor.RED + "You don't have permission!"); + } + } + if(args[0].equalsIgnoreCase("Reload")){ + plugin.reloadConfig(); + p.sendMessage(ChatColor.AQUA + "HungerArena Reloaded!"); + } + if(args[0].equalsIgnoreCase("WarpAll")){ + if(p.hasPermission("HungerArena.Warpall")){ + if(Playing.size()== 1){ + p.sendMessage(ChatColor.RED + "There are not enough players!"); + } + if(Playing.size()>= 2){ + config.getString("Tribute_one_spawn"); + String[] onecoords = config.getString("Tribute_one_spawn").split(","); + Player Tribute_one = 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); + Frozen.add(Tribute_one); + Tribute_one.setFoodLevel(20); + config.getString("Tribute_two_spawn"); + String[] twocoords = config.getString("Tribute_two_spawn").split(","); + Player Tribute_two = 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); + Frozen.add(Tribute_two); + Tribute_two.setFoodLevel(20); + p.getWorld().setTime(0); + } + if(Playing.size()>= 3){ + config.getString("Tribute_three_spawn"); + String[] coords = config.getString("Tribute_three_spawn").split(","); + Player Tribute_three = 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); + Frozen.add(Tribute_three); + Tribute_three.setFoodLevel(20); + } + if(Playing.size()>= 4){ + config.getString("Tribute_four_spawn"); + String[] coords = config.getString("Tribute_four_spawn").split(","); + Player Tribute_four = 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); + Frozen.add(Tribute_four); + Tribute_four.setFoodLevel(20); + } + if(Playing.size()>= 5){ + config.getString("Tribute_five_spawn"); + String[] coords = config.getString("Tribute_five_spawn").split(","); + Player Tribute_five = 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); + Frozen.add(Tribute_five); + Tribute_five.setFoodLevel(20); + } + if(Playing.size()>= 6){ + config.getString("Tribute_six_spawn"); + String[] coords = config.getString("Tribute_six_spawn").split(","); + Player Tribute_six = 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); + Frozen.add(Tribute_six); + Tribute_six.setFoodLevel(20); + } + if(Playing.size()>= 7){ + config.getString("Tribute_seven_spawn"); + String[] coords = config.getString("Tribute_seven_spawn").split(","); + Player Tribute_seven = 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); + Frozen.add(Tribute_seven); + Tribute_seven.setFoodLevel(20); + } + if(Playing.size()>= 8){ + config.getString("Tribute_eight_spawn"); + String[] coords = config.getString("Tribute_eight_spawn").split(","); + Player Tribute_eight = 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); + Frozen.add(Tribute_eight); + Tribute_eight.setFoodLevel(20); + } + if(Playing.size()>= 9){ + config.getString("Tribute_nine_spawn"); + String[] coords = config.getString("Tribute_nine_spawn").split(","); + Player Tribute_nine = 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); + Frozen.add(Tribute_nine); + Tribute_nine.setFoodLevel(20); + } + if(Playing.size()>= 10){ + config.getString("Tribute_ten_spawn"); + String[] coords = config.getString("Tribute_ten_spawn").split(","); + Player Tribute_ten = 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); + Frozen.add(Tribute_ten); + Tribute_ten.setFoodLevel(20); + } + if(Playing.size()>= 11){ + config.getString("Tribute_eleven_spawn"); + String[] coords = config.getString("Tribute_eleven_spawn").split(","); + Player Tribute_eleven = 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); + Frozen.add(Tribute_eleven); + Tribute_eleven.setFoodLevel(20); + } + if(Playing.size()>= 12){ + config.getString("Tribute_twelve_spawn"); + String[] coords = config.getString("Tribute_twelve_spawn").split(","); + Player Tribute_twelve = 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); + Frozen.add(Tribute_twelve); + Tribute_twelve.setFoodLevel(20); + } + if(Playing.size()>= 13){ + config.getString("Tribute_thirteen_spawn"); + String[] coords = config.getString("Tribute_thirteen_spawn").split(","); + Player Tribute_thirteen = 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); + Frozen.add(Tribute_thirteen); + Tribute_thirteen.setFoodLevel(20); + } + if(Playing.size()>= 14){ + config.getString("Tribute_fourteen_spawn"); + String[] coords = config.getString("Tribute_fourteen_spawn").split(","); + Player Tribute_fourteen = 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); + Frozen.add(Tribute_fourteen); + Tribute_fourteen.setFoodLevel(20); + } + if(Playing.size()>= 15){ + config.getString("Tribute_fifteen_spawn"); + String[] coords = config.getString("Tribute_fifteen_spawn").split(","); + Player Tribute_fifteen = 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); + Frozen.add(Tribute_fifteen); + Tribute_fifteen.setFoodLevel(20); + } + if(Playing.size()>= 16){ + config.getString("Tribute_sixteen_spawn"); + String[] coords = config.getString("Tribute_sixteen_spawn").split(","); + Player Tribute_sixteen = 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); + Frozen.add(Tribute_sixteen); + Tribute_sixteen.setFoodLevel(20); + } + if(Playing.size()>= 17){ + config.getString("Tribute_seventeen_spawn"); + String[] coords = config.getString("Tribute_seventeen_spawn").split(","); + Player Tribute_seventeen = 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); + Frozen.add(Tribute_seventeen); + Tribute_seventeen.setFoodLevel(20); + } + if(Playing.size()>= 18){ + config.getString("Tribute_eighteen_spawn"); + String[] coords = config.getString("Tribute_eighteen_spawn").split(","); + Player Tribute_eighteen = 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); + Frozen.add(Tribute_eighteen); + Tribute_eighteen.setFoodLevel(20); + } + if(Playing.size()>= 19){ + config.getString("Tribute_nineteen_spawn"); + String[] coords = config.getString("Tribute_nineteen_spawn").split(","); + Player Tribute_nineteen = 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); + Frozen.add(Tribute_nineteen); + Tribute_nineteen.setFoodLevel(20); + } + if(Playing.size()>= 20){ + config.getString("Tribute_twenty_spawn"); + String[] coords = config.getString("Tribute_twenty_spawn").split(","); + Player Tribute_twenty = 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); + Frozen.add(Tribute_twenty); + Tribute_twenty.setFoodLevel(20); + } + if(Playing.size()>= 21){ + config.getString("Tribute_twentyone_spawn"); + String[] coords = config.getString("Tribute_twentyone_spawn").split(","); + Player Tribute_twentyone = 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); + Frozen.add(Tribute_twentyone); + Tribute_twentyone.setFoodLevel(20); + } + if(Playing.size()>= 22){ + config.getString("Tribute_twentytwo_spawn"); + String[] coords = config.getString("Tribute_twentytwo_spawn").split(","); + Player Tribute_twentytwo = 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); + Frozen.add(Tribute_twentytwo); + Tribute_twentytwo.setFoodLevel(20); + } + if(Playing.size()>= 23){ + config.getString("Tribute_twentythree_spawn"); + String[] coords = config.getString("Tribute_twentythree_spawn").split(","); + Player Tribute_twentythree = 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); + Frozen.add(Tribute_twentythree); + Tribute_twentythree.setFoodLevel(20); + } + if(Playing.size()>= 24){ + config.getString("Tribute_twentyfour_spawn"); + String[] coords = config.getString("Tribute_twentyfour_spawn").split(","); + Player Tribute_twentyfour = 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); + Frozen.add(Tribute_twentyfour); + Tribute_twentyfour.setFoodLevel(20); + } + } + } + } + return false; + + } +} + diff --git a/src/me/Travja/HungerArena/JoinAndQuitListener.java b/src/me/Travja/HungerArena/JoinAndQuitListener.java new file mode 100644 index 0000000..14bf357 --- /dev/null +++ b/src/me/Travja/HungerArena/JoinAndQuitListener.java @@ -0,0 +1,98 @@ +package me.Travja.HungerArena; + +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; + } + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event){ + Player p = event.getPlayer(); + final Player player = event.getPlayer(); + if(plugin.Out.contains(p)){ + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + player.sendMessage(ChatColor.AQUA + "You have saved yourself from being ejected from the arena!"); + } + }, 40L); + plugin.Out.remove(p); + } + if(plugin.Quit.contains(p) || plugin.Dead.contains(p)){ + 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(){ + player.teleport(Spawn); + player.sendMessage(ChatColor.RED + "You have been teleported to spawn because you quit/forfieted!"); + } + }, 40L); + } + } + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event){ + final Player p = event.getPlayer(); + 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(p)){ + plugin.Out.add(p); + } + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + if(plugin.Playing.contains(p) && plugin.Out.contains(p)){ + if(plugin.canjoin== true){ + plugin.Playing.remove(p); + plugin.Quit.add(p); + plugin.Out.remove(p); + if(plugin.Playing.size()== 1){ + for(Player winner:plugin.Playing){ + String winnername = winner.getName(); + p.getServer().broadcastMessage(ChatColor.GREEN + winnername + " 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); + } + for(Player spectator:plugin.Watching){ + spectator.setAllowFlight(false); + spectator.teleport(Spawn); + } + if(plugin.config.getString("Auto_Restart").equalsIgnoreCase("True")){ + plugin.Dead.clear(); + plugin.Playing.clear(); + plugin.Quit.clear(); + plugin.Watching.clear(); + plugin.Frozen.clear(); + plugin.canjoin = false; + } + } + }else if(plugin.canjoin== false){ + plugin.Playing.remove(p); + plugin.Quit.add(p); + plugin.Out.remove(p); + } + } + } + }, 1200L); + } +} diff --git a/src/me/Travja/HungerArena/Main.java b/src/me/Travja/HungerArena/Main.java index 7b7b894..621f6a6 100644 --- a/src/me/Travja/HungerArena/Main.java +++ b/src/me/Travja/HungerArena/Main.java @@ -15,6 +15,7 @@ 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.configuration.file.FileConfiguration; import org.bukkit.entity.Entity; @@ -47,6 +48,15 @@ public class Main extends JavaPlugin{ 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 CommandExecutor HaCommands = new HaCommands(this); public boolean canjoin; public boolean exists; public FileConfiguration config; @@ -58,7 +68,15 @@ public class Main extends JavaPlugin{ config = getConfig(); config.options().copyDefaults(true); this.saveDefaultConfig(); - getServer().getPluginManager().registerEvents(new DeathListener(this), this); + 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); + getCommand("Ha").setExecutor(HaCommands); Reward = new ItemStack(config.getInt("Reward.ID"), config.getInt("Reward.Amount")); Cost = new ItemStack(config.getInt("Sponsor_Cost.ID"), config.getInt("Sponsor_Cost.Amount")); } @@ -70,7 +88,7 @@ public class Main extends JavaPlugin{ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ Player p = (Player) sender; String pname = p.getName(); - if(cmd.getName().equalsIgnoreCase("Sponsor")){ + /*if(cmd.getName().equalsIgnoreCase("Sponsor")){ Player target = Bukkit.getPlayer(args[0]); if(!Playing.contains(p)){ if(args.length== 0){ @@ -764,7 +782,7 @@ public class Main extends JavaPlugin{ p.sendMessage(ChatColor.RED + "You don't have permission!"); } } - } + }*/ if(cmd.getName().equalsIgnoreCase("StartPoint")){ if(p.hasPermission("HungerArena.StartPoint")){ if(args[0].equalsIgnoreCase("1")){ @@ -990,20 +1008,14 @@ public class Main extends JavaPlugin{ return true; } } -class DeathListener implements Listener{ +/*class DeadListener implements Listener{ public Main plugin; - public DeathListener(Main m){ + public DeadListener(Main m){ this.plugin = m; } - public FileConfiguration config; @EventHandler public void onPlayerMove(PlayerMoveEvent event){ Player p = event.getPlayer(); - if(p.getWorld().getFullTime()== 18000){ - for(Player dead:plugin.Dead){ - p.getServer().broadcastMessage(ChatColor.GREEN + dead.getName() + " was killed today!"); - } - } if(plugin.Frozen.contains(p) && plugin.config.getString("Frozen_Teleport").equalsIgnoreCase("True")){ event.setCancelled(true); } @@ -1352,4 +1364,4 @@ class DeathListener implements Listener{ } } } -} +}*/ diff --git a/src/me/Travja/HungerArena/PvP.java b/src/me/Travja/HungerArena/PvP.java new file mode 100644 index 0000000..0e3b2f0 --- /dev/null +++ b/src/me/Travja/HungerArena/PvP.java @@ -0,0 +1,23 @@ +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){ + if(plugin.Playing.contains(p) && plugin.canjoin== false){ + event.setCancelled(true); + } + } + } +} diff --git a/src/me/Travja/HungerArena/SpectatorListener.java b/src/me/Travja/HungerArena/SpectatorListener.java new file mode 100644 index 0000000..f57598c --- /dev/null +++ b/src/me/Travja/HungerArena/SpectatorListener.java @@ -0,0 +1,115 @@ +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.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +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(); + if(plugin.Watching.contains(p)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + @EventHandler + public void SpectatorInteractions(PlayerInteractEvent event){ + Player p = event.getPlayer(); + if(plugin.Watching.contains(p)){ + 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(); + if(plugin.Watching.contains(p)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + @EventHandler + public void SpectatorPvP(EntityDamageByEntityEvent event){ + Entity offense = event.getDamager(); + if(offense instanceof Player){ + Player Attacker = (Player) event.getDamager(); + if(plugin.Watching.contains(Attacker)){ + 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(); + if(plugin.Watching.contains(BowMan)){ + event.setCancelled(true); + BowMan.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + } + } + @EventHandler + public void SpectatorBlocks(BlockBreakEvent event){ + Player p = event.getPlayer(); + if(plugin.Watching.contains(p)){ + event.setCancelled(true); + p.sendMessage(ChatColor.RED + "You are spectating, you can't interfere with the game!"); + } + } + @EventHandler + public void SpectatorJoin(PlayerJoinEvent event){ + Player p = event.getPlayer(); + final Player player = event.getPlayer(); + if(plugin.Watching.contains(p)){ + if(plugin.canjoin== false){ + 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.Watching.remove(p); + for(Player everyone:plugin.getServer().getOnlinePlayers()){ + everyone.showPlayer(p); + } + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + public void run(){ + player.teleport(Spawn); + player.sendMessage(ChatColor.RED + "You have been teleported to spawn because the game is over!"); + } + }, 40L); + }else{ + p.setAllowFlight(true); + p.setFlying(true); + for(Player everyone:plugin.getServer().getOnlinePlayers()){ + everyone.hidePlayer(p); + } + } + } + } + @EventHandler + public void SpectatorQuit(PlayerQuitEvent event){ + Player p = event.getPlayer(); + if(plugin.Watching.contains(p)){ + System.out.println(p.getName() + " quit while spectating!"); + } + } +}