diff --git a/war/pom.xml b/war/pom.xml index a51b1d0..cee1882 100644 --- a/war/pom.xml +++ b/war/pom.xml @@ -81,7 +81,7 @@ org.bukkit bukkit - 1.6.1-R0.1-SNAPSHOT + 1.6.2-R0.1 org.kitteh diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index bc362ec..08daef4 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -57,8 +57,8 @@ public class Team { this.teamConfig = new TeamConfigBag(warzone); this.inventories = new InventoryBag(warzone); // important constructors for cascading configs this.setName(name); - this.teamSpawns = new ArrayList(teamSpawn); - this.spawnVolumes = new HashMap(); + this.teamSpawns = new ArrayList(teamSpawn); + this.spawnVolumes = new HashMap(); for (Location spawn : teamSpawn) { this.setSpawnVolume(spawn, new Volume(name + teamSpawns.indexOf(spawn), warzone.getWorld())); } @@ -181,11 +181,7 @@ public class Team { 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 = Direction.NORTH_WEST(); - opposite = Direction.SOUTH_EAST(); signData = 10; signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.WEST(), 2); @@ -217,8 +213,6 @@ public class Team { this.setBlock(x + 2, y + 3, z - 2, this.kind); } } else if (yaw >= 90 && yaw <= 180) { - facing = Direction.NORTH_EAST(); - opposite = Direction.SOUTH_WEST(); signData = 14; signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.EAST(), 2); if (style.equals(TeamSpawnStyle.BIG)) { @@ -249,8 +243,6 @@ public class Team { this.setBlock(x + 2, y + 3, z + 2, this.kind); } } else if (yaw >= 180 && yaw < 270) { - facing = Direction.SOUTH_EAST(); - opposite = Direction.NORTH_WEST(); signData = 2; signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.EAST(), 2); if (style.equals(TeamSpawnStyle.BIG)) { @@ -281,8 +273,6 @@ public class Team { this.setBlock(x - 2, y + 3, z + 2, this.kind); } } else if (yaw >= 270 && yaw <= 360) { - facing = Direction.SOUTH_WEST(); - opposite = Direction.NORTH_EAST(); signData = 6; signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.WEST(), 2); if (style.equals(TeamSpawnStyle.BIG)) { diff --git a/war/src/main/java/com/tommytony/war/War.java b/war/src/main/java/com/tommytony/war/War.java index 30f2d8e..400b4c3 100644 --- a/war/src/main/java/com/tommytony/war/War.java +++ b/war/src/main/java/com/tommytony/war/War.java @@ -18,6 +18,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.plugin.PluginDescriptionFile; @@ -307,6 +308,7 @@ public class War extends JavaPlugin { this.getServer().getScheduler().cancelTasks(this); this.playerListener.purgeLatestPositions(); + HandlerList.unregisterAll(this); this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO); this.setLoaded(false); } @@ -350,13 +352,9 @@ public class War extends JavaPlugin { } } + @Deprecated public ItemStack copyStack(ItemStack originalStack) { - ItemStack copiedStack = new ItemStack(originalStack.getType(), originalStack.getAmount(), originalStack.getDurability(), new Byte(originalStack.getData().getData())); - copiedStack.setDurability(originalStack.getDurability()); - copiedStack.setItemMeta(originalStack.getItemMeta()); - copyEnchantments(originalStack, copiedStack); - - return copiedStack; + return originalStack.clone(); } public void copyEnchantments(ItemStack originalStack, ItemStack copiedStack) { @@ -392,8 +390,8 @@ public class War extends JavaPlugin { public String updateTeamFromNamedParams(Team team, CommandSender commandSender, String[] arguments) { try { - Map namedParams = new HashMap(); - Map thirdParameter = new HashMap(); + Map namedParams = new HashMap(); + Map thirdParameter = new HashMap(); for (String namedPair : arguments) { String[] pairSplit = namedPair.split(":"); if (pairSplit.length == 2) { @@ -468,8 +466,8 @@ public class War extends JavaPlugin { public String updateZoneFromNamedParams(Warzone warzone, CommandSender commandSender, String[] arguments) { try { - Map namedParams = new HashMap(); - Map thirdParameter = new HashMap(); + Map namedParams = new HashMap(); + Map thirdParameter = new HashMap(); for (String namedPair : arguments) { String[] pairSplit = namedPair.split(":"); if (pairSplit.length == 2) { @@ -662,8 +660,8 @@ public class War extends JavaPlugin { public String updateFromNamedParams(CommandSender commandSender, String[] arguments) { try { - Map namedParams = new HashMap(); - Map thirdParameter = new HashMap(); + Map namedParams = new HashMap(); + Map thirdParameter = new HashMap(); for (String namedPair : arguments) { String[] pairSplit = namedPair.split(":"); if (pairSplit.length == 2) { diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index a430409..375eaf2 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -1,6 +1,5 @@ package com.tommytony.war; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -20,6 +19,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.LeatherArmorMeta; import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.player.SpoutPlayer; @@ -36,8 +36,8 @@ import com.tommytony.war.mapper.LoadoutYmlMapper; import com.tommytony.war.spout.SpoutDisplayer; import com.tommytony.war.structure.Bomb; import com.tommytony.war.structure.Cake; -import com.tommytony.war.structure.Monument; import com.tommytony.war.structure.HubLobbyMaterials; +import com.tommytony.war.structure.Monument; import com.tommytony.war.structure.WarzoneMaterials; import com.tommytony.war.structure.ZoneLobby; import com.tommytony.war.structure.ZoneWallGuard; @@ -49,7 +49,6 @@ import com.tommytony.war.utility.PotionEffectHelper; import com.tommytony.war.volume.BlockInfo; import com.tommytony.war.volume.Volume; import com.tommytony.war.volume.ZoneVolume; -import org.bukkit.inventory.meta.LeatherArmorMeta; /** * @@ -432,23 +431,23 @@ public class Warzone { boolean helmetIsInLoadout = false; for (Integer slot : loadout.keySet()) { if (slot == 100) { - playerInv.setBoots(War.war.copyStack(loadout.get(slot))); + playerInv.setBoots(loadout.get(slot).clone()); } else if (slot == 101) { - playerInv.setLeggings(War.war.copyStack(loadout.get(slot))); + playerInv.setLeggings(loadout.get(slot).clone()); } else if (slot == 102) { - playerInv.setChestplate(War.war.copyStack(loadout.get(slot))); + playerInv.setChestplate(loadout.get(slot).clone()); } else if (slot == 103) { - playerInv.setHelmet(War.war.copyStack(loadout.get(slot))); + playerInv.setHelmet(loadout.get(slot).clone()); helmetIsInLoadout = true; } else { ItemStack item = loadout.get(slot); if (item != null) { - playerInv.addItem(War.war.copyStack(item)); + playerInv.addItem(item.clone()); } } } if (this.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) { - playerInv.setHelmet(new ItemStack(team.getKind().getMaterial(), 1, (short) 1, new Byte(team.getKind().getData()))); + playerInv.setHelmet(team.getKind().getBlockHead()); } else { if (!helmetIsInLoadout) { ItemStack helmet = new ItemStack(Material.LEATHER_HELMET); @@ -900,12 +899,12 @@ public class Warzone { for (Player p : t.getPlayers()) { SpoutPlayer sp = SpoutManager.getPlayer(p); if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutDisplayer.cleanForNotification("Round over! " + playerTeam.getKind().getColor() + playerTeam.getName()), - SpoutDisplayer.cleanForNotification("ran out of lives."), - playerTeam.getKind().getMaterial(), - playerTeam.getKind().getData(), - 10000); + sp.sendNotification( + SpoutDisplayer.cleanForNotification("Round over! " + playerTeam.getKind().getColor() + playerTeam.getName()), + SpoutDisplayer.cleanForNotification("ran out of lives."), + playerTeam.getKind().getMaterial(), + playerTeam.getKind().getDyeColor().getWoolData(), + 10000); } } } @@ -966,12 +965,12 @@ public class Warzone { for (Player p : victim.getPlayers()) { SpoutPlayer sp = SpoutManager.getPlayer(p); if (sp.isSpoutCraftEnabled()) { - sp.sendNotification( - SpoutDisplayer.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " dropped"), - SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "your flag."), - playerTeam.getKind().getMaterial(), - playerTeam.getKind().getData(), - 5000); + sp.sendNotification( + SpoutDisplayer.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " dropped"), + SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "your flag."), + playerTeam.getKind().getMaterial(), + playerTeam.getKind().getDyeColor().getWoolData(), + 5000); } } } diff --git a/war/src/main/java/com/tommytony/war/command/ZoneSetter.java b/war/src/main/java/com/tommytony/war/command/ZoneSetter.java index afeb144..938c179 100644 --- a/war/src/main/java/com/tommytony/war/command/ZoneSetter.java +++ b/war/src/main/java/com/tommytony/war/command/ZoneSetter.java @@ -3,10 +3,8 @@ package com.tommytony.war.command; import java.util.logging.Level; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; - import com.tommytony.war.War; import com.tommytony.war.Warzone; import com.tommytony.war.config.WarConfig; diff --git a/war/src/main/java/com/tommytony/war/config/InventoryBag.java b/war/src/main/java/com/tommytony/war/config/InventoryBag.java index 8da73e9..9acc620 100644 --- a/war/src/main/java/com/tommytony/war/config/InventoryBag.java +++ b/war/src/main/java/com/tommytony/war/config/InventoryBag.java @@ -9,11 +9,12 @@ import com.tommytony.war.War; import com.tommytony.war.Warzone; import com.tommytony.war.utility.Loadout; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class InventoryBag { - private List loadouts = new ArrayList(); + private List loadouts = new ArrayList(); private HashMap reward = null; private Warzone warzone; @@ -82,7 +83,7 @@ public class InventoryBag { } else if (War.war.getDefaultInventories().hasLoadouts()) { return War.war.getDefaultInventories().resolveNewLoadouts(); } else { - return new ArrayList(); + return Collections.emptyList(); } } diff --git a/war/src/main/java/com/tommytony/war/config/TeamKind.java b/war/src/main/java/com/tommytony/war/config/TeamKind.java index c326c1a..cf5cea2 100644 --- a/war/src/main/java/com/tommytony/war/config/TeamKind.java +++ b/war/src/main/java/com/tommytony/war/config/TeamKind.java @@ -1,36 +1,40 @@ package com.tommytony.war.config; import org.bukkit.ChatColor; +import org.bukkit.DyeColor; import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.material.MaterialData; +import org.bukkit.material.Wool; import org.getspout.spoutapi.gui.Color; public enum TeamKind { - WHITE ((byte) 0, Material.WOOL, ChatColor.WHITE, 450), - ORANGE ((byte) 1, Material.WOOL, ChatColor.GOLD, 51), - MAGENTA ((byte) 2, Material.WOOL, ChatColor.LIGHT_PURPLE, 353), - BLUE ((byte) 3, Material.WOOL, ChatColor.BLUE, 23), - GOLD ((byte) 4, Material.WOOL, ChatColor.YELLOW, 403), // yellow = gold - GREEN ((byte) 5, Material.WOOL, ChatColor.GREEN, 612), - PINK ((byte) 6, Material.WOOL, ChatColor.LIGHT_PURPLE, 929), - GRAY ((byte) 7, Material.WOOL, ChatColor.DARK_GRAY, 600), - IRON ((byte) 8, Material.WOOL, ChatColor.GRAY, 154), // lightgrey = iron - DIAMOND ((byte) 9, Material.WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond - PURPLE ((byte) 10, Material.WOOL, ChatColor.DARK_PURPLE, 153), - NAVY ((byte) 11, Material.WOOL, ChatColor.DARK_BLUE, 939), - BROWN ((byte) 12, Material.WOOL, ChatColor.DARK_RED, 908), - DARKGREEN ((byte) 13, Material.WOOL, ChatColor.DARK_GREEN, 612), - RED ((byte) 14, Material.WOOL, ChatColor.RED, 245), - BLACK ((byte) 15, Material.WOOL, ChatColor.BLACK, 0); + WHITE (DyeColor.WHITE, Material.WOOL, ChatColor.WHITE, 450), + ORANGE (DyeColor.ORANGE, Material.WOOL, ChatColor.GOLD, 51), + MAGENTA (DyeColor.MAGENTA, Material.WOOL, ChatColor.LIGHT_PURPLE, 353), + BLUE (DyeColor.LIGHT_BLUE, Material.WOOL, ChatColor.BLUE, 23), + GOLD (DyeColor.YELLOW, Material.WOOL, ChatColor.YELLOW, 403), // yellow = gold + GREEN (DyeColor.LIME, Material.WOOL, ChatColor.GREEN, 612), + PINK (DyeColor.PINK, Material.WOOL, ChatColor.LIGHT_PURPLE, 929), + GRAY (DyeColor.GRAY, Material.WOOL, ChatColor.DARK_GRAY, 600), + IRON (DyeColor.SILVER, Material.WOOL, ChatColor.GRAY, 154), // lightgrey = iron + DIAMOND (DyeColor.CYAN, Material.WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond + PURPLE (DyeColor.PURPLE, Material.WOOL, ChatColor.DARK_PURPLE, 153), + NAVY (DyeColor.BLUE, Material.WOOL, ChatColor.DARK_BLUE, 939), + BROWN (DyeColor.BROWN, Material.WOOL, ChatColor.DARK_RED, 908), + DARKGREEN (DyeColor.GREEN, Material.WOOL, ChatColor.DARK_GREEN, 612), + RED (DyeColor.RED, Material.WOOL, ChatColor.RED, 245), + BLACK (DyeColor.BLACK, Material.WOOL, ChatColor.BLACK, 0); - private final byte data; - private final ChatColor color; + private final DyeColor dyeColor; + private final ChatColor chatColor; private final Material material; private final int potionEffectColor; - private TeamKind(byte data, Material material, ChatColor color, int potionEffectColor) { - this.data = data; + private TeamKind(DyeColor blockHeadColor, Material material, ChatColor color, int potionEffectColor) { + this.dyeColor = blockHeadColor; this.material = material; - this.color = color; + this.chatColor = color; this.potionEffectColor = potionEffectColor; } @@ -44,100 +48,58 @@ public enum TeamKind { return null; } + /** + * Get wool block data for the dye color. + * + * @return wool color data value + */ 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(255,215,0); - case 5: - return new Color(0,255,0); - case 6: - return new Color(255,128,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); - } - } - /** - * Gets the color for Bukkit - * @return the color - */ - public org.bukkit.Color getBukkitColor() { - int colorCode = (int)this.data; - switch (colorCode) { - case 0: - return org.bukkit.Color.fromRGB(255,255,255); - case 1: - return org.bukkit.Color.fromRGB(255,128,0); - case 2: - return org.bukkit.Color.fromRGB(255,128,255); - case 3: - return org.bukkit.Color.fromRGB(0,0,255); - case 4: - return org.bukkit.Color.fromRGB(255,215,0); - case 5: - return org.bukkit.Color.fromRGB(0,255,0); - case 6: - return org.bukkit.Color.fromRGB(255,128,255); - case 7: - return org.bukkit.Color.fromRGB(100,100,100); - case 8: - return org.bukkit.Color.fromRGB(200,200,200); - case 9: - return org.bukkit.Color.fromRGB(128,255,255); - case 10: - return org.bukkit.Color.fromRGB(128,0,255); - case 11: - return org.bukkit.Color.fromRGB(0,0,128); - case 12: - return org.bukkit.Color.fromRGB(128,0,0); - case 13: - return org.bukkit.Color.fromRGB(0,128,0); - case 14: - return org.bukkit.Color.fromRGB(255,0,0); - case 15: - return org.bukkit.Color.fromRGB(0,0,0); - default: - return org.bukkit.Color.fromRGB(255,255,255); - } + return this.dyeColor.getWoolData(); } + /** + * Get the color of the wool head block. + * + * @return head wool color. + */ + public DyeColor getDyeColor() { + return this.dyeColor; + } + + /** + * Get the color of this team in chat messages. + * + * @return team chat color. + */ + public ChatColor getColor() { + return this.chatColor; + } + + /** + * Get the color of this team in the Spout client GUI. + * + * @return spout chat GUI color + */ + public Color getSpoutColor() { + return new org.getspout.spoutapi.gui.Color( + dyeColor.getColor().getRed(), dyeColor.getColor().getGreen(), + dyeColor.getColor().getRed()); + } + + /** + * Get the color of the wool block as a bukkit color. + * + * @return wool block color. + */ + public org.bukkit.Color getBukkitColor() { + return this.dyeColor.getColor(); + } + + /** + * Get head block material. Should always be {@link Material#WOOL}. + * + * @return team head block material. + */ public Material getMaterial() { return this.material; } @@ -147,7 +109,31 @@ public enum TeamKind { return super.toString().toLowerCase(); } + /** + * Get color of the team's potion effect, for thieves. + * + * @return potion effect color. + */ public int getPotionEffectColor() { return this.potionEffectColor; } + + /** + * Get a single item of this team's wool head block. Creates a single block + * with data from {@link #getBlockData()}. + * + * @return single block head item. + */ + public ItemStack getBlockHead() { + return new Wool(this.dyeColor).toItemStack(1); + } + + /** + * Get wool head block data (for creating blocks). + * + * @return wool head block data. + */ + public MaterialData getBlockData() { + return new Wool(this.dyeColor); + } } diff --git a/war/src/main/java/com/tommytony/war/event/WarBlockListener.java b/war/src/main/java/com/tommytony/war/event/WarBlockListener.java index 595b0df..9201c1d 100644 --- a/war/src/main/java/com/tommytony/war/event/WarBlockListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarBlockListener.java @@ -168,8 +168,7 @@ public class WarBlockListener implements Listener { // Just give the user his f&s back but almost broken (max durability is 8). newItemInHand = new ItemStack(Material.FLINT_AND_STEEL, 1, (short)1); } else { - newItemInHand = new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData()); - newItemInHand.setDurability(inHand.getDurability()); + newItemInHand = inHand.clone(); } event.getPlayer().setItemInHand(newItemInHand); @@ -278,9 +277,8 @@ public class WarBlockListener implements Listener { if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) { // breakage of spawn if (team != null && team.isSpawnLocation(block.getLocation())) { - 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)) { + if (player.getInventory().containsAtLeast(team.getKind().getBlockHead(), 1)) { War.war.badMsg(player, "You already have a " + team.getName() + " block."); event.setCancelled(true); return; @@ -300,7 +298,7 @@ public class WarBlockListener implements Listener { 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())); + ItemStack teamKindBlock = lostFlagTeam.getKind().getBlockHead(); player.getInventory().clear(); player.getInventory().addItem(teamKindBlock); warzone.addFlagThief(lostFlagTeam, player.getName()); @@ -350,7 +348,7 @@ public class WarBlockListener implements Listener { } 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); + ItemStack tntBlock = new ItemStack(Material.TNT); tntBlock.setDurability((short)8); player.getInventory().clear(); player.getInventory().addItem(tntBlock); @@ -393,7 +391,7 @@ public class WarBlockListener implements Listener { } 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); + ItemStack cakeBlock = new ItemStack(Material.CAKE); cakeBlock.setDurability((short)8); player.getInventory().clear(); player.getInventory().addItem(cakeBlock); diff --git a/war/src/main/java/com/tommytony/war/event/WarEntityListener.java b/war/src/main/java/com/tommytony/war/event/WarEntityListener.java index 8f90fd8..58655f6 100644 --- a/war/src/main/java/com/tommytony/war/event/WarEntityListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarEntityListener.java @@ -1,6 +1,7 @@ package com.tommytony.war.event; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Random; @@ -387,17 +388,7 @@ public class WarEntityListener implements Listener { } 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; + return Arrays.asList(contents); } /** diff --git a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java index cf9eb56..b556271 100644 --- a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java @@ -224,16 +224,8 @@ public class WarPlayerListener implements Listener { if (zone != null && zone.getLoadoutSelections().containsKey(player.getName()) && zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) { event.setUseItemInHand(Result.DENY); - ItemStack inHand = event.getItem(); - - if (inHand != null) { - ItemStack newItemInHand = War.war.copyStack(inHand); - - event.getPlayer().setItemInHand(newItemInHand); - event.setCancelled(true); - - War.war.badMsg(player, "Can't use items while still in spawn."); - } + event.setCancelled(true); + War.war.badMsg(player, "Can't use items while still in spawn."); } if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENDER_CHEST) { event.setCancelled(true); @@ -846,7 +838,7 @@ public class WarPlayerListener implements Listener { if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName()) && playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) { LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()); - List loadouts = (List)new ArrayList(playerTeam.getInventories().resolveNewLoadouts()).clone(); + List loadouts = new ArrayList(playerTeam.getInventories().resolveNewLoadouts()); for (Iterator it = loadouts.iterator(); it.hasNext();) { Loadout ldt = it.next(); if ("first".equals(ldt.getName())) { diff --git a/war/src/main/java/com/tommytony/war/job/HelmetProtectionTask.java b/war/src/main/java/com/tommytony/war/job/HelmetProtectionTask.java index b1086ac..9903acd 100644 --- a/war/src/main/java/com/tommytony/war/job/HelmetProtectionTask.java +++ b/war/src/main/java/com/tommytony/war/job/HelmetProtectionTask.java @@ -37,7 +37,7 @@ public class HelmetProtectionTask implements Runnable { teamBlockMaterial = team.getKind().getMaterial(); // 1) Replace missing block head if (playerInv.getHelmet() == null || playerInv.getHelmet().getType() != teamBlockMaterial) { - playerInv.setHelmet(this.createBlockHead(team)); + playerInv.setHelmet(team.getKind().getBlockHead()); } // 2) Get rid of extra blocks in inventory: only keep one @@ -56,7 +56,7 @@ public class HelmetProtectionTask implements Runnable { int firstEmpty = playerInv.firstEmpty(); if (firstEmpty > 0) { - playerInv.setItem(firstEmpty, this.createBlockHead(team)); + playerInv.setItem(firstEmpty, team.getKind().getBlockHead()); } if (removed > 1) { @@ -69,7 +69,7 @@ public class HelmetProtectionTask implements Runnable { if (zone.isFlagThief(player.getName())) { Team victim = zone.getVictimTeamForFlagThief(player.getName()); player.setItemInHand(null); - player.getInventory().addItem(new ItemStack(victim.getKind().getMaterial(), 2240, victim.getKind().getData(), victim.getKind().getData())); + player.getInventory().addItem(victim.getKind().getBlockData().toItemStack(2240)); } else if (zone.isBombThief(player.getName())) { player.setItemInHand(null); player.getInventory().addItem(new ItemStack(Material.TNT, 2240)); @@ -81,8 +81,4 @@ public class HelmetProtectionTask implements Runnable { } } } - - 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/job/ResetCursorJob.java b/war/src/main/java/com/tommytony/war/job/ResetCursorJob.java index dd932a2..399fc78 100644 --- a/war/src/main/java/com/tommytony/war/job/ResetCursorJob.java +++ b/war/src/main/java/com/tommytony/war/job/ResetCursorJob.java @@ -1,7 +1,6 @@ package com.tommytony.war.job; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import com.tommytony.war.utility.Direction; import com.tommytony.war.volume.BlockInfo; diff --git a/war/src/main/java/com/tommytony/war/mapper/LoadoutTxtMapper.java b/war/src/main/java/com/tommytony/war/mapper/LoadoutTxtMapper.java index b84c012..3be1c7f 100644 --- a/war/src/main/java/com/tommytony/war/mapper/LoadoutTxtMapper.java +++ b/war/src/main/java/com/tommytony/war/mapper/LoadoutTxtMapper.java @@ -39,11 +39,11 @@ public class LoadoutTxtMapper { 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 = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability); 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 = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability); item.setDurability(durability); // enchantments diff --git a/war/src/main/java/com/tommytony/war/mapper/LoadoutYmlMapper.java b/war/src/main/java/com/tommytony/war/mapper/LoadoutYmlMapper.java index 8504328..2b6b6cb 100644 --- a/war/src/main/java/com/tommytony/war/mapper/LoadoutYmlMapper.java +++ b/war/src/main/java/com/tommytony/war/mapper/LoadoutYmlMapper.java @@ -30,7 +30,7 @@ public class LoadoutYmlMapper { public static List fromConfigToLoadouts(ConfigurationSection config, HashMap> loadouts) { List loadoutNames = config.getStringList("names"); loadouts.clear(); - List ldts = new ArrayList(); + List ldts = new ArrayList(); for (String name : loadoutNames) { HashMap newLoadout = new HashMap(); Loadout ldt = fromConfigToLoadout(config, newLoadout, name); @@ -59,11 +59,10 @@ public class LoadoutYmlMapper { } 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); + ItemStack stack = new ItemStack(id, amount, durability); stack.setDurability(durability); if (config.contains(prefix + "enchantments")) { @@ -118,7 +117,7 @@ public class LoadoutYmlMapper { */ public static void fromLoadoutsToConfig(List loadouts, ConfigurationSection section) { Collections.sort(loadouts); - List names = new ArrayList(); + List names = new ArrayList(); for (Loadout ldt : loadouts) { names.add(ldt.getName()); LoadoutYmlMapper.fromLoadoutToConfig(ldt, section); diff --git a/war/src/main/java/com/tommytony/war/mapper/WarYmlMapper.java b/war/src/main/java/com/tommytony/war/mapper/WarYmlMapper.java index 4ff336d..e8f1a36 100644 --- a/war/src/main/java/com/tommytony/war/mapper/WarYmlMapper.java +++ b/war/src/main/java/com/tommytony/war/mapper/WarYmlMapper.java @@ -70,7 +70,7 @@ public class WarYmlMapper { // defaultLoadouts ConfigurationSection loadoutsSection = warRootSection.getConfigurationSection("team.default.loadout"); - War.war.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap())); + War.war.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap>())); // defaultReward ConfigurationSection rewardsSection = warRootSection.getConfigurationSection("team.default.reward"); diff --git a/war/src/main/java/com/tommytony/war/mapper/WarzoneYmlMapper.java b/war/src/main/java/com/tommytony/war/mapper/WarzoneYmlMapper.java index 90f821a..50731fa 100644 --- a/war/src/main/java/com/tommytony/war/mapper/WarzoneYmlMapper.java +++ b/war/src/main/java/com/tommytony/war/mapper/WarzoneYmlMapper.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; import org.bukkit.Location; @@ -14,7 +15,6 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; - import com.tommytony.war.Team; import com.tommytony.war.War; import com.tommytony.war.Warzone; @@ -27,10 +27,8 @@ import com.tommytony.war.structure.Monument; import com.tommytony.war.structure.WarzoneMaterials; import com.tommytony.war.structure.ZoneLobby; import com.tommytony.war.utility.Direction; -import com.tommytony.war.utility.Loadout; import com.tommytony.war.volume.Volume; import com.tommytony.war.volume.ZoneVolume; -import java.util.Map; public class WarzoneYmlMapper { @@ -81,7 +79,7 @@ public class WarzoneYmlMapper { // defaultLoadouts if (warzoneRootSection.contains("team.default.loadout")) { ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection("team.default.loadout"); - warzone.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap())); + warzone.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap>())); } // defaultReward @@ -197,7 +195,7 @@ public class WarzoneYmlMapper { // try lowercase instead - supports custom team names teamInfoPrefix = "team." + teamName.toLowerCase() + ".info."; } - List teamSpawns = new ArrayList(); + List teamSpawns = new ArrayList(); if (warzoneRootSection.contains(teamInfoPrefix + "spawn")) { int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x"); int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y"); @@ -254,11 +252,11 @@ public class WarzoneYmlMapper { if (warzoneRootSection.contains(teamLoadoutPrefix)) { // team specific loadouts ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix); - team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap())); + team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap>())); } else if (warzoneRootSection.contains(teamLoadoutPrefix.toLowerCase())) { // try lowercase instead ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix.toLowerCase()); - team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap())); + team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap>())); } String teamRewardPrefix = "team." + teamName + ".reward"; @@ -594,9 +592,9 @@ public class WarzoneYmlMapper { ConfigurationSection teamInfoSection = teamsSection.createSection(team.getName() + ".info"); - List> spawnSerilization = new ArrayList(); + List> spawnSerilization = new ArrayList>(); for (Location spawn : team.getTeamSpawns()) { - Map map = new HashMap(); + Map map = new HashMap(); map.put("x", spawn.getBlockX()); map.put("y", spawn.getBlockY()); map.put("z", spawn.getBlockZ()); diff --git a/war/src/main/java/com/tommytony/war/utility/Loadout.java b/war/src/main/java/com/tommytony/war/utility/Loadout.java index abbd5d7..8d4728d 100644 --- a/war/src/main/java/com/tommytony/war/utility/Loadout.java +++ b/war/src/main/java/com/tommytony/war/utility/Loadout.java @@ -1,26 +1,21 @@ package com.tommytony.war.utility; -import com.tommytony.war.War; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; -import org.bukkit.Color; + import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerialization; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.bukkit.material.MaterialData; /** * Represents a loadout of items * * @author cmastudios */ -public class Loadout implements Comparable, ConfigurationSerializable { +public class Loadout implements Comparable, ConfigurationSerializable { private String name; private HashMap contents; @@ -36,12 +31,7 @@ public class Loadout implements Comparable, ConfigurationSerializable { ConfigurationSerialization.registerClass(Loadout.class); } - public int compareTo(Object o) { - if (!(o instanceof Loadout)) { - throw new ClassCastException(this.getClass().getCanonicalName() - + " is not comparable to a " + o.getClass().getCanonicalName()); - } - Loadout ldt = (Loadout) o; + public int compareTo(Loadout ldt) { if ("default".equals(ldt.getName()) && !"default".equals(this.getName())) { return -1; } else if ("default".equals(this.getName()) && !"default".equals(ldt.getName())) { @@ -88,7 +78,7 @@ public class Loadout implements Comparable, ConfigurationSerializable { } public static HashMap> toLegacyFormat(List loadouts) { - HashMap> oldLoadouts = new HashMap(); + HashMap> oldLoadouts = new HashMap>(); for (Loadout ldt : loadouts) { oldLoadouts.put(ldt.getName(), ldt.getContents()); } @@ -106,88 +96,22 @@ public class Loadout implements Comparable, ConfigurationSerializable { // For future use public Map serialize() { - Map config = new HashMap(); + Map config = new HashMap(); config.put("slots", this.toIntList(contents.keySet())); for (Integer slot : contents.keySet()) { - Map slotConfig = new HashMap(); ItemStack stack = contents.get(slot); - slotConfig.put("id", stack.getTypeId()); - slotConfig.put("data", stack.getData().getData()); - slotConfig.put("amount", stack.getAmount()); - slotConfig.put("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); - } - slotConfig.put("enchantments", enchantmentStringList); - } - if (stack.hasItemMeta() && stack.getItemMeta() instanceof LeatherArmorMeta - && ((LeatherArmorMeta) stack.getItemMeta()).getColor() != null) { - LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta(); - int rgb = meta.getColor().asRGB(); - slotConfig.put("armorcolor", rgb); - } - if (stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) { - ItemMeta meta = stack.getItemMeta(); - slotConfig.put("name", meta.getDisplayName()); - } - if (stack.hasItemMeta() && stack.getItemMeta().hasLore()) { - ItemMeta meta = stack.getItemMeta(); - slotConfig.put("lore", meta.getLore()); - } - config.put(slot.toString(), slotConfig); + config.put(slot.toString(), stack.serialize()); } config.put("permission", permission); return config; } + @SuppressWarnings("unchecked") public static Loadout deserialize(Map config) { - HashMap contents = new HashMap(); + HashMap contents = new HashMap(); List slots = (List) config.get("slots"); for (Integer slot : slots) { - Map slotConfig = (Map) config.get(slot.toString()); - int id = (Integer) slotConfig.get("id"); - byte data = (Byte) slotConfig.get("data"); - int amount = (Integer) slotConfig.get("amount"); - short durability = (Short) slotConfig.get("durability"); - - ItemStack stack = new ItemStack(id, amount, durability); - stack.setData(new MaterialData(id, data)); - - if (slotConfig.containsKey("enchantments")) { - List enchantmentStringList = (List) slotConfig.get("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]); - War.war.safelyEnchant(stack, Enchantment.getById(enchantId), level); - } - } - } - if (slotConfig.containsKey("armorcolor")) { - int rgb = (Integer) slotConfig.get("armorcolor"); - Color clr = Color.fromRGB(rgb); - LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta(); - meta.setColor(clr); - stack.setItemMeta(meta); - } - if (slotConfig.containsKey("name")) { - String itemName = (String) slotConfig.get("name"); - ItemMeta meta = stack.getItemMeta(); - meta.setDisplayName(itemName); - stack.setItemMeta(meta); - } - if (slotConfig.containsKey("lore")) { - List itemLore = (List) slotConfig.get("lore"); - ItemMeta meta = stack.getItemMeta(); - meta.setLore(itemLore); - stack.setItemMeta(meta); - } - contents.put(slot, stack); + contents.put(slot, ItemStack.deserialize((Map) config.get(slot.toString()))); } String permission = ""; if (config.containsKey("permission")) {