mirror of
https://github.com/taoneill/war.git
synced 2024-12-03 15:43:27 +01:00
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:
parent
ea0df4f22b
commit
890e78fd5d
@ -81,7 +81,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.6.1-R0.1-SNAPSHOT</version>
|
<version>1.6.2-R0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.kitteh</groupId>
|
<groupId>org.kitteh</groupId>
|
||||||
|
@ -57,8 +57,8 @@ public class Team {
|
|||||||
this.teamConfig = new TeamConfigBag(warzone);
|
this.teamConfig = new TeamConfigBag(warzone);
|
||||||
this.inventories = new InventoryBag(warzone); // important constructors for cascading configs
|
this.inventories = new InventoryBag(warzone); // important constructors for cascading configs
|
||||||
this.setName(name);
|
this.setName(name);
|
||||||
this.teamSpawns = new ArrayList(teamSpawn);
|
this.teamSpawns = new ArrayList<Location>(teamSpawn);
|
||||||
this.spawnVolumes = new HashMap();
|
this.spawnVolumes = new HashMap<Location, Volume>();
|
||||||
for (Location spawn : teamSpawn) {
|
for (Location spawn : teamSpawn) {
|
||||||
this.setSpawnVolume(spawn, new Volume(name + teamSpawns.indexOf(spawn), warzone.getWorld()));
|
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 - 1, this.kind);
|
||||||
this.setBlock(x - 2, y - 1, z - 2, this.kind);
|
this.setBlock(x - 2, y - 1, z - 2, this.kind);
|
||||||
|
|
||||||
BlockFace facing = null;
|
|
||||||
BlockFace opposite = null;
|
|
||||||
if (yaw >= 0 && yaw < 90) {
|
if (yaw >= 0 && yaw < 90) {
|
||||||
facing = Direction.NORTH_WEST();
|
|
||||||
opposite = Direction.SOUTH_EAST();
|
|
||||||
signData = 10;
|
signData = 10;
|
||||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.WEST(), 2);
|
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);
|
this.setBlock(x + 2, y + 3, z - 2, this.kind);
|
||||||
}
|
}
|
||||||
} else if (yaw >= 90 && yaw <= 180) {
|
} else if (yaw >= 90 && yaw <= 180) {
|
||||||
facing = Direction.NORTH_EAST();
|
|
||||||
opposite = Direction.SOUTH_WEST();
|
|
||||||
signData = 14;
|
signData = 14;
|
||||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.EAST(), 2);
|
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.NORTH(), 2).getRelative(Direction.EAST(), 2);
|
||||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||||
@ -249,8 +243,6 @@ public class Team {
|
|||||||
this.setBlock(x + 2, y + 3, z + 2, this.kind);
|
this.setBlock(x + 2, y + 3, z + 2, this.kind);
|
||||||
}
|
}
|
||||||
} else if (yaw >= 180 && yaw < 270) {
|
} else if (yaw >= 180 && yaw < 270) {
|
||||||
facing = Direction.SOUTH_EAST();
|
|
||||||
opposite = Direction.NORTH_WEST();
|
|
||||||
signData = 2;
|
signData = 2;
|
||||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.EAST(), 2);
|
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.EAST(), 2);
|
||||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||||
@ -281,8 +273,6 @@ public class Team {
|
|||||||
this.setBlock(x - 2, y + 3, z + 2, this.kind);
|
this.setBlock(x - 2, y + 3, z + 2, this.kind);
|
||||||
}
|
}
|
||||||
} else if (yaw >= 270 && yaw <= 360) {
|
} else if (yaw >= 270 && yaw <= 360) {
|
||||||
facing = Direction.SOUTH_WEST();
|
|
||||||
opposite = Direction.NORTH_EAST();
|
|
||||||
signData = 6;
|
signData = 6;
|
||||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.WEST(), 2);
|
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(Direction.SOUTH(), 2).getRelative(Direction.WEST(), 2);
|
||||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||||
|
@ -18,6 +18,7 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
@ -307,6 +308,7 @@ public class War extends JavaPlugin {
|
|||||||
this.getServer().getScheduler().cancelTasks(this);
|
this.getServer().getScheduler().cancelTasks(this);
|
||||||
this.playerListener.purgeLatestPositions();
|
this.playerListener.purgeLatestPositions();
|
||||||
|
|
||||||
|
HandlerList.unregisterAll(this);
|
||||||
this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO);
|
this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO);
|
||||||
this.setLoaded(false);
|
this.setLoaded(false);
|
||||||
}
|
}
|
||||||
@ -350,13 +352,9 @@ public class War extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public ItemStack copyStack(ItemStack originalStack) {
|
public ItemStack copyStack(ItemStack originalStack) {
|
||||||
ItemStack copiedStack = new ItemStack(originalStack.getType(), originalStack.getAmount(), originalStack.getDurability(), new Byte(originalStack.getData().getData()));
|
return originalStack.clone();
|
||||||
copiedStack.setDurability(originalStack.getDurability());
|
|
||||||
copiedStack.setItemMeta(originalStack.getItemMeta());
|
|
||||||
copyEnchantments(originalStack, copiedStack);
|
|
||||||
|
|
||||||
return copiedStack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyEnchantments(ItemStack originalStack, ItemStack copiedStack) {
|
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) {
|
public String updateTeamFromNamedParams(Team team, CommandSender commandSender, String[] arguments) {
|
||||||
try {
|
try {
|
||||||
Map<String, String> namedParams = new HashMap();
|
Map<String, String> namedParams = new HashMap<String, String>();
|
||||||
Map<String, String> thirdParameter = new HashMap();
|
Map<String, String> thirdParameter = new HashMap<String, String>();
|
||||||
for (String namedPair : arguments) {
|
for (String namedPair : arguments) {
|
||||||
String[] pairSplit = namedPair.split(":");
|
String[] pairSplit = namedPair.split(":");
|
||||||
if (pairSplit.length == 2) {
|
if (pairSplit.length == 2) {
|
||||||
@ -468,8 +466,8 @@ public class War extends JavaPlugin {
|
|||||||
|
|
||||||
public String updateZoneFromNamedParams(Warzone warzone, CommandSender commandSender, String[] arguments) {
|
public String updateZoneFromNamedParams(Warzone warzone, CommandSender commandSender, String[] arguments) {
|
||||||
try {
|
try {
|
||||||
Map<String, String> namedParams = new HashMap();
|
Map<String, String> namedParams = new HashMap<String, String>();
|
||||||
Map<String, String> thirdParameter = new HashMap();
|
Map<String, String> thirdParameter = new HashMap<String, String>();
|
||||||
for (String namedPair : arguments) {
|
for (String namedPair : arguments) {
|
||||||
String[] pairSplit = namedPair.split(":");
|
String[] pairSplit = namedPair.split(":");
|
||||||
if (pairSplit.length == 2) {
|
if (pairSplit.length == 2) {
|
||||||
@ -662,8 +660,8 @@ public class War extends JavaPlugin {
|
|||||||
|
|
||||||
public String updateFromNamedParams(CommandSender commandSender, String[] arguments) {
|
public String updateFromNamedParams(CommandSender commandSender, String[] arguments) {
|
||||||
try {
|
try {
|
||||||
Map<String, String> namedParams = new HashMap();
|
Map<String, String> namedParams = new HashMap<String, String>();
|
||||||
Map<String, String> thirdParameter = new HashMap();
|
Map<String, String> thirdParameter = new HashMap<String, String>();
|
||||||
for (String namedPair : arguments) {
|
for (String namedPair : arguments) {
|
||||||
String[] pairSplit = namedPair.split(":");
|
String[] pairSplit = namedPair.split(":");
|
||||||
if (pairSplit.length == 2) {
|
if (pairSplit.length == 2) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.tommytony.war;
|
package com.tommytony.war;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -20,6 +19,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.getspout.spoutapi.SpoutManager;
|
import org.getspout.spoutapi.SpoutManager;
|
||||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
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.spout.SpoutDisplayer;
|
||||||
import com.tommytony.war.structure.Bomb;
|
import com.tommytony.war.structure.Bomb;
|
||||||
import com.tommytony.war.structure.Cake;
|
import com.tommytony.war.structure.Cake;
|
||||||
import com.tommytony.war.structure.Monument;
|
|
||||||
import com.tommytony.war.structure.HubLobbyMaterials;
|
import com.tommytony.war.structure.HubLobbyMaterials;
|
||||||
|
import com.tommytony.war.structure.Monument;
|
||||||
import com.tommytony.war.structure.WarzoneMaterials;
|
import com.tommytony.war.structure.WarzoneMaterials;
|
||||||
import com.tommytony.war.structure.ZoneLobby;
|
import com.tommytony.war.structure.ZoneLobby;
|
||||||
import com.tommytony.war.structure.ZoneWallGuard;
|
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.BlockInfo;
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
import com.tommytony.war.volume.ZoneVolume;
|
import com.tommytony.war.volume.ZoneVolume;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -432,23 +431,23 @@ public class Warzone {
|
|||||||
boolean helmetIsInLoadout = false;
|
boolean helmetIsInLoadout = false;
|
||||||
for (Integer slot : loadout.keySet()) {
|
for (Integer slot : loadout.keySet()) {
|
||||||
if (slot == 100) {
|
if (slot == 100) {
|
||||||
playerInv.setBoots(War.war.copyStack(loadout.get(slot)));
|
playerInv.setBoots(loadout.get(slot).clone());
|
||||||
} else if (slot == 101) {
|
} else if (slot == 101) {
|
||||||
playerInv.setLeggings(War.war.copyStack(loadout.get(slot)));
|
playerInv.setLeggings(loadout.get(slot).clone());
|
||||||
} else if (slot == 102) {
|
} else if (slot == 102) {
|
||||||
playerInv.setChestplate(War.war.copyStack(loadout.get(slot)));
|
playerInv.setChestplate(loadout.get(slot).clone());
|
||||||
} else if (slot == 103) {
|
} else if (slot == 103) {
|
||||||
playerInv.setHelmet(War.war.copyStack(loadout.get(slot)));
|
playerInv.setHelmet(loadout.get(slot).clone());
|
||||||
helmetIsInLoadout = true;
|
helmetIsInLoadout = true;
|
||||||
} else {
|
} else {
|
||||||
ItemStack item = loadout.get(slot);
|
ItemStack item = loadout.get(slot);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
playerInv.addItem(War.war.copyStack(item));
|
playerInv.addItem(item.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
|
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 {
|
} else {
|
||||||
if (!helmetIsInLoadout) {
|
if (!helmetIsInLoadout) {
|
||||||
ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
|
ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
|
||||||
@ -900,12 +899,12 @@ public class Warzone {
|
|||||||
for (Player p : t.getPlayers()) {
|
for (Player p : t.getPlayers()) {
|
||||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||||
if (sp.isSpoutCraftEnabled()) {
|
if (sp.isSpoutCraftEnabled()) {
|
||||||
sp.sendNotification(
|
sp.sendNotification(
|
||||||
SpoutDisplayer.cleanForNotification("Round over! " + playerTeam.getKind().getColor() + playerTeam.getName()),
|
SpoutDisplayer.cleanForNotification("Round over! " + playerTeam.getKind().getColor() + playerTeam.getName()),
|
||||||
SpoutDisplayer.cleanForNotification("ran out of lives."),
|
SpoutDisplayer.cleanForNotification("ran out of lives."),
|
||||||
playerTeam.getKind().getMaterial(),
|
playerTeam.getKind().getMaterial(),
|
||||||
playerTeam.getKind().getData(),
|
playerTeam.getKind().getDyeColor().getWoolData(),
|
||||||
10000);
|
10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -966,12 +965,12 @@ public class Warzone {
|
|||||||
for (Player p : victim.getPlayers()) {
|
for (Player p : victim.getPlayers()) {
|
||||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||||
if (sp.isSpoutCraftEnabled()) {
|
if (sp.isSpoutCraftEnabled()) {
|
||||||
sp.sendNotification(
|
sp.sendNotification(
|
||||||
SpoutDisplayer.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " dropped"),
|
SpoutDisplayer.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " dropped"),
|
||||||
SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "your flag."),
|
SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "your flag."),
|
||||||
playerTeam.getKind().getMaterial(),
|
playerTeam.getKind().getMaterial(),
|
||||||
playerTeam.getKind().getData(),
|
playerTeam.getKind().getDyeColor().getWoolData(),
|
||||||
5000);
|
5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,8 @@ package com.tommytony.war.command;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.config.WarConfig;
|
import com.tommytony.war.config.WarConfig;
|
||||||
|
@ -9,11 +9,12 @@ import com.tommytony.war.War;
|
|||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.utility.Loadout;
|
import com.tommytony.war.utility.Loadout;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InventoryBag {
|
public class InventoryBag {
|
||||||
|
|
||||||
private List<Loadout> loadouts = new ArrayList();
|
private List<Loadout> loadouts = new ArrayList<Loadout>();
|
||||||
private HashMap<Integer, ItemStack> reward = null;
|
private HashMap<Integer, ItemStack> reward = null;
|
||||||
|
|
||||||
private Warzone warzone;
|
private Warzone warzone;
|
||||||
@ -82,7 +83,7 @@ public class InventoryBag {
|
|||||||
} else if (War.war.getDefaultInventories().hasLoadouts()) {
|
} else if (War.war.getDefaultInventories().hasLoadouts()) {
|
||||||
return War.war.getDefaultInventories().resolveNewLoadouts();
|
return War.war.getDefaultInventories().resolveNewLoadouts();
|
||||||
} else {
|
} else {
|
||||||
return new ArrayList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,36 +1,40 @@
|
|||||||
package com.tommytony.war.config;
|
package com.tommytony.war.config;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
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;
|
import org.getspout.spoutapi.gui.Color;
|
||||||
|
|
||||||
public enum TeamKind {
|
public enum TeamKind {
|
||||||
WHITE ((byte) 0, Material.WOOL, ChatColor.WHITE, 450),
|
WHITE (DyeColor.WHITE, Material.WOOL, ChatColor.WHITE, 450),
|
||||||
ORANGE ((byte) 1, Material.WOOL, ChatColor.GOLD, 51),
|
ORANGE (DyeColor.ORANGE, Material.WOOL, ChatColor.GOLD, 51),
|
||||||
MAGENTA ((byte) 2, Material.WOOL, ChatColor.LIGHT_PURPLE, 353),
|
MAGENTA (DyeColor.MAGENTA, Material.WOOL, ChatColor.LIGHT_PURPLE, 353),
|
||||||
BLUE ((byte) 3, Material.WOOL, ChatColor.BLUE, 23),
|
BLUE (DyeColor.LIGHT_BLUE, Material.WOOL, ChatColor.BLUE, 23),
|
||||||
GOLD ((byte) 4, Material.WOOL, ChatColor.YELLOW, 403), // yellow = gold
|
GOLD (DyeColor.YELLOW, Material.WOOL, ChatColor.YELLOW, 403), // yellow = gold
|
||||||
GREEN ((byte) 5, Material.WOOL, ChatColor.GREEN, 612),
|
GREEN (DyeColor.LIME, Material.WOOL, ChatColor.GREEN, 612),
|
||||||
PINK ((byte) 6, Material.WOOL, ChatColor.LIGHT_PURPLE, 929),
|
PINK (DyeColor.PINK, Material.WOOL, ChatColor.LIGHT_PURPLE, 929),
|
||||||
GRAY ((byte) 7, Material.WOOL, ChatColor.DARK_GRAY, 600),
|
GRAY (DyeColor.GRAY, Material.WOOL, ChatColor.DARK_GRAY, 600),
|
||||||
IRON ((byte) 8, Material.WOOL, ChatColor.GRAY, 154), // lightgrey = iron
|
IRON (DyeColor.SILVER, Material.WOOL, ChatColor.GRAY, 154), // lightgrey = iron
|
||||||
DIAMOND ((byte) 9, Material.WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond
|
DIAMOND (DyeColor.CYAN, Material.WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond
|
||||||
PURPLE ((byte) 10, Material.WOOL, ChatColor.DARK_PURPLE, 153),
|
PURPLE (DyeColor.PURPLE, Material.WOOL, ChatColor.DARK_PURPLE, 153),
|
||||||
NAVY ((byte) 11, Material.WOOL, ChatColor.DARK_BLUE, 939),
|
NAVY (DyeColor.BLUE, Material.WOOL, ChatColor.DARK_BLUE, 939),
|
||||||
BROWN ((byte) 12, Material.WOOL, ChatColor.DARK_RED, 908),
|
BROWN (DyeColor.BROWN, Material.WOOL, ChatColor.DARK_RED, 908),
|
||||||
DARKGREEN ((byte) 13, Material.WOOL, ChatColor.DARK_GREEN, 612),
|
DARKGREEN (DyeColor.GREEN, Material.WOOL, ChatColor.DARK_GREEN, 612),
|
||||||
RED ((byte) 14, Material.WOOL, ChatColor.RED, 245),
|
RED (DyeColor.RED, Material.WOOL, ChatColor.RED, 245),
|
||||||
BLACK ((byte) 15, Material.WOOL, ChatColor.BLACK, 0);
|
BLACK (DyeColor.BLACK, Material.WOOL, ChatColor.BLACK, 0);
|
||||||
|
|
||||||
private final byte data;
|
private final DyeColor dyeColor;
|
||||||
private final ChatColor color;
|
private final ChatColor chatColor;
|
||||||
private final Material material;
|
private final Material material;
|
||||||
private final int potionEffectColor;
|
private final int potionEffectColor;
|
||||||
|
|
||||||
private TeamKind(byte data, Material material, ChatColor color, int potionEffectColor) {
|
private TeamKind(DyeColor blockHeadColor, Material material, ChatColor color, int potionEffectColor) {
|
||||||
this.data = data;
|
this.dyeColor = blockHeadColor;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
this.color = color;
|
this.chatColor = color;
|
||||||
this.potionEffectColor = potionEffectColor;
|
this.potionEffectColor = potionEffectColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,100 +48,58 @@ public enum TeamKind {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get wool block data for the dye color.
|
||||||
|
*
|
||||||
|
* @return wool color data value
|
||||||
|
*/
|
||||||
public byte getData() {
|
public byte getData() {
|
||||||
return this.data;
|
return this.dyeColor.getWoolData();
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
public Material getMaterial() {
|
||||||
return this.material;
|
return this.material;
|
||||||
}
|
}
|
||||||
@ -147,7 +109,31 @@ public enum TeamKind {
|
|||||||
return super.toString().toLowerCase();
|
return super.toString().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get color of the team's potion effect, for thieves.
|
||||||
|
*
|
||||||
|
* @return potion effect color.
|
||||||
|
*/
|
||||||
public int getPotionEffectColor() {
|
public int getPotionEffectColor() {
|
||||||
return this.potionEffectColor;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,8 +168,7 @@ public class WarBlockListener implements Listener {
|
|||||||
// Just give the user his f&s back but almost broken (max durability is 8).
|
// 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);
|
newItemInHand = new ItemStack(Material.FLINT_AND_STEEL, 1, (short)1);
|
||||||
} else {
|
} else {
|
||||||
newItemInHand = new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData());
|
newItemInHand = inHand.clone();
|
||||||
newItemInHand.setDurability(inHand.getDurability());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event.getPlayer().setItemInHand(newItemInHand);
|
event.getPlayer().setItemInHand(newItemInHand);
|
||||||
@ -278,9 +277,8 @@ public class WarBlockListener implements Listener {
|
|||||||
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||||
// breakage of spawn
|
// breakage of spawn
|
||||||
if (team != null && team.isSpawnLocation(block.getLocation())) {
|
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
|
// 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.");
|
War.war.badMsg(player, "You already have a " + team.getName() + " block.");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -300,7 +298,7 @@ public class WarBlockListener implements Listener {
|
|||||||
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
|
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
|
||||||
if (lostFlagTeam.getPlayers().size() != 0) {
|
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
|
// 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().clear();
|
||||||
player.getInventory().addItem(teamKindBlock);
|
player.getInventory().addItem(teamKindBlock);
|
||||||
warzone.addFlagThief(lostFlagTeam, player.getName());
|
warzone.addFlagThief(lostFlagTeam, player.getName());
|
||||||
@ -350,7 +348,7 @@ public class WarBlockListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
Bomb bomb = warzone.getBombForBlock(block);
|
Bomb bomb = warzone.getBombForBlock(block);
|
||||||
// player just broke the bomb block: cancel to avoid drop, give player the block, set block to air
|
// 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);
|
tntBlock.setDurability((short)8);
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
player.getInventory().addItem(tntBlock);
|
player.getInventory().addItem(tntBlock);
|
||||||
@ -393,7 +391,7 @@ public class WarBlockListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
Cake cake = warzone.getCakeForBlock(block);
|
Cake cake = warzone.getCakeForBlock(block);
|
||||||
// player just broke the cake block: cancel to avoid drop, give player the block, set block to air
|
// 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);
|
cakeBlock.setDurability((short)8);
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
player.getInventory().addItem(cakeBlock);
|
player.getInventory().addItem(cakeBlock);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.tommytony.war.event;
|
package com.tommytony.war.event;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@ -387,17 +388,7 @@ public class WarEntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<ItemStack> copyItems(ItemStack[] contents) {
|
private List<ItemStack> copyItems(ItemStack[] contents) {
|
||||||
List<ItemStack> list = new ArrayList<ItemStack>();
|
return Arrays.asList(contents);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -224,16 +224,8 @@ public class WarPlayerListener implements Listener {
|
|||||||
if (zone != null && zone.getLoadoutSelections().containsKey(player.getName())
|
if (zone != null && zone.getLoadoutSelections().containsKey(player.getName())
|
||||||
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||||
event.setUseItemInHand(Result.DENY);
|
event.setUseItemInHand(Result.DENY);
|
||||||
ItemStack inHand = event.getItem();
|
event.setCancelled(true);
|
||||||
|
War.war.badMsg(player, "Can't use items while still in spawn.");
|
||||||
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENDER_CHEST) {
|
if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENDER_CHEST) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -846,7 +838,7 @@ public class WarPlayerListener implements Listener {
|
|||||||
if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName())
|
if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName())
|
||||||
&& playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) {
|
&& playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) {
|
||||||
LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName());
|
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();) {
|
for (Iterator<Loadout> it = loadouts.iterator(); it.hasNext();) {
|
||||||
Loadout ldt = it.next();
|
Loadout ldt = it.next();
|
||||||
if ("first".equals(ldt.getName())) {
|
if ("first".equals(ldt.getName())) {
|
||||||
|
@ -37,7 +37,7 @@ public class HelmetProtectionTask implements Runnable {
|
|||||||
teamBlockMaterial = team.getKind().getMaterial();
|
teamBlockMaterial = team.getKind().getMaterial();
|
||||||
// 1) Replace missing block head
|
// 1) Replace missing block head
|
||||||
if (playerInv.getHelmet() == null || playerInv.getHelmet().getType() != teamBlockMaterial) {
|
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
|
// 2) Get rid of extra blocks in inventory: only keep one
|
||||||
@ -56,7 +56,7 @@ public class HelmetProtectionTask implements Runnable {
|
|||||||
|
|
||||||
int firstEmpty = playerInv.firstEmpty();
|
int firstEmpty = playerInv.firstEmpty();
|
||||||
if (firstEmpty > 0) {
|
if (firstEmpty > 0) {
|
||||||
playerInv.setItem(firstEmpty, this.createBlockHead(team));
|
playerInv.setItem(firstEmpty, team.getKind().getBlockHead());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removed > 1) {
|
if (removed > 1) {
|
||||||
@ -69,7 +69,7 @@ public class HelmetProtectionTask implements Runnable {
|
|||||||
if (zone.isFlagThief(player.getName())) {
|
if (zone.isFlagThief(player.getName())) {
|
||||||
Team victim = zone.getVictimTeamForFlagThief(player.getName());
|
Team victim = zone.getVictimTeamForFlagThief(player.getName());
|
||||||
player.setItemInHand(null);
|
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())) {
|
} else if (zone.isBombThief(player.getName())) {
|
||||||
player.setItemInHand(null);
|
player.setItemInHand(null);
|
||||||
player.getInventory().addItem(new ItemStack(Material.TNT, 2240));
|
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()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.tommytony.war.job;
|
package com.tommytony.war.job;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
|
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
import com.tommytony.war.volume.BlockInfo;
|
import com.tommytony.war.volume.BlockInfo;
|
||||||
|
@ -39,11 +39,11 @@ public class LoadoutTxtMapper {
|
|||||||
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||||
} else if (itemStrSplit.length == 5) {
|
} else if (itemStrSplit.length == 5) {
|
||||||
short durability = Short.parseShort(itemStrSplit[3]);
|
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);
|
item.setDurability(durability);
|
||||||
} else if (itemStrSplit.length == 6) {
|
} else if (itemStrSplit.length == 6) {
|
||||||
short durability = Short.parseShort(itemStrSplit[3]);
|
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);
|
item.setDurability(durability);
|
||||||
|
|
||||||
// enchantments
|
// enchantments
|
||||||
|
@ -30,7 +30,7 @@ public class LoadoutYmlMapper {
|
|||||||
public static List<Loadout> fromConfigToLoadouts(ConfigurationSection config, HashMap<String, HashMap<Integer, ItemStack>> loadouts) {
|
public static List<Loadout> fromConfigToLoadouts(ConfigurationSection config, HashMap<String, HashMap<Integer, ItemStack>> loadouts) {
|
||||||
List<String> loadoutNames = config.getStringList("names");
|
List<String> loadoutNames = config.getStringList("names");
|
||||||
loadouts.clear();
|
loadouts.clear();
|
||||||
List<Loadout> ldts = new ArrayList();
|
List<Loadout> ldts = new ArrayList<Loadout>();
|
||||||
for (String name : loadoutNames) {
|
for (String name : loadoutNames) {
|
||||||
HashMap<Integer, ItemStack> newLoadout = new HashMap<Integer, ItemStack>();
|
HashMap<Integer, ItemStack> newLoadout = new HashMap<Integer, ItemStack>();
|
||||||
Loadout ldt = fromConfigToLoadout(config, newLoadout, name);
|
Loadout ldt = fromConfigToLoadout(config, newLoadout, name);
|
||||||
@ -59,11 +59,10 @@ public class LoadoutYmlMapper {
|
|||||||
}
|
}
|
||||||
String prefix = loadoutName + "." + slot + ".";
|
String prefix = loadoutName + "." + slot + ".";
|
||||||
int id = config.getInt(prefix + "id");
|
int id = config.getInt(prefix + "id");
|
||||||
byte data = (byte)config.getInt(prefix + "data");
|
|
||||||
int amount = config.getInt(prefix + "amount");
|
int amount = config.getInt(prefix + "amount");
|
||||||
short durability = (short)config.getInt(prefix + "durability");
|
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);
|
stack.setDurability(durability);
|
||||||
|
|
||||||
if (config.contains(prefix + "enchantments")) {
|
if (config.contains(prefix + "enchantments")) {
|
||||||
@ -118,7 +117,7 @@ public class LoadoutYmlMapper {
|
|||||||
*/
|
*/
|
||||||
public static void fromLoadoutsToConfig(List<Loadout> loadouts, ConfigurationSection section) {
|
public static void fromLoadoutsToConfig(List<Loadout> loadouts, ConfigurationSection section) {
|
||||||
Collections.sort(loadouts);
|
Collections.sort(loadouts);
|
||||||
List<String> names = new ArrayList();
|
List<String> names = new ArrayList<String>();
|
||||||
for (Loadout ldt : loadouts) {
|
for (Loadout ldt : loadouts) {
|
||||||
names.add(ldt.getName());
|
names.add(ldt.getName());
|
||||||
LoadoutYmlMapper.fromLoadoutToConfig(ldt, section);
|
LoadoutYmlMapper.fromLoadoutToConfig(ldt, section);
|
||||||
|
@ -70,7 +70,7 @@ public class WarYmlMapper {
|
|||||||
|
|
||||||
// defaultLoadouts
|
// defaultLoadouts
|
||||||
ConfigurationSection loadoutsSection = warRootSection.getConfigurationSection("team.default.loadout");
|
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
|
// defaultReward
|
||||||
ConfigurationSection rewardsSection = warRootSection.getConfigurationSection("team.default.reward");
|
ConfigurationSection rewardsSection = warRootSection.getConfigurationSection("team.default.reward");
|
||||||
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -14,7 +15,6 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.Team;
|
import com.tommytony.war.Team;
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.Warzone;
|
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.WarzoneMaterials;
|
||||||
import com.tommytony.war.structure.ZoneLobby;
|
import com.tommytony.war.structure.ZoneLobby;
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
import com.tommytony.war.utility.Loadout;
|
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
import com.tommytony.war.volume.ZoneVolume;
|
import com.tommytony.war.volume.ZoneVolume;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class WarzoneYmlMapper {
|
public class WarzoneYmlMapper {
|
||||||
|
|
||||||
@ -81,7 +79,7 @@ public class WarzoneYmlMapper {
|
|||||||
// defaultLoadouts
|
// defaultLoadouts
|
||||||
if (warzoneRootSection.contains("team.default.loadout")) {
|
if (warzoneRootSection.contains("team.default.loadout")) {
|
||||||
ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection("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
|
// defaultReward
|
||||||
@ -197,7 +195,7 @@ public class WarzoneYmlMapper {
|
|||||||
// try lowercase instead - supports custom team names
|
// try lowercase instead - supports custom team names
|
||||||
teamInfoPrefix = "team." + teamName.toLowerCase() + ".info.";
|
teamInfoPrefix = "team." + teamName.toLowerCase() + ".info.";
|
||||||
}
|
}
|
||||||
List<Location> teamSpawns = new ArrayList();
|
List<Location> teamSpawns = new ArrayList<Location>();
|
||||||
if (warzoneRootSection.contains(teamInfoPrefix + "spawn")) {
|
if (warzoneRootSection.contains(teamInfoPrefix + "spawn")) {
|
||||||
int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x");
|
int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x");
|
||||||
int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y");
|
int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y");
|
||||||
@ -254,11 +252,11 @@ public class WarzoneYmlMapper {
|
|||||||
if (warzoneRootSection.contains(teamLoadoutPrefix)) {
|
if (warzoneRootSection.contains(teamLoadoutPrefix)) {
|
||||||
// team specific loadouts
|
// team specific loadouts
|
||||||
ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix);
|
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())) {
|
} else if (warzoneRootSection.contains(teamLoadoutPrefix.toLowerCase())) {
|
||||||
// try lowercase instead
|
// try lowercase instead
|
||||||
ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix.toLowerCase());
|
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";
|
String teamRewardPrefix = "team." + teamName + ".reward";
|
||||||
@ -594,9 +592,9 @@ public class WarzoneYmlMapper {
|
|||||||
|
|
||||||
ConfigurationSection teamInfoSection = teamsSection.createSection(team.getName() + ".info");
|
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()) {
|
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("x", spawn.getBlockX());
|
||||||
map.put("y", spawn.getBlockY());
|
map.put("y", spawn.getBlockY());
|
||||||
map.put("z", spawn.getBlockZ());
|
map.put("z", spawn.getBlockZ());
|
||||||
|
@ -1,26 +1,21 @@
|
|||||||
package com.tommytony.war.utility;
|
package com.tommytony.war.utility;
|
||||||
|
|
||||||
import com.tommytony.war.War;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.bukkit.Color;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
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
|
* Represents a loadout of items
|
||||||
*
|
*
|
||||||
* @author cmastudios
|
* @author cmastudios
|
||||||
*/
|
*/
|
||||||
public class Loadout implements Comparable, ConfigurationSerializable {
|
public class Loadout implements Comparable<Loadout>, ConfigurationSerializable {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private HashMap<Integer, ItemStack> contents;
|
private HashMap<Integer, ItemStack> contents;
|
||||||
@ -36,12 +31,7 @@ public class Loadout implements Comparable, ConfigurationSerializable {
|
|||||||
ConfigurationSerialization.registerClass(Loadout.class);
|
ConfigurationSerialization.registerClass(Loadout.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Loadout ldt) {
|
||||||
if (!(o instanceof Loadout)) {
|
|
||||||
throw new ClassCastException(this.getClass().getCanonicalName()
|
|
||||||
+ " is not comparable to a " + o.getClass().getCanonicalName());
|
|
||||||
}
|
|
||||||
Loadout ldt = (Loadout) o;
|
|
||||||
if ("default".equals(ldt.getName()) && !"default".equals(this.getName())) {
|
if ("default".equals(ldt.getName()) && !"default".equals(this.getName())) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if ("default".equals(this.getName()) && !"default".equals(ldt.getName())) {
|
} 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) {
|
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) {
|
for (Loadout ldt : loadouts) {
|
||||||
oldLoadouts.put(ldt.getName(), ldt.getContents());
|
oldLoadouts.put(ldt.getName(), ldt.getContents());
|
||||||
}
|
}
|
||||||
@ -106,88 +96,22 @@ public class Loadout implements Comparable, ConfigurationSerializable {
|
|||||||
|
|
||||||
// For future use
|
// For future use
|
||||||
public Map<String, Object> serialize() {
|
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()));
|
config.put("slots", this.toIntList(contents.keySet()));
|
||||||
for (Integer slot : contents.keySet()) {
|
for (Integer slot : contents.keySet()) {
|
||||||
Map<String, Object> slotConfig = new HashMap();
|
|
||||||
ItemStack stack = contents.get(slot);
|
ItemStack stack = contents.get(slot);
|
||||||
slotConfig.put("id", stack.getTypeId());
|
config.put(slot.toString(), stack.serialize());
|
||||||
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("permission", permission);
|
config.put("permission", permission);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static Loadout deserialize(Map<String, Object> config) {
|
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");
|
List<Integer> slots = (List<Integer>) config.get("slots");
|
||||||
for (Integer slot : slots) {
|
for (Integer slot : slots) {
|
||||||
Map<String, Object> slotConfig = (Map<String, Object>) config.get(slot.toString());
|
contents.put(slot, ItemStack.deserialize((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);
|
|
||||||
}
|
}
|
||||||
String permission = "";
|
String permission = "";
|
||||||
if (config.containsKey("permission")) {
|
if (config.containsKey("permission")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user