TeamKind cleanup, warning fixes, closes gh-631

TeamKind has been changed to store colors in a DyeColor object instead
of using a byte value store. This improves readability and makes the
code future-proof.

All listeners are now unregistered when the plugin gets unloaded. This
removes the need for listeners to check if War is loaded and prevents
duplicate registration. I would prefer if the ability to unload and load
the War plugin was completely removed, however, as there are plugins out
there such as PlugMan that are dedicated to cleanly reloading plugins.

The main purpose of this was to clean up all issues and problems
reported by the eclipse java IDE. 0 warnings are shown by the IDE now.
This commit is contained in:
cmastudios 2013-09-04 19:07:16 -05:00
parent ea0df4f22b
commit 890e78fd5d
17 changed files with 169 additions and 300 deletions

View File

@ -81,7 +81,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.6.1-R0.1-SNAPSHOT</version>
<version>1.6.2-R0.1</version>
</dependency>
<dependency>
<groupId>org.kitteh</groupId>

View File

@ -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<Location>(teamSpawn);
this.spawnVolumes = new HashMap<Location, Volume>();
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)) {

View File

@ -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<String, String> namedParams = new HashMap();
Map<String, String> thirdParameter = new HashMap();
Map<String, String> namedParams = new HashMap<String, String>();
Map<String, String> thirdParameter = new HashMap<String, String>();
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<String, String> namedParams = new HashMap();
Map<String, String> thirdParameter = new HashMap();
Map<String, String> namedParams = new HashMap<String, String>();
Map<String, String> thirdParameter = new HashMap<String, String>();
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<String, String> namedParams = new HashMap();
Map<String, String> thirdParameter = new HashMap();
Map<String, String> namedParams = new HashMap<String, String>();
Map<String, String> thirdParameter = new HashMap<String, String>();
for (String namedPair : arguments) {
String[] pairSplit = namedPair.split(":");
if (pairSplit.length == 2) {

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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<Loadout> loadouts = new ArrayList();
private List<Loadout> loadouts = new ArrayList<Loadout>();
private HashMap<Integer, ItemStack> 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();
}
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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<ItemStack> copyItems(ItemStack[] contents) {
List<ItemStack> list = new ArrayList<ItemStack>();
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);
}
/**

View File

@ -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<Loadout> loadouts = (List<Loadout>)new ArrayList(playerTeam.getInventories().resolveNewLoadouts()).clone();
List<Loadout> loadouts = new ArrayList<Loadout>(playerTeam.getInventories().resolveNewLoadouts());
for (Iterator<Loadout> it = loadouts.iterator(); it.hasNext();) {
Loadout ldt = it.next();
if ("first".equals(ldt.getName())) {

View File

@ -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()));
}
}

View File

@ -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;

View File

@ -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

View File

@ -30,7 +30,7 @@ public class LoadoutYmlMapper {
public static List<Loadout> fromConfigToLoadouts(ConfigurationSection config, HashMap<String, HashMap<Integer, ItemStack>> loadouts) {
List<String> loadoutNames = config.getStringList("names");
loadouts.clear();
List<Loadout> ldts = new ArrayList();
List<Loadout> ldts = new ArrayList<Loadout>();
for (String name : loadoutNames) {
HashMap<Integer, ItemStack> newLoadout = new HashMap<Integer, ItemStack>();
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<Loadout> loadouts, ConfigurationSection section) {
Collections.sort(loadouts);
List<String> names = new ArrayList();
List<String> names = new ArrayList<String>();
for (Loadout ldt : loadouts) {
names.add(ldt.getName());
LoadoutYmlMapper.fromLoadoutToConfig(ldt, section);

View File

@ -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<String, HashMap<Integer, ItemStack>>()));
// defaultReward
ConfigurationSection rewardsSection = warRootSection.getConfigurationSection("team.default.reward");

View File

@ -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<String, HashMap<Integer, ItemStack>>()));
}
// defaultReward
@ -197,7 +195,7 @@ public class WarzoneYmlMapper {
// try lowercase instead - supports custom team names
teamInfoPrefix = "team." + teamName.toLowerCase() + ".info.";
}
List<Location> teamSpawns = new ArrayList();
List<Location> teamSpawns = new ArrayList<Location>();
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<String, HashMap<Integer, ItemStack>>()));
} 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, HashMap<Integer, ItemStack>>()));
}
String teamRewardPrefix = "team." + teamName + ".reward";
@ -594,9 +592,9 @@ public class WarzoneYmlMapper {
ConfigurationSection teamInfoSection = teamsSection.createSection(team.getName() + ".info");
List<Map<String, Object>> spawnSerilization = new ArrayList();
List<Map<String, Object>> spawnSerilization = new ArrayList<Map<String, Object>>();
for (Location spawn : team.getTeamSpawns()) {
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<String, Object>();
map.put("x", spawn.getBlockX());
map.put("y", spawn.getBlockY());
map.put("z", spawn.getBlockZ());

View File

@ -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<Loadout>, ConfigurationSerializable {
private String name;
private HashMap<Integer, ItemStack> 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<String, HashMap<Integer, ItemStack>> toLegacyFormat(List<Loadout> loadouts) {
HashMap<String, HashMap<Integer, ItemStack>> oldLoadouts = new HashMap();
HashMap<String, HashMap<Integer, ItemStack>> oldLoadouts = new HashMap<String, HashMap<Integer, ItemStack>>();
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<String, Object> serialize() {
Map<String, Object> config = new HashMap();
Map<String, Object> config = new HashMap<String, Object>();
config.put("slots", this.toIntList(contents.keySet()));
for (Integer slot : contents.keySet()) {
Map<String, Object> 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<String> enchantmentStringList = new ArrayList<String>();
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<String, Object> config) {
HashMap<Integer, ItemStack> contents = new HashMap();
HashMap<Integer, ItemStack> contents = new HashMap<Integer, ItemStack>();
List<Integer> slots = (List<Integer>) config.get("slots");
for (Integer slot : slots) {
Map<String, Object> slotConfig = (Map<String, Object>) 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<String> enchantmentStringList = (List<String>) 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<String> itemLore = (List<String>) slotConfig.get("lore");
ItemMeta meta = stack.getItemMeta();
meta.setLore(itemLore);
stack.setItemMeta(meta);
}
contents.put(slot, stack);
contents.put(slot, ItemStack.deserialize((Map<String, Object>) config.get(slot.toString())));
}
String permission = "";
if (config.containsKey("permission")) {