From e8e2c0c472c04f3fb52c585f9d04d249929ed21f Mon Sep 17 00:00:00 2001 From: Thomas-Antoine O'Neill Date: Fri, 20 Jan 2012 21:28:19 -0500 Subject: [PATCH] Forgot to delete the rename-namespace files. --- .../main/java/bukkit/tommytony/war/War.java | 913 ------------ .../tommytony/war/WarBlockListener.java | 461 ------ .../tommytony/war/WarCommandHandler.java | 140 -- .../tommytony/war/WarEntityListener.java | 537 ------- .../tommytony/war/WarPlayerListener.java | 767 ---------- .../tommytony/war/WarServerListener.java | 26 - .../war/command/AbstractWarAdminCommand.java | 27 - .../war/command/AbstractWarCommand.java | 84 -- .../war/command/AbstractZoneMakerCommand.java | 50 - .../war/command/DeleteBombCommand.java | 66 - .../war/command/DeleteCakeCommand.java | 66 - .../war/command/DeleteMonumentCommand.java | 66 - .../war/command/DeleteTeamCommand.java | 73 - .../war/command/DeleteTeamFlagCommand.java | 71 - .../war/command/DeleteWarhubCommand.java | 49 - .../war/command/DeleteZoneCommand.java | 83 -- .../tommytony/war/command/JoinCommand.java | 123 -- .../tommytony/war/command/LeaveCommand.java | 40 - .../tommytony/war/command/LoadWarCommand.java | 28 - .../war/command/NextBattleCommand.java | 51 - .../war/command/NotWarAdminException.java | 11 - .../war/command/NotZoneMakerException.java | 11 - .../war/command/RenameZoneCommand.java | 102 -- .../war/command/ResetZoneCommand.java | 66 - .../war/command/SaveZoneCommand.java | 89 -- .../tommytony/war/command/SetBombCommand.java | 64 - .../tommytony/war/command/SetCakeCommand.java | 64 - .../war/command/SetMonumentCommand.java | 64 - .../tommytony/war/command/SetTeamCommand.java | 72 - .../war/command/SetTeamConfigCommand.java | 163 --- .../war/command/SetTeamFlagCommand.java | 68 - .../war/command/SetWarConfigCommand.java | 47 - .../war/command/SetWarHubCommand.java | 60 - .../tommytony/war/command/SetZoneCommand.java | 53 - .../war/command/SetZoneConfigCommand.java | 124 -- .../war/command/SetZoneLobbyCommand.java | 119 -- .../tommytony/war/command/TeamCommand.java | 43 - .../tommytony/war/command/TeamsCommand.java | 49 - .../war/command/UnloadWarCommand.java | 28 - .../tommytony/war/command/WarhubCommand.java | 44 - .../tommytony/war/command/WarzoneCommand.java | 51 - .../war/command/WarzonesCommand.java | 45 - .../war/command/ZoneMakerCommand.java | 79 - war/src/main/java/com/tommytony/war/Bomb.java | 111 -- war/src/main/java/com/tommytony/war/Cake.java | 111 -- .../java/com/tommytony/war/FlagReturn.java | 22 - .../com/tommytony/war/LoadoutSelection.java | 29 - .../main/java/com/tommytony/war/Monument.java | 161 -- .../java/com/tommytony/war/PotionEffect.java | 125 -- war/src/main/java/com/tommytony/war/Team.java | 613 -------- .../main/java/com/tommytony/war/TeamKind.java | 104 -- .../com/tommytony/war/TeamSpawnStyle.java | 28 - .../main/java/com/tommytony/war/WarHub.java | 263 ---- .../main/java/com/tommytony/war/Warzone.java | 1295 ----------------- .../java/com/tommytony/war/ZoneLobby.java | 699 --------- .../java/com/tommytony/war/ZoneSetter.java | 262 ---- .../java/com/tommytony/war/ZoneWallGuard.java | 224 --- .../com/tommytony/war/jobs/BlockResetJob.java | 17 - .../war/jobs/DeferredBlockResetsJob.java | 168 --- .../war/jobs/HelmetProtectionTask.java | 87 -- .../com/tommytony/war/jobs/InitZoneJob.java | 26 - .../tommytony/war/jobs/LoadoutResetJob.java | 31 - .../tommytony/war/jobs/LootDropperTask.java | 25 - .../tommytony/war/jobs/ResetCursorJob.java | 37 - .../tommytony/war/jobs/RespawnPlayerJob.java | 25 - .../war/jobs/RestoreDeadmanInventoryJob.java | 21 - .../tommytony/war/jobs/RestoreWarhubJob.java | 63 - .../war/jobs/RestoreWarzonesJob.java | 64 - .../war/jobs/RestoreYmlWarhubJob.java | 54 - .../war/jobs/RestoreYmlWarzonesJob.java | 49 - .../war/jobs/ScoreCapReachedJob.java | 71 - .../war/jobs/SpoutFadeOutMessageJob.java | 14 - .../tommytony/war/jobs/ZoneVolumeSaveJob.java | 19 - .../war/mappers/LoadoutTxtMapper.java | 62 - .../war/mappers/LoadoutYmlMapper.java | 109 -- .../mappers/PreDeGaulleZoneVolumeMapper.java | 433 ------ .../tommytony/war/mappers/PropertiesFile.java | 407 ------ .../tommytony/war/mappers/VolumeMapper.java | 333 ----- .../tommytony/war/mappers/WarTxtMapper.java | 459 ------ .../tommytony/war/mappers/WarYmlMapper.java | 183 --- .../war/mappers/WarzoneTxtMapper.java | 627 -------- .../war/mappers/WarzoneYmlMapper.java | 527 ------- .../war/mappers/ZoneVolumeMapper.java | 443 ------ .../com/tommytony/war/utils/ChatFixUtil.java | 185 --- .../war/utils/DeferredBlockReset.java | 87 -- .../com/tommytony/war/utils/PlayerState.java | 107 -- .../com/tommytony/war/utils/SignHelper.java | 35 - .../com/tommytony/war/volumes/BlockInfo.java | 110 -- .../tommytony/war/volumes/CenteredVolume.java | 70 - .../war/volumes/NotNorthwestException.java | 7 - .../war/volumes/NotSoutheastException.java | 10 - .../war/volumes/TooBigException.java | 10 - .../war/volumes/TooSmallException.java | 10 - .../tommytony/war/volumes/VerticalVolume.java | 169 --- .../com/tommytony/war/volumes/Volume.java | 563 ------- .../com/tommytony/war/volumes/ZoneVolume.java | 306 ---- 96 files changed, 15307 deletions(-) delete mode 100644 war/src/main/java/bukkit/tommytony/war/War.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/WarBlockListener.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/WarEntityListener.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/WarServerListener.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/AbstractWarAdminCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/AbstractWarCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/AbstractZoneMakerCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeleteBombCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeleteCakeCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeleteMonumentCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeleteTeamCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeleteTeamFlagCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeleteWarhubCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeleteZoneCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/LeaveCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/LoadWarCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/NextBattleCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/NotWarAdminException.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/NotZoneMakerException.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/RenameZoneCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/ResetZoneCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SaveZoneCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetBombCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetCakeCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetMonumentCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetTeamCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetTeamConfigCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetTeamFlagCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetWarConfigCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetWarHubCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetZoneCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetZoneConfigCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/SetZoneLobbyCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/TeamCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/TeamsCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/UnloadWarCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/WarhubCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/WarzoneCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/WarzonesCommand.java delete mode 100644 war/src/main/java/bukkit/tommytony/war/command/ZoneMakerCommand.java delete mode 100644 war/src/main/java/com/tommytony/war/Bomb.java delete mode 100644 war/src/main/java/com/tommytony/war/Cake.java delete mode 100644 war/src/main/java/com/tommytony/war/FlagReturn.java delete mode 100644 war/src/main/java/com/tommytony/war/LoadoutSelection.java delete mode 100644 war/src/main/java/com/tommytony/war/Monument.java delete mode 100644 war/src/main/java/com/tommytony/war/PotionEffect.java delete mode 100644 war/src/main/java/com/tommytony/war/Team.java delete mode 100644 war/src/main/java/com/tommytony/war/TeamKind.java delete mode 100644 war/src/main/java/com/tommytony/war/TeamSpawnStyle.java delete mode 100644 war/src/main/java/com/tommytony/war/WarHub.java delete mode 100644 war/src/main/java/com/tommytony/war/Warzone.java delete mode 100644 war/src/main/java/com/tommytony/war/ZoneLobby.java delete mode 100644 war/src/main/java/com/tommytony/war/ZoneSetter.java delete mode 100644 war/src/main/java/com/tommytony/war/ZoneWallGuard.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/BlockResetJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/DeferredBlockResetsJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/HelmetProtectionTask.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/InitZoneJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/LoadoutResetJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/LootDropperTask.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/RespawnPlayerJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/RestoreDeadmanInventoryJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/RestoreYmlWarhubJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/RestoreYmlWarzonesJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/SpoutFadeOutMessageJob.java delete mode 100644 war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/LoadoutTxtMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/LoadoutYmlMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/PropertiesFile.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/WarTxtMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/WarYmlMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/WarzoneTxtMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/WarzoneYmlMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java delete mode 100644 war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java delete mode 100644 war/src/main/java/com/tommytony/war/utils/DeferredBlockReset.java delete mode 100644 war/src/main/java/com/tommytony/war/utils/PlayerState.java delete mode 100644 war/src/main/java/com/tommytony/war/utils/SignHelper.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/BlockInfo.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/NotNorthwestException.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/NotSoutheastException.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/TooBigException.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/TooSmallException.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/Volume.java delete mode 100644 war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java deleted file mode 100644 index cc2ade0..0000000 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ /dev/null @@ -1,913 +0,0 @@ -package bukkit.tommytony.war; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import com.tommytony.war.FlagReturn; -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.TeamSpawnStyle; -import com.tommytony.war.WarHub; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.config.InventoryBag; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.TeamConfigBag; -import com.tommytony.war.config.WarConfig; -import com.tommytony.war.config.WarConfigBag; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.config.WarzoneConfigBag; -import com.tommytony.war.jobs.HelmetProtectionTask; -import com.tommytony.war.jobs.SpoutFadeOutMessageJob; -import com.tommytony.war.mappers.WarYmlMapper; -import com.tommytony.war.mappers.WarzoneYmlMapper; -import com.tommytony.war.spout.SpoutMessenger; -import com.tommytony.war.utils.ChatFixUtil; -import com.tommytony.war.utils.PlayerState; - -/** - * Main class of War - * - * @author tommytony, Tim Düsterhus - * @package bukkit.tommytony.war - */ -public class War extends JavaPlugin { - public static War war; - - // general - private WarPlayerListener playerListener = new WarPlayerListener(); - private WarEntityListener entityListener = new WarEntityListener(); - private WarBlockListener blockListener = new WarBlockListener(); - private WarServerListener serverListener = new WarServerListener(); - - private WarCommandHandler commandHandler = new WarCommandHandler(); - private Logger logger; - private PluginDescriptionFile desc = null; - private boolean loaded = false; - private boolean isSpoutServer = false; - - // Zones and hub - private List warzones = new ArrayList(); - private WarHub warHub; - - private final List zoneMakerNames = new ArrayList(); - private final List commandWhitelist = new ArrayList(); - - private final List incompleteZones = new ArrayList(); - private final List zoneMakersImpersonatingPlayers = new ArrayList(); - private HashMap disconnected = new HashMap(); - private final HashMap wandBearers = new HashMap(); // playername to zonename - - private final List deadlyAdjectives = new ArrayList(); - private final List killerVerbs = new ArrayList(); - - private final InventoryBag defaultInventories = new InventoryBag(); - - private final WarConfigBag warConfig = new WarConfigBag(); - private final WarzoneConfigBag warzoneDefaultConfig = new WarzoneConfigBag(); - private final TeamConfigBag teamDefaultConfig = new TeamConfigBag(); - private SpoutMessenger spoutMessenger = null; - - public War() { - super(); - War.war = this; - } - - /** - * @see JavaPlugin.onEnable() - * @see War.loadWar() - */ - public void onEnable() { - this.loadWar(); - } - - /** - * @see JavaPlugin.onDisable() - * @see War.unloadWar() - */ - public void onDisable() { - this.unloadWar(); - } - - /** - * Initializes war - */ - public void loadWar() { - this.setLoaded(true); - this.desc = this.getDescription(); - this.logger = this.getServer().getLogger(); - - // Spout server detection - try { - Class.forName("org.getspout.spoutapi.player.SpoutPlayer"); - isSpoutServer = true; - spoutMessenger = new SpoutMessenger(); - } catch (ClassNotFoundException e) { - isSpoutServer = false; - } - - // Register events - PluginManager pm = this.getServer().getPluginManager(); - pm.registerEvents(this.playerListener, this); - pm.registerEvents(this.entityListener, this); - pm.registerEvents(this.blockListener, this); - pm.registerEvents(this.serverListener, this); - - // Add defaults - warConfig.put(WarConfig.BUILDINZONESONLY, false); - warConfig.put(WarConfig.DISABLEBUILDMESSAGE, false); - warConfig.put(WarConfig.DISABLEPVPMESSAGE, false); - warConfig.put(WarConfig.MAXZONES, 12); - warConfig.put(WarConfig.PVPINZONESONLY, false); - warConfig.put(WarConfig.TNTINZONESONLY, false); - - warzoneDefaultConfig.put(WarzoneConfig.AUTOASSIGN, false); - warzoneDefaultConfig.put(WarzoneConfig.BLOCKHEADS, true); - warzoneDefaultConfig.put(WarzoneConfig.DISABLED, false); - warzoneDefaultConfig.put(WarzoneConfig.FRIENDLYFIRE, false); - warzoneDefaultConfig.put(WarzoneConfig.GLASSWALLS, true); - warzoneDefaultConfig.put(WarzoneConfig.INSTABREAK, false); - warzoneDefaultConfig.put(WarzoneConfig.MINPLAYERS, 1); - warzoneDefaultConfig.put(WarzoneConfig.MINTEAMS, 1); - warzoneDefaultConfig.put(WarzoneConfig.MONUMENTHEAL, 5); - warzoneDefaultConfig.put(WarzoneConfig.NOCREATURES, false); - warzoneDefaultConfig.put(WarzoneConfig.NODROPS, false); - warzoneDefaultConfig.put(WarzoneConfig.PVPINZONE, true); - warzoneDefaultConfig.put(WarzoneConfig.RESETONEMPTY, false); - warzoneDefaultConfig.put(WarzoneConfig.RESETONLOAD, false); - warzoneDefaultConfig.put(WarzoneConfig.RESETONUNLOAD, false); - warzoneDefaultConfig.put(WarzoneConfig.UNBREAKABLE, false); - - teamDefaultConfig.put(TeamConfig.FLAGMUSTBEHOME, true); - teamDefaultConfig.put(TeamConfig.FLAGPOINTSONLY, false); - teamDefaultConfig.put(TeamConfig.FLAGRETURN, FlagReturn.BOTH); - teamDefaultConfig.put(TeamConfig.LIFEPOOL, 7); - teamDefaultConfig.put(TeamConfig.MAXSCORE, 10); - teamDefaultConfig.put(TeamConfig.NOHUNGER, false); - teamDefaultConfig.put(TeamConfig.RESPAWNTIMER, 0); - teamDefaultConfig.put(TeamConfig.SATURATION, 10); - teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL); - teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10); - - this.getDefaultInventories().getLoadouts().clear(); - HashMap defaultLoadout = new HashMap(); - - ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1, (byte) 8); - stoneSword.setDurability((short) 8); - defaultLoadout.put(0, stoneSword); - - ItemStack bow = new ItemStack(Material.BOW, 1, (byte) 8); - bow.setDurability((short) 8); - defaultLoadout.put(1, bow); - - ItemStack arrows = new ItemStack(Material.ARROW, 7); - defaultLoadout.put(2, arrows); - - ItemStack stonePick = new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8); - stonePick.setDurability((short) 8); - defaultLoadout.put(3, stonePick); - - ItemStack stoneSpade = new ItemStack(Material.STONE_SPADE, 1, (byte) 8); - stoneSword.setDurability((short) 8); - defaultLoadout.put(4, stoneSpade); - - this.getDefaultInventories().addLoadout("default", defaultLoadout); - - HashMap reward = new HashMap(); - reward.put(0, new ItemStack(Material.CAKE, 1)); - this.getDefaultInventories().setReward(reward); - - this.getCommandWhitelist().add("who"); - this.getZoneMakerNames().add("tommytony"); - - // Add constants - this.getDeadlyAdjectives().clear(); - this.getDeadlyAdjectives().add(""); - this.getDeadlyAdjectives().add(""); - this.getDeadlyAdjectives().add("mighty "); - this.getDeadlyAdjectives().add("deadly "); - this.getDeadlyAdjectives().add("fine "); - this.getDeadlyAdjectives().add("precise "); - this.getDeadlyAdjectives().add("brutal "); - this.getDeadlyAdjectives().add("powerful "); - - this.getKillerVerbs().clear(); - this.getKillerVerbs().add("killed"); - this.getKillerVerbs().add("killed"); - this.getKillerVerbs().add("killed"); - this.getKillerVerbs().add("finished"); - this.getKillerVerbs().add("annihilated"); - this.getKillerVerbs().add("murdered"); - this.getKillerVerbs().add("obliterated"); - this.getKillerVerbs().add("exterminated"); - - // Load files - WarYmlMapper.load(); - - // Start tasks - HelmetProtectionTask helmetProtectionTask = new HelmetProtectionTask(); - this.getServer().getScheduler().scheduleSyncRepeatingTask(this, helmetProtectionTask, 250, 100); - - if (this.isSpoutServer) { - SpoutFadeOutMessageJob fadeOutMessagesTask = new SpoutFadeOutMessageJob(); - this.getServer().getScheduler().scheduleSyncRepeatingTask(this, fadeOutMessagesTask, 100, 100); - } - - this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO); - } - - /** - * Cleans up war - */ - public void unloadWar() { - for (Warzone warzone : this.warzones) { - warzone.unload(); - } - this.warzones.clear(); - - if (this.warHub != null) { - this.warHub.getVolume().resetBlocks(); - } - - this.getServer().getScheduler().cancelTasks(this); - this.playerListener.purgeLatestPositions(); - - this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO); - this.setLoaded(false); - } - - /** - * @see JavaPlugin.onCommand() - */ - public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { - return this.commandHandler.handle(sender, cmd, args); - } - - /** - * Converts the player-inventory to a loadout hashmap - * - * @param inv - * inventory to get the items from - * @param loadout - * the hashmap to save to - */ - private void inventoryToLoadout(PlayerInventory inv, HashMap loadout) { - loadout.clear(); - int i = 0; - for (ItemStack stack : inv.getContents()) { - if (stack != null && stack.getType() != Material.AIR) { - loadout.put(i, this.copyStack(stack)); - i++; - } - - } - if (inv.getBoots() != null && inv.getBoots().getType() != Material.AIR) { - loadout.put(100, this.copyStack(inv.getBoots())); - } - if (inv.getLeggings() != null && inv.getLeggings().getType() != Material.AIR) { - loadout.put(101, this.copyStack(inv.getLeggings())); - } - if (inv.getChestplate() != null && inv.getChestplate().getType() != Material.AIR) { - loadout.put(102, this.copyStack(inv.getChestplate())); - } - } - - public ItemStack copyStack(ItemStack originalStack) { - ItemStack copiedStack = new ItemStack(originalStack.getType(), originalStack.getAmount(), originalStack.getDurability(), new Byte(originalStack.getData().getData())); - copiedStack.setDurability(originalStack.getDurability()); - for (Enchantment enchantment : originalStack.getEnchantments().keySet()) { - copiedStack.addEnchantment(Enchantment.getById(enchantment.getId()), originalStack.getEnchantments().get(enchantment)); - } - return copiedStack; - } - - /** - * Converts the player-inventory to a loadout hashmap - * - * @param player - * player to get the inventory to get the items from - * @param loadout - * the hashmap to save to - */ - private void inventoryToLoadout(Player player, HashMap loadout) { - this.inventoryToLoadout(player.getInventory(), loadout); - } - - public String updateTeamFromNamedParams(Team team, CommandSender commandSender, String[] arguments) { - try { - Map namedParams = new HashMap(); - for (String namedPair : arguments) { - String[] pairSplit = namedPair.split(":"); - if (pairSplit.length == 2) { - namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]); - } - } - - StringBuilder returnMessage = new StringBuilder(); - returnMessage.append(team.getTeamConfig().updateFromNamedParams(namedParams)); - - if (commandSender instanceof Player) { - Player player = (Player) commandSender; - if (namedParams.containsKey("loadout")) { - String loadoutName = namedParams.get("loadout"); - HashMap loadout = team.getInventories().getLoadouts().get(loadoutName); - if (loadout == null) { - loadout = new HashMap(); - team.getInventories().getLoadouts().put(loadoutName, loadout); - returnMessage.append(loadoutName + " respawn loadout added."); - } else { - returnMessage.append(loadoutName + " respawn loadout updated."); - } - this.inventoryToLoadout(player, loadout); - } - if (namedParams.containsKey("deleteloadout")) { - String loadoutName = namedParams.get("deleteloadout"); - if (team.getInventories().getLoadouts().keySet().contains(loadoutName)) { - team.getInventories().removeLoadout(loadoutName); - returnMessage.append(" " + loadoutName + " loadout removed."); - } else { - returnMessage.append(" " + loadoutName + " loadout not found."); - } - } - if (namedParams.containsKey("reward")) { - HashMap reward = new HashMap(); - this.inventoryToLoadout(player, reward); - team.getInventories().setReward(reward); - returnMessage.append(" game end reward updated."); - } - } - - return returnMessage.toString(); - } catch (Exception e) { - return "PARSE-ERROR"; - } - } - - public String updateZoneFromNamedParams(Warzone warzone, CommandSender commandSender, String[] arguments) { - try { - Map namedParams = new HashMap(); - for (String namedPair : arguments) { - String[] pairSplit = namedPair.split(":"); - if (pairSplit.length == 2) { - namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]); - } - } - - StringBuilder returnMessage = new StringBuilder(); - if (namedParams.containsKey("author")) { - for(String author : namedParams.get("author").split(",")) { - if (!author.equals("") && !warzone.getAuthors().contains(author)) { - warzone.addAuthor(author); - returnMessage.append(" author " + author + " added."); - } - } - } - if (namedParams.containsKey("deleteauthor")) { - for(String author : namedParams.get("deleteauthor").split(",")) { - if (warzone.getAuthors().contains(author)) { - warzone.getAuthors().remove(author); - returnMessage.append(" " + author + " removed from zone authors."); - } - } - } - - returnMessage.append(warzone.getWarzoneConfig().updateFromNamedParams(namedParams)); - returnMessage.append(warzone.getTeamDefaultConfig().updateFromNamedParams(namedParams)); - - if (commandSender instanceof Player) { - Player player = (Player) commandSender; - if (namedParams.containsKey("loadout")) { - String loadoutName = namedParams.get("loadout"); - HashMap loadout = warzone.getDefaultInventories().getLoadouts().get(loadoutName); - if (loadout == null) { - loadout = new HashMap(); - warzone.getDefaultInventories().getLoadouts().put(loadoutName, loadout); - returnMessage.append(loadoutName + " respawn loadout added."); - } else { - returnMessage.append(loadoutName + " respawn loadout updated."); - } - this.inventoryToLoadout(player, loadout); - } - if (namedParams.containsKey("deleteloadout")) { - String loadoutName = namedParams.get("deleteloadout"); - if (warzone.getDefaultInventories().getLoadouts().keySet().contains(loadoutName)) { - warzone.getDefaultInventories().removeLoadout(loadoutName); - returnMessage.append(" " + loadoutName + " loadout removed."); - } else { - returnMessage.append(" " + loadoutName + " loadout not found."); - } - } - if (namedParams.containsKey("reward")) { - HashMap reward = new HashMap(); - this.inventoryToLoadout(player, reward); - warzone.getDefaultInventories().setReward(reward); - returnMessage.append(" game end reward updated."); - } - } - - return returnMessage.toString(); - } catch (Exception e) { - return "PARSE-ERROR"; - } - } - - public String updateFromNamedParams(CommandSender commandSender, String[] arguments) { - try { - Map namedParams = new HashMap(); - for (String namedPair : arguments) { - String[] pairSplit = namedPair.split(":"); - if (pairSplit.length == 2) { - namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]); - } - } - - StringBuilder returnMessage = new StringBuilder(); - - returnMessage.append(this.getWarConfig().updateFromNamedParams(namedParams)); - returnMessage.append(this.getWarzoneDefaultConfig().updateFromNamedParams(namedParams)); - returnMessage.append(this.getTeamDefaultConfig().updateFromNamedParams(namedParams)); - - if (commandSender instanceof Player) { - Player player = (Player) commandSender; - if (namedParams.containsKey("loadout")) { - String loadoutName = namedParams.get("loadout"); - HashMap loadout = this.getDefaultInventories().getLoadouts().get(loadoutName); - if (loadout == null) { - loadout = new HashMap(); - this.getDefaultInventories().addLoadout(loadoutName, loadout); - returnMessage.append(loadoutName + " respawn loadout added."); - } else { - returnMessage.append(loadoutName + " respawn loadout updated."); - } - this.inventoryToLoadout(player, loadout); - } - if (namedParams.containsKey("deleteloadout")) { - String loadoutName = namedParams.get("deleteloadout"); - if (this.getDefaultInventories().getLoadouts().keySet().contains(loadoutName)) { - if (this.getDefaultInventories().getLoadouts().keySet().size() > 1) { - this.getDefaultInventories().removeLoadout(loadoutName); - returnMessage.append(" " + loadoutName + " loadout removed."); - } else { - returnMessage.append(" Can't remove only loadout."); - } - } else { - returnMessage.append(" " + loadoutName + " loadout not found."); - } - } - if (namedParams.containsKey("reward")) { - HashMap reward = new HashMap(); - this.inventoryToLoadout(player, reward); - this.getDefaultInventories().setReward(reward); - returnMessage.append(" game end reward updated."); - } - if (namedParams.containsKey("rallypoint")) { - String zoneName = namedParams.get("rallypoint"); - this.setZoneRallyPoint(zoneName, player); - returnMessage.append(" rallypoint set for zone " + zoneName + "."); - } - } - - return returnMessage.toString(); - } catch (Exception e) { - return "PARSE-ERROR"; - } - } - - public String printConfig(Team team) { - ChatColor teamColor = ChatColor.AQUA; - - ChatColor normalColor = ChatColor.WHITE; - - String teamConfigStr = ""; - InventoryBag invs = team.getInventories(); - teamConfigStr += getLoadoutsString(invs); - - for (TeamConfig teamConfig : TeamConfig.values()) { - Object value = team.getTeamConfig().getValue(teamConfig); - if (value != null) { - teamConfigStr += " " + teamConfig.toStringWithValue(value).replace(":", ":" + teamColor) + normalColor; - } - } - - return " ::" + teamColor + "Team " + team.getName() + teamColor + " config" + normalColor + "::" - + ifEmptyInheritedForTeam(teamConfigStr); - } - - private String getLoadoutsString(InventoryBag invs) { - String loadoutsString = ""; - ChatColor loadoutColor = ChatColor.GREEN; - ChatColor normalColor = ChatColor.WHITE; - - if (invs.hasLoadouts()) { - String loadouts = ""; - for (String loadoutName : invs.getLoadouts().keySet()) { - loadouts += loadoutName + ","; - } - loadoutsString += " loadout:" + loadoutColor + loadouts + normalColor; - } - - if (invs.hasReward()) { - loadoutsString += " reward:" + loadoutColor + "default" + normalColor; - } - - return loadoutsString; - } - - public String printConfig(Warzone zone) { - ChatColor teamColor = ChatColor.AQUA; - ChatColor zoneColor = ChatColor.DARK_AQUA; - ChatColor authorColor = ChatColor.GREEN; - ChatColor normalColor = ChatColor.WHITE; - - String warzoneConfigStr = ""; - for (WarzoneConfig warzoneConfig : WarzoneConfig.values()) { - Object value = zone.getWarzoneConfig().getValue(warzoneConfig); - if (value != null) { - warzoneConfigStr += " " + warzoneConfig.toStringWithValue(value).replace(":", ":" + zoneColor) + normalColor; - } - } - - String teamDefaultsStr = ""; - teamDefaultsStr += getLoadoutsString( zone.getDefaultInventories()); - for (TeamConfig teamConfig : TeamConfig.values()) { - Object value = zone.getTeamDefaultConfig().getValue(teamConfig); - if (value != null) { - teamDefaultsStr += " " + teamConfig.toStringWithValue(value).replace(":", ":" + teamColor) + normalColor; - } - } - - return "::" + zoneColor + "Warzone " + authorColor + zone.getName() + zoneColor + " config" + normalColor + "::" - + " author:" + authorColor + ifEmptyEveryone(zone.getAuthorsString()) + normalColor - + ifEmptyInheritedForWarzone(warzoneConfigStr) - + " ::" + teamColor + "Team defaults" + normalColor + "::" - + ifEmptyInheritedForWarzone(teamDefaultsStr); - } - - private String ifEmptyInheritedForWarzone(String maybeEmpty) { - if (maybeEmpty.equals("")) { - maybeEmpty = " all values inherited (see " + ChatColor.GREEN + "/warcfg -p)" + ChatColor.WHITE; - } - return maybeEmpty; - } - - private String ifEmptyInheritedForTeam(String maybeEmpty) { - if (maybeEmpty.equals("")) { - maybeEmpty = " all values inherited (see " + ChatColor.GREEN + "/warcfg -p" + ChatColor.WHITE - + " and " + ChatColor.GREEN + "/zonecfg -p" + ChatColor.WHITE + ")"; - } - return maybeEmpty; - } - - private String ifEmptyEveryone(String maybeEmpty) { - if (maybeEmpty.equals("")) { - maybeEmpty = "*"; - } - return maybeEmpty; - } - - public String printConfig() { - ChatColor teamColor = ChatColor.AQUA; - ChatColor zoneColor = ChatColor.DARK_AQUA; - ChatColor globalColor = ChatColor.DARK_GREEN; - ChatColor normalColor = ChatColor.WHITE; - - String warConfigStr = ""; - for (WarConfig warConfig : WarConfig.values()) { - warConfigStr += " " + warConfig.toStringWithValue(this.getWarConfig().getValue(warConfig)).replace(":", ":" + globalColor) + normalColor; - } - - String warzoneDefaultsStr = ""; - for (WarzoneConfig warzoneConfig : WarzoneConfig.values()) { - warzoneDefaultsStr += " " + warzoneConfig.toStringWithValue(this.getWarzoneDefaultConfig().getValue(warzoneConfig)).replace(":", ":" + zoneColor) + normalColor; - } - - String teamDefaultsStr = ""; - teamDefaultsStr += getLoadoutsString(this.getDefaultInventories()); - for (TeamConfig teamConfig : TeamConfig.values()) { - teamDefaultsStr += " " + teamConfig.toStringWithValue(this.getTeamDefaultConfig().getValue(teamConfig)).replace(":", ":" + teamColor) + normalColor; - } - - return normalColor + "::" + globalColor + "War config" + normalColor + "::" + warConfigStr - + normalColor + " ::" + zoneColor + "Warzone defaults" + normalColor + "::" + warzoneDefaultsStr - + normalColor + " ::" + teamColor + "Team defaults" + normalColor + "::" + teamDefaultsStr; - } - - private void setZoneRallyPoint(String warzoneName, Player player) { - Warzone zone = this.findWarzone(warzoneName); - if (zone == null) { - this.badMsg(player, "Can't set rally point. No such warzone."); - } else { - zone.setRallyPoint(player.getLocation()); - WarzoneYmlMapper.save(zone, false); - } - } - - public void addWarzone(Warzone zone) { - this.warzones.add(zone); - } - - public List getWarzones() { - return this.warzones; - } - - public void msg(CommandSender sender, String str) { - if (sender instanceof Player) { - String out = ChatColor.GRAY + "War> " + ChatColor.WHITE + this.colorKnownTokens(str, ChatColor.WHITE) + " "; - ChatFixUtil.sendMessage(sender, out); - } else { - sender.sendMessage("War> " + str); - } - } - - public void badMsg(CommandSender sender, String str) { - if (sender instanceof Player) { - String out = ChatColor.GRAY + "War> " + ChatColor.RED + this.colorKnownTokens(str, ChatColor.RED) + " "; - ChatFixUtil.sendMessage(sender, out); - } else { - sender.sendMessage("War> " + str); - } - } - - /** - * Colors the teams and examples in messages - * - * @param String - * str message-string - * @param String - * msgColor current message-color - * @return String Message with colored teams - */ - private String colorKnownTokens(String str, ChatColor msgColor) { - for (TeamKind kind : TeamKind.values()) { - str = str.replaceAll(" " + kind.toString(), " " + kind.getColor() + kind.toString() + msgColor); - } - str = str.replaceAll("Ex -", ChatColor.GRAY + "Ex -"); - return str; - } - - /** - * Logs a specified message with a specified level - * - * @param String - * str message to log - * @param Level - * lvl level to use - */ - public void log(String str, Level lvl) { - this.getLogger().log(lvl, "War> " + str); - } - - // the only way to find a zone that has only one corner - public Warzone findWarzone(String warzoneName) { - for (Warzone warzone : this.warzones) { - if (warzone.getName().toLowerCase().equals(warzoneName.toLowerCase())) { - return warzone; - } - } - for (Warzone warzone : this.incompleteZones) { - if (warzone.getName().equals(warzoneName)) { - return warzone; - } - } - return null; - } - - /** - * Checks whether the given player is allowed to play war. - * - * @param player Player to check - * @return true if the player may play war - */ - public boolean canPlayWar(Player player) { - return player.hasPermission("war.player"); - } - - /** - * Checks whether the given player is allowed to warp. - * - * @param player Player to check - * @return true if the player may warp - */ - public boolean canWarp(Player player) { - return player.hasPermission("war.warp"); - } - - /** - * Checks whether the given player is allowed to build outside zones - * - * @param player Player to check - * @return true if the player may build outside zones - */ - public boolean canBuildOutsideZone(Player player) { - if (this.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY)) { - return player.hasPermission("war.build"); - } else { - return true; - } - } - - /** - * Checks whether the given player is allowed to pvp outside zones - * - * @param player Player to check - * @return true if the player may pvp outside zones - */ - public boolean canPvpOutsideZones(Player player) { - if (this.getWarConfig().getBoolean(WarConfig.PVPINZONESONLY)) { - return player.hasPermission("war.pvp"); - } else { - return true; - } - } - - /** - * Checks whether the given player is a zone maker - * - * @param player Player to check - * @return true if the player is a zone maker - */ - public boolean isZoneMaker(Player player) { - // sort out disguised first - for (String disguised : this.zoneMakersImpersonatingPlayers) { - if (disguised.equals(player.getName())) { - return false; - } - } - - for (String zoneMaker : this.zoneMakerNames) { - if (zoneMaker.equals(player.getName())) { - return true; - } - } - - return player.hasPermission("war.zonemaker"); - } - - /** - * Checks whether the given player is a War admin - * - * @param player Player to check - * @return true if the player is a War admin - */ - public boolean isWarAdmin(Player player) { - return player.hasPermission("war.admin"); - } - - public void addWandBearer(Player player, String zoneName) { - if (this.wandBearers.containsKey(player.getName())) { - String alreadyHaveWand = this.wandBearers.get(player.getName()); - if (player.getInventory().first(Material.WOOD_SWORD) != -1) { - if (zoneName.equals(alreadyHaveWand)) { - this.badMsg(player, "You already have a wand for zone " + alreadyHaveWand + ". Drop the wooden sword first."); - } else { - // new zone, already have sword - this.wandBearers.remove(player.getName()); - this.wandBearers.put(player.getName(), zoneName); - this.msg(player, "Switched wand to zone " + zoneName + "."); - } - } else { - // lost his sword, or new warzone - if (zoneName.equals(alreadyHaveWand)) { - // same zone, give him a new sword - player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8)); - this.msg(player, "Here's a new sword for zone " + zoneName + "."); - } - } - } else { - if (player.getInventory().firstEmpty() == -1) { - this.badMsg(player, "Your inventory is full. Please drop an item and try again."); - } else { - this.wandBearers.put(player.getName(), zoneName); - player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8)); - // player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.WOOD_SWORD)); - this.msg(player, "You now have a wand for zone " + zoneName + ". Left-click with wodden sword for corner 1. Right-click for corner 2."); - } - } - } - - public boolean isWandBearer(Player player) { - return this.wandBearers.containsKey(player.getName()); - } - - public String getWandBearerZone(Player player) { - if (this.isWandBearer(player)) { - return this.wandBearers.get(player.getName()); - } - return ""; - } - - public void removeWandBearer(Player player) { - if (this.wandBearers.containsKey(player.getName())) { - this.wandBearers.remove(player.getName()); - } - } - - public Logger getLogger() { - return this.logger; - } - - public boolean isSpoutServer() { - return this.isSpoutServer; - } - - public Warzone zoneOfZoneWallAtProximity(Location location) { - for (Warzone zone : this.warzones) { - if (zone.getWorld() == location.getWorld() && zone.isNearWall(location)) { - return zone; - } - } - return null; - } - - public List getZoneMakerNames() { - return this.zoneMakerNames; - } - - public List getCommandWhitelist() { - return this.commandWhitelist; - } - - public boolean inAnyWarzoneLobby(Location location) { - if (ZoneLobby.getLobbyByLocation(location) == null) { - return false; - } - return true; - } - - public List getZoneMakersImpersonatingPlayers() { - return this.zoneMakersImpersonatingPlayers; - } - - public List getIncompleteZones() { - return this.incompleteZones; - } - - public WarHub getWarHub() { - return this.warHub; - } - - public void setWarHub(WarHub warHub) { - this.warHub = warHub; - } - - public boolean isLoaded() { - return this.loaded; - } - - public void setLoaded(boolean loaded) { - this.loaded = loaded; - } - - public HashMap getDisconnected() { - return this.disconnected; - } - - public void setDisconnected(HashMap disconnected) { - this.disconnected = disconnected; - } - - public InventoryBag getDefaultInventories() { - return defaultInventories; - } - - public List getDeadlyAdjectives() { - return deadlyAdjectives; - } - - public List getKillerVerbs() { - return killerVerbs; - } - - public TeamConfigBag getTeamDefaultConfig() { - return this.teamDefaultConfig ; - } - - public WarzoneConfigBag getWarzoneDefaultConfig() { - return this.warzoneDefaultConfig; - } - - public WarConfigBag getWarConfig() { - return this.warConfig; - } - - public SpoutMessenger getSpoutMessenger() { - return this.spoutMessenger ; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java deleted file mode 100644 index b69c97a..0000000 --- a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java +++ /dev/null @@ -1,461 +0,0 @@ -package bukkit.tommytony.war; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.inventory.ItemStack; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.player.SpoutPlayer; - -import com.tommytony.war.Bomb; -import com.tommytony.war.Cake; -import com.tommytony.war.FlagReturn; -import com.tommytony.war.Monument; -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; -import com.tommytony.war.config.WarConfig; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.spout.SpoutMessenger; - -/** - * - * @author tommytony - * - */ -public class WarBlockListener implements Listener { - - /** - * @see BlockListener.onBlockPlace() - */ - @EventHandler(event = BlockPlaceEvent.class) - public void onBlockPlace(final BlockPlaceEvent event) { - if (!War.war.isLoaded()) { - return; - } - - Player player = event.getPlayer(); - Block block = event.getBlock(); - if (player == null || block == null) { - return; - } - - Team team = Team.getTeamByPlayerName(player.getName()); - Warzone zone = Warzone.getZoneByLocation(player); - // Monument capturing - if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) { - Monument monument = zone.getMonumentFromCenterBlock(block); - if (monument != null && !monument.hasOwner()) { - monument.capture(team); - List teams = zone.getTeams(); - - if (War.war.isSpoutServer()) { - for (Player p : team.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "capped by " + team.getKind().getColor() + player.getName() + ChatColor.YELLOW + "!"), - team.getKind().getMaterial(), - team.getKind().getData(), - 10000); - } - } - } - for (Team t : teams) { - t.teamcast("Monument " + monument.getName() + " has been captured by team " + team.getName() + "."); - } - event.setCancelled(false); - return; // important otherwise cancelled down a few line by isImportantblock - } else { - War.war.badMsg(player, "You must capture a monument with a block of your team's wool color. Get one from your team spawn."); - cancelAndKeepItem(event); - return; - } - } - - boolean isZoneMaker = War.war.isZoneMaker(player); - // prevent build in important parts - if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) { - War.war.badMsg(player, "Can't build here."); - cancelAndKeepItem(event); - return; - } - - // protect warzone lobbies - for (Warzone wz : War.war.getWarzones()) { - if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) { - War.war.badMsg(player, "Can't build here."); - cancelAndKeepItem(event); - return; - } - } - - // protect the hub - if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) { - War.war.badMsg(player, "Can't build here."); - cancelAndKeepItem(event); - return; - } - - // buildInZonesOnly - if (zone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) { - if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) { - War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside."); - } - cancelAndKeepItem(event); - return; - } - - // can't place a block of your team's color - if (team != null && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) { - War.war.badMsg(player, "You can only use your team's blocks to capture monuments."); - cancelAndKeepItem(event); - return; - } - - // a flag thief can't drop his flag - if (team != null && zone != null && zone.isFlagThief(player.getName())) { - War.war.badMsg(player, "Can't drop the flag. What are you doing? Run!"); - cancelAndKeepItem(event); - return; - } - - // a bomb thief can't drop his bomb - if (team != null && zone != null && zone.isBombThief(player.getName())) { - War.war.badMsg(player, "Can't drop the bomb. What are you doing? Run for your enemy's spawn!"); - cancelAndKeepItem(event); - return; - } - - // a cake thief can't drop his cake - if (team != null && zone != null && zone.isCakeThief(player.getName())) { - War.war.badMsg(player, "Can't drop the cake. What are you doing? Run to your spawn!"); - cancelAndKeepItem(event); - return; - } - - // unbreakableZoneBlocks - if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) { - // if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks) - War.war.badMsg(player, "The blocks in this zone are unbreakable - this also means you can't build!"); - cancelAndKeepItem(event); - return; - } - } - - private void cancelAndKeepItem(BlockPlaceEvent event) { - event.setCancelled(true); - ItemStack inHand = event.getItemInHand(); - ItemStack newItemInHand = new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData()); - newItemInHand.setDurability(inHand.getDurability()); - event.getPlayer().setItemInHand(newItemInHand); - } - - @EventHandler(event = BlockPistonExtendEvent.class) - // Do not allow moving of block into or from important zones - public void onBlockPistonExtend(final BlockPistonExtendEvent event) { - Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation()); - if (zone!=null) { - for (Block b : event.getBlocks()) { - if (zone.isImportantBlock(b)) { - event.setCancelled(true); - return; - } - } - if (zone.isImportantBlock(event.getBlock().getRelative(event.getDirection(), event.getLength()+1))) { - event.setCancelled(true); - return; - } - } - } - - @EventHandler(event = BlockPistonRetractEvent.class) - public void onBlockPistonRetract(final BlockPistonRetractEvent event) { - Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation()); - if (zone!=null) { - Block b = event.getBlock().getRelative(event.getDirection(), 2); - if (zone.isImportantBlock(b)) { - event.setCancelled(true); - return; - } - } - } - - /** - * @see BlockListener.onBlockBreak() - */ - @EventHandler(event = BlockBreakEvent.class) - public void onBlockBreak(final BlockBreakEvent event) { - if (!War.war.isLoaded()) { - return; - } - Player player = event.getPlayer(); - Block block = event.getBlock(); - if (player != null && block != null) { - this.handleBreakOrDamage(player, block, event); - } - } - - @EventHandler(event = BlockDamageEvent.class) - public void onBlockDamage(final BlockDamageEvent event) { - if (!War.war.isLoaded()) { - return; - } - Player player = event.getPlayer(); - Block block = event.getBlock(); - Warzone playerZone = Warzone.getZoneByLocation(player); - if (player != null && block != null && playerZone != null && playerZone.getWarzoneConfig().getBoolean(WarzoneConfig.INSTABREAK)) { - Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())); - if (blockZone != null && blockZone == playerZone) { - event.setInstaBreak(true); - } - } - } - - private void handleBreakOrDamage(Player player, Block block, Cancellable event) { - Warzone warzone = Warzone.getZoneByLocation(player); - Team team = Team.getTeamByPlayerName(player.getName()); - boolean isZoneMaker = War.war.isZoneMaker(player); - - if (warzone != null && team == null && !isZoneMaker) { - // can't actually destroy blocks in a warzone if not part of a team - War.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team."); - event.setCancelled(true); - return; - } - // monument's center is destroyed - if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) { - Monument monument = warzone.getMonumentFromCenterBlock(block); - if (monument.hasOwner()) { - List teams = warzone.getTeams(); - Team ownerTeam = monument.getOwnerTeam(); - if (War.war.isSpoutServer()) { - for (Player p : team.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "freed by " + team.getKind().getColor() + player.getName() + ChatColor.YELLOW + "!"), - ownerTeam.getKind().getMaterial(), - ownerTeam.getKind().getData(), - 10000); - } - } - } - for (Team t : teams) { - t.teamcast("Team " + ownerTeam.getName() + " loses control of monument " + monument.getName()); - } - monument.uncapture(); - } - event.setCancelled(false); - return; - } - // changes in parts of important areas - if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) { - // breakage of spawn - if (team != null && team.getSpawnVolume().contains(block)) { - ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData()); - // let team members loot one block the spawn for monument captures - if (player.getInventory().contains(teamKindBlock)) { - War.war.badMsg(player, "You already have a " + team.getName() + " block."); - event.setCancelled(true); - return; - } else { - event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down - return; - } - } - // stealing of flag - if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) { - if (warzone.isFlagThief(player.getName())) { - // detect audacious thieves - War.war.badMsg(player, "You can only steal one flag at a time!"); - } else if (warzone.isBombThief(player.getName()) || warzone.isCakeThief(player.getName())) { - War.war.badMsg(player, "You can only steal one thing at a time!"); - } else { - Team lostFlagTeam = warzone.getTeamForFlagBlock(block); - if (lostFlagTeam.getPlayers().size() != 0) { - // player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air - ItemStack teamKindBlock = new ItemStack(lostFlagTeam.getKind().getMaterial(), 1, (short) 1, new Byte(lostFlagTeam.getKind().getData())); - player.getInventory().clear(); - player.getInventory().addItem(teamKindBlock); - warzone.addFlagThief(lostFlagTeam, player.getName()); - block.setType(Material.AIR); - - String spawnOrFlag = "spawn or flag"; - if (team.getTeamConfig().resolveFlagReturn().equals(FlagReturn.FLAG) - || team.getTeamConfig().resolveFlagReturn() == FlagReturn.SPAWN) { - spawnOrFlag = team.getTeamConfig().resolveFlagReturn().toString(); - } - - for (Team t : warzone.getTeams()) { - t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " stole team " + lostFlagTeam.getName() + "'s flag."); - if (t.getName().equals(lostFlagTeam.getName())) { - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " stole"), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "your flag!"), - lostFlagTeam.getKind().getMaterial(), - lostFlagTeam.getKind().getData(), - 5000); - } - } - } - t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE - + " from reaching team " + team.getName() + "'s " + spawnOrFlag + "."); - } - } - - - War.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team " + spawnOrFlag + " to capture it!"); - } else { - War.war.msg(player, "You can't steal team " + lostFlagTeam.getName() + "'s flag since no players are on that team."); - } - } - event.setCancelled(true); - return; - } else if (team != null && warzone.isBombBlock(block)) { - if (warzone.isBombThief(player.getName())) { - // detect audacious thieves - War.war.badMsg(player, "You can only steal one bomb at a time!"); - } else if (warzone.isFlagThief(player.getName()) || warzone.isCakeThief(player.getName())) { - War.war.badMsg(player, "You can only steal one thing at a time!"); - } else { - Bomb bomb = warzone.getBombForBlock(block); - // player just broke the bomb block: cancel to avoid drop, give player the block, set block to air - ItemStack tntBlock = new ItemStack(Material.TNT, 1, (short)8, (byte)8); - tntBlock.setDurability((short)8); - player.getInventory().clear(); - player.getInventory().addItem(tntBlock); - warzone.addBombThief(bomb, player.getName()); - block.setType(Material.AIR); - - for (Team t : warzone.getTeams()) { - t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " has bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.WHITE + "."); - - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " has "), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.YELLOW + "!"), - Material.TNT, - (short)0, - 5000); - } - } - } - - t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE - + " from reaching your spawn with the bomb!"); - } - - - War.war.msg(player, "You have bomb " + bomb.getName() + ". Reach another team's spawn to score. Don't get touched by anyone or you'll blow up!"); - } - - event.setCancelled(true); - return; - } else if (team != null && warzone.isCakeBlock(block)) { - if (warzone.isCakeThief(player.getName())) { - // detect audacious thieves - War.war.badMsg(player, "You can only steal one cake at a time!"); - } else if (warzone.isFlagThief(player.getName()) || warzone.isBombThief(player.getName())) { - War.war.badMsg(player, "You can only steal one thing at a time!"); - } else { - Cake cake = warzone.getCakeForBlock(block); - // player just broke the cake block: cancel to avoid drop, give player the block, set block to air - ItemStack cakeBlock = new ItemStack(Material.CAKE, 1, (short)8, (byte)8); - cakeBlock.setDurability((short)8); - player.getInventory().clear(); - player.getInventory().addItem(cakeBlock); - warzone.addCakeThief(cake, player.getName()); - block.setType(Material.AIR); - - for (Team t : warzone.getTeams()) { - t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " has cake " + ChatColor.GREEN + cake.getName() + ChatColor.WHITE + "."); - - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " has "), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "cake " + ChatColor.GREEN + cake.getName() + ChatColor.YELLOW + "!"), - Material.CAKE, - (short)0, - 5000); - } - } - } - - t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE - + " from reaching their spawn with the cake!"); - } - - - War.war.msg(player, "You have cake " + cake.getName() + ". Reach your team's spawn to score and replenish your lifepool."); - } - - event.setCancelled(true); - return; - } else if (!warzone.isMonumentCenterBlock(block)) { - War.war.badMsg(player, "Can't destroy this."); - event.setCancelled(true); - return; - } - } - - // protect warzone lobbies - if (block != null) { - for (Warzone zone : War.war.getWarzones()) { - if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) { - War.war.badMsg(player, "Can't destroy this."); - event.setCancelled(true); - return; - } - } - } - - // protect the hub - if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) { - War.war.badMsg(player, "Can't destroy this."); - event.setCancelled(true); - return; - } - - // buildInZonesOnly - Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())); - if (blockZone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) { - if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) { - War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside."); - } - event.setCancelled(true); - return; - } - - // unbreakableZoneBlocks - if (blockZone != null && blockZone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) { - // if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks - War.war.badMsg(player, "The blocks in this zone are unbreakable!"); - event.setCancelled(true); - return; - } - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java deleted file mode 100644 index 61fda8b..0000000 --- a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java +++ /dev/null @@ -1,140 +0,0 @@ -package bukkit.tommytony.war; - -import java.util.logging.Level; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; - -import bukkit.tommytony.war.command.*; - -/** - * Handles commands received by War - * - * @author Tim Düsterhus - * @package bukkit.tommytony.war - */ -public class WarCommandHandler { - - /** - * Handles a command - * - * @param sender - * The sender of the command - * @param cmd - * The command - * @param args - * The arguments - * @return Success - */ - public boolean handle(CommandSender sender, Command cmd, String[] args) { - String command = cmd.getName(); - String[] arguments = null; - - // parse prefixed commands - if ((command.equals("war") || command.equals("War")) && args.length > 0) { - command = args[0]; - arguments = new String[args.length - 1]; - for (int i = 1; i <= arguments.length; i++) { - arguments[i - 1] = args[i]; - } - - if (arguments.length == 1 && (arguments[0].equals("help") || arguments[0].equals("h"))) { - // show /war help - War.war.badMsg(sender, cmd.getUsage()); - return true; - } - } else if (command.equals("war") || command.equals("War")) { - // show /war help - War.war.msg(sender, cmd.getUsage()); - return true; - } else { - arguments = args; - } - - AbstractWarCommand commandObj = null; - try { - if (command.equals("warhub")) { - commandObj = new WarhubCommand(this, sender, arguments); - } else if (command.equals("zones") || command.equals("warzones")) { - commandObj = new WarzonesCommand(this, sender, arguments); - } else if (command.equals("zone") || command.equals("warzone")) { - commandObj = new WarzoneCommand(this, sender, arguments); - } else if (command.equals("teams")) { - commandObj = new TeamsCommand(this, sender, arguments); - } else if (command.equals("join")) { - commandObj = new JoinCommand(this, sender, arguments); - } else if (command.equals("leave")) { - commandObj = new LeaveCommand(this, sender, arguments); - } else if (command.equals("team")) { - commandObj = new TeamCommand(this, sender, arguments); - } else if (command.equals("setzone")) { - commandObj = new SetZoneCommand(this, sender, arguments); - } else if (command.equals("deletezone")) { - commandObj = new DeleteZoneCommand(this, sender, arguments); - } else if (command.equals("setzonelobby")) { - commandObj = new SetZoneLobbyCommand(this, sender, arguments); - } else if (command.equals("savezone")) { - commandObj = new SaveZoneCommand(this, sender, arguments); - } else if (command.equals("resetzone")) { - commandObj = new ResetZoneCommand(this, sender, arguments); - } else if (command.equals("nextbattle")) { - commandObj = new NextBattleCommand(this, sender, arguments); - } else if (command.equals("renamezone")) { - commandObj = new RenameZoneCommand(this, sender, arguments); - } else if (command.equals("setteam")) { - commandObj = new SetTeamCommand(this, sender, arguments); - } else if (command.equals("deleteteam")) { - commandObj = new DeleteTeamCommand(this, sender, arguments); - } else if (command.equals("setteamflag")) { - commandObj = new SetTeamFlagCommand(this, sender, arguments); - } else if (command.equals("deleteteamflag")) { - commandObj = new DeleteTeamFlagCommand(this, sender, arguments); - } else if (command.equals("setmonument")) { - commandObj = new SetMonumentCommand(this, sender, arguments); - } else if (command.equals("deletemonument")) { - commandObj = new DeleteMonumentCommand(this, sender, arguments); - } else if (command.equals("setbomb")) { - commandObj = new SetBombCommand(this, sender, arguments); - } else if (command.equals("deletebomb")) { - commandObj = new DeleteBombCommand(this, sender, arguments); - } else if (command.equals("setcake")) { - commandObj = new SetCakeCommand(this, sender, arguments); - } else if (command.equals("deletecake")) { - commandObj = new DeleteCakeCommand(this, sender, arguments); - }else if (command.equals("setteamconfig") || command.equals("teamcfg")) { - commandObj = new SetTeamConfigCommand(this, sender, arguments); - } else if (command.equals("setzoneconfig") || command.equals("zonecfg")) { - commandObj = new SetZoneConfigCommand(this, sender, arguments); - } else if (command.equals("setwarhub")) { - commandObj = new SetWarHubCommand(this, sender, arguments); - } else if (command.equals("deletewarhub")) { - commandObj = new DeleteWarhubCommand(this, sender, arguments); - } else if (command.equals("loadwar")) { - commandObj = new LoadWarCommand(this, sender, arguments); - } else if (command.equals("unloadwar")) { - commandObj = new UnloadWarCommand(this, sender, arguments); - } else if (command.equals("setwarconfig") || command.equals("warcfg")) { - commandObj = new SetWarConfigCommand(this, sender, arguments); - } else if (command.equals("zonemaker") || command.equals("zm")) { - commandObj = new ZoneMakerCommand(this, sender, arguments); - } - // we are not responsible for any other command - } catch (NotWarAdminException e) { - War.war.badMsg(sender, "You can't do this if you are not a War admin (permission war.admin)."); - } catch (NotZoneMakerException e) { - War.war.badMsg(sender, "You can't do this if you are not a warzone maker (permission war.zonemaker)."); - } catch (Exception e) { - War.war.log("An error occured while handling command " + cmd.getName() + ". Exception:" + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - - if(commandObj != null) { - boolean handled = commandObj.handle(); - if(!handled) { - War.war.badMsg(sender, cmd.getUsage()); - } - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java deleted file mode 100644 index 59ed570..0000000 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ /dev/null @@ -1,537 +0,0 @@ -package bukkit.tommytony.war; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.ContainerBlock; -import org.bukkit.block.NoteBlock; -import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.entity.CraftTNTPrimed; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; -import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.bukkit.inventory.ItemStack; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.player.SpoutPlayer; - -import com.tommytony.war.Bomb; -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.WarConfig; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.jobs.DeferredBlockResetsJob; -import com.tommytony.war.spout.SpoutMessenger; -import com.tommytony.war.utils.DeferredBlockReset; - -/** - * Handles Entity-Events - * - * @author tommytony, Tim Düsterhus - * @package bukkit.tommytony.war - */ -public class WarEntityListener implements Listener { - - private final Random killSeed = new Random(); - - /** - * Handles PVP-Damage - * - * @param event - * fired event - */ - private void handlerAttackDefend(EntityDamageByEntityEvent event) { - Entity attacker = event.getDamager(); - Entity defender = event.getEntity(); - - //DamageCause cause = event.getCause(); - //War.war.log(cause.toString(), Level.INFO); - // Maybe an arrow was thrown - if (attacker != null && event.getDamager() instanceof Projectile && ((Projectile)event.getDamager()).getShooter() instanceof Player){ - attacker = ((Player)((Projectile)event.getDamager()).getShooter()); - } - - if (attacker != null && defender != null && attacker instanceof Player && defender instanceof Player) { - // only let adversaries (same warzone, different team) attack each other - Player a = (Player) attacker; - Player d = (Player) defender; - Warzone attackerWarzone = Warzone.getZoneByPlayerName(a.getName()); - Team attackerTeam = Team.getTeamByPlayerName(a.getName()); - Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName()); - Team defenderTeam = Team.getTeamByPlayerName(d.getName()); - - if ((attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) - || (attackerTeam != null && defenderTeam != null && attacker.getEntityId() == defender.getEntityId())) { - // Make sure one of the players isn't in the spawn - if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn - if (!defenderWarzone.isFlagThief(d.getName()) - && !defenderWarzone.isBombThief(d.getName())) { // thieves can always be attacked - War.war.badMsg(a, "Can't attack a player that's inside his team's spawn."); - event.setCancelled(true); - return; - } - } else if (attackerTeam.getSpawnVolume().contains(a.getLocation()) && !attackerTeam.getSpawnVolume().contains(d.getLocation())) { - // only let a player inside spawn attack an enemy player if that player enters the spawn - if (!attackerWarzone.isFlagThief(a.getName()) - && !defenderWarzone.isBombThief(d.getName())) { // thieves can always attack - War.war.badMsg(a, "Can't attack a player from inside your spawn."); - event.setCancelled(true); - return; - } - // Make sure none of them are respawning - } else if (defenderWarzone.isRespawning(d)) { - War.war.badMsg(a, "The target is currently respawning!"); - event.setCancelled(true); - return; - } else if (attackerWarzone.isRespawning(a)) { - War.war.badMsg(a, "You can't attack while respawning!"); - event.setCancelled(true); - return; - } - - if (!attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.PVPINZONE)) { - // spleef-like, non-pvp, zone - event.setCancelled(true); - return; - } - - if (attackerTeam != null && defenderTeam != null && attacker.getEntityId() == defender.getEntityId()) { - War.war.badMsg(a, "You hit yourself!"); - } - - // Detect death, prevent it and respawn the player - if (event.getDamage() >= d.getHealth()) { - String killMessage = ""; - String attackerString = attackerTeam.getKind().getColor() + a.getName(); - String defenderString = defenderTeam.getKind().getColor() + d.getName(); - - if (attacker.getEntityId() != defender.getEntityId()) { - Material killerWeapon = a.getItemInHand().getType(); - String weaponString = killerWeapon.toString(); - if (killerWeapon == Material.AIR) { - weaponString = "hand"; - } else if (killerWeapon == Material.BOW || event.getDamager() instanceof Arrow) { - int rand = killSeed.nextInt(3); - if (rand == 0) { - weaponString = "arrow"; - } else if (rand == 1) { - weaponString = "bow"; - } else { - weaponString = "aim"; - } - - } else if (event.getDamager() instanceof Projectile) { - weaponString = "aim"; - } - - String adjectiveString = War.war.getDeadlyAdjectives().get(this.killSeed.nextInt(War.war.getDeadlyAdjectives().size())); - String verbString = War.war.getKillerVerbs().get(this.killSeed.nextInt(War.war.getKillerVerbs().size())); - - killMessage = attackerString + ChatColor.WHITE + "'s " + adjectiveString + weaponString.toLowerCase().replace('_', ' ') - + " " + verbString + " " + defenderString; - } else { - killMessage = defenderString + ChatColor.WHITE + " committed accidental suicide"; - } - - for (Team team : defenderWarzone.getTeams()) { - team.teamcast(killMessage); - } - defenderWarzone.handleDeath(d); - - event.setCancelled(true); - } else if (defenderWarzone.isBombThief(d.getName()) && d.getLocation().distance(a.getLocation()) < 2) { - Bomb bomb = defenderWarzone.getBombForThief(d.getName()); - - // Kill the bomber - defenderWarzone.handleDeath(d); - - // blow up bomb man if attacker is close enough - defenderWarzone.getWorld().createExplosion(a.getLocation(), 2F); - - // Notify everyone - for (Team t : defenderWarzone.getTeams()) { - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(attackerTeam.getKind().getColor() + a.getName() + ChatColor.YELLOW + " made "), - SpoutMessenger.cleanForNotification(defenderTeam.getKind().getColor() + d.getName() + ChatColor.YELLOW + " blow up!"), - Material.TNT, - (short)0, - 10000); - } - } - } - - // bring back tnt - bomb.getVolume().resetBlocks(); - bomb.addBombBlocks(); - - t.teamcast(attackerTeam.getKind().getColor() + a.getName() + ChatColor.WHITE - + " made " + defenderTeam.getKind().getColor() + d.getName() + ChatColor.WHITE + " blow up!"); - } - } - } else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) { - // same team, but not same person - if (attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.FRIENDLYFIRE)) { - War.war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through - } else { - War.war.badMsg(a, "Your attack missed! Your target is on your team."); - event.setCancelled(true); // ff is off - } - } else if (attackerTeam == null && defenderTeam == null && War.war.canPvpOutsideZones(a)) { - // let normal PVP through is its not turned off or if you have perms - } else if (attackerTeam == null && defenderTeam == null && !War.war.canPvpOutsideZones(a)) { - if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE)) { - War.war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones."); - } - event.setCancelled(true); // global pvp is off - } else { - War.war.badMsg(a, "Your attack missed!"); - if (attackerTeam == null) { - War.war.badMsg(a, "You must join a team, then you'll be able to damage people " + "in the other teams in that warzone."); - } else if (defenderTeam == null) { - War.war.badMsg(a, "Your target is not in a team."); - } else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) { - // You just hit yourself, probably with a bouncing arrow - } else if (attackerTeam == defenderTeam) { - War.war.badMsg(a, "Your target is on your team."); - } else if (attackerWarzone != defenderWarzone) { - War.war.badMsg(a, "Your target is playing in another warzone."); - } - event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team - } - } else if (defender instanceof Player) { - // attacked by dispenser arrow most probably - // Detect death, prevent it and respawn the player - Player d = (Player) defender; - Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName()); - if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) { - String deathMessage = ""; - String defenderString = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getName(); - - if (event.getDamager() instanceof CraftTNTPrimed) { - deathMessage = defenderString + ChatColor.WHITE + " exploded"; - } else { - deathMessage = defenderString + ChatColor.WHITE + " died"; - } - for (Team team : defenderWarzone.getTeams()) { - team.teamcast(deathMessage); - } - defenderWarzone.handleDeath(d); - event.setCancelled(true); - } - } - } - - /** - * Protects important structures from explosions - * - * @see EntityListener.onEntityExplode() - */ - @EventHandler(event = EntityExplodeEvent.class) - public void onEntityExplode(final EntityExplodeEvent event) { - if (!War.war.isLoaded()) { - return; - } - // protect zones elements, lobbies and warhub from creepers and tnt - List explodedBlocks = event.blockList(); - List dontExplode = new ArrayList(); - - boolean explosionInAWarzone = event.getEntity() != null && Warzone.getZoneByLocation(event.getEntity().getLocation()) != null; - - if (!explosionInAWarzone && War.war.getWarConfig().getBoolean(WarConfig.TNTINZONESONLY) && event.getEntity() instanceof TNTPrimed) { - // if tntinzonesonly:true, no tnt blows up outside zones - event.setCancelled(true); - return; - } - - for (Block block : explodedBlocks) { - if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) { - dontExplode.add(block); - } else { - boolean inOneZone = false; - for (Warzone zone : War.war.getWarzones()) { - if (zone.isImportantBlock(block)) { - dontExplode.add(block); - if (zone.isBombBlock(block)) { - // tnt doesn't get reset like normal blocks, gotta schedule a later reset just for the Bomb - // structure's tnt block - DeferredBlockResetsJob job = new DeferredBlockResetsJob(block.getWorld()); - job.add(new DeferredBlockReset(block.getX(), block.getY(), block.getZ(), Material.TNT.getId(), (byte)0)); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, 10); - } - inOneZone = true; - break; - } else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) { - dontExplode.add(block); - inOneZone = true; - break; - } else if (zone.getVolume().contains(block)) { - inOneZone = true; - } - } - - if (!inOneZone && explosionInAWarzone) { - // if the explosion originated in warzone, always rollback - dontExplode.add(block); - } - } - } - - int dontExplodeSize = dontExplode.size(); - if (dontExplode.size() > 0) { - // Reset the exploded blocks that shouldn't have exploded (some of these are zone artifacts, if rollbackexplosion some may be outside-of-zone blocks - DeferredBlockResetsJob job = new DeferredBlockResetsJob(dontExplode.get(0).getWorld()); - List doors = new ArrayList(); - for (Block dont : dontExplode) { - DeferredBlockReset deferred = null; - if (dont.getState() instanceof Sign) { - String[] lines = ((Sign)dont.getState()).getLines(); - deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), lines); - } else if (dont.getState() instanceof ContainerBlock) { - ItemStack[] contents = ((ContainerBlock)dont.getState()).getInventory().getContents(); - Block worldBlock = dont.getWorld().getBlockAt(dont.getLocation()); - if (worldBlock.getState() instanceof ContainerBlock) { - ((ContainerBlock)worldBlock.getState()).getInventory().clear(); - } - deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), copyItems(contents)); - } else if (dont.getTypeId() == Material.NOTE_BLOCK.getId()) { - Block worldBlock = dont.getWorld().getBlockAt(dont.getLocation()); - if (worldBlock.getState() instanceof NoteBlock) { - NoteBlock noteBlock = ((NoteBlock)worldBlock.getState()); - if (noteBlock != null) { - deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), noteBlock.getRawNote()); - } - } - } else if (dont.getTypeId() != Material.TNT.getId()) { - deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData()); - if (dont.getTypeId() == Material.WOODEN_DOOR.getId() || dont.getTypeId() == Material.IRON_DOOR_BLOCK.getId()) { - doors.add(dont); - } - } - if (deferred != null) { - job.add(deferred); - } - } - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - - // Changed explosion yield following proportion of explosion prevention (makes drops less buggy too) - int explodedSize = explodedBlocks.size(); - float middleYeild = (float)(explodedSize - dontExplodeSize) / (float)explodedSize; - float newYeild = middleYeild * event.getYield(); - - event.setYield(newYeild); - } - } - - private List copyItems(ItemStack[] contents) { - List list = new ArrayList(); - for (ItemStack stack : contents) { - if (stack != null) { - if (stack.getData() != null) { - list.add(new ItemStack(stack.getType(), stack.getAmount(), stack.getDurability(), stack.getData().getData())); - } else { - list.add(new ItemStack(stack.getType(), stack.getAmount(), stack.getDurability())); - } - } - } - return list; - } - - /** - * Handles damage on Players - * - * @see EntityListener.onEntityDamage() - */ - @EventHandler(event = EntityDamageEvent.class) - public void onEntityDamage(final EntityDamageEvent event) { - if (!War.war.isLoaded()) { - return; - } - - Entity entity = event.getEntity(); - if (!(entity instanceof Player)) { - return; - } - Player player = (Player) entity; - - // prevent godmode - if (Warzone.getZoneByPlayerName(player.getName()) != null) { - event.setCancelled(false); - } - - // pass pvp-damage - if (event instanceof EntityDamageByEntityEvent) { - this.handlerAttackDefend((EntityDamageByEntityEvent) event); - } else { - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - - if (zone != null && event.getDamage() >= player.getHealth()) { - // Detect death, prevent it and respawn the player - String deathMessage = ""; - String cause = " died"; - if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK - || event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.LIGHTNING) { - cause = " burned to a crisp"; - } else if (event.getCause() == DamageCause.DROWNING) { - cause = " drowned"; - } else if (event.getCause() == DamageCause.FALL) { - cause = " fell to an untimely death"; - } - deathMessage = Team.getTeamByPlayerName(player.getName()).getKind().getColor() + player.getName() + ChatColor.WHITE + cause; - for (Team team : zone.getTeams()) { - team.teamcast(deathMessage); - } - zone.handleDeath(player); - event.setCancelled(true); - } - } - } - - @EventHandler(event = EntityCombustEvent.class) - public void onEntityCombust(final EntityCombustEvent event) { - if (!War.war.isLoaded()) { - return; - } - Entity entity = event.getEntity(); - if (entity instanceof Player) { - Player player = (Player) entity; - Team team = Team.getTeamByPlayerName(player.getName()); - if (team != null && team.getSpawnVolume().contains(player.getLocation())) { - // smother out the fire that didn't burn out when you respawned - // Stop fire (upcast, watch out!) - if (player instanceof CraftPlayer) { - net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle(); - playerEntity.fireTicks = 0; - } - event.setCancelled(true); - } - } - } - - /** - * Prevents creatures from spawning in warzones if no creatures is active - * - * @see EntityListener.onCreatureSpawn() - */ - @EventHandler(event = CreatureSpawnEvent.class) - public void onCreatureSpawn(final CreatureSpawnEvent event) { - if (!War.war.isLoaded()) { - return; - } - - Location location = event.getLocation(); - Warzone zone = Warzone.getZoneByLocation(location); - if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.NOCREATURES)) { - event.setCancelled(true); - } - } - - /** - * Prevents health regaining caused by peaceful mode - * - * @see EntityListener.onEntityRegainHealth() - */ - @EventHandler(event = EntityRegainHealthEvent.class) - public void onEntityRegainHealth(final EntityRegainHealthEvent event) { - if (!War.war.isLoaded() || - (event.getRegainReason() != RegainReason.REGEN - && event.getRegainReason() != RegainReason.EATING - && event.getRegainReason().toString() != "SATIATED")) { - return; - } - - Entity entity = event.getEntity(); - if (!(entity instanceof Player)) { - return; - } - - Player player = (Player) entity; - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - if (zone != null) { - Team team = Team.getTeamByPlayerName(player.getName()); - if ((event.getRegainReason() == RegainReason.EATING - || event.getRegainReason().toString() != "SATIATED" ) - && team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)) { - // noHunger setting means you can't auto-heal with full hunger bar (use saturation instead to control how fast you get hungry) - event.setCancelled(true); - } else if (event.getRegainReason() == RegainReason.REGEN) { - // disable peaceful mode regen - event.setCancelled(true); - } - } - } - - @EventHandler(event = FoodLevelChangeEvent.class) - public void onFoodLevelChange(final FoodLevelChangeEvent event) { - if (!War.war.isLoaded() || !(event.getEntity() instanceof Player)) { - return; - } - - Player player = (Player) event.getEntity(); - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - Team team = Team.getTeamByPlayerName(player.getName()); - if (zone != null && team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)){ - event.setCancelled(true); - } - } - - @EventHandler(event = EntityDeathEvent.class) - public void onEntityDeath(final EntityDeathEvent event) { - if (!War.war.isLoaded() || !(event.getEntity() instanceof Player)) { - return; - } - - Player player = (Player) event.getEntity(); - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - if (zone != null) { - event.getDrops().clear(); - zone.handleDeath(player); - - for (Team team : zone.getTeams()) { - team.teamcast(player.getName() + " died"); - } - } - } - - @EventHandler(event = ExplosionPrimeEvent.class) - public void onExplosionPrime(final ExplosionPrimeEvent event) { - if (!War.war.isLoaded()) { - return; - } - - Location eventLocation = event.getEntity().getLocation(); - - for (Warzone zone : War.war.getWarzones()) { - if (zone.isBombBlock(eventLocation.getBlock())) { - // prevent the Bomb from exploding on its pedestral - event.setCancelled(true); - return; - } - } - } - -} diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java deleted file mode 100644 index 9b5344a..0000000 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ /dev/null @@ -1,767 +0,0 @@ -package bukkit.tommytony.war; - -import java.util.HashMap; -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.entity.CraftItem; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.event.Event.Result; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerInventoryEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.player.SpoutPlayer; - -import com.tommytony.war.Bomb; -import com.tommytony.war.Cake; -import com.tommytony.war.FlagReturn; -import com.tommytony.war.LoadoutSelection; -import com.tommytony.war.Team; -import com.tommytony.war.WarHub; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.ZoneSetter; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.spout.SpoutMessenger; - -/** - * @author tommytony, Tim Düsterhus - * @package bukkit.tommytony.war - */ -public class WarPlayerListener implements Listener { - private java.util.Random random = new java.util.Random(); - private HashMap latestLocations = new HashMap(); - - /** - * Correctly removes quitting players from warzones - * - * @see PlayerListener.onPlayerQuit() - */ - @EventHandler(event = PlayerQuitEvent.class) - public void onPlayerQuit(final PlayerQuitEvent event) { - if (War.war.isLoaded()) { - Player player = event.getPlayer(); - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - if (zone != null) { - zone.handlePlayerLeave(player, zone.getTeleport(), true); - } - - if (War.war.isWandBearer(player)) { - War.war.removeWandBearer(player); - } - } - } - - @EventHandler(event = PlayerDropItemEvent.class) - public void onPlayerDropItem(final PlayerDropItemEvent event) { - if (War.war.isLoaded()) { - Player player = event.getPlayer(); - Team team = Team.getTeamByPlayerName(player.getName()); - if (team != null) { - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - - if (zone.isFlagThief(player.getName())) { - // a flag thief can't drop his flag - War.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!"); - event.setCancelled(true); - } else if (zone.isBombThief(player.getName())) { - // a bomb thief can't drop his bomb - War.war.badMsg(player, "Can't drop items while stealing bomb. What are you doing?! Run for your enemy's spawn!"); - event.setCancelled(true); - } else if (zone.isCakeThief(player.getName())) { - // a cake thief can't drop his cake - War.war.badMsg(player, "Can't drop items while stealing cake. What are you doing?! Run!"); - event.setCancelled(true); - } else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.NODROPS)) { - War.war.badMsg(player, "Can't drop items in this warzone."); - event.setCancelled(true); - } else { - Item item = event.getItemDrop(); - if (item != null) { - ItemStack itemStack = item.getItemStack(); - if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) { - // Can't drop your team's kind block - War.war.badMsg(player, "Can't drop " + team.getName() + " blocks."); - event.setCancelled(true); - return; - } - - if (zone.isNearWall(player.getLocation()) && itemStack != null) { - War.war.badMsg(player, "Can't drop items near the zone border!"); - event.setCancelled(true); - return; - } - - if (zone.getLoadoutSelections().keySet().contains(player.getName()) - && zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) { - // still at spawn - War.war.badMsg(player, "Can't drop items while still in spawn."); - event.setCancelled(true); - return; - } - } - } - } - - if (War.war.isWandBearer(player)) { - Item item = event.getItemDrop(); - if (item.getItemStack().getType() == Material.WOOD_SWORD) { - String zoneName = War.war.getWandBearerZone(player); - War.war.removeWandBearer(player); - War.war.msg(player, "You dropped the zone " + zoneName + " wand."); - } - } - } - } - - @EventHandler(event = PlayerPickupItemEvent.class) - public void onPlayerPickupItem(final PlayerPickupItemEvent event) { - if (War.war.isLoaded()) { - Player player = event.getPlayer(); - Team team = Team.getTeamByPlayerName(player.getName()); - if (team != null) { - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - - if (zone.isFlagThief(player.getName())) { - // a flag thief can't pick up anything - event.setCancelled(true); - } else { - Item item = event.getItem(); - if (item != null && item instanceof CraftItem) { - CraftItem cItem = (CraftItem) item; - if (cItem != null) { - ItemStack itemStack = cItem.getItemStack(); - if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) { - // Can't pick up a second precious block - event.setCancelled(true); - return; - } - } - } - } - } - } - } - - @EventHandler(event = PlayerInventoryEvent.class) - public void onInventoryOpen(final PlayerInventoryEvent event) { - if (War.war.isLoaded()) { - Player player = event.getPlayer(); - Inventory inventory = event.getInventory(); - Team team = Team.getTeamByPlayerName(player.getName()); - if (team != null && inventory instanceof PlayerInventory) { - // make sure the player doesn't have too many precious blocks - // or illegal armor (i.e. armor not found in loadout) - PlayerInventory playerInv = (PlayerInventory) inventory; - ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData()); - if (playerInv.contains(teamKindBlock, 2)) { - playerInv.remove(teamKindBlock); - playerInv.addItem(teamKindBlock); - War.war.badMsg(player, "All that " + team.getName() + " must have been heavy!"); - } - } - } - } - - @EventHandler(event = PlayerCommandPreprocessEvent.class) - public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) { - if (War.war.isLoaded()) { - Player player = event.getPlayer(); - Team talkingPlayerTeam = Team.getTeamByPlayerName(player.getName()); - if (talkingPlayerTeam != null) { - String msg = event.getMessage(); - String[] split = msg.split(" "); - if (!War.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) { - String command = split[0].substring(1); - if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) { - // allow white commands - for (String whiteCommand : War.war.getCommandWhitelist()) { - if (whiteCommand.equals(command)) { - return; - } - } - - War.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone."); - event.setCancelled(true); - } - } - } - } - } - - @EventHandler(event = PlayerKickEvent.class) - public void onPlayerKick(final PlayerKickEvent event) { - if (War.war.isLoaded()) { - Player player = event.getPlayer(); - String reason = event.getReason(); - if (reason.contains("moved") || reason.contains("too quickly") || reason.contains("Hacking")) { - boolean inWarzone = Warzone.getZoneByLocation(player) != null; - boolean inLobby = ZoneLobby.getLobbyByLocation(player) != null; - boolean inWarhub = false; - if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(player.getLocation())) { - inWarhub = true; - } - if (inWarzone || inLobby || inWarhub) { - event.setCancelled(true); - War.war.log("Prevented " + player.getName() + " from getting kicked.", java.util.logging.Level.WARNING); - } - } - } - } - - @EventHandler(event = PlayerInteractEvent.class) - public void onPlayerInteract(PlayerInteractEvent event) { - if (War.war.isLoaded()) { - Player player = event.getPlayer(); - if (player.getItemInHand().getType() == Material.WOOD_SWORD && War.war.isWandBearer(player)) { - String zoneName = War.war.getWandBearerZone(player); - ZoneSetter setter = new ZoneSetter(player, zoneName); - if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) { - War.war.badMsg(player, "Too far."); - } else if (event.getAction() == Action.LEFT_CLICK_BLOCK) { - setter.placeCorner1(event.getClickedBlock()); - event.setUseItemInHand(Result.ALLOW); - } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - setter.placeCorner2(event.getClickedBlock()); - event.setUseItemInHand(Result.ALLOW); - } - } - - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - if (zone != null && zone.getLoadoutSelections().containsKey(player.getName()) - && zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) { - event.setUseItemInHand(Result.DENY); - War.war.badMsg(player, "Can't use items while still in spawn."); - - ItemStack inHand = event.getItem(); - - if (inHand != null) { - ItemStack newItemInHand = new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData()); - newItemInHand.setDurability(inHand.getDurability()); - event.getPlayer().setItemInHand(newItemInHand); - - event.setCancelled(true); - } - } - } - } - - @EventHandler(event = PlayerMoveEvent.class) - public void onPlayerMove(final PlayerMoveEvent event) { - if (!War.war.isLoaded()) { - return; - } - - Player player = event.getPlayer(); - Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result. - - Location previousLocation = latestLocations.get(player.getName()); - if (previousLocation != null && - playerLoc.getBlockX() == previousLocation.getBlockX() && - playerLoc.getBlockY() == previousLocation.getBlockY() && - playerLoc.getBlockZ() == previousLocation.getBlockZ() && - playerLoc.getWorld() == previousLocation.getWorld()) { - // we only care when people change location - return; - } - latestLocations.put(player.getName(), playerLoc); - - Warzone locZone = Warzone.getZoneByLocation(playerLoc); - ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc); - - boolean canPlay = War.war.canPlayWar(player); - boolean isMaker = War.war.isZoneMaker(player); - - // Zone walls - Team currentTeam = Team.getTeamByPlayerName(player.getName()); - Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone - boolean protecting = false; - if (currentTeam != null) { - if (playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS)) { - protecting = playerWarzone.protectZoneWallAgainstPlayer(player); - } - } else { - Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc); - if (nearbyZone != null && nearbyZone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS) && !isMaker) { - protecting = nearbyZone.protectZoneWallAgainstPlayer(player); - } - } - - if (!protecting) { - // zone makers still need to delete their walls - // make sure to delete any wall guards as you leave - for (Warzone zone : War.war.getWarzones()) { - zone.dropZoneWallGuardIfAny(player); - } - } - - // Warzone lobby gates - if (locLobby != null) { - Warzone zone = locLobby.getZone(); - Team oldTeam = Team.getTeamByPlayerName(player.getName()); - boolean isAutoAssignGate = false; - if (oldTeam == null && canPlay) { // trying to counter spammy player move - isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc); - if (isAutoAssignGate) { - if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) { - this.handleDisabledZone(event, player, zone); - } else { - this.dropFromOldTeamIfAny(player); - int noOfPlayers = 0; - int totalCap = 0; - for (Team t : zone.getTeams()) { - noOfPlayers += t.getPlayers().size(); - totalCap += t.getTeamConfig().resolveInt(TeamConfig.MAXSCORE); - } - - if (noOfPlayers < totalCap) { - zone.autoAssign(player); - - if (War.war.getWarHub() != null) { - War.war.getWarHub().resetZoneSign(zone); - } - } else { - event.setTo(zone.getTeleport()); - // player.teleport(zone.getTeleport()); - War.war.badMsg(player, "All teams are full."); - } - } - return; - } - - // go through all the team gates - for (Team team : zone.getTeams()) { - if (zone.getLobby().isInTeamGate(team, playerLoc)) { - this.dropFromOldTeamIfAny(player); - if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) { - this.handleDisabledZone(event, player, zone); - } else if (team.getPlayers().size() < team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE)) { - team.addPlayer(player); - team.resetSign(); - if (War.war.getWarHub() != null) { - War.war.getWarHub().resetZoneSign(zone); - } - zone.keepPlayerState(player); - War.war.msg(player, "Your inventory is in storage until you exit with '/war leave'."); - zone.respawnPlayer(event, team, player); - for (Team t : zone.getTeams()) { - t.teamcast("" + player.getName() + " joined team " + team.getName() + "."); - } - } else { - event.setTo(zone.getTeleport()); - War.war.badMsg(player, "Team " + team.getName() + " is full."); - } - return; - } - } - - if (War.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) && !War.war.getWarHub().getVolume().contains(player.getLocation())) { - this.dropFromOldTeamIfAny(player); - event.setTo(War.war.getWarHub().getLocation()); - // player.teleport(war.getWarHub().getLocation()); - War.war.msg(player, "Welcome to the War hub."); - return; - } - } - - } - - // Warhub zone gates - WarHub hub = War.war.getWarHub(); - if (hub != null && hub.getVolume().contains(player.getLocation())) { - Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc); - if (zone != null && zone.getTeleport() != null) { - event.setTo(zone.getTeleport()); - // player.teleport(zone.getTeleport()); - War.war.msg(player, "Welcome to warzone " + zone.getName() + "."); - return; - } - } - - boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc); - Team playerTeam = Team.getTeamByPlayerName(player.getName()); - if (isLeaving) { // already in a team and in warzone, leaving - // same as leave - if (playerTeam != null) { - boolean atSpawnAlready = playerTeam.getTeamSpawn().getBlockX() == player.getLocation().getBlockX() && playerTeam.getTeamSpawn().getBlockY() == player.getLocation().getBlockY() && playerTeam.getTeamSpawn().getBlockZ() == player.getLocation().getBlockZ(); - if (!atSpawnAlready) { - playerWarzone.handlePlayerLeave(player, playerWarzone.getTeleport(), event, true); - return; - } - } - } - - if (playerWarzone != null) { - // Player belongs to a warzone team but is outside: he snuck out or is at spawn and died - if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) { - List nearestWalls = playerWarzone.getNearestWalls(playerLoc); - War.war.badMsg(player, "Use /leave (or /war leave) to exit the zone."); - if(nearestWalls != null && nearestWalls.size() > 0) { - // First, try to bump the player back in - int northSouthMove = 0; - int eastWestMove = 0; - int upDownMove = 0; - int moveDistance = 1; - - if (nearestWalls.contains(BlockFace.NORTH)) { - // move south - northSouthMove += moveDistance; - } else if (nearestWalls.contains(BlockFace.SOUTH)) { - // move north - northSouthMove -= moveDistance; - } - - if (nearestWalls.contains(BlockFace.EAST)) { - // move west - eastWestMove += moveDistance; - } else if (nearestWalls.contains(BlockFace.WEST)) { - // move east - eastWestMove -= moveDistance; - } - - if (nearestWalls.contains(BlockFace.UP)) { - upDownMove -= moveDistance; - } else if (nearestWalls.contains(BlockFace.DOWN)) { - // fell off the map, back to spawn - event.setTo(playerTeam.getTeamSpawn()); - return; - } - - event.setTo(new Location(playerLoc.getWorld(), - playerLoc.getX() + northSouthMove, - playerLoc.getY() + upDownMove, - playerLoc.getZ() + eastWestMove, - playerLoc.getYaw(), - playerLoc.getPitch())); - return; - } else { - // Otherwise, send him to spawn - event.setTo(playerTeam.getTeamSpawn()); - return; - } - } - - if (!playerTeam.getSpawnVolume().contains(playerLoc)) { - if (!playerWarzone.isEnoughPlayers()) { - War.war.badMsg(player, "Can't leave spawn until there's a minimum of " + playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINPLAYERS) - +" player(s) on at least " + playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINTEAMS) + " team(s)."); - event.setTo(playerTeam.getTeamSpawn()); - return; - } - if (playerWarzone.isRespawning(player)) { - int rt = playerTeam.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER); - String isS = "s"; - if (rt==1) isS = ""; - War.war.badMsg(player, "Can't leave spawn for "+rt+" second"+isS+" after spawning!"); - event.setTo(playerTeam.getTeamSpawn()); - return; - } - } - - // Monuments - if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead - && this.random.nextInt(7) == 3) { // one chance out of many of getting healed - int currentHp = player.getHealth(); - int newHp = Math.min(20, currentHp + locZone.getWarzoneConfig().getInt(WarzoneConfig.MONUMENTHEAL)); - - player.setHealth(newHp); - String isS = "s"; - String heartNum = ""; // since (newHp-currentHp)/2 won't give the right amount - if (newHp - currentHp == 2) { // no 's' in 'hearts' when it's just one heart - isS = ""; - heartNum = "one "; - } else if (newHp - currentHp % 2 == 0) { - heartNum = ((newHp - currentHp) / 2) + " "; - } else { - heartNum = ((newHp - currentHp - 1) / 2) + ".5 "; - } - War.war.msg(player, "Your dance pleases the monument's voodoo. You gain " + heartNum + "heart" + isS + "!"); - return; - } - - // Flag capture - if (playerWarzone.isFlagThief(player.getName())) { - boolean inSpawn = playerTeam.getSpawnVolume().contains(player.getLocation()); - boolean inFlag = (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())); - - if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.BOTH)) { - if (!inSpawn && !inFlag) { - return; - } - } else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.SPAWN)) { - if (inFlag) { - War.war.badMsg(player, "You have to capture the enemy flag at your team's spawn."); - return; - } else if (!inSpawn) { - return; - } - } else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.FLAG)) { - if (inSpawn) { - War.war.badMsg(player, "You have to capture the enemy flag at your team's flag."); - return; - } else if (!inFlag) { - return; - } - } - - if (playerWarzone.isTeamFlagStolen(playerTeam) && playerTeam.getTeamConfig().resolveBoolean(TeamConfig.FLAGMUSTBEHOME)) { - War.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned."); - } else { - // flags can be captured at own spawn or own flag pole - playerTeam.addPoint(); - Team victim = playerWarzone.getVictimTeamForFlagThief(player.getName()); - - // Notify everyone - for (Team t : playerWarzone.getTeams()) { - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " captured"), - SpoutMessenger.cleanForNotification(victim.getKind().getColor() + victim.getName() + ChatColor.YELLOW + " flag!"), - victim.getKind().getMaterial(), - victim.getKind().getData(), - 10000); - } - } - } - t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE - + " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point."); - } - - // Detect win conditions - if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) { - if (playerWarzone.hasPlayerState(player.getName())) { - playerWarzone.restorePlayerState(player); - } - playerWarzone.handleScoreCapReached(player, playerTeam.getName()); - event.setTo(playerWarzone.getTeleport()); - } else { - // just added a point - victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it - victim.initializeTeamFlag(); - - playerWarzone.respawnPlayer(event, playerTeam, player); - playerTeam.resetSign(); - playerWarzone.getLobby().resetTeamGateSign(playerTeam); - } - playerWarzone.removeFlagThief(player.getName()); - } - - return; - } - - // Bomb detonation - if (playerWarzone.isBombThief(player.getName())) { - boolean inEnemySpawn = false; - Team victim = null; - for (Team team : playerWarzone.getTeams()) { - if (team != playerTeam - && team.getSpawnVolume().contains(player.getLocation()) - && team.getPlayers().size() > 0) { - inEnemySpawn = true; - victim = team; - break; - } - } - - if (inEnemySpawn) { - Bomb bomb = playerWarzone.getBombForThief(player.getName()); - - // Boom! - playerWarzone.getWorld().createExplosion(player.getLocation(), 2F); - - playerTeam.addPoint(); - - // Notify everyone - for (Team t : playerWarzone.getTeams()) { - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " blew up "), - SpoutMessenger.cleanForNotification(victim.getKind().getColor() + victim.getName() + ChatColor.YELLOW + "'s spawn!"), - victim.getKind().getMaterial(), - victim.getKind().getData(), - 10000); - } - } - } - t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE - + " blew up team " + victim.getName() + "'s spawn. Team " + playerTeam.getName() + " scores one point."); - } - - // Detect win conditions - if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) { - if (playerWarzone.hasPlayerState(player.getName())) { - playerWarzone.restorePlayerState(player); - } - playerWarzone.handleScoreCapReached(player, playerTeam.getName()); - event.setTo(playerWarzone.getTeleport()); - } else { - // just added a point - - // bring back flag to team that lost it - victim.getSpawnVolume().resetBlocks(); - victim.initializeTeamSpawn(); - - // bring back tnt - bomb.getVolume().resetBlocks(); - bomb.addBombBlocks(); - - playerWarzone.respawnPlayer(event, playerTeam, player); - playerTeam.resetSign(); - playerWarzone.getLobby().resetTeamGateSign(playerTeam); - } - - playerWarzone.removeBombThief(player.getName()); - } - - return; - } - - // Cake retrieval - if (playerWarzone.isCakeThief(player.getName())) { - boolean inSpawn = playerTeam.getSpawnVolume().contains(player.getLocation()); - - if (inSpawn) { - boolean hasOpponent = false; - for (Team t : playerWarzone.getTeams()) { - if (t != playerTeam && t.getPlayers().size() > 0) { - hasOpponent = true; - } - } - - // Don't let someone alone make points off cakes - if (hasOpponent) { - Cake cake = playerWarzone.getCakeForThief(player.getName()); - - // Woot! - playerTeam.addPoint(); - playerTeam.setRemainingLives(playerTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL)); - - // Notify everyone - for (Team t : playerWarzone.getTeams()) { - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " captured"), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "cake " + ChatColor.GREEN + cake.getName() + ChatColor.YELLOW + "!"), - playerTeam.getKind().getMaterial(), - playerTeam.getKind().getData(), - 10000); - } - } - } - - t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE - + " captured cake " + ChatColor.GREEN + cake.getName() + ChatColor.WHITE + ". Team " + playerTeam.getName() + " scores one point and gets a full lifepool."); - } - - // Detect win conditions - if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) { - if (playerWarzone.hasPlayerState(player.getName())) { - playerWarzone.restorePlayerState(player); - } - playerWarzone.handleScoreCapReached(player, playerTeam.getName()); - event.setTo(playerWarzone.getTeleport()); - } else { - // just added a point - - // bring back cake - cake.getVolume().resetBlocks(); - cake.addCakeBlocks(); - - playerWarzone.respawnPlayer(event, playerTeam, player); - playerTeam.resetSign(); - playerWarzone.getLobby().resetTeamGateSign(playerTeam); - } - - playerWarzone.removeCakeThief(player.getName()); - } - } - - return; - } - - // Class selection lock - if (!playerTeam.getSpawnVolume().contains(player.getLocation()) && - playerWarzone.getLoadoutSelections().keySet().contains(player.getName()) - && playerWarzone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) { - playerWarzone.getLoadoutSelections().get(player.getName()).setStillInSpawn(false); - } - - } else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) { - // player is not in any team, but inside warzone boundaries, get him out - Warzone zone = Warzone.getZoneByLocation(playerLoc); - event.setTo(zone.getTeleport()); - War.war.badMsg(player, "You can't be inside a warzone without a team."); - return; - } - } - - @EventHandler(event = PlayerToggleSneakEvent.class) - public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { - if (War.war.isLoaded() && event.isSneaking()) { - Warzone playerWarzone = Warzone.getZoneByLocation(event.getPlayer()); - Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName()); - if (playerWarzone != null && playerTeam != null && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1 && playerTeam.getSpawnVolume().contains(event.getPlayer().getLocation())) { - if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName()) - && playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) { - LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()); - int currentIndex = (selection.getSelectedIndex() + 1) % (playerTeam.getInventories().resolveLoadouts().keySet().size()); - selection.setSelectedIndex(currentIndex); - - playerWarzone.equipPlayerLoadoutSelection(event.getPlayer(), playerTeam, false, true); - } else { - War.war.badMsg(event.getPlayer(), "Can't change loadout after exiting the spawn."); - } - } - } - } - - public void purgeLatestPositions() { - this.latestLocations.clear(); - } - - private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) { - if (zone.getLobby() != null) { - War.war.badMsg(player, "This warzone is disabled."); - event.setTo(zone.getTeleport()); - } - } - - private void dropFromOldTeamIfAny(Player player) { - // drop from old team if any - Team previousTeam = Team.getTeamByPlayerName(player.getName()); - if (previousTeam != null) { - if (!previousTeam.removePlayer(player.getName())) { - War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING); - } - } - } - - -} diff --git a/war/src/main/java/bukkit/tommytony/war/WarServerListener.java b/war/src/main/java/bukkit/tommytony/war/WarServerListener.java deleted file mode 100644 index 64fa360..0000000 --- a/war/src/main/java/bukkit/tommytony/war/WarServerListener.java +++ /dev/null @@ -1,26 +0,0 @@ -package bukkit.tommytony.war; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.server.PluginDisableEvent; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.player.SpoutPlayer; - -public class WarServerListener implements Listener { - - @EventHandler(event = PluginDisableEvent.class) - public void onPluginDisable(final PluginDisableEvent event) { - if (event.getPlugin().getDataFolder().getName().equals("Spout")) { - if (War.war.isSpoutServer()) { - for (Player player : War.war.getServer().getOnlinePlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(player); - if (sp.isSpoutCraftEnabled()) { - sp.getMainScreen().removeWidgets(War.war); - } - } - War.war.getSpoutMessenger().clearAll(); - } - } - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarAdminCommand.java b/war/src/main/java/bukkit/tommytony/war/command/AbstractWarAdminCommand.java deleted file mode 100644 index f0ebce3..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarAdminCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -/** - * Represents a command that may only be used by War admins - * - */ -public abstract class AbstractWarAdminCommand extends AbstractWarCommand { - - public AbstractWarAdminCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException { - super(handler, sender, args); - - if (sender instanceof Player) { - if (!War.war.isWarAdmin((Player) sender)) { - throw new NotWarAdminException(); - } - } else if (!(sender instanceof ConsoleCommandSender)) { - throw new NotWarAdminException(); - } - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarCommand.java b/war/src/main/java/bukkit/tommytony/war/command/AbstractWarCommand.java deleted file mode 100644 index dd3ab6b..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/AbstractWarCommand.java +++ /dev/null @@ -1,84 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -/** - * Represents a war command - * - * @author Tim Düsterhus - */ -public abstract class AbstractWarCommand { - - /** - * The sender of this command - * - * @var sender - */ - private CommandSender sender; - - /** - * The arguments of this command - * - * @var args - */ - protected String[] args; - - /** - * Instance of WarCommandHandler - * - * @var handler - */ - protected WarCommandHandler handler; - - public AbstractWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - this.handler = handler; - this.setSender(sender); - this.args = args; - } - - /** - * Handles the command - * - * @return true if command was used the right way - */ - abstract public boolean handle(); - - /** - * Sends a success message - * - * @param message message to send - */ - public void msg(String message) { - War.war.msg(this.getSender(), message); - } - - /** - * Sends a failure message - * - * @param message message to send - */ - public void badMsg(String message) { - War.war.badMsg(this.getSender(), message); - } - - /** - * Changes the command-sender - * - * @param sender new sender - */ - public void setSender(CommandSender sender) { - this.sender = sender; - } - - /** - * Gets the command-sender - * - * @return Command-Sender - */ - public CommandSender getSender() { - return this.sender; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/AbstractZoneMakerCommand.java b/war/src/main/java/bukkit/tommytony/war/command/AbstractZoneMakerCommand.java deleted file mode 100644 index dff2338..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/AbstractZoneMakerCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; - -import com.tommytony.war.Warzone; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -/** - * Represents a command that may only be used by zone makers - * - * @author Tim Düsterhus - */ -public abstract class AbstractZoneMakerCommand extends AbstractWarCommand { - - public AbstractZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - - if (sender instanceof Player) { - // for players check War.isZoneMaker() - if (!War.war.isZoneMaker((Player) sender)) { - throw new NotZoneMakerException(); - } - } else if (!(sender instanceof ConsoleCommandSender)) { - throw new NotZoneMakerException(); - } - } - - public boolean isSenderAuthorOfZone(Warzone zone) { - if (this.getSender() instanceof Player) { - if (War.war.isWarAdmin((Player) this.getSender())) { - // War admin has rights over all warzones - return true; - } - - // Not War admin, is he author? - boolean isAuthor = zone.isAuthor((Player) this.getSender()); - if (!isAuthor) { - War.war.badMsg(this.getSender(), "You can't do this because you are not an author of the " + zone.getName() + " warzone." ); - } - return isAuthor; - } else { - // From console, you can do anything - return true; - } - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeleteBombCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeleteBombCommand.java deleted file mode 100644 index 156a7e7..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/DeleteBombCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Bomb; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Deletes a bomb. - * - * @author tommytony - */ -public class DeleteBombCommand extends AbstractZoneMakerCommand { - public DeleteBombCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - - if (this.args.length == 0) { - return false; - } else if (this.args.length == 2) { - zone = Warzone.getZoneByName(this.args[0]); - this.args[0] = this.args[1]; - } else if (this.args.length == 1) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - Bomb bomb = zone.getBomb(this.args[0]); - if (bomb != null) { - bomb.getVolume().resetBlocks(); - zone.getBombs().remove(bomb); - WarzoneYmlMapper.save(zone, false); - this.msg("Bomb " + bomb.getName() + " removed."); - } else { - this.badMsg("No such bomb."); - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeleteCakeCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeleteCakeCommand.java deleted file mode 100644 index 5ac136c..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/DeleteCakeCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Cake; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Deletes a cake. - * - * @author tommytony - */ -public class DeleteCakeCommand extends AbstractZoneMakerCommand { - public DeleteCakeCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - - if (this.args.length == 0) { - return false; - } else if (this.args.length == 2) { - zone = Warzone.getZoneByName(this.args[0]); - this.args[0] = this.args[1]; - } else if (this.args.length == 1) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - Cake cake = zone.getCake(this.args[0]); - if (cake != null) { - cake.getVolume().resetBlocks(); - zone.getCakes().remove(cake); - WarzoneYmlMapper.save(zone, false); - this.msg("Cake " + cake.getName() + " removed."); - } else { - this.badMsg("No such cake."); - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeleteMonumentCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeleteMonumentCommand.java deleted file mode 100644 index a8750b3..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/DeleteMonumentCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Monument; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Deletes a monument. - * - * @author Tim Düsterhus - */ -public class DeleteMonumentCommand extends AbstractZoneMakerCommand { - public DeleteMonumentCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - - if (this.args.length == 0) { - return false; - } else if (this.args.length == 2) { - zone = Warzone.getZoneByName(this.args[0]); - this.args[0] = this.args[1]; - } else if (this.args.length == 1) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - Monument monument = zone.getMonument(this.args[0]); - if (monument != null) { - monument.getVolume().resetBlocks(); - zone.getMonuments().remove(monument); - WarzoneYmlMapper.save(zone, false); - this.msg("Monument " + monument.getName() + " removed."); - } else { - this.badMsg("No such monument."); - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeleteTeamCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeleteTeamCommand.java deleted file mode 100644 index 469595e..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/DeleteTeamCommand.java +++ /dev/null @@ -1,73 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Deletes a team. - * - * @author Tim Düsterhus - */ -public class DeleteTeamCommand extends AbstractZoneMakerCommand { - public DeleteTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - - if (this.args.length == 0) { - return false; - } else if (this.args.length == 2) { - zone = Warzone.getZoneByName(this.args[0]); - this.args[0] = this.args[1]; - } else if (this.args.length == 1) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - Team team = zone.getTeamByKind(TeamKind.teamKindFromString(this.args[0])); - if (team != null) { - if (team.getFlagVolume() != null) { - team.getFlagVolume().resetBlocks(); - } - team.getSpawnVolume().resetBlocks(); - zone.getTeams().remove(team); - if (zone.getLobby() != null) { - zone.getLobby().initialize(); - } - WarzoneYmlMapper.save(zone, false); - this.msg("Team " + team.getName() + " removed."); - } else { - this.badMsg("No such team."); - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeleteTeamFlagCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeleteTeamFlagCommand.java deleted file mode 100644 index e79abe7..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/DeleteTeamFlagCommand.java +++ /dev/null @@ -1,71 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Deletes a monument. - * - * @author Tim Düsterhus - */ -public class DeleteTeamFlagCommand extends AbstractZoneMakerCommand { - public DeleteTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - - if (this.args.length == 0) { - return false; - } else if (this.args.length == 2) { - zone = Warzone.getZoneByName(this.args[0]); - this.args[0] = this.args[1]; - } else if (this.args.length == 1) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - Team teamFlagTeam = null; - for (Team team : zone.getTeams()) { - if (team.getName().startsWith(this.args[0].toLowerCase())) { - teamFlagTeam = team; - } - } - if (teamFlagTeam != null) { - teamFlagTeam.deleteTeamFlag(); - - WarzoneYmlMapper.save(zone, false); - this.msg(teamFlagTeam.getName() + " flag removed."); - } else { - this.badMsg("No such team flag."); - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeleteWarhubCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeleteWarhubCommand.java deleted file mode 100644 index e5231f6..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/DeleteWarhubCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.WarHub; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.VolumeMapper; -import com.tommytony.war.mappers.WarYmlMapper; - -/** - * Deletes the warhub. - * - * @author Tim Düsterhus - */ -public class DeleteWarhubCommand extends AbstractWarAdminCommand { - public DeleteWarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (this.args.length != 0) { - return false; - } - - if (War.war.getWarHub() != null) { - // reset existing hub - War.war.getWarHub().getVolume().resetBlocks(); - VolumeMapper.delete(War.war.getWarHub().getVolume()); - War.war.setWarHub((WarHub) null); - for (Warzone zone : War.war.getWarzones()) { - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - zone.getLobby().initialize(); - } - } - - this.msg("War hub removed."); - } else { - this.badMsg("No War hub to delete."); - } - WarYmlMapper.save(); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeleteZoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeleteZoneCommand.java deleted file mode 100644 index 6a7fff6..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/DeleteZoneCommand.java +++ /dev/null @@ -1,83 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Monument; -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarYmlMapper; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Deletes a warzone. - * - * @author Tim Düsterhus - */ -public class DeleteZoneCommand extends AbstractZoneMakerCommand { - public DeleteZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - - if (this.args.length == 1) { - zone = Warzone.getZoneByName(this.args[0]); - } else if (this.args.length == 0) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - for (Team t : zone.getTeams()) { - if (t.getTeamFlag() != null) { - t.getFlagVolume().resetBlocks(); - } - t.getSpawnVolume().resetBlocks(); - - // reset inventory - for (Player p : t.getPlayers()) { - zone.restorePlayerState(p); - } - } - for (Monument m : zone.getMonuments()) { - m.getVolume().resetBlocks(); - } - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - } - zone.getVolume().resetBlocks(); - War.war.getWarzones().remove(zone); - WarYmlMapper.save(); - WarzoneYmlMapper.delete(zone.getName()); - if (War.war.getWarHub() != null) { // warhub has to change - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().initialize(); - } - this.msg("Warzone " + zone.getName() + " removed."); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java b/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java deleted file mode 100644 index a55a92a..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java +++ /dev/null @@ -1,123 +0,0 @@ -package bukkit.tommytony.war.command; - -import java.util.List; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.WarzoneConfig; - -/** - * Joins a team. - * - * @author Tim Düsterhus - */ -public class JoinCommand extends AbstractWarCommand { - public JoinCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - Player player = (Player) this.getSender(); - if (!War.war.canPlayWar(player)) { - this.badMsg("Cannot play war. You need the war.player permission."); - return true; - } - - Warzone zone; - if (this.args.length == 0) { - return false; - } else if (this.args.length == 2) { - // zone by name - zone = Warzone.getZoneByName(this.args[0]); - // move the team-name to first place :) - this.args[0] = this.args[1]; - } else if (this.args.length == 1) { - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - if (zone == null) { - return false; - } - - String name = this.args[0]; - TeamKind kind = TeamKind.teamKindFromString(this.args[0]); - - // drop from old team if any - Team previousTeam = Team.getTeamByPlayerName(player.getName()); - if (previousTeam != null) { - if (previousTeam.getName().startsWith(name) || previousTeam.getKind() == kind) { - // trying to join own team - War.war.badMsg(player, "Can't join your own team."); - return true; - } - - Warzone oldZone = Warzone.getZoneByPlayerName(player.getName()); - if (!previousTeam.removePlayer(player.getName())) { - War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING); - } - previousTeam.resetSign(); - } - - // join new team - - - if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) { - this.msg("This warzone is disabled."); - } else { - List teams = zone.getTeams(); - boolean foundTeam = false; - for (Team team : teams) { - if (team.getName().startsWith(name) || team.getKind() == kind) { - if (!zone.hasPlayerState(player.getName())) { - zone.keepPlayerState(player); - this.msg("Your inventory is in storage until you use '/war leave'."); - } - if (team.getPlayers().size() < team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE)) { - team.addPlayer(player); - team.resetSign(); - zone.respawnPlayer(team, player); - if (War.war.getWarHub() != null) { - War.war.getWarHub().resetZoneSign(zone); - } - foundTeam = true; - } else { - this.msg("Team " + team.getName() + " is full."); - foundTeam = true; - } - } - } - - if (foundTeam) { - for (Team team : teams) { - team.teamcast("" + player.getName() + " joined " + team.getName()); - } - } else { - this.msg("No such team. Try /teams."); - } - } - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/LeaveCommand.java b/war/src/main/java/bukkit/tommytony/war/command/LeaveCommand.java deleted file mode 100644 index 7e85dd0..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/LeaveCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; - -/** - * Leaves a game. - * - * @author Tim Düsterhus - */ -public class LeaveCommand extends AbstractWarCommand { - public LeaveCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - if (this.args.length != 0) { - return false; - } - - Player player = (Player) this.getSender(); - Warzone zone = Warzone.getZoneByPlayerName(player.getName()); - if (zone == null) { - return false; - } - - zone.handlePlayerLeave(player, zone.getTeleport(), true); - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/LoadWarCommand.java b/war/src/main/java/bukkit/tommytony/war/command/LoadWarCommand.java deleted file mode 100644 index 1fa2114..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/LoadWarCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -/** - * Loads war. - * - * @author Tim Düsterhus - */ -public class LoadWarCommand extends AbstractWarAdminCommand { - public LoadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (this.args.length != 0) { - return false; - } - - War.war.loadWar(); - this.msg("War loaded."); - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/NextBattleCommand.java b/war/src/main/java/bukkit/tommytony/war/command/NextBattleCommand.java deleted file mode 100644 index 2d36784..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/NextBattleCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; - -import bukkit.tommytony.war.WarCommandHandler; - -public class NextBattleCommand extends AbstractZoneMakerCommand { - public NextBattleCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - if (this.args.length == 1) { - zone = Warzone.getZoneByName(this.args[0]); - } else if (this.args.length == 0) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } - - zone.clearThieves(); - for (Team team : zone.getTeams()) { - team.teamcast("The battle was interrupted. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and life pools..."); - } - zone.getVolume().resetBlocksAsJob(); - zone.initializeZoneAsJob(); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/NotWarAdminException.java b/war/src/main/java/bukkit/tommytony/war/command/NotWarAdminException.java deleted file mode 100644 index 3ec52e6..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/NotWarAdminException.java +++ /dev/null @@ -1,11 +0,0 @@ -package bukkit.tommytony.war.command; - -/** - * NotZoneMakerException is thrown when a player is no zonemaker. - * - * @author Tim Düsterhus - */ -public class NotWarAdminException extends Exception { - - private static final long serialVersionUID = -5412011034665080340L; -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/NotZoneMakerException.java b/war/src/main/java/bukkit/tommytony/war/command/NotZoneMakerException.java deleted file mode 100644 index a0608cd..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/NotZoneMakerException.java +++ /dev/null @@ -1,11 +0,0 @@ -package bukkit.tommytony.war.command; - -/** - * NotZoneMakerException is thrown when a player is no zonemaker. - * - * @author Tim Düsterhus - */ -public class NotZoneMakerException extends Exception { - - private static final long serialVersionUID = -5412011034665080340L; -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/RenameZoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/RenameZoneCommand.java deleted file mode 100644 index 8b013a3..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/RenameZoneCommand.java +++ /dev/null @@ -1,102 +0,0 @@ -package bukkit.tommytony.war.command; - -import java.io.File; -import java.util.logging.Level; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.mappers.PropertiesFile; -import com.tommytony.war.mappers.WarYmlMapper; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -public class RenameZoneCommand extends AbstractZoneMakerCommand { - public RenameZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - - if (this.args.length == 2) { - zone = Warzone.getZoneByName(this.args[0]); - this.args[0] = this.args[1]; - } else if (this.args.length == 1) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - // kill old reference - zone.unload(); - War.war.getWarzones().remove(zone); - - // rename zone file - (new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".yml")).renameTo(new File(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".yml")); - // rename zone folder - (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName())).renameTo(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0])); - - // TODO: Move renaming into ZoneVolumeMapper? - // rename volume files - String oldStart = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0] + "/volume-" + zone.getName() + "."; - String newStart = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0] + "/volume-" + this.args[0] + "."; - (new File(oldStart + "corners")).renameTo(new File(newStart + "corners")); - (new File(oldStart + "blocks")).renameTo(new File(newStart + "blocks")); - (new File(oldStart + "signs")).renameTo(new File(newStart + "signs")); - (new File(oldStart + "invs")).renameTo(new File(newStart + "invs")); - - // set new name - PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".yml"); - warzoneConfig.setString("name", this.args[0]); - warzoneConfig.save(); - warzoneConfig.close(); - - War.war.log("Loading zone " + this.args[0] + "...", Level.INFO); - Warzone newZone = WarzoneYmlMapper.load(this.args[0], false); - War.war.getWarzones().add(newZone); - // zone.getVolume().loadCorners(); - newZone.getVolume().loadCorners(); - if (newZone.getLobby() != null) { - newZone.getLobby().getVolume().resetBlocks(); - } - if (newZone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) { - newZone.getVolume().resetBlocks(); - } - newZone.initializeZone(); - - // save war config - WarYmlMapper.save(); - - if (War.war.getWarHub() != null) { // warhub has to change - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().initialize(); - } - - this.msg("Warzone " + zone.getName() + " renamed to " + this.args[0] + "."); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/ResetZoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/ResetZoneCommand.java deleted file mode 100644 index 7fb3fa1..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/ResetZoneCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -public class ResetZoneCommand extends AbstractZoneMakerCommand { - public ResetZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - if (this.args.length == 1) { - zone = Warzone.getZoneByName(this.args[0]); - } else if (this.args.length == 0) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - zone.clearThieves(); - for (Team team : zone.getTeams()) { - team.teamcast("The war has ended. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and teams..."); - for (Player p : team.getPlayers()) { - zone.restorePlayerState(p); - p.teleport(zone.getTeleport()); - War.war.msg(p, "You have left the warzone. Your inventory is being restored."); - } - team.resetPoints(); - team.getPlayers().clear(); - } - - this.msg("Reloading warzone " + zone.getName() + "."); - zone.getVolume().resetBlocksAsJob(); - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocksAsJob(); - } - zone.initializeZoneAsJob(); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SaveZoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SaveZoneCommand.java deleted file mode 100644 index f601a49..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SaveZoneCommand.java +++ /dev/null @@ -1,89 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -public class SaveZoneCommand extends AbstractZoneMakerCommand { - - public SaveZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone = null; - CommandSender commandSender = this.getSender(); - boolean isFirstParamWarzone = false; - - if (this.args.length > 0 && !this.args[0].contains(":")) { - // warzone name maybe in first place - Warzone zoneByName = Warzone.getZoneByName(this.args[0]); - if (zoneByName != null) { - zone = zoneByName; - isFirstParamWarzone = true; - } - } - - if (this.getSender() instanceof Player) { - Player player = (Player) commandSender; - - Warzone zoneByLoc = Warzone.getZoneByLocation(player); - ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player); - if (zoneByLoc == null && lobbyByLoc != null) { - zoneByLoc = lobbyByLoc.getZone(); - } - if (zoneByLoc != null) { - zone = zoneByLoc; - } - } - - if (zone == null) { - // No warzone found, whatever the mean, escape - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - if (isFirstParamWarzone) { - if (this.args.length > 1) { - // More than one param: the arguments need to be shifted - String[] newargs = new String[this.args.length - 1]; - for (int i = 1; i < this.args.length; i++) { - newargs[i - 1] = this.args[i]; - } - this.args = newargs; - } - } - - // We have a warzone and indexed-from-0 arguments, let's updatethis.msg(player, "Saving warzone " + warzone.getName() + "."); - int savedBlocks = zone.saveState(true); - - // changed settings: must reinitialize with new settings - String namedParamResult = War.war.updateZoneFromNamedParams(zone, commandSender, this.args); - WarzoneYmlMapper.save(zone, true); - if (this.args.length > 0) { - // the config may have changed, requiring a reset for spawn styles etc. - zone.getVolume().resetBlocks(); - } - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - } - zone.initializeZone(); // bring back team spawns etc - - if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().initialize(); - } - - this.msg("Warzone " + zone.getName() + " initial state changed. Saved " + savedBlocks + " blocks." + namedParamResult); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetBombCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetBombCommand.java deleted file mode 100644 index 44a8b00..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetBombCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Bomb; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Places a bomb - * - * @author tommytony - */ -public class SetBombCommand extends AbstractZoneMakerCommand { - public SetBombCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - Player player = (Player) this.getSender(); - - if (this.args.length != 1) { - return false; - } - - Warzone zone = Warzone.getZoneByLocation(player); - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - if (this.args[0].equals(zone.getName())) { - return false; - } - - if (zone.hasBomb(this.args[0])) { - // move the existing bomb - Bomb bomb = zone.getBomb(this.args[0]); - bomb.getVolume().resetBlocks(); - bomb.setLocation(player.getLocation()); - this.msg("Bomb " + bomb.getName() + " was moved."); - } else { - // create a new bomb - Bomb bomb = new Bomb(this.args[0], zone, player.getLocation()); - zone.getBombs().add(bomb); - this.msg("Bomb " + bomb.getName() + " created."); - } - - WarzoneYmlMapper.save(zone, false); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetCakeCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetCakeCommand.java deleted file mode 100644 index 6af50e4..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetCakeCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Cake; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Places a cake - * - * @author tommytony - */ -public class SetCakeCommand extends AbstractZoneMakerCommand { - public SetCakeCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - Player player = (Player) this.getSender(); - - if (this.args.length != 1) { - return false; - } - - Warzone zone = Warzone.getZoneByLocation(player); - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - if (this.args[0].equals(zone.getName())) { - return false; - } - - if (zone.hasCake(this.args[0])) { - // move the existing cake - Cake cake = zone.getCake(this.args[0]); - cake.getVolume().resetBlocks(); - cake.setLocation(player.getLocation()); - this.msg("Cake " + cake.getName() + " was moved."); - } else { - // create a new cake - Cake cake = new Cake(this.args[0], zone, player.getLocation()); - zone.getCakes().add(cake); - this.msg("Cake " + cake.getName() + " created."); - } - - WarzoneYmlMapper.save(zone, false); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetMonumentCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetMonumentCommand.java deleted file mode 100644 index 1c82c10..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetMonumentCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Monument; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Places a monument - * - * @author Tim Düsterhus - */ -public class SetMonumentCommand extends AbstractZoneMakerCommand { - public SetMonumentCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - Player player = (Player) this.getSender(); - - if (this.args.length != 1) { - return false; - } - - Warzone zone = Warzone.getZoneByLocation(player); - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - if (this.args[0].equals(zone.getName())) { - return false; - } - - if (zone.hasMonument(this.args[0])) { - // move the existing monument - Monument monument = zone.getMonument(this.args[0]); - monument.getVolume().resetBlocks(); - monument.setLocation(player.getLocation()); - this.msg("Monument " + monument.getName() + " was moved."); - } else { - // create a new monument - Monument monument = new Monument(this.args[0], zone, player.getLocation()); - zone.getMonuments().add(monument); - this.msg("Monument " + monument.getName() + " created."); - } - - WarzoneYmlMapper.save(zone, false); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetTeamCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetTeamCommand.java deleted file mode 100644 index 1b1799a..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetTeamCommand.java +++ /dev/null @@ -1,72 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.Warzone; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Places a soawn - * - * @author Tim Düsterhus - */ -public class SetTeamCommand extends AbstractZoneMakerCommand { - public SetTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - Player player = (Player) this.getSender(); - - if (this.args.length != 1) { - return false; - } - Warzone zone = Warzone.getZoneByLocation(player); - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - TeamKind teamKind = TeamKind.teamKindFromString(this.args[0]); - - if (teamKind == null) { - return false; - } else { - Team existingTeam = zone.getTeamByKind(teamKind); - if (existingTeam != null) { - // relocate - existingTeam.setTeamSpawn(player.getLocation()); - this.msg("Team " + existingTeam.getName() + " spawn relocated."); - } else { - // new team (use default TeamKind name for now) - Team newTeam = new Team(teamKind.toString(), teamKind, player.getLocation(), zone); - newTeam.setRemainingLives(newTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL)); - zone.getTeams().add(newTeam); - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - zone.getLobby().initialize(); - } - newTeam.setTeamSpawn(player.getLocation()); - this.msg("Team " + newTeam.getName() + " created with spawn here."); - } - } - - WarzoneYmlMapper.save(zone, false); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetTeamConfigCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetTeamConfigCommand.java deleted file mode 100644 index 1a16016..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetTeamConfigCommand.java +++ /dev/null @@ -1,163 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -public class SetTeamConfigCommand extends AbstractZoneMakerCommand { - - public SetTeamConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone = null; - Player player = null; - CommandSender commandSender = this.getSender(); - boolean isFirstParamWarzone = false; - boolean wantsToPrint = false; - - Team team = null; - - if (this.args.length == 0) { - return false; - } else { - if (!this.args[0].contains(":")) { - // warzone name maybe in first place - Warzone zoneByName = Warzone.getZoneByName(this.args[0]); - if (zoneByName != null) { - zone = zoneByName; - isFirstParamWarzone = true; - } else if (this.args[0].equals("-p") || this.args[0].equals("print")) { - wantsToPrint = true; - } - } - - if (this.getSender() instanceof Player) { - player = (Player) commandSender; - - if (zone == null) { - // zone not found, is he standing in it? - Warzone zoneByLoc = Warzone.getZoneByLocation(player); - ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player); - if (zoneByLoc == null && lobbyByLoc != null) { - zoneByLoc = lobbyByLoc.getZone(); - } - if (zoneByLoc != null) { - zone = zoneByLoc; - } - } - - team = Team.getTeamByPlayerName(player.getName()); - } - - if (zone == null) { - // No warzone found, whatever the mean, escape - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - if (isFirstParamWarzone) { - if (this.args.length == 1) { - // Only one param: the warzone name - pritn usage - return false; - } - // More than one param: the arguments need to be shifted - String[] newargs = new String[this.args.length - 1]; - for (int i = 1; i < this.args.length; i++) { - newargs[i - 1] = this.args[i]; - } - this.args = newargs; - } - - // args have been shifted if needed - if (this.args.length > 0) { - TeamKind kind = TeamKind.teamKindFromString(this.args[0]); - Team teamByName = zone.getTeamByKind(kind); - - if (team == null && teamByName == null) { - // Team not found - this.badMsg("No such team. Use /teams."); - return true; - } else if (this.args.length == 1 && teamByName != null) { - // only team name, print config - this.msg(War.war.printConfig(teamByName)); - return true; - } - - if (teamByName != null) { - // first param was team, shift again - String[] newargs = new String[this.args.length - 1]; - for (int i = 1; i < this.args.length; i++) { - newargs[i - 1] = this.args[i]; - } - this.args = newargs; - } - - if (teamByName != null) { - // Named team > player's team - team = teamByName; - } - } else { - // No team param, show usage - return false; - } - - if (this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) { - // only printing - if (this.args.length == 1) { - this.msg(War.war.printConfig(team)); - return true; - } else { - // first param was to print, shift again - String[] newargs = new String[this.args.length - 1]; - for (int i = 1; i < this.args.length; i++) { - newargs[i - 1] = this.args[i]; - } - this.args = newargs; - } - wantsToPrint = true; - } - - // We have a warzone, a team and indexed-from-0 arguments, let's update - String namedParamReturn = War.war.updateTeamFromNamedParams(team, player, this.args); - if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) { - this.msg("Saving config and resetting warzone " + zone.getName() + "."); - WarzoneYmlMapper.save(zone, false); - zone.getVolume().resetBlocks(); - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - } - zone.initializeZone(); // bring back team spawns etc - - if (wantsToPrint) { - this.msg("Team config saved. Zone reset." + namedParamReturn + " " + War.war.printConfig(team)); - } else { - this.msg("Team config saved. Zone reset." + namedParamReturn); - } - - if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().initialize(); - } - } else if (namedParamReturn.equals("PARSE-ERROR")) { - this.badMsg("Failed to read named parameter(s)."); - } else { - // empty return means no param was parsed - print command usage - return false; - } - - return true; - } - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetTeamFlagCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetTeamFlagCommand.java deleted file mode 100644 index 1f07c22..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetTeamFlagCommand.java +++ /dev/null @@ -1,68 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Places a teamflag - * - * @author Tim Düsterhus - */ -public class SetTeamFlagCommand extends AbstractZoneMakerCommand { - public SetTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - Player player = (Player) this.getSender(); - - if (this.args.length != 1) { - return false; - } - Warzone zone = Warzone.getZoneByLocation(player); - - if (zone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - TeamKind kind = TeamKind.teamKindFromString(this.args[0]); - Team team = zone.getTeamByKind(kind); - if (team == null) { - // no such team yet - this.msg("Place the team spawn first."); - } else if (team.getFlagVolume() == null) { - // new team flag - team.setTeamFlag(player.getLocation()); - Location playerLoc = player.getLocation(); - player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ())); - this.msg("Team " + team.getName() + " flag added here."); - WarzoneYmlMapper.save(zone, false); - } else { - // relocate flag - team.getFlagVolume().resetBlocks(); - team.setTeamFlag(player.getLocation()); - Location playerLoc = player.getLocation(); - player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1)); - this.msg("Team " + team.getName() + " flag moved."); - WarzoneYmlMapper.save(zone, false); - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetWarConfigCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetWarConfigCommand.java deleted file mode 100644 index 31f3735..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetWarConfigCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.mappers.WarYmlMapper; - -public class SetWarConfigCommand extends AbstractWarAdminCommand { - - public SetWarConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - boolean wantsToPrint = false; - if (this.args.length == 0) { - return false; - } else if (this.args.length == 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) { - String config = War.war.printConfig(); - this.msg(config); - return true; - } else if (this.args.length > 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) { - wantsToPrint = true; - } - - String namedParamReturn = War.war.updateFromNamedParams(this.getSender(), this.args); - if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) { - WarYmlMapper.save(); - if (wantsToPrint) { - String config = War.war.printConfig(); - this.msg("War config saved." + namedParamReturn + " " + config); - } else { - this.msg("War config saved." + namedParamReturn); - } - } else if (namedParamReturn.equals("PARSE-ERROR")) { - this.msg("Failed to read named parameters."); - } else { - return false; - } - - return true; - } - -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetWarHubCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetWarHubCommand.java deleted file mode 100644 index 899ddbb..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetWarHubCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.WarHub; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.WarYmlMapper; - -/** - * Places the warhub - * - * @author Tim Düsterhus - */ -public class SetWarHubCommand extends AbstractWarAdminCommand { - public SetWarHubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - if (this.args.length != 0) { - return false; - } - Player player = (Player) this.getSender(); - - if (War.war.getWarzones().size() > 0) { - if (War.war.getWarHub() != null) { - // reset existing hub - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().setLocation(player.getLocation()); - War.war.getWarHub().initialize(); - this.msg("War hub moved."); - } else { - War.war.setWarHub(new WarHub(player.getLocation())); - War.war.getWarHub().initialize(); - for (Warzone zone : War.war.getWarzones()) { - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - zone.getLobby().initialize(); - } - } - this.msg("War hub created."); - } - WarYmlMapper.save(); - } else { - this.msg("No warzones yet."); - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetZoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetZoneCommand.java deleted file mode 100644 index 04897a1..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetZoneCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.tommytony.war.ZoneSetter; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -public class SetZoneCommand extends AbstractZoneMakerCommand { - - public SetZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - Player player = (Player) this.getSender(); - - if (this.args.length == 0) { - return false; - } else if (this.args.length > 2) { - return false; - } else if (this.args.length == 1) { - War.war.addWandBearer(player, this.args[0]); - } else if (this.args.length == 2) { - if (!this.args[1].equals("southeast") && !this.args[1].equals("northwest") && !this.args[1].equals("se") && !this.args[1].equals("nw") && !this.args[1].equals("corner1") && !this.args[1].equals("corner2") && !this.args[1].equals("c1") && !this.args[1].equals("c2") && !this.args[1].equals("pos1") && !this.args[1].equals("pos2") && !this.args[1].equals("wand")) { - return false; - } - - ZoneSetter setter = new ZoneSetter(player, this.args[0]); - if (this.args[1].equals("northwest") || this.args[1].equals("nw")) { - setter.placeNorthwest(); - } else if (this.args[1].equals("southeast") || this.args[1].equals("se")) { - setter.placeSoutheast(); - } else if (this.args[1].equals("corner1") || this.args[1].equals("c1") || this.args[1].equals("pos1")) { - setter.placeCorner1(); - } else if (this.args[1].equals("corner2") || this.args[1].equals("c2") || this.args[1].equals("pos2")) { - setter.placeCorner2(); - } else if (this.args[1].equals("wand")) { - War.war.addWandBearer(player, this.args[0]); - } - } - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetZoneConfigCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetZoneConfigCommand.java deleted file mode 100644 index cc6c7f4..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetZoneConfigCommand.java +++ /dev/null @@ -1,124 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -public class SetZoneConfigCommand extends AbstractZoneMakerCommand { - - public SetZoneConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone = null; - Player player = null; - CommandSender commandSender = this.getSender(); - boolean isFirstParamWarzone = false; - boolean wantsToPrint = false; - - if (this.args.length == 0) { - return false; - } else { - if (!this.args[0].contains(":")) { - // warzone name maybe in first place - Warzone zoneByName = Warzone.getZoneByName(this.args[0]); - if (zoneByName != null) { - zone = zoneByName; - isFirstParamWarzone = true; - } else if (this.args[0].equals("-p") || this.args[0].equals("print")) { - wantsToPrint = true; - } - } - - if (this.getSender() instanceof Player) { - player = (Player) commandSender; - if (zone == null) { - // zone not found, is he standing in it? - Warzone zoneByLoc = Warzone.getZoneByLocation(player); - ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player); - if (zoneByLoc == null && lobbyByLoc != null) { - zoneByLoc = lobbyByLoc.getZone(); - } - if (zoneByLoc != null) { - zone = zoneByLoc; - } - } - } - - if (zone == null) { - // No warzone found, whatever the mean, escape - return false; - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } - - if (isFirstParamWarzone) { - if (this.args.length == 1) { - // Only one param: the warzone name - default to usage - return false; - } - // More than one param: the arguments need to be shifted - String[] newargs = new String[this.args.length - 1]; - for (int i = 1; i < this.args.length; i++) { - newargs[i - 1] = this.args[i]; - } - this.args = newargs; - } - - // args have been shifted if needed - if (this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) { - // only printing - if (this.args.length == 1) { - this.msg(War.war.printConfig(zone)); - return true; - } else { - // first param was to print, shift again - String[] newargs = new String[this.args.length - 1]; - for (int i = 1; i < this.args.length; i++) { - newargs[i - 1] = this.args[i]; - } - this.args = newargs; - } - wantsToPrint = true; - } - - // We have a warzone and indexed-from-0 arguments, let's update - String namedParamReturn = War.war.updateZoneFromNamedParams(zone, player, this.args); - if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) { - this.msg("Saving config and resetting warzone " + zone.getName() + "."); - WarzoneYmlMapper.save(zone, false); - zone.getVolume().resetBlocks(); - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - } - zone.initializeZone(); // bring back team spawns etc - - if (wantsToPrint) { - this.msg("Warzone config saved. Zone reset." + namedParamReturn + " " + War.war.printConfig(zone)); - } else { - this.msg("Warzone config saved. Zone reset." + namedParamReturn); - } - - if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().initialize(); - } - } else if (namedParamReturn.equals("PARSE-ERROR")) { - this.badMsg("Failed to read named parameter(s)."); - } else { - // empty return means no param was parsed - print command usage - return false; - } - - return true; - } - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetZoneLobbyCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetZoneLobbyCommand.java deleted file mode 100644 index 9a5c519..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/SetZoneLobbyCommand.java +++ /dev/null @@ -1,119 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.block.BlockFace; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -/** - * Places the zonelobby - * - * @author Tim Düsterhus - */ -public class SetZoneLobbyCommand extends AbstractZoneMakerCommand { - - public SetZoneLobbyCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - if (this.args.length != 1) { - return false; - } - Player player = (Player) this.getSender(); - Warzone zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby != null) { - zone = lobby.getZone(); - } - } - - if (zone == null) { - // Zone not where player is standing, maybe player is detaching/relocating the lobby - Warzone givenWarzone = Warzone.getZoneByName(this.args[0]); - if (givenWarzone == null) { - return false; - } else if (!this.isSenderAuthorOfZone(givenWarzone)) { - return true; - } else { - // Move the warzone lobby - ZoneLobby lobby = givenWarzone.getLobby(); - if (lobby != null) { - // reset existing lobby and save new volume at new location - lobby.setLocation(player.getLocation()); - lobby.initialize(); - this.msg("Warzone lobby moved to your location."); - } else { - // new lobby - lobby = new ZoneLobby(givenWarzone, player.getLocation()); - givenWarzone.setLobby(lobby); - lobby.initialize(); - if (War.war.getWarHub() != null) { // warhub has to change - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().initialize(); - } - this.msg("Warzone lobby moved to your location."); - } - WarzoneYmlMapper.save(givenWarzone, false); - } - } else if (!this.isSenderAuthorOfZone(zone)) { - return true; - } else { - // Inside a warzone: use the classic n/s/e/w mode - if (!this.args[0].equals("north") && !this.args[0].equals("n") && !this.args[0].equals("east") && !this.args[0].equals("e") && !this.args[0].equals("south") && !this.args[0].equals("s") && !this.args[0].equals("west") && !this.args[0].equals("w")) { - return false; - } - ZoneLobby lobby = zone.getLobby(); - - BlockFace wall = BlockFace.WEST; - String wallStr = ""; - if (this.args[0].equals("north") || this.args[0].equals("n")) { - wall = BlockFace.NORTH; - wallStr = "north"; - } else if (this.args[0].equals("east") || this.args[0].equals("e")) { - wall = BlockFace.EAST; - wallStr = "east"; - } else if (this.args[0].equals("south") || this.args[0].equals("s")) { - wall = BlockFace.SOUTH; - wallStr = "south"; - } else if (this.args[0].equals("west") || this.args[0].equals("w")) { - wall = BlockFace.WEST; - wallStr = "west"; - } - - if (lobby != null) { - // reset existing lobby - lobby.getVolume().resetBlocks(); - lobby.setWall(wall); - lobby.initialize(); - this.msg("Warzone lobby moved to " + wallStr + " side of zone."); - } else { - // new lobby - lobby = new ZoneLobby(zone, wall); - zone.setLobby(lobby); - lobby.initialize(); - if (War.war.getWarHub() != null) { // warhub has to change - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().initialize(); - } - this.msg("Warzone lobby created on " + wallStr + "side of zone."); - } - WarzoneYmlMapper.save(zone, false); - } - - return true; - } - -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/TeamCommand.java b/war/src/main/java/bukkit/tommytony/war/command/TeamCommand.java deleted file mode 100644 index c079220..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/TeamCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Team; - -/** - * Sends a message to all team-members - * - * @author Tim Düsterhus - */ -public class TeamCommand extends AbstractWarCommand { - public TeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - Player player = (Player) this.getSender(); - Team playerTeam = Team.getTeamByPlayerName(player.getName()); - if (playerTeam == null) { - return false; - } - - ChatColor color = playerTeam.getKind().getColor(); - String teamMessage = color + player.getName() + ": " + ChatColor.WHITE; - for (String part : this.args) { - teamMessage += part + " "; - } - playerTeam.teamcast(teamMessage, false); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/TeamsCommand.java b/war/src/main/java/bukkit/tommytony/war/command/TeamsCommand.java deleted file mode 100644 index a1fe9b4..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/TeamsCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; - -/** - * Shows team information - * - * @author Tim Düsterhus - */ -public class TeamsCommand extends AbstractWarCommand { - public TeamsCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - super(handler, sender, args); - } - - @Override - public boolean handle() { - Warzone zone; - if (this.args.length == 1) { - zone = Warzone.getZoneByName(this.args[0]); - } else if (this.args.length == 0) { - if (!(this.getSender() instanceof Player)) { - return false; - } - zone = Warzone.getZoneByLocation((Player) this.getSender()); - if (zone == null) { - ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); - if (lobby == null) { - return false; - } - zone = lobby.getZone(); - } - } else { - return false; - } - if (zone == null) { - return false; - } - - this.msg(zone.getTeamInformation()); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/UnloadWarCommand.java b/war/src/main/java/bukkit/tommytony/war/command/UnloadWarCommand.java deleted file mode 100644 index 346eb02..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/UnloadWarCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -/** - * Unloads war. - * - * @author Tim Düsterhus - */ -public class UnloadWarCommand extends AbstractWarAdminCommand { - public UnloadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (this.args.length != 0) { - return false; - } - - War.war.unloadWar(); - this.msg("War unloaded."); - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/WarhubCommand.java b/war/src/main/java/bukkit/tommytony/war/command/WarhubCommand.java deleted file mode 100644 index 63c7855..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/WarhubCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; - -/** - * Warps the player to the warhub. - * - * @author Tim Düsterhus - */ -public class WarhubCommand extends AbstractWarCommand { - public WarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - if (this.args.length != 0) { - return false; - } - Player player = (Player) this.getSender(); - if (War.war.getWarHub() == null) { - this.badMsg("No warhub on this War server. Try /zones and /zone."); - } else if (!War.war.canWarp(player)) { - this.badMsg("Can't warp to warhub. You need the 'war.warp' permission."); - } else { - Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); - if (playerWarzone != null) { // was in zone - playerWarzone.handlePlayerLeave(player, War.war.getWarHub().getLocation(), true); - } - player.teleport(War.war.getWarHub().getLocation()); - } - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/WarzoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/WarzoneCommand.java deleted file mode 100644 index f930ffd..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/WarzoneCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Warzone; - -/** - * Warps the player to the given warzone. - * - * @author Tim Düsterhus - */ -public class WarzoneCommand extends AbstractWarCommand { - public WarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - - if (this.args.length != 1) { - return false; - } - Player player = (Player) this.getSender(); - - if (!War.war.canWarp(player)) { - this.badMsg("Can't warp to zone. You need the 'war.warp' permission."); - } else { - Warzone warzone = Warzone.getZoneByName(this.args[0]); - if (warzone != null && warzone.getTeleport() != null) { - Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); - if (playerWarzone != null) { - playerWarzone.handlePlayerLeave(player, warzone.getTeleport(), true); - } else { - player.teleport(warzone.getTeleport()); - } - return true; - } - - this.badMsg("No such warzone."); - } - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/WarzonesCommand.java b/war/src/main/java/bukkit/tommytony/war/command/WarzonesCommand.java deleted file mode 100644 index 662a19f..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/WarzonesCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; - -/** - * Lists all warzones - * - * @author Tim Düsterhus - */ -public class WarzonesCommand extends AbstractWarCommand { - public WarzonesCommand(WarCommandHandler handler, CommandSender sender, String[] args) { - super(handler, sender, args); - } - - @Override - public boolean handle() { - if (this.args.length != 0) { - return false; - } - String warzonesMessage = "Warzones: "; - if (War.war.getWarzones().isEmpty()) { - warzonesMessage += "none."; - } else { - for (Warzone warzone : War.war.getWarzones()) { - warzonesMessage += warzone.getName() + " (" + warzone.getTeams().size() + " teams, "; - int playerTotal = 0; - for (Team team : warzone.getTeams()) { - playerTotal += team.getPlayers().size(); - } - warzonesMessage += playerTotal + " players) "; - } - } - - this.msg(warzonesMessage + ((this.getSender() instanceof Player) ? " Use /zone to teleport to a warzone." : "")); - - return true; - } -} diff --git a/war/src/main/java/bukkit/tommytony/war/command/ZoneMakerCommand.java b/war/src/main/java/bukkit/tommytony/war/command/ZoneMakerCommand.java deleted file mode 100644 index 3900476..0000000 --- a/war/src/main/java/bukkit/tommytony/war/command/ZoneMakerCommand.java +++ /dev/null @@ -1,79 +0,0 @@ -package bukkit.tommytony.war.command; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; -import bukkit.tommytony.war.WarCommandHandler; - -import com.tommytony.war.mappers.WarYmlMapper; - -/** - * Makes a player zonemaker and other way round. - * - * @author Tim Düsterhus - */ -public class ZoneMakerCommand extends AbstractWarCommand { - - public ZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { - super(handler, sender, args); - - if (sender instanceof Player) { // i hate java for this. - if (!War.war.isZoneMaker((Player) sender)) { - for (String name : War.war.getZoneMakersImpersonatingPlayers()) { - if (((Player) sender).getName().equals(name)) { - return; - } - } - throw new NotZoneMakerException(); - } - } - } - - @Override - public boolean handle() { - if (!(this.getSender() instanceof Player)) { - this.badMsg("You can't do this if you are not in-game."); - return true; - } - Player player = (Player) this.getSender(); - - if (War.war.isZoneMaker(player)) { - if (this.args.length == 0) { - War.war.getZoneMakersImpersonatingPlayers().add(player.getName()); - this.msg("You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode."); - } else if (this.args.length == 1) { - // make someone zonemaker or remove the right - if (War.war.getZoneMakerNames().contains(this.args[0])) { - // kick - War.war.getZoneMakerNames().remove(this.args[0]); - this.msg(this.args[0] + " is not a zone maker anymore."); - Player kickedMaker = War.war.getServer().getPlayer(this.args[0]); - if (kickedMaker != null) { - War.war.msg(kickedMaker, player.getName() + " took away your warzone maker priviledges."); - } - } else { - // add - War.war.getZoneMakerNames().add(this.args[0]); - this.msg(this.args[0] + " is now a zone maker."); - Player newMaker = War.war.getServer().getPlayer(this.args[0]); - if (newMaker != null) { - War.war.msg(newMaker, player.getName() + " made you warzone maker."); - } - } - } else { - return false; - } - } else { - if (this.args.length != 0) { - return false; - } - - War.war.getZoneMakersImpersonatingPlayers().remove(player.getName()); - this.msg("You are back as a zone maker."); - WarYmlMapper.save(); - } - - return true; - } -} diff --git a/war/src/main/java/com/tommytony/war/Bomb.java b/war/src/main/java/com/tommytony/war/Bomb.java deleted file mode 100644 index a3fb4d2..0000000 --- a/war/src/main/java/com/tommytony/war/Bomb.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.tommytony.war; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; - -import com.tommytony.war.volumes.Volume; - -/** - * - * @author tommytony - * - */ -public class Bomb { - private Location location; - private Volume volume; - - private final String name; - private Warzone warzone; - private Player capturer; - - public Bomb(String name, Warzone warzone, Location location) { - this.name = name; - this.location = location; - this.warzone = warzone; - this.volume = new Volume("bomb-" + name, warzone.getWorld()); - this.setLocation(location); - } - - public void addBombBlocks() { - this.volume.setToMaterial(Material.AIR); - - int x = this.location.getBlockX(); - int y = this.location.getBlockY(); - int z = this.location.getBlockZ(); - - // center - this.warzone.getWorld().getBlockAt(x, y - 1, z).getState().setType(Material.OBSIDIAN); - - // inner ring - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.GLOWSTONE); - - this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.GLOWSTONE); - - // block holder - this.warzone.getWorld().getBlockAt(x, y, z).setType(Material.OBSIDIAN); - Block tntBlock = this.warzone.getWorld().getBlockAt(x, y + 1, z); - tntBlock.setType(Material.TNT); - } - - public boolean isBombBlock(Location otherLocation) { - int x = this.location.getBlockX(); - int y = this.location.getBlockY() + 1; - int z = this.location.getBlockZ(); - int otherX = otherLocation.getBlockX(); - int otherY = otherLocation.getBlockY(); - int otherZ = otherLocation.getBlockZ(); - - return x == otherX - && y == otherY - && z == otherZ; - } - - public void capture(Player capturer) { - this.capturer = capturer; - } - - public boolean isCaptured() { - return this.capturer != null; - } - - public void uncapture() { - this.capturer = null; - } - - public Location getLocation() { - return this.location; - } - - public String getName() { - return this.name; - } - - public void setLocation(Location location) { - Block locationBlock = this.warzone.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - this.volume.setCornerOne(locationBlock.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST, 1).getRelative(BlockFace.SOUTH, 1)); - this.volume.setCornerTwo(locationBlock.getRelative(BlockFace.UP, 2).getRelative(BlockFace.WEST, 1).getRelative(BlockFace.NORTH, 1)); - this.volume.saveBlocks(); - this.location = location; - this.addBombBlocks(); - } - - public Volume getVolume() { - return this.volume; - } - - public void setVolume(Volume newVolume) { - this.volume = newVolume; - - } -} diff --git a/war/src/main/java/com/tommytony/war/Cake.java b/war/src/main/java/com/tommytony/war/Cake.java deleted file mode 100644 index 8324c7a..0000000 --- a/war/src/main/java/com/tommytony/war/Cake.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.tommytony.war; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; - -import com.tommytony.war.volumes.Volume; - -/** - * - * @author tommytony - * - */ -public class Cake { - private Location location; - private Volume volume; - - private final String name; - private Warzone warzone; - private Player capturer; - - public Cake(String name, Warzone warzone, Location location) { - this.name = name; - this.location = location; - this.warzone = warzone; - this.volume = new Volume("cake-" + name, warzone.getWorld()); - this.setLocation(location); - } - - public void addCakeBlocks() { - this.volume.setToMaterial(Material.AIR); - - int x = this.location.getBlockX(); - int y = this.location.getBlockY(); - int z = this.location.getBlockZ(); - - // center - this.warzone.getWorld().getBlockAt(x, y - 1, z).getState().setType(Material.OBSIDIAN); - - // inner ring - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN); - - // block holder - this.warzone.getWorld().getBlockAt(x, y, z).setType(Material.GLASS); - Block cakeBlock = this.warzone.getWorld().getBlockAt(x, y + 1, z); - cakeBlock.setType(Material.CAKE_BLOCK); - } - - public boolean isCakeBlock(Location otherLocation) { - int x = this.location.getBlockX(); - int y = this.location.getBlockY() + 1; - int z = this.location.getBlockZ(); - int otherX = otherLocation.getBlockX(); - int otherY = otherLocation.getBlockY(); - int otherZ = otherLocation.getBlockZ(); - - return x == otherX - && y == otherY - && z == otherZ; - } - - public void capture(Player capturer) { - this.capturer = capturer; - } - - public boolean isCaptured() { - return this.capturer != null; - } - - public void uncapture() { - this.capturer = null; - } - - public Location getLocation() { - return this.location; - } - - public String getName() { - return this.name; - } - - public void setLocation(Location location) { - Block locationBlock = this.warzone.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - this.volume.setCornerOne(locationBlock.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST, 1).getRelative(BlockFace.SOUTH, 1)); - this.volume.setCornerTwo(locationBlock.getRelative(BlockFace.UP, 2).getRelative(BlockFace.WEST, 1).getRelative(BlockFace.NORTH, 1)); - this.volume.saveBlocks(); - this.location = location; - this.addCakeBlocks(); - } - - public Volume getVolume() { - return this.volume; - } - - public void setVolume(Volume newVolume) { - this.volume = newVolume; - - } -} diff --git a/war/src/main/java/com/tommytony/war/FlagReturn.java b/war/src/main/java/com/tommytony/war/FlagReturn.java deleted file mode 100644 index 218be89..0000000 --- a/war/src/main/java/com/tommytony/war/FlagReturn.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.tommytony.war; - -public enum FlagReturn { - BOTH, - FLAG, - SPAWN; - - @Override - public String toString() { - return super.toString().toLowerCase(); - } - - public static FlagReturn getFromString(String string) { - for (FlagReturn flagMode : FlagReturn.values()) { - if (string.toLowerCase().equals(flagMode.toString())) { - return flagMode; - } - } - - return FlagReturn.BOTH; - } -} diff --git a/war/src/main/java/com/tommytony/war/LoadoutSelection.java b/war/src/main/java/com/tommytony/war/LoadoutSelection.java deleted file mode 100644 index 460397c..0000000 --- a/war/src/main/java/com/tommytony/war/LoadoutSelection.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.tommytony.war; - -public class LoadoutSelection { - - private boolean stillInSpawn; - private int selectedIndex; - - public LoadoutSelection(boolean stillInSpawn, int selectedIndex) { - this.setStillInSpawn(stillInSpawn); - this.setSelectedIndex(selectedIndex); - - } - - public void setStillInSpawn(boolean stillInSpawn) { - this.stillInSpawn = stillInSpawn; - } - - public boolean isStillInSpawn() { - return stillInSpawn; - } - - public void setSelectedIndex(int selectedIndex) { - this.selectedIndex = selectedIndex; - } - - public int getSelectedIndex() { - return selectedIndex; - } -} diff --git a/war/src/main/java/com/tommytony/war/Monument.java b/war/src/main/java/com/tommytony/war/Monument.java deleted file mode 100644 index aefedb1..0000000 --- a/war/src/main/java/com/tommytony/war/Monument.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.tommytony.war; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; - -import com.tommytony.war.volumes.Volume; - -/** - * - * @author tommytony - * - */ -public class Monument { - private Location location; - private Volume volume; - - private Team ownerTeam = null; - private final String name; - private Warzone warzone; - - public Monument(String name, Warzone warzone, Location location) { - this.name = name; - this.location = location; - this.warzone = warzone; - this.volume = new Volume(name, warzone.getWorld()); - this.setLocation(location); - } - - public void addMonumentBlocks() { - this.volume.setToMaterial(Material.AIR); - - this.ownerTeam = null; - int x = this.location.getBlockX(); - int y = this.location.getBlockY(); - int z = this.location.getBlockZ(); - - // center - this.warzone.getWorld().getBlockAt(x, y - 1, z).getState().setType(Material.OBSIDIAN); - - // inner ring - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN); - - // outer ring - this.warzone.getWorld().getBlockAt(x + 2, y - 1, z + 2).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x + 2, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 2, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 2, y - 1, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 2, y - 1, z - 2).setType(Material.GLOWSTONE); - - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 2).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x, y - 1, z + 2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y - 1, z - 2).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 2).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x - 2, y - 1, z + 2).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x - 2, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 2, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2).setType(Material.GLOWSTONE); - - // block holder - this.warzone.getWorld().getBlockAt(x, y, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y, z + 1).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).setType(Material.OBSIDIAN); - - this.warzone.getWorld().getBlockAt(x, y + 2, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y + 2, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y + 2, z + 1).setType(Material.OBSIDIAN); - - } - - public boolean isNear(Location playerLocation) { - int x = this.location.getBlockX(); - int y = this.location.getBlockY(); - int z = this.location.getBlockZ(); - int playerX = playerLocation.getBlockX(); - int playerY = playerLocation.getBlockY(); - int playerZ = playerLocation.getBlockZ(); - int diffX = Math.abs(playerX - x); - int diffY = Math.abs(playerY - y); - int diffZ = Math.abs(playerZ - z); - if (diffX < 6 && diffY < 6 && diffZ < 6) { - return true; - } - return false; - } - - public boolean isOwner(Team team) { - if (team == this.ownerTeam) { - return true; - } - return false; - } - - public boolean hasOwner() { - return this.ownerTeam != null; - } - - public void capture(Team team) { - this.ownerTeam = team; - } - - public void uncapture() { - this.ownerTeam = null; - } - - public Location getLocation() { - return this.location; - } - - public void setOwnerTeam(Team team) { - this.ownerTeam = team; - - } - - public String getName() { - return this.name; - } - - public void setLocation(Location location) { - Block locationBlock = this.warzone.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - this.volume.setCornerOne(locationBlock.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST, 2).getRelative(BlockFace.SOUTH, 2)); - this.volume.setCornerTwo(locationBlock.getRelative(BlockFace.UP, 2).getRelative(BlockFace.WEST, 2).getRelative(BlockFace.NORTH, 2)); - this.volume.saveBlocks(); - this.location = location; - - this.addMonumentBlocks(); - } - - public Volume getVolume() { - return this.volume; - } - - public void setVolume(Volume newVolume) { - this.volume = newVolume; - - } - - public Team getOwnerTeam() { - - return this.ownerTeam; - } -} diff --git a/war/src/main/java/com/tommytony/war/PotionEffect.java b/war/src/main/java/com/tommytony/war/PotionEffect.java deleted file mode 100644 index 90f16a9..0000000 --- a/war/src/main/java/com/tommytony/war/PotionEffect.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.tommytony.war; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.server.MobEffect; -import net.minecraft.server.MobEffectList; - -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class PotionEffect { - - private int id; - private int amplifier; - private int time; - - public PotionEffect(int id, int amplifier, int time) { - this.setId(id); - this.setAmplifier(amplifier); - this.setTime(time); - } - - public void setId(int id) { - this.id = id; - } - - public int getId() { - return id; - } - - public void setAmplifier(int amplifier) { - this.amplifier = amplifier; - } - - public int getAmplifier() { - return amplifier; - } - - public void setTime(int time) { - this.time = time; - } - - public int getTime() { - return time; - } - - public static List getCurrentPotionEffects(Player player) { - List effects = new ArrayList(); - - for(int i = 1; i < 20; i++) - { - if(((CraftPlayer)player).getHandle().hasEffect(enchantIdToList(i))) - { - MobEffect mobEffect = ((CraftPlayer)player).getHandle().getEffect(enchantIdToList(i)); - effects.add(new PotionEffect(mobEffect.getEffectId(), mobEffect.getAmplifier(), mobEffect.getDuration())); - } - } - - return effects; - } - - public static void restorePotionEffects(Player player, List potionEffects) { - clearPotionEffects(player); - for (PotionEffect effect : potionEffects) { - ((CraftPlayer)player).getHandle().addEffect(new MobEffect(effect.getId(), effect.getTime(), effect.getAmplifier())); - } - } - - public static void clearPotionEffects(Player player) { - for (int i = 1; i < 20; i++) { - if(((CraftPlayer)player).getHandle().hasEffect(enchantIdToList(i))) - { - int amplifier = ((CraftPlayer)player).getHandle().getEffect(enchantIdToList(i)).getAmplifier(); - ((CraftPlayer)player).getHandle().addEffect(new MobEffect(i, -1, amplifier + 1)); - } - } - } - - private static MobEffectList enchantIdToList(int id) { - switch (id) { - case 1: - return MobEffectList.FASTER_MOVEMENT; - case 2: - return MobEffectList.SLOWER_MOVEMENT; - case 3: - return MobEffectList.FASTER_DIG; - case 4: - return MobEffectList.SLOWER_DIG; - case 5: - return MobEffectList.INCREASE_DAMAGE; - case 6: - return MobEffectList.HEAL; - case 7: - return MobEffectList.HARM; - case 8: - return MobEffectList.JUMP; - case 9: - return MobEffectList.CONFUSION; - case 10: - return MobEffectList.REGENERATION; - case 11: - return MobEffectList.RESISTANCE; - case 12: - return MobEffectList.FIRE_RESISTANCE; - case 13: - return MobEffectList.WATER_BREATHING; - case 14: - return MobEffectList.INVISIBILITY; - case 15: - return MobEffectList.BLINDNESS; - case 16: - return MobEffectList.NIGHT_VISION; - case 17: - return MobEffectList.HUNGER; - case 18: - return MobEffectList.WEAKNESS; - case 19: - return MobEffectList.POISON; - default: - return null; - } - } - -} diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java deleted file mode 100644 index 1e236cd..0000000 --- a/war/src/main/java/com/tommytony/war/Team.java +++ /dev/null @@ -1,613 +0,0 @@ -package com.tommytony.war; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.player.SpoutPlayer; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.config.InventoryBag; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.TeamConfigBag; -import com.tommytony.war.utils.SignHelper; -import com.tommytony.war.volumes.Volume; - -/** - * - * @author tommytony - * - */ -public class Team { - private List players = new ArrayList(); - private Location teamSpawn = null; - private Location teamFlag = null; - private String name; - private int remainingLives; - private int points = 0; - private Volume spawnVolume; - private Volume flagVolume; - private final Warzone warzone; - private TeamKind kind; - - private TeamConfigBag teamConfig; - private InventoryBag inventories; - - public Team(String name, TeamKind kind, Location teamSpawn, Warzone warzone) { - this.warzone = warzone; - this.teamConfig = new TeamConfigBag(warzone); - this.inventories = new InventoryBag(warzone); // important constructors for cascading configs - this.setName(name); - this.teamSpawn = teamSpawn; - this.setSpawnVolume(new Volume(name, warzone.getWorld())); - this.kind = kind; - this.setFlagVolume(null); // no flag at the start - } - - public static Team getTeamByPlayerName(String playerName) { - for (Warzone warzone : War.war.getWarzones()) { - Team team = warzone.getPlayerTeam(playerName); - if (team != null) { - return team; - } - } - return null; - } - - public TeamKind getKind() { - return this.kind; - } - - private void setSpawnVolume() { - if (this.spawnVolume.isSaved()) { - this.spawnVolume.resetBlocks(); - } - int x = this.teamSpawn.getBlockX(); - int y = this.teamSpawn.getBlockY(); - int z = this.teamSpawn.getBlockZ(); - - TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle(); - if (style.equals(TeamSpawnStyle.INVISIBLE)) { - this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x, y - 1, z)); - this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x, y + 3, z)); - } else if (style.equals(TeamSpawnStyle.SMALL)) { - this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1)); - this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1)); - } else { - // flat or big - this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2)); - this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 2, y + 3, z + 2)); - } - } - - @SuppressWarnings("unused") - public void initializeTeamSpawn() { - // make air - this.spawnVolume.setToMaterial(Material.AIR); - - // Set the spawn - int x = this.teamSpawn.getBlockX(); - int y = this.teamSpawn.getBlockY(); - int z = this.teamSpawn.getBlockZ(); - - TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle(); - if (style.equals(TeamSpawnStyle.INVISIBLE)) { - // nothing but glowstone - this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE); - } else { - // first ring - this.setBlock(x + 1, y - 1, z + 1, this.kind); - this.setBlock(x + 1, y - 1, z, this.kind); - this.setBlock(x + 1, y - 1, z - 1, this.kind); - this.setBlock(x, y - 1, z + 1, this.kind); - this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE); - this.setBlock(x, y - 1, z - 1, this.kind); - this.setBlock(x - 1, y - 1, z + 1, this.kind); - this.setBlock(x - 1, y - 1, z, this.kind); - this.setBlock(x - 1, y - 1, z - 1, this.kind); - } - - // Orientation - int yaw = 0; - if (this.teamSpawn.getYaw() >= 0) { - yaw = (int) (this.teamSpawn.getYaw() % 360); - } else { - yaw = (int) (360 + (this.teamSpawn.getYaw() % 360)); - } - Block signBlock = null; - int signData = 0; - - if (style.equals(TeamSpawnStyle.INVISIBLE)) { - // INVISIBLE style - signBlock = this.warzone.getWorld().getBlockAt(x, y, z); - if (yaw >= 0 && yaw < 90) { - signData = 10; - } else if (yaw >= 90 && yaw <= 180) { - signData = 14; - } else if (yaw >= 180 && yaw < 270) { - signData = 2; - } else if (yaw >= 270 && yaw <= 360) { - signData = 6; - } - } else if (style.equals(TeamSpawnStyle.SMALL)) { - // SMALL style - if (yaw >= 0 && yaw < 90) { - signData = 10; - signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST); - } else if (yaw >= 90 && yaw <= 180) { - signData = 14; - signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST); - } else if (yaw >= 180 && yaw < 270) { - signData = 2; - signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.SOUTH).getRelative(BlockFace.EAST); - } else if (yaw >= 270 && yaw <= 360) { - signData = 6; - signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST); - } - } else { - // outer ring (FLAT or BIG) - this.setBlock(x + 2, y - 1, z + 2, this.kind); - this.setBlock(x + 2, y - 1, z + 1, this.kind); - this.setBlock(x + 2, y - 1, z, this.kind); - this.setBlock(x + 2, y - 1, z - 1, this.kind); - this.setBlock(x + 2, y - 1, z - 2, this.kind); - - this.setBlock(x - 1, y - 1, z + 2, this.kind); - this.setBlock(x - 1, y - 1, z - 2, this.kind); - - this.setBlock(x, y - 1, z + 2, this.kind); - this.setBlock(x, y - 1, z - 2, this.kind); - - this.setBlock(x + 1, y - 1, z + 2, this.kind); - this.setBlock(x + 1, y - 1, z - 2, this.kind); - - this.setBlock(x - 2, y - 1, z + 2, this.kind); - this.setBlock(x - 2, y - 1, z + 1, this.kind); - this.setBlock(x - 2, y - 1, z, this.kind); - this.setBlock(x - 2, y - 1, z - 1, this.kind); - this.setBlock(x - 2, y - 1, z - 2, this.kind); - - BlockFace facing = null; - BlockFace opposite = null; - if (yaw >= 0 && yaw < 90) { - facing = BlockFace.NORTH_WEST; - opposite = BlockFace.SOUTH_EAST; - signData = 10; - signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.WEST, 2); - - if (style.equals(TeamSpawnStyle.BIG)) { - // rim - this.setBlock(x - 2, y, z - 1, this.kind); - this.setBlock(x - 2, y, z - 2, this.kind); - this.setBlock(x - 1, y, z - 2, this.kind); - this.setBlock(x, y, z - 2, this.kind); - this.setBlock(x + 1, y, z - 2, this.kind); - this.setBlock(x + 2, y, z - 2, this.kind); - this.setBlock(x + 2, y, z - 1, this.kind); - this.setBlock(x + 2, y, z, this.kind); - this.setBlock(x + 2, y, z + 1, this.kind); - this.setBlock(x + 2, y, z + 2, this.kind); - this.setBlock(x + 1, y, z + 2, this.kind); - - // tower - this.setBlock(x, y + 1, z - 2, this.kind); - this.setBlock(x + 1, y + 1, z - 2, this.kind); - this.setBlock(x + 2, y + 1, z - 2, this.kind); - this.setBlock(x + 2, y + 1, z - 1, this.kind); - this.setBlock(x + 2, y + 1, z, this.kind); - - this.setBlock(x + 1, y + 2, z - 2, this.kind); - this.setBlock(x + 2, y + 2, z - 2, this.kind); - this.setBlock(x + 2, y + 2, z - 1, this.kind); - - this.setBlock(x + 2, y + 3, z - 2, this.kind); - } - } else if (yaw >= 90 && yaw <= 180) { - facing = BlockFace.NORTH_EAST; - opposite = BlockFace.SOUTH_WEST; - signData = 14; - signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.EAST, 2); - if (style.equals(TeamSpawnStyle.BIG)) { - // rim - this.setBlock(x + 1, y, z - 2, this.kind); - this.setBlock(x + 2, y, z - 2, this.kind); - this.setBlock(x + 2, y, z - 1, this.kind); - this.setBlock(x + 2, y, z, this.kind); - this.setBlock(x + 2, y, z + 1, this.kind); - this.setBlock(x + 2, y, z + 2, this.kind); - this.setBlock(x + 1, y, z + 2, this.kind); - this.setBlock(x, y, z + 2, this.kind); - this.setBlock(x - 1, y, z + 2, this.kind); - this.setBlock(x - 2, y, z + 2, this.kind); - this.setBlock(x - 2, y, z + 1, this.kind); - - // tower - this.setBlock(x + 2, y + 1, z, this.kind); - this.setBlock(x + 2, y + 1, z + 1, this.kind); - this.setBlock(x + 2, y + 1, z + 2, this.kind); - this.setBlock(x + 1, y + 1, z + 2, this.kind); - this.setBlock(x, y + 1, z + 2, this.kind); - - this.setBlock(x + 2, y + 2, z + 1, this.kind); - this.setBlock(x + 2, y + 2, z + 2, this.kind); - this.setBlock(x + 1, y + 2, z + 2, this.kind); - - this.setBlock(x + 2, y + 3, z + 2, this.kind); - } - } else if (yaw >= 180 && yaw < 270) { - facing = BlockFace.SOUTH_EAST; - opposite = BlockFace.NORTH_WEST; - signData = 2; - signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.EAST, 2); - if (style.equals(TeamSpawnStyle.BIG)) { - // rim - this.setBlock(x + 2, y, z + 1, this.kind); - this.setBlock(x + 2, y, z + 2, this.kind); - this.setBlock(x + 1, y, z + 2, this.kind); - this.setBlock(x, y, z + 2, this.kind); - this.setBlock(x - 1, y, z + 2, this.kind); - this.setBlock(x - 2, y, z + 2, this.kind); - this.setBlock(x - 2, y, z + 1, this.kind); - this.setBlock(x - 2, y, z, this.kind); - this.setBlock(x - 2, y, z - 1, this.kind); - this.setBlock(x - 2, y, z - 2, this.kind); - this.setBlock(x - 1, y, z - 2, this.kind); - - // tower - this.setBlock(x, y + 1, z + 2, this.kind); - this.setBlock(x - 1, y + 1, z + 2, this.kind); - this.setBlock(x - 2, y + 1, z + 2, this.kind); - this.setBlock(x - 2, y + 1, z + 1, this.kind); - this.setBlock(x - 2, y + 1, z, this.kind); - - this.setBlock(x - 1, y + 2, z + 2, this.kind); - this.setBlock(x - 2, y + 2, z + 2, this.kind); - this.setBlock(x - 2, y + 2, z + 1, this.kind); - - this.setBlock(x - 2, y + 3, z + 2, this.kind); - } - } else if (yaw >= 270 && yaw <= 360) { - facing = BlockFace.SOUTH_WEST; - opposite = BlockFace.NORTH_EAST; - signData = 6; - signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.WEST, 2); - if (style.equals(TeamSpawnStyle.BIG)) { - // rim - this.setBlock(x - 1, y, z + 2, this.kind); - this.setBlock(x - 2, y, z + 2, this.kind); - this.setBlock(x - 2, y, z + 1, this.kind); - this.setBlock(x - 2, y, z, this.kind); - this.setBlock(x - 2, y, z - 1, this.kind); - this.setBlock(x - 2, y, z - 2, this.kind); - this.setBlock(x - 1, y, z - 2, this.kind); - this.setBlock(x, y, z - 2, this.kind); - this.setBlock(x + 1, y, z - 2, this.kind); - this.setBlock(x + 2, y, z - 2, this.kind); - this.setBlock(x + 2, y, z - 1, this.kind); - - // tower - this.setBlock(x - 2, y + 1, z, this.kind); - this.setBlock(x - 2, y + 1, z - 1, this.kind); - this.setBlock(x - 2, y + 1, z - 2, this.kind); - this.setBlock(x - 1, y + 1, z - 2, this.kind); - this.setBlock(x, y + 1, z - 2, this.kind); - - this.setBlock(x - 2, y + 2, z - 1, this.kind); - this.setBlock(x - 2, y + 2, z - 2, this.kind); - this.setBlock(x - 1, y + 2, z - 2, this.kind); - - this.setBlock(x - 2, y + 3, z - 2, this.kind); - } - } - } - - if (signBlock != null) { - String[] lines = new String[4]; - lines[0] = "Team " + this.name; - lines[1] = this.players.size() + "/" + this.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE) + " players"; - lines[2] = this.points + "/" + this.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)+ " pts"; - if (this.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) == -1) { - lines[3] = "unlimited lives"; - } else { - lines[3] = this.remainingLives + "/" + this.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) + " lives left"; - } - - SignHelper.setToSign(War.war, signBlock, (byte) signData, lines); - } - - if (War.war.isSpoutServer()) { - War.war.getSpoutMessenger().updateStats(this.warzone); - } - } - - private void setBlock(int x, int y, int z, TeamKind kind) { - Block block = this.warzone.getWorld().getBlockAt(x, y, z); - block.setType(kind.getMaterial()); - block.setData(kind.getData()); - } - - public void setTeamSpawn(Location teamSpawn) { - this.teamSpawn = teamSpawn; - - // this resets the block to old state - this.setSpawnVolume(); - this.getSpawnVolume().saveBlocks(); - - this.initializeTeamSpawn(); - } - - public Location getTeamSpawn() { - return this.teamSpawn; - } - - public void addPlayer(Player player) { - this.players.add(player); - } - - public List getPlayers() { - return this.players; - } - - public void teamcast(String message) { - // by default a teamcast is a notification - teamcast(message, true); - } - - public void teamcast(String message, boolean isNotification) { - for (Player player : this.players) { - if (War.war.isSpoutServer()) { - SpoutPlayer sp = SpoutManager.getPlayer(player); - if (sp.isSpoutCraftEnabled() && isNotification) { - // team notifications go to the top left for Spout players to lessen War spam in chat box - War.war.getSpoutMessenger().msg(sp, message); - } else { - War.war.msg(player, message); - } - } else { - War.war.msg(player, message); - } - } - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - public boolean removePlayer(String name) { - Player thePlayer = null; - for (Player player : this.players) { - if (player.getName().equals(name)) { - thePlayer = player; - } - } - if (thePlayer != null) { - this.players.remove(thePlayer); - - if (this.warzone.isFlagThief(thePlayer.getName())) { - Team victim = this.warzone.getVictimTeamForFlagThief(thePlayer.getName()); - victim.getFlagVolume().resetBlocks(); - victim.initializeTeamFlag(); - this.warzone.removeFlagThief(thePlayer.getName()); - for (Team t : this.warzone.getTeams()) { - t.teamcast("Team " + ChatColor.GREEN + victim.getName() + ChatColor.WHITE + " flag was returned."); - } - } - - if (this.warzone.isBombThief(thePlayer.getName())) { - Bomb bomb = this.warzone.getBombForThief(thePlayer.getName()); - bomb.getVolume().resetBlocks(); - bomb.addBombBlocks(); - this.warzone.removeBombThief(thePlayer.getName()); - for (Team t : this.warzone.getTeams()) { - t.teamcast("Bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.WHITE + " was returned."); - } - } - - if (this.warzone.isCakeThief(thePlayer.getName())) { - Cake cake = this.warzone.getCakeForThief(thePlayer.getName()); - cake.getVolume().resetBlocks(); - cake.addCakeBlocks(); - this.warzone.removeCakeThief(thePlayer.getName()); - for (Team t : this.warzone.getTeams()) { - t.teamcast("Cake " + ChatColor.GREEN + cake.getName() + ChatColor.WHITE + " was returned."); - } - } - - return true; - } - - return false; - } - - public void setRemainingLives(int remainingLives) { - this.remainingLives = remainingLives; - } - - public int getRemainingLifes() { - return this.remainingLives; - } - - public void addPoint() { - boolean atLeastOnePlayerOnTeam = this.players.size() != 0; - boolean atLeastOnePlayerOnOtherTeam = false; - for (Team team : this.warzone.getTeams()) { - if (!team.getName().equals(this.getName()) && team.getPlayers().size() > 0) { - atLeastOnePlayerOnOtherTeam = true; - } - } - if (atLeastOnePlayerOnTeam && atLeastOnePlayerOnOtherTeam) { - this.points++; - } else if (!atLeastOnePlayerOnOtherTeam) { - this.teamcast("Can't score until at least one player joins another team."); - } - } - - public int getPoints() { - return this.points; - } - - public Volume getSpawnVolume() { - - return this.spawnVolume; - } - - public void resetSign() { - this.getSpawnVolume().resetBlocks(); - this.initializeTeamSpawn(); // reset everything instead of just sign - - if (this.warzone.getLobby() != null) { - this.warzone.getLobby().resetTeamGateSign(this); - } - } - - public void setSpawnVolume(Volume volume) { - this.spawnVolume = volume; - } - - public void resetPoints() { - this.points = 0; - } - - public void setFlagVolume(Volume flagVolume) { - this.flagVolume = flagVolume; - } - - public Volume getFlagVolume() { - return this.flagVolume; - } - - private void setFlagVolume() { - if (this.flagVolume == null) { - this.flagVolume = new Volume(this.getName() + "flag", this.warzone.getWorld()); - } - if (this.flagVolume.isSaved()) { - this.flagVolume.resetBlocks(); - } - int x = this.teamFlag.getBlockX(); - int y = this.teamFlag.getBlockY(); - int z = this.teamFlag.getBlockZ(); - this.flagVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1)); - this.flagVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1)); - } - - @SuppressWarnings("unused") - public void initializeTeamFlag() { - // make air - this.flagVolume.setToMaterial(Material.AIR); - - // Set the flag blocks - int x = this.teamFlag.getBlockX(); - int y = this.teamFlag.getBlockY(); - int z = this.teamFlag.getBlockZ(); - - // first ring - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN); - - // flag - this.warzone.getWorld().getBlockAt(x, y + 1, z).setType(this.kind.getMaterial()); - this.warzone.getWorld().getBlockAt(x, y + 1, z).setData(this.kind.getData()); - this.warzone.getWorld().getBlockAt(x, y + 2, z).setType(Material.FENCE); - - // Flag post using Orientation - int yaw = 0; - if (this.teamFlag.getYaw() >= 0) { - yaw = (int) (this.teamFlag.getYaw() % 360); - } else { - yaw = (int) (360 + (this.teamFlag.getYaw() % 360)); - } - BlockFace facing = null; - BlockFace opposite = null; - if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) { - facing = BlockFace.WEST; - opposite = BlockFace.EAST; - this.warzone.getWorld().getBlockAt(x, y, z - 1).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x, y + 2, z - 1).setType(Material.FENCE); - } else if (yaw >= 45 && yaw < 135) { - facing = BlockFace.NORTH; - opposite = BlockFace.SOUTH; - this.warzone.getWorld().getBlockAt(x + 1, y, z).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x + 1, y + 1, z).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x + 1, y + 2, z).setType(Material.FENCE); - } else if (yaw >= 135 && yaw < 225) { - facing = BlockFace.EAST; - opposite = BlockFace.WEST; - this.warzone.getWorld().getBlockAt(x, y, z + 1).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x, y + 2, z + 1).setType(Material.FENCE); - } else if (yaw >= 225 && yaw < 315) { - facing = BlockFace.SOUTH; - opposite = BlockFace.NORTH; - this.warzone.getWorld().getBlockAt(x - 1, y, z).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x - 1, y + 1, z).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x - 1, y + 2, z).setType(Material.FENCE); - } - } - - public void setTeamFlag(Location teamFlag) { - this.teamFlag = teamFlag; - - // this resets the block to old state - this.setFlagVolume(); - this.getFlagVolume().saveBlocks(); - - this.initializeTeamFlag(); - } - - public boolean isTeamFlagBlock(Block block) { - if (this.teamFlag != null) { - int flagX = this.teamFlag.getBlockX(); - int flagY = this.teamFlag.getBlockY() + 1; - int flagZ = this.teamFlag.getBlockZ(); - if (block.getX() == flagX && block.getY() == flagY && block.getZ() == flagZ) { - return true; - } - } - return false; - } - - public Location getTeamFlag() { - return this.teamFlag; - } - - public void deleteTeamFlag() { - this.getFlagVolume().resetBlocks(); - this.setFlagVolume(null); - this.teamFlag = null; - - // remove volume file - String filePath = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.warzone.getName() + "/volume-" + this.getName() + "flag.dat"; - if (!new File(filePath).delete()) { - War.war.log("Failed to delete file " + filePath, Level.WARNING); - } - } - - public InventoryBag getInventories() { - return this.inventories ; - } - - public TeamConfigBag getTeamConfig() { - return this.teamConfig; - } -} diff --git a/war/src/main/java/com/tommytony/war/TeamKind.java b/war/src/main/java/com/tommytony/war/TeamKind.java deleted file mode 100644 index fbb6fbe..0000000 --- a/war/src/main/java/com/tommytony/war/TeamKind.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.tommytony.war; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.getspout.spoutapi.gui.Color; - -public enum TeamKind { - WHITE ((byte) 0, Material.WOOL, ChatColor.WHITE), - ORANGE ((byte) 1, Material.WOOL, ChatColor.GOLD), - MAGENTA ((byte) 2, Material.WOOL, ChatColor.LIGHT_PURPLE), - BLUE ((byte) 3, Material.WOOL, ChatColor.BLUE), - GOLD ((byte) 4, Material.WOOL, ChatColor.YELLOW), // yellow = gold - GREEN ((byte) 5, Material.WOOL, ChatColor.GREEN), - PINK ((byte) 6, Material.WOOL, ChatColor.WHITE), - GRAY ((byte) 7, Material.WOOL, ChatColor.DARK_GRAY), - IRON ((byte) 8, Material.WOOL, ChatColor.GRAY), // lightgrey = iron - DIAMOND ((byte) 9, Material.WOOL, ChatColor.DARK_AQUA), // cyan = diamond - PURPLE ((byte) 10, Material.WOOL, ChatColor.DARK_PURPLE), - NAVY ((byte) 11, Material.WOOL, ChatColor.DARK_BLUE), - BROWN ((byte) 12, Material.WOOL, ChatColor.DARK_RED), - DARKGREEN ((byte) 13, Material.WOOL, ChatColor.DARK_GREEN), - RED ((byte) 14, Material.WOOL, ChatColor.RED), - BLACK ((byte) 15, Material.WOOL, ChatColor.BLACK); - - private final byte data; - private final ChatColor color; - private final Material material; - - private TeamKind(byte data, Material material, ChatColor color) { - this.data = data; - this.material = material; - this.color = color; - } - - public static TeamKind teamKindFromString(String str) { - String lowered = str.toLowerCase(); - for (TeamKind kind : TeamKind.values()) { - if (kind.toString().startsWith(lowered)) { - return kind; - } - } - return null; - } - - public byte getData() { - return this.data; - } - public ChatColor getColor() { - return this.color; - } - - /** - * Don't call unless War.war.isSpoutServer() is true - * @return - */ - public Color getSpoutColor() { - int colorCode = (int)this.data; - switch (colorCode) { - case 0: - return new Color(255,255,255); - case 1: - return new Color(255,128,0); - case 2: - return new Color(255,128,255); - case 3: - return new Color(0,0,255); - case 4: - return new Color(0,255,255); - case 5: - return new Color(0,255,0); - case 6: - return new Color(255,255,255); - case 7: - return new Color(100,100,100); - case 8: - return new Color(200,200,200); - case 9: - return new Color(128,255,255); - case 10: - return new Color(128,0,255); - case 11: - return new Color(0,0,128); - case 12: - return new Color(128,0,0); - case 13: - return new Color(0,128,0); - case 14: - return new Color(255,0,0); - case 15: - return new Color(0,0,0); - default: - return new Color(255,255,255); - } - } - - public Material getMaterial() { - return this.material; - } - - @Override - public String toString() { - return super.toString().toLowerCase(); - } -} diff --git a/war/src/main/java/com/tommytony/war/TeamSpawnStyle.java b/war/src/main/java/com/tommytony/war/TeamSpawnStyle.java deleted file mode 100644 index b485dff..0000000 --- a/war/src/main/java/com/tommytony/war/TeamSpawnStyle.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tommytony.war; - -/** - * - * @author tommytony - * - */ -public enum TeamSpawnStyle { - INVISIBLE, - SMALL, - FLAT, - BIG; - - @Override - public String toString() { - return super.toString().toLowerCase(); - } - - public static TeamSpawnStyle getStyleFromString(String string) { - for (TeamSpawnStyle style : TeamSpawnStyle.values()) { - if (string.toLowerCase().equals(style.toString())) { - return style; - } - } - - return TeamSpawnStyle.SMALL; - } -} diff --git a/war/src/main/java/com/tommytony/war/WarHub.java b/war/src/main/java/com/tommytony/war/WarHub.java deleted file mode 100644 index 794f8ac..0000000 --- a/war/src/main/java/com/tommytony/war/WarHub.java +++ /dev/null @@ -1,263 +0,0 @@ -package com.tommytony.war; - -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.utils.SignHelper; -import com.tommytony.war.volumes.BlockInfo; -import com.tommytony.war.volumes.Volume; - -/** - * - * @author tommytony, Tim Düsterhus - * @package com.tommytony.war - */ -public class WarHub { - private Location location; - private Volume volume; - private Map zoneGateBlocks = new HashMap(); - private BlockFace orientation; - - public WarHub(Location location, String hubOrientation) { - int yaw = 0; - if (hubOrientation.equals("south")) { - yaw = 270; - this.setOrientation(BlockFace.SOUTH); - } else if (hubOrientation.equals("north")) { - yaw = 90; - this.setOrientation(BlockFace.NORTH); - } else if (hubOrientation.equals("east")) { - yaw = 180; - this.setOrientation(BlockFace.EAST); - } else { - yaw = 0; - this.setOrientation(BlockFace.WEST); - } - - this.location = new Location(location.getWorld(), - location.getX(), - location.getY(), - location.getZ(), - yaw, 0); - this.volume = new Volume("warhub", location.getWorld()); - } - - // Use when creating from player location (with yaw) - public WarHub(Location location) { - this.location = location; - this.volume = new Volume("warhub", location.getWorld()); - - this.setLocation(location); - } - - public Volume getVolume() { - return this.volume; - } - - public void setLocation(Location loc) { - this.location = loc; - // Lobby orientation - int yaw = 0; - if (this.location.getYaw() >= 0) { - yaw = (int) (this.location.getYaw() % 360); - } else { - yaw = (int) (360 + (this.location.getYaw() % 360)); - } - - BlockFace facing = null; - if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) { - facing = BlockFace.WEST; - } else if (yaw >= 45 && yaw < 135) { - facing = BlockFace.NORTH; - } else if (yaw >= 135 && yaw < 225) { - facing = BlockFace.EAST; - } else if (yaw >= 225 && yaw < 315) { - facing = BlockFace.SOUTH; - } - this.setOrientation(facing); - } - - public Location getLocation() { - return this.location; - } - - public Warzone getDestinationWarzoneForLocation(Location playerLocation) { - Warzone zone = null; - for (String zoneName : this.zoneGateBlocks.keySet()) { - Block gate = this.zoneGateBlocks.get(zoneName); - if (gate.getX() == playerLocation.getBlockX() && gate.getY() == playerLocation.getBlockY() && gate.getZ() == playerLocation.getBlockZ()) { - zone = War.war.findWarzone(zoneName); - } - } - return zone; - } - - public void initialize() { - // for now, draw the wall of gates to the west - this.zoneGateBlocks.clear(); - int disabled = 0; - for (Warzone zone : War.war.getWarzones()) { - if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) { - disabled++; - } - } - int noOfWarzones = War.war.getWarzones().size() - disabled; - if (noOfWarzones > 0) { - int hubWidth = noOfWarzones * 4 + 2; - int halfHubWidth = hubWidth / 2; - int hubDepth = 6; - int hubHeigth = 4; - - BlockFace left; - BlockFace right; - BlockFace front = this.getOrientation(); - BlockFace back; - byte data; - if (this.getOrientation() == BlockFace.SOUTH) { - data = (byte) 4; - left = BlockFace.EAST; - right = BlockFace.WEST; - back = BlockFace.NORTH; - } else if (this.getOrientation() == BlockFace.NORTH) { - data = (byte) 12; - left = BlockFace.WEST; - right = BlockFace.EAST; - back = BlockFace.SOUTH; - } else if (this.getOrientation() == BlockFace.EAST) { - data = (byte) 0; - left = BlockFace.NORTH; - right = BlockFace.SOUTH; - back = BlockFace.WEST; - } else { - data = (byte) 8; - left = BlockFace.SOUTH; - right = BlockFace.NORTH; - back = BlockFace.EAST; - } - - Block locationBlock = this.location.getWorld().getBlockAt(this.location.getBlockX(), this.location.getBlockY(), this.location.getBlockZ()); - - this.volume.setWorld(this.location.getWorld()); - this.volume.setCornerOne(locationBlock.getRelative(back).getRelative(left, halfHubWidth).getRelative(BlockFace.DOWN)); - this.volume.setCornerTwo(locationBlock.getRelative(right, halfHubWidth).getRelative(front, hubDepth).getRelative(BlockFace.UP, hubHeigth)); - this.volume.saveBlocks(); - - // glass floor - this.volume.clearBlocksThatDontFloat(); - this.volume.setToMaterial(Material.AIR); - this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); - - // draw gates - Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(front, hubDepth).getRelative(right, 2); - - for (Warzone zone : War.war.getWarzones()) { // gonna use the index to find it again - if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) { - this.zoneGateBlocks.put(zone.getName(), currentGateBlock); - currentGateBlock.getRelative(BlockFace.DOWN).setType(Material.GLOWSTONE); - currentGateBlock.getRelative(left).setType(Material.OBSIDIAN); - currentGateBlock.getRelative(right).getRelative(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock.getRelative(left).getRelative(BlockFace.UP).getRelative(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock.getRelative(right).setType(Material.OBSIDIAN); - currentGateBlock.getRelative(left).getRelative(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock.getRelative(right).getRelative(BlockFace.UP).getRelative(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock = currentGateBlock.getRelative(right, 4); - - } - } - - // War hub sign - Block signBlock = locationBlock.getRelative(front); - - String[] lines = new String[4]; - lines[0] = "War hub"; - lines[1] = "(/warhub)"; - lines[2] = "Pick your"; - lines[3] = "battle!"; - SignHelper.setToSign(War.war, signBlock, data, lines); - - // Warzone signs - for (Warzone zone : War.war.getWarzones()) { - if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) && zone.ready()) { - this.resetZoneSign(zone); - } - } - } - } - - /** - * Resets the sign of the given warzone - * - * @param Warzone - * zone - */ - public void resetZoneSign(Warzone zone) { - BlockFace left; - BlockFace back; - byte data; - if (this.getOrientation() == BlockFace.SOUTH) { - data = (byte) 4; - left = BlockFace.EAST; - back = BlockFace.NORTH; - } else if (this.getOrientation() == BlockFace.NORTH) { - data = (byte) 12; - left = BlockFace.WEST; - back = BlockFace.SOUTH; - } else if (this.getOrientation() == BlockFace.EAST) { - data = (byte) 0; - left = BlockFace.NORTH; - back = BlockFace.WEST; - } else { - data = (byte) 8; - left = BlockFace.SOUTH; - back = BlockFace.EAST; - } - - Block zoneGate = this.zoneGateBlocks.get(zone.getName()); - if (zoneGate != null) { - Block block = zoneGate.getRelative(left).getRelative(back, 1); - if (block.getType() != Material.SIGN_POST) { - block.setType(Material.SIGN_POST); - } - block.setData(data); - - int zoneCap = 0; - int zonePlayers = 0; - for (Team t : zone.getTeams()) { - zonePlayers += t.getPlayers().size(); - zoneCap += t.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE); - } - String[] lines = new String[4]; - lines[0] = "Warzone"; - lines[1] = zone.getName(); - lines[2] = zonePlayers + "/" + zoneCap + " players"; - lines[3] = zone.getTeams().size() + " teams"; - SignHelper.setToSign(War.war, block, data, lines); - } else { - War.war.log("Failed to find warhub gate for " + zone.getName() + " warzone.", Level.WARNING); - } - } - - public void setVolume(Volume vol) { - this.volume = vol; - } - - public void setOrientation(BlockFace orientation) { - this.orientation = orientation; - } - - public BlockFace getOrientation() { - return this.orientation; - } - -} diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java deleted file mode 100644 index 09c4b56..0000000 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ /dev/null @@ -1,1295 +0,0 @@ -package com.tommytony.war; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; - -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.entity.CraftItem; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.player.SpoutPlayer; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.config.InventoryBag; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.TeamConfigBag; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.config.WarzoneConfigBag; -import com.tommytony.war.jobs.InitZoneJob; -import com.tommytony.war.jobs.LoadoutResetJob; -import com.tommytony.war.jobs.ScoreCapReachedJob; -import com.tommytony.war.mappers.LoadoutYmlMapper; -import com.tommytony.war.spout.SpoutMessenger; -import com.tommytony.war.utils.PlayerState; -import com.tommytony.war.volumes.ZoneVolume; - -/** - * - * @author tommytony - * @package com.tommytony.war - */ -public class Warzone { - private String name; - private ZoneVolume volume; - private World world; - private final List teams = new ArrayList(); - private final List monuments = new ArrayList(); - private final List bombs = new ArrayList(); - private final List cakes = new ArrayList(); - private Location teleport; - private ZoneLobby lobby; - private Location rallyPoint; - - private final List authors = new ArrayList(); - - private final int minSafeDistanceFromWall = 6; - private List zoneWallGuards = new ArrayList(); - private HashMap playerStates = new HashMap(); - private HashMap flagThieves = new HashMap(); - private HashMap bombThieves = new HashMap(); - private HashMap cakeThieves = new HashMap(); - private HashMap loadoutSelections = new HashMap(); - private HashMap deadMenInventories = new HashMap(); - private final List respawn = new ArrayList(); - - private final WarzoneConfigBag warzoneConfig = new WarzoneConfigBag(); - private final TeamConfigBag teamDefaultConfig = new TeamConfigBag(); - private InventoryBag defaultInventories = new InventoryBag(); - - public Warzone(World world, String name) { - this.world = world; - this.name = name; - this.volume = new ZoneVolume(name, this.getWorld(), this); - } - - public static Warzone getZoneByName(String name) { - Warzone bestGuess = null; - for (Warzone warzone : War.war.getWarzones()) { - if (warzone.getName().toLowerCase().equals(name.toLowerCase())) { - // perfect match, return right away - return warzone; - } else if (warzone.getName().toLowerCase().startsWith(name.toLowerCase())) { - // perhaps there's a perfect match in the remaining zones, let's take this one aside - bestGuess = warzone; - } - } - return bestGuess; - } - - public static Warzone getZoneByLocation(Location location) { - for (Warzone warzone : War.war.getWarzones()) { - if (location.getWorld().getName().equals(warzone.getWorld().getName()) && warzone.getVolume() != null && warzone.getVolume().contains(location)) { - return warzone; - } - } - return null; - } - - public static Warzone getZoneByLocation(Player player) { - return Warzone.getZoneByLocation(player.getLocation()); - } - - public static Warzone getZoneByPlayerName(String playerName) { - for (Warzone warzone : War.war.getWarzones()) { - Team team = warzone.getPlayerTeam(playerName); - if (team != null) { - return warzone; - } - } - return null; - } - - public boolean ready() { - if (this.volume.hasTwoCorners() && !this.volume.tooSmall() && !this.volume.tooBig()) { - return true; - } - return false; - } - - public List getTeams() { - return this.teams; - } - - public Team getPlayerTeam(String playerName) { - for (Team team : this.teams) { - for (Player player : team.getPlayers()) { - if (player.getName().equals(playerName)) { - return team; - } - } - } - return null; - } - - public String getTeamInformation() { - String teamsMessage = "Teams: "; - if (this.getTeams().isEmpty()) { - teamsMessage += "none."; - } else { - for (Team team : this.getTeams()) { - teamsMessage += team.getName() + " (" + team.getPoints() + " points, " + team.getRemainingLifes() + "/" - + team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) + " lives left. "; - for (Player member : team.getPlayers()) { - teamsMessage += member.getName() + " "; - } - teamsMessage += ") "; - } - } - return teamsMessage; - } - - public String getName() { - return this.name; - } - - @Override - public String toString() { - return this.getName(); - } - - public void setTeleport(Location location) { - this.teleport = location; - } - - public Location getTeleport() { - return this.teleport; - } - - public int saveState(boolean clearArtifacts) { - if (this.ready()) { - if (clearArtifacts) { - // removed everything to keep save clean - for (ZoneWallGuard guard : this.zoneWallGuards) { - guard.deactivate(); - } - this.zoneWallGuards.clear(); - - for (Team team : this.teams) { - team.getSpawnVolume().resetBlocks(); - if (team.getTeamFlag() != null) { - team.getFlagVolume().resetBlocks(); - } - } - - for (Monument monument : this.monuments) { - monument.getVolume().resetBlocks(); - } - - if (this.lobby != null) { - this.lobby.getVolume().resetBlocks(); - } - } - - int saved = this.volume.saveBlocks(); - if (clearArtifacts) { - this.initializeZone(); // bring back stuff - } - return saved; - } - return 0; - } - - /** - * Goes back to the saved state of the warzone (resets only block types, not physics). Also teleports all players back to their respective spawns. - * - * @return - */ - public void initializeZone() { - this.initializeZone(null); - } - - public void initializeZone(Player respawnExempted) { - if (this.ready() && this.volume.isSaved()) { - // everyone back to team spawn with full health - for (Team team : this.teams) { - for (Player player : team.getPlayers()) { - if (player != respawnExempted) { - this.respawnPlayer(team, player); - } - } - team.setRemainingLives(team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL)); - team.initializeTeamSpawn(); - if (team.getTeamFlag() != null) { - team.setTeamFlag(team.getTeamFlag()); - } - } - - this.initZone(); - } - } - - public void initializeZoneAsJob(Player respawnExempted) { - InitZoneJob job = new InitZoneJob(this, respawnExempted); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - } - - public void initializeZoneAsJob() { - InitZoneJob job = new InitZoneJob(this); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - } - - private void initZone() { - // reset monuments - for (Monument monument : this.monuments) { - monument.getVolume().resetBlocks(); - monument.addMonumentBlocks(); - } - - // reset bombs - for (Bomb bomb : this.bombs) { - bomb.getVolume().resetBlocks(); - bomb.addBombBlocks(); - } - - // reset cakes - for (Cake cake : this.cakes) { - cake.getVolume().resetBlocks(); - cake.addCakeBlocks(); - } - - // reset lobby (here be demons) - if (this.lobby != null) { - this.lobby.initialize(); - } - - this.flagThieves.clear(); - - // nom drops - for(Entity entity : (this.getWorld().getEntities())) { - if (!(entity instanceof Item) && !(entity instanceof CraftItem)) { - continue; - } - // validate position - if (!this.getVolume().contains(entity.getLocation())) { - continue; - } - - // omnomnomnom - entity.remove(); - } - } - - public void endRound() { - - } - - public void respawnPlayer(Team team, Player player) { - this.handleRespawn(team, player); - // Teleport the player back to spawn - player.teleport(team.getTeamSpawn()); - } - - public void respawnPlayer(PlayerMoveEvent event, Team team, Player player) { - this.handleRespawn(team, player); - // Teleport the player back to spawn - event.setTo(team.getTeamSpawn()); - } - - public boolean isRespawning(Player p) { - return respawn.contains(p); - } - - private void handleRespawn(final Team team, final Player player) { - // Fill hp - player.setRemainingAir(300); - player.setHealth(20); - player.setFoodLevel(20); - player.setSaturation(team.getTeamConfig().resolveInt(TeamConfig.SATURATION)); - player.setExhaustion(0); - player.setFireTicks(0); //this works fine here, why put it in LoudoutResetJob...? I'll keep it over there though - - player.getInventory().clear(); - - if (player.getGameMode() == GameMode.CREATIVE) { - player.setGameMode(GameMode.SURVIVAL); - } - // clear potion effects - PotionEffect.clearPotionEffects(player); - - boolean isFirstRespawn = false; - if (!this.getLoadoutSelections().keySet().contains(player.getName())) { - isFirstRespawn = true; - this.getLoadoutSelections().put(player.getName(), new LoadoutSelection(true, 0)); - } else { - this.getLoadoutSelections().get(player.getName()).setStillInSpawn(true); - } - - // Spout - if (War.war.isSpoutServer()) { - SpoutManager.getPlayer(player).setTitle(team.getKind().getColor() + player.getName()); - } - - final LoadoutResetJob job = new LoadoutResetJob(this, team, player, isFirstRespawn, false); - if (team.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER) == 0 || isFirstRespawn) { - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - } - else { - // "Respawn" Timer - player will not be able to leave spawn for a few seconds - respawn.add(player); - - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, new Runnable() { - public void run() { - respawn.remove(player); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - } - }, team.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER) * 20L); // 20 ticks = 1 second - } - } - - public void resetInventory(Team team, Player player, HashMap loadout) { - // Reset inventory to loadout - PlayerInventory playerInv = player.getInventory(); - playerInv.clear(); - playerInv.clear(playerInv.getSize() + 0); - playerInv.clear(playerInv.getSize() + 1); - playerInv.clear(playerInv.getSize() + 2); - playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead - for (Integer slot : loadout.keySet()) { - if (slot == 100) { - playerInv.setBoots(War.war.copyStack(loadout.get(slot))); - } else if (slot == 101) { - playerInv.setLeggings(War.war.copyStack(loadout.get(slot))); - } else if (slot == 102) { - playerInv.setChestplate(War.war.copyStack(loadout.get(slot))); - } else { - ItemStack item = loadout.get(slot); - if (item != null) { - playerInv.addItem(War.war.copyStack(item)); - } - } - } - if (this.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) { - playerInv.setHelmet(new ItemStack(team.getKind().getMaterial(), 1, (short) 1, new Byte(team.getKind().getData()))); - } else { - if (team.getKind() == TeamKind.GOLD) { - playerInv.setHelmet(new ItemStack(Material.GOLD_HELMET)); - } else if (team.getKind() == TeamKind.DIAMOND) { - playerInv.setHelmet(new ItemStack(Material.DIAMOND_HELMET)); - } else if (team.getKind() == TeamKind.IRON) { - playerInv.setHelmet(new ItemStack(Material.IRON_HELMET)); - } else { - playerInv.setHelmet(new ItemStack(Material.LEATHER_HELMET)); - } - } - } - - public boolean isMonumentCenterBlock(Block block) { - for (Monument monument : this.monuments) { - int x = monument.getLocation().getBlockX(); - int y = monument.getLocation().getBlockY() + 1; - int z = monument.getLocation().getBlockZ(); - if (x == block.getX() && y == block.getY() && z == block.getZ()) { - return true; - } - } - return false; - } - - public Monument getMonumentFromCenterBlock(Block block) { - for (Monument monument : this.monuments) { - int x = monument.getLocation().getBlockX(); - int y = monument.getLocation().getBlockY() + 1; - int z = monument.getLocation().getBlockZ(); - if (x == block.getX() && y == block.getY() && z == block.getZ()) { - return monument; - } - } - return null; - } - - public boolean nearAnyOwnedMonument(Location to, Team team) { - for (Monument monument : this.monuments) { - if (monument.isNear(to) && monument.isOwner(team)) { - return true; - } - } - return false; - } - - public List getMonuments() { - return this.monuments; - } - -// public void setLifePool(int lifePool) { -// this.lifePool = lifePool; -// for (Team team : this.teams) { -// team.setRemainingLives(lifePool); -// } -// } - - public boolean hasPlayerState(String playerName) { - return this.playerStates.containsKey(playerName); - } - - public void keepPlayerState(Player player) { - PlayerInventory inventory = player.getInventory(); - ItemStack[] contents = inventory.getContents(); - List potionEffects = PotionEffect.getCurrentPotionEffects(player); - - String playerTitle = player.getName(); - if (War.war.isSpoutServer()) { - playerTitle = SpoutManager.getPlayer(player).getTitle(); - } - - this.playerStates.put(player.getName(), new PlayerState(player.getGameMode(), - contents, - inventory.getHelmet(), - inventory.getChestplate(), - inventory.getLeggings(), - inventory.getBoots(), - player.getHealth(), - player.getExhaustion(), - player.getSaturation(), - player.getFoodLevel(), - potionEffects, - playerTitle)); - } - - public void restorePlayerState(Player player) { - PlayerState originalContents = this.playerStates.remove(player.getName()); - PlayerInventory playerInv = player.getInventory(); - if (originalContents != null) { - this.playerInvFromInventoryStash(playerInv, originalContents); - player.setGameMode(originalContents.getGamemode()); - player.setHealth(originalContents.getHealth()); - player.setExhaustion(originalContents.getExhaustion()); - player.setSaturation(originalContents.getSaturation()); - player.setFoodLevel(originalContents.getFoodLevel()); - PotionEffect.restorePotionEffects(player, originalContents.getPotionEffects()); - - if (War.war.isSpoutServer()) { - SpoutManager.getPlayer(player).setTitle(originalContents.getPlayerTitle()); - } - } - } - - private void playerInvFromInventoryStash(PlayerInventory playerInv, PlayerState originalContents) { - playerInv.clear(); - playerInv.clear(playerInv.getSize() + 0); - playerInv.clear(playerInv.getSize() + 1); - playerInv.clear(playerInv.getSize() + 2); - playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead - for (ItemStack item : originalContents.getContents()) { - if (item != null && item.getTypeId() != 0) { - playerInv.addItem(item); - } - } - if (originalContents.getHelmet() != null && originalContents.getHelmet().getType() != Material.AIR) { - playerInv.setHelmet(originalContents.getHelmet()); - } - if (originalContents.getChest() != null && originalContents.getChest().getType() != Material.AIR) { - playerInv.setChestplate(originalContents.getChest()); - } - if (originalContents.getLegs() != null && originalContents.getLegs().getType() != Material.AIR) { - playerInv.setLeggings(originalContents.getLegs()); - } - if (originalContents.getFeet() != null && originalContents.getFeet().getType() != Material.AIR) { - playerInv.setBoots(originalContents.getFeet()); - } - } - - public PlayerState getPlayerState(String playerName) { - if (this.playerStates.containsKey(playerName)) { - return this.playerStates.get(playerName); - } - return null; - } - - public boolean hasMonument(String monumentName) { - for (Monument monument : this.monuments) { - if (monument.getName().startsWith(monumentName)) { - return true; - } - } - return false; - } - - public Monument getMonument(String monumentName) { - for (Monument monument : this.monuments) { - if (monument.getName().startsWith(monumentName)) { - return monument; - } - } - return null; - } - - public boolean hasBomb(String bombName) { - for (Bomb bomb : this.bombs) { - if (bomb.getName().equals(bombName)) { - return true; - } - } - return false; - } - - public Bomb getBomb(String bombName) { - for (Bomb bomb : this.bombs) { - if (bomb.getName().startsWith(bombName)) { - return bomb; - } - } - return null; - } - - public boolean hasCake(String cakeName) { - for (Cake cake : this.cakes) { - if (cake.getName().equals(cakeName)) { - return true; - } - } - return false; - } - - public Cake getCake(String cakeName) { - for (Cake cake : this.cakes) { - if (cake.getName().startsWith(cakeName)) { - return cake; - } - } - return null; - } - - public boolean isImportantBlock(Block block) { - if (this.ready()) { - for (Monument m : this.monuments) { - if (m.getVolume().contains(block)) { - return true; - } - } - for (Bomb b : this.bombs) { - if (b.getVolume().contains(block)) { - return true; - } - } - for (Cake c : this.cakes) { - if (c.getVolume().contains(block)) { - return true; - } - } - for (Team t : this.teams) { - if (t.getSpawnVolume().contains(block)) { - return true; - } else if (t.getFlagVolume() != null && t.getFlagVolume().contains(block)) { - return true; - } - } - if (this.volume.isWallBlock(block)) { - return true; - } - } - return false; - } - - public World getWorld() { - - return this.world; - } - - public void setWorld(World world) { - this.world = world; - } - - public ZoneVolume getVolume() { - return this.volume; - } - - public void setVolume(ZoneVolume zoneVolume) { - this.volume = zoneVolume; - } - - public Team getTeamByKind(TeamKind kind) { - for (Team t : this.teams) { - if (t.getKind() == kind) { - return t; - } - } - return null; - } - - public boolean isNearWall(Location latestPlayerLocation) { - if (this.volume.hasTwoCorners()) { - if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - return true; // near east wall - } else if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - return true; // near south wall - } else if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - return true; // near north wall - } else if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - return true; // near west wall - } else if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { - return true; // near up wall - } else if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { - return true; // near down wall - } - } - return false; - } - - public List getNearestWallBlocks(Location latestPlayerLocation) { - List nearestWallBlocks = new ArrayList(); - if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - // near east wall - Block eastWallBlock = this.world.getBlockAt(latestPlayerLocation.getBlockX() + 1, latestPlayerLocation.getBlockY() + 1, this.volume.getSoutheastZ()); - nearestWallBlocks.add(eastWallBlock); - } - - if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - // near south wall - Block southWallBlock = this.world.getBlockAt(this.volume.getSoutheastX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ()); - nearestWallBlocks.add(southWallBlock); - } - - if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - // near north wall - Block northWallBlock = this.world.getBlockAt(this.volume.getNorthwestX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ()); - nearestWallBlocks.add(northWallBlock); - } - - if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - // near west wall - Block westWallBlock = this.world.getBlockAt(latestPlayerLocation.getBlockX(), latestPlayerLocation.getBlockY() + 1, this.volume.getNorthwestZ()); - nearestWallBlocks.add(westWallBlock); - } - - if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { - // near up wall - Block upWallBlock = this.world.getBlockAt(latestPlayerLocation.getBlockX(), this.volume.getMaxY(), latestPlayerLocation.getBlockZ()); - nearestWallBlocks.add(upWallBlock); - } - - if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { - // near down wall - Block downWallBlock = this.world.getBlockAt(latestPlayerLocation.getBlockX(), this.volume.getMinY(), latestPlayerLocation.getBlockZ()); - nearestWallBlocks.add(downWallBlock); - } - return nearestWallBlocks; - // note: y + 1 to line up 3 sided square with player eyes - } - - public List getNearestWalls(Location latestPlayerLocation) { - List walls = new ArrayList(); - if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - // near east wall - walls.add(BlockFace.EAST); - } - - if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - // near south wall - walls.add(BlockFace.SOUTH); - } - - if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - // near north wall - walls.add(BlockFace.NORTH); - } - - if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - // near west wall - walls.add(BlockFace.WEST); - } - - if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { - // near up wall - walls.add(BlockFace.UP); - } - - if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { - // near down wall - walls.add(BlockFace.DOWN); - } - return walls; - } - - public ZoneWallGuard getPlayerZoneWallGuard(String name, BlockFace wall) { - for (ZoneWallGuard guard : this.zoneWallGuards) { - if (guard.getPlayer().getName().equals(name) && wall == guard.getWall()) { - return guard; - } - } - return null; - } - - public boolean protectZoneWallAgainstPlayer(Player player) { - List nearestWalls = this.getNearestWalls(player.getLocation()); - boolean protecting = false; - for (BlockFace wall : nearestWalls) { - ZoneWallGuard guard = this.getPlayerZoneWallGuard(player.getName(), wall); - if (guard != null) { - // already protected, need to move the guard - guard.updatePlayerPosition(player.getLocation()); - } else { - // new guard - guard = new ZoneWallGuard(player, War.war, this, wall); - this.zoneWallGuards.add(guard); - } - protecting = true; - } - return protecting; - } - - public void dropZoneWallGuardIfAny(Player player) { - List playerGuards = new ArrayList(); - for (ZoneWallGuard guard : this.zoneWallGuards) { - if (guard.getPlayer().getName().equals(player.getName())) { - playerGuards.add(guard); - guard.deactivate(); - } - } - // now remove those zone guards - for (ZoneWallGuard playerGuard : playerGuards) { - this.zoneWallGuards.remove(playerGuard); - } - playerGuards.clear(); - } - - public void setLobby(ZoneLobby lobby) { - this.lobby = lobby; - } - - public ZoneLobby getLobby() { - return this.lobby; - } - - public Team autoAssign(Player player) { - Team lowestNoOfPlayers = null; - for (Team t : this.teams) { - if (lowestNoOfPlayers == null || (lowestNoOfPlayers != null && lowestNoOfPlayers.getPlayers().size() > t.getPlayers().size())) { - lowestNoOfPlayers = t; - } - } - if (lowestNoOfPlayers != null) { - lowestNoOfPlayers.addPlayer(player); - lowestNoOfPlayers.resetSign(); - if (!this.hasPlayerState(player.getName())) { - this.keepPlayerState(player); - } - War.war.msg(player, "Your inventory is in storage until you use '/war leave'."); - this.respawnPlayer(lowestNoOfPlayers, player); - for (Team team : this.teams) { - team.teamcast("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + "."); - } - } - return lowestNoOfPlayers; - } - - public void handleDeath(Player player) { - Team playerTeam = Team.getTeamByPlayerName(player.getName()); - Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); - if (playerTeam != null && playerWarzone != null) { - // teleport to team spawn upon death - - playerWarzone.respawnPlayer(playerTeam, player); - int remaining = playerTeam.getRemainingLifes(); - if (remaining == 0) { // your death caused your team to lose - List teams = playerWarzone.getTeams(); - String scores = ""; - for (Team t : teams) { - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification("Round over! " + playerTeam.getKind().getColor() + playerTeam.getName()), - SpoutMessenger.cleanForNotification("ran out of lives."), - playerTeam.getKind().getMaterial(), - playerTeam.getKind().getData(), - 10000); - } - } - } - t.teamcast("The battle is over. Team " + playerTeam.getName() + " lost: " + player.getName() + " died and there were no lives left in their life pool."); - - if (t.getPlayers().size() != 0 && !t.getTeamConfig().resolveBoolean(TeamConfig.FLAGPOINTSONLY)) { - if (!t.getName().equals(playerTeam.getName())) { - // all other teams get a point - t.addPoint(); - t.resetSign(); - } - scores += t.getName() + "(" + t.getPoints() + "/" + t.getTeamConfig().resolveInt(TeamConfig.MAXSCORE) + ") "; - } - } - if (!scores.equals("")) { - for (Team t : teams) { - t.teamcast("New scores - " + scores); - } - } - // detect score cap - List scoreCapTeams = new ArrayList(); - for (Team t : teams) { - if (t.getPoints() == t.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) { - scoreCapTeams.add(t); - } - } - if (!scoreCapTeams.isEmpty()) { - String winnersStr = ""; - for (Team winner : scoreCapTeams) { - if (winner.getPlayers().size() != 0) { - winnersStr += winner.getName() + " "; - } - } - - playerWarzone.handleScoreCapReached(player, winnersStr); - // player.teleport(playerWarzone.getTeleport()); - // player will die because it took too long :( - // we dont restore his inventory in handleScoreCapReached - // check out PLAYER_MOVE for the rest of the fix - - } else { - // A new battle starts. Reset the zone but not the teams. - for (Team t : teams) { - t.teamcast("A new battle begins. Resetting warzone..."); - } - playerWarzone.getVolume().resetBlocksAsJob(); - playerWarzone.initializeZoneAsJob(player); - } - } else { - // player died without causing his team's demise - if (playerWarzone.isFlagThief(player.getName())) { - // died while carrying flag.. dropped it - Team victim = playerWarzone.getVictimTeamForFlagThief(player.getName()); - victim.getFlagVolume().resetBlocks(); - victim.initializeTeamFlag(); - playerWarzone.removeFlagThief(player.getName()); - - if (War.war.isSpoutServer()) { - for (Player p : victim.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " dropped"), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "your flag."), - playerTeam.getKind().getMaterial(), - playerTeam.getKind().getData(), - 5000); - } - } - } - - for (Team t : playerWarzone.getTeams()) { - t.teamcast(player.getName() + " died and dropped team " + victim.getName() + "'s flag."); - } - } - - // Bomb thieves - if (playerWarzone.isBombThief(player.getName())) { - // died while carrying bomb.. dropped it - Bomb bomb = playerWarzone.getBombForThief(player.getName()); - bomb.getVolume().resetBlocks(); - bomb.addBombBlocks(); - playerWarzone.removeBombThief(player.getName()); - - for (Team t : playerWarzone.getTeams()) { - t.teamcast(player.getName() + " died and dropped bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.WHITE + "."); - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " dropped"), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.YELLOW + "."), - Material.TNT, - (short)0, - 5000); - } - } - } - } - } - - if (playerWarzone.isCakeThief(player.getName())) { - // died while carrying cake.. dropped it - Cake cake = playerWarzone.getCakeForThief(player.getName()); - cake.getVolume().resetBlocks(); - cake.addCakeBlocks(); - playerWarzone.removeCakeThief(player.getName()); - - for (Team t : playerWarzone.getTeams()) { - t.teamcast(player.getName() + " died and dropped cake " + ChatColor.GREEN + cake.getName() + ChatColor.WHITE + "."); - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " dropped"), - SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "cake " + ChatColor.GREEN + cake.getName() + ChatColor.YELLOW + "."), - Material.CAKE, - (short)0, - 5000); - } - } - } - } - } - - // Lifepool empty warning - playerTeam.setRemainingLives(remaining - 1); - if (remaining - 1 == 0) { - for (Team t : playerWarzone.getTeams()) { - t.teamcast("Team " + playerTeam.getName() + "'s life pool is empty. One more death and they lose the battle!"); - } - } - } - playerTeam.resetSign(); - } - } - - public void handlePlayerLeave(Player player, Location destination, PlayerMoveEvent event, boolean removeFromTeam) { - this.handlePlayerLeave(player, removeFromTeam); - event.setTo(destination); - } - - public void handlePlayerLeave(Player player, Location destination, boolean removeFromTeam) { - this.handlePlayerLeave(player, removeFromTeam); - player.teleport(destination); - } - - private void handlePlayerLeave(Player player, boolean removeFromTeam) { - Team playerTeam = Team.getTeamByPlayerName(player.getName()); - if (playerTeam != null) { - if (removeFromTeam) { - playerTeam.removePlayer(player.getName()); - } - for (Team t : this.getTeams()) { - t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE + " left the zone."); - } - playerTeam.resetSign(); - - if (this.getLobby() != null) { - this.getLobby().resetTeamGateSign(playerTeam); - } - if (this.hasPlayerState(player.getName())) { - this.restorePlayerState(player); - } - if (this.getLoadoutSelections().containsKey(player.getName())) { - // clear inventory selection - this.getLoadoutSelections().remove(player.getName()); - } - player.setFireTicks(0); - player.setRemainingAir(300); - - // To hide stats - if (War.war.isSpoutServer()) { - War.war.getSpoutMessenger().updateStats(player); - } - - War.war.msg(player, "Your inventory is being restored."); - if (War.war.getWarHub() != null) { - War.war.getWarHub().resetZoneSign(this); - } - - boolean zoneEmpty = true; - for (Team team : this.getTeams()) { - if (team.getPlayers().size() > 0) { - zoneEmpty = false; - break; - } - } - if (zoneEmpty && this.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONEMPTY)) { - // reset the zone for a new game when the last player leaves - for (Team team : this.getTeams()) { - team.resetPoints(); - team.setRemainingLives(team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL)); - } - this.getVolume().resetBlocksAsJob(); - this.initializeZoneAsJob(); - War.war.log("Last player left warzone " + this.getName() + ". Warzone blocks resetting automatically...", Level.INFO); - } - } - } - - public boolean isEnemyTeamFlagBlock(Team playerTeam, Block block) { - for (Team team : this.teams) { - if (!team.getName().equals(playerTeam.getName()) && team.isTeamFlagBlock(block)) { - return true; - } - } - return false; - } - - public boolean isFlagBlock(Block block) { - for (Team team : this.teams) { - if (team.isTeamFlagBlock(block)) { - return true; - } - } - return false; - } - - public Team getTeamForFlagBlock(Block block) { - for (Team team : this.teams) { - if (team.isTeamFlagBlock(block)) { - return team; - } - } - return null; - } - - public boolean isBombBlock(Block block) { - for (Bomb bomb : this.bombs) { - if (bomb.isBombBlock(block.getLocation())) { - return true; - } - } - return false; - } - - public Bomb getBombForBlock(Block block) { - for (Bomb bomb : this.bombs) { - if (bomb.isBombBlock(block.getLocation())) { - return bomb; - } - } - return null; - } - - public boolean isCakeBlock(Block block) { - for (Cake cake : this.cakes) { - if (cake.isCakeBlock(block.getLocation())) { - return true; - } - } - return false; - } - - public Cake getCakeForBlock(Block block) { - for (Cake cake : this.cakes) { - if (cake.isCakeBlock(block.getLocation())) { - return cake; - } - } - return null; - } - - // Flags - public void addFlagThief(Team lostFlagTeam, String flagThief) { - this.flagThieves.put(flagThief, lostFlagTeam); - } - - public boolean isFlagThief(String suspect) { - if (this.flagThieves.containsKey(suspect)) { - return true; - } - return false; - } - - public Team getVictimTeamForFlagThief(String thief) { - return this.flagThieves.get(thief); - } - - public void removeFlagThief(String thief) { - this.flagThieves.remove(thief); - } - - // Bomb - public void addBombThief(Bomb bomb, String bombThief) { - this.bombThieves.put(bombThief, bomb); - } - - public boolean isBombThief(String suspect) { - if (this.bombThieves.containsKey(suspect)) { - return true; - } - return false; - } - - public Bomb getBombForThief(String thief) { - return this.bombThieves.get(thief); - } - - public void removeBombThief(String thief) { - this.bombThieves.remove(thief); - } - - // Cake - - public void addCakeThief(Cake cake, String cakeThief) { - this.cakeThieves.put(cakeThief, cake); - } - - public boolean isCakeThief(String suspect) { - if (this.cakeThieves.containsKey(suspect)) { - return true; - } - return false; - } - - public Cake getCakeForThief(String thief) { - return this.cakeThieves.get(thief); - } - - public void removeCakeThief(String thief) { - this.cakeThieves.remove(thief); - } - - public void clearThieves() { - this.flagThieves.clear(); - this.bombThieves.clear(); - this.cakeThieves.clear(); - } - - public boolean isTeamFlagStolen(Team team) { - for (String playerKey : this.flagThieves.keySet()) { - if (this.flagThieves.get(playerKey).getName().equals(team.getName())) { - return true; - } - } - return false; - } - - public void handleScoreCapReached(Player player, String winnersStr) { - // Score cap reached. Reset everything. - ScoreCapReachedJob job = new ScoreCapReachedJob(this, winnersStr); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - this.getVolume().resetBlocksAsJob(); - this.initializeZoneAsJob(player); - if (War.war.getWarHub() != null) { - // TODO: test if warhub sign gives the correct info despite the jobs - War.war.getWarHub().resetZoneSign(this); - } - } - -// public void setSpawnStyle(TeamSpawnStyle spawnStyle) { -// this.spawnStyle = spawnStyle; -// for (Team team : this.teams) { -// team.setTeamSpawn(team.getTeamSpawn()); -// } -// } - - public boolean isDeadMan(String playerName) { - if (this.deadMenInventories.containsKey(playerName)) { - return true; - } - return false; - } - - public void restoreDeadmanInventory(Player player) { - if (this.isDeadMan(player.getName())) { - this.playerInvFromInventoryStash(player.getInventory(), this.deadMenInventories.get(player.getName())); - this.deadMenInventories.remove(player.getName()); - } - - } - - public void setRallyPoint(Location location) { - this.rallyPoint = location; - } - - public Location getRallyPoint() { - return this.rallyPoint; - } - - public void unload() { - War.war.log("Unloading zone " + this.getName() + "...", Level.INFO); - for (Team team : this.getTeams()) { - for (Player player : team.getPlayers()) { - this.handlePlayerLeave(player, this.getTeleport(), false); - } - team.getPlayers().clear(); - } - if (this.getLobby() != null) { - this.getLobby().getVolume().resetBlocks(); - this.getLobby().getVolume().finalize(); - } - if (this.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONUNLOAD)) { - this.getVolume().resetBlocks(); - } - this.getVolume().finalize(); - } - - public boolean isEnoughPlayers() { - int teamsWithEnough = 0; - for (Team team : teams) { - if (team.getPlayers().size() >= this.getWarzoneConfig().getInt(WarzoneConfig.MINPLAYERS)) { - teamsWithEnough++; - } - } - if (teamsWithEnough >= this.getWarzoneConfig().getInt(WarzoneConfig.MINTEAMS)) { - return true; - } - return false; - } - - public HashMap getLoadoutSelections() { - return loadoutSelections; - } - - public boolean isAuthor(Player player) { - // if no authors, all zonemakers can edit the zone - return authors.size() == 0 || authors.contains(player.getName()); - } - - public void addAuthor(String playerName) { - authors.add(playerName); - } - - public List getAuthors() { - return this.authors; - } - - public String getAuthorsString() { - String authors = ""; - for (String author : this.getAuthors()) { - authors += author + ","; - } - return authors; - } - - public void equipPlayerLoadoutSelection(Player player, Team playerTeam, boolean isFirstRespawn, boolean isToggle) { - LoadoutSelection selection = this.getLoadoutSelections().get(player.getName()); - if (selection != null && !this.isRespawning(player)) { - HashMap> loadouts = playerTeam.getInventories().resolveLoadouts(); - List sortedNames = LoadoutYmlMapper.sortNames(loadouts); - - int currentIndex = selection.getSelectedIndex(); - int i = 0; - Iterator it = sortedNames.iterator(); - while (it.hasNext()) { - String name = (String)it.next(); - if (i == currentIndex) { - this.resetInventory(playerTeam, player, loadouts.get(name)); - if (isFirstRespawn && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1) { - War.war.msg(player, "Equipped " + name + " loadout (sneak to switch)."); - } else if (isToggle) { - War.war.msg(player, "Equipped " + name + " loadout."); - } - } - i++; - } - } - } - - public WarzoneConfigBag getWarzoneConfig() { - return this.warzoneConfig; - } - - public TeamConfigBag getTeamDefaultConfig() { - return this.teamDefaultConfig; - } - - public InventoryBag getDefaultInventories() { - return this.defaultInventories ; - } - - public List getBombs() { - return bombs; - } - - public List getCakes() { - return cakes; - } -} diff --git a/war/src/main/java/com/tommytony/war/ZoneLobby.java b/war/src/main/java/com/tommytony/war/ZoneLobby.java deleted file mode 100644 index d69e449..0000000 --- a/war/src/main/java/com/tommytony/war/ZoneLobby.java +++ /dev/null @@ -1,699 +0,0 @@ -package com.tommytony.war; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.utils.SignHelper; -import com.tommytony.war.volumes.BlockInfo; -import com.tommytony.war.volumes.Volume; -import com.tommytony.war.volumes.ZoneVolume; - -/** - * - * @author tommytony - * - */ -public class ZoneLobby { - private final Warzone warzone; - private BlockFace wall; - private Volume volume; - BlockInfo lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor - - BlockInfo warHubLinkGate = null; - - Map teamGateBlocks = new HashMap(); - BlockInfo autoAssignGate = null; - - BlockInfo zoneTeleportBlock = null; - - private final int lobbyHeight = 3; - private int lobbyHalfSide; - private final int lobbyDepth = 10; - - /** - * Use this constructor with /setzonelobby - * - * @param war - * @param warzone - * @param wall - * On which wall of the warzone will the lobby be stuck to at mid-weight - */ - public ZoneLobby(Warzone warzone, BlockFace wall) { - this.warzone = warzone; - int lobbyWidth = warzone.getTeams().size() * 4 + 5; - this.lobbyHalfSide = lobbyWidth / 2; - if (this.lobbyHalfSide < 7) { - this.lobbyHalfSide = 7; - } - this.setWall(wall); - } - - /** - * Use this constructor with /setzonelobby . Makes sure the lobby is not sticking inside the zone. - * - * @param war - * @param warzone - * @param wall - * On which wall of the warzone will the lobby be stuck to at mid-weight - */ - public ZoneLobby(Warzone warzone, Location playerLocation) { - this.warzone = warzone; - int lobbyWidth = warzone.getTeams().size() * 4 + 5; - this.lobbyHalfSide = lobbyWidth / 2; - if (this.lobbyHalfSide < 7) { - this.lobbyHalfSide = 7; - } - this.setLocation(playerLocation); - } - - /** - * Convenience ctor when loading form disk. This figures out the middle wall block of the lobby from the volume instead of the other way around. - */ - public ZoneLobby(Warzone warzone, BlockFace wall, Volume volume) { - this.warzone = warzone; - int lobbyWidth = warzone.getTeams().size() * 4 + 5; - this.lobbyHalfSide = lobbyWidth / 2; - if (this.lobbyHalfSide < 7) { - this.lobbyHalfSide = 7; - } - this.wall = wall; - this.setVolume(volume); - - // we're setting the zoneVolume directly, so we need to figure out the lobbyMiddleWallBlock on our own - if (wall == BlockFace.NORTH) { - this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(BlockFace.EAST, this.lobbyHalfSide)); - } else if (wall == BlockFace.EAST) { - this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(BlockFace.SOUTH, this.lobbyHalfSide)); - } else if (wall == BlockFace.SOUTH) { - this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(BlockFace.WEST, this.lobbyHalfSide)); - } else if (wall == BlockFace.WEST) { - this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(BlockFace.NORTH, this.lobbyHalfSide)); - } - } - - public static ZoneLobby getLobbyByLocation(Location location) { - for (Warzone warzone : War.war.getWarzones()) { - if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null && warzone.getLobby().getVolume().contains(location)) { - return warzone.getLobby(); - } - } - return null; - } - - public static ZoneLobby getLobbyByLocation(Player player) { - return ZoneLobby.getLobbyByLocation(player.getLocation()); - } - - /** - * Changes the lobby's position. Orientation is determined from the player location. Creates volume or resets. Saves new lobby blocks. - * - * @param playerLocation - */ - public void setLocation(Location playerLocation) { - World lobbyWorld = playerLocation.getWorld(); - this.createVolumeOrReset(lobbyWorld); - - // Lobby orientation - int yaw = 0; - if (playerLocation.getYaw() >= 0) { - yaw = (int) (playerLocation.getYaw() % 360); - } else { - yaw = (int) (360 + (playerLocation.getYaw() % 360)); - } - BlockFace facing = null; - BlockFace opposite = null; - if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) { - facing = BlockFace.WEST; - opposite = BlockFace.EAST; - } else if (yaw >= 45 && yaw < 135) { - facing = BlockFace.NORTH; - opposite = BlockFace.SOUTH; - } else if (yaw >= 135 && yaw < 225) { - facing = BlockFace.EAST; - opposite = BlockFace.WEST; - } else if (yaw >= 225 && yaw < 315) { - facing = BlockFace.SOUTH; - opposite = BlockFace.NORTH; - } - - this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall - - this.calculateLobbyWidth(); - this.lobbyMiddleWallBlock = new BlockInfo(lobbyWorld.getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getRelative(facing, 6)); - - Block corner1 = null; - Block corner2 = null; - int x = this.lobbyMiddleWallBlock.getX(); - int y = this.lobbyMiddleWallBlock.getY(); - int z = this.lobbyMiddleWallBlock.getZ(); - - if (this.wall == BlockFace.NORTH) { - corner1 = lobbyWorld.getBlockAt(x, y - 1, z + this.lobbyHalfSide); - corner2 = lobbyWorld.getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, z - this.lobbyHalfSide); - } else if (this.wall == BlockFace.EAST) { - corner1 = lobbyWorld.getBlockAt(x - this.lobbyHalfSide, y - 1, z); - corner2 = lobbyWorld.getBlockAt(x + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth); - } else if (this.wall == BlockFace.SOUTH) { - corner1 = lobbyWorld.getBlockAt(x, y - 1, z - this.lobbyHalfSide); - corner2 = lobbyWorld.getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, z + this.lobbyHalfSide); - } else if (this.wall == BlockFace.WEST) { - corner1 = lobbyWorld.getBlockAt(x + this.lobbyHalfSide, y - 1, z); - corner2 = lobbyWorld.getBlockAt(x - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth); - } - - this.saveLobbyBlocks(corner1, corner2); - } - - /** - * Classic way of creating a lobby. Lobby position goes to middle of zone wall. Creates volume or resets. Saves new lobby blocks. - * - * @param newWall - */ - public void setWall(BlockFace newWall) { - this.createVolumeOrReset(this.warzone.getWorld()); // when attached to the warzone, lobby is in same world - this.wall = newWall; - - ZoneVolume zoneVolume = this.warzone.getVolume(); - this.calculateLobbyWidth(); - - Block corner1 = null; - Block corner2 = null; - - if (this.wall == BlockFace.NORTH) { - int wallStart = zoneVolume.getMinZ(); - int wallEnd = zoneVolume.getMaxZ(); - int x = zoneVolume.getMinX(); - int wallLength = wallEnd - wallStart + 1; - int wallCenterPos = wallStart + wallLength / 2; - int y = zoneVolume.getCenterY(); - this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos)); - corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos + this.lobbyHalfSide); - corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos - this.lobbyHalfSide); - } else if (this.wall == BlockFace.EAST) { - int wallStart = zoneVolume.getMinX(); - int wallEnd = zoneVolume.getMaxX(); - int z = zoneVolume.getMinZ(); - int wallLength = wallEnd - wallStart + 1; - int wallCenterPos = wallStart + wallLength / 2; - int y = zoneVolume.getCenterY(); - this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z)); - corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y - 1, z); - corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth); - } else if (this.wall == BlockFace.SOUTH) { - int wallStart = zoneVolume.getMinZ(); - int wallEnd = zoneVolume.getMaxZ(); - int x = zoneVolume.getMaxX(); - int wallLength = wallEnd - wallStart + 1; - int wallCenterPos = wallStart + wallLength / 2; - int y = zoneVolume.getCenterY(); - this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos)); - corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos - this.lobbyHalfSide); - corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos + this.lobbyHalfSide); - } else if (this.wall == BlockFace.WEST) { - int wallStart = zoneVolume.getMinX(); - int wallEnd = zoneVolume.getMaxX(); - int z = zoneVolume.getMaxZ(); - int wallLength = wallEnd - wallStart + 1; - int wallCenterPos = wallStart + wallLength / 2; - int y = zoneVolume.getCenterY(); - this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z)); - corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y - 1, z); - corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth); - } - - this.saveLobbyBlocks(corner1, corner2); - } - - private void createVolumeOrReset(World lobbyWorld) { - if (this.volume == null) { - // no previous wall - this.volume = new Volume("lobby", lobbyWorld); - } else if (this.volume.isSaved()) { - this.volume.resetBlocks(); - this.volume.setWorld(lobbyWorld); // set world for the case where where are changing lobby location between worlds - } - } - - private void calculateLobbyWidth() { - int noOfTeams = this.warzone.getTeams().size(); - if (this.warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) { - noOfTeams = 1; - } - int lobbyWidth = noOfTeams * 4 + 5; - this.lobbyHalfSide = lobbyWidth / 2; - if (this.lobbyHalfSide < 7) { - this.lobbyHalfSide = 7; - } - } - - private void saveLobbyBlocks(Block corner1, Block corner2) { - if (corner1 != null && corner2 != null) { - // save the blocks, wide enough for three team gates, 3+1 high and 10 deep, extruding out from the zone wall. - this.volume.setCornerOne(corner1); - this.volume.setCornerTwo(corner2); - this.volume.saveBlocks(); - } - } - - public void initialize() { - // maybe the number of teams change, now reset the gate positions - if (this.lobbyMiddleWallBlock != null && this.volume != null /* && volume.isSaved() */) { - this.setGatePositions(BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock)); - // flatten the area (set all but floor to air, then replace any floor air blocks with glass) - this.volume.clearBlocksThatDontFloat(); - this.volume.setToMaterial(Material.AIR); - this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful - - // add war hub link gate - if (War.war.getWarHub() != null) { - Block linkGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.warHubLinkGate); - this.placeGate(linkGateBlock, Material.OBSIDIAN); - // add warhub sign - String[] lines = new String[4]; - lines[0] = ""; - lines[1] = "To War hub"; - lines[2] = ""; - lines[3] = ""; - this.resetGateSign(linkGateBlock, lines, false); - } - - // add team gates or single auto assign gate - this.placeAutoAssignGate(); - for (String teamName : this.teamGateBlocks.keySet()) { - BlockInfo gateInfo = this.teamGateBlocks.get(teamName); - this.placeGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), TeamKind.teamKindFromString(teamName)); - } - for (Team t : this.warzone.getTeams()) { - this.resetTeamGateSign(t); - } - - // set zone tp - this.zoneTeleportBlock = new BlockInfo(BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 6)); - int yaw = 0; - if (this.wall == BlockFace.WEST) { - yaw = 180; - } else if (this.wall == BlockFace.SOUTH) { - yaw = 90; - } else if (this.wall == BlockFace.EAST) { - yaw = 0; - } else if (this.wall == BlockFace.NORTH) { - yaw = 270; - } - this.warzone.setTeleport(new Location(this.volume.getWorld(), this.zoneTeleportBlock.getX(), this.zoneTeleportBlock.getY(), this.zoneTeleportBlock.getZ(), yaw, 0)); - - // set zone sign - Block zoneSignBlock = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 4); - byte data = 0; - if (this.wall == BlockFace.NORTH) { - data = (byte) 4; - } else if (this.wall == BlockFace.EAST) { - data = (byte) 8; - } else if (this.wall == BlockFace.SOUTH) { - data = (byte) 12; - } else if (this.wall == BlockFace.WEST) { - data = (byte) 0; - } - String[] lines = new String[4]; - lines[0] = "Warzone"; - lines[1] = this.warzone.getName(); - if (this.autoAssignGate != null) { - lines[2] = "Enter the auto-"; - lines[3] = "assign gate."; - } else { - lines[2] = ""; - lines[3] = "Pick your team."; - } - SignHelper.setToSign(War.war, zoneSignBlock, data, lines); - - // lets get some light in here - if (this.wall == BlockFace.NORTH || this.wall == BlockFace.SOUTH) { - BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(BlockFace.WEST, this.lobbyHalfSide - 1).getRelative(this.wall, 9).setType(Material.GLOWSTONE); - BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST, this.lobbyHalfSide - 1).getRelative(this.wall, 9).setType(Material.GLOWSTONE); - } else { - BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(BlockFace.NORTH, this.lobbyHalfSide - 1).getRelative(this.wall, 9).setType(Material.GLOWSTONE); - BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(BlockFace.SOUTH, this.lobbyHalfSide - 1).getRelative(this.wall, 9).setType(Material.GLOWSTONE); - } - } else { - War.war.log("Failed to initalize zone lobby for zone " + this.warzone.getName(), java.util.logging.Level.WARNING); - } - } - - private void setGatePositions(Block lobbyMiddleWallBlock) { - BlockFace leftSide = null; // look at the zone - BlockFace rightSide = null; - if (this.wall == BlockFace.NORTH) { - leftSide = BlockFace.EAST; - rightSide = BlockFace.WEST; - } else if (this.wall == BlockFace.EAST) { - leftSide = BlockFace.SOUTH; - rightSide = BlockFace.NORTH; - } else if (this.wall == BlockFace.SOUTH) { - leftSide = BlockFace.WEST; - rightSide = BlockFace.EAST; - } else if (this.wall == BlockFace.WEST) { - leftSide = BlockFace.NORTH; - rightSide = BlockFace.SOUTH; - } - this.teamGateBlocks.clear(); - if (this.warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) { - this.autoAssignGate = new BlockInfo(lobbyMiddleWallBlock); - } else { - this.autoAssignGate = null; - for (int doorIndex = 0; doorIndex < this.warzone.getTeams().size(); doorIndex++) { - // 0 at center, 1 to the left, 2 to the right, 3 to the left, etc - Team team = this.warzone.getTeams().get(doorIndex); - if (this.warzone.getTeams().size() % 2 == 0) { - // even number of teams - if (doorIndex % 2 == 0) { - this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2 + 2))); - } else { - this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2))); - } - - } else { - if (doorIndex == 0) { - this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock)); - } else if (doorIndex % 2 == 0) { - this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2))); - } else { - this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2 + 2))); - } - } - } - } - this.warHubLinkGate = new BlockInfo(lobbyMiddleWallBlock.getRelative(this.wall, 9)); - } - - private void placeGate(Block block, TeamKind teamKind) { - if (block != null) { - BlockFace leftSide = null; // look at the zone - BlockFace rightSide = null; - if (this.wall == BlockFace.NORTH) { - leftSide = BlockFace.EAST; - rightSide = BlockFace.WEST; - } else if (this.wall == BlockFace.EAST) { - leftSide = BlockFace.SOUTH; - rightSide = BlockFace.NORTH; - } else if (this.wall == BlockFace.SOUTH) { - leftSide = BlockFace.WEST; - rightSide = BlockFace.EAST; - } else if (this.wall == BlockFace.WEST) { - leftSide = BlockFace.NORTH; - rightSide = BlockFace.SOUTH; - } - block.getRelative(BlockFace.DOWN).setType(Material.GLOWSTONE); - this.setBlock(block.getRelative(leftSide), teamKind); - this.setBlock(block.getRelative(rightSide).getRelative(BlockFace.UP), teamKind); - this.setBlock(block.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), teamKind); - this.setBlock(block.getRelative(rightSide), teamKind); - this.setBlock(block.getRelative(leftSide).getRelative(BlockFace.UP), teamKind); - this.setBlock(block.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), teamKind); - this.setBlock(block.getRelative(BlockFace.UP).getRelative(BlockFace.UP), teamKind); - } - } - - private void placeGate(Block block, Material material) { - if (block != null) { - BlockFace leftSide = null; // look at the zone - BlockFace rightSide = null; - if (this.wall == BlockFace.NORTH) { - leftSide = BlockFace.EAST; - rightSide = BlockFace.WEST; - } else if (this.wall == BlockFace.EAST) { - leftSide = BlockFace.SOUTH; - rightSide = BlockFace.NORTH; - } else if (this.wall == BlockFace.SOUTH) { - leftSide = BlockFace.WEST; - rightSide = BlockFace.EAST; - } else if (this.wall == BlockFace.WEST) { - leftSide = BlockFace.NORTH; - rightSide = BlockFace.SOUTH; - } - block.getRelative(BlockFace.DOWN).setType(Material.GLOWSTONE); - this.setBlock(block.getRelative(leftSide), material); - this.setBlock(block.getRelative(rightSide).getRelative(BlockFace.UP), material); - this.setBlock(block.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), material); - this.setBlock(block.getRelative(rightSide), material); - this.setBlock(block.getRelative(leftSide).getRelative(BlockFace.UP), material); - this.setBlock(block.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), material); - this.setBlock(block.getRelative(BlockFace.UP).getRelative(BlockFace.UP), material); - } - } - - private void setBlock(Block block, TeamKind kind) { - block.setType(kind.getMaterial()); - block.setData(kind.getData()); - } - - private void setBlock(Block block, Material material) { - block.setType(material); - } - - private void placeAutoAssignGate() { - if (this.autoAssignGate != null) { - BlockFace leftSide = null; // look at the zone - BlockFace rightSide = null; - if (this.wall == BlockFace.NORTH) { - leftSide = BlockFace.EAST; - rightSide = BlockFace.WEST; - } else if (this.wall == BlockFace.EAST) { - leftSide = BlockFace.SOUTH; - rightSide = BlockFace.NORTH; - } else if (this.wall == BlockFace.SOUTH) { - leftSide = BlockFace.WEST; - rightSide = BlockFace.EAST; - } else if (this.wall == BlockFace.WEST) { - leftSide = BlockFace.NORTH; - rightSide = BlockFace.SOUTH; - } - List teams = this.warzone.getTeams(); - - Block autoAssignGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate); - this.setBlock(autoAssignGateBlock.getRelative(BlockFace.DOWN), (Material.GLOWSTONE)); - int size = teams.size(); - if (size > 0) { - TeamKind[] doorBlockKinds = new TeamKind[7]; - for (int i = 0; i < 7; i++) { - doorBlockKinds[i] = teams.get(i % size).getKind(); - } - this.setBlock(autoAssignGateBlock.getRelative(leftSide), doorBlockKinds[0]); - this.setBlock(autoAssignGateBlock.getRelative(leftSide).getRelative(BlockFace.UP), doorBlockKinds[1]); - this.setBlock(autoAssignGateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), doorBlockKinds[2]); - this.setBlock(autoAssignGateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP), doorBlockKinds[3]); - this.setBlock(autoAssignGateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), doorBlockKinds[4]); - this.setBlock(autoAssignGateBlock.getRelative(rightSide).getRelative(BlockFace.UP), doorBlockKinds[5]); - this.setBlock(autoAssignGateBlock.getRelative(rightSide), doorBlockKinds[6]); - } - } - } - - public boolean isInTeamGate(Team team, Location location) { - BlockInfo info = this.teamGateBlocks.get(team.getName()); - if (info != null) { - if (location.getBlockX() == info.getX() && location.getBlockY() == info.getY() && location.getBlockZ() == info.getZ()) { - return true; - } - } - return false; - } - - public boolean isAutoAssignGate(Location location) { - if (this.autoAssignGate != null && (location.getBlockX() == this.autoAssignGate.getX() && location.getBlockY() == this.autoAssignGate.getY() && location.getBlockZ() == this.autoAssignGate.getZ())) { - return true; - } - return false; - } - - public Volume getVolume() { - return this.volume; - } - - public void setVolume(Volume volume) { - this.volume = volume; - } - - public BlockFace getWall() { - return this.wall; - } - - public boolean isInWarHubLinkGate(Location location) { - if (this.warHubLinkGate != null && location.getBlockX() == this.warHubLinkGate.getX() && location.getBlockY() == this.warHubLinkGate.getY() && location.getBlockZ() == this.warHubLinkGate.getZ()) { - return true; - } - return false; - } - - public boolean blockIsAGateBlock(Block block, BlockFace blockWall) { - if (blockWall == this.wall) { - for (String teamName : this.teamGateBlocks.keySet()) { - BlockInfo gateInfo = this.teamGateBlocks.get(teamName); - if (this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), block)) { - return true; - } - } - if (this.autoAssignGate != null && this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate), block)) { - // auto assign - return true; - } - } - return false; - } - - private boolean isPartOfGate(Block gateBlock, Block block) { - if (gateBlock != null) { - BlockFace leftSide = null; // look at the zone - BlockFace rightSide = null; - if (this.wall == BlockFace.NORTH) { - leftSide = BlockFace.EAST; - rightSide = BlockFace.WEST; - } else if (this.wall == BlockFace.EAST) { - leftSide = BlockFace.SOUTH; - rightSide = BlockFace.NORTH; - } else if (this.wall == BlockFace.SOUTH) { - leftSide = BlockFace.WEST; - rightSide = BlockFace.EAST; - } else if (this.wall == BlockFace.WEST) { - leftSide = BlockFace.NORTH; - rightSide = BlockFace.SOUTH; - } - return (block.getX() == gateBlock.getX() && block.getY() == gateBlock.getY() && block.getZ() == gateBlock.getZ()) || (block.getX() == gateBlock.getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(leftSide).getX() && block.getY() == gateBlock.getRelative(leftSide).getY() && block.getZ() == gateBlock.getRelative(leftSide).getZ()) || (block.getX() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(rightSide).getX() && block.getY() == gateBlock.getRelative(rightSide).getY() && block.getZ() == gateBlock.getRelative(rightSide).getZ()) || (block.getX() == gateBlock.getX() && block.getY() == gateBlock.getY() - 1 && block.getZ() == gateBlock.getZ()); - } - return false; - } - - public Warzone getZone() { - return this.warzone; - } - - public void resetTeamGateSign(Team team) { - BlockInfo info = this.teamGateBlocks.get(team.getName()); - if (info != null) { - this.resetTeamGateSign(team, BlockInfo.getBlock(this.volume.getWorld(), info)); - } - } - - private void resetTeamGateSign(Team team, Block gate) { - if (gate != null) { - String[] lines = new String[4]; - lines[0] = "Team " + team.getName(); - lines[1] = team.getPlayers().size() + "/" + team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE) + " players"; - lines[2] = team.getPoints() + "/" + team.getTeamConfig().resolveInt(TeamConfig.MAXSCORE) + " pts"; - if (team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) == -1) { - lines[3] = "unlimited lives"; - } else { - lines[3] = team.getRemainingLifes() + "/" + team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) + " lives left"; - } - this.resetGateSign(gate, lines, true); - } - } - - private void resetGateSign(Block gate, String[] lines, boolean awayFromWall) { - Block block = null; - BlockFace direction = null; - if (awayFromWall) { - direction = this.wall; - } else if (this.wall == BlockFace.NORTH) { - direction = BlockFace.SOUTH; - } else if (this.wall == BlockFace.EAST) { - direction = BlockFace.WEST; - } else if (this.wall == BlockFace.SOUTH) { - direction = BlockFace.NORTH; - } else if (this.wall == BlockFace.WEST) { - direction = BlockFace.EAST; - } - byte data = 0; - if (this.wall == BlockFace.NORTH) { - block = gate.getRelative(direction).getRelative(BlockFace.EAST); - if (awayFromWall) { - data = (byte) 4; - } else { - data = (byte) 12; - } - } else if (this.wall == BlockFace.EAST) { - block = gate.getRelative(direction).getRelative(BlockFace.SOUTH); - if (awayFromWall) { - data = (byte) 8; - } else { - data = (byte) 0; - } - } else if (this.wall == BlockFace.SOUTH) { - block = gate.getRelative(direction).getRelative(BlockFace.WEST); - if (awayFromWall) { - data = (byte) 12; - } else { - data = (byte) 4; - } - } else if (this.wall == BlockFace.WEST) { - block = gate.getRelative(direction).getRelative(BlockFace.NORTH); - if (awayFromWall) { - data = (byte) 0; - } else { - data = (byte) 8; - } - } - - SignHelper.setToSign(War.war, block, data, lines); - } - - public boolean isLeavingZone(Location location) { - BlockFace inside = null; - BlockFace left = null; - BlockFace right = null; - if (this.wall == BlockFace.NORTH) { - inside = BlockFace.SOUTH; - left = BlockFace.WEST; - right = BlockFace.EAST; - } else if (this.wall == BlockFace.EAST) { - inside = BlockFace.WEST; - left = BlockFace.NORTH; - right = BlockFace.SOUTH; - } else if (this.wall == BlockFace.SOUTH) { - inside = BlockFace.NORTH; - left = BlockFace.EAST; - right = BlockFace.WEST; - } else if (this.wall == BlockFace.WEST) { - inside = BlockFace.EAST; - left = BlockFace.SOUTH; - right = BlockFace.NORTH; - } - if (this.autoAssignGate != null) { - if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate), inside, left, right)) { - return true; - } - } - for (String teamName : this.teamGateBlocks.keySet()) { - - BlockInfo info = this.teamGateBlocks.get(teamName); - if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), info), inside, left, right)) { - return true; - } - } - return false; - } - - private boolean leaving(Location location, Block gate, BlockFace inside, BlockFace left, BlockFace right) { - // 3x4x1 deep - Volume gateExitVolume = new Volume("tempGateExit", location.getWorld()); - Block out = gate.getRelative(inside); - gateExitVolume.setCornerOne(out.getRelative(left).getRelative(BlockFace.DOWN)); - gateExitVolume.setCornerTwo(gate.getRelative(right, 1).getRelative(BlockFace.UP, 2)); - - if (gateExitVolume.contains(location)) { - return true; - } - - return false; - } -} diff --git a/war/src/main/java/com/tommytony/war/ZoneSetter.java b/war/src/main/java/com/tommytony/war/ZoneSetter.java deleted file mode 100644 index f0bfd87..0000000 --- a/war/src/main/java/com/tommytony/war/ZoneSetter.java +++ /dev/null @@ -1,262 +0,0 @@ -package com.tommytony.war; - -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.config.WarConfig; -import com.tommytony.war.mappers.WarYmlMapper; -import com.tommytony.war.mappers.WarzoneYmlMapper; -import com.tommytony.war.volumes.NotNorthwestException; -import com.tommytony.war.volumes.NotSoutheastException; -import com.tommytony.war.volumes.TooBigException; -import com.tommytony.war.volumes.TooSmallException; - -public class ZoneSetter { - - private final Player player; - private final String zoneName; - - public ZoneSetter(Player player, String zoneName) { - this.player = player; - this.zoneName = zoneName; - } - - public void placeNorthwest() { - Warzone warzone = War.war.findWarzone(this.zoneName); - Block northwestBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation()); - StringBuilder msgString = new StringBuilder(); - try { - if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) { - // max warzones reached - War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20."); - return; - } else if (warzone == null) { - // create the warzone - warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName); - warzone.addAuthor(player.getName()); - War.war.getIncompleteZones().add(warzone); - warzone.getVolume().setNorthwest(northwestBlock); - War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". "); - } else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) { - return; - } else { - // change existing warzone - this.resetWarzone(warzone, msgString); - warzone.getVolume().setNorthwest(northwestBlock); - msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". "); - } - this.saveIfReady(warzone, msgString); - } catch (NotNorthwestException e) { - War.war.badMsg(this.player, "The block you selected is not to the northwest of the existing southeasternmost block."); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); // was reset before changing - } - } catch (TooSmallException e) { - this.handleTooSmall(); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); - } - } catch (TooBigException e) { - this.handleTooBig(); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); - } - } - } - - public void placeSoutheast() { - Warzone warzone = War.war.findWarzone(this.zoneName); - Block southeastBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation()); - StringBuilder msgString = new StringBuilder(); - try { - if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) { - // max warzones reached - War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20."); - return; - } else if (warzone == null) { - // create the warzone - warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName); - warzone.addAuthor(player.getName()); - War.war.getIncompleteZones().add(warzone); - warzone.getVolume().setSoutheast(southeastBlock); - War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". "); - } else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) { - return; - } else { - // change existing warzone - this.resetWarzone(warzone, msgString); - warzone.getVolume().setSoutheast(southeastBlock); - msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". "); - } - this.saveIfReady(warzone, msgString); - } catch (NotSoutheastException e) { - War.war.badMsg(this.player, "The block you selected is not to the southeast of the existing northwestnmost block."); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); // was reset before changing - } - } catch (TooSmallException e) { - this.handleTooSmall(); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); - } - } catch (TooBigException e) { - this.handleTooBig(); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); - } - } - } - - public void placeCorner1() { - Block corner1Block = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation()); - this.placeCorner1(corner1Block); - } - - public void placeCorner1(Block corner1Block) { - Warzone warzone = War.war.findWarzone(this.zoneName); - StringBuilder msgString = new StringBuilder(); - try { - if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) { - // max warzones reached - War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20."); - return; - } else if (warzone == null) { - // create the warzone - warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName); - warzone.addAuthor(player.getName()); - War.war.getIncompleteZones().add(warzone); - warzone.getVolume().setZoneCornerOne(corner1Block); - War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". "); - } else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) { - return; - } else { - // change existing warzone - this.resetWarzone(warzone, msgString); - warzone.getVolume().setZoneCornerOne(corner1Block); - msgString.append("Warzone " + warzone.getName() + " modified. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". "); - } - this.saveIfReady(warzone, msgString); - } catch (TooSmallException e) { - this.handleTooSmall(); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); - } - } catch (TooBigException e) { - this.handleTooBig(); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); - } - } - } - - public void placeCorner2() { - Block corner2Block = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation()); - this.placeCorner2(corner2Block); - } - - public void placeCorner2(Block corner2Block) { - Warzone warzone = War.war.findWarzone(this.zoneName); - StringBuilder msgString = new StringBuilder(); - try { - if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) { - // max warzones reached - War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20."); - return; - } else if (warzone == null) { - // create the warzone - warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName); - warzone.addAuthor(player.getName()); - War.war.getIncompleteZones().add(warzone); - warzone.getVolume().setZoneCornerTwo(corner2Block); - War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". "); - } else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) { - return; - } else { - // change existing warzone - this.resetWarzone(warzone, msgString); - warzone.getVolume().setZoneCornerTwo(corner2Block); - msgString.append("Warzone " + warzone.getName() + " modified. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". "); - } - this.saveIfReady(warzone, msgString); - } catch (TooSmallException e) { - this.handleTooSmall(); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); - } - } catch (TooBigException e) { - this.handleTooBig(); - if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); - } - } - } - - private boolean isPlayerAuthorOfZoneOrAdmin(Warzone warzone) { - boolean isAuthor = warzone.isAuthor(player); - boolean isAdmin = !War.war.isWarAdmin(player); - if (!isAuthor && !isAdmin) { - War.war.badMsg(player, "You can't do this because you are not an author of the " + warzone.getName() + " warzone." ); - } - return isAuthor || isAdmin; - } - - private void resetWarzone(Warzone warzone, StringBuilder msgString) { - if (warzone.getVolume().isSaved()) { - War.war.msg(this.player, "Resetting " + warzone.getName() + " blocks."); - if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) { - warzone.getLobby().getVolume().resetBlocks(); - } - int reset = warzone.getVolume().resetBlocks(); - msgString.append(reset + " blocks reset. "); - } - } - - private void handleTooSmall() { - War.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too small. Sides must be at least 10 blocks and all existing structures (spawns, flags, etc) must fit inside."); - } - - private void handleTooBig() { - War.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too big. Sides must be less than 750 blocks."); - } - - private void saveIfReady(Warzone warzone, StringBuilder msgString) { - if (warzone.ready()) { - if (!War.war.getWarzones().contains(warzone)) { - War.war.addWarzone(warzone); - } - if (War.war.getIncompleteZones().contains(warzone)) { - War.war.getIncompleteZones().remove(warzone); - } - WarYmlMapper.save(); - msgString.append("Saving new warzone blocks..."); - War.war.msg(this.player, msgString.toString()); - warzone.saveState(false); // we just changed the volume, cant reset walls - - if (warzone.getLobby() == null) { - // Set default lobby on south side - ZoneLobby lobby = new ZoneLobby(warzone, BlockFace.SOUTH); - warzone.setLobby(lobby); - if (War.war.getWarHub() != null) { // warhub has to change - War.war.getWarHub().getVolume().resetBlocks(); - War.war.getWarHub().initialize(); - } - War.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby to change its position."); - } - - warzone.initializeZone(); - WarzoneYmlMapper.save(warzone, true); - War.war.msg(this.player, "Warzone saved."); - } else { - if (warzone.getVolume().getCornerOne() == null) { - msgString.append("Still missing corner 1."); - } else if (warzone.getVolume().getCornerTwo() == null) { - msgString.append("Still missing corner 2."); - } - War.war.msg(this.player, msgString.toString()); - } - } - -} diff --git a/war/src/main/java/com/tommytony/war/ZoneWallGuard.java b/war/src/main/java/com/tommytony/war/ZoneWallGuard.java deleted file mode 100644 index a4e8cfa..0000000 --- a/war/src/main/java/com/tommytony/war/ZoneWallGuard.java +++ /dev/null @@ -1,224 +0,0 @@ -package com.tommytony.war; - -import java.util.ArrayList; -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.entity.Player; - -import com.tommytony.war.volumes.BlockInfo; - -import bukkit.tommytony.war.War; - -/** - * - * @author tommytony - * - */ -public class ZoneWallGuard { - private Player player; - private Warzone warzone; - private Location playerLocation; - private BlockFace wall; - private List glassified = new ArrayList(); - - public ZoneWallGuard(Player player, War war, Warzone warzone, BlockFace wall) { - this.player = player; - this.wall = wall; - this.playerLocation = player.getLocation(); - this.warzone = warzone; - this.activate(); - } - - private void activate() { - List nearestWallBlocks = this.warzone.getNearestWallBlocks(this.playerLocation); - - // add wall guard blocks - for (Block block : nearestWallBlocks) { - this.glassify(block, this.wall); - if (this.wall != BlockFace.UP && this.wall != BlockFace.DOWN) { - this.glassify(block.getRelative(BlockFace.UP), this.wall); - this.glassify(block.getRelative(BlockFace.UP, 2), this.wall); - this.glassify(block.getRelative(BlockFace.DOWN), this.wall); - this.glassify(block.getRelative(BlockFace.DOWN, 2), this.wall); - } - if (this.wall == BlockFace.NORTH && this.warzone.getVolume().isNorthWallBlock(block)) { - this.glassify(block.getRelative(BlockFace.EAST), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.UP), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.EAST, 2), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.EAST, 2).getRelative(BlockFace.UP), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.EAST, 2).getRelative(BlockFace.DOWN), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.UP, 2), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN, 2), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.WEST), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.UP), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.WEST, 2), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.WEST, 2).getRelative(BlockFace.UP), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.WEST, 2).getRelative(BlockFace.DOWN), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.UP, 2), BlockFace.NORTH); - this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN, 2), BlockFace.NORTH); - } else if (this.wall == BlockFace.SOUTH && this.warzone.getVolume().isSouthWallBlock(block)) { - this.glassify(block.getRelative(BlockFace.EAST), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.UP), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.EAST, 2), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.EAST, 2).getRelative(BlockFace.UP), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.EAST, 2).getRelative(BlockFace.DOWN), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.UP, 2), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN, 2), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.WEST), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.UP), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.WEST, 2), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.WEST, 2).getRelative(BlockFace.UP), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.WEST, 2).getRelative(BlockFace.DOWN), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.UP, 2), BlockFace.SOUTH); - this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN, 2), BlockFace.SOUTH); - } else if (this.wall == BlockFace.EAST && this.warzone.getVolume().isEastWallBlock(block)) { - this.glassify(block.getRelative(BlockFace.NORTH), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.NORTH, 2), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.UP), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.DOWN), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP, 2), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN, 2), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.SOUTH), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.SOUTH, 2), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.UP), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.DOWN), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP, 2), BlockFace.EAST); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.EAST); - } else if (this.wall == BlockFace.WEST && this.warzone.getVolume().isWestWallBlock(block)) { - this.glassify(block.getRelative(BlockFace.NORTH), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.NORTH, 2), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.UP), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.DOWN), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP, 2), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN, 2), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.SOUTH), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.SOUTH, 2), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.UP), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.DOWN), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP, 2), BlockFace.WEST); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.WEST); - } else if (this.wall == BlockFace.UP && this.warzone.getVolume().isUpWallBlock(block)) { - this.glassify(block.getRelative(BlockFace.EAST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.EAST, 2), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.WEST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.WEST, 2), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.NORTH), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.NORTH, 2), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.EAST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.WEST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST, 2), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST, 2), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.SOUTH), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.EAST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.SOUTH, 2), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.EAST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.WEST), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP, 2), BlockFace.UP); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.UP); - } else if (this.wall == BlockFace.DOWN && this.warzone.getVolume().isDownWallBlock(block)) { - this.glassify(block.getRelative(BlockFace.EAST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.EAST, 2), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.WEST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.WEST, 2), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.NORTH), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.NORTH, 2), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.EAST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.WEST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST, 2), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST, 2), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.SOUTH), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.EAST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.SOUTH, 2), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.EAST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.WEST), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.DOWN); - this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.DOWN); - } - } - } - - private void glassify(Block block, BlockFace wall) { - // face here means which wall we are working on - - if ((block.getTypeId() == Material.AIR.getId() || block.getTypeId() == Material.WATER.getId()) && (this.warzone.getLobby() == null || (this.warzone.getLobby() != null && !this.warzone.getLobby().blockIsAGateBlock(block, wall)))) { - if (wall == BlockFace.NORTH) { - if (this.warzone.getVolume().isNorthWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); - block.setType(Material.GLASS); - } - } else if (wall == BlockFace.SOUTH) { - if (this.warzone.getVolume().isSouthWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); - block.setType(Material.GLASS); - } - } else if (wall == BlockFace.EAST) { - if (this.warzone.getVolume().isEastWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); - block.setType(Material.GLASS); - } - } else if (wall == BlockFace.WEST) { - if (this.warzone.getVolume().isWestWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); - block.setType(Material.GLASS); - } - } else if (wall == BlockFace.UP) { - if (this.warzone.getVolume().isUpWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); - block.setType(Material.GLASS); - } - } else if (wall == BlockFace.DOWN) { - if (this.warzone.getVolume().isDownWallBlock(block)) { - this.glassified.add(new BlockInfo(block)); - block.setType(Material.GLASS); - } - } - } - } - - public void updatePlayerPosition(Location location) { - if (this.warzone.isNearWall(location)) { - this.playerLocation = location; - this.deactivate(); - this.activate(); - } - } - - public void deactivate() { - for (BlockInfo oldBlock : this.glassified) { - // return to original - Block glassifiedBlock = this.warzone.getWorld().getBlockAt(oldBlock.getX(), oldBlock.getY(), oldBlock.getZ()); - glassifiedBlock.setTypeId(oldBlock.getTypeId()); - glassifiedBlock.setData(oldBlock.getData()); - } - } - - public Player getPlayer() { - return this.player; - } - - public BlockFace getWall() { - return this.wall; - } -} diff --git a/war/src/main/java/com/tommytony/war/jobs/BlockResetJob.java b/war/src/main/java/com/tommytony/war/jobs/BlockResetJob.java deleted file mode 100644 index 867f13b..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/BlockResetJob.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.tommytony.war.jobs; - -import com.tommytony.war.volumes.Volume; - -public class BlockResetJob implements Runnable { - - private final Volume volume; - - public BlockResetJob(Volume volume) { - this.volume = volume; - } - - public void run() { - this.volume.resetBlocks(); - } - -} diff --git a/war/src/main/java/com/tommytony/war/jobs/DeferredBlockResetsJob.java b/war/src/main/java/com/tommytony/war/jobs/DeferredBlockResetsJob.java deleted file mode 100644 index 37b1c6a..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/DeferredBlockResetsJob.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.tommytony.war.jobs; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Chunk; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.ContainerBlock; -import org.bukkit.block.NoteBlock; -import org.bukkit.block.Sign; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Item; -import org.bukkit.inventory.ItemStack; - -import com.tommytony.war.utils.DeferredBlockReset; -import com.tommytony.war.volumes.Volume; - -public class DeferredBlockResetsJob implements Runnable { - - List deferred = new ArrayList(); - private final World world; - - public DeferredBlockResetsJob(World world) { - this.world = world; - - } - - public void add(DeferredBlockReset pleaseResetLater) { - this.deferred.add(pleaseResetLater); - } - - public boolean isEmpty() { - return this.deferred.isEmpty(); - } - - public void run() { - ArrayList doors = new ArrayList(); - - for (DeferredBlockReset reset : this.deferred) { - if (this.world != null && reset != null) { - Block worldBlock = this.world.getBlockAt(reset.getX(), reset.getY(), reset.getZ()); - worldBlock.setType(Material.getMaterial(reset.getBlockType())); - - if (reset.getBlockType() == Material.WALL_SIGN.getId() || reset.getBlockType() == Material.SIGN_POST.getId()) { - BlockState state = worldBlock.getState(); - state.setData(new org.bukkit.material.Sign(reset.getBlockType(), reset.getBlockData())); - if (state instanceof Sign) { - Sign sign = (Sign) state; - if (reset.getLines() != null && sign.getLines() != null) { - if (reset.getLines().length > 0) { - sign.setLine(0, reset.getLines()[0]); - } - if (reset.getLines().length > 1) { - sign.setLine(1, reset.getLines()[1]); - } - if (reset.getLines().length > 2) { - sign.setLine(2, reset.getLines()[2]); - } - if (reset.getLines().length > 3) { - sign.setLine(3, reset.getLines()[3]); - } - sign.update(true); - } - } - } else if (reset.getBlockType() == Material.CHEST.getId() - || reset.getBlockType() == Material.DISPENSER.getId() - || reset.getBlockType() == Material.FURNACE.getId() - || reset.getBlockType() == Material.BURNING_FURNACE.getId()) { - List items = reset.getItems(); - - worldBlock.setType(Material.getMaterial(reset.getBlockType())); - worldBlock.setData(reset.getBlockData()); - BlockState state = worldBlock.getState(); - if (state instanceof ContainerBlock) { - ContainerBlock container = (ContainerBlock) state; - if (items != null) { - int ii = 0; - container.getInventory().clear(); - for (ItemStack item : items) { - if (item != null) { - container.getInventory().setItem(ii, item); - ii++; - } - } - state.update(true); - items.clear(); - } - } else { - // normal reset - worldBlock.setData(reset.getBlockData()); - } - } else if (reset.getBlockType() == Material.NOTE_BLOCK.getId()) { - worldBlock.setType(Material.getMaterial(reset.getBlockType())); - worldBlock.setData(reset.getBlockData()); - BlockState state = worldBlock.getState(); - if (state instanceof NoteBlock && reset.getRawNote() != null) { - NoteBlock noteBlock = (NoteBlock) state; - noteBlock.setRawNote(reset.getRawNote()); - noteBlock.update(true); - } else { - // normal reset - worldBlock.setData(reset.getBlockData()); - } - } else if (reset.getBlockType() == Material.WOODEN_DOOR.getId() || reset.getBlockType() == Material.IRON_DOOR_BLOCK.getId()) { - // Door blocks - doors.add(reset); - } else { - // normal data reset - worldBlock.setData(reset.getBlockData()); - } - } - } - - // Take care of doors last - for (DeferredBlockReset doorBlock : doors) { - Block worldBlock = world.getBlockAt(doorBlock.getX(), doorBlock.getY(), doorBlock.getZ()); - if (worldBlock.getTypeId() != doorBlock.getBlockType() || worldBlock.getData() != doorBlock.getBlockData()) { - // find its friend - for (DeferredBlockReset other : doors) { - if (other.getX() == doorBlock.getX() - && other.getY() == doorBlock.getY() - 1 - && other.getZ() == doorBlock.getZ()) { - // doorBlock is above - Block above = worldBlock; - Block below = world.getBlockAt(other.getX(), other.getY(), other.getZ()); - above.setTypeId(doorBlock.getBlockType()); - above.setData(doorBlock.getBlockData()); - below.setTypeId(other.getBlockType()); - below.setData(other.getBlockData()); - scrubDroppedDoors(below); - break; - } else if (other.getX() == doorBlock.getX() - && other.getY() == doorBlock.getY() + 1 - && other.getZ() == doorBlock.getZ()) { - // doorBlock is below - Block above = world.getBlockAt(other.getX(), other.getY(), other.getZ()); - Block below = worldBlock; - above.setTypeId(doorBlock.getBlockType()); - above.setData(doorBlock.getBlockData()); - below.setTypeId(other.getBlockType()); - below.setData(other.getBlockData()); - scrubDroppedDoors(below); - break; - } - } - } - } - } - - private void scrubDroppedDoors(Block block) { - Chunk chunk = block.getWorld().getChunkAt(block); - Volume scrubVolume = new Volume("scrub", block.getWorld()); - scrubVolume.setCornerOne(block.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST).getRelative(BlockFace.NORTH)); - scrubVolume.setCornerTwo(block.getRelative(BlockFace.UP).getRelative(BlockFace.WEST).getRelative(BlockFace.SOUTH)); - for (Entity entity : chunk.getEntities()) { - if ((entity instanceof Item && (((Item)entity).getItemStack().getTypeId() == Material.IRON_DOOR.getId() - || ((Item)entity).getItemStack().getTypeId() == Material.WOOD_DOOR.getId())) - && scrubVolume.contains(entity.getLocation())) { - entity.remove(); - } - } - } - -} diff --git a/war/src/main/java/com/tommytony/war/jobs/HelmetProtectionTask.java b/war/src/main/java/com/tommytony/war/jobs/HelmetProtectionTask.java deleted file mode 100644 index 3637357..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/HelmetProtectionTask.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.tommytony.war.jobs; - -import java.util.HashMap; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; - -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.Warzone; -import com.tommytony.war.config.WarzoneConfig; - -import bukkit.tommytony.war.War; - -/** - * Sets the helmet again onto the players heads. Also limits the number of blocks being held. - * - * @author Tim Düsterhus - */ -public class HelmetProtectionTask implements Runnable { - - /** - * @see Runnable.run() - */ - public void run() { - if (!War.war.isLoaded()) { - return; - } - for (Warzone zone : War.war.getWarzones()) { - for (Team team : zone.getTeams()) { - for (Player player : team.getPlayers()) { - PlayerInventory playerInv = player.getInventory(); - Material teamBlockMaterial; - if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) { - teamBlockMaterial = team.getKind().getMaterial(); - // 1) Replace missing block head - if (playerInv.getHelmet().getType() != teamBlockMaterial) { - playerInv.setHelmet(this.createBlockHead(team)); - } - // 2) Get rid of extra blocks in inventory: only keep one - HashMap blocks = playerInv.all(teamBlockMaterial); - if (blocks.size() > 1 || (blocks.size() == 1 && blocks.get(blocks.keySet().iterator().next()).getAmount() > 1)) { - int i = 0; - int removed = 0; - for (ItemStack item : playerInv.getContents()) { - // remove only same colored wool - if (item != null && item.getType() == teamBlockMaterial && item.getData().getData() == team.getKind().getData()) { - playerInv.clear(i); - removed++; - } - i++; - } - playerInv.setItem(playerInv.firstEmpty(), this.createBlockHead(team)); - if (removed > 1) { - War.war.badMsg(player, "All that " + team.getName() + " wool must have been heavy!"); - } - } - } else { - if (team.getKind() == TeamKind.GOLD) { - teamBlockMaterial = Material.GOLD_HELMET; - } else if (team.getKind() == TeamKind.DIAMOND) { - teamBlockMaterial = Material.DIAMOND_HELMET; - } else if (team.getKind() == TeamKind.IRON) { - teamBlockMaterial = Material.IRON_HELMET; - } else { - teamBlockMaterial = Material.LEATHER_HELMET; - } - if (playerInv.getHelmet() != null && playerInv.getHelmet().getType() != teamBlockMaterial) { - playerInv.setHelmet(new ItemStack(teamBlockMaterial)); - } - HashMap helmets = playerInv.all(teamBlockMaterial); - if (helmets.size() > 1 || (helmets.size() == 1 && helmets.get(helmets.keySet().iterator().next()).getAmount() > 1)) { - playerInv.remove(teamBlockMaterial); - playerInv.setItem(playerInv.firstEmpty(), new ItemStack(teamBlockMaterial)); - War.war.badMsg(player, "All those helmets must have been heavy!"); - } - } - } - } - } - } - - public ItemStack createBlockHead(Team team) { - return new ItemStack(team.getKind().getMaterial(), 1, (short) 1, new Byte(team.getKind().getData())); - } -} diff --git a/war/src/main/java/com/tommytony/war/jobs/InitZoneJob.java b/war/src/main/java/com/tommytony/war/jobs/InitZoneJob.java deleted file mode 100644 index 0ee725d..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/InitZoneJob.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.tommytony.war.jobs; - -import org.bukkit.entity.Player; - -import com.tommytony.war.Warzone; - -public class InitZoneJob implements Runnable { - - private final Warzone zone; - private final Player respawnExempted; - - public InitZoneJob(Warzone zone) { - this.zone = zone; - this.respawnExempted = null; - } - - public InitZoneJob(Warzone warzone, Player respawnExempted) { - this.zone = warzone; - this.respawnExempted = respawnExempted; - } - - public void run() { - this.zone.initializeZone(this.respawnExempted); - } - -} diff --git a/war/src/main/java/com/tommytony/war/jobs/LoadoutResetJob.java b/war/src/main/java/com/tommytony/war/jobs/LoadoutResetJob.java deleted file mode 100644 index a96c235..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/LoadoutResetJob.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.tommytony.war.jobs; - -import org.bukkit.entity.Player; - -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; - -public class LoadoutResetJob implements Runnable { - - private final Player player; - private final Warzone zone; - private final Team team; - private final boolean isFirstRespawn; - private final boolean isToggle; - - public LoadoutResetJob(Warzone zone, Team team, Player player, boolean isFirstRespawn, boolean isToggle) { - this.zone = zone; - this.team = team; - this.player = player; - this.isFirstRespawn = isFirstRespawn; - this.isToggle = isToggle; - } - - public void run() { - this.zone.equipPlayerLoadoutSelection(player, team, isFirstRespawn, isToggle); - - // Stop fire here, since doing it in the same tick as death doesn't extinguish it - this.player.setFireTicks(0); - } - -} diff --git a/war/src/main/java/com/tommytony/war/jobs/LootDropperTask.java b/war/src/main/java/com/tommytony/war/jobs/LootDropperTask.java deleted file mode 100644 index da0f4f5..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/LootDropperTask.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.tommytony.war.jobs; - -import java.util.List; - -import org.bukkit.Location; -import org.bukkit.inventory.ItemStack; - -public class LootDropperTask implements Runnable { - - private final List drop; - private final Location location; - - public LootDropperTask(Location location, List drop) { - this.location = location; - this.drop = drop; - } - - public void run() { - for (ItemStack item : this.drop) { - if (item != null) { - this.location.getWorld().dropItemNaturally(this.location, item); - } - } - } -} diff --git a/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java b/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java deleted file mode 100644 index e14faf3..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.tommytony.war.jobs; - -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; - -import com.tommytony.war.volumes.BlockInfo; - -public class ResetCursorJob implements Runnable { - - private final Block cornerBlock; - private final BlockInfo[] originalCursorBlocks; - private final boolean isSoutheast; - - public ResetCursorJob(Block cornerBlock, BlockInfo[] originalCursorBlocks, boolean isSoutheast) { - this.cornerBlock = cornerBlock; - this.originalCursorBlocks = originalCursorBlocks; - this.isSoutheast = isSoutheast; - } - - public void run() { - if (this.isSoutheast) { - this.cornerBlock.setType(this.originalCursorBlocks[0].getType()); - this.cornerBlock.setData(this.originalCursorBlocks[0].getData()); - this.cornerBlock.getRelative(BlockFace.WEST).setType(this.originalCursorBlocks[1].getType()); - this.cornerBlock.getRelative(BlockFace.WEST).setData(this.originalCursorBlocks[1].getData()); - this.cornerBlock.getRelative(BlockFace.NORTH).setType(this.originalCursorBlocks[2].getType()); - this.cornerBlock.getRelative(BlockFace.NORTH).setData(this.originalCursorBlocks[2].getData()); - } else { - this.cornerBlock.setType(this.originalCursorBlocks[0].getType()); - this.cornerBlock.setData(this.originalCursorBlocks[0].getData()); - this.cornerBlock.getRelative(BlockFace.EAST).setType(this.originalCursorBlocks[1].getType()); - this.cornerBlock.getRelative(BlockFace.EAST).setData(this.originalCursorBlocks[1].getData()); - this.cornerBlock.getRelative(BlockFace.SOUTH).setType(this.originalCursorBlocks[2].getType()); - this.cornerBlock.getRelative(BlockFace.SOUTH).setData(this.originalCursorBlocks[2].getData()); - } - } -} diff --git a/war/src/main/java/com/tommytony/war/jobs/RespawnPlayerJob.java b/war/src/main/java/com/tommytony/war/jobs/RespawnPlayerJob.java deleted file mode 100644 index a11a05f..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/RespawnPlayerJob.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.tommytony.war.jobs; - -import org.bukkit.entity.Player; - -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; - -public class RespawnPlayerJob implements Runnable { - - private final Team team; - private final Player player; - private final Warzone zone; - - public RespawnPlayerJob(Warzone zone, Team playerTeam, Player player) { - this.zone = zone; - // TODO Auto-generated constructor stub - this.team = playerTeam; - this.player = player; - } - - public void run() { - this.zone.respawnPlayer(this.team, this.player); - } - -} diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreDeadmanInventoryJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreDeadmanInventoryJob.java deleted file mode 100644 index 8dfc3fd..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreDeadmanInventoryJob.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.tommytony.war.jobs; - -import org.bukkit.entity.Player; - -import com.tommytony.war.Warzone; - -public class RestoreDeadmanInventoryJob implements Runnable { - - private final Player player; - private final Warzone zone; - - public RestoreDeadmanInventoryJob(Player player, Warzone zone) { - this.player = player; - this.zone = zone; - } - - public void run() { - this.zone.restoreDeadmanInventory(this.player); - this.player.teleport(this.zone.getTeleport()); - } -} diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java deleted file mode 100644 index c9a3b3f..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.tommytony.war.jobs; - -import java.util.logging.Level; - -import org.bukkit.Location; -import org.bukkit.World; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.WarHub; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.VolumeMapper; -import com.tommytony.war.volumes.Volume; - -public class RestoreWarhubJob implements Runnable { - - private final String hubStr; - - public RestoreWarhubJob(String hubStr) { - this.hubStr = hubStr; - } - - public void run() { - String[] hubStrSplit = this.hubStr.split(","); - - int hubX = Integer.parseInt(hubStrSplit[0]); - int hubY = Integer.parseInt(hubStrSplit[1]); - int hubZ = Integer.parseInt(hubStrSplit[2]); - World world = null; - String worldName; - String hubOrientation = "west"; - if (hubStrSplit.length > 3) { - worldName = hubStrSplit[3]; - world = War.war.getServer().getWorld(worldName); - if (hubStrSplit.length > 4) { - hubOrientation = hubStrSplit[4]; - } - } else { - worldName = "DEFAULT"; - world = War.war.getServer().getWorlds().get(0); // default to first world - } - if (world != null) { - Location hubLocation = new Location(world, hubX, hubY, hubZ); - WarHub hub = new WarHub(hubLocation, hubOrientation); - War.war.setWarHub(hub); - Volume vol = VolumeMapper.loadVolume("warhub", "", world); - hub.setVolume(vol); - hub.getVolume().resetBlocks(); - hub.initialize(); - - // In the previous job started by the mapper, warzones were created, but their lobbies are missing the war hub gate (because it didn't exist yet) - for (Warzone zone : War.war.getWarzones()) { - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - zone.getLobby().initialize(); - } - } - War.war.log("Warhub ready.", Level.INFO); - } else { - War.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING); - } - } -} diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java deleted file mode 100644 index 8a00813..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.tommytony.war.jobs; - -import java.util.logging.Level; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.Warzone; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.mappers.WarYmlMapper; -import com.tommytony.war.mappers.WarzoneTxtMapper; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -public class RestoreWarzonesJob implements Runnable { - - private final String warzonesStr; - private final boolean newWarInstall; - private final boolean convertingToYml; - - public RestoreWarzonesJob(String warzonesStr, boolean newWarInstall, boolean convertingToYml) { - this.warzonesStr = warzonesStr; - this.newWarInstall = newWarInstall; - this.convertingToYml = convertingToYml; - } - - public void run() { - String[] warzoneSplit = this.warzonesStr.split(","); - War.war.getWarzones().clear(); - - for (String warzoneName : warzoneSplit) { - if (warzoneName != null && !warzoneName.equals("")) { - War.war.log("Loading zone " + warzoneName + "...", Level.INFO); - Warzone zone = WarzoneTxtMapper.load(warzoneName, !this.newWarInstall); - if (zone != null) { // could have failed, would've been logged already - War.war.getWarzones().add(zone); - zone.getVolume().loadCorners(); - - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - } - if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) { - zone.getVolume().resetBlocks(); - } - zone.initializeZone(); - } - } - } - - if (War.war.getWarzones().size() > 0) { - War.war.log("Warzones ready.", Level.INFO); - } - - if (convertingToYml) { - // Loading process is over, we can convert (i.e. save in new format) - WarYmlMapper.save(); - War.war.log("Converted war.txt to war.yml.", Level.INFO); - - for (Warzone zone : War.war.getWarzones()) { - WarzoneYmlMapper.save(zone, false); - War.war.log("Converted warzone-" + zone.getName() + ".txt to warzone-" + zone.getName() + ".yml.", Level.INFO); - } - } - } - -} diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreYmlWarhubJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreYmlWarhubJob.java deleted file mode 100644 index 6c274c3..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreYmlWarhubJob.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.tommytony.war.jobs; - -import java.util.logging.Level; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.ConfigurationSection; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.WarHub; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.VolumeMapper; -import com.tommytony.war.volumes.Volume; - -public class RestoreYmlWarhubJob implements Runnable { - - private final ConfigurationSection warhubConfig; - - public RestoreYmlWarhubJob(ConfigurationSection warhubConfig) { - this.warhubConfig = warhubConfig; - } - - public void run() { - int hubX = warhubConfig.getInt("x"); - int hubY = warhubConfig.getInt("y"); - int hubZ = warhubConfig.getInt("z"); - - String worldName = warhubConfig.getString("world"); - String hubOrientation = warhubConfig.getString("orientation"); - - World world = War.war.getServer().getWorld(worldName); - if (world != null) { - Location hubLocation = new Location(world, hubX, hubY, hubZ); - WarHub hub = new WarHub(hubLocation, hubOrientation); - War.war.setWarHub(hub); - Volume vol = VolumeMapper.loadVolume("warhub", "", world); - hub.setVolume(vol); - hub.getVolume().resetBlocks(); - hub.initialize(); - - // In the previous job started by the mapper, warzones were created, but their lobbies are missing the war hub gate (because it didn't exist yet) - for (Warzone zone : War.war.getWarzones()) { - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - zone.getLobby().initialize(); - } - } - War.war.log("Warhub ready.", Level.INFO); - } else { - War.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING); - } - } -} diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreYmlWarzonesJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreYmlWarzonesJob.java deleted file mode 100644 index b9fa026..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreYmlWarzonesJob.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.tommytony.war.jobs; - -import java.util.List; -import java.util.logging.Level; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.Warzone; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.mappers.WarzoneYmlMapper; - -public class RestoreYmlWarzonesJob implements Runnable { - - private final List warzones; - private final boolean newWarInstall; - - public RestoreYmlWarzonesJob(List warzones, boolean newWarInstall) { - this.warzones = warzones; - this.newWarInstall = newWarInstall; - } - - public void run() { - War.war.getWarzones().clear(); - if (this.warzones != null) { - for (String warzoneName : this.warzones) { - if (warzoneName != null && !warzoneName.equals("")) { - War.war.log("Loading zone " + warzoneName + "...", Level.INFO); - Warzone zone = WarzoneYmlMapper.load(warzoneName, !this.newWarInstall); - if (zone != null) { // could have failed, would've been logged already - War.war.getWarzones().add(zone); - - zone.getVolume().loadCorners(); - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - } - if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) { - zone.getVolume().resetBlocks(); - } - zone.initializeZone(); - } - } - } - if (War.war.getWarzones().size() > 0) { - War.war.log("Warzones ready.", Level.INFO); - } - } - } - -} diff --git a/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java b/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java deleted file mode 100644 index 7417ad8..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.tommytony.war.jobs; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.player.SpoutPlayer; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; -import com.tommytony.war.spout.SpoutMessenger; - -public class ScoreCapReachedJob implements Runnable { - - private final Warzone zone; - private final String winnersStr; - - public ScoreCapReachedJob(Warzone zone, String winnersStr) { - this.zone = zone; - this.winnersStr = winnersStr; - } - - public void run() { - for (Team t : this.zone.getTeams()) { - if (War.war.isSpoutServer()) { - for (Player p : t.getPlayers()) { - SpoutPlayer sp = SpoutManager.getPlayer(p); - if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutMessenger.cleanForNotification("Match won! " + ChatColor.WHITE + "Winners:"), - SpoutMessenger.cleanForNotification(SpoutMessenger.addMissingColor(winnersStr, zone)), - Material.CAKE, - (short)0, - 10000); - } - } - } - String winnersStrAndExtra = "Score cap reached. Game is over! Winning team(s): " + this.winnersStr; - winnersStrAndExtra += ". Resetting warzone and your inventory..."; - t.teamcast(winnersStrAndExtra); - boolean isSpoutServer = War.war.isSpoutServer(); - for (Player tp : t.getPlayers()) { - // Send everyone to rally point (or zone lobby if not rally point) - if (this.zone.getRallyPoint() != null) { - tp.teleport(this.zone.getRallyPoint()); - } else { - tp.teleport(this.zone.getTeleport()); - } - tp.setFireTicks(0); - tp.setRemainingAir(300); - if (this.zone.hasPlayerState(tp.getName())) { - this.zone.restorePlayerState(tp); - } - if (this.winnersStr.contains(t.getName())) { - // give reward - for (Integer slot : t.getInventories().resolveReward().keySet()) { - ItemStack item = t.getInventories().resolveReward().get(slot); - if (item != null) { - tp.getInventory().addItem(item); - } - } - } - } - t.resetPoints(); - t.getPlayers().clear(); // empty the team - } - } -} diff --git a/war/src/main/java/com/tommytony/war/jobs/SpoutFadeOutMessageJob.java b/war/src/main/java/com/tommytony/war/jobs/SpoutFadeOutMessageJob.java deleted file mode 100644 index 8970907..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/SpoutFadeOutMessageJob.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.tommytony.war.jobs; - -import bukkit.tommytony.war.War; - -public class SpoutFadeOutMessageJob implements Runnable { - - public SpoutFadeOutMessageJob() { - } - - public void run() { - War.war.getSpoutMessenger().fadeOutOldMessages(); - } - -} diff --git a/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java b/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java deleted file mode 100644 index f004661..0000000 --- a/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.tommytony.war.jobs; - -import com.tommytony.war.mappers.ZoneVolumeMapper; -import com.tommytony.war.volumes.Volume; - -public class ZoneVolumeSaveJob extends Thread { - private final Volume volume; - private final String zoneName; - - public ZoneVolumeSaveJob(Volume volume, String zoneName) { - this.volume = volume; - this.zoneName = zoneName; - } - - @Override - public void run() { - ZoneVolumeMapper.save(this.volume, this.zoneName); - } -} diff --git a/war/src/main/java/com/tommytony/war/mappers/LoadoutTxtMapper.java b/war/src/main/java/com/tommytony/war/mappers/LoadoutTxtMapper.java deleted file mode 100644 index 67b7f1f..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/LoadoutTxtMapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.tommytony.war.mappers; - -import java.util.HashMap; - -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; - -public class LoadoutTxtMapper { - - public static String fromLoadoutToString(HashMap loadout) { - String loadoutString = ""; - for (Integer slot : loadout.keySet()) { - ItemStack item = loadout.get(slot); - if (item != null) { - loadoutString += item.getTypeId() + "," + item.getAmount() + "," + slot + "," + item.getDurability() + "," + item.getData().getData(); - if (item.getEnchantments().keySet().size() > 0) { - String enchantmentsStr = ""; - for (Enchantment enchantment : item.getEnchantments().keySet()) { - enchantmentsStr += enchantment.getId() + ":" + item.getEnchantments().get(enchantment) + "::"; - } - loadoutString += "," + enchantmentsStr; - } - } - loadoutString += ";"; - } - return loadoutString; - } - - public static void fromStringToLoadout(String loadoutString, HashMap destinationLoadout) { - String[] rewardStrSplit = loadoutString.split(";"); - destinationLoadout.clear(); - for (String itemStr : rewardStrSplit) { - if (itemStr != null && !itemStr.equals("")) { - String[] itemStrSplit = itemStr.split(","); - ItemStack item = null; - if (itemStrSplit.length == 3) { - item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); - } else if (itemStrSplit.length == 5) { - short durability = Short.parseShort(itemStrSplit[3]); - item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability, Byte.parseByte(itemStrSplit[4])); - item.setDurability(durability); - } else if (itemStrSplit.length == 6) { - short durability = Short.parseShort(itemStrSplit[3]); - item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability, Byte.parseByte(itemStrSplit[4])); - item.setDurability(durability); - - // enchantments - String[] enchantmentsSplit = itemStrSplit[5].split("::"); - for (String enchantmentStr : enchantmentsSplit) { - if (!enchantmentStr.equals("")) { - String[] enchantmentSplit = enchantmentStr.split(":"); - int enchantId = Integer.parseInt(enchantmentSplit[0]); - int level = Integer.parseInt(enchantmentSplit[1]); - item.addEnchantment(Enchantment.getById(enchantId), level); - } - } - } - destinationLoadout.put(Integer.parseInt(itemStrSplit[2]), item); - } - } - } -} diff --git a/war/src/main/java/com/tommytony/war/mappers/LoadoutYmlMapper.java b/war/src/main/java/com/tommytony/war/mappers/LoadoutYmlMapper.java deleted file mode 100644 index 24df62e..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/LoadoutYmlMapper.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.tommytony.war.mappers; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; - -public class LoadoutYmlMapper { - - public static void fromConfigToLoadouts(ConfigurationSection config, HashMap> loadouts) { - List loadoutNames = config.getStringList("names"); - loadouts.clear(); - for (String name : loadoutNames) { - HashMap newLoadout = new HashMap(); - fromConfigToLoadout(config, newLoadout, name); - loadouts.put(name, newLoadout); - } - } - - public static void fromConfigToLoadout(ConfigurationSection config, HashMap loadout, String loadoutName) { - List slots = config.getIntegerList(loadoutName + ".slots"); - for (Integer slot : slots) { - String prefix = loadoutName + "." + slot + "."; - - int id = config.getInt(prefix + "id"); - byte data = (byte)config.getInt(prefix + "data"); - int amount = config.getInt(prefix + "amount"); - short durability = (short)config.getInt(prefix + "durability"); - - ItemStack stack = new ItemStack(id, amount, durability, data); - stack.setDurability(durability); - - if (config.contains(prefix + "enchantments")) { - List enchantmentStringList = config.getStringList(prefix + "enchantments"); - for (String enchantmentString : enchantmentStringList) { - String[] enchantmentStringSplit = enchantmentString.split(","); - if (enchantmentStringSplit.length == 2) { - int enchantId = Integer.parseInt(enchantmentStringSplit[0]); - int level = Integer.parseInt(enchantmentStringSplit[1]); - stack.addEnchantment(Enchantment.getById(enchantId), level); - } - } - } - - loadout.put(slot, stack); - } - } - - public static void fromLoadoutsToConfig(HashMap> loadouts, ConfigurationSection section) { - List sortedNames = sortNames(loadouts); - - section.set("names", sortedNames); - for (String name : sortedNames) { - fromLoadoutToConfig(name, loadouts.get(name), section); - } - } - - public static List sortNames(HashMap> loadouts) { - List sortedNames = new ArrayList(); - - // default comes first - if (loadouts.containsKey("default")) { - sortedNames.add("default"); - } - - for (String name : loadouts.keySet()) { - if (!name.equals("default")) { - sortedNames.add(name); - } - } - - return sortedNames; - } - - private static List toIntList(Set keySet) { - List list = new ArrayList(); - for (Integer key : keySet) { - list.add(key); - } - return list; - } - - public static void fromLoadoutToConfig(String loadoutName, HashMap loadout, ConfigurationSection section) { - ConfigurationSection loadoutSection = section.createSection(loadoutName); - loadoutSection.set("slots", toIntList(loadout.keySet())); - for (Integer slot : loadout.keySet()) { - ConfigurationSection slotSection = loadoutSection.createSection(slot.toString()); - ItemStack stack = loadout.get(slot); - - slotSection.set("id", stack.getTypeId()); - slotSection.set("data", stack.getData().getData()); - slotSection.set("amount", stack.getAmount()); - slotSection.set("durability", stack.getDurability()); - - if (stack.getEnchantments().keySet().size() > 0) { - List enchantmentStringList = new ArrayList(); - for (Enchantment enchantment : stack.getEnchantments().keySet()) { - int level = stack.getEnchantments().get(enchantment); - enchantmentStringList.add(enchantment.getId() + "," + level); - } - slotSection.set("enchantments", enchantmentStringList); - } - } - } -} diff --git a/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java deleted file mode 100644 index f43c6d6..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java +++ /dev/null @@ -1,433 +0,0 @@ -package com.tommytony.war.mappers; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Chest; -import org.bukkit.block.Dispenser; -import org.bukkit.block.Sign; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.jobs.DeferredBlockResetsJob; -import com.tommytony.war.utils.DeferredBlockReset; -import com.tommytony.war.volumes.Volume; -import com.tommytony.war.volumes.ZoneVolume; - -/** - * The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes. - * - * @author tommytony - * - */ -public class PreDeGaulleZoneVolumeMapper { - - private static List readInventoryString(String invString) { - List items = new ArrayList(); - String[] itemsStrSplit = invString.split(";;"); - for (String itemStr : itemsStrSplit) { - String[] itemStrSplit = itemStr.split(";"); - if (itemStrSplit.length == 4) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); - stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3]))); - short durability = (short) Integer.parseInt(itemStrSplit[2]); - stack.setDurability(durability); - items.add(stack); - } else if (itemStrSplit.length == 3) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); - short durability = (short) Integer.parseInt(itemStrSplit[2]); - stack.setDurability(durability); - items.add(stack); - } else { - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]))); - } - } - return items; - } - - public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) { - BufferedReader in = null; - int noOfResetBlocks = 0; - try { - in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); - String firstLine = in.readLine(); - - if (firstLine != null && !firstLine.equals("")) { - boolean height129Fix = false; - int x1 = Integer.parseInt(in.readLine()); - int y1 = Integer.parseInt(in.readLine()); - if (y1 == 128) { - height129Fix = true; - y1 = 127; - } - int z1 = Integer.parseInt(in.readLine()); - in.readLine(); - int x2 = Integer.parseInt(in.readLine()); - int y2 = Integer.parseInt(in.readLine()); - if (y2 == 128) { - height129Fix = true; - y2 = 127; - } - int z2 = Integer.parseInt(in.readLine()); - - volume.setCornerOne(world.getBlockAt(x1, y1, z1)); - volume.setCornerTwo(world.getBlockAt(x2, y2, z2)); - - if (!onlyLoadCorners) { - DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world); - int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0; - int diskBlockType; - byte diskBlockData; - Block worldBlock; - int worldBlockId; - volume.clearBlocksThatDontFloat(); - x = volume.getMinX(); - String blockLine; - String[] blockSplit; - for (i = 0; i < volume.getSizeX(); i++) { - y = volume.getMinY(); - for (j = 0; j < volume.getSizeY(); j++) { - z = volume.getMinZ(); - for (k = 0; k < volume.getSizeZ(); k++) { - try { - blockLine = in.readLine(); - - if (blockLine != null && !blockLine.equals("")) { - blockSplit = blockLine.split(","); - if (blockLine != null && !blockLine.equals("") && blockSplit.length > 1) { - diskBlockType = Integer.parseInt(blockSplit[0]); - diskBlockData = Byte.parseByte(blockSplit[1]); - worldBlock = volume.getWorld().getBlockAt(x, y, z); - worldBlockId = worldBlock.getTypeId(); - if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) { - if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) { - // Signs read - String linesStr = ""; - if (blockSplit.length > 2) { - for (int o = 2; o < blockSplit.length; o++) { - linesStr += blockSplit[o]; - } - String[] lines = linesStr.split(";;"); - - // Signs set - // A sign post hanging on a wall south of here will - if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) { - deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines)); - } else { - worldBlock.setType(Material.getMaterial(diskBlockType)); - BlockState state = worldBlock.getState(); - state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData)); - if (state instanceof Sign) { - Sign sign = (Sign) state; - if (lines != null && sign.getLines() != null) { - if (lines.length > 0) { - sign.setLine(0, lines[0]); - } - if (lines.length > 1) { - sign.setLine(1, lines[1]); - } - if (lines.length > 2) { - sign.setLine(2, lines[2]); - } - if (lines.length > 3) { - sign.setLine(3, lines[3]); - } - sign.update(true); - } - } - } - } - } else if (diskBlockType == Material.CHEST.getId()) { - // Chests read - List items = null; - if (blockSplit.length > 2) { - String itemsStr = blockSplit[2]; - items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr); - } - - // Chests set - worldBlock.setType(Material.getMaterial(diskBlockType)); - worldBlock.setData(diskBlockData); - BlockState state = worldBlock.getState(); - if (state instanceof Chest) { - Chest chest = (Chest) state; - if (items != null) { - int ii = 0; - chest.getInventory().clear(); - for (ItemStack item : items) { - if (item != null) { - chest.getInventory().setItem(ii, item); - ii++; - } - } - chest.update(true); - } - } - } else if (diskBlockType == Material.DISPENSER.getId()) { - // Dispensers read - List items = null; - if (blockSplit.length > 2) { - String itemsStr = blockSplit[2]; - // String itemsStr = lineScanner.nextLine(); - items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr); - } - - // Dispensers set - worldBlock.setType(Material.getMaterial(diskBlockType)); - worldBlock.setData(diskBlockData); - BlockState state = worldBlock.getState(); - if (state instanceof Dispenser) { - Dispenser dispenser = (Dispenser) state; - if (items != null) { - int ii = 0; - dispenser.getInventory().clear(); - for (ItemStack item : items) { - if (item != null) { - dispenser.getInventory().setItem(ii, item); - ii++; - } - } - dispenser.update(true); - } - } - } else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) { - // Door blocks - - if (j - 1 > 0) { - Block blockBelow = world.getBlockAt(x, y - 1, z); - boolean belowIsGlass = blockBelow.getTypeId() == Material.GLASS.getId(); - // Set current block to glass if block below isn't glass. - // Having a glass block below means the current block is a door top. - if (belowIsGlass) { - // Top door block. Set both it and the block below as door. - blockBelow.setType(Material.getMaterial(diskBlockType)); - blockBelow.setData(diskBlockData); - worldBlock.setType(Material.getMaterial(diskBlockType)); - worldBlock.setData(diskBlockData); - } else { - worldBlock.setType(Material.GLASS); - } - } - - } else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) { - // Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol - // Change the block itself later on: - deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData)); - } else { - // regular block - worldBlock.setType(Material.getMaterial(diskBlockType)); - worldBlock.setData(diskBlockData); - } - noOfResetBlocks++; - } - visitedBlocks++; - } - blockReads++; - } - - } catch (Exception e) { - War.war.getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); - e.printStackTrace(); - } finally { - z++; - } - } - if (height129Fix && j == volume.getSizeY() - 1) { - for (int skip = 0; skip < volume.getSizeZ(); skip++) { - in.readLine(); // throw away the extra vertical block I used to save pre 0.8 - // scanner.nextLine(); - } - } - y++; - } - x++; - } - if (!deferred.isEmpty()) { - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1); - } - } - } - } catch (IOException e) { - War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } catch (Exception e) { - War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } finally { - if (in != null) { - // if (scanner != null) - try { - in.close(); - in = null; - // scanner.close(); - // scanner = null; - } catch (IOException e) { - War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - } - } - return noOfResetBlocks; - } - - public static int save(Volume volume, String zoneName, War war) { - int noOfSavedBlocks = 0; - if (volume.hasTwoCorners()) { - BufferedWriter out = null; - try { - (new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir(); - if (zoneName.equals("")) { - out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); - } else { - out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); - } - - out.write("corner1"); - out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getX())); - out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getY())); - out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getZ())); - out.newLine(); - out.write("corner2"); - out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getX())); - out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getY())); - out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getZ())); - out.newLine(); - - int x = 0; - int y = 0; - int z = 0; - Block block; - int typeId; - byte data; - BlockState state; - - x = volume.getMinX(); - for (int i = 0; i < volume.getSizeX(); i++) { - y = volume.getMinY(); - for (int j = 0; j < volume.getSizeY(); j++) { - z = volume.getMinZ(); - for (int k = 0; k < volume.getSizeZ(); k++) { - try { - block = volume.getWorld().getBlockAt(x, y, z); - typeId = block.getTypeId(); - data = block.getData(); - state = block.getState(); - - out.write(typeId + "," + data + ","); - - if (state instanceof Sign) { - // Signs - String extra = ""; - Sign sign = (Sign) state; - if (sign.getLines() != null) { - for (String line : sign.getLines()) { - extra += line + ";;"; - } - out.write(extra); - } - - } else if (state instanceof Chest) { - // Chests - Chest chest = (Chest) state; - Inventory inv = chest.getInventory(); - int size = inv.getSize(); - List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++) { - ItemStack item = inv.getItem(invIndex); - if (item != null && item.getType().getId() != Material.AIR.getId()) { - items.add(item); - } - } - String extra = ""; - if (items != null) { - for (ItemStack item : items) { - if (item != null) { - extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); - if (item.getData() != null) { - extra += ";" + item.getData().getData(); - } - extra += ";;"; - } - } - out.write(extra); - } - } else if (state instanceof Dispenser) { - // Dispensers - Dispenser dispenser = (Dispenser) state; - Inventory inv = dispenser.getInventory(); - int size = inv.getSize(); - List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++) { - ItemStack item = inv.getItem(invIndex); - if (item != null && item.getType().getId() != Material.AIR.getId()) { - items.add(item); - } - } - String extra = ""; - if (items != null) { - for (ItemStack item : items) { - if (item != null) { - extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); - if (item.getData() != null) { - extra += ";" + item.getData().getData(); - } - extra += ";;"; - } - } - out.write(extra); - } - } - noOfSavedBlocks++; - out.newLine(); - } catch (Exception e) { - war.log("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } finally { - z++; - } - } - y++; - } - x++; - } - } catch (IOException e) { - war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } catch (Exception e) { - war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - } - } - } - return noOfSavedBlocks; - } - -} diff --git a/war/src/main/java/com/tommytony/war/mappers/PropertiesFile.java b/war/src/main/java/com/tommytony/war/mappers/PropertiesFile.java deleted file mode 100644 index 254c313..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/PropertiesFile.java +++ /dev/null @@ -1,407 +0,0 @@ -package com.tommytony.war.mappers; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.logging.Logger; -import java.io.FileInputStream; -import java.util.Map; -import java.util.Properties; - -/** - * Used for accessing and creating .[properties] files, reads them as utf-8, saves as utf-8. Internationalization is key importance especially for character codes. - * - * @author Nijikokun - * @version 1.0.4, %G% - */ -public final class PropertiesFile { - - private static final Logger log = Logger.getLogger("Minecraft"); - private String fileName; - private Properties props = new Properties(); - private FileInputStream inputStream; - private FileOutputStream outputStream; - - // private List lines = new ArrayList(); - // private Map props = new HashMap(); - - /** - * Creates or opens a properties file using specified filename - * - * @param fileName - */ - public PropertiesFile(String fileName) { - this.fileName = fileName; - - File file = new File(fileName); - - try { - if (file.exists()) { - this.load(); - } else { - this.save(); - } - } catch (IOException ex) { - PropertiesFile.log.severe("[PropertiesFile] Unable to load " + fileName + "!"); - } - } - - /** - * The loader for property files, it reads the file as UTF8 or converts the string into UTF8. Used for simple runthrough's, loading, or reloading of the file. - * - * @throws IOException - */ - public void load() throws IOException { - this.inputStream = new FileInputStream(this.fileName); - this.props.load(this.inputStream); - } - - /** - * Writes out the key=value properties that were changed into a .[properties] file in UTF8. - */ - public void save() { - try { - this.outputStream = new FileOutputStream(this.fileName); - this.props.store(this.outputStream, null); - } catch (IOException ex) { - PropertiesFile.log.severe("[PropertiesFile] Unable to save " + this.fileName + "!"); - } - } - - public void close() { - if (this.outputStream != null) { - try { - this.outputStream.close(); - } catch (IOException e) { - PropertiesFile.log.severe("[PropertiesFile] Failed to close " + this.fileName + " writer!"); - } - } else if (this.inputStream != null) { - try { - this.inputStream.close(); - } catch (IOException e) { - PropertiesFile.log.severe("[PropertiesFile] Failed to close " + this.fileName + " reader!"); - } - } - } - - /** - * Returns a Map of all key=value properties in the file as <key (java.lang.String), value (java.lang.String)>
- *
- * Example:
- * - *
-	 * PropertiesFile settings = new PropertiesFile("settings.properties");
-	 * Map<String, String> mappedSettings;
-	 *
-	 * try {
-	 * 	mappedSettings = settings.returnMap();
-	 * } catch (Exception ex) {
-	 * 	log.info("Failed mapping settings.properties");
-	 * }
-	 * 
- * - *
- * - * @return map - Simple Map HashMap of the entire key=value as <key (java.lang.String), value (java.lang.String)> - * @throws Exception - * If the properties file doesn't exist. - */ - @SuppressWarnings("unchecked") - public Map returnMap() throws Exception { - return (Map) this.props.clone(); - } - - /** - * Checks to see if the .[properties] file contains the given key. - * - * @param var - * The key we are going to be checking the existance of. - * @return Boolean - True if the key exists, false if it cannot be found. - */ - public boolean containsKey(String var) { - return this.props.containsKey(var); - } - - /** - * Checks to see if this key exists in the .[properties] file. - * - * @param var - * The key we are grabbing the value of. - * @return java.lang.String - True if the key exists, false if it cannot be found. - */ - public String getProperty(String var) { - return this.props.getProperty(var); - } - - /** - * Remove a key from the file if it exists. This will save() which will invoke a load() on the file. - * - * @see #save() - * @param var - * The key that will be removed from the file - */ - public void removeKey(String var) { - if (this.props.containsKey(var)) { - this.props.remove(var); - this.save(); - } - } - - /** - * Checks the existance of a key. - * - * @see #containsKey(java.lang.String) - * @param key - * The key in question of existance. - * @return Boolean - True for existance, false for key found. - */ - public boolean keyExists(String key) { - return this.containsKey(key); - } - - /** - * Returns the value of the key given as a String, however we do not set a string if no key is found. - * - * @see #getProperty(java.lang.String) - * @param key - * The key we will retrieve the property from, if no key is found default to "" or empty. - */ - public String getString(String key) { - if (this.containsKey(key)) { - return this.getProperty(key); - } - - return ""; - } - - /** - * Returns the value of the key given as a String. If it is not found, it will invoke saving the default value to the properties file. - * - * @see #setString(java.lang.String, java.lang.String) - * @see #getProperty(java.lang.String) - * @param key - * The key that we will be grabbing the value from, if no value is found set and return value - * @param value - * The default value that we will be setting if no prior key is found. - * @return java.lang.String Either we will return the default value or a prior existing value depending on existance. - */ - public String getString(String key, String value) { - if (this.containsKey(key)) { - return this.getProperty(key); - } - - this.setString(key, value); - return value; - } - - /** - * Save the value given as a String on the specified key. - * - * @see #save() - * @param key - * The key that we will be addressing the value to. - * @param value - * The value we will be setting inside the .[properties] file. - */ - public void setString(String key, String value) { - this.props.put(key, value); - this.save(); - } - - /** - * Returns the value of the key given in a Integer, however we do not set a string if no key is found. - * - * @see #getProperty(String var) - * @param key - * The key we will retrieve the property from, if no key is found default to 0 - */ - public int getInt(String key) { - if (this.containsKey(key)) { - return Integer.parseInt(this.getProperty(key)); - } - - return 0; - } - - /** - * Returns the int value of a key - * - * @see #setInt(String key, int value) - * @param key - * The key that we will be grabbing the value from, if no value is found set and return value - * @param value - * The default value that we will be setting if no prior key is found. - * @return Integer - Either we will return the default value or a prior existing value depending on existance. - */ - public int getInt(String key, int value) { - if (this.containsKey(key)) { - return Integer.parseInt(this.getProperty(key)); - } - - this.setInt(key, value); - return value; - - } - - /** - * Save the value given as a int on the specified key. - * - * @see #save() - * @param key - * The key that we will be addressing the value to. - * @param value - * The value we will be setting inside the .[properties] file. - */ - public void setInt(String key, int value) { - this.props.put(key, String.valueOf(value)); - - this.save(); - } - - /** - * Returns the value of the key given in a Double, however we do not set a string if no key is found. - * - * @see #getProperty(String var) - * @param key - * The key we will retrieve the property from, if no key is found default to 0.0 - */ - public double getDouble(String key) { - if (this.containsKey(key)) { - return Double.parseDouble(this.getProperty(key)); - } - - return 0; - } - - /** - * Returns the double value of a key - * - * @see #setDouble(String key, double value) - * @param key - * The key that we will be grabbing the value from, if no value is found set and return value - * @param value - * The default value that we will be setting if no prior key is found. - * @return Double - Either we will return the default value or a prior existing value depending on existance. - */ - public double getDouble(String key, double value) { - if (this.containsKey(key)) { - return Double.parseDouble(this.getProperty(key)); - } - - this.setDouble(key, value); - return value; - } - - /** - * Save the value given as a double on the specified key. - * - * @see #save() - * @param key - * The key that we will be addressing the value to. - * @param value - * The value we will be setting inside the .[properties] file. - */ - public void setDouble(String key, double value) { - this.props.put(key, String.valueOf(value)); - - this.save(); - } - - /** - * Returns the value of the key given in a Long, however we do not set a string if no key is found. - * - * @see #getProperty(String var) - * @param key - * The key we will retrieve the property from, if no key is found default to 0L - */ - public long getLong(String key) { - if (this.containsKey(key)) { - return Long.parseLong(this.getProperty(key)); - } - - return 0; - } - - /** - * Returns the long value of a key - * - * @see #setLong(String key, long value) - * @param key - * The key that we will be grabbing the value from, if no value is found set and return value - * @param value - * The default value that we will be setting if no prior key is found. - * @return Long - Either we will return the default value or a prior existing value depending on existance. - */ - public long getLong(String key, long value) { - if (this.containsKey(key)) { - return Long.parseLong(this.getProperty(key)); - } - - this.setLong(key, value); - return value; - } - - /** - * Save the value given as a long on the specified key. - * - * @see #save() - * @param key - * The key that we will be addressing the value to. - * @param value - * The value we will be setting inside the .[properties] file. - */ - public void setLong(String key, long value) { - this.props.put(key, String.valueOf(value)); - - this.save(); - } - - /** - * Returns the value of the key given in a Boolean, however we do not set a string if no key is found. - * - * @see #getProperty(String var) - * @param key - * The key we will retrieve the property from, if no key is found default to false - */ - public boolean getBoolean(String key) { - if (this.containsKey(key)) { - return Boolean.parseBoolean(this.getProperty(key)); - } - - return false; - } - - /** - * Returns the boolean value of a key - * - * @see #setBoolean(String key, boolean value) - * @param key - * The key that we will be grabbing the value from, if no value is found set and return value - * @param value - * The default value that we will be setting if no prior key is found. - * @return Boolean - Either we will return the default value or a prior existing value depending on existance. - */ - public boolean getBoolean(String key, boolean value) { - if (this.containsKey(key)) { - return Boolean.parseBoolean(this.getProperty(key)); - } - - this.setBoolean(key, value); - return value; - } - - /** - * Save the value given as a boolean on the specified key. - * - * @see #save() - * @param key - * The key that we will be addressing the value to. - * @param value - * The value we will be setting inside the .[properties] file. - */ - public void setBoolean(String key, boolean value) { - this.props.put(key, String.valueOf(value)); - - this.save(); - } -} diff --git a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java deleted file mode 100644 index 3913109..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java +++ /dev/null @@ -1,333 +0,0 @@ -package com.tommytony.war.mappers; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.volumes.Volume; - -/** - * - * @author tommytony - * - */ -public class VolumeMapper { - - public static Volume loadVolume(String volumeName, String zoneName, World world) { - Volume volume = new Volume(volumeName, world); - VolumeMapper.load(volume, zoneName, world); - return volume; - } - - public static void load(Volume volume, String zoneName, World world) { - BufferedReader in = null; - try { - if (zoneName.equals("")) { - in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub - } else { - in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); - } - String firstLine = in.readLine(); - if (firstLine != null && !firstLine.equals("")) { - boolean height129Fix = false; - int x1 = Integer.parseInt(in.readLine()); - int y1 = Integer.parseInt(in.readLine()); - if (y1 == 128) { - height129Fix = true; - y1 = 127; - } - int z1 = Integer.parseInt(in.readLine()); - in.readLine(); - int x2 = Integer.parseInt(in.readLine()); - int y2 = Integer.parseInt(in.readLine()); - if (y2 == 128) { - height129Fix = true; - y2 = 127; - } - int z2 = Integer.parseInt(in.readLine()); - - volume.setCornerOne(world.getBlockAt(x1, y1, z1)); - volume.setCornerTwo(world.getBlockAt(x2, y2, z2)); - - volume.setBlockTypes(new int[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]); - volume.setBlockDatas(new byte[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]); - int blockReads = 0; - for (int i = 0; i < volume.getSizeX(); i++) { - for (int j = 0; j < volume.getSizeY(); j++) { - for (int k = 0; k < volume.getSizeZ(); k++) { - try { - String blockLine = in.readLine(); - if (blockLine != null && !blockLine.equals("")) { - String[] blockSplit = blockLine.split(","); - if (blockLine != null && !blockLine.equals("") && blockSplit.length > 1) { - int typeID = Integer.parseInt(blockSplit[0]); - byte data = Byte.parseByte(blockSplit[1]); - - volume.getBlockTypes()[i][j][k] = typeID; - volume.getBlockDatas()[i][j][k] = data; - - if (typeID == Material.WALL_SIGN.getId() || typeID == Material.SIGN_POST.getId()) { - // Signs - String linesStr = ""; - if (blockSplit.length > 2) { - for (int o = 2; o < blockSplit.length; o++) { - linesStr += blockSplit[o]; - } - String[] lines = linesStr.split(";;"); - volume.getSignLines().put("sign-" + i + "-" + j + "-" + k, lines); - } - } else if (typeID == Material.CHEST.getId()) { - // Chests - List items = new ArrayList(); - if (blockSplit.length > 2) { - items = readInventoryString(blockSplit[2]); - } - volume.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items); - } else if (typeID == Material.DISPENSER.getId()) { - // Dispensers - List items = new ArrayList(); - if (blockSplit.length > 2) { - items = readInventoryString(blockSplit[2]); - } - volume.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items); - } - } - blockReads++; - } - } catch (Exception e) { - War.war.log("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - } - if (height129Fix && j == volume.getSizeY() - 1) { - for (int skip = 0; skip < volume.getSizeZ(); skip++) { - in.readLine(); // throw away the extra vertical block I used to save pre 0.8 - } - } - } - } - } - } catch (IOException e) { - War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } catch (Exception e) { - War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - } - } - } - - public static void save(Volume volume, String zoneName) { - if (volume.hasTwoCorners()) { - BufferedWriter out = null; - try { - if (zoneName.equals("")) { - out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); - } else { - out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); - } - - out.write("corner1"); - out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getX())); - out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getY())); - out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getZ())); - out.newLine(); - out.write("corner2"); - out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getX())); - out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getY())); - out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getZ())); - out.newLine(); - int blockWrites = 0; - for (int i = 0; i < volume.getSizeX(); i++) { - for (int j = 0; j < volume.getSizeY(); j++) { - for (int k = 0; k < volume.getSizeZ(); k++) { - try { - int typeId = volume.getBlockTypes()[i][j][k]; - byte data = volume.getBlockDatas()[i][j][k]; - out.write(typeId + "," + data + ","); - if (typeId == Material.WALL_SIGN.getId() || typeId == Material.SIGN_POST.getId()) { - // Signs - String extra = ""; - String[] lines = volume.getSignLines().get("sign-" + i + "-" + j + "-" + k); - if (lines != null) { - for (String line : lines) { - extra += line + ";;"; - } - out.write(extra); - } - } else if (typeId == Material.CHEST.getId()) { - // Chests - String extra = ""; - List contents = volume.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k); - if (contents != null) { - out.write(buildInventoryStringFromItemList(contents)); - out.write(extra); - } - } else if (typeId == Material.DISPENSER.getId()) { - // Dispensers - List contents = volume.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k); - if (contents != null) { - out.write(buildInventoryStringFromItemList(contents)); - } - } - out.newLine(); - } catch (Exception e) { - War.war.log("Unexpected error while writing block into volume " + volume.getName() + " file for zone " + zoneName + ". Blocks written so far: " + blockWrites + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - } - } - } - } catch (IOException e) { - War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } catch (Exception e) { - War.war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - War.war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - } - } - } - } - - /** - * Parses an inventory string - * - * @param String - * invString string to parse - * @return List Parsed items - */ - public static List readInventoryString(String invString) { - List items = new ArrayList(); - if (invString != null && !invString.equals("")) { - String[] itemsStrSplit = invString.split(";;"); - for (String itemStr : itemsStrSplit) { - String[] itemStrSplit = itemStr.split(";"); - if (itemStrSplit.length == 5) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); - stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3]))); - short durability = (short) Integer.parseInt(itemStrSplit[2]); - stack.setDurability(durability); - - // enchantments - String[] enchantmentsSplit = itemStrSplit[4].split("::"); - for (String enchantmentStr : enchantmentsSplit) { - if (!enchantmentStr.equals("")) { - String[] enchantmentSplit = enchantmentStr.split(":"); - int enchantId = Integer.parseInt(enchantmentSplit[0]); - int level = Integer.parseInt(enchantmentSplit[1]); - stack.addEnchantment(Enchantment.getById(enchantId), level); - } - } - - items.add(stack); - } else if (itemStrSplit.length == 4) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); - stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3]))); - short durability = (short) Integer.parseInt(itemStrSplit[2]); - stack.setDurability(durability); - items.add(stack); - } else if (itemStrSplit.length == 3) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); - short durability = (short) Integer.parseInt(itemStrSplit[2]); - stack.setDurability(durability); - items.add(stack); - } else { - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]))); - } - } - } - return items; - } - - /** - * Create a string out of a list of items - * - * @param items The list of items - * @return The list as a string - */ - public static String buildInventoryStringFromItemList(List items) { - String extra = ""; - for (ItemStack item : items) { - if (item != null) { - extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); - if (item.getData() != null) { - extra += ";" + item.getData().getData(); - } - if (item.getEnchantments().keySet().size() > 0) { - String enchantmentsStr = ""; - for (Enchantment enchantment : item.getEnchantments().keySet()) { - enchantmentsStr += enchantment.getId() + ":" + item.getEnchantments().get(enchantment) + "::"; - } - extra += ";" + enchantmentsStr; - } - extra += ";;"; - } - } - - return extra; - } - - /** - * Extracts a list of items from and inventory - * - * @param inv The inventory - * @return The inventory as a list - */ - public static List getItemListFromInv(Inventory inv) { - int size = inv.getSize(); - List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++) { - ItemStack item = inv.getItem(invIndex); - if (item != null && item.getType().getId() != Material.AIR.getId()) { - items.add(item); - } - } - return items; - } - - public static void delete(Volume volume) { - File volFile = new File("War/dat/volume-" + volume.getName()); - boolean deletedData = volFile.delete(); - if (!deletedData) { - War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING); - } - } - -} diff --git a/war/src/main/java/com/tommytony/war/mappers/WarTxtMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarTxtMapper.java deleted file mode 100644 index 8f4581e..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/WarTxtMapper.java +++ /dev/null @@ -1,459 +0,0 @@ -package com.tommytony.war.mappers; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.logging.Level; - -import org.bukkit.inventory.ItemStack; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.FlagReturn; -import com.tommytony.war.TeamSpawnStyle; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.WarConfig; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.jobs.RestoreWarhubJob; -import com.tommytony.war.jobs.RestoreWarzonesJob; - -/** - * - * @author tommytony - * - */ -public class WarTxtMapper { - - public static void load() { - load(false); - } - - public static void load(boolean convertingToYml) { - (War.war.getDataFolder()).mkdir(); - (new File(War.war.getDataFolder().getPath() + "/dat")).mkdir(); - PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt"); - try { - warConfig.load(); - } catch (IOException e) { - War.war.log("Failed to load war.txt file.", Level.WARNING); - e.printStackTrace(); - } - - // Create file if need be - boolean newWar = false; - if (!warConfig.containsKey("warzones")) { - newWar = true; - WarTxtMapper.save(); - War.war.log("war.txt settings file created.", Level.INFO); - try { - warConfig.load(); - } catch (IOException e) { - War.war.log("Failed to reload war.txt file after creating it.", Level.WARNING); - e.printStackTrace(); - } - } - - // warzones - String warzonesStr = warConfig.getString("warzones"); - RestoreWarzonesJob restoreWarzones = new RestoreWarzonesJob(warzonesStr, newWar, convertingToYml); - // make sure warhub job is over before this one ends, because this job will launch conversion (which needs the warhub) - if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarzones, 20) == -1) { - War.war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING); - } - - // zone makers - String[] makers = warConfig.getString("zoneMakers").split(","); - War.war.getZoneMakerNames().clear(); - for (String makerName : makers) { - if (makerName != null && !makerName.equals("")) { - War.war.getZoneMakerNames().add(makerName); - } - } - - // command whitelist - String[] whitelist = warConfig.getString("commandWhitelist").split(","); - War.war.getCommandWhitelist().clear(); - for (String command : whitelist) { - if (command != null && !command.equals("")) { - War.war.getCommandWhitelist().add(command); - } - } - - // defaultLoadout - War.war.getDefaultInventories().getLoadouts().clear(); - - String loadoutStr = warConfig.getString("defaultLoadout"); - if (loadoutStr != null && !loadoutStr.equals("")) { - War.war.getDefaultInventories().addLoadout("default", new HashMap()); - LoadoutTxtMapper.fromStringToLoadout(loadoutStr, War.war.getDefaultInventories().getLoadouts().get("default")); - } - - // defaultExtraLoadouts - String extraLoadoutStr = warConfig.getString("defaultExtraLoadouts"); - String[] extraLoadoutsSplit = extraLoadoutStr.split(","); - - for (String nameStr : extraLoadoutsSplit) { - if (nameStr != null && !nameStr.equals("")) { - War.war.getDefaultInventories().addLoadout(nameStr, new HashMap()); - } - } - - for (String extraName : extraLoadoutsSplit) { - if (extraName != null && !extraName.equals("")) { - String loadoutString = warConfig.getString(extraName + "Loadout"); - HashMap loadout = War.war.getDefaultInventories().getLoadouts().get(extraName); - LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout); - } - } - - // maxZones - if (warConfig.keyExists("maxZones")) { - War.war.getWarConfig().put(WarConfig.MAXZONES, warConfig.getInt("maxZones")); - } - - // defaultLifePool - if (warConfig.keyExists("defaultLifePool")) { - War.war.getTeamDefaultConfig().put(TeamConfig.LIFEPOOL, warConfig.getInt("defaultLifePool")); - } - - // defaultMonumentHeal - if (warConfig.keyExists("defaultMonumentHeal")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MONUMENTHEAL, warConfig.getInt("defaultMonumentHeal")); - } - - // defaultFriendlyFire - if (warConfig.keyExists("defaultFriendlyFire")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.FRIENDLYFIRE, warConfig.getBoolean("defaultFriendlyFire")); - } - - // defaultAutoAssignOnly - if (warConfig.keyExists("defaultAutoAssignOnly")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.AUTOASSIGN, warConfig.getBoolean("defaultAutoAssignOnly")); - } - - // defaultFlagPointsOnly - if (warConfig.keyExists("defaultFlagPointsOnly")) { - War.war.getTeamDefaultConfig().put(TeamConfig.FLAGPOINTSONLY, warConfig.getBoolean("defaultFlagPointsOnly")); - } - - // defaultFlagMustBeHome - if (warConfig.keyExists("defaultFlagMustBeHome")) { - War.war.getTeamDefaultConfig().put(TeamConfig.FLAGMUSTBEHOME, warConfig.getBoolean("defaultFlagMustBeHome")); - } - - // defaultTeamCap - if (warConfig.keyExists("defaultTeamCap")) { - War.war.getTeamDefaultConfig().put(TeamConfig.TEAMSIZE, warConfig.getInt("defaultTeamCap")); - } - - // defaultScoreCap - if (warConfig.keyExists("defaultScoreCap")) { - War.war.getTeamDefaultConfig().put(TeamConfig.MAXSCORE, warConfig.getInt("defaultScoreCap")); - } - - // defaultRespawnTimer - if (warConfig.keyExists("defaultRespawnTimer")) { - War.war.getTeamDefaultConfig().put(TeamConfig.RESPAWNTIMER, warConfig.getInt("defaultRespawnTimer")); - } - - // pvpInZonesOnly - if (warConfig.keyExists("pvpInZonesOnly")) { - War.war.getWarConfig().put(WarConfig.PVPINZONESONLY, warConfig.getBoolean("pvpInZonesOnly")); - } - - // defaultBlockHeads - if (warConfig.keyExists("defaultBlockHeads")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.BLOCKHEADS, warConfig.getBoolean("defaultBlockHeads")); - } - - // buildInZonesOnly - if (warConfig.keyExists("buildInZonesOnly")) { - War.war.getWarConfig().put(WarConfig.BUILDINZONESONLY, warConfig.getBoolean("buildInZonesOnly")); - } - - // disablePVPMessage - if (warConfig.keyExists("disablePvpMessage")) { - War.war.getWarConfig().put(WarConfig.DISABLEPVPMESSAGE, warConfig.getBoolean("disablePvpMessage")); - } - - // disableBuildMessage - if (warConfig.keyExists("disableBuildMessage")) { - War.war.getWarConfig().put(WarConfig.DISABLEBUILDMESSAGE, warConfig.getBoolean("disableBuildMessage")); - } - - // tntInZonesOnly - if (warConfig.keyExists("tntInZonesOnly")) { - War.war.getWarConfig().put(WarConfig.TNTINZONESONLY, warConfig.getBoolean("tntInZonesOnly")); - } - - // defaultSpawnStyle - String spawnStyle = warConfig.getString("defaultspawnStyle"); - if (spawnStyle != null && !spawnStyle.equals("")) { - War.war.getTeamDefaultConfig().put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.getStyleFromString(spawnStyle)); - } - - // defaultFlagReturn - String flagReturn = warConfig.getString("defaultFlagReturn"); - if (flagReturn != null && !flagReturn.equals("")) { - War.war.getTeamDefaultConfig().put(TeamConfig.FLAGRETURN, FlagReturn.getFromString(flagReturn)); - } - - // defaultReward - String defaultRewardStr = warConfig.getString("defaultReward"); - if (defaultRewardStr != null && !defaultRewardStr.equals("")) { - LoadoutTxtMapper.fromStringToLoadout(defaultRewardStr, War.war.getDefaultInventories().getReward()); - } - - // defaultUnbreakableZoneBlocks - if (warConfig.keyExists("defaultUnbreakableZoneBlocks")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.UNBREAKABLE, warConfig.getBoolean("defaultUnbreakableZoneBlocks")); - } - - // defaultNoCreatures - if (warConfig.keyExists("defaultNoCreatures")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.NOCREATURES, warConfig.getBoolean("defaultNoCreatures")); - } - - // defaultGlassWalls - if (warConfig.keyExists("defaultGlassWalls")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.GLASSWALLS, warConfig.getBoolean("defaultGlassWalls")); - } - - // defaultPvpInZone - if (warConfig.keyExists("defaultPvpInZone")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.PVPINZONE, warConfig.getBoolean("defaultPvpInZone")); - } - - // defaultInstaBreak - if (warConfig.keyExists("defaultInstaBreak")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.INSTABREAK, warConfig.getBoolean("defaultInstaBreak")); - } - - // defaultNoDrops - if (warConfig.keyExists("defaultNoDrops")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.NODROPS, warConfig.getBoolean("defaultNoDrops")); - } - - // defaultNoHunger - if (warConfig.keyExists("defaultNoHunger")) { - War.war.getTeamDefaultConfig().put(TeamConfig.NOHUNGER, warConfig.getBoolean("defaultNoHunger")); - } - - // defaultSaturation - if (warConfig.keyExists("defaultSaturation")) { - War.war.getTeamDefaultConfig().put(TeamConfig.SATURATION, warConfig.getInt("defaultSaturation")); - } - - // defaultMinPlayers - if (warConfig.keyExists("defaultMinPlayers")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MINPLAYERS, warConfig.getInt("defaultMinPlayers")); - } - - // defaultMinTeams - if (warConfig.keyExists("defaultMinTeams")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MINTEAMS, warConfig.getInt("defaultMinTeams")); - } - - // defaultResetOnEmpty - if (warConfig.keyExists("defaultResetOnEmpty")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONEMPTY, warConfig.getBoolean("defaultResetOnEmpty")); - } - - // defaultResetOnLoad - if (warConfig.keyExists("defaultResetOnLoad")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONLOAD, warConfig.getBoolean("defaultResetOnLoad")); - } - - // defaultResetOnUnload - if (warConfig.keyExists("defaultResetOnUnload")) { - War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONUNLOAD, warConfig.getBoolean("defaultResetOnUnload")); - } - - // warhub - String hubStr = warConfig.getString("warhub"); - if (hubStr != null && !hubStr.equals("")) { - RestoreWarhubJob restoreWarhub = new RestoreWarhubJob(hubStr); - if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarhub) == -1) { - War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING); - } - } - - warConfig.close(); - } - - public static void save() { -// PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt"); -// String warzonesStr = ""; - - War.war.log("Saving War with WarTxtMapper", Level.SEVERE); - -// // warzones -// for (Warzone zone : War.war.getWarzones()) { -// warzonesStr += zone.getName() + ","; -// } -// warConfig.setString("warzones", warzonesStr); -// -// // zone makers: default is none and it means everyone can use /setzone -// String makersStr = ""; // everyone -// for (String name : War.war.getZoneMakerNames()) { -// makersStr += name + ","; -// } -// warConfig.setString("zoneMakers", makersStr); -// -// // whitelisted commands during a game -// String commandWhitelistStr = ""; // everyone -// for (String command : War.war.getCommandWhitelist()) { -// commandWhitelistStr += command + ","; -// } -// warConfig.setString("commandWhitelist", commandWhitelistStr); -// -// // defaultLoadout -// HashMap items = War.war.getDefaultInventories().getLoadouts().get("default"); -// warConfig.setString("defaultLoadout", LoadoutTxtMapper.fromLoadoutToString(items)); -// -// // defaultExtraLoadouts -// String extraLoadoutsStr = ""; -// for (String name : War.war.getDefaultInventories().getLoadouts().keySet()) { -// if (!name.equals("default")) { -// extraLoadoutsStr += name + ","; -// -// HashMap loadout = War.war.getDefaultInventories().getLoadouts().get(name); -// warConfig.setString(name + "Loadout", LoadoutTxtMapper.fromLoadoutToString(loadout)); -// } -// } -// warConfig.setString("defaultExtraLoadouts", extraLoadoutsStr); -// -// // maxZones -// warConfig.setInt("maxZones", War.war.getWarConfig().getInt(WarConfig.MAXZONES)); -// -// // defaultLifepool -// warConfig.setInt("defaultLifePool", War.war.getDefaultLifepool()); -// -// // defaultMonumentHeal -// warConfig.setInt("defaultMonumentHeal", War.war.getDefaultMonumentHeal()); -// -// // defaultFriendlyFire -// warConfig.setBoolean("defaultFriendlyFire", War.war.isDefaultFriendlyFire()); -// -// // defaultAutoAssignOnly -// warConfig.setBoolean("defaultAutoAssignOnly", War.war.isDefaultAutoAssignOnly()); -// -// // defaultFlagPointsOnly -// warConfig.setBoolean("defaultFlagPointsOnly", War.war.isDefaultFlagPointsOnly()); -// -// // defaultFlagMustBeHome -// warConfig.setBoolean("defaultFlagMustBeHome", War.war.isDefaultFlagMustBeHome()); -// -// // defaultTeamCap -// warConfig.setInt("defaultTeamCap", War.war.getDefaultTeamCap()); -// -// // defaultScoreCap -// warConfig.setInt("defaultScoreCap", War.war.getDefaultScoreCap()); -// -// // defaultRespawnTimer -// warConfig.setInt("defaultRespawnTimer", War.war.getDefaultRespawnTimer()); -// -// // pvpInZonesOnly -// warConfig.setBoolean("pvpInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.PVPINZONESONLY)); -// -// // defaultBlockHeads -// warConfig.setBoolean("defaultBlockHeads", War.war.isDefaultBlockHeads()); -// -// // buildInZonesOnly -// warConfig.setBoolean("buildInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY)); -// -// // disablePVPMessage -// warConfig.setBoolean("disablePvpMessage", War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE)); -// -// // disableBuildMessage -// warConfig.setBoolean("disableBuildMessage", War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)); -// -// // tntInZonesOnly -// warConfig.setBoolean("tntInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.TNTINZONESONLY)); -// -// // spawnStyle -// warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle().toString()); -// -// // flagReturn -// warConfig.setString("flagReturn", War.war.getDefaultFlagReturn().toString()); -// -// // defaultReward -// String defaultRewardStr = ""; -// HashMap rewardItems = War.war.getDefaultInventories().getReward(); -// for (Integer slot : rewardItems.keySet()) { -// ItemStack item = items.get(slot); -// if (item != null) { -// defaultRewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";"; -// } -// } -// warConfig.setString("defaultReward", defaultRewardStr); -// -// // defaultUnbreakableZoneBlocks -// warConfig.setBoolean("defaultUnbreakableZoneBlocks", War.war.isDefaultUnbreakableZoneBlocks()); -// -// // defaultNoCreatures -// warConfig.setBoolean("defaultNoCreatures", War.war.isDefaultNoCreatures()); -// -// // defaultGlassWalls -// warConfig.setBoolean("defaultGlassWalls", War.war.isDefaultGlassWalls()); -// -// // defaultPvpInZone -// warConfig.setBoolean("defaultPvpInZone", War.war.isDefaultPvpInZone()); -// -// // defaultInstaBreak -// warConfig.setBoolean("defaultInstaBreak", War.war.isDefaultInstaBreak()); -// -// // defaultNoDrops -// warConfig.setBoolean("defaultNoDrops", War.war.isDefaultNoDrops()); -// -// // defaultNoHunger -// warConfig.setBoolean("defaultNoHunger", War.war.isDefaultNoHunger()); -// -// // defaultSaturation -// warConfig.setInt("defaultSaturation", War.war.getDefaultSaturation()); -// -// // defaultMinPlayers -// warConfig.setInt("defaultMinPlayers", War.war.getDefaultMinPlayers()); -// -// // defaultMinTeams -// warConfig.setInt("defaultMinTeams", War.war.getDefaultMinTeams()); -// -// // defaultResetOnEmpty -// warConfig.setBoolean("defaultResetOnEmpty", War.war.isDefaultResetOnEmpty()); -// -// // defaultResetOnLoad -// warConfig.setBoolean("defaultResetOnLoad", War.war.isDefaultResetOnLoad()); -// -// // defaultResetOnUnload -// warConfig.setBoolean("defaultResetOnUnload", War.war.isDefaultResetOnUnload()); -// -// // warhub -// String hubStr = ""; -// WarHub hub = War.war.getWarHub(); -// if (hub != null) { -// String orientationStr = ""; -// switch (hub.getOrientation()) { -// case SOUTH: -// orientationStr = "south"; -// break; -// case EAST: -// orientationStr = "east"; -// break; -// case NORTH: -// orientationStr = "north"; -// break; -// case WEST: -// default: -// orientationStr = "west"; -// break; -// } -// hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + "," -// + hub.getLocation().getWorld().getName() + "," + orientationStr; -// VolumeMapper.save(hub.getVolume(), ""); -// } -// warConfig.setString("warhub", hubStr); -// -// warConfig.save(); -// warConfig.close(); - } -} diff --git a/war/src/main/java/com/tommytony/war/mappers/WarYmlMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarYmlMapper.java deleted file mode 100644 index b2c93b7..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/WarYmlMapper.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.tommytony.war.mappers; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.logging.Level; - -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.inventory.ItemStack; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.WarHub; -import com.tommytony.war.Warzone; -import com.tommytony.war.jobs.RestoreYmlWarhubJob; -import com.tommytony.war.jobs.RestoreYmlWarzonesJob; - -public class WarYmlMapper { - - public static void load() { - (War.war.getDataFolder()).mkdir(); - (new File(War.war.getDataFolder().getPath() + "/dat")).mkdir(); - File warTxtFile = new File(War.war.getDataFolder().getPath() + "/war.txt"); - File warYmlFile = new File(War.war.getDataFolder().getPath() + "/war.yml"); - - boolean newWar = false; - if (warTxtFile.exists() && !warYmlFile.exists()) { - // Load both War and warzones (with delay) in old format, save War to new format immediatly - WarTxtMapper.load(true); - // Warzones are getting loaded by TxtMapper launched job. That job will in turn save the Warzones to their new format. - return; - } else if (!warTxtFile.exists() && !warYmlFile.exists()) { - // Save defaults to disk - newWar = true; - WarYmlMapper.save(); - War.war.log("war.yml settings file created.", Level.INFO); - } - - YamlConfiguration warYmlConfig = YamlConfiguration.loadConfiguration(warYmlFile); - ConfigurationSection warRootSection = warYmlConfig.getConfigurationSection("set"); - - // warzones - List warzones = warRootSection.getStringList("war.info.warzones"); - RestoreYmlWarzonesJob restoreWarzones = new RestoreYmlWarzonesJob(warzones, newWar); // during conversion, this should execute just after the RestoreTxtWarzonesJob - if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarzones) == -1) { - War.war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING); - } - - // zone makers - List makers = warRootSection.getStringList("war.info.zonemakers"); - War.war.getZoneMakerNames().clear(); - for (String makerName : makers) { - if (makerName != null && !makerName.equals("")) { - War.war.getZoneMakerNames().add(makerName); - } - } - - // command whitelist - List whitelist = warRootSection.getStringList("war.info.commandwhitelist"); - War.war.getCommandWhitelist().clear(); - for (String command : whitelist) { - if (command != null && !command.equals("")) { - War.war.getCommandWhitelist().add(command); - } - } - - // defaultLoadouts - ConfigurationSection loadoutsSection = warRootSection.getConfigurationSection("team.default.loadout"); - LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, War.war.getDefaultInventories().getLoadouts()); - - // defaultReward - ConfigurationSection rewardsSection = warRootSection.getConfigurationSection("team.default.reward"); - HashMap reward = new HashMap(); - LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default"); - War.war.getDefaultInventories().setReward(reward); - - // War settings - ConfigurationSection warConfigSection = warRootSection.getConfigurationSection("war.config"); - War.war.getWarConfig().loadFrom(warConfigSection); - - // Warzone default settings - ConfigurationSection warzoneConfigSection = warRootSection.getConfigurationSection("warzone.default.config"); - War.war.getWarzoneDefaultConfig().loadFrom(warzoneConfigSection); - - // Team default settings - ConfigurationSection teamConfigSection = warRootSection.getConfigurationSection("team.default.config"); - War.war.getTeamDefaultConfig().loadFrom(teamConfigSection); - - // warhub - ConfigurationSection hubConfigSection = warRootSection.getConfigurationSection("war.info.warhub"); - if (hubConfigSection != null) { - RestoreYmlWarhubJob restoreWarhub = new RestoreYmlWarhubJob(hubConfigSection); - if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarhub) == -1) { - War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING); - } - } - } - - public static void save() { - YamlConfiguration warYmlConfig = new YamlConfiguration(); - ConfigurationSection warRootSection = warYmlConfig.createSection("set"); - (new File(War.war.getDataFolder().getPath())).mkdir(); - (new File(War.war.getDataFolder().getPath() + "/dat")).mkdir(); - - // War settings - ConfigurationSection warConfigSection = warRootSection.createSection("war.config"); - War.war.getWarConfig().saveTo(warConfigSection); - - // Warzone default settings - ConfigurationSection warzoneConfigSection = warRootSection.createSection("warzone.default.config"); - War.war.getWarzoneDefaultConfig().saveTo(warzoneConfigSection); - - // Team default settings - ConfigurationSection teamDefault = warRootSection.createSection("team.default"); - ConfigurationSection teamConfigSection = teamDefault.createSection("config"); - War.war.getTeamDefaultConfig().saveTo(teamConfigSection); - - // defaultLoadouts - ConfigurationSection loadoutSection = teamDefault.createSection("loadout"); - LoadoutYmlMapper.fromLoadoutsToConfig(War.war.getDefaultInventories().getLoadouts(), loadoutSection); - - // defaultReward - ConfigurationSection rewardsSection = teamDefault.createSection("reward"); - LoadoutYmlMapper.fromLoadoutToConfig("default", War.war.getDefaultInventories().getReward(), rewardsSection); - - ConfigurationSection warInfoSection = warRootSection.createSection("war.info"); - - // warzones - List warzones = new ArrayList(); - for (Warzone zone : War.war.getWarzones()) { - warzones.add(zone.getName()); - } - warInfoSection.set("warzones", warzones); - - // zone makers - warInfoSection.set("zonemakers", War.war.getZoneMakerNames()); - - // whitelisted commands during a game - warInfoSection.set("commandwhitelist", War.war.getCommandWhitelist()); - - // warhub - WarHub hub = War.war.getWarHub(); - if (hub != null) { - String orientationStr = ""; - switch (hub.getOrientation()) { - case SOUTH: - orientationStr = "south"; - break; - case EAST: - orientationStr = "east"; - break; - case NORTH: - orientationStr = "north"; - break; - case WEST: - default: - orientationStr = "west"; - break; - } - - ConfigurationSection hubConfigSection = warInfoSection.createSection("warhub"); - hubConfigSection.set("x", hub.getLocation().getBlockX()); - hubConfigSection.set("y", hub.getLocation().getBlockY()); - hubConfigSection.set("z", hub.getLocation().getBlockZ()); - hubConfigSection.set("world", hub.getLocation().getWorld().getName()); - hubConfigSection.set("orientation", orientationStr); - - VolumeMapper.save(hub.getVolume(), ""); - } - - // Save to disk - File warConfigFile = new File(War.war.getDataFolder().getPath() + "/war.yml"); - try { - warYmlConfig.save(warConfigFile); - } catch (IOException e) { - War.war.log("Failed to save war.yml", Level.WARNING); - e.printStackTrace(); - } - } -} diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneTxtMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneTxtMapper.java deleted file mode 100644 index 65656fb..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneTxtMapper.java +++ /dev/null @@ -1,627 +0,0 @@ -package com.tommytony.war.mappers; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.logging.Level; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.BlockFace; -import org.bukkit.inventory.ItemStack; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.FlagReturn; -import com.tommytony.war.Monument; -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.TeamSpawnStyle; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.config.WarzoneConfig; -import com.tommytony.war.volumes.Volume; -import com.tommytony.war.volumes.ZoneVolume; - -/** - * - * @author tommytony - * - */ -public class WarzoneTxtMapper { - - public static Warzone load(String name, boolean createNewVolume) { - // war.getLogger().info("Loading warzone " + name + " config and blocks..."); - PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt"); - try { - warzoneConfig.load(); - } catch (IOException e) { - War.war.getLogger().info("Failed to load warzone-" + name + ".txt file."); - e.printStackTrace(); - } - - // world - String worldStr = warzoneConfig.getProperty("world"); - World world = null; - if (worldStr == null || worldStr.equals("")) { - world = War.war.getServer().getWorlds().get(0); // default to first world - } else { - world = War.war.getServer().getWorld(worldStr); - } - - if (world == null) { - War.war.log("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!", Level.WARNING); - } else { - // Create the zone - Warzone warzone = new Warzone(world, name); - - // Create file if needed - if (!warzoneConfig.containsKey("name")) { - WarzoneTxtMapper.save(warzone, false); - War.war.getLogger().info("Warzone " + name + " config file created."); - try { - warzoneConfig.load(); - } catch (IOException e) { - // war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it."); - e.printStackTrace(); - } - } - - // teleport - String teleportStr = warzoneConfig.getString("teleport"); - if (teleportStr != null && !teleportStr.equals("")) { - String[] teleportSplit = teleportStr.split(","); - int teleX = Integer.parseInt(teleportSplit[0]); - int teleY = Integer.parseInt(teleportSplit[1]); - int teleZ = Integer.parseInt(teleportSplit[2]); - int yaw = Integer.parseInt(teleportSplit[3]); - warzone.setTeleport(new Location(world, teleX, teleY, teleZ, yaw, 0)); - } - - // ff - if (warzoneConfig.containsKey("friendlyFire")) { - warzone.getWarzoneConfig().put(WarzoneConfig.FRIENDLYFIRE, warzoneConfig.getBoolean("friendlyFire")); - } - - // loadout - warzone.getDefaultInventories().getLoadouts().clear(); - - String loadoutStr = warzoneConfig.getString("loadout"); - if (loadoutStr != null && !loadoutStr.equals("")) { - warzone.getDefaultInventories().getLoadouts().put("default", new HashMap()); - LoadoutTxtMapper.fromStringToLoadout(loadoutStr, warzone.getDefaultInventories().getLoadouts().get("default")); - } - - // extraLoadouts - String extraLoadoutStr = warzoneConfig.getString("extraLoadouts"); - String[] extraLoadoutsSplit = extraLoadoutStr.split(","); - - for (String nameStr : extraLoadoutsSplit) { - if (nameStr != null && !nameStr.equals("")) { - warzone.getDefaultInventories().getLoadouts().put(nameStr, new HashMap()); - } - } - - for (String extraName : extraLoadoutsSplit) { - if (extraName != null && !extraName.equals("")) { - String loadoutString = warzoneConfig.getString(extraName + "Loadout"); - HashMap loadout = warzone.getDefaultInventories().getLoadouts().get(extraName); - LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout); - } - } - - // authors - if (warzoneConfig.containsKey("author") && !warzoneConfig.getString("author").equals("")) { - for(String authorStr : warzoneConfig.getString("author").split(",")) { - if (!authorStr.equals("")) { - warzone.addAuthor(authorStr); - } - } - } - - // life pool (always set after teams, so the teams' remaining lives get initialized properly by this setter) - if (warzoneConfig.containsKey("lifePool")) { - warzone.getTeamDefaultConfig().put(TeamConfig.LIFEPOOL, warzoneConfig.getInt("lifePool")); - } - - // monument heal - if (warzoneConfig.containsKey("monumentHeal")) { - warzone.getWarzoneConfig().put(WarzoneConfig.MONUMENTHEAL, warzoneConfig.getInt("monumentHeal")); - } - - // autoAssignOnly - if (warzoneConfig.containsKey("autoAssignOnly")) { - warzone.getWarzoneConfig().put(WarzoneConfig.AUTOASSIGN, warzoneConfig.getBoolean("autoAssignOnly")); - } - - // flagPointsOnly - if (warzoneConfig.containsKey("flagPointsOnly")) { - warzone.getTeamDefaultConfig().put(TeamConfig.FLAGPOINTSONLY, warzoneConfig.getBoolean("flagPointsOnly")); - } - - // flagMustBeHome - if (warzoneConfig.containsKey("flagMustBeHome")) { - warzone.getTeamDefaultConfig().put(TeamConfig.FLAGMUSTBEHOME, warzoneConfig.getBoolean("flagMustBeHome")); - } - - // team cap - if (warzoneConfig.containsKey("teamCap")) { - warzone.getTeamDefaultConfig().put(TeamConfig.TEAMSIZE, warzoneConfig.getInt("teamCap")); - } - - // score cap - if (warzoneConfig.containsKey("scoreCap")) { - warzone.getTeamDefaultConfig().put(TeamConfig.MAXSCORE, warzoneConfig.getInt("scoreCap")); - } - - // respawn timer - if (warzoneConfig.containsKey("respawnTimer")) { - warzone.getTeamDefaultConfig().put(TeamConfig.RESPAWNTIMER, warzoneConfig.getInt("respawnTimer")); - } - - // blockHeads - if (warzoneConfig.containsKey("blockHeads")) { - warzone.getWarzoneConfig().put(WarzoneConfig.BLOCKHEADS, warzoneConfig.getBoolean("blockHeads")); - } - - // spawnStyle - String spawnStyle = warzoneConfig.getString("spawnStyle"); - if (spawnStyle != null && !spawnStyle.equals("")) { - warzone.getTeamDefaultConfig().put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.getStyleFromString(spawnStyle)); - } - - // flagReturn - String flagReturn = warzoneConfig.getString("flagReturn"); - if (flagReturn != null && !flagReturn.equals("")) { - warzone.getTeamDefaultConfig().put(TeamConfig.FLAGRETURN, FlagReturn.getFromString(flagReturn)); - } - - // reward - String rewardStr = warzoneConfig.getString("reward"); - if (rewardStr != null && !rewardStr.equals("")) { - HashMap reward = new HashMap(); - LoadoutTxtMapper.fromStringToLoadout(rewardStr, reward); - warzone.getDefaultInventories().setReward(reward); - } - - // unbreakableZoneBlocks - if (warzoneConfig.containsKey("unbreakableZoneBlocks")) { - warzone.getWarzoneConfig().put(WarzoneConfig.UNBREAKABLE, warzoneConfig.getBoolean("unbreakableZoneBlocks")); - } - - // disabled - if (warzoneConfig.containsKey("disabled")) { - warzone.getWarzoneConfig().put(WarzoneConfig.DISABLED, warzoneConfig.getBoolean("disabled")); - } - - // noCreatures - if (warzoneConfig.containsKey("noCreatures")) { - warzone.getWarzoneConfig().put(WarzoneConfig.NOCREATURES, warzoneConfig.getBoolean("noCreatures")); - } - - // glassWalls - if (warzoneConfig.containsKey("glassWalls")) { - warzone.getWarzoneConfig().put(WarzoneConfig.GLASSWALLS, warzoneConfig.getBoolean("glassWalls")); - } - - // pvpInZone - if (warzoneConfig.containsKey("pvpInZone")) { - warzone.getWarzoneConfig().put(WarzoneConfig.PVPINZONE, warzoneConfig.getBoolean("pvpInZone")); - } - - // instaBreak - if (warzoneConfig.containsKey("instaBreak")) { - warzone.getWarzoneConfig().put(WarzoneConfig.INSTABREAK, warzoneConfig.getBoolean("instaBreak")); - } - - // noDrops - if (warzoneConfig.containsKey("noDrops")) { - warzone.getWarzoneConfig().put(WarzoneConfig.NODROPS, warzoneConfig.getBoolean("noDrops")); - } - - // noHunger - if (warzoneConfig.containsKey("noHunger")) { - warzone.getTeamDefaultConfig().put(TeamConfig.NOHUNGER, warzoneConfig.getBoolean("noHunger")); - } - - // saturation - if (warzoneConfig.containsKey("saturation")) { - warzone.getTeamDefaultConfig().put(TeamConfig.SATURATION, warzoneConfig.getInt("saturation")); - } - - // minPlayers - if (warzoneConfig.containsKey("minPlayers")) { - warzone.getWarzoneConfig().put(WarzoneConfig.MINPLAYERS, warzoneConfig.getInt("minPlayers")); - } - - // minTeams - if (warzoneConfig.containsKey("minTeams")) { - warzone.getWarzoneConfig().put(WarzoneConfig.MINTEAMS, warzoneConfig.getInt("minTeams")); - } - - // resetOnEmpty - if (warzoneConfig.containsKey("resetOnEmpty")) { - warzone.getWarzoneConfig().put(WarzoneConfig.RESETONEMPTY, warzoneConfig.getBoolean("resetOnEmpty")); - } - - // resetOnLoad - if (warzoneConfig.containsKey("resetOnLoad")) { - warzone.getWarzoneConfig().put(WarzoneConfig.RESETONLOAD, warzoneConfig.getBoolean("resetOnLoad")); - } - - // resetOnUnload - if (warzoneConfig.containsKey("resetOnUnload")) { - warzone.getWarzoneConfig().put(WarzoneConfig.RESETONUNLOAD, warzoneConfig.getBoolean("resetOnUnload")); - } - - // rallyPoint - String rallyPointStr = warzoneConfig.getString("rallyPoint"); - if (rallyPointStr != null && !rallyPointStr.equals("")) { - String[] rallyPointStrSplit = rallyPointStr.split(","); - - int rpX = Integer.parseInt(rallyPointStrSplit[0]); - int rpY = Integer.parseInt(rallyPointStrSplit[1]); - int rpZ = Integer.parseInt(rallyPointStrSplit[2]); - Location rallyPoint = new Location(world, rpX, rpY, rpZ); - warzone.setRallyPoint(rallyPoint); - } - - // monuments - String monumentsStr = warzoneConfig.getString("monuments"); - if (monumentsStr != null && !monumentsStr.equals("")) { - String[] monumentsSplit = monumentsStr.split(";"); - warzone.getMonuments().clear(); - for (String monumentStr : monumentsSplit) { - if (monumentStr != null && !monumentStr.equals("")) { - String[] monumentStrSplit = monumentStr.split(","); - int monumentX = Integer.parseInt(monumentStrSplit[1]); - int monumentY = Integer.parseInt(monumentStrSplit[2]); - int monumentZ = Integer.parseInt(monumentStrSplit[3]); - Monument monument = new Monument(monumentStrSplit[0], warzone, new Location(world, monumentX, monumentY, monumentZ)); - warzone.getMonuments().add(monument); - } - } - } - - // teams - String teamsStr = warzoneConfig.getString("teams"); - if (teamsStr != null && !teamsStr.equals("")) { - String[] teamsSplit = teamsStr.split(";"); - warzone.getTeams().clear(); - for (String teamStr : teamsSplit) { - if (teamStr != null && !teamStr.equals("")) { - String[] teamStrSplit = teamStr.split(","); - int teamX = Integer.parseInt(teamStrSplit[1]); - int teamY = Integer.parseInt(teamStrSplit[2]); - int teamZ = Integer.parseInt(teamStrSplit[3]); - Location teamLocation = new Location(world, teamX, teamY, teamZ); - if (teamStrSplit.length > 4) { - int yaw = Integer.parseInt(teamStrSplit[4]); - teamLocation.setYaw(yaw); - } - Team team = new Team(teamStrSplit[0], TeamKind.teamKindFromString(teamStrSplit[0]), teamLocation, warzone); - team.setRemainingLives(warzone.getTeamDefaultConfig().resolveInt(TeamConfig.LIFEPOOL)); - warzone.getTeams().add(team); - } - } - } - - // teamFlags - String teamFlagsStr = warzoneConfig.getString("teamFlags"); - if (teamFlagsStr != null && !teamFlagsStr.equals("")) { - String[] teamFlagsSplit = teamFlagsStr.split(";"); - for (String teamFlagStr : teamFlagsSplit) { - if (teamFlagStr != null && !teamFlagStr.equals("")) { - String[] teamFlagStrSplit = teamFlagStr.split(","); - Team team = warzone.getTeamByKind(TeamKind.teamKindFromString(teamFlagStrSplit[0])); - if (team != null) { - int teamFlagX = Integer.parseInt(teamFlagStrSplit[1]); - int teamFlagY = Integer.parseInt(teamFlagStrSplit[2]); - int teamFlagZ = Integer.parseInt(teamFlagStrSplit[3]); - Location teamFlagLocation = new Location(world, teamFlagX, teamFlagY, teamFlagZ); - if (teamFlagStrSplit.length > 4) { - int yaw = Integer.parseInt(teamFlagStrSplit[4]); - teamFlagLocation.setYaw(yaw); - } - team.setTeamFlag(teamFlagLocation); // this may screw things up - } - } - } - } - - // lobby - String lobbyStr = warzoneConfig.getString("lobby"); - - warzoneConfig.close(); - - if (createNewVolume) { - ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), world, warzone); // VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone); - warzone.setVolume(zoneVolume); - } - - // monument blocks - for (Monument monument : warzone.getMonuments()) { - monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world)); - } - - // team spawn blocks - for (Team team : warzone.getTeams()) { - team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), world)); - if (team.getTeamFlag() != null) { - team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world)); - } - } - - // lobby - BlockFace lobbyFace = null; - if (lobbyStr != null && !lobbyStr.equals("")) { - String[] lobbyStrSplit = lobbyStr.split(","); - if (lobbyStrSplit.length > 0) { - // lobby orientation - if (lobbyStrSplit[0].equals("south")) { - lobbyFace = BlockFace.SOUTH; - } else if (lobbyStrSplit[0].equals("east")) { - lobbyFace = BlockFace.EAST; - } else if (lobbyStrSplit[0].equals("north")) { - lobbyFace = BlockFace.NORTH; - } else if (lobbyStrSplit[0].equals("west")) { - lobbyFace = BlockFace.WEST; - } - - // lobby world - World lobbyWorld = world; // by default, warzone world - if (lobbyStrSplit.length > 1) { - World strWorld = War.war.getServer().getWorld(lobbyStrSplit[1]); - if (strWorld != null) { - lobbyWorld = strWorld; - } - } - - // create the lobby - Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld); - ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume); - warzone.setLobby(lobby); - } - } - - return warzone; - } - return null; - } - - public static void save(Warzone warzone, boolean saveAllBlocks) { - - War.war.log("Saving War with WarzoneTxtMapper", Level.SEVERE); -// (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir(); -// PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt"); -// // war.getLogger().info("Saving warzone " + warzone.getName() + "..."); -// -// // name -// warzoneConfig.setString("name", warzone.getName()); -// -// // world -// warzoneConfig.setString("world", warzone.getWorld().getName()); // default for now -// -// // teleport -// String teleportStr = ""; -// Location tele = warzone.getTeleport(); -// if (tele != null) { -// int intYaw = 0; -// if (tele.getYaw() >= 0) { -// intYaw = (int) (tele.getYaw() % 360); -// } else { -// intYaw = (int) (360 + (tele.getYaw() % 360)); -// } -// teleportStr = tele.getBlockX() + "," + tele.getBlockY() + "," + tele.getBlockZ() + "," + intYaw; -// } -// warzoneConfig.setString("teleport", teleportStr); -// -// // teams -// String teamsStr = ""; -// List teams = warzone.getTeams(); -// for (Team team : teams) { -// Location spawn = team.getTeamSpawn(); -// int intYaw = 0; -// if (spawn.getYaw() >= 0) { -// intYaw = (int) (spawn.getYaw() % 360); -// } else { -// intYaw = (int) (360 + (spawn.getYaw() % 360)); -// } -// teamsStr += team.getName() + "," + spawn.getBlockX() + "," + spawn.getBlockY() + "," + spawn.getBlockZ() + "," + intYaw + ";"; -// } -// warzoneConfig.setString("teams", teamsStr); -// -// // team flags -// String teamFlagsStr = "";; -// for (Team team : teams) { -// if (team.getFlagVolume() != null) { -// Location flag = team.getTeamFlag(); -// int intYaw = 0; -// if (flag.getYaw() >= 0) { -// intYaw = (int) (flag.getYaw() % 360); -// } else { -// intYaw = (int) (360 + (flag.getYaw() % 360)); -// } -// teamFlagsStr += team.getName() + "," + flag.getBlockX() + "," + flag.getBlockY() + "," + flag.getBlockZ() + "," + intYaw + ";"; -// } -// } -// warzoneConfig.setString("teamFlags", teamFlagsStr); -// -// // ff -// warzoneConfig.setBoolean("friendlyFire", warzone.getFriendlyFire()); -// -// // loadout -// HashMap items = warzone.getDefaultInventories().getLoadouts().get("default"); -// warzoneConfig.setString("loadout", LoadoutTxtMapper.fromLoadoutToString(items)); -// -// // defaultExtraLoadouts -// String extraLoadoutsStr = ""; -// for (String name : warzone.getDefaultInventories().getLoadouts().keySet()) { -// if (!name.equals("default")) { -// extraLoadoutsStr += name + ","; -// -// HashMap loadout = warzone.getDefaultInventories().getLoadouts().get(name); -// warzoneConfig.setString(name + "Loadout", LoadoutTxtMapper.fromLoadoutToString(loadout)); -// } -// } -// warzoneConfig.setString("extraLoadouts", extraLoadoutsStr); -// -// // authors -// warzoneConfig.setString("author", warzone.getAuthorsString()); -// -// // life pool -// warzoneConfig.setInt("lifePool", warzone.getLifePool()); -// -// // monument heal -// warzoneConfig.setInt("monumentHeal", warzone.getMonumentHeal()); -// -// // autoAssignOnly -// warzoneConfig.setBoolean("autoAssignOnly", warzone.isAutoAssignOnly()); -// -// // flagPointsOnly -// warzoneConfig.setBoolean("flagPointsOnly", warzone.isFlagPointsOnly()); -// -// // flagMustBeHome -// warzoneConfig.setBoolean("flagMustBeHome", warzone.isFlagMustBeHome()); -// -// // team cap -// warzoneConfig.setInt("teamCap", warzone.getTeamCap()); -// -// // score cap -// warzoneConfig.setInt("scoreCap", warzone.getScoreCap()); -// -// // respawn timer -// warzoneConfig.setInt("respawnTimer", warzone.getRespawnTimer()); -// -// // blockHeads -// warzoneConfig.setBoolean("blockHeads", warzone.isBlockHeads()); -// -// // spawnStyle -// warzoneConfig.setString("spawnStyle", warzone.getSpawnStyle().toString()); -// -// // flagReturn -// warzoneConfig.setString("flagReturn", warzone.getFlagReturn().toString()); -// -// // reward -// HashMap rewardItems = warzone.getDefaultInventories().getReward(); -// warzoneConfig.setString("reward", LoadoutTxtMapper.fromLoadoutToString(rewardItems)); -// -// // unbreakableZoneBlocks -// warzoneConfig.setBoolean("unbreakableZoneBlocks", warzone.isUnbreakableZoneBlocks()); -// -// // disabled -// warzoneConfig.setBoolean("disabled", warzone.isDisabled()); -// -// // noCreatures -// warzoneConfig.setBoolean("noCreatures", warzone.isNoCreatures()); -// -// // glassWalls -// warzoneConfig.setBoolean("glassWalls", warzone.isGlassWalls()); -// -// // pvpInZone -// warzoneConfig.setBoolean("pvpInZone", warzone.isPvpInZone()); -// -// // instaBreak -// warzoneConfig.setBoolean("instaBreak", warzone.isInstaBreak()); -// -// // noDrops -// warzoneConfig.setBoolean("noDrops", warzone.isNoDrops()); -// -// // noHunger -// warzoneConfig.setBoolean("noHunger", warzone.isNoHunger()); -// -// // saturation -// warzoneConfig.setInt("saturation", warzone.getSaturation()); -// -// // minPlayers -// warzoneConfig.setInt("minPlayers", warzone.getMinPlayers()); -// -// // minTeams -// warzoneConfig.setInt("minTeams", warzone.getMinTeams()); -// -// // resetOnEmpty -// warzoneConfig.setBoolean("resetOnEmpty", warzone.isResetOnEmpty()); -// -// // resetOnLoad -// warzoneConfig.setBoolean("resetOnLoad", warzone.isResetOnLoad()); -// -// // resetOnUnload -// warzoneConfig.setBoolean("resetOnUnload", warzone.isResetOnUnload()); -// -// // rallyPoint -// String rpStr = ""; -// Location rp = warzone.getRallyPoint(); -// if (rp != null) { -// rpStr = rp.getBlockX() + "," + rp.getBlockY() + "," + rp.getBlockZ(); -// } -// warzoneConfig.setString("rallyPoint", rpStr); -// -// // defaultDropLootOnDeath -// // warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath()); -// -// // monuments -// String monumentsStr = ""; -// List monuments = warzone.getMonuments(); -// for (Monument monument : monuments) { -// Location monumentLoc = monument.getLocation(); -// monumentsStr += monument.getName() + "," + monumentLoc.getBlockX() + "," + monumentLoc.getBlockY() + "," + monumentLoc.getBlockZ() + ";"; -// } -// warzoneConfig.setString("monuments", monumentsStr); -// -// // lobby -// String lobbyStr = ""; -// if (warzone.getLobby() != null) { -// if (BlockFace.SOUTH == warzone.getLobby().getWall()) { -// lobbyStr = "south"; -// } else if (BlockFace.EAST == warzone.getLobby().getWall()) { -// lobbyStr = "east"; -// } else if (BlockFace.NORTH == warzone.getLobby().getWall()) { -// lobbyStr = "north"; -// } else if (BlockFace.WEST == warzone.getLobby().getWall()) { -// lobbyStr = "west"; -// } -// } -// warzoneConfig.setString("lobby", lobbyStr + "," + warzone.getLobby().getVolume().getWorld().getName()); -// -// warzoneConfig.save(); -// warzoneConfig.close(); -// -// // monument blocks -// for (Monument monument : monuments) { -// VolumeMapper.save(monument.getVolume(), warzone.getName()); -// } -// -// // team spawn & flag blocks -// for (Team team : teams) { -// VolumeMapper.save(team.getSpawnVolume(), warzone.getName()); -// if (team.getFlagVolume() != null) { -// VolumeMapper.save(team.getFlagVolume(), warzone.getName()); -// } -// } -// -// if (warzone.getLobby() != null) { -// VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName()); -// } - } - - public static void delete(String name) { - File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name); - File[] files = zoneFolder.listFiles(); - for (File file : files) { - boolean deletedData = file.delete(); - if (!deletedData) { - War.war.log("Failed to delete file " + file.getName(), Level.WARNING); - } - } - boolean deletedData = zoneFolder.delete(); - if (!deletedData) { - War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING); - } - File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt"); - deletedData = zoneFile.delete(); - if (!deletedData) { - War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING); - } - } -} diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneYmlMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneYmlMapper.java deleted file mode 100644 index bdfb7b3..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneYmlMapper.java +++ /dev/null @@ -1,527 +0,0 @@ -package com.tommytony.war.mappers; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.logging.Level; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.BlockFace; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.inventory.ItemStack; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.Bomb; -import com.tommytony.war.Cake; -import com.tommytony.war.Monument; -import com.tommytony.war.Team; -import com.tommytony.war.TeamKind; -import com.tommytony.war.Warzone; -import com.tommytony.war.ZoneLobby; -import com.tommytony.war.config.TeamConfig; -import com.tommytony.war.volumes.Volume; -import com.tommytony.war.volumes.ZoneVolume; - -public class WarzoneYmlMapper { - - public static Warzone load(String name, boolean createNewVolume) { - File warzoneTxtFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt"); - File warzoneYmlFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml"); - - // Convert from TXT to YML if needed - if (warzoneTxtFile.exists() && !warzoneYmlFile.exists()) { - // Since we're converting, WarTxtMapper didn't load the warzones. - // We need to load the old-text-format-Warzone into memory. - Warzone zoneToConvert = WarzoneTxtMapper.load(name, false); - WarzoneYmlMapper.save(zoneToConvert, false); - War.war.log("Converted warzone-" + name + ".txt to warzone-" + name + ".yml", Level.INFO); - } - - if (!warzoneYmlFile.exists()) { - War.war.log("File warzone-" + name + ".yml not found", Level.WARNING); - } else { - YamlConfiguration warzoneYmlConfig = YamlConfiguration.loadConfiguration(warzoneYmlFile); - ConfigurationSection warzoneRootSection = warzoneYmlConfig.getConfigurationSection("set"); - - String zoneInfoPrefix = "warzone." + name + ".info."; - - // world - String worldStr = warzoneRootSection.getString(zoneInfoPrefix + "world"); - World world = War.war.getServer().getWorld(worldStr); - - // Create the zone - Warzone warzone = new Warzone(world, name); - - // teleport - int teleX = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.x"); - int teleY = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.y"); - int teleZ = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.z"); - int teleYaw = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.yaw"); - warzone.setTeleport(new Location(world, teleX, teleY, teleZ, teleYaw, 0)); - - // defaultLoadouts - if (warzoneRootSection.contains("team.default.loadout")) { - ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection("team.default.loadout"); - LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, warzone.getDefaultInventories().getLoadouts()); - } - - // defaultReward - if (warzoneRootSection.contains("team.default.reward")) { - ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection("team.default.reward"); - HashMap reward = new HashMap(); - LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default"); - warzone.getDefaultInventories().setReward(reward); - } - - // Team default settings - if (warzoneRootSection.contains("team.default.config")) { - ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection("team.default.config"); - warzone.getTeamDefaultConfig().loadFrom(teamConfigSection); - } - - // Warzone settings - if (warzoneRootSection.contains("warzone." + warzone.getName() + ".config")) { - ConfigurationSection warzoneConfigSection = warzoneRootSection.getConfigurationSection("warzone." + warzone.getName() + ".config"); - warzone.getWarzoneConfig().loadFrom(warzoneConfigSection); - } - - // authors - if (warzoneRootSection.contains(zoneInfoPrefix + "authors")) { - for(String authorStr : warzoneRootSection.getStringList(zoneInfoPrefix + "authors")) { - if (!authorStr.equals("")) { - warzone.addAuthor(authorStr); - } - } - } - - // rallyPoint - if (warzoneRootSection.contains(zoneInfoPrefix + "rallypoint")) { - int rpX = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.x"); - int rpY = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.y"); - int rpZ = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.z"); - int rpYaw = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.yaw"); - Location rallyPoint = new Location(world, rpX, rpY, rpZ, rpYaw, 0); - warzone.setRallyPoint(rallyPoint); - } - - // monuments - if (warzoneRootSection.contains(zoneInfoPrefix + "monument")) { - List monunmentNames = warzoneRootSection.getStringList(zoneInfoPrefix + "monument.names"); - for (String monumentName : monunmentNames) { - if (monumentName != null && !monumentName.equals("")) { - String monumentPrefix = zoneInfoPrefix + "monument." + monumentName + "."; - int monumentX = warzoneRootSection.getInt(monumentPrefix + "x"); - int monumentY = warzoneRootSection.getInt(monumentPrefix + "y"); - int monumentZ = warzoneRootSection.getInt(monumentPrefix + "z"); - int monumentYaw = warzoneRootSection.getInt(monumentPrefix + "yaw"); - Monument monument = new Monument(monumentName, warzone, new Location(world, monumentX, monumentY, monumentZ, monumentYaw, 0)); - warzone.getMonuments().add(monument); - } - } - } - - // bombs - if (warzoneRootSection.contains(zoneInfoPrefix + "bomb")) { - List bombNames = warzoneRootSection.getStringList(zoneInfoPrefix + "bomb.names"); - for (String bombName : bombNames) { - if (bombName != null && !bombName.equals("")) { - String bombPrefix = zoneInfoPrefix + "bomb." + bombName + "."; - int bombX = warzoneRootSection.getInt(bombPrefix + "x"); - int bombY = warzoneRootSection.getInt(bombPrefix + "y"); - int bombZ = warzoneRootSection.getInt(bombPrefix + "z"); - int bombYaw = warzoneRootSection.getInt(bombPrefix + "yaw"); - Bomb bomb = new Bomb(bombName, warzone, new Location(world, bombX, bombY, bombZ, bombYaw, 0)); - warzone.getBombs().add(bomb); - } - } - } - - // cakes - if (warzoneRootSection.contains(zoneInfoPrefix + "cake")) { - List cakeNames = warzoneRootSection.getStringList(zoneInfoPrefix + "cake.names"); - for (String cakeName : cakeNames) { - if (cakeName != null && !cakeName.equals("")) { - String cakePrefix = zoneInfoPrefix + "cake." + cakeName + "."; - int cakeX = warzoneRootSection.getInt(cakePrefix + "x"); - int cakeY = warzoneRootSection.getInt(cakePrefix + "y"); - int cakeZ = warzoneRootSection.getInt(cakePrefix + "z"); - int cakeYaw = warzoneRootSection.getInt(cakePrefix + "yaw"); - Cake cake = new Cake(cakeName, warzone, new Location(world, cakeX, cakeY, cakeZ, cakeYaw, 0)); - warzone.getCakes().add(cake); - } - } - } - - // teams (maybe no teams) - if (warzoneRootSection.contains("team.names")) { - List teamsNames = warzoneRootSection.getStringList("team.names"); - for (String teamName : teamsNames) { - // team info - String teamInfoPrefix = "team." + teamName + ".info."; - int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x"); - int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y"); - int teamZ = warzoneRootSection.getInt(teamInfoPrefix + "spawn.z"); - int teamYaw = warzoneRootSection.getInt(teamInfoPrefix + "spawn.yaw"); - Location teamLocation = new Location(world, teamX, teamY, teamZ, teamYaw, 0); - - Team team = new Team(teamName, TeamKind.teamKindFromString(teamName), teamLocation, warzone); - warzone.getTeams().add(team); - - if (warzoneRootSection.contains(teamInfoPrefix + "flag")) { - int flagX = warzoneRootSection.getInt(teamInfoPrefix + "flag.x"); - int flagY = warzoneRootSection.getInt(teamInfoPrefix + "flag.y"); - int flagZ = warzoneRootSection.getInt(teamInfoPrefix + "flag.z"); - int flagYaw = warzoneRootSection.getInt(teamInfoPrefix + "flag.yaw"); - Location flagLocation = new Location(world, flagX, flagY, flagZ, flagYaw, 0); - team.setTeamFlag(flagLocation); - } - - String teamConfigPrefix = "team." + teamName + ".config"; - if (warzoneRootSection.contains(teamConfigPrefix)) { - // team specific config - ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection(teamConfigPrefix); - team.getTeamConfig().loadFrom(teamConfigSection); - } - - team.setRemainingLives(team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL)); - - String teamLoadoutPrefix = "team." + teamName + ".loadout"; - if (warzoneRootSection.contains(teamLoadoutPrefix)) { - // team specific loadouts - ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix); - LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, team.getInventories().getLoadouts()); - } - - String teamRewardPrefix = "team." + teamName + ".reward"; - if (warzoneRootSection.contains(teamRewardPrefix)) { - // team specific reward - ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection(teamRewardPrefix); - HashMap reward = new HashMap(); - LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default"); - warzone.getDefaultInventories().setReward(reward); - } - } - } - - if (createNewVolume) { - ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), world, warzone); - warzone.setVolume(zoneVolume); - } - - // monument blocks - for (Monument monument : warzone.getMonuments()) { - monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world)); - } - - // bomb blocks - for (Bomb bomb : warzone.getBombs()) { - bomb.setVolume(VolumeMapper.loadVolume("bomb-" + bomb.getName(), warzone.getName(), world)); - } - - // cake blocks - for (Cake cake : warzone.getCakes()) { - cake.setVolume(VolumeMapper.loadVolume("cake-" + cake.getName(), warzone.getName(), world)); - } - - // team spawn blocks - for (Team team : warzone.getTeams()) { - team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), world)); - if (team.getTeamFlag() != null) { - team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world)); - } - } - - // lobby - String lobbyPrefix = zoneInfoPrefix + "lobby."; - - // lobby orientation - String lobbyOrientation = warzoneRootSection.getString(lobbyPrefix + "orientation"); - BlockFace lobbyFace = null; - if (lobbyOrientation.equals("south")) { - lobbyFace = BlockFace.SOUTH; - } else if (lobbyOrientation.equals("east")) { - lobbyFace = BlockFace.EAST; - } else if (lobbyOrientation.equals("north")) { - lobbyFace = BlockFace.NORTH; - } else if (lobbyOrientation.equals("west")) { - lobbyFace = BlockFace.WEST; - } - - // lobby world - String lobbyWorldName = warzoneRootSection.getString(lobbyPrefix + "world"); - World lobbyWorld = War.war.getServer().getWorld(lobbyWorldName); - - // create the lobby - Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld); - ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume); - warzone.setLobby(lobby); - - return warzone; - } - - return null; - } - - public static void save(Warzone warzone, boolean saveAllBlocks) { - YamlConfiguration warzoneYmlConfig = new YamlConfiguration(); - ConfigurationSection warzoneRootSection = warzoneYmlConfig.createSection("set"); - (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir(); // create folder - - ConfigurationSection warzoneSection = warzoneRootSection.createSection("warzone." + warzone.getName()); - - // Warzone settings - if (!warzone.getWarzoneConfig().isEmpty()) { - ConfigurationSection warzoneConfigSection = warzoneSection.createSection("config"); - warzone.getWarzoneConfig().saveTo(warzoneConfigSection); - } - - ConfigurationSection warzoneInfoSection = warzoneSection.createSection("info"); - - // authors - warzoneInfoSection.set("authors", warzone.getAuthors()); - - // teleport - ConfigurationSection teleSection = warzoneInfoSection.createSection("teleport"); - teleSection.set("x", warzone.getTeleport().getBlockX()); - teleSection.set("y", warzone.getTeleport().getBlockY()); - teleSection.set("z", warzone.getTeleport().getBlockZ()); - teleSection.set("yaw", toIntYaw(warzone.getTeleport().getYaw())); - - // world - warzoneInfoSection.set("world", warzone.getWorld().getName()); - - // lobby - if (warzone.getLobby() != null) { - String lobbyOrientation = ""; - if (BlockFace.SOUTH == warzone.getLobby().getWall()) { - lobbyOrientation = "south"; - } else if (BlockFace.EAST == warzone.getLobby().getWall()) { - lobbyOrientation = "east"; - } else if (BlockFace.NORTH == warzone.getLobby().getWall()) { - lobbyOrientation = "north"; - } else if (BlockFace.WEST == warzone.getLobby().getWall()) { - lobbyOrientation = "west"; - } - - ConfigurationSection lobbySection = warzoneInfoSection.createSection("lobby"); - lobbySection.set("orientation", lobbyOrientation); - lobbySection.set("world", warzone.getLobby().getVolume().getWorld().getName()); - } - - // rallyPoint - if (warzone.getRallyPoint() != null) { - ConfigurationSection rpSection = warzoneInfoSection.createSection("rallypoint"); - rpSection.set("x", warzone.getRallyPoint().getBlockX()); - rpSection.set("y", warzone.getRallyPoint().getBlockY()); - rpSection.set("z", warzone.getRallyPoint().getBlockZ()); - rpSection.set("yaw", toIntYaw(warzone.getRallyPoint().getYaw())); - } - - // monuments - if (warzone.getMonuments().size() > 0) { - ConfigurationSection monumentsSection = warzoneInfoSection.createSection("monument"); - - List monumentNames = new ArrayList(); - for (Monument monument : warzone.getMonuments()) { - monumentNames.add(monument.getName()); - } - monumentsSection.set("names", monumentNames); - - for (Monument monument : warzone.getMonuments()) { - - ConfigurationSection monumentSection = monumentsSection.createSection(monument.getName()); - monumentSection.set("x", monument.getLocation().getBlockX()); - monumentSection.set("y", monument.getLocation().getBlockY()); - monumentSection.set("z", monument.getLocation().getBlockZ()); - monumentSection.set("yaw", toIntYaw(monument.getLocation().getYaw())); - } - } - - // bombs - if (warzone.getBombs().size() > 0) { - ConfigurationSection bombsSection = warzoneInfoSection.createSection("bomb"); - - List bombNames = new ArrayList(); - for (Bomb bomb : warzone.getBombs()) { - bombNames.add(bomb.getName()); - } - bombsSection.set("names", bombNames); - - for (Bomb bomb : warzone.getBombs()) { - - ConfigurationSection bombSection = bombsSection.createSection(bomb.getName()); - bombSection.set("x", bomb.getLocation().getBlockX()); - bombSection.set("y", bomb.getLocation().getBlockY()); - bombSection.set("z", bomb.getLocation().getBlockZ()); - bombSection.set("yaw", toIntYaw(bomb.getLocation().getYaw())); - } - } - - // cakes - if (warzone.getCakes().size() > 0) { - ConfigurationSection cakesSection = warzoneInfoSection.createSection("cake"); - - List cakeNames = new ArrayList(); - for (Cake cake : warzone.getCakes()) { - cakeNames.add(cake.getName()); - } - cakesSection.set("names", cakeNames); - - for (Cake cake : warzone.getCakes()) { - - ConfigurationSection cakeSection = cakesSection.createSection(cake.getName()); - cakeSection.set("x", cake.getLocation().getBlockX()); - cakeSection.set("y", cake.getLocation().getBlockY()); - cakeSection.set("z", cake.getLocation().getBlockZ()); - cakeSection.set("yaw", toIntYaw(cake.getLocation().getYaw())); - } - } - - ConfigurationSection teamsSection = warzoneRootSection.createSection("team"); - - // teams - List teams = warzone.getTeams(); - - List teamNames = new ArrayList(); - for (Team team : teams) { - teamNames.add(team.getName()); - } - if (teamNames.size() > 0) { - teamsSection.set("names", teamNames); - } - - // Team default settings - if (!warzone.getTeamDefaultConfig().isEmpty()) { - ConfigurationSection teamConfigSection = teamsSection.createSection("default.config"); - warzone.getTeamDefaultConfig().saveTo(teamConfigSection); - } - - // defaultLoadouts - if (warzone.getDefaultInventories().hasLoadouts()) { - ConfigurationSection loadoutsSection = teamsSection.createSection("default.loadout"); - LoadoutYmlMapper.fromLoadoutsToConfig(warzone.getDefaultInventories().getLoadouts(), loadoutsSection); - } - - // defaultReward - if (warzone.getDefaultInventories().hasReward()) { - ConfigurationSection rewardsSection = teamsSection.createSection("default.reward"); - LoadoutYmlMapper.fromLoadoutToConfig("default", warzone.getDefaultInventories().getReward(), rewardsSection); - } - - for (Team team : teams) { - if (!team.getTeamConfig().isEmpty()) { - // team specific config - ConfigurationSection teamConfigSection = teamsSection.createSection(team.getName() + ".config"); - team.getTeamConfig().saveTo(teamConfigSection); - } - - if (team.getInventories().hasLoadouts()) { - // team specific loadouts - ConfigurationSection loadoutsSection = teamsSection.createSection(team.getName() + ".loadout"); - LoadoutYmlMapper.fromLoadoutsToConfig(team.getInventories().getLoadouts(), loadoutsSection); - } - - if (team.getInventories().hasReward()) { - // team specific reward - ConfigurationSection rewardsSection = teamsSection.createSection(team.getName() + ".reward"); - LoadoutYmlMapper.fromLoadoutToConfig("default", team.getInventories().getReward(), rewardsSection); - } - - ConfigurationSection teamInfoSection = teamsSection.createSection(team.getName() + ".info"); - - ConfigurationSection spawnSection = teamInfoSection.createSection("spawn"); - Location spawn = team.getTeamSpawn(); - spawnSection.set("x", spawn.getBlockX()); - spawnSection.set("y", spawn.getBlockY()); - spawnSection.set("z", spawn.getBlockZ()); - spawnSection.set("yaw", toIntYaw(spawn.getYaw())); - - if (team.getTeamFlag() != null) { - ConfigurationSection flagSection = teamInfoSection.createSection("flag"); - Location teamFlag = team.getTeamFlag(); - flagSection.set("x", teamFlag.getBlockX()); - flagSection.set("y", teamFlag.getBlockY()); - flagSection.set("z", teamFlag.getBlockZ()); - flagSection.set("yaw", toIntYaw(teamFlag.getYaw())); - } - } - - // monument blocks - for (Monument monument : warzone.getMonuments()) { - VolumeMapper.save(monument.getVolume(), warzone.getName()); - } - - // bomb blocks - for (Bomb bomb : warzone.getBombs()) { - VolumeMapper.save(bomb.getVolume(), warzone.getName()); - } - - // cake blocks - for (Cake cake : warzone.getCakes()) { - VolumeMapper.save(cake.getVolume(), warzone.getName()); - } - - // team spawn & flag blocks - for (Team team : teams) { - VolumeMapper.save(team.getSpawnVolume(), warzone.getName()); - if (team.getFlagVolume() != null) { - VolumeMapper.save(team.getFlagVolume(), warzone.getName()); - } - } - - if (warzone.getLobby() != null) { - VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName()); - } - - // Save to disk - try { - File warzoneConfigFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".yml"); - warzoneYmlConfig.save(warzoneConfigFile); - } catch (IOException e) { - War.war.log("Failed to save warzone-" + warzone.getName() + ".yml", Level.WARNING); - e.printStackTrace(); - } - } - - private static int toIntYaw(float yaw) { - int intYaw = 0; - if (yaw >= 0) { - intYaw = (int) (yaw % 360); - } else { - intYaw = (int) (360 + (yaw % 360)); - } - return intYaw; - } - - public static void delete(String name) { - File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name); - File[] files = zoneFolder.listFiles(); - for (File file : files) { - boolean deletedData = file.delete(); - if (!deletedData) { - War.war.log("Failed to delete file " + file.getName(), Level.WARNING); - } - } - boolean deletedData = zoneFolder.delete(); - if (!deletedData) { - War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING); - } - File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt"); - if (zoneFile.exists()) { - deletedData = zoneFile.delete(); - if (!deletedData) { - War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING); - } - } - zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml"); - deletedData = zoneFile.delete(); - if (!deletedData) { - War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING); - } - } -} diff --git a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java deleted file mode 100644 index 03de131..0000000 --- a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java +++ /dev/null @@ -1,443 +0,0 @@ -package com.tommytony.war.mappers; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.List; -import java.util.logging.Level; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Chest; -import org.bukkit.block.Dispenser; -import org.bukkit.block.Sign; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.jobs.DeferredBlockResetsJob; -import com.tommytony.war.jobs.ZoneVolumeSaveJob; -import com.tommytony.war.utils.DeferredBlockReset; -import com.tommytony.war.volumes.Volume; -import com.tommytony.war.volumes.ZoneVolume; - -/** - * The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes. - * - * @author tommytony, Tim Düsterhus - * @package com.tommytony.war.mappers - */ -public class ZoneVolumeMapper { - - /** - * Loads the given volume - * - * @param ZoneVolume - * volume Volume to load - * @param String - * zoneName Zone to load the volume from - * @param World - * world The world the zone is located - * @param boolean onlyLoadCorners Should only the corners be loaded - * @return integer Changed blocks - */ - public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) { - File cornersFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners"); - File blocksFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks"); - File signsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".signs"); - File invsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".invs"); - int noOfResetBlocks = 0; - if (!blocksFile.exists()) { - // The post 1.6 formatted files haven't been created yet so - // we need to use the old load. - noOfResetBlocks = PreDeGaulleZoneVolumeMapper.load(volume, zoneName, world, onlyLoadCorners); - - // The new 1.6 files aren't created yet. We just reset the zone (except deferred blocks which will soon execute on main thread ), - // so let's save to the new format as soon as the zone is fully reset. - ZoneVolumeMapper.saveAsJob(volume, zoneName, 2); - War.war.log("Warzone " + zoneName + " file converted!", Level.INFO); - - return noOfResetBlocks; - } else { - // 1.6 file exist, so go ahead with reset - BufferedReader cornersReader = null; - FileInputStream blocksStream = null; - BufferedReader signsReader = null; - BufferedReader invsReader = null; - try { - cornersReader = new BufferedReader(new FileReader(cornersFile)); - blocksStream = new FileInputStream(blocksFile); - signsReader = new BufferedReader(new FileReader(signsFile)); - invsReader = new BufferedReader(new FileReader(invsFile)); - - // Get the corners - cornersReader.readLine(); - int x1 = Integer.parseInt(cornersReader.readLine()); - int y1 = Integer.parseInt(cornersReader.readLine()); - int z1 = Integer.parseInt(cornersReader.readLine()); - cornersReader.readLine(); - int x2 = Integer.parseInt(cornersReader.readLine()); - int y2 = Integer.parseInt(cornersReader.readLine()); - int z2 = Integer.parseInt(cornersReader.readLine()); - - volume.setCornerOne(world.getBlockAt(x1, y1, z1)); - volume.setCornerTwo(world.getBlockAt(x2, y2, z2)); - - // Allocate block byte arrays - int noOfBlocks = volume.getSizeX() * volume.getSizeY() * volume.getSizeZ(); - byte[] blockBytes = new byte[noOfBlocks * 2]; // one byte for type, one for data - - blocksStream.read(blockBytes); // read it all - - // Now use the block bytes to reset the world blocks - if (!onlyLoadCorners) { - DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world); - int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0; - int diskBlockType; - byte diskBlockData; - Block worldBlock; - int worldBlockId; - volume.clearBlocksThatDontFloat(); - x = volume.getMinX(); - for (i = 0; i < volume.getSizeX(); i++) { - y = volume.getMinY(); - for (j = 0; j < volume.getSizeY(); j++) { - z = volume.getMinZ(); - for (k = 0; k < volume.getSizeZ(); k++) { - try { - diskBlockType = blockBytes[visitedBlocks * 2]; - diskBlockData = blockBytes[visitedBlocks * 2 + 1]; - - worldBlock = volume.getWorld().getBlockAt(x, y, z); - worldBlockId = worldBlock.getTypeId(); - if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) { - if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) { - // Signs read - String linesStr = signsReader.readLine(); - String[] lines = linesStr.split(";;"); - - // Signs set - if (diskBlockType == Material.WALL_SIGN.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) { - // A sign post hanging on a wall south of here needs that block to be set first - deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines)); - } else { - worldBlock.setType(Material.getMaterial(diskBlockType)); - BlockState state = worldBlock.getState(); - state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData)); - if (state instanceof Sign) { - Sign sign = (Sign) state; - if (lines != null && sign.getLines() != null) { - if (lines.length > 0) { - sign.setLine(0, lines[0]); - } - if (lines.length > 1) { - sign.setLine(1, lines[1]); - } - if (lines.length > 2) { - sign.setLine(2, lines[2]); - } - if (lines.length > 3) { - sign.setLine(3, lines[3]); - } - sign.update(true); - } - } - } - } else if (diskBlockType == Material.CHEST.getId()) { - // Chests read - List items = VolumeMapper.readInventoryString(invsReader.readLine()); - - // Chests set - worldBlock.setType(Material.getMaterial(diskBlockType)); - worldBlock.setData(diskBlockData); - BlockState state = worldBlock.getState(); - if (state instanceof Chest) { - Chest chest = (Chest) state; - if (items != null) { - int ii = 0; - chest.getInventory().clear(); - for (ItemStack item : items) { - if (item != null) { - chest.getInventory().setItem(ii, item); - ii++; - } - } - chest.update(true); - } - } - } else if (diskBlockType == Material.DISPENSER.getId()) { - // Dispensers read - List items = VolumeMapper.readInventoryString(invsReader.readLine()); - - // Dispensers set - worldBlock.setType(Material.getMaterial(diskBlockType)); - worldBlock.setData(diskBlockData); - BlockState state = worldBlock.getState(); - if (state instanceof Dispenser) { - Dispenser dispenser = (Dispenser) state; - if (items != null) { - int ii = 0; - dispenser.getInventory().clear(); - for (ItemStack item : items) { - if (item != null) { - dispenser.getInventory().setItem(ii, item); - ii++; - } - } - dispenser.update(true); - } - } - } else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) { - // Door blocks - deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData)); - } else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) { - // Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol - // Change the block itself later on: - deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData)); - } else { - // regular block - worldBlock.setType(Material.getMaterial(diskBlockType)); - worldBlock.setData(diskBlockData); - } - noOfResetBlocks++; - } - visitedBlocks++; - - blockReads++; - - } catch (Exception e) { - War.war.getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); - e.printStackTrace(); - } finally { - z++; - } - } - y++; - } - x++; - } - if (!deferred.isEmpty()) { - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 2); - } - } - } catch (FileNotFoundException e) { - War.war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } catch (IOException e) { - War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } finally { - try { - if (cornersReader != null) { - cornersReader.close(); - } - if (blocksStream != null) { - blocksStream.close(); - } - if (signsReader != null) { - signsReader.close(); - } - if (invsReader != null) { - invsReader.close(); - } - } catch (IOException e) { - War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - } - return noOfResetBlocks; - } - } - - /** - * Saves the given volume - * - * @param Volume - * volume Volume to save - * @param String - * zoneName The warzone the volume is located - * @return integer Number of written blocks - */ - public static int save(Volume volume, String zoneName) { - int noOfSavedBlocks = 0; - if (volume.hasTwoCorners()) { - BufferedWriter cornersWriter = null; - FileOutputStream blocksOutput = null; - BufferedWriter signsWriter = null; - BufferedWriter invsWriter = null; - try { - (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir(); - String path = War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName(); - cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners"))); - blocksOutput = new FileOutputStream(new File(path + ".blocks")); - signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs"))); - invsWriter = new BufferedWriter(new FileWriter(new File(path + ".invs"))); - - cornersWriter.write("corner1"); - cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerOne().getX())); - cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerOne().getY())); - cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerOne().getZ())); - cornersWriter.newLine(); - cornersWriter.write("corner2"); - cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerTwo().getX())); - cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerTwo().getY())); - cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerTwo().getZ())); - cornersWriter.newLine(); - - int x = 0; - int y = 0; - int z = 0; - Block block; - int typeId; - byte data; - BlockState state; - - x = volume.getMinX(); - for (int i = 0; i < volume.getSizeX(); i++) { - y = volume.getMinY(); - for (int j = 0; j < volume.getSizeY(); j++) { - z = volume.getMinZ(); - for (int k = 0; k < volume.getSizeZ(); k++) { - try { - block = volume.getWorld().getBlockAt(x, y, z); - typeId = block.getTypeId(); - data = block.getData(); - state = block.getState(); - - blocksOutput.write((byte) typeId); - blocksOutput.write(data); - - if (state instanceof Sign) { - // Signs - String extra = ""; - Sign sign = (Sign) state; - if (sign.getLines() != null) { - for (String line : sign.getLines()) { - extra += line + ";;"; - } - signsWriter.write(extra); - signsWriter.newLine(); - } - } else if (state instanceof Chest) { - // Chests - Chest chest = (Chest) state; - Inventory inv = chest.getInventory(); - List items = VolumeMapper.getItemListFromInv(inv); - invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items)); - invsWriter.newLine(); - } else if (state instanceof Dispenser) { - // Dispensers - Dispenser dispenser = (Dispenser) state; - Inventory inv = dispenser.getInventory(); - List items = VolumeMapper.getItemListFromInv(inv); - invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items)); - invsWriter.newLine(); - } - noOfSavedBlocks++; - } catch (Exception e) { - War.war.log("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } finally { - z++; - } - } - y++; - } - x++; - } - } catch (IOException e) { - War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } catch (Exception e) { - War.war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } finally { - try { - if (cornersWriter != null) { - cornersWriter.close(); - } - if (blocksOutput != null) { - blocksOutput.close(); - } - if (signsWriter != null) { - signsWriter.close(); - } - if (invsWriter != null) { - invsWriter.close(); - } - } catch (IOException e) { - War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - } - } - return noOfSavedBlocks; - } - - - - /** - * Saves the Volume as a background-job - * - * @param ZoneVolme - * volume volume to save - * @param String - * zoneName The zone the volume is located - * @param War - * war Instance of war - * @param long tickDelay delay before beginning the task - */ - private static void saveAsJob(ZoneVolume volume, String zoneName, long tickDelay) { - ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, tickDelay); - } - - /** - * Deletes the given volume - * - * @param Volume - * volume volume to delete - * @param War - * war Instance of war - */ - public static void delete(Volume volume) { - ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"); - ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".corners"); - ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".blocks"); - ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".signs"); - ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".invs"); - } - - /** - * Deletes a volume file - * - * @param String - * path path of file - * @param War - * war Instance of war - */ - private static void deleteFile(String path) { - File volFile = new File(path); - if (volFile.exists()) { - boolean deletedData = volFile.delete(); - if (!deletedData) { - War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING); - } - } - } -} diff --git a/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java b/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java deleted file mode 100644 index 361c98c..0000000 --- a/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.tommytony.war.utils; - -import java.util.*; - -import org.bukkit.command.CommandSender; - -/** - * The purpose of this tool is twofold: 1: Avoid client crashes due to bad color formating. 2: Make color continue on word wrapping - * - * In minecraft the degree sign is used as a prefix to another char to create a color. For example the code for white is "\u00A7f". The "\u00A7" is the unicode notation for the degree sign and the "f" means white. - * - * When does minecraft wrap the text? After how many chars? Answer: Because the font isn't monospace this differs depending on what you write. However we can fit 53 "M" without wrapping and the 54th char would then wrap (be at the beginning of the next line instead) As there is no broader char than "M" we can know for sure the minimum line length is 53. Note that this means the number of DISPLAYED chars per row is 53. A degree sign and the char after will NOT count, as they will not be displayed as chars. - * - * Good to know: Numbers have the same font width as an M. - * - * When does the client crash? Answer: When a row ends with a degree char and optionally another sign after. Another way to say the same: When a line ends with either a broken or valid color notation. AND The client will ALWAYS crash if the sign after the last displayed char in a row is a degree char. A goofy way to explatin it: For a line with only "M" and numbers, the fiftyfourth "displayed char" musn't be a degree sign. - * - * WARNING: Above is a hypothesis I have created based on what my experiments have shown. I am fairly sure it is correct but please help me test it further. - */ -public class ChatFixUtil { - public final static char deg = '\u00A7'; - public final static int lineLength = 53; - - /** - * This method wraps the msg for you at row lengths of 53, avoids client crash scenarios and makes the previous color continue on the next line. - * - * The upsides with filtering your messages through this method are: - No client crashes. - Line wrapping with preserved color. - * - * The downsides are: - The width of the chat window will not be used to it's fullest. For example you can fit more that 53 commas (,) in a chatwindow row but the line would break after 53 displayed chars. - * - * Suggested usage: NO NEED TO USE the fix method for static help pages in your plugin. As the text is static you can make sure there is no client crash yourself and be able to use the full line length. - * - * DO USE in cases like where you output colored messages with playernames in your plugin. As the player names have different length there is potential for client crash. - */ - public static ArrayList fix(String msg) { - // Make sure the end of msg is good - msg = ChatFixUtil.cleanMsgEnding(msg); - - ArrayList ret = new ArrayList(); - int displen = 0; // The number of displayed chars in row so far. - String row = ""; - String latestColor = null; - - for (int i = 0; i < msg.length(); i++) { - if (displen == ChatFixUtil.lineLength) { - // it is time to start on the next row! - ret.add(row); - displen = 0; - row = ""; - if (latestColor != null) { - row += ChatFixUtil.deg + latestColor; - } - } - char c = msg.charAt(i); - - if (c == ChatFixUtil.deg) { - latestColor = String.valueOf(msg.charAt(i + 1)); - row += ChatFixUtil.deg + latestColor; - i++; - } else { - displen += 1; - row += c; - } - } - ret.add(row); - return ret; - } - - public static ArrayList fix(List messages) { - ArrayList ret = new ArrayList(); - for (String message : messages) { - ret.addAll(ChatFixUtil.fix(message)); - } - return ret; - } - - /** - * Removes the ending chars as long as they are deg or deg+'anychar' or a space As I see it we would never want those chars at the end of a msg. - */ - protected static String cleanMsgEnding(String msg) { - - while (msg.length() > 0) { - if (msg.endsWith(String.valueOf(ChatFixUtil.deg)) || msg.endsWith(" ")) { - msg = msg.substring(0, msg.length() - 1); - } else if (msg.length() >= 2 && msg.charAt(msg.length() - 2) == ChatFixUtil.deg) { - msg = msg.substring(0, msg.length() - 2); - } else { - break; - } - } - return msg; - } - - /** - * This test util assumes line break after 53 displayed chars. The fix method above breaks like that so this method should be a valid way to test if a message row would crash a client. - */ - public static String thisMsgWouldCrashClient(String str) { - // There would always be crash if we end with deg or deg+'anychar' - if (str.length() >= 1 && str.charAt(str.length() - 1) == ChatFixUtil.deg) { - return "Crash: The str ends with deg."; - } else if (str.length() >= 2 && str.charAt(str.length() - 2) == ChatFixUtil.deg) { - return "Crash: The str ends with deg+'anychar'."; - } - - int displayedChars = 0; - - for (int i = 0; i < str.length(); i++) { - char c = str.charAt(i); - if (c == ChatFixUtil.deg && displayedChars == ChatFixUtil.lineLength) { - return "Crash: Deg as fiftyforth \"displayed\" char"; - } else if (c == ChatFixUtil.deg) { - i++; // this and next: they are not displayed... skip them... - } else { - displayedChars += 1; - } - } - return "all ok"; - } - - // ----------------------------------------------// - // Methods for effectively sending messages - // ----------------------------------------------// - // ----------------------------------------------// - // One player - // ----------------------------------------------// - public static void sendMessage(CommandSender player, String message, boolean fix) { - if (fix) { - List messages = ChatFixUtil.fix(message); - ChatFixUtil.sendMessage(player, messages, false); - } else { - if (player != null) { - player.sendMessage(message); - } - } - } - - public static void sendMessage(CommandSender player, List messages, boolean fix) { - if (fix) { - messages = ChatFixUtil.fix(messages); - } - for (String message : messages) { - ChatFixUtil.sendMessage(player, message, false); - } - } - - public static void sendMessage(CommandSender player, String message) { - ChatFixUtil.sendMessage(player, message, true); - } - - public static void sendMessage(CommandSender player, List messages) { - ChatFixUtil.sendMessage(player, messages, true); - } - - // ----------------------------------------------// - // Many CommandSenders - // ----------------------------------------------// - public static void sendMessage(Collection players, String message, boolean fix) { - if (fix) { - List messages = ChatFixUtil.fix(message); - ChatFixUtil.sendMessage(players, messages, false); - } else { - for (CommandSender player : players) { - ChatFixUtil.sendMessage(player, message, false); - } - } - } - - public static void sendMessage(Collection players, List messages, boolean fix) { - if (fix) { - messages = ChatFixUtil.fix(messages); - } - - for (String message : messages) { - ChatFixUtil.sendMessage(players, message, false); - } - } - - public static void sendMessage(Collection players, String message) { - ChatFixUtil.sendMessage(players, message, true); - } - - public static void sendMessage(Collection players, List messages) { - ChatFixUtil.sendMessage(players, messages, true); - } -} diff --git a/war/src/main/java/com/tommytony/war/utils/DeferredBlockReset.java b/war/src/main/java/com/tommytony/war/utils/DeferredBlockReset.java deleted file mode 100644 index 398a78c..0000000 --- a/war/src/main/java/com/tommytony/war/utils/DeferredBlockReset.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.tommytony.war.utils; - -import java.util.List; - -import org.bukkit.inventory.ItemStack; - -public class DeferredBlockReset { - - private final int x; - private final int y; - private final int z; - private final int blockType; - private final byte blockData; - private String[] lines; - private List items; - private Byte rawNote; - - public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData) { - this.x = x; - this.y = y; - this.z = z; - this.blockType = blockType; - this.blockData = blockData; - } - - // Signs - public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, String[] signLines) { - this.x = x; - this.y = y; - this.z = z; - this.blockType = blockType; - this.blockData = blockData; - this.lines = signLines; - } - - // Container block - public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, List contents) { - this.x = x; - this.y = y; - this.z = z; - this.blockType = blockType; - this.blockData = blockData; - this.items = contents; - } - - // Noteblock - public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, byte rawNote) { - this.x = x; - this.y = y; - this.z = z; - this.blockType = blockType; - this.blockData = blockData; - this.rawNote = rawNote; - } - - public int getX() { - return this.x; - } - - public int getY() { - return this.y; - } - - public int getZ() { - return this.z; - } - - public int getBlockType() { - return this.blockType; - } - - public byte getBlockData() { - return this.blockData; - } - - public String[] getLines() { - return this.lines; - } - - public List getItems() { - return items; - } - - public Byte getRawNote() { - return rawNote; - } -} diff --git a/war/src/main/java/com/tommytony/war/utils/PlayerState.java b/war/src/main/java/com/tommytony/war/utils/PlayerState.java deleted file mode 100644 index 2a9ad7b..0000000 --- a/war/src/main/java/com/tommytony/war/utils/PlayerState.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.tommytony.war.utils; - -import java.util.List; - -import org.bukkit.GameMode; -import org.bukkit.inventory.ItemStack; - -import com.tommytony.war.PotionEffect; - -public class PlayerState { - private ItemStack[] contents; - private ItemStack helmet; - private ItemStack chest; - private ItemStack legs; - private ItemStack feet; - private final float exhaustion; - private final float saturation; - private final int foodLevel; - private final int health; - private final GameMode gamemode; - private final List potionEffects; - private final String playerTitle; - - public PlayerState(GameMode gamemode, ItemStack[] contents, ItemStack helmet, ItemStack chest, ItemStack legs, ItemStack feet, int health, float exhaustion, float saturation, int foodLevel, List potionEffects, String playerTitle) { - this.gamemode = gamemode; - this.health = health; - this.exhaustion = exhaustion; - this.saturation = saturation; - this.foodLevel = foodLevel; - this.potionEffects = potionEffects; - this.playerTitle = playerTitle; - this.setContents(contents); - this.setHelmet(helmet); - this.setChest(chest); - this.setLegs(legs); - this.setFeet(feet); - } - - public void setContents(ItemStack[] contents) { - this.contents = contents; - } - - public ItemStack[] getContents() { - return this.contents; - } - - public void setHelmet(ItemStack helmet) { - this.helmet = helmet; - } - - public ItemStack getHelmet() { - return this.helmet; - } - - public void setChest(ItemStack chest) { - this.chest = chest; - } - - public ItemStack getChest() { - return this.chest; - } - - public void setLegs(ItemStack legs) { - this.legs = legs; - } - - public ItemStack getLegs() { - return this.legs; - } - - public void setFeet(ItemStack feet) { - this.feet = feet; - } - - public ItemStack getFeet() { - return this.feet; - } - - public float getExhaustion() { - return exhaustion; - } - - public float getSaturation() { - return saturation; - } - - public int getFoodLevel() { - return foodLevel; - } - - public int getHealth() { - return health; - } - - public GameMode getGamemode() { - return gamemode; - } - - public List getPotionEffects() { - return potionEffects; - } - - public String getPlayerTitle() { - return playerTitle; - } - -} diff --git a/war/src/main/java/com/tommytony/war/utils/SignHelper.java b/war/src/main/java/com/tommytony/war/utils/SignHelper.java deleted file mode 100644 index 2b7841b..0000000 --- a/war/src/main/java/com/tommytony/war/utils/SignHelper.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.tommytony.war.utils; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; - -import bukkit.tommytony.war.War; - -public class SignHelper { - - public static void setToSign(War war, Block block, byte data, String[] lines) { - if (block.getType() != Material.SIGN_POST) { - block.setType(Material.SIGN_POST); - } - try { - BlockState state = block.getState(); - state.setData(new org.bukkit.material.Sign(Material.SIGN_POST, data)); - if (state instanceof Sign) { - Sign sign = (Sign) state; - - if (sign.getLines() != null) { - sign.setLine(0, lines[0]); - sign.setLine(1, lines[1]); - sign.setLine(2, lines[2]); - sign.setLine(3, lines[3]); - sign.update(true); - } - } - } catch (Exception e) { - // just can't stand this anymore - } - } - -} diff --git a/war/src/main/java/com/tommytony/war/volumes/BlockInfo.java b/war/src/main/java/com/tommytony/war/volumes/BlockInfo.java deleted file mode 100644 index 83d78ee..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/BlockInfo.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.tommytony.war.volumes; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; - -/** - * - * @author tommytony - * - */ -public class BlockInfo { - private int x; - private int y; - private int z; - private int type; - private byte data; - - // private String[] signLines; - - public static Block getBlock(World world, BlockInfo info) { - return world.getBlockAt(info.getX(), info.getY(), info.getZ()); - } - - public BlockInfo(int x, int y, int z, int type, byte data) { - this.x = x; - this.y = y; - this.z = z; - this.type = type; - this.data = data; - } - - public BlockInfo(Block block) { - this.x = block.getX(); - this.y = block.getY(); - this.z = block.getZ(); - this.type = block.getTypeId(); - this.data = block.getData(); - // if (is(Material.SIGN) || is(Material.SIGN_POST)) { - // Sign sign = (Sign)block.getState(); - // this.signLines = sign.getLines(); - // } - } - - // public BlockInfo(BlockState blockState) { - // this.x = blockState.getX(); - // this.y = blockState.getY(); - // this.z = blockState.getZ(); - // this.type = blockState.getTypeId(); - // this.data = blockState.getData().getData(); - // // if (is(Material.SIGN) || is(Material.SIGN_POST)) { - // // Sign sign = (Sign)blockState; - // // this.signLines = sign.getLines(); - // // } - // } - - // public BlockInfo(int typeID, byte data, String[] lines) { - // type = typeID; - // this.data = data; - // //signLines = lines; - // } - - public int getX() { - return this.x; - } - - public int getY() { - return this.y; - } - - public int getZ() { - return this.z; - } - - // letting us mutate the BlockInfos might be a bad idea; use setters with care - public void setX(int x) { - this.x = x; - } - - public void setY(int y) { - this.y = y; - } - - public void setZ(int z) { - this.z = z; - } - - public int getTypeId() { - return this.type; - } - - public Material getType() { - return Material.getMaterial(this.type); - } - - public byte getData() { - return this.data; - } - - public boolean is(Material material) { - return this.getType() == material; - } - - // public String[] getSignLines() { - // if (is(Material.SIGN) || is(Material.SIGN_POST)){ - // return new String[4] {"", ""}; - // } - // return null; - // } -} diff --git a/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java b/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java deleted file mode 100644 index 3898357..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.tommytony.war.volumes; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; - -/** - * - * @author tommytony - * @deprecated Broken, don't use. - */ -@Deprecated -public class CenteredVolume extends Volume { - - private Block center; - private int sideSize = -1; - private final World world; - - public CenteredVolume(String name, Block center, int sideSize, World world) { - super(name, world); - this.world = world; - this.setCenter(center); - this.setSideSize(sideSize); - } - - public void changeCenter(Location newCenter) { - this.changeCenter(this.world.getBlockAt(newCenter.getBlockX(), newCenter.getBlockY(), newCenter.getBlockZ()), this.sideSize); - } - - public void changeCenter(Block newCenter, int sideSize) { - this.resetBlocks(); - this.center = newCenter; - this.sideSize = sideSize; - this.calculateCorners(); - } - - public void setCenter(Block block) { - this.center = block; - } - - public void calculateCorners() { - int topHalfOfSide = this.sideSize / 2; - - int x = this.center.getX() + topHalfOfSide; - int y = this.center.getY() + topHalfOfSide; - int z = this.center.getZ() + topHalfOfSide; - Block cornerOne = this.world.getBlockAt(x, y, z); - this.setCornerOne(cornerOne); - - if (this.sideSize % 2 == 0) { // not a real center, bottom half is larger by 1 - int bottomHalfOfSide = this.sideSize - topHalfOfSide; - x = this.center.getX() - bottomHalfOfSide; - y = this.center.getY() - bottomHalfOfSide; - z = this.center.getZ() - bottomHalfOfSide; - Block cornerTwo = this.world.getBlockAt(x, y, z); - this.setCornerTwo(cornerTwo); - } else { - x = this.center.getX() - topHalfOfSide; - y = this.center.getY() - topHalfOfSide; - z = this.center.getZ() - topHalfOfSide; - Block cornerTwo = this.world.getBlockAt(x, y, z); - this.setCornerTwo(cornerTwo); - } - } - - private void setSideSize(int sideSize) { - this.sideSize = sideSize; - } - -} diff --git a/war/src/main/java/com/tommytony/war/volumes/NotNorthwestException.java b/war/src/main/java/com/tommytony/war/volumes/NotNorthwestException.java deleted file mode 100644 index a700183..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/NotNorthwestException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.tommytony.war.volumes; - -public class NotNorthwestException extends Exception { - - private static final long serialVersionUID = -5736463256274556866L; - -} diff --git a/war/src/main/java/com/tommytony/war/volumes/NotSoutheastException.java b/war/src/main/java/com/tommytony/war/volumes/NotSoutheastException.java deleted file mode 100644 index 30ac2be..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/NotSoutheastException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.tommytony.war.volumes; - -public class NotSoutheastException extends Exception { - - /** - * - */ - private static final long serialVersionUID = -4347064837067648341L; - -} diff --git a/war/src/main/java/com/tommytony/war/volumes/TooBigException.java b/war/src/main/java/com/tommytony/war/volumes/TooBigException.java deleted file mode 100644 index 5a1210c..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/TooBigException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.tommytony.war.volumes; - -public class TooBigException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 61793179891881015L; - -} diff --git a/war/src/main/java/com/tommytony/war/volumes/TooSmallException.java b/war/src/main/java/com/tommytony/war/volumes/TooSmallException.java deleted file mode 100644 index 4014f9b..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/TooSmallException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.tommytony.war.volumes; - -public class TooSmallException extends Exception { - - /** - * - */ - private static final long serialVersionUID = -1641366536434076088L; - -} diff --git a/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java b/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java deleted file mode 100644 index fad1a4d..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.tommytony.war.volumes; - -import java.util.logging.Level; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; - -import bukkit.tommytony.war.War; - -/** - * - * @author tommytony - * - */ -@Deprecated -public class VerticalVolume extends Volume { - - public VerticalVolume(String name, World world) { - super(name, world); - - } - - @Override - public void setCornerOne(Block block) { - // corner one defaults to topmost corner - Block topBlock = this.getWorld().getBlockAt(block.getX(), 127, block.getZ()); - super.setCornerOne(topBlock); - } - - @Override - public void setCornerTwo(Block block) { - // corner two defaults to bottom most corner - Block bottomBlock = this.getWorld().getBlockAt(block.getX(), 0, block.getZ()); - super.setCornerTwo(bottomBlock); - } - - public boolean isWallBlock(Block block) { - return this.isEastWallBlock(block) || this.isNorthWallBlock(block) || this.isSouthWallBlock(block) || this.isWestWallBlock(block); - } - - public boolean isEastWallBlock(Block block) { - if (this.getMinZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) { - return true; // east wall - } - return false; - } - - public boolean isSouthWallBlock(Block block) { - if (this.getMaxX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) { - return true; // south wall - } - return false; - } - - public boolean isNorthWallBlock(Block block) { - if (this.getMinX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) { - return true; // north wall - } - return false; - } - - public boolean isWestWallBlock(Block block) { - if (this.getMaxZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) { - return true; // west wall - } - return false; - } - - public int resetWallBlocks(BlockFace wall) { - int noOfResetBlocks = 0; - try { - if (this.hasTwoCorners() && this.getBlockTypes() != null) { - if (wall == BlockFace.EAST) { - int z = this.getMinZ(); - int k = 0; - int y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++) { - int x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++) { - int oldBlockType = this.getBlockTypes()[i][j][k]; - byte oldBlockData = this.getBlockDatas()[i][j][k]; - Block currentBlock = this.getWorld().getBlockAt(x, y, z); - if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - x++; - } - y++; - } - } else if (wall == BlockFace.WEST) { - int z = this.getMaxZ(); - int k = this.getSizeZ() - 1; - int y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++) { - int x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++) { - int oldBlockType = this.getBlockTypes()[i][j][k]; - byte oldBlockData = this.getBlockDatas()[i][j][k]; - Block currentBlock = this.getWorld().getBlockAt(x, y, z); - if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - x++; - } - y++; - } - } else if (wall == BlockFace.NORTH) { - int x = this.getMinX(); - int i = 0; - int y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++) { - int z = this.getMinZ(); - for (int k = 0; k < this.getSizeZ(); k++) { - int oldBlockType = this.getBlockTypes()[i][j][k]; - byte oldBlockData = this.getBlockDatas()[i][j][k]; - Block currentBlock = this.getWorld().getBlockAt(x, y, z); - if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - z++; - } - y++; - } - } else if (wall == BlockFace.SOUTH) { - int x = this.getMaxX(); - int i = this.getSizeX() - 1; - int y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++) { - int z = this.getMinZ(); - for (int k = 0; k < this.getSizeZ(); k++) { - int oldBlockType = this.getBlockTypes()[i][j][k]; - byte oldBlockData = this.getBlockDatas()[i][j][k]; - Block currentBlock = this.getWorld().getBlockAt(x, y, z); - if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - z++; - } - y++; - } - } - } - } catch (Exception e) { - War.war.log("Failed to reset wall " + wall + " in volume " + this.getName() + ". " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); - } - return noOfResetBlocks; - } - - private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) { - if (currentBlock.getTypeId() != oldBlockType || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()))) { - currentBlock.setTypeId(oldBlockType); - currentBlock.setData(oldBlockData); - // if (oldBlockInfo.is(Material.SIGN) || oldBlockInfo.is(Material.SIGN_POST)) { - // BlockState state = currentBlock.getState(); - // Sign currentSign = (Sign) state; - // currentSign.setLine(0, oldBlockInfo.getSignLines()[0]); - // currentSign.setLine(1, oldBlockInfo.getSignLines()[0]); - // currentSign.setLine(2, oldBlockInfo.getSignLines()[0]); - // currentSign.setLine(3, oldBlockInfo.getSignLines()[0]); - // state.update(); - // } - return true; - } - return false; - } - -} diff --git a/war/src/main/java/com/tommytony/war/volumes/Volume.java b/war/src/main/java/com/tommytony/war/volumes/Volume.java deleted file mode 100644 index d084c79..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/Volume.java +++ /dev/null @@ -1,563 +0,0 @@ -package com.tommytony.war.volumes; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.logging.Level; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.Chest; -import org.bukkit.block.Dispenser; -import org.bukkit.block.Sign; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.jobs.BlockResetJob; - -/** - * - * @author tommytony - * - */ -public class Volume { - private final String name; - private World world; - // private final Warzone warzone; - private BlockInfo cornerOne; - private BlockInfo cornerTwo; - private int[][][] blockTypes = null; - private byte[][][] blockDatas = null; - private HashMap signLines = new HashMap(); - private HashMap> invBlockContents = new HashMap>(); - - public Volume(String name, World world) { - this.name = name; - this.world = world; - } - - public World getWorld() { - return this.world; - } - - public void setWorld(World world) { - this.world = world; - } - - public boolean hasTwoCorners() { - return this.cornerOne != null && this.cornerTwo != null; - } - - public void setCornerOne(Block block) { - this.cornerOne = new BlockInfo(block); - } - - public void setCornerOne(BlockInfo blockInfo) { - this.cornerOne = blockInfo; - } - - public int saveBlocks() { - // BlockSaveJob job = new BlockSaveJob(this); - // war.getServer().getScheduler().scheduleSyncDelayedTask(war, job); - // return 0; - int noOfSavedBlocks = 0; - int x = 0; - int y = 0; - int z = 0; - try { - if (this.hasTwoCorners()) { - this.setBlockTypes(new int[this.getSizeX()][this.getSizeY()][this.getSizeZ()]); - this.setBlockDatas(new byte[this.getSizeX()][this.getSizeY()][this.getSizeZ()]); - this.getSignLines().clear(); - this.getInvBlockContents().clear(); - x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++) { - y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++) { - z = this.getMinZ(); - for (int k = 0; k < this.getSizeZ(); k++) { - try { - Block block = this.getWorld().getBlockAt(x, y, z); - this.getBlockTypes()[i][j][k] = block.getTypeId(); - this.getBlockDatas()[i][j][k] = block.getData(); - BlockState state = block.getState(); - if (state instanceof Sign) { - // Signs - Sign sign = (Sign) state; - if (sign.getLines() != null) { - this.getSignLines().put("sign-" + i + "-" + j + "-" + k, sign.getLines()); - } - - } else if (state instanceof Chest) { - // Chests - Chest chest = (Chest) state; - Inventory inv = chest.getInventory(); - int size = inv.getSize(); - List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++) { - ItemStack item = inv.getItem(invIndex); - if (item != null && item.getType().getId() != Material.AIR.getId()) { - items.add(item); - } - } - this.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items); - } else if (state instanceof Dispenser) { - // Dispensers - Dispenser dispenser = (Dispenser) state; - Inventory inv = dispenser.getInventory(); - int size = inv.getSize(); - List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++) { - ItemStack item = inv.getItem(invIndex); - if (item != null && item.getType().getId() != Material.AIR.getId()) { - items.add(item); - } - } - this.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items); - } - - noOfSavedBlocks++; - } catch (Exception e) { - War.war.getLogger().warning("Failed to save block in volume " + this.getName() + ". Saved blocks so far:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + e.getMessage()); - e.printStackTrace(); - } finally { - z++; - } - } - y++; - } - x++; - } - } - } catch (Exception e) { - War.war.getLogger().warning("Failed to save volume " + this.getName() + " blocks. Saved blocks:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); - e.printStackTrace(); - } - return noOfSavedBlocks; - } - - public void resetBlocksAsJob() { - BlockResetJob job = new BlockResetJob(this); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - } - - public int resetBlocks() { - int visitedBlocks = 0, noOfResetBlocks = 0, x = 0, y = 0, z = 0; - int currentBlockId = 0; - int oldBlockType = 0; - this.clearBlocksThatDontFloat(); - try { - if (this.hasTwoCorners() && this.isSaved()) { - x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++) { - y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++) { - z = this.getMinZ(); - for (int k = 0; k < this.getSizeZ(); k++) { - try { - oldBlockType = this.getBlockTypes()[i][j][k]; - byte oldBlockData = this.getBlockDatas()[i][j][k]; - Block currentBlock = this.getWorld().getBlockAt(x, y, z); - currentBlockId = currentBlock.getTypeId(); - if (currentBlockId != oldBlockType || (currentBlockId == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlockId == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId() || oldBlockType == Material.CHEST.getId() || oldBlockType == Material.DISPENSER.getId()))) { - if (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()) { - // Signs - if (oldBlockType == Material.SIGN_POST.getId() && ((oldBlockData & 0x04) == 0x04) && i + 1 != this.getSizeX()) { - Block southBlock = currentBlock.getRelative(BlockFace.SOUTH); - int oldSouthBlockType = this.getBlockTypes()[i + 1][j][k]; - byte oldSouthBlockData = this.getBlockDatas()[i + 1][j][k]; - if (southBlock.getTypeId() != oldSouthBlockType) { - southBlock.setTypeId(oldSouthBlockType); - southBlock.setData(oldSouthBlockData); - } - } - currentBlock.setType(Material.getMaterial(oldBlockType)); - BlockState state = currentBlock.getState(); - state.setData(new org.bukkit.material.Sign(oldBlockType, oldBlockData)); - if (state instanceof Sign) { - Sign sign = (Sign) state; - String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k); - if (lines != null && sign.getLines() != null) { - if (lines.length > 0) { - sign.setLine(0, lines[0]); - } - if (lines.length > 1) { - sign.setLine(1, lines[1]); - } - if (lines.length > 2) { - sign.setLine(2, lines[2]); - } - if (lines.length > 3) { - sign.setLine(3, lines[3]); - } - sign.update(true); - } - } - } else if (oldBlockType == Material.CHEST.getId()) { - // Chests - currentBlock.setType(Material.getMaterial(oldBlockType)); - currentBlock.setData(oldBlockData); - BlockState state = currentBlock.getState(); - if (state instanceof Chest) { - Chest chest = (Chest) state; - List contents = this.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k); - if (contents != null) { - int ii = 0; - chest.getInventory().clear(); - for (ItemStack item : contents) { - if (item != null) { - chest.getInventory().setItem(ii, item); - ii++; - } - } - chest.update(true); - } - } - } else if (oldBlockType == Material.DISPENSER.getId()) { - // Dispensers - currentBlock.setType(Material.getMaterial(oldBlockType)); - currentBlock.setData(oldBlockData); - BlockState state = currentBlock.getState(); - if (state instanceof Dispenser) { - Dispenser dispenser = (Dispenser) state; - List contents = this.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k); - if (contents != null) { - int ii = 0; - dispenser.getInventory().clear(); - for (ItemStack item : contents) { - if (item != null) { - dispenser.getInventory().setItem(ii, item); - ii++; - } - } - dispenser.update(true); - } - } - } else if (oldBlockType == Material.WOODEN_DOOR.getId() || oldBlockType == Material.IRON_DOOR_BLOCK.getId()) { - // Door blocks - - // Check if is bottom door block - if (j + 1 < this.getSizeY() && this.getBlockTypes()[i][j + 1][k] == oldBlockType) { - // set both door blocks right away - - Block blockAbove = this.getWorld().getBlockAt(x, y + 1, z); - blockAbove.setType(Material.getMaterial(oldBlockType)); - blockAbove.setData(this.getBlockDatas()[i][j + 1][k]); - - currentBlock.setType(Material.getMaterial(oldBlockType)); - currentBlock.setData(oldBlockData); - } - } else if (((oldBlockType == Material.TORCH.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.REDSTONE_TORCH_ON.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.LEVER.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.STONE_BUTTON.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.LADDER.getId() && ((oldBlockData & 0x04) == 0x04)) || (oldBlockType == Material.RAILS.getId() && ((oldBlockData & 0x02) == 0x02))) && i + 1 != this.getSizeX()) { - // Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol - Block southBlock = currentBlock.getRelative(BlockFace.SOUTH); - int oldSouthBlockType = this.getBlockTypes()[i + 1][j][k]; - byte oldSouthBlockData = this.getBlockDatas()[i + 1][j][k]; - if (southBlock.getTypeId() != oldSouthBlockType) { - southBlock.setTypeId(oldSouthBlockType); - southBlock.setData(oldSouthBlockData); - } - // change the block itself, now that we have a block to set it on - currentBlock.setType(Material.getMaterial(oldBlockType)); - currentBlock.setData(oldBlockData); - } else { - // regular block - currentBlock.setType(Material.getMaterial(oldBlockType)); - currentBlock.setData(oldBlockData); - } - noOfResetBlocks++; - } - visitedBlocks++; - } catch (Exception e) { - War.war.getLogger().warning("Failed to reset block in volume " + this.getName() + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); - e.printStackTrace(); - } finally { - z++; - } - } - y++; - } - x++; - } - } - } catch (Exception e) { - War.war.log("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); - e.printStackTrace(); - } - return noOfResetBlocks; - } - - public byte[][][] getBlockDatas() { - // TODO Auto-generated method stub - return this.blockDatas; - } - - public void setBlockDatas(byte[][][] data) { - this.blockDatas = data; - } - - public void setCornerTwo(Block block) { - this.cornerTwo = new BlockInfo(block); - } - - public void setCornerTwo(BlockInfo blockInfo) { - this.cornerTwo = blockInfo; - } - - public BlockInfo getMinXBlock() { - if (this.cornerOne.getX() < this.cornerTwo.getX()) { - return this.cornerOne; - } - return this.cornerTwo; - } - - public BlockInfo getMinYBlock() { - if (this.cornerOne.getY() < this.cornerTwo.getY()) { - return this.cornerOne; - } - return this.cornerTwo; - } - - public BlockInfo getMinZBlock() { - if (this.cornerOne.getZ() < this.cornerTwo.getZ()) { - return this.cornerOne; - } - return this.cornerTwo; - } - - public int getMinX() { - return this.getMinXBlock().getX(); - } - - public int getMinY() { - return this.getMinYBlock().getY(); - } - - public int getMinZ() { - return this.getMinZBlock().getZ(); - } - - public BlockInfo getMaxXBlock() { - if (this.cornerOne.getX() < this.cornerTwo.getX()) { - return this.cornerTwo; - } - return this.cornerOne; - } - - public BlockInfo getMaxYBlock() { - if (this.cornerOne.getY() < this.cornerTwo.getY()) { - return this.cornerTwo; - } - return this.cornerOne; - } - - public BlockInfo getMaxZBlock() { - if (this.cornerOne.getZ() < this.cornerTwo.getZ()) { - return this.cornerTwo; - } - return this.cornerOne; - } - - public int getMaxX() { - return this.getMaxXBlock().getX(); - } - - public int getMaxY() { - return this.getMaxYBlock().getY(); - } - - public int getMaxZ() { - return this.getMaxZBlock().getZ(); - } - - public int getSizeX() { - return this.getMaxX() - this.getMinX() + 1; - } - - public int getSizeY() { - return this.getMaxY() - this.getMinY() + 1; - } - - public int getSizeZ() { - return this.getMaxZ() - this.getMinZ() + 1; - } - - public boolean isSaved() { - return this.getBlockTypes() != null; - } - - public int[][][] getBlockTypes() { - return this.blockTypes; - } - - public BlockInfo getCornerOne() { - return this.cornerOne; - } - - public BlockInfo getCornerTwo() { - return this.cornerTwo; - } - - public boolean contains(Location location) { - int x = location.getBlockX(); - int y = location.getBlockY(); - int z = location.getBlockZ(); - return this.hasTwoCorners() && location.getWorld().getName().equals(this.world.getName()) && x <= this.getMaxX() && x >= this.getMinX() && y <= this.getMaxY() && y >= this.getMinY() && z <= this.getMaxZ() && z >= this.getMinZ(); - } - - public boolean contains(Block block) { - int x = block.getX(); - int y = block.getY(); - int z = block.getZ(); - return this.hasTwoCorners() && block.getWorld().getName().equals(this.world.getName()) && x <= this.getMaxX() && x >= this.getMinX() && y <= this.getMaxY() && y >= this.getMinY() && z <= this.getMaxZ() && z >= this.getMinZ(); - } - - public void setBlockTypes(int[][][] blockTypes) { - this.blockTypes = blockTypes; - } - - public String getName() { - return this.name; - } - - public void setToMaterial(Material material) { - try { - if (this.hasTwoCorners() && this.isSaved()) { - int x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++) { - int y = this.getMaxY(); - for (int j = this.getSizeY(); j > 0; j--) { - int z = this.getMinZ(); - for (int k = 0; k < this.getSizeZ(); k++) { - Block currentBlock = this.getWorld().getBlockAt(x, y, z); - currentBlock.setType(material); - z++; - } - y--; - } - x++; - } - } - } catch (Exception e) { - War.war.log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); - } - } - - public void setFaceMaterial(BlockFace face, Material material) { - try { - if (this.hasTwoCorners() && this.isSaved()) { - int x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++) { - int y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++) { - int z = this.getMinZ(); - for (int k = 0; k < this.getSizeZ(); k++) { - if ((face == BlockFace.DOWN && y == this.getMinY()) || (face == BlockFace.UP && y == this.getMaxY()) || (face == BlockFace.NORTH && x == this.getMinX()) || (face == BlockFace.EAST && z == this.getMinZ()) || (face == BlockFace.SOUTH && x == this.getMaxX()) || (face == BlockFace.WEST && z == this.getMaxZ())) { - Block currentBlock = this.getWorld().getBlockAt(x, y, z); - currentBlock.setType(material); - } - z++; - } - y++; - } - x++; - } - } - } catch (Exception e) { - War.war.log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); - } - } - - private void switchMaterials(Material[] oldTypes, Material newType) { - try { - int i = 0, j = 0, k = 0; - int x, y, z; - Block currentBlock = null; - if (this.hasTwoCorners() && this.isSaved()) { - x = this.getMinX(); - for (i = 0; i < this.getSizeX(); i++) { - y = this.getMaxY(); - for (j = this.getSizeY(); j > 0; j--) { - z = this.getMinZ(); - for (k = 0; k < this.getSizeZ(); k++) { - currentBlock = this.getWorld().getBlockAt(x, y, z); - for (Material oldType : oldTypes) { - if (currentBlock.getType().getId() == oldType.getId()) { - currentBlock.setType(newType); - // BlockState state = currentBlock.getState(); - // if (state != null) { - // state.setType(newType); - // state.update(true); - // } - } - } - z++; - } - y--; - } - x++; - } - } - } catch (Exception e) { - War.war.log("Failed to switch block to " + newType + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); - } - } - - public void clearBlocksThatDontFloat() { - Material[] toAirMaterials = new Material[22]; - toAirMaterials[0] = Material.SIGN_POST; - toAirMaterials[1] = Material.WALL_SIGN; - toAirMaterials[2] = Material.IRON_DOOR; - toAirMaterials[3] = Material.WOOD_DOOR; - toAirMaterials[4] = Material.LADDER; - toAirMaterials[5] = Material.YELLOW_FLOWER; - toAirMaterials[6] = Material.RED_ROSE; - toAirMaterials[7] = Material.RED_MUSHROOM; - toAirMaterials[8] = Material.BROWN_MUSHROOM; - toAirMaterials[9] = Material.SAPLING; - toAirMaterials[10] = Material.TORCH; - toAirMaterials[11] = Material.RAILS; - toAirMaterials[12] = Material.STONE_BUTTON; - toAirMaterials[13] = Material.STONE_PLATE; - toAirMaterials[14] = Material.WOOD_PLATE; - toAirMaterials[15] = Material.LEVER; - toAirMaterials[16] = Material.REDSTONE; - toAirMaterials[17] = Material.REDSTONE_TORCH_ON; - toAirMaterials[18] = Material.REDSTONE_TORCH_OFF; - toAirMaterials[19] = Material.CACTUS; - toAirMaterials[20] = Material.SNOW; - toAirMaterials[21] = Material.ICE; - this.switchMaterials(toAirMaterials, Material.AIR); - } - - public void setSignLines(HashMap signLines) { - this.signLines = signLines; - } - - public HashMap getSignLines() { - return this.signLines; - } - - public void setInvBlockContents(HashMap> invBlockContents) { - this.invBlockContents = invBlockContents; - } - - public HashMap> getInvBlockContents() { - return this.invBlockContents; - } - - @Override - public void finalize() { - this.blockDatas = null; - this.blockTypes = null; - this.signLines.clear(); - this.signLines = null; - this.invBlockContents.clear(); - this.invBlockContents = null; - } -} diff --git a/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java b/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java deleted file mode 100644 index 1013398..0000000 --- a/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java +++ /dev/null @@ -1,306 +0,0 @@ -package com.tommytony.war.volumes; - -import org.bukkit.World; -import org.bukkit.block.Block; - -import bukkit.tommytony.war.War; - -import com.tommytony.war.Monument; -import com.tommytony.war.Team; -import com.tommytony.war.Warzone; -import com.tommytony.war.mappers.ZoneVolumeMapper; - -/** - * - * @author tommytony - * - */ -public class ZoneVolume extends Volume { - - private Warzone zone; - private boolean isSaved = false; - - public ZoneVolume(String name, World world, Warzone zone) { - super(name, world); - this.zone = zone; - } - - @Override - public int saveBlocks() { - // Save blocks directly to disk (i.e. don't put everything in memory) - int saved = ZoneVolumeMapper.save(this, this.zone.getName()); - War.war.log("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO); - this.isSaved = true; - return saved; - } - - @Override - public boolean isSaved() { - return this.isSaved; - } - - public void loadCorners() { - ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), true); - this.isSaved = true; - } - - @Override - public int resetBlocks() { - // Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks) - int reset = ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), false); - War.war.log("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO); - this.isSaved = true; - return reset; - } - - @Override - public void setBlockTypes(int[][][] blockTypes) { - return; - } - - @Override - public void setBlockDatas(byte[][][] blockData) { - return; - } - - public void setNorthwest(Block block) throws NotNorthwestException, TooSmallException, TooBigException { - // northwest defaults to top block - BlockInfo topBlock = new BlockInfo(block.getX(), 127, block.getZ(), block.getTypeId(), block.getData()); - BlockInfo oldCornerOne = this.getCornerOne(); - BlockInfo oldCornerTwo = this.getCornerTwo(); - if (this.getCornerOne() == null) { - if (this.getCornerTwo() == null) { - // northwest defaults to corner 1 - super.setCornerOne(topBlock); - } else if (this.getCornerTwo().getX() <= block.getX() || this.getCornerTwo().getZ() >= block.getZ()) { - throw new NotNorthwestException(); - } else { - // corner 2 already set, but we're sure we're located at the northwest of it - super.setCornerOne(topBlock); - } - } else if (this.getCornerTwo() == null) { - // corner 1 already exists, set northwest as corner 2 (only if it's at the northwest of corner 1) - if (this.getCornerOne().getX() <= block.getX() || this.getCornerOne().getZ() >= block.getZ()) { - throw new NotNorthwestException(); - } - super.setCornerTwo(topBlock); - } else { - // both corners already set: we are resizing (only if the new block is northwest relative to the southeasternmost block) - if (this.getSoutheastX() <= block.getX() || this.getSoutheastZ() >= block.getZ()) { - throw new NotNorthwestException(); - } - BlockInfo minXBlock = this.getMinXBlock(); // north means min X - minXBlock.setX(block.getX()); // mutating, argh! - BlockInfo maxZBlock = this.getMaxZBlock(); // west means max Z - maxZBlock.setZ(block.getZ()); - } - if (this.tooSmall() || this.zoneStructuresAreOutside()) { - super.setCornerOne(oldCornerOne); - super.setCornerTwo(oldCornerTwo); - throw new TooSmallException(); - } else if (this.tooBig()) { - super.setCornerOne(oldCornerOne); - super.setCornerTwo(oldCornerTwo); - throw new TooBigException(); - } - } - - public int getNorthwestX() { - if (!this.hasTwoCorners()) { - return 0; - } else { - return this.getMinX(); - } - } - - public int getNorthwestZ() { - if (!this.hasTwoCorners()) { - return 0; - } else { - return this.getMaxZ(); - } - } - - public void setSoutheast(Block block) throws NotSoutheastException, TooSmallException, TooBigException { - // southeast defaults to bottom block - BlockInfo bottomBlock = new BlockInfo(block.getX(), 0, block.getZ(), block.getTypeId(), block.getData()); - BlockInfo oldCornerOne = this.getCornerOne(); - BlockInfo oldCornerTwo = this.getCornerTwo(); - if (this.getCornerTwo() == null) { - if (this.getCornerOne() == null) { - // southeast defaults to corner 2 - super.setCornerTwo(bottomBlock); - } else if (this.getCornerOne().getX() >= block.getX() || this.getCornerOne().getZ() <= block.getZ()) { - throw new NotSoutheastException(); - } else { - // corner 1 already set, but we're sure we're located at the southeast of it - super.setCornerTwo(bottomBlock); - } - } else if (this.getCornerOne() == null) { - // corner 2 already exists, set northwest as corner 1 (only if it's at the southeast of corner 2) - if (this.getCornerTwo().getX() >= block.getX() || this.getCornerTwo().getZ() <= block.getZ()) { - throw new NotSoutheastException(); - } - super.setCornerOne(bottomBlock); - } else { - // both corners already set: we are resizing (only if the new block is southeast relative to the northwesternmost block) - if (this.getNorthwestX() >= block.getX() || this.getNorthwestZ() <= block.getZ()) { - throw new NotSoutheastException(); - } - BlockInfo maxXBlock = this.getMaxXBlock(); // south means max X - maxXBlock.setX(block.getX()); // mutating, argh! - BlockInfo minZBlock = this.getMinZBlock(); // east means min Z - minZBlock.setZ(block.getZ()); - } - if (this.tooSmall() || this.zoneStructuresAreOutside()) { - super.setCornerOne(oldCornerOne); - super.setCornerTwo(oldCornerTwo); - throw new TooSmallException(); - } else if (this.tooBig()) { - super.setCornerOne(oldCornerOne); - super.setCornerTwo(oldCornerTwo); - throw new TooBigException(); - } - - } - - public int getSoutheastX() { - if (!this.hasTwoCorners()) { - return 0; - } else { - return this.getMaxX(); - } - } - - public int getSoutheastZ() { - if (!this.hasTwoCorners()) { - return 0; - } else { - return this.getMinZ(); - } - } - - public int getCenterY() { - if (!this.hasTwoCorners()) { - return 0; - } else { - return this.getMinY() + (this.getMaxY() - this.getMinY()) / 2; - } - } - - public void setZoneCornerOne(Block block) throws TooSmallException, TooBigException { - BlockInfo oldCornerOne = this.getCornerOne(); - super.setCornerOne(block); - if (this.tooSmall() || this.zoneStructuresAreOutside()) { - super.setCornerOne(oldCornerOne); - throw new TooSmallException(); - } else if (this.tooBig()) { - super.setCornerOne(oldCornerOne); - throw new TooBigException(); - } - } - - public void setZoneCornerTwo(Block block) throws TooSmallException, TooBigException { - BlockInfo oldCornerTwo = this.getCornerTwo(); - super.setCornerTwo(block); - if (this.tooSmall() || this.zoneStructuresAreOutside()) { - super.setCornerTwo(oldCornerTwo); - throw new TooSmallException(); - } else if (this.tooBig()) { - super.setCornerTwo(oldCornerTwo); - throw new TooBigException(); - } - } - - public boolean tooSmall() { - if (this.hasTwoCorners() && ((this.getMaxX() - this.getMinX() < 10) || (this.getMaxY() - this.getMinY() < 10) || (this.getMaxZ() - this.getMinZ() < 10))) { - return true; - } - return false; - } - - public boolean tooBig() { - if (this.hasTwoCorners() && ((this.getMaxX() - this.getMinX() > 750) || (this.getMaxY() - this.getMinY() > 750) || (this.getMaxZ() - this.getMinZ() > 750))) { - return true; - } - return false; - } - - public boolean zoneStructuresAreOutside() { - // check team spawns & flags - for (Team team : this.zone.getTeams()) { - if (team.getTeamSpawn() != null) { - if (!this.isInside(team.getSpawnVolume().getCornerOne()) || !this.isInside(team.getSpawnVolume().getCornerTwo())) { - return true; - } - } - if (team.getTeamFlag() != null) { - if (!this.isInside(team.getFlagVolume().getCornerOne()) || !this.isInside(team.getFlagVolume().getCornerTwo())) { - return true; - } - } - } - // check monuments - for (Monument monument : this.zone.getMonuments()) { - if (monument.getVolume() != null) { - if (!this.isInside(monument.getVolume().getCornerOne()) || !this.isInside(monument.getVolume().getCornerTwo())) { - return true; - } - } - } - return false; - } - - private boolean isInside(BlockInfo info) { - if (info.getX() <= this.getMaxX() && info.getX() >= this.getMinX() && info.getY() <= this.getMaxY() && info.getY() >= this.getMinY() && info.getZ() <= this.getMaxZ() && info.getZ() >= this.getMinZ()) { - return true; - } - return false; - } - - public boolean isWallBlock(Block block) { - return this.isEastWallBlock(block) || this.isNorthWallBlock(block) || this.isSouthWallBlock(block) || this.isWestWallBlock(block) || this.isUpWallBlock(block) || this.isDownWallBlock(block); - } - - public boolean isEastWallBlock(Block block) { - if (this.getMinZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) { - return true; // east wall - } - return false; - } - - public boolean isSouthWallBlock(Block block) { - if (this.getMaxX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) { - return true; // south wall - } - return false; - } - - public boolean isNorthWallBlock(Block block) { - if (this.getMinX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) { - return true; // north wall - } - return false; - } - - public boolean isWestWallBlock(Block block) { - if (this.getMaxZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) { - return true; // west wall - } - return false; - } - - public boolean isUpWallBlock(Block block) { - if (this.getMaxY() == block.getY() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getZ() >= this.getMinZ() && block.getZ() <= this.getMaxZ()) { - return true; // top wall - } - return false; - } - - public boolean isDownWallBlock(Block block) { - if (this.getMinY() == block.getY() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getZ() >= this.getMinZ() && block.getZ() <= this.getMaxZ()) { - return true; // bottom wall - } - return false; - } -}