Bugfixes !

merged routines, fixed "Protect_Always", added possibility for full
Protection when noone is playing...
Fixed autorestart,
added configurable countdown.
reload command : fixed multiple listeners
restart command : fixed reopen, merged routines, added respawn
close command: fixed for multiple arenas and merged routines.
open command: small textfix
fix for whitelisted commands (can be used now...)
This commit is contained in:
Jeppa 2013-03-20 17:51:59 +01:00
parent 482e3e8e55
commit 4696c01a35
4 changed files with 0 additions and 2620 deletions

View File

@ -1,402 +0,0 @@
package me.Travja.HungerArena;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
public class BlockStorage implements Listener {
public Main plugin;
public BlockStorage(Main m) {
this.plugin = m;
}
@EventHandler(priority = EventPriority.MONITOR)
public void BlockBreak(BlockBreakEvent event){
Block b = event.getBlock();
Player p = event.getPlayer();
String pname = p.getName();
if(plugin.getArena(p)!= null){
int a = plugin.getArena(p);
if(!event.isCancelled()){
if(plugin.Playing.get(a).contains(pname)){
if(plugin.config.getString("Protected_Arena").equalsIgnoreCase("True")){
p.sendMessage(ChatColor.RED + "You can't break blocks while playing!");
}
if(plugin.canjoin.get(a)){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(p.getWorld().getName()))){
if(!plugin.management.getBoolean("blocks.useWhitelistAsBlacklist")){
if(!plugin.management.getIntegerList("blocks.whitelist").isEmpty()){
if(!plugin.management.getIntegerList("blocks.whitelist").contains(b.getTypeId())){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}else if(plugin.management.getIntegerList("blocks.whitelist").contains(b.getTypeId())){
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m + "," + a;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + a)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}else{
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
}
}else{
if(!plugin.management.getIntegerList("blocks.whitelist").isEmpty()){
if(!plugin.management.getIntegerList("blocks.whitelist").contains(b.getTypeId())){
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m + "," + a;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + a)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}else if(plugin.management.getIntegerList("blocks.whitelist").contains(b.getTypeId())){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block");
}
}else{
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m + "," + a;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + a)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void Explosion(EntityExplodeEvent event){
List<Block> blocksd = event.blockList();
Entity e = event.getEntity();
int i = 0;
if(!event.isCancelled()){
for(i = 1; i <= plugin.canjoin.size(); i++){
if(plugin.canjoin.get(i)){
i = plugin.canjoin.size()+1;
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(event.getEntity().getWorld().getName()))){
if(e.getType()== EntityType.PRIMED_TNT){
if(!plugin.data.getStringList("Blocks_Placed").contains(e.getLocation().getWorld() + "," + e.getLocation().getX() + "," + e.getLocation().getY() + "," + e.getLocation().getZ()) /*|| !plugin.data.getStringList("Blocks_Destroyed").contains(e.getLocation().getWorld() + "," + e.getLocation().getX() + "," + e.getLocation().getY() + "," + e.getLocation().getZ())*/){
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
blocks.add(e.getLocation().getWorld().getName() + "," + e.getLocation().getX() + "," + e.getLocation().getY() + "," + e.getLocation().getZ() + ",46" + ",0");
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
for(Block b:blocksd){
String w = event.getEntity().getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m + "," + i;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + i) || !plugin.data.getStringList("Blocks_Destroyed").contains(w + "," + x + "," + y + "," + z + "," + i)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void burningBlocks(BlockBurnEvent event){
Block b = event.getBlock();
int i = 0;
if(!event.isCancelled()){
for(i = 1; i <= plugin.canjoin.size(); i++){
if(plugin.canjoin.get(i)){
i = plugin.canjoin.size()+1;
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(b.getWorld().getName()))){
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m + "," + i;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + i)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void blockPlace(BlockPlaceEvent event){
Block b = event.getBlock();
Player p = event.getPlayer();
if(plugin.getArena(p)!= null){
int a = plugin.getArena(p);
if(!event.isCancelled()){
if(plugin.Playing.get(a).contains(p.getName())){
if(plugin.canjoin.get(a)){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(b.getWorld().getName()))){
if((b.getType()== Material.SAND || b.getType()== Material.GRAVEL) && (b.getRelative(BlockFace.DOWN).getType()== Material.AIR || b.getRelative(BlockFace.DOWN).getType()== Material.WATER || b.getRelative(BlockFace.DOWN).getType()== Material.LAVA)){
int n = b.getY() -1;
while(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()== Material.LAVA){
n = n -1;
event.getPlayer().sendMessage(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType().toString().toLowerCase());
if(b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType()!= Material.LAVA){
int l = n +1;
Block br = b.getWorld().getBlockAt(b.getX(), l, b.getZ());
String w = br.getWorld().getName();
int x = br.getX();
int y = br.getY();
int z = br.getZ();
String coords = w + "," + x + "," + y + "," + z + "," + a;
p.sendMessage(ChatColor.GREEN + "Sand/Gravel will land at " + coords);
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.set("Blocks_Placed", blocks);
plugin.saveData();
}
}
}else{
if(b.getType()!= Material.SAND || b.getType()!= Material.GRAVEL){
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
String coords = w + "," + x + "," + y + "," + z + "," + a;
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.set("Blocks_Placed", blocks);
plugin.saveData();
}
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void bucketEmpty(PlayerBucketEmptyEvent event){
if(plugin.getArena(event.getPlayer())!= null){
int a = plugin.getArena(event.getPlayer());
if(!event.isCancelled()){
if(plugin.canjoin.get(a)){
if(plugin.Playing.get(a).contains(event.getPlayer().getName())){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(event.getPlayer().getWorld().getName()))){
Block b = event.getBlockClicked().getRelative(event.getBlockFace());
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
String coords = w + "," + x + "," + y + "," + z + "," + a;
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.set("Blocks_Placed", blocks);
plugin.saveData();
}
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void bucketFill(PlayerBucketFillEvent event){
if(plugin.getArena(event.getPlayer())!= null){
int a = plugin.getArena(event.getPlayer());
if(!event.isCancelled()){
if(plugin.canjoin.get(a)){
if(plugin.Playing.get(a).contains(event.getPlayer().getName())){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(event.getPlayer().getWorld().getName()))){
Block b = event.getBlockClicked().getRelative(event.getBlockFace());
String w = b.getWorld().getName();
int x = b.getX();
int y = b.getY();
int z = b.getZ();
int d = b.getTypeId();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m + "," + a;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + a)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void blockMelt(BlockFadeEvent event){
int i = 0;
if(!event.isCancelled()){
for(i = 1; i <= plugin.canjoin.size(); i++){
if(plugin.canjoin.get(i)){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(event.getBlock().getWorld().getName()))){
i = plugin.canjoin.size()+1;
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();
byte m = b.getData();
String coords = w + "," + x + "," + y + "," + z + "," + d + "," + m + "," + i;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if(!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + i)){
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
}
}
}
}
/*@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<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.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<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.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<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
blocks.add(coords);
plugin.data.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<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.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<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.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<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveConfig();
}
}
}*/
}

View File

@ -1,149 +0,0 @@
package me.Travja.HungerArena;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandBlock implements Listener {
public Main plugin;
public CommandBlock(Main m) {
this.plugin = m;
}
@EventHandler(priority = EventPriority.MONITOR)
public void CatchCommand(PlayerCommandPreprocessEvent event){
String cmd = event.getMessage();
Player p = event.getPlayer();
String pname = p.getName();
int i = 0;
int x = 0;
for(x = 1; x < plugin.Watching.size(); x++){
if(plugin.Watching.get(x).contains(p.getName())){
if(!p.hasPermission("HungerArena.UseCommands")){
if(!plugin.management.getStringList("commands.whitelist").isEmpty()){
for(String whitelist: plugin.management.getStringList("commands.whitelist")){
i = i+1;
if(i== plugin.management.getStringList("commands.whitelist").size()){
if(!cmd.toLowerCase().startsWith(whitelist.toLowerCase()) || !cmd.toLowerCase().startsWith("/ha")){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You are only allowed to perform the following commands:");
for(String whitelistfull: plugin.management.getStringList("commands.whitelist")){
p.sendMessage(ChatColor.AQUA + whitelistfull);
}
p.sendMessage(ChatColor.AQUA + "/ha");
p.sendMessage(ChatColor.AQUA + "/ha close");
p.sendMessage(ChatColor.AQUA + "/ha help");
p.sendMessage(ChatColor.AQUA + "/ha join");
p.sendMessage(ChatColor.AQUA + "/ha kick [Player]");
p.sendMessage(ChatColor.AQUA + "/ha leave");
p.sendMessage(ChatColor.AQUA + "/ha list");
p.sendMessage(ChatColor.AQUA + "/ha open");
p.sendMessage(ChatColor.AQUA + "/ha ready");
p.sendMessage(ChatColor.AQUA + "/ha refill");
p.sendMessage(ChatColor.AQUA + "/ha reload");
p.sendMessage(ChatColor.AQUA + "/ha restart");
p.sendMessage(ChatColor.AQUA + "/ha rlist");
p.sendMessage(ChatColor.AQUA + "/ha setspawn");
p.sendMessage(ChatColor.AQUA + "/ha start");
p.sendMessage(ChatColor.AQUA + "/ha tp");
p.sendMessage(ChatColor.AQUA + "/ha watch");
p.sendMessage(ChatColor.AQUA + "/ha warpall");
}
}
}
}else if(!cmd.toLowerCase().startsWith("/ha")){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You are only allowed to perform /ha commands!");
}
}else if(!cmd.toLowerCase().startsWith("/ha")){
if(cmd.toLowerCase().startsWith("/spawn")){
event.setCancelled(true);
p.sendMessage("You have perms for all commands except this one!");
}
}
}
}
if(plugin.getArena(p)!= null){
if(!p.hasPermission("HungerArena.UseCommands")){
if(!plugin.management.getStringList("commands.whitelist").isEmpty()){
for(String whitelist: plugin.management.getStringList("commands.whitelist")){
i = i+1;
if(i== plugin.management.getStringList("commands.whitelist").size()){
if(!cmd.toLowerCase().startsWith(whitelist.toLowerCase()) || !cmd.toLowerCase().startsWith("/ha")){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You are only allowed to perform the following commands:");
for(String whitelistfull: plugin.management.getStringList("commands.whitelist")){
p.sendMessage(ChatColor.AQUA + whitelistfull);
}
p.sendMessage(ChatColor.AQUA + "/ha");
p.sendMessage(ChatColor.AQUA + "/ha close");
p.sendMessage(ChatColor.AQUA + "/ha help");
p.sendMessage(ChatColor.AQUA + "/ha join");
p.sendMessage(ChatColor.AQUA + "/ha kick [Player]");
p.sendMessage(ChatColor.AQUA + "/ha leave");
p.sendMessage(ChatColor.AQUA + "/ha list");
p.sendMessage(ChatColor.AQUA + "/ha open");
p.sendMessage(ChatColor.AQUA + "/ha ready");
p.sendMessage(ChatColor.AQUA + "/ha refill");
p.sendMessage(ChatColor.AQUA + "/ha reload");
p.sendMessage(ChatColor.AQUA + "/ha restart");
p.sendMessage(ChatColor.AQUA + "/ha rlist");
p.sendMessage(ChatColor.AQUA + "/ha setspawn");
p.sendMessage(ChatColor.AQUA + "/ha start");
p.sendMessage(ChatColor.AQUA + "/ha tp");
p.sendMessage(ChatColor.AQUA + "/ha watch");
p.sendMessage(ChatColor.AQUA + "/ha warpall");
}
}
}
}else if(!cmd.toLowerCase().startsWith("/ha")){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You are only allowed to perform /ha commands!");
}
}else if(!cmd.toLowerCase().startsWith("/ha")){
if(cmd.toLowerCase().startsWith("/spawn")){
event.setCancelled(true);
p.sendMessage("You have perms for all commands except this one!");
}
}
}else if(cmd.toLowerCase().equals("/back")){
for(i = 1; i < plugin.Dead.size(); i++){
if(plugin.Dead.get(i).contains(pname) && plugin.canjoin.get(i))
plugin.Tele.add(p);
}
}else if(cmd.startsWith("/tp") || cmd.startsWith("/tpa") || cmd.startsWith("/tpo")){
String[] args = cmd.split(" ");
Player arg1 = null;
Player arg2 = null;
if(args.length == 2){
if(Bukkit.getPlayer(args[0]) != null && Bukkit.getPlayer(args[1]) != null){
arg1 = Bukkit.getPlayer(args[0]);
arg2 = Bukkit.getPlayer(args[1]);
if(plugin.isSpectating(p)){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "Invalid command for spectating, using /ha tp " + arg2);
p.performCommand("/ha tp " + arg2);
}else if(plugin.getArena(arg1)!= null || plugin.getArena(arg2)!= null){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You can't teleport to other tributes!");
}
}
}else if(args.length == 1){
if(Bukkit.getPlayer(args[0]) != null){
arg1 = Bukkit.getPlayer(args[0]);
if(plugin.isSpectating(p)){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "Invalid command for spectating, using /ha tp " + arg1);
p.performCommand("/ha tp " + arg1);
}else if(plugin.getArena(arg1)!= null || plugin.getArena(p)!= null){
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You can't teleport to other tributes!");
}
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,511 +0,0 @@
package me.Travja.HungerArena;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.command.CommandExecutor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class Main extends JavaPlugin{
static Logger log;
public HashMap<Integer, List<String>> Playing = new HashMap<Integer, List<String>>();
public HashMap<Integer, List<String>> Ready = new HashMap<Integer, List<String>>();
public HashMap<Integer, List<String>> Dead = new HashMap<Integer, List<String>>();
public HashMap<Integer, List<String>> Quit = new HashMap<Integer, List<String>>();
public HashMap<Integer, List<String>> Out = new HashMap<Integer, List<String>>();
public HashMap<Integer, List<String>> Watching = new HashMap<Integer, List<String>>();
public HashMap<Integer, List<String>> NeedConfirm = new HashMap<Integer, List<String>>();
public HashMap<Integer, HashMap<Integer, Location>> location = new HashMap<Integer, HashMap<Integer, Location>>();
public ArrayList<Player> Tele = new ArrayList<Player>();
public HashMap<Integer, List<String>> inArena = new HashMap<Integer, List<String>>();
public HashMap<Integer, List<String>> Frozen = new HashMap<Integer, List<String>>();
public HashMap<Integer, List<String>> arena = new HashMap<Integer, List<String>>();
public HashMap<Integer, Boolean> canjoin = new HashMap<Integer, Boolean>();
public HashMap<Integer, Integer> maxPlayers = new HashMap<Integer, Integer>();
public HashMap<Integer, Boolean> open = new HashMap<Integer, Boolean>();
public List<String> worlds;
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 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 exists;
public boolean restricted;
public FileConfiguration config;
public FileConfiguration spawns = null;
public File spawnsFile = null;
public FileConfiguration data = null;
public File dataFile = null;
public File managementFile = null;
public FileConfiguration management = null;
public ArrayList<ItemStack> Reward = new ArrayList<ItemStack>();
public ArrayList<ItemStack> Cost = new ArrayList<ItemStack>();
public ArrayList<ItemStack> Fee = new ArrayList<ItemStack>();
public boolean vault = false;
public boolean eco = false;
public Economy econ = null;
int i = 0;
int v = 0;
int start = 0;
int deathtime = 0;
int timetodeath = 0;
int a = 0;
public void onEnable(){
log = this.getLogger();
config = this.getConfig();
config.options().copyDefaults(true);
this.saveDefaultConfig();
spawns = this.getSpawns();
spawns.options().copyDefaults(true);
this.saveSpawns();
data = this.getData();
data.options().copyDefaults(true);
this.saveData();
management = this.getManagement();
management.options().copyDefaults(true);
this.saveManagement();
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(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);
i = 1;
//TODO THIS CRAP
if(spawns.getConfigurationSection("Spawns")!= null){
Map<String, Object> temp = spawns.getConfigurationSection("Spawns").getValues(false);
for(Entry<String, Object> entry: temp.entrySet()){
if(spawns.getConfigurationSection("Spawns." + entry.getKey())!= null){
Map<String, Object> temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false);
for(Map.Entry<String, Object> e: temp2.entrySet()){
if(spawns.get("Spawns." + entry.getKey() + "." + e.getKey())!= null){
String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "." + e.getKey())).split(",");
Integer a = Integer.parseInt(entry.getKey());
Integer s = Integer.parseInt(e.getKey());
if(location.get(a)== null)
location.put(a, new HashMap<Integer, Location>());
log.info("Added spawn number " + s + " in arena " + a + "!");
location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3])));
}
}
}
}
}
for(i = 1; i <= location.size(); i++){
log.info("Loaded " + location.get(i).size() + " tribute spawns for arena " + i + "!");
Playing.put(i, new ArrayList<String>());
Ready.put(i, new ArrayList<String>());
Dead.put(i, new ArrayList<String>());
Quit.put(i, new ArrayList<String>());
Out.put(i, new ArrayList<String>());
Watching.put(i, new ArrayList<String>());
NeedConfirm.put(i, new ArrayList<String>());
inArena.put(i, new ArrayList<String>());
Frozen.put(i, new ArrayList<String>());
arena.put(i, new ArrayList<String>());
canjoin.put(i, false);
if(location.get(i).size()== config.getInt("maxPlayers")){
maxPlayers.put(i, location.get(i).size());
}else if(location.size()< config.getInt("maxPlayers")){
maxPlayers.put(i, location.get(i).size());
}else if(location.size()> config.getInt("maxPlayers")){
maxPlayers.put(i, config.getInt("maxPlayers"));
}
log.info("Max players is for arena " + i + " is " + maxPlayers.get(i));
open.put(i, true);
}
if (setupEconomy()) {
log.info("Found Vault! Hooking in for economy!");
}
if (config.getDouble("config.version") != 1.3) {
config.set("config.version", 1.3);
config.set("rewardEco.enabled", false);
config.set("rewardEco.reward", 100);
}
if (config.getBoolean("rewardEco.enabled", true) || config.getBoolean("sponsorEco.enabled", true) || config.getBoolean("EntryFee.eco", true)) {
if (vault == true) {
log.info("Economy hook deployed.");
eco = true;
}else{
log.info("You want economy support... yet you either don't have Vault or don't have an economy plugin. Sorry, can't give you it.");
}
}
if (!eco) {
if (vault == true) {
log.info("We see that you have Vault on your server. To set economy support to true, enable it in the config.");
}
}
try{
for(String rewards: config.getStringList("Reward")){
String[] rinfo = rewards.split(",");
Reward.add(new ItemStack(Integer.parseInt(rinfo[0]), Integer.parseInt(rinfo[1])));
}
for(String scost: config.getStringList("Sponsor_Cost")){
String[] sinfo = scost.split(",");
Cost.add(new ItemStack(Integer.parseInt(sinfo[0]), Integer.parseInt(sinfo[1])));
}
if(config.getBoolean("EntryFee.enabled")){
for(String fee: config.getStringList("EntryFee.fee")){
String[] finfo = fee.split(",");
Fee.add(new ItemStack(Integer.parseInt(finfo[0]), Integer.parseInt(finfo[1])));
}
}
}catch(Exception e){
log.warning("Could not add a reward/sponsor/entry cost! One of the rewards/costs is not a number!");
}
worlds = config.getStringList("worlds");
if(worlds.isEmpty()){
restricted = false;
}else if(!worlds.isEmpty()){
restricted = true;
}
log.info("Enabled v" + getDescription().getVersion());
}
public void onDisable(){
log.info("Disabled v" + getDescription().getVersion());
}
public boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
vault = true;
return econ != null;
}
public void reloadSpawns() {
if (spawnsFile == null) {
spawnsFile = new File(getDataFolder(), "spawns.yml");
}
spawns = YamlConfiguration.loadConfiguration(spawnsFile);
// Look for defaults in the jar
InputStream defConfigStream = this.getResource("spawns.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
spawns.setDefaults(defConfig);
}
}
public FileConfiguration getSpawns() {
if (spawns == null) {
this.reloadSpawns();
}
return spawns;
}
public void saveSpawns() {
if (spawns == null || spawnsFile == null) {
return;
}
try {
getSpawns().save(spawnsFile);
} catch (IOException ex) {
this.getLogger().log(Level.SEVERE, "Could not save config to " + spawnsFile, ex);
}
}
public void reloadData() {
if (dataFile == null) {
dataFile = new File(getDataFolder(), "Data.yml");
}
data = YamlConfiguration.loadConfiguration(dataFile);
// Look for defaults in the jar
InputStream defConfigStream = this.getResource("Data.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
data.setDefaults(defConfig);
}
}
public FileConfiguration getData() {
if (data == null) {
this.reloadData();
}
return data;
}
public void saveData() {
if (data == null || dataFile == null) {
return;
}
try {
getData().save(dataFile);
} catch (IOException ex) {
this.getLogger().log(Level.SEVERE, "Could not save config to " + dataFile, ex);
}
}
public void reloadManagement() {
if (managementFile == null) {
managementFile = new File(getDataFolder(), "commandAndBlockManagement.yml");
}
management = YamlConfiguration.loadConfiguration(managementFile);
// Look for defaults in the jar
InputStream defConfigStream = this.getResource("commandAndBlockManagement.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
management.setDefaults(defConfig);
}
}
public FileConfiguration getManagement() {
if (management == null) {
this.reloadManagement();
}
return management;
}
public void saveManagement() {
if (management == null || managementFile == null) {
return;
}
try {
getManagement().save(managementFile);
} catch (IOException ex) {
this.getLogger().log(Level.SEVERE, "Could not save config to " + managementFile, ex);
}
}
public void winner(Integer a){
String[] Spawncoords = spawns.getString("Spawn_coords").split(",");
World spawnw = getServer().getWorld(Spawncoords[3]);
double spawnx = Double.parseDouble(Spawncoords[0]);
double spawny = Double.parseDouble(Spawncoords[1]);
double spawnz = Double.parseDouble(Spawncoords[2]);
Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
if(Playing.get(a).size()== 1 && canjoin.get(a)== true){
//Announce winner
for(i = 0; i < Playing.get(a).size(); i++){
String winnername = Playing.get(a).get(i);
Player winner = getServer().getPlayerExact(winnername);
String winnername2 = winner.getName();
getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!");
winner.getInventory().clear();
winner.getInventory().setBoots(null);
winner.getInventory().setChestplate(null);
winner.getInventory().setHelmet(null);
winner.getInventory().setLeggings(null);
winner.setLevel(0);
for(PotionEffect pe: winner.getActivePotionEffects()){
PotionEffectType potion = pe.getType();
winner.removePotionEffect(potion);
}
Tele.add(winner);
final World w = winner.getWorld();
winner.teleport(Spawn);
if(config.getBoolean("reloadWorld")){
getServer().unloadWorld(w, false);
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
public void run(){
getServer().createWorld(new WorldCreator(w.getName()));
}
},200L);
}
if(!config.getBoolean("rewardEco.enabled")){
for(ItemStack Rewards: Reward){
winner.getInventory().addItem(Rewards);
}
}else{
for(ItemStack Rewards: Reward){
winner.getInventory().addItem(Rewards);
}
econ.depositPlayer(winner.getName(), config.getDouble("rewardEco.reward"));
}
Playing.get(a).clear();
getServer().getScheduler().cancelTask(deathtime);
}
//Show spectators
for(String s1: Watching.get(a)){
Player spectator = getServer().getPlayerExact(s1);
spectator.setAllowFlight(false);
spectator.teleport(Spawn);
for(Player online:getServer().getOnlinePlayers()){
online.showPlayer(spectator);
}
}
if(config.getString("Auto_Restart").equalsIgnoreCase("True")){
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
public void run(){
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart");
}
}, 220L);
}
}
}
public void startGames(final Integer a){
String begin = config.getString("Start_Message");
begin = begin.replaceAll("(&([a-f0-9]))", "\u00A7$2");
final String msg = begin;
i = 10;
if(config.getString("Countdown").equalsIgnoreCase("true")){
start = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
public void run(){
if(i > 0){
if(worlds.isEmpty()){
if(config.getBoolean("broadcastAll")){
getServer().broadcastMessage(String.valueOf(i));
}else{
for(String gn: Playing.get(a)){
Player g = getServer().getPlayer(gn);
g.sendMessage(String.valueOf(i));
}
}
}else{
for(String world: worlds){
World w = getServer().getWorld(world);
if(config.getBoolean("broadcastAll")){
for(Player wp: w.getPlayers()){
wp.sendMessage(String.valueOf(i));
}
}else{
for(String gn: Playing.get(a)){
Player g = getServer().getPlayer(gn);
g.sendMessage(String.valueOf(i));
}
}
}
}
}
i = i-1;
canjoin.put(a, true);
if(i== -1){
if(Frozen.get(a)!= null)
Frozen.get(a).clear();
if(config.getBoolean("broadcastAll")){
getServer().broadcastMessage(msg);
}else{
for(String gn: Playing.get(a)){
Player g = getServer().getPlayer(gn);
g.sendMessage(msg);
}
}
getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + a);
getServer().getScheduler().cancelTask(start);
if(config.getInt("DeathMatch")!= 0){
int death = config.getInt("DeathMatch");
timetodeath = death;
deathtime = getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), new Runnable(){
public void run(){
timetodeath = timetodeath-1;
if(config.getBoolean("broadcastAll")){
for(Player wp: location.get(a).get(0).getWorld().getPlayers()){
if(timetodeath!= 0){
wp.sendMessage(ChatColor.RED + String.valueOf(timetodeath) + " mins till the death match!");
}
}
}else{
for(String gn: Playing.get(a)){
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.RED + String.valueOf(timetodeath) + " mins till the death match!");
}
}
if(timetodeath== 0){
for(String playing: Playing.get(a)){
Player tribute = getServer().getPlayerExact(playing);
tribute.teleport(location.get(a).get(i));
i = i+1;
for(PotionEffect pe: tribute.getActivePotionEffects()){
PotionEffectType potion = pe.getType();
tribute.removePotionEffect(potion);
}
if(tribute.getAllowFlight()){
tribute.setAllowFlight(false);
}
}
if(config.getBoolean("broadcastAll")){
for(Player wp: location.get(a).get(0).getWorld().getPlayers()){
wp.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.size() + " tributes will be facing off!");
}
}else{
for(String gn: Playing.get(a)){
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.size() + " tributes will be facing off!");
}
}
getServer().getScheduler().cancelTask(deathtime);
}
}
}, 1200L, 1200L);
}
}
}
}, 20L, 20L);
}else{
Frozen.get(a).clear();
if(config.getBoolean("broadcastAll")){
getServer().broadcastMessage(msg);
}else{
for(String gn: Playing.get(a)){
Player g = getServer().getPlayer(gn);
g.sendMessage(msg);
}
}
canjoin.put(a, true);
getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + a);
}
}
public Integer getArena(Player p){
for (int x: Playing.keySet()) {
if (Playing.get(x).contains(p.getName())){
return x;
}
}
return null;
}
public boolean isSpectating(Player p){
int x = 0;
if(!Watching.isEmpty()){
for(x= 1; x <= Watching.size(); x++){
if(Watching.get(x).contains(p.getName())){
x = Watching.size()+1;
return true;
}else if(Watching.size()== x)
return false;
}
}
return false;
}
}