mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 04:35:35 +01:00
Forgot to delete the rename-namespace files.
This commit is contained in:
parent
06272803f1
commit
e8e2c0c472
@ -1,913 +0,0 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.TeamSpawnStyle;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.config.InventoryBag;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.TeamConfigBag;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarConfigBag;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.config.WarzoneConfigBag;
|
||||
import com.tommytony.war.jobs.HelmetProtectionTask;
|
||||
import com.tommytony.war.jobs.SpoutFadeOutMessageJob;
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
import com.tommytony.war.spout.SpoutMessenger;
|
||||
import com.tommytony.war.utils.ChatFixUtil;
|
||||
import com.tommytony.war.utils.PlayerState;
|
||||
|
||||
/**
|
||||
* Main class of War
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class War extends JavaPlugin {
|
||||
public static War war;
|
||||
|
||||
// general
|
||||
private WarPlayerListener playerListener = new WarPlayerListener();
|
||||
private WarEntityListener entityListener = new WarEntityListener();
|
||||
private WarBlockListener blockListener = new WarBlockListener();
|
||||
private WarServerListener serverListener = new WarServerListener();
|
||||
|
||||
private WarCommandHandler commandHandler = new WarCommandHandler();
|
||||
private Logger logger;
|
||||
private PluginDescriptionFile desc = null;
|
||||
private boolean loaded = false;
|
||||
private boolean isSpoutServer = false;
|
||||
|
||||
// Zones and hub
|
||||
private List<Warzone> warzones = new ArrayList<Warzone>();
|
||||
private WarHub warHub;
|
||||
|
||||
private final List<String> zoneMakerNames = new ArrayList<String>();
|
||||
private final List<String> commandWhitelist = new ArrayList<String>();
|
||||
|
||||
private final List<Warzone> incompleteZones = new ArrayList<Warzone>();
|
||||
private final List<String> zoneMakersImpersonatingPlayers = new ArrayList<String>();
|
||||
private HashMap<String, PlayerState> disconnected = new HashMap<String, PlayerState>();
|
||||
private final HashMap<String, String> wandBearers = new HashMap<String, String>(); // playername to zonename
|
||||
|
||||
private final List<String> deadlyAdjectives = new ArrayList<String>();
|
||||
private final List<String> killerVerbs = new ArrayList<String>();
|
||||
|
||||
private final InventoryBag defaultInventories = new InventoryBag();
|
||||
|
||||
private final WarConfigBag warConfig = new WarConfigBag();
|
||||
private final WarzoneConfigBag warzoneDefaultConfig = new WarzoneConfigBag();
|
||||
private final TeamConfigBag teamDefaultConfig = new TeamConfigBag();
|
||||
private SpoutMessenger spoutMessenger = null;
|
||||
|
||||
public War() {
|
||||
super();
|
||||
War.war = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onEnable()
|
||||
* @see War.loadWar()
|
||||
*/
|
||||
public void onEnable() {
|
||||
this.loadWar();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onDisable()
|
||||
* @see War.unloadWar()
|
||||
*/
|
||||
public void onDisable() {
|
||||
this.unloadWar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes war
|
||||
*/
|
||||
public void loadWar() {
|
||||
this.setLoaded(true);
|
||||
this.desc = this.getDescription();
|
||||
this.logger = this.getServer().getLogger();
|
||||
|
||||
// Spout server detection
|
||||
try {
|
||||
Class.forName("org.getspout.spoutapi.player.SpoutPlayer");
|
||||
isSpoutServer = true;
|
||||
spoutMessenger = new SpoutMessenger();
|
||||
} catch (ClassNotFoundException e) {
|
||||
isSpoutServer = false;
|
||||
}
|
||||
|
||||
// Register events
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
pm.registerEvents(this.playerListener, this);
|
||||
pm.registerEvents(this.entityListener, this);
|
||||
pm.registerEvents(this.blockListener, this);
|
||||
pm.registerEvents(this.serverListener, this);
|
||||
|
||||
// Add defaults
|
||||
warConfig.put(WarConfig.BUILDINZONESONLY, false);
|
||||
warConfig.put(WarConfig.DISABLEBUILDMESSAGE, false);
|
||||
warConfig.put(WarConfig.DISABLEPVPMESSAGE, false);
|
||||
warConfig.put(WarConfig.MAXZONES, 12);
|
||||
warConfig.put(WarConfig.PVPINZONESONLY, false);
|
||||
warConfig.put(WarConfig.TNTINZONESONLY, false);
|
||||
|
||||
warzoneDefaultConfig.put(WarzoneConfig.AUTOASSIGN, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.BLOCKHEADS, true);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.DISABLED, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.FRIENDLYFIRE, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.GLASSWALLS, true);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.INSTABREAK, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.MINPLAYERS, 1);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.MINTEAMS, 1);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.MONUMENTHEAL, 5);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.NOCREATURES, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.NODROPS, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.PVPINZONE, true);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.RESETONEMPTY, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.RESETONLOAD, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.RESETONUNLOAD, false);
|
||||
warzoneDefaultConfig.put(WarzoneConfig.UNBREAKABLE, false);
|
||||
|
||||
teamDefaultConfig.put(TeamConfig.FLAGMUSTBEHOME, true);
|
||||
teamDefaultConfig.put(TeamConfig.FLAGPOINTSONLY, false);
|
||||
teamDefaultConfig.put(TeamConfig.FLAGRETURN, FlagReturn.BOTH);
|
||||
teamDefaultConfig.put(TeamConfig.LIFEPOOL, 7);
|
||||
teamDefaultConfig.put(TeamConfig.MAXSCORE, 10);
|
||||
teamDefaultConfig.put(TeamConfig.NOHUNGER, false);
|
||||
teamDefaultConfig.put(TeamConfig.RESPAWNTIMER, 0);
|
||||
teamDefaultConfig.put(TeamConfig.SATURATION, 10);
|
||||
teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL);
|
||||
teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10);
|
||||
|
||||
this.getDefaultInventories().getLoadouts().clear();
|
||||
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
||||
|
||||
ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1, (byte) 8);
|
||||
stoneSword.setDurability((short) 8);
|
||||
defaultLoadout.put(0, stoneSword);
|
||||
|
||||
ItemStack bow = new ItemStack(Material.BOW, 1, (byte) 8);
|
||||
bow.setDurability((short) 8);
|
||||
defaultLoadout.put(1, bow);
|
||||
|
||||
ItemStack arrows = new ItemStack(Material.ARROW, 7);
|
||||
defaultLoadout.put(2, arrows);
|
||||
|
||||
ItemStack stonePick = new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8);
|
||||
stonePick.setDurability((short) 8);
|
||||
defaultLoadout.put(3, stonePick);
|
||||
|
||||
ItemStack stoneSpade = new ItemStack(Material.STONE_SPADE, 1, (byte) 8);
|
||||
stoneSword.setDurability((short) 8);
|
||||
defaultLoadout.put(4, stoneSpade);
|
||||
|
||||
this.getDefaultInventories().addLoadout("default", defaultLoadout);
|
||||
|
||||
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
reward.put(0, new ItemStack(Material.CAKE, 1));
|
||||
this.getDefaultInventories().setReward(reward);
|
||||
|
||||
this.getCommandWhitelist().add("who");
|
||||
this.getZoneMakerNames().add("tommytony");
|
||||
|
||||
// Add constants
|
||||
this.getDeadlyAdjectives().clear();
|
||||
this.getDeadlyAdjectives().add("");
|
||||
this.getDeadlyAdjectives().add("");
|
||||
this.getDeadlyAdjectives().add("mighty ");
|
||||
this.getDeadlyAdjectives().add("deadly ");
|
||||
this.getDeadlyAdjectives().add("fine ");
|
||||
this.getDeadlyAdjectives().add("precise ");
|
||||
this.getDeadlyAdjectives().add("brutal ");
|
||||
this.getDeadlyAdjectives().add("powerful ");
|
||||
|
||||
this.getKillerVerbs().clear();
|
||||
this.getKillerVerbs().add("killed");
|
||||
this.getKillerVerbs().add("killed");
|
||||
this.getKillerVerbs().add("killed");
|
||||
this.getKillerVerbs().add("finished");
|
||||
this.getKillerVerbs().add("annihilated");
|
||||
this.getKillerVerbs().add("murdered");
|
||||
this.getKillerVerbs().add("obliterated");
|
||||
this.getKillerVerbs().add("exterminated");
|
||||
|
||||
// Load files
|
||||
WarYmlMapper.load();
|
||||
|
||||
// Start tasks
|
||||
HelmetProtectionTask helmetProtectionTask = new HelmetProtectionTask();
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, helmetProtectionTask, 250, 100);
|
||||
|
||||
if (this.isSpoutServer) {
|
||||
SpoutFadeOutMessageJob fadeOutMessagesTask = new SpoutFadeOutMessageJob();
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, fadeOutMessagesTask, 100, 100);
|
||||
}
|
||||
|
||||
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up war
|
||||
*/
|
||||
public void unloadWar() {
|
||||
for (Warzone warzone : this.warzones) {
|
||||
warzone.unload();
|
||||
}
|
||||
this.warzones.clear();
|
||||
|
||||
if (this.warHub != null) {
|
||||
this.warHub.getVolume().resetBlocks();
|
||||
}
|
||||
|
||||
this.getServer().getScheduler().cancelTasks(this);
|
||||
this.playerListener.purgeLatestPositions();
|
||||
|
||||
this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO);
|
||||
this.setLoaded(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onCommand()
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
return this.commandHandler.handle(sender, cmd, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the player-inventory to a loadout hashmap
|
||||
*
|
||||
* @param inv
|
||||
* inventory to get the items from
|
||||
* @param loadout
|
||||
* the hashmap to save to
|
||||
*/
|
||||
private void inventoryToLoadout(PlayerInventory inv, HashMap<Integer, ItemStack> loadout) {
|
||||
loadout.clear();
|
||||
int i = 0;
|
||||
for (ItemStack stack : inv.getContents()) {
|
||||
if (stack != null && stack.getType() != Material.AIR) {
|
||||
loadout.put(i, this.copyStack(stack));
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
if (inv.getBoots() != null && inv.getBoots().getType() != Material.AIR) {
|
||||
loadout.put(100, this.copyStack(inv.getBoots()));
|
||||
}
|
||||
if (inv.getLeggings() != null && inv.getLeggings().getType() != Material.AIR) {
|
||||
loadout.put(101, this.copyStack(inv.getLeggings()));
|
||||
}
|
||||
if (inv.getChestplate() != null && inv.getChestplate().getType() != Material.AIR) {
|
||||
loadout.put(102, this.copyStack(inv.getChestplate()));
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack copyStack(ItemStack originalStack) {
|
||||
ItemStack copiedStack = new ItemStack(originalStack.getType(), originalStack.getAmount(), originalStack.getDurability(), new Byte(originalStack.getData().getData()));
|
||||
copiedStack.setDurability(originalStack.getDurability());
|
||||
for (Enchantment enchantment : originalStack.getEnchantments().keySet()) {
|
||||
copiedStack.addEnchantment(Enchantment.getById(enchantment.getId()), originalStack.getEnchantments().get(enchantment));
|
||||
}
|
||||
return copiedStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the player-inventory to a loadout hashmap
|
||||
*
|
||||
* @param player
|
||||
* player to get the inventory to get the items from
|
||||
* @param loadout
|
||||
* the hashmap to save to
|
||||
*/
|
||||
private void inventoryToLoadout(Player player, HashMap<Integer, ItemStack> loadout) {
|
||||
this.inventoryToLoadout(player.getInventory(), loadout);
|
||||
}
|
||||
|
||||
public String updateTeamFromNamedParams(Team team, CommandSender commandSender, String[] arguments) {
|
||||
try {
|
||||
Map<String, String> namedParams = new HashMap<String, String>();
|
||||
for (String namedPair : arguments) {
|
||||
String[] pairSplit = namedPair.split(":");
|
||||
if (pairSplit.length == 2) {
|
||||
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder returnMessage = new StringBuilder();
|
||||
returnMessage.append(team.getTeamConfig().updateFromNamedParams(namedParams));
|
||||
|
||||
if (commandSender instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
if (namedParams.containsKey("loadout")) {
|
||||
String loadoutName = namedParams.get("loadout");
|
||||
HashMap<Integer, ItemStack> loadout = team.getInventories().getLoadouts().get(loadoutName);
|
||||
if (loadout == null) {
|
||||
loadout = new HashMap<Integer, ItemStack>();
|
||||
team.getInventories().getLoadouts().put(loadoutName, loadout);
|
||||
returnMessage.append(loadoutName + " respawn loadout added.");
|
||||
} else {
|
||||
returnMessage.append(loadoutName + " respawn loadout updated.");
|
||||
}
|
||||
this.inventoryToLoadout(player, loadout);
|
||||
}
|
||||
if (namedParams.containsKey("deleteloadout")) {
|
||||
String loadoutName = namedParams.get("deleteloadout");
|
||||
if (team.getInventories().getLoadouts().keySet().contains(loadoutName)) {
|
||||
team.getInventories().removeLoadout(loadoutName);
|
||||
returnMessage.append(" " + loadoutName + " loadout removed.");
|
||||
} else {
|
||||
returnMessage.append(" " + loadoutName + " loadout not found.");
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("reward")) {
|
||||
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
this.inventoryToLoadout(player, reward);
|
||||
team.getInventories().setReward(reward);
|
||||
returnMessage.append(" game end reward updated.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnMessage.toString();
|
||||
} catch (Exception e) {
|
||||
return "PARSE-ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
public String updateZoneFromNamedParams(Warzone warzone, CommandSender commandSender, String[] arguments) {
|
||||
try {
|
||||
Map<String, String> namedParams = new HashMap<String, String>();
|
||||
for (String namedPair : arguments) {
|
||||
String[] pairSplit = namedPair.split(":");
|
||||
if (pairSplit.length == 2) {
|
||||
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder returnMessage = new StringBuilder();
|
||||
if (namedParams.containsKey("author")) {
|
||||
for(String author : namedParams.get("author").split(",")) {
|
||||
if (!author.equals("") && !warzone.getAuthors().contains(author)) {
|
||||
warzone.addAuthor(author);
|
||||
returnMessage.append(" author " + author + " added.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("deleteauthor")) {
|
||||
for(String author : namedParams.get("deleteauthor").split(",")) {
|
||||
if (warzone.getAuthors().contains(author)) {
|
||||
warzone.getAuthors().remove(author);
|
||||
returnMessage.append(" " + author + " removed from zone authors.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returnMessage.append(warzone.getWarzoneConfig().updateFromNamedParams(namedParams));
|
||||
returnMessage.append(warzone.getTeamDefaultConfig().updateFromNamedParams(namedParams));
|
||||
|
||||
if (commandSender instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
if (namedParams.containsKey("loadout")) {
|
||||
String loadoutName = namedParams.get("loadout");
|
||||
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(loadoutName);
|
||||
if (loadout == null) {
|
||||
loadout = new HashMap<Integer, ItemStack>();
|
||||
warzone.getDefaultInventories().getLoadouts().put(loadoutName, loadout);
|
||||
returnMessage.append(loadoutName + " respawn loadout added.");
|
||||
} else {
|
||||
returnMessage.append(loadoutName + " respawn loadout updated.");
|
||||
}
|
||||
this.inventoryToLoadout(player, loadout);
|
||||
}
|
||||
if (namedParams.containsKey("deleteloadout")) {
|
||||
String loadoutName = namedParams.get("deleteloadout");
|
||||
if (warzone.getDefaultInventories().getLoadouts().keySet().contains(loadoutName)) {
|
||||
warzone.getDefaultInventories().removeLoadout(loadoutName);
|
||||
returnMessage.append(" " + loadoutName + " loadout removed.");
|
||||
} else {
|
||||
returnMessage.append(" " + loadoutName + " loadout not found.");
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("reward")) {
|
||||
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
this.inventoryToLoadout(player, reward);
|
||||
warzone.getDefaultInventories().setReward(reward);
|
||||
returnMessage.append(" game end reward updated.");
|
||||
}
|
||||
}
|
||||
|
||||
return returnMessage.toString();
|
||||
} catch (Exception e) {
|
||||
return "PARSE-ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
public String updateFromNamedParams(CommandSender commandSender, String[] arguments) {
|
||||
try {
|
||||
Map<String, String> namedParams = new HashMap<String, String>();
|
||||
for (String namedPair : arguments) {
|
||||
String[] pairSplit = namedPair.split(":");
|
||||
if (pairSplit.length == 2) {
|
||||
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder returnMessage = new StringBuilder();
|
||||
|
||||
returnMessage.append(this.getWarConfig().updateFromNamedParams(namedParams));
|
||||
returnMessage.append(this.getWarzoneDefaultConfig().updateFromNamedParams(namedParams));
|
||||
returnMessage.append(this.getTeamDefaultConfig().updateFromNamedParams(namedParams));
|
||||
|
||||
if (commandSender instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
if (namedParams.containsKey("loadout")) {
|
||||
String loadoutName = namedParams.get("loadout");
|
||||
HashMap<Integer, ItemStack> loadout = this.getDefaultInventories().getLoadouts().get(loadoutName);
|
||||
if (loadout == null) {
|
||||
loadout = new HashMap<Integer, ItemStack>();
|
||||
this.getDefaultInventories().addLoadout(loadoutName, loadout);
|
||||
returnMessage.append(loadoutName + " respawn loadout added.");
|
||||
} else {
|
||||
returnMessage.append(loadoutName + " respawn loadout updated.");
|
||||
}
|
||||
this.inventoryToLoadout(player, loadout);
|
||||
}
|
||||
if (namedParams.containsKey("deleteloadout")) {
|
||||
String loadoutName = namedParams.get("deleteloadout");
|
||||
if (this.getDefaultInventories().getLoadouts().keySet().contains(loadoutName)) {
|
||||
if (this.getDefaultInventories().getLoadouts().keySet().size() > 1) {
|
||||
this.getDefaultInventories().removeLoadout(loadoutName);
|
||||
returnMessage.append(" " + loadoutName + " loadout removed.");
|
||||
} else {
|
||||
returnMessage.append(" Can't remove only loadout.");
|
||||
}
|
||||
} else {
|
||||
returnMessage.append(" " + loadoutName + " loadout not found.");
|
||||
}
|
||||
}
|
||||
if (namedParams.containsKey("reward")) {
|
||||
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
this.inventoryToLoadout(player, reward);
|
||||
this.getDefaultInventories().setReward(reward);
|
||||
returnMessage.append(" game end reward updated.");
|
||||
}
|
||||
if (namedParams.containsKey("rallypoint")) {
|
||||
String zoneName = namedParams.get("rallypoint");
|
||||
this.setZoneRallyPoint(zoneName, player);
|
||||
returnMessage.append(" rallypoint set for zone " + zoneName + ".");
|
||||
}
|
||||
}
|
||||
|
||||
return returnMessage.toString();
|
||||
} catch (Exception e) {
|
||||
return "PARSE-ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
public String printConfig(Team team) {
|
||||
ChatColor teamColor = ChatColor.AQUA;
|
||||
|
||||
ChatColor normalColor = ChatColor.WHITE;
|
||||
|
||||
String teamConfigStr = "";
|
||||
InventoryBag invs = team.getInventories();
|
||||
teamConfigStr += getLoadoutsString(invs);
|
||||
|
||||
for (TeamConfig teamConfig : TeamConfig.values()) {
|
||||
Object value = team.getTeamConfig().getValue(teamConfig);
|
||||
if (value != null) {
|
||||
teamConfigStr += " " + teamConfig.toStringWithValue(value).replace(":", ":" + teamColor) + normalColor;
|
||||
}
|
||||
}
|
||||
|
||||
return " ::" + teamColor + "Team " + team.getName() + teamColor + " config" + normalColor + "::"
|
||||
+ ifEmptyInheritedForTeam(teamConfigStr);
|
||||
}
|
||||
|
||||
private String getLoadoutsString(InventoryBag invs) {
|
||||
String loadoutsString = "";
|
||||
ChatColor loadoutColor = ChatColor.GREEN;
|
||||
ChatColor normalColor = ChatColor.WHITE;
|
||||
|
||||
if (invs.hasLoadouts()) {
|
||||
String loadouts = "";
|
||||
for (String loadoutName : invs.getLoadouts().keySet()) {
|
||||
loadouts += loadoutName + ",";
|
||||
}
|
||||
loadoutsString += " loadout:" + loadoutColor + loadouts + normalColor;
|
||||
}
|
||||
|
||||
if (invs.hasReward()) {
|
||||
loadoutsString += " reward:" + loadoutColor + "default" + normalColor;
|
||||
}
|
||||
|
||||
return loadoutsString;
|
||||
}
|
||||
|
||||
public String printConfig(Warzone zone) {
|
||||
ChatColor teamColor = ChatColor.AQUA;
|
||||
ChatColor zoneColor = ChatColor.DARK_AQUA;
|
||||
ChatColor authorColor = ChatColor.GREEN;
|
||||
ChatColor normalColor = ChatColor.WHITE;
|
||||
|
||||
String warzoneConfigStr = "";
|
||||
for (WarzoneConfig warzoneConfig : WarzoneConfig.values()) {
|
||||
Object value = zone.getWarzoneConfig().getValue(warzoneConfig);
|
||||
if (value != null) {
|
||||
warzoneConfigStr += " " + warzoneConfig.toStringWithValue(value).replace(":", ":" + zoneColor) + normalColor;
|
||||
}
|
||||
}
|
||||
|
||||
String teamDefaultsStr = "";
|
||||
teamDefaultsStr += getLoadoutsString( zone.getDefaultInventories());
|
||||
for (TeamConfig teamConfig : TeamConfig.values()) {
|
||||
Object value = zone.getTeamDefaultConfig().getValue(teamConfig);
|
||||
if (value != null) {
|
||||
teamDefaultsStr += " " + teamConfig.toStringWithValue(value).replace(":", ":" + teamColor) + normalColor;
|
||||
}
|
||||
}
|
||||
|
||||
return "::" + zoneColor + "Warzone " + authorColor + zone.getName() + zoneColor + " config" + normalColor + "::"
|
||||
+ " author:" + authorColor + ifEmptyEveryone(zone.getAuthorsString()) + normalColor
|
||||
+ ifEmptyInheritedForWarzone(warzoneConfigStr)
|
||||
+ " ::" + teamColor + "Team defaults" + normalColor + "::"
|
||||
+ ifEmptyInheritedForWarzone(teamDefaultsStr);
|
||||
}
|
||||
|
||||
private String ifEmptyInheritedForWarzone(String maybeEmpty) {
|
||||
if (maybeEmpty.equals("")) {
|
||||
maybeEmpty = " all values inherited (see " + ChatColor.GREEN + "/warcfg -p)" + ChatColor.WHITE;
|
||||
}
|
||||
return maybeEmpty;
|
||||
}
|
||||
|
||||
private String ifEmptyInheritedForTeam(String maybeEmpty) {
|
||||
if (maybeEmpty.equals("")) {
|
||||
maybeEmpty = " all values inherited (see " + ChatColor.GREEN + "/warcfg -p" + ChatColor.WHITE
|
||||
+ " and " + ChatColor.GREEN + "/zonecfg -p" + ChatColor.WHITE + ")";
|
||||
}
|
||||
return maybeEmpty;
|
||||
}
|
||||
|
||||
private String ifEmptyEveryone(String maybeEmpty) {
|
||||
if (maybeEmpty.equals("")) {
|
||||
maybeEmpty = "*";
|
||||
}
|
||||
return maybeEmpty;
|
||||
}
|
||||
|
||||
public String printConfig() {
|
||||
ChatColor teamColor = ChatColor.AQUA;
|
||||
ChatColor zoneColor = ChatColor.DARK_AQUA;
|
||||
ChatColor globalColor = ChatColor.DARK_GREEN;
|
||||
ChatColor normalColor = ChatColor.WHITE;
|
||||
|
||||
String warConfigStr = "";
|
||||
for (WarConfig warConfig : WarConfig.values()) {
|
||||
warConfigStr += " " + warConfig.toStringWithValue(this.getWarConfig().getValue(warConfig)).replace(":", ":" + globalColor) + normalColor;
|
||||
}
|
||||
|
||||
String warzoneDefaultsStr = "";
|
||||
for (WarzoneConfig warzoneConfig : WarzoneConfig.values()) {
|
||||
warzoneDefaultsStr += " " + warzoneConfig.toStringWithValue(this.getWarzoneDefaultConfig().getValue(warzoneConfig)).replace(":", ":" + zoneColor) + normalColor;
|
||||
}
|
||||
|
||||
String teamDefaultsStr = "";
|
||||
teamDefaultsStr += getLoadoutsString(this.getDefaultInventories());
|
||||
for (TeamConfig teamConfig : TeamConfig.values()) {
|
||||
teamDefaultsStr += " " + teamConfig.toStringWithValue(this.getTeamDefaultConfig().getValue(teamConfig)).replace(":", ":" + teamColor) + normalColor;
|
||||
}
|
||||
|
||||
return normalColor + "::" + globalColor + "War config" + normalColor + "::" + warConfigStr
|
||||
+ normalColor + " ::" + zoneColor + "Warzone defaults" + normalColor + "::" + warzoneDefaultsStr
|
||||
+ normalColor + " ::" + teamColor + "Team defaults" + normalColor + "::" + teamDefaultsStr;
|
||||
}
|
||||
|
||||
private void setZoneRallyPoint(String warzoneName, Player player) {
|
||||
Warzone zone = this.findWarzone(warzoneName);
|
||||
if (zone == null) {
|
||||
this.badMsg(player, "Can't set rally point. No such warzone.");
|
||||
} else {
|
||||
zone.setRallyPoint(player.getLocation());
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void addWarzone(Warzone zone) {
|
||||
this.warzones.add(zone);
|
||||
}
|
||||
|
||||
public List<Warzone> getWarzones() {
|
||||
return this.warzones;
|
||||
}
|
||||
|
||||
public void msg(CommandSender sender, String str) {
|
||||
if (sender instanceof Player) {
|
||||
String out = ChatColor.GRAY + "War> " + ChatColor.WHITE + this.colorKnownTokens(str, ChatColor.WHITE) + " ";
|
||||
ChatFixUtil.sendMessage(sender, out);
|
||||
} else {
|
||||
sender.sendMessage("War> " + str);
|
||||
}
|
||||
}
|
||||
|
||||
public void badMsg(CommandSender sender, String str) {
|
||||
if (sender instanceof Player) {
|
||||
String out = ChatColor.GRAY + "War> " + ChatColor.RED + this.colorKnownTokens(str, ChatColor.RED) + " ";
|
||||
ChatFixUtil.sendMessage(sender, out);
|
||||
} else {
|
||||
sender.sendMessage("War> " + str);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Colors the teams and examples in messages
|
||||
*
|
||||
* @param String
|
||||
* str message-string
|
||||
* @param String
|
||||
* msgColor current message-color
|
||||
* @return String Message with colored teams
|
||||
*/
|
||||
private String colorKnownTokens(String str, ChatColor msgColor) {
|
||||
for (TeamKind kind : TeamKind.values()) {
|
||||
str = str.replaceAll(" " + kind.toString(), " " + kind.getColor() + kind.toString() + msgColor);
|
||||
}
|
||||
str = str.replaceAll("Ex -", ChatColor.GRAY + "Ex -");
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a specified message with a specified level
|
||||
*
|
||||
* @param String
|
||||
* str message to log
|
||||
* @param Level
|
||||
* lvl level to use
|
||||
*/
|
||||
public void log(String str, Level lvl) {
|
||||
this.getLogger().log(lvl, "War> " + str);
|
||||
}
|
||||
|
||||
// the only way to find a zone that has only one corner
|
||||
public Warzone findWarzone(String warzoneName) {
|
||||
for (Warzone warzone : this.warzones) {
|
||||
if (warzone.getName().toLowerCase().equals(warzoneName.toLowerCase())) {
|
||||
return warzone;
|
||||
}
|
||||
}
|
||||
for (Warzone warzone : this.incompleteZones) {
|
||||
if (warzone.getName().equals(warzoneName)) {
|
||||
return warzone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is allowed to play war.
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player may play war
|
||||
*/
|
||||
public boolean canPlayWar(Player player) {
|
||||
return player.hasPermission("war.player");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is allowed to warp.
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player may warp
|
||||
*/
|
||||
public boolean canWarp(Player player) {
|
||||
return player.hasPermission("war.warp");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is allowed to build outside zones
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player may build outside zones
|
||||
*/
|
||||
public boolean canBuildOutsideZone(Player player) {
|
||||
if (this.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY)) {
|
||||
return player.hasPermission("war.build");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is allowed to pvp outside zones
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player may pvp outside zones
|
||||
*/
|
||||
public boolean canPvpOutsideZones(Player player) {
|
||||
if (this.getWarConfig().getBoolean(WarConfig.PVPINZONESONLY)) {
|
||||
return player.hasPermission("war.pvp");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is a zone maker
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player is a zone maker
|
||||
*/
|
||||
public boolean isZoneMaker(Player player) {
|
||||
// sort out disguised first
|
||||
for (String disguised : this.zoneMakersImpersonatingPlayers) {
|
||||
if (disguised.equals(player.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (String zoneMaker : this.zoneMakerNames) {
|
||||
if (zoneMaker.equals(player.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return player.hasPermission("war.zonemaker");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is a War admin
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player is a War admin
|
||||
*/
|
||||
public boolean isWarAdmin(Player player) {
|
||||
return player.hasPermission("war.admin");
|
||||
}
|
||||
|
||||
public void addWandBearer(Player player, String zoneName) {
|
||||
if (this.wandBearers.containsKey(player.getName())) {
|
||||
String alreadyHaveWand = this.wandBearers.get(player.getName());
|
||||
if (player.getInventory().first(Material.WOOD_SWORD) != -1) {
|
||||
if (zoneName.equals(alreadyHaveWand)) {
|
||||
this.badMsg(player, "You already have a wand for zone " + alreadyHaveWand + ". Drop the wooden sword first.");
|
||||
} else {
|
||||
// new zone, already have sword
|
||||
this.wandBearers.remove(player.getName());
|
||||
this.wandBearers.put(player.getName(), zoneName);
|
||||
this.msg(player, "Switched wand to zone " + zoneName + ".");
|
||||
}
|
||||
} else {
|
||||
// lost his sword, or new warzone
|
||||
if (zoneName.equals(alreadyHaveWand)) {
|
||||
// same zone, give him a new sword
|
||||
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
|
||||
this.msg(player, "Here's a new sword for zone " + zoneName + ".");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (player.getInventory().firstEmpty() == -1) {
|
||||
this.badMsg(player, "Your inventory is full. Please drop an item and try again.");
|
||||
} else {
|
||||
this.wandBearers.put(player.getName(), zoneName);
|
||||
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
|
||||
// player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.WOOD_SWORD));
|
||||
this.msg(player, "You now have a wand for zone " + zoneName + ". Left-click with wodden sword for corner 1. Right-click for corner 2.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWandBearer(Player player) {
|
||||
return this.wandBearers.containsKey(player.getName());
|
||||
}
|
||||
|
||||
public String getWandBearerZone(Player player) {
|
||||
if (this.isWandBearer(player)) {
|
||||
return this.wandBearers.get(player.getName());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void removeWandBearer(Player player) {
|
||||
if (this.wandBearers.containsKey(player.getName())) {
|
||||
this.wandBearers.remove(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
public boolean isSpoutServer() {
|
||||
return this.isSpoutServer;
|
||||
}
|
||||
|
||||
public Warzone zoneOfZoneWallAtProximity(Location location) {
|
||||
for (Warzone zone : this.warzones) {
|
||||
if (zone.getWorld() == location.getWorld() && zone.isNearWall(location)) {
|
||||
return zone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getZoneMakerNames() {
|
||||
return this.zoneMakerNames;
|
||||
}
|
||||
|
||||
public List<String> getCommandWhitelist() {
|
||||
return this.commandWhitelist;
|
||||
}
|
||||
|
||||
public boolean inAnyWarzoneLobby(Location location) {
|
||||
if (ZoneLobby.getLobbyByLocation(location) == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<String> getZoneMakersImpersonatingPlayers() {
|
||||
return this.zoneMakersImpersonatingPlayers;
|
||||
}
|
||||
|
||||
public List<Warzone> getIncompleteZones() {
|
||||
return this.incompleteZones;
|
||||
}
|
||||
|
||||
public WarHub getWarHub() {
|
||||
return this.warHub;
|
||||
}
|
||||
|
||||
public void setWarHub(WarHub warHub) {
|
||||
this.warHub = warHub;
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return this.loaded;
|
||||
}
|
||||
|
||||
public void setLoaded(boolean loaded) {
|
||||
this.loaded = loaded;
|
||||
}
|
||||
|
||||
public HashMap<String, PlayerState> getDisconnected() {
|
||||
return this.disconnected;
|
||||
}
|
||||
|
||||
public void setDisconnected(HashMap<String, PlayerState> disconnected) {
|
||||
this.disconnected = disconnected;
|
||||
}
|
||||
|
||||
public InventoryBag getDefaultInventories() {
|
||||
return defaultInventories;
|
||||
}
|
||||
|
||||
public List<String> getDeadlyAdjectives() {
|
||||
return deadlyAdjectives;
|
||||
}
|
||||
|
||||
public List<String> getKillerVerbs() {
|
||||
return killerVerbs;
|
||||
}
|
||||
|
||||
public TeamConfigBag getTeamDefaultConfig() {
|
||||
return this.teamDefaultConfig ;
|
||||
}
|
||||
|
||||
public WarzoneConfigBag getWarzoneDefaultConfig() {
|
||||
return this.warzoneDefaultConfig;
|
||||
}
|
||||
|
||||
public WarConfigBag getWarConfig() {
|
||||
return this.warConfig;
|
||||
}
|
||||
|
||||
public SpoutMessenger getSpoutMessenger() {
|
||||
return this.spoutMessenger ;
|
||||
}
|
||||
}
|
@ -1,461 +0,0 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.tommytony.war.Bomb;
|
||||
import com.tommytony.war.Cake;
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.spout.SpoutMessenger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarBlockListener implements Listener {
|
||||
|
||||
/**
|
||||
* @see BlockListener.onBlockPlace()
|
||||
*/
|
||||
@EventHandler(event = BlockPlaceEvent.class)
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player == null || block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
// Monument capturing
|
||||
if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
|
||||
Monument monument = zone.getMonumentFromCenterBlock(block);
|
||||
if (monument != null && !monument.hasOwner()) {
|
||||
monument.capture(team);
|
||||
List<Team> teams = zone.getTeams();
|
||||
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : team.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()),
|
||||
SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "capped by " + team.getKind().getColor() + player.getName() + ChatColor.YELLOW + "!"),
|
||||
team.getKind().getMaterial(),
|
||||
team.getKind().getData(),
|
||||
10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Team t : teams) {
|
||||
t.teamcast("Monument " + monument.getName() + " has been captured by team " + team.getName() + ".");
|
||||
}
|
||||
event.setCancelled(false);
|
||||
return; // important otherwise cancelled down a few line by isImportantblock
|
||||
} else {
|
||||
War.war.badMsg(player, "You must capture a monument with a block of your team's wool color. Get one from your team spawn.");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
// prevent build in important parts
|
||||
if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
War.war.badMsg(player, "Can't build here.");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
for (Warzone wz : War.war.getWarzones()) {
|
||||
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't build here.");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't build here.");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
if (zone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
|
||||
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
|
||||
}
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// can't place a block of your team's color
|
||||
if (team != null && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
|
||||
War.war.badMsg(player, "You can only use your team's blocks to capture monuments.");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a flag thief can't drop his flag
|
||||
if (team != null && zone != null && zone.isFlagThief(player.getName())) {
|
||||
War.war.badMsg(player, "Can't drop the flag. What are you doing? Run!");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a bomb thief can't drop his bomb
|
||||
if (team != null && zone != null && zone.isBombThief(player.getName())) {
|
||||
War.war.badMsg(player, "Can't drop the bomb. What are you doing? Run for your enemy's spawn!");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// a cake thief can't drop his cake
|
||||
if (team != null && zone != null && zone.isCakeThief(player.getName())) {
|
||||
War.war.badMsg(player, "Can't drop the cake. What are you doing? Run to your spawn!");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks)
|
||||
War.war.badMsg(player, "The blocks in this zone are unbreakable - this also means you can't build!");
|
||||
cancelAndKeepItem(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelAndKeepItem(BlockPlaceEvent event) {
|
||||
event.setCancelled(true);
|
||||
ItemStack inHand = event.getItemInHand();
|
||||
ItemStack newItemInHand = new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData());
|
||||
newItemInHand.setDurability(inHand.getDurability());
|
||||
event.getPlayer().setItemInHand(newItemInHand);
|
||||
}
|
||||
|
||||
@EventHandler(event = BlockPistonExtendEvent.class)
|
||||
// Do not allow moving of block into or from important zones
|
||||
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
if (zone!=null) {
|
||||
for (Block b : event.getBlocks()) {
|
||||
if (zone.isImportantBlock(b)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (zone.isImportantBlock(event.getBlock().getRelative(event.getDirection(), event.getLength()+1))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = BlockPistonRetractEvent.class)
|
||||
public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
|
||||
Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
|
||||
if (zone!=null) {
|
||||
Block b = event.getBlock().getRelative(event.getDirection(), 2);
|
||||
if (zone.isImportantBlock(b)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BlockListener.onBlockBreak()
|
||||
*/
|
||||
@EventHandler(event = BlockBreakEvent.class)
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player != null && block != null) {
|
||||
this.handleBreakOrDamage(player, block, event);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = BlockDamageEvent.class)
|
||||
public void onBlockDamage(final BlockDamageEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
Warzone playerZone = Warzone.getZoneByLocation(player);
|
||||
if (player != null && block != null && playerZone != null && playerZone.getWarzoneConfig().getBoolean(WarzoneConfig.INSTABREAK)) {
|
||||
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
|
||||
if (blockZone != null && blockZone == playerZone) {
|
||||
event.setInstaBreak(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
|
||||
if (warzone != null && team == null && !isZoneMaker) {
|
||||
// can't actually destroy blocks in a warzone if not part of a team
|
||||
War.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// monument's center is destroyed
|
||||
if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
|
||||
Monument monument = warzone.getMonumentFromCenterBlock(block);
|
||||
if (monument.hasOwner()) {
|
||||
List<Team> teams = warzone.getTeams();
|
||||
Team ownerTeam = monument.getOwnerTeam();
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : team.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()),
|
||||
SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "freed by " + team.getKind().getColor() + player.getName() + ChatColor.YELLOW + "!"),
|
||||
ownerTeam.getKind().getMaterial(),
|
||||
ownerTeam.getKind().getData(),
|
||||
10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Team t : teams) {
|
||||
t.teamcast("Team " + ownerTeam.getName() + " loses control of monument " + monument.getName());
|
||||
}
|
||||
monument.uncapture();
|
||||
}
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
// changes in parts of important areas
|
||||
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// breakage of spawn
|
||||
if (team != null && team.getSpawnVolume().contains(block)) {
|
||||
ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData());
|
||||
// let team members loot one block the spawn for monument captures
|
||||
if (player.getInventory().contains(teamKindBlock)) {
|
||||
War.war.badMsg(player, "You already have a " + team.getName() + " block.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down
|
||||
return;
|
||||
}
|
||||
}
|
||||
// stealing of flag
|
||||
if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
|
||||
if (warzone.isFlagThief(player.getName())) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "You can only steal one flag at a time!");
|
||||
} else if (warzone.isBombThief(player.getName()) || warzone.isCakeThief(player.getName())) {
|
||||
War.war.badMsg(player, "You can only steal one thing at a time!");
|
||||
} else {
|
||||
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
|
||||
if (lostFlagTeam.getPlayers().size() != 0) {
|
||||
// player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack teamKindBlock = new ItemStack(lostFlagTeam.getKind().getMaterial(), 1, (short) 1, new Byte(lostFlagTeam.getKind().getData()));
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(teamKindBlock);
|
||||
warzone.addFlagThief(lostFlagTeam, player.getName());
|
||||
block.setType(Material.AIR);
|
||||
|
||||
String spawnOrFlag = "spawn or flag";
|
||||
if (team.getTeamConfig().resolveFlagReturn().equals(FlagReturn.FLAG)
|
||||
|| team.getTeamConfig().resolveFlagReturn() == FlagReturn.SPAWN) {
|
||||
spawnOrFlag = team.getTeamConfig().resolveFlagReturn().toString();
|
||||
}
|
||||
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " stole team " + lostFlagTeam.getName() + "'s flag.");
|
||||
if (t.getName().equals(lostFlagTeam.getName())) {
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " stole"),
|
||||
SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "your flag!"),
|
||||
lostFlagTeam.getKind().getMaterial(),
|
||||
lostFlagTeam.getKind().getData(),
|
||||
5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " from reaching team " + team.getName() + "'s " + spawnOrFlag + ".");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
War.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team " + spawnOrFlag + " to capture it!");
|
||||
} else {
|
||||
War.war.msg(player, "You can't steal team " + lostFlagTeam.getName() + "'s flag since no players are on that team.");
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (team != null && warzone.isBombBlock(block)) {
|
||||
if (warzone.isBombThief(player.getName())) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "You can only steal one bomb at a time!");
|
||||
} else if (warzone.isFlagThief(player.getName()) || warzone.isCakeThief(player.getName())) {
|
||||
War.war.badMsg(player, "You can only steal one thing at a time!");
|
||||
} else {
|
||||
Bomb bomb = warzone.getBombForBlock(block);
|
||||
// player just broke the bomb block: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack tntBlock = new ItemStack(Material.TNT, 1, (short)8, (byte)8);
|
||||
tntBlock.setDurability((short)8);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(tntBlock);
|
||||
warzone.addBombThief(bomb, player.getName());
|
||||
block.setType(Material.AIR);
|
||||
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " has bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.WHITE + ".");
|
||||
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " has "),
|
||||
SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.YELLOW + "!"),
|
||||
Material.TNT,
|
||||
(short)0,
|
||||
5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " from reaching your spawn with the bomb!");
|
||||
}
|
||||
|
||||
|
||||
War.war.msg(player, "You have bomb " + bomb.getName() + ". Reach another team's spawn to score. Don't get touched by anyone or you'll blow up!");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (team != null && warzone.isCakeBlock(block)) {
|
||||
if (warzone.isCakeThief(player.getName())) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "You can only steal one cake at a time!");
|
||||
} else if (warzone.isFlagThief(player.getName()) || warzone.isBombThief(player.getName())) {
|
||||
War.war.badMsg(player, "You can only steal one thing at a time!");
|
||||
} else {
|
||||
Cake cake = warzone.getCakeForBlock(block);
|
||||
// player just broke the cake block: cancel to avoid drop, give player the block, set block to air
|
||||
ItemStack cakeBlock = new ItemStack(Material.CAKE, 1, (short)8, (byte)8);
|
||||
cakeBlock.setDurability((short)8);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(cakeBlock);
|
||||
warzone.addCakeThief(cake, player.getName());
|
||||
block.setType(Material.AIR);
|
||||
|
||||
for (Team t : warzone.getTeams()) {
|
||||
t.teamcast(team.getKind().getColor() + player.getName() + ChatColor.WHITE + " has cake " + ChatColor.GREEN + cake.getName() + ChatColor.WHITE + ".");
|
||||
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " has "),
|
||||
SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "cake " + ChatColor.GREEN + cake.getName() + ChatColor.YELLOW + "!"),
|
||||
Material.CAKE,
|
||||
(short)0,
|
||||
5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.teamcast("Prevent " + team.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " from reaching their spawn with the cake!");
|
||||
}
|
||||
|
||||
|
||||
War.war.msg(player, "You have cake " + cake.getName() + ". Reach your team's spawn to score and replenish your lifepool.");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (!warzone.isMonumentCenterBlock(block)) {
|
||||
War.war.badMsg(player, "Can't destroy this.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
if (block != null) {
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't destroy this.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't destroy this.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
|
||||
if (blockZone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
|
||||
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (blockZone != null && blockZone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks
|
||||
War.war.badMsg(player, "The blocks in this zone are unbreakable!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.command.*;
|
||||
|
||||
/**
|
||||
* Handles commands received by War
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarCommandHandler {
|
||||
|
||||
/**
|
||||
* Handles a command
|
||||
*
|
||||
* @param sender
|
||||
* The sender of the command
|
||||
* @param cmd
|
||||
* The command
|
||||
* @param args
|
||||
* The arguments
|
||||
* @return Success
|
||||
*/
|
||||
public boolean handle(CommandSender sender, Command cmd, String[] args) {
|
||||
String command = cmd.getName();
|
||||
String[] arguments = null;
|
||||
|
||||
// parse prefixed commands
|
||||
if ((command.equals("war") || command.equals("War")) && args.length > 0) {
|
||||
command = args[0];
|
||||
arguments = new String[args.length - 1];
|
||||
for (int i = 1; i <= arguments.length; i++) {
|
||||
arguments[i - 1] = args[i];
|
||||
}
|
||||
|
||||
if (arguments.length == 1 && (arguments[0].equals("help") || arguments[0].equals("h"))) {
|
||||
// show /war help
|
||||
War.war.badMsg(sender, cmd.getUsage());
|
||||
return true;
|
||||
}
|
||||
} else if (command.equals("war") || command.equals("War")) {
|
||||
// show /war help
|
||||
War.war.msg(sender, cmd.getUsage());
|
||||
return true;
|
||||
} else {
|
||||
arguments = args;
|
||||
}
|
||||
|
||||
AbstractWarCommand commandObj = null;
|
||||
try {
|
||||
if (command.equals("warhub")) {
|
||||
commandObj = new WarhubCommand(this, sender, arguments);
|
||||
} else if (command.equals("zones") || command.equals("warzones")) {
|
||||
commandObj = new WarzonesCommand(this, sender, arguments);
|
||||
} else if (command.equals("zone") || command.equals("warzone")) {
|
||||
commandObj = new WarzoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("teams")) {
|
||||
commandObj = new TeamsCommand(this, sender, arguments);
|
||||
} else if (command.equals("join")) {
|
||||
commandObj = new JoinCommand(this, sender, arguments);
|
||||
} else if (command.equals("leave")) {
|
||||
commandObj = new LeaveCommand(this, sender, arguments);
|
||||
} else if (command.equals("team")) {
|
||||
commandObj = new TeamCommand(this, sender, arguments);
|
||||
} else if (command.equals("setzone")) {
|
||||
commandObj = new SetZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletezone")) {
|
||||
commandObj = new DeleteZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("setzonelobby")) {
|
||||
commandObj = new SetZoneLobbyCommand(this, sender, arguments);
|
||||
} else if (command.equals("savezone")) {
|
||||
commandObj = new SaveZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("resetzone")) {
|
||||
commandObj = new ResetZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("nextbattle")) {
|
||||
commandObj = new NextBattleCommand(this, sender, arguments);
|
||||
} else if (command.equals("renamezone")) {
|
||||
commandObj = new RenameZoneCommand(this, sender, arguments);
|
||||
} else if (command.equals("setteam")) {
|
||||
commandObj = new SetTeamCommand(this, sender, arguments);
|
||||
} else if (command.equals("deleteteam")) {
|
||||
commandObj = new DeleteTeamCommand(this, sender, arguments);
|
||||
} else if (command.equals("setteamflag")) {
|
||||
commandObj = new SetTeamFlagCommand(this, sender, arguments);
|
||||
} else if (command.equals("deleteteamflag")) {
|
||||
commandObj = new DeleteTeamFlagCommand(this, sender, arguments);
|
||||
} else if (command.equals("setmonument")) {
|
||||
commandObj = new SetMonumentCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletemonument")) {
|
||||
commandObj = new DeleteMonumentCommand(this, sender, arguments);
|
||||
} else if (command.equals("setbomb")) {
|
||||
commandObj = new SetBombCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletebomb")) {
|
||||
commandObj = new DeleteBombCommand(this, sender, arguments);
|
||||
} else if (command.equals("setcake")) {
|
||||
commandObj = new SetCakeCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletecake")) {
|
||||
commandObj = new DeleteCakeCommand(this, sender, arguments);
|
||||
}else if (command.equals("setteamconfig") || command.equals("teamcfg")) {
|
||||
commandObj = new SetTeamConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("setzoneconfig") || command.equals("zonecfg")) {
|
||||
commandObj = new SetZoneConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("setwarhub")) {
|
||||
commandObj = new SetWarHubCommand(this, sender, arguments);
|
||||
} else if (command.equals("deletewarhub")) {
|
||||
commandObj = new DeleteWarhubCommand(this, sender, arguments);
|
||||
} else if (command.equals("loadwar")) {
|
||||
commandObj = new LoadWarCommand(this, sender, arguments);
|
||||
} else if (command.equals("unloadwar")) {
|
||||
commandObj = new UnloadWarCommand(this, sender, arguments);
|
||||
} else if (command.equals("setwarconfig") || command.equals("warcfg")) {
|
||||
commandObj = new SetWarConfigCommand(this, sender, arguments);
|
||||
} else if (command.equals("zonemaker") || command.equals("zm")) {
|
||||
commandObj = new ZoneMakerCommand(this, sender, arguments);
|
||||
}
|
||||
// we are not responsible for any other command
|
||||
} catch (NotWarAdminException e) {
|
||||
War.war.badMsg(sender, "You can't do this if you are not a War admin (permission war.admin).");
|
||||
} catch (NotZoneMakerException e) {
|
||||
War.war.badMsg(sender, "You can't do this if you are not a warzone maker (permission war.zonemaker).");
|
||||
} catch (Exception e) {
|
||||
War.war.log("An error occured while handling command " + cmd.getName() + ". Exception:" + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(commandObj != null) {
|
||||
boolean handled = commandObj.handle();
|
||||
if(!handled) {
|
||||
War.war.badMsg(sender, cmd.getUsage());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,537 +0,0 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.ContainerBlock;
|
||||
import org.bukkit.block.NoteBlock;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.entity.CraftTNTPrimed;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.tommytony.war.Bomb;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.jobs.DeferredBlockResetsJob;
|
||||
import com.tommytony.war.spout.SpoutMessenger;
|
||||
import com.tommytony.war.utils.DeferredBlockReset;
|
||||
|
||||
/**
|
||||
* Handles Entity-Events
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarEntityListener implements Listener {
|
||||
|
||||
private final Random killSeed = new Random();
|
||||
|
||||
/**
|
||||
* Handles PVP-Damage
|
||||
*
|
||||
* @param event
|
||||
* fired event
|
||||
*/
|
||||
private void handlerAttackDefend(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
Entity defender = event.getEntity();
|
||||
|
||||
//DamageCause cause = event.getCause();
|
||||
//War.war.log(cause.toString(), Level.INFO);
|
||||
// Maybe an arrow was thrown
|
||||
if (attacker != null && event.getDamager() instanceof Projectile && ((Projectile)event.getDamager()).getShooter() instanceof Player){
|
||||
attacker = ((Player)((Projectile)event.getDamager()).getShooter());
|
||||
}
|
||||
|
||||
if (attacker != null && defender != null && attacker instanceof Player && defender instanceof Player) {
|
||||
// only let adversaries (same warzone, different team) attack each other
|
||||
Player a = (Player) attacker;
|
||||
Player d = (Player) defender;
|
||||
Warzone attackerWarzone = Warzone.getZoneByPlayerName(a.getName());
|
||||
Team attackerTeam = Team.getTeamByPlayerName(a.getName());
|
||||
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
|
||||
Team defenderTeam = Team.getTeamByPlayerName(d.getName());
|
||||
|
||||
if ((attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone)
|
||||
|| (attackerTeam != null && defenderTeam != null && attacker.getEntityId() == defender.getEntityId())) {
|
||||
// Make sure one of the players isn't in the spawn
|
||||
if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn
|
||||
if (!defenderWarzone.isFlagThief(d.getName())
|
||||
&& !defenderWarzone.isBombThief(d.getName())) { // thieves can always be attacked
|
||||
War.war.badMsg(a, "Can't attack a player that's inside his team's spawn.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (attackerTeam.getSpawnVolume().contains(a.getLocation()) && !attackerTeam.getSpawnVolume().contains(d.getLocation())) {
|
||||
// only let a player inside spawn attack an enemy player if that player enters the spawn
|
||||
if (!attackerWarzone.isFlagThief(a.getName())
|
||||
&& !defenderWarzone.isBombThief(d.getName())) { // thieves can always attack
|
||||
War.war.badMsg(a, "Can't attack a player from inside your spawn.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
// Make sure none of them are respawning
|
||||
} else if (defenderWarzone.isRespawning(d)) {
|
||||
War.war.badMsg(a, "The target is currently respawning!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (attackerWarzone.isRespawning(a)) {
|
||||
War.war.badMsg(a, "You can't attack while respawning!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.PVPINZONE)) {
|
||||
// spleef-like, non-pvp, zone
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attackerTeam != null && defenderTeam != null && attacker.getEntityId() == defender.getEntityId()) {
|
||||
War.war.badMsg(a, "You hit yourself!");
|
||||
}
|
||||
|
||||
// Detect death, prevent it and respawn the player
|
||||
if (event.getDamage() >= d.getHealth()) {
|
||||
String killMessage = "";
|
||||
String attackerString = attackerTeam.getKind().getColor() + a.getName();
|
||||
String defenderString = defenderTeam.getKind().getColor() + d.getName();
|
||||
|
||||
if (attacker.getEntityId() != defender.getEntityId()) {
|
||||
Material killerWeapon = a.getItemInHand().getType();
|
||||
String weaponString = killerWeapon.toString();
|
||||
if (killerWeapon == Material.AIR) {
|
||||
weaponString = "hand";
|
||||
} else if (killerWeapon == Material.BOW || event.getDamager() instanceof Arrow) {
|
||||
int rand = killSeed.nextInt(3);
|
||||
if (rand == 0) {
|
||||
weaponString = "arrow";
|
||||
} else if (rand == 1) {
|
||||
weaponString = "bow";
|
||||
} else {
|
||||
weaponString = "aim";
|
||||
}
|
||||
|
||||
} else if (event.getDamager() instanceof Projectile) {
|
||||
weaponString = "aim";
|
||||
}
|
||||
|
||||
String adjectiveString = War.war.getDeadlyAdjectives().get(this.killSeed.nextInt(War.war.getDeadlyAdjectives().size()));
|
||||
String verbString = War.war.getKillerVerbs().get(this.killSeed.nextInt(War.war.getKillerVerbs().size()));
|
||||
|
||||
killMessage = attackerString + ChatColor.WHITE + "'s " + adjectiveString + weaponString.toLowerCase().replace('_', ' ')
|
||||
+ " " + verbString + " " + defenderString;
|
||||
} else {
|
||||
killMessage = defenderString + ChatColor.WHITE + " committed accidental suicide";
|
||||
}
|
||||
|
||||
for (Team team : defenderWarzone.getTeams()) {
|
||||
team.teamcast(killMessage);
|
||||
}
|
||||
defenderWarzone.handleDeath(d);
|
||||
|
||||
event.setCancelled(true);
|
||||
} else if (defenderWarzone.isBombThief(d.getName()) && d.getLocation().distance(a.getLocation()) < 2) {
|
||||
Bomb bomb = defenderWarzone.getBombForThief(d.getName());
|
||||
|
||||
// Kill the bomber
|
||||
defenderWarzone.handleDeath(d);
|
||||
|
||||
// blow up bomb man if attacker is close enough
|
||||
defenderWarzone.getWorld().createExplosion(a.getLocation(), 2F);
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : defenderWarzone.getTeams()) {
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification(attackerTeam.getKind().getColor() + a.getName() + ChatColor.YELLOW + " made "),
|
||||
SpoutMessenger.cleanForNotification(defenderTeam.getKind().getColor() + d.getName() + ChatColor.YELLOW + " blow up!"),
|
||||
Material.TNT,
|
||||
(short)0,
|
||||
10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bring back tnt
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.addBombBlocks();
|
||||
|
||||
t.teamcast(attackerTeam.getKind().getColor() + a.getName() + ChatColor.WHITE
|
||||
+ " made " + defenderTeam.getKind().getColor() + d.getName() + ChatColor.WHITE + " blow up!");
|
||||
}
|
||||
}
|
||||
} else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) {
|
||||
// same team, but not same person
|
||||
if (attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.FRIENDLYFIRE)) {
|
||||
War.war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through
|
||||
} else {
|
||||
War.war.badMsg(a, "Your attack missed! Your target is on your team.");
|
||||
event.setCancelled(true); // ff is off
|
||||
}
|
||||
} else if (attackerTeam == null && defenderTeam == null && War.war.canPvpOutsideZones(a)) {
|
||||
// let normal PVP through is its not turned off or if you have perms
|
||||
} else if (attackerTeam == null && defenderTeam == null && !War.war.canPvpOutsideZones(a)) {
|
||||
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE)) {
|
||||
War.war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones.");
|
||||
}
|
||||
event.setCancelled(true); // global pvp is off
|
||||
} else {
|
||||
War.war.badMsg(a, "Your attack missed!");
|
||||
if (attackerTeam == null) {
|
||||
War.war.badMsg(a, "You must join a team, then you'll be able to damage people " + "in the other teams in that warzone.");
|
||||
} else if (defenderTeam == null) {
|
||||
War.war.badMsg(a, "Your target is not in a team.");
|
||||
} else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) {
|
||||
// You just hit yourself, probably with a bouncing arrow
|
||||
} else if (attackerTeam == defenderTeam) {
|
||||
War.war.badMsg(a, "Your target is on your team.");
|
||||
} else if (attackerWarzone != defenderWarzone) {
|
||||
War.war.badMsg(a, "Your target is playing in another warzone.");
|
||||
}
|
||||
event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
|
||||
}
|
||||
} else if (defender instanceof Player) {
|
||||
// attacked by dispenser arrow most probably
|
||||
// Detect death, prevent it and respawn the player
|
||||
Player d = (Player) defender;
|
||||
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
|
||||
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
|
||||
String deathMessage = "";
|
||||
String defenderString = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getName();
|
||||
|
||||
if (event.getDamager() instanceof CraftTNTPrimed) {
|
||||
deathMessage = defenderString + ChatColor.WHITE + " exploded";
|
||||
} else {
|
||||
deathMessage = defenderString + ChatColor.WHITE + " died";
|
||||
}
|
||||
for (Team team : defenderWarzone.getTeams()) {
|
||||
team.teamcast(deathMessage);
|
||||
}
|
||||
defenderWarzone.handleDeath(d);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protects important structures from explosions
|
||||
*
|
||||
* @see EntityListener.onEntityExplode()
|
||||
*/
|
||||
@EventHandler(event = EntityExplodeEvent.class)
|
||||
public void onEntityExplode(final EntityExplodeEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
// protect zones elements, lobbies and warhub from creepers and tnt
|
||||
List<Block> explodedBlocks = event.blockList();
|
||||
List<Block> dontExplode = new ArrayList<Block>();
|
||||
|
||||
boolean explosionInAWarzone = event.getEntity() != null && Warzone.getZoneByLocation(event.getEntity().getLocation()) != null;
|
||||
|
||||
if (!explosionInAWarzone && War.war.getWarConfig().getBoolean(WarConfig.TNTINZONESONLY) && event.getEntity() instanceof TNTPrimed) {
|
||||
// if tntinzonesonly:true, no tnt blows up outside zones
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Block block : explodedBlocks) {
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
dontExplode.add(block);
|
||||
} else {
|
||||
boolean inOneZone = false;
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isImportantBlock(block)) {
|
||||
dontExplode.add(block);
|
||||
if (zone.isBombBlock(block)) {
|
||||
// tnt doesn't get reset like normal blocks, gotta schedule a later reset just for the Bomb
|
||||
// structure's tnt block
|
||||
DeferredBlockResetsJob job = new DeferredBlockResetsJob(block.getWorld());
|
||||
job.add(new DeferredBlockReset(block.getX(), block.getY(), block.getZ(), Material.TNT.getId(), (byte)0));
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, 10);
|
||||
}
|
||||
inOneZone = true;
|
||||
break;
|
||||
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
|
||||
dontExplode.add(block);
|
||||
inOneZone = true;
|
||||
break;
|
||||
} else if (zone.getVolume().contains(block)) {
|
||||
inOneZone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inOneZone && explosionInAWarzone) {
|
||||
// if the explosion originated in warzone, always rollback
|
||||
dontExplode.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int dontExplodeSize = dontExplode.size();
|
||||
if (dontExplode.size() > 0) {
|
||||
// Reset the exploded blocks that shouldn't have exploded (some of these are zone artifacts, if rollbackexplosion some may be outside-of-zone blocks
|
||||
DeferredBlockResetsJob job = new DeferredBlockResetsJob(dontExplode.get(0).getWorld());
|
||||
List<Block> doors = new ArrayList<Block>();
|
||||
for (Block dont : dontExplode) {
|
||||
DeferredBlockReset deferred = null;
|
||||
if (dont.getState() instanceof Sign) {
|
||||
String[] lines = ((Sign)dont.getState()).getLines();
|
||||
deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), lines);
|
||||
} else if (dont.getState() instanceof ContainerBlock) {
|
||||
ItemStack[] contents = ((ContainerBlock)dont.getState()).getInventory().getContents();
|
||||
Block worldBlock = dont.getWorld().getBlockAt(dont.getLocation());
|
||||
if (worldBlock.getState() instanceof ContainerBlock) {
|
||||
((ContainerBlock)worldBlock.getState()).getInventory().clear();
|
||||
}
|
||||
deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), copyItems(contents));
|
||||
} else if (dont.getTypeId() == Material.NOTE_BLOCK.getId()) {
|
||||
Block worldBlock = dont.getWorld().getBlockAt(dont.getLocation());
|
||||
if (worldBlock.getState() instanceof NoteBlock) {
|
||||
NoteBlock noteBlock = ((NoteBlock)worldBlock.getState());
|
||||
if (noteBlock != null) {
|
||||
deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), noteBlock.getRawNote());
|
||||
}
|
||||
}
|
||||
} else if (dont.getTypeId() != Material.TNT.getId()) {
|
||||
deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData());
|
||||
if (dont.getTypeId() == Material.WOODEN_DOOR.getId() || dont.getTypeId() == Material.IRON_DOOR_BLOCK.getId()) {
|
||||
doors.add(dont);
|
||||
}
|
||||
}
|
||||
if (deferred != null) {
|
||||
job.add(deferred);
|
||||
}
|
||||
}
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
|
||||
|
||||
// Changed explosion yield following proportion of explosion prevention (makes drops less buggy too)
|
||||
int explodedSize = explodedBlocks.size();
|
||||
float middleYeild = (float)(explodedSize - dontExplodeSize) / (float)explodedSize;
|
||||
float newYeild = middleYeild * event.getYield();
|
||||
|
||||
event.setYield(newYeild);
|
||||
}
|
||||
}
|
||||
|
||||
private List<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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles damage on Players
|
||||
*
|
||||
* @see EntityListener.onEntityDamage()
|
||||
*/
|
||||
@EventHandler(event = EntityDamageEvent.class)
|
||||
public void onEntityDamage(final EntityDamageEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) entity;
|
||||
|
||||
// prevent godmode
|
||||
if (Warzone.getZoneByPlayerName(player.getName()) != null) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
// pass pvp-damage
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
|
||||
} else {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
|
||||
if (zone != null && event.getDamage() >= player.getHealth()) {
|
||||
// Detect death, prevent it and respawn the player
|
||||
String deathMessage = "";
|
||||
String cause = " died";
|
||||
if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK
|
||||
|| event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.LIGHTNING) {
|
||||
cause = " burned to a crisp";
|
||||
} else if (event.getCause() == DamageCause.DROWNING) {
|
||||
cause = " drowned";
|
||||
} else if (event.getCause() == DamageCause.FALL) {
|
||||
cause = " fell to an untimely death";
|
||||
}
|
||||
deathMessage = Team.getTeamByPlayerName(player.getName()).getKind().getColor() + player.getName() + ChatColor.WHITE + cause;
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast(deathMessage);
|
||||
}
|
||||
zone.handleDeath(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = EntityCombustEvent.class)
|
||||
public void onEntityCombust(final EntityCombustEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null && team.getSpawnVolume().contains(player.getLocation())) {
|
||||
// smother out the fire that didn't burn out when you respawned
|
||||
// Stop fire (upcast, watch out!)
|
||||
if (player instanceof CraftPlayer) {
|
||||
net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle();
|
||||
playerEntity.fireTicks = 0;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents creatures from spawning in warzones if no creatures is active
|
||||
*
|
||||
* @see EntityListener.onCreatureSpawn()
|
||||
*/
|
||||
@EventHandler(event = CreatureSpawnEvent.class)
|
||||
public void onCreatureSpawn(final CreatureSpawnEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = event.getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(location);
|
||||
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.NOCREATURES)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents health regaining caused by peaceful mode
|
||||
*
|
||||
* @see EntityListener.onEntityRegainHealth()
|
||||
*/
|
||||
@EventHandler(event = EntityRegainHealthEvent.class)
|
||||
public void onEntityRegainHealth(final EntityRegainHealthEvent event) {
|
||||
if (!War.war.isLoaded() ||
|
||||
(event.getRegainReason() != RegainReason.REGEN
|
||||
&& event.getRegainReason() != RegainReason.EATING
|
||||
&& event.getRegainReason().toString() != "SATIATED")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) entity;
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if ((event.getRegainReason() == RegainReason.EATING
|
||||
|| event.getRegainReason().toString() != "SATIATED" )
|
||||
&& team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)) {
|
||||
// noHunger setting means you can't auto-heal with full hunger bar (use saturation instead to control how fast you get hungry)
|
||||
event.setCancelled(true);
|
||||
} else if (event.getRegainReason() == RegainReason.REGEN) {
|
||||
// disable peaceful mode regen
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = FoodLevelChangeEvent.class)
|
||||
public void onFoodLevelChange(final FoodLevelChangeEvent event) {
|
||||
if (!War.war.isLoaded() || !(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (zone != null && team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = EntityDeathEvent.class)
|
||||
public void onEntityDeath(final EntityDeathEvent event) {
|
||||
if (!War.war.isLoaded() || !(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
event.getDrops().clear();
|
||||
zone.handleDeath(player);
|
||||
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast(player.getName() + " died");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = ExplosionPrimeEvent.class)
|
||||
public void onExplosionPrime(final ExplosionPrimeEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location eventLocation = event.getEntity().getLocation();
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isBombBlock(eventLocation.getBlock())) {
|
||||
// prevent the Bomb from exploding on its pedestral
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,767 +0,0 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.entity.CraftItem;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerInventoryEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.tommytony.war.Bomb;
|
||||
import com.tommytony.war.Cake;
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.LoadoutSelection;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.ZoneSetter;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.spout.SpoutMessenger;
|
||||
|
||||
/**
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarPlayerListener implements Listener {
|
||||
private java.util.Random random = new java.util.Random();
|
||||
private HashMap<String, Location> latestLocations = new HashMap<String, Location>();
|
||||
|
||||
/**
|
||||
* Correctly removes quitting players from warzones
|
||||
*
|
||||
* @see PlayerListener.onPlayerQuit()
|
||||
*/
|
||||
@EventHandler(event = PlayerQuitEvent.class)
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null) {
|
||||
zone.handlePlayerLeave(player, zone.getTeleport(), true);
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
War.war.removeWandBearer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = PlayerDropItemEvent.class)
|
||||
public void onPlayerDropItem(final PlayerDropItemEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
|
||||
if (zone.isFlagThief(player.getName())) {
|
||||
// a flag thief can't drop his flag
|
||||
War.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.isBombThief(player.getName())) {
|
||||
// a bomb thief can't drop his bomb
|
||||
War.war.badMsg(player, "Can't drop items while stealing bomb. What are you doing?! Run for your enemy's spawn!");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.isCakeThief(player.getName())) {
|
||||
// a cake thief can't drop his cake
|
||||
War.war.badMsg(player, "Can't drop items while stealing cake. What are you doing?! Run!");
|
||||
event.setCancelled(true);
|
||||
} else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.NODROPS)) {
|
||||
War.war.badMsg(player, "Can't drop items in this warzone.");
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Item item = event.getItemDrop();
|
||||
if (item != null) {
|
||||
ItemStack itemStack = item.getItemStack();
|
||||
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) {
|
||||
// Can't drop your team's kind block
|
||||
War.war.badMsg(player, "Can't drop " + team.getName() + " blocks.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone.isNearWall(player.getLocation()) && itemStack != null) {
|
||||
War.war.badMsg(player, "Can't drop items near the zone border!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone.getLoadoutSelections().keySet().contains(player.getName())
|
||||
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
// still at spawn
|
||||
War.war.badMsg(player, "Can't drop items while still in spawn.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
Item item = event.getItemDrop();
|
||||
if (item.getItemStack().getType() == Material.WOOD_SWORD) {
|
||||
String zoneName = War.war.getWandBearerZone(player);
|
||||
War.war.removeWandBearer(player);
|
||||
War.war.msg(player, "You dropped the zone " + zoneName + " wand.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = PlayerPickupItemEvent.class)
|
||||
public void onPlayerPickupItem(final PlayerPickupItemEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null) {
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
|
||||
if (zone.isFlagThief(player.getName())) {
|
||||
// a flag thief can't pick up anything
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Item item = event.getItem();
|
||||
if (item != null && item instanceof CraftItem) {
|
||||
CraftItem cItem = (CraftItem) item;
|
||||
if (cItem != null) {
|
||||
ItemStack itemStack = cItem.getItemStack();
|
||||
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) {
|
||||
// Can't pick up a second precious block
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = PlayerInventoryEvent.class)
|
||||
public void onInventoryOpen(final PlayerInventoryEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Inventory inventory = event.getInventory();
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null && inventory instanceof PlayerInventory) {
|
||||
// make sure the player doesn't have too many precious blocks
|
||||
// or illegal armor (i.e. armor not found in loadout)
|
||||
PlayerInventory playerInv = (PlayerInventory) inventory;
|
||||
ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData());
|
||||
if (playerInv.contains(teamKindBlock, 2)) {
|
||||
playerInv.remove(teamKindBlock);
|
||||
playerInv.addItem(teamKindBlock);
|
||||
War.war.badMsg(player, "All that " + team.getName() + " must have been heavy!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = PlayerCommandPreprocessEvent.class)
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Team talkingPlayerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (talkingPlayerTeam != null) {
|
||||
String msg = event.getMessage();
|
||||
String[] split = msg.split(" ");
|
||||
if (!War.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) {
|
||||
String command = split[0].substring(1);
|
||||
if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) {
|
||||
// allow white commands
|
||||
for (String whiteCommand : War.war.getCommandWhitelist()) {
|
||||
if (whiteCommand.equals(command)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
War.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = PlayerKickEvent.class)
|
||||
public void onPlayerKick(final PlayerKickEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
String reason = event.getReason();
|
||||
if (reason.contains("moved") || reason.contains("too quickly") || reason.contains("Hacking")) {
|
||||
boolean inWarzone = Warzone.getZoneByLocation(player) != null;
|
||||
boolean inLobby = ZoneLobby.getLobbyByLocation(player) != null;
|
||||
boolean inWarhub = false;
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(player.getLocation())) {
|
||||
inWarhub = true;
|
||||
}
|
||||
if (inWarzone || inLobby || inWarhub) {
|
||||
event.setCancelled(true);
|
||||
War.war.log("Prevented " + player.getName() + " from getting kicked.", java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = PlayerInteractEvent.class)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getItemInHand().getType() == Material.WOOD_SWORD && War.war.isWandBearer(player)) {
|
||||
String zoneName = War.war.getWandBearerZone(player);
|
||||
ZoneSetter setter = new ZoneSetter(player, zoneName);
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
War.war.badMsg(player, "Too far.");
|
||||
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
setter.placeCorner1(event.getClickedBlock());
|
||||
event.setUseItemInHand(Result.ALLOW);
|
||||
} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
setter.placeCorner2(event.getClickedBlock());
|
||||
event.setUseItemInHand(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null && zone.getLoadoutSelections().containsKey(player.getName())
|
||||
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
War.war.badMsg(player, "Can't use items while still in spawn.");
|
||||
|
||||
ItemStack inHand = event.getItem();
|
||||
|
||||
if (inHand != null) {
|
||||
ItemStack newItemInHand = new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData());
|
||||
newItemInHand.setDurability(inHand.getDurability());
|
||||
event.getPlayer().setItemInHand(newItemInHand);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = PlayerMoveEvent.class)
|
||||
public void onPlayerMove(final PlayerMoveEvent event) {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
|
||||
|
||||
Location previousLocation = latestLocations.get(player.getName());
|
||||
if (previousLocation != null &&
|
||||
playerLoc.getBlockX() == previousLocation.getBlockX() &&
|
||||
playerLoc.getBlockY() == previousLocation.getBlockY() &&
|
||||
playerLoc.getBlockZ() == previousLocation.getBlockZ() &&
|
||||
playerLoc.getWorld() == previousLocation.getWorld()) {
|
||||
// we only care when people change location
|
||||
return;
|
||||
}
|
||||
latestLocations.put(player.getName(), playerLoc);
|
||||
|
||||
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
|
||||
boolean canPlay = War.war.canPlayWar(player);
|
||||
boolean isMaker = War.war.isZoneMaker(player);
|
||||
|
||||
// Zone walls
|
||||
Team currentTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
|
||||
boolean protecting = false;
|
||||
if (currentTeam != null) {
|
||||
if (playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS)) {
|
||||
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
} else {
|
||||
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
if (nearbyZone != null && nearbyZone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS) && !isMaker) {
|
||||
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (!protecting) {
|
||||
// zone makers still need to delete their walls
|
||||
// make sure to delete any wall guards as you leave
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
zone.dropZoneWallGuardIfAny(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Warzone lobby gates
|
||||
if (locLobby != null) {
|
||||
Warzone zone = locLobby.getZone();
|
||||
Team oldTeam = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isAutoAssignGate = false;
|
||||
if (oldTeam == null && canPlay) { // trying to counter spammy player move
|
||||
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
|
||||
if (isAutoAssignGate) {
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
this.handleDisabledZone(event, player, zone);
|
||||
} else {
|
||||
this.dropFromOldTeamIfAny(player);
|
||||
int noOfPlayers = 0;
|
||||
int totalCap = 0;
|
||||
for (Team t : zone.getTeams()) {
|
||||
noOfPlayers += t.getPlayers().size();
|
||||
totalCap += t.getTeamConfig().resolveInt(TeamConfig.MAXSCORE);
|
||||
}
|
||||
|
||||
if (noOfPlayers < totalCap) {
|
||||
zone.autoAssign(player);
|
||||
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
} else {
|
||||
event.setTo(zone.getTeleport());
|
||||
// player.teleport(zone.getTeleport());
|
||||
War.war.badMsg(player, "All teams are full.");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// go through all the team gates
|
||||
for (Team team : zone.getTeams()) {
|
||||
if (zone.getLobby().isInTeamGate(team, playerLoc)) {
|
||||
this.dropFromOldTeamIfAny(player);
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
this.handleDisabledZone(event, player, zone);
|
||||
} else if (team.getPlayers().size() < team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE)) {
|
||||
team.addPlayer(player);
|
||||
team.resetSign();
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
zone.keepPlayerState(player);
|
||||
War.war.msg(player, "Your inventory is in storage until you exit with '/war leave'.");
|
||||
zone.respawnPlayer(event, team, player);
|
||||
for (Team t : zone.getTeams()) {
|
||||
t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
|
||||
}
|
||||
} else {
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "Team " + team.getName() + " is full.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) && !War.war.getWarHub().getVolume().contains(player.getLocation())) {
|
||||
this.dropFromOldTeamIfAny(player);
|
||||
event.setTo(War.war.getWarHub().getLocation());
|
||||
// player.teleport(war.getWarHub().getLocation());
|
||||
War.war.msg(player, "Welcome to the War hub.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Warhub zone gates
|
||||
WarHub hub = War.war.getWarHub();
|
||||
if (hub != null && hub.getVolume().contains(player.getLocation())) {
|
||||
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
|
||||
if (zone != null && zone.getTeleport() != null) {
|
||||
event.setTo(zone.getTeleport());
|
||||
// player.teleport(zone.getTeleport());
|
||||
War.war.msg(player, "Welcome to warzone " + zone.getName() + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc);
|
||||
Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (isLeaving) { // already in a team and in warzone, leaving
|
||||
// same as leave
|
||||
if (playerTeam != null) {
|
||||
boolean atSpawnAlready = playerTeam.getTeamSpawn().getBlockX() == player.getLocation().getBlockX() && playerTeam.getTeamSpawn().getBlockY() == player.getLocation().getBlockY() && playerTeam.getTeamSpawn().getBlockZ() == player.getLocation().getBlockZ();
|
||||
if (!atSpawnAlready) {
|
||||
playerWarzone.handlePlayerLeave(player, playerWarzone.getTeleport(), event, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (playerWarzone != null) {
|
||||
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died
|
||||
if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) {
|
||||
List<BlockFace> nearestWalls = playerWarzone.getNearestWalls(playerLoc);
|
||||
War.war.badMsg(player, "Use /leave (or /war leave) to exit the zone.");
|
||||
if(nearestWalls != null && nearestWalls.size() > 0) {
|
||||
// First, try to bump the player back in
|
||||
int northSouthMove = 0;
|
||||
int eastWestMove = 0;
|
||||
int upDownMove = 0;
|
||||
int moveDistance = 1;
|
||||
|
||||
if (nearestWalls.contains(BlockFace.NORTH)) {
|
||||
// move south
|
||||
northSouthMove += moveDistance;
|
||||
} else if (nearestWalls.contains(BlockFace.SOUTH)) {
|
||||
// move north
|
||||
northSouthMove -= moveDistance;
|
||||
}
|
||||
|
||||
if (nearestWalls.contains(BlockFace.EAST)) {
|
||||
// move west
|
||||
eastWestMove += moveDistance;
|
||||
} else if (nearestWalls.contains(BlockFace.WEST)) {
|
||||
// move east
|
||||
eastWestMove -= moveDistance;
|
||||
}
|
||||
|
||||
if (nearestWalls.contains(BlockFace.UP)) {
|
||||
upDownMove -= moveDistance;
|
||||
} else if (nearestWalls.contains(BlockFace.DOWN)) {
|
||||
// fell off the map, back to spawn
|
||||
event.setTo(playerTeam.getTeamSpawn());
|
||||
return;
|
||||
}
|
||||
|
||||
event.setTo(new Location(playerLoc.getWorld(),
|
||||
playerLoc.getX() + northSouthMove,
|
||||
playerLoc.getY() + upDownMove,
|
||||
playerLoc.getZ() + eastWestMove,
|
||||
playerLoc.getYaw(),
|
||||
playerLoc.getPitch()));
|
||||
return;
|
||||
} else {
|
||||
// Otherwise, send him to spawn
|
||||
event.setTo(playerTeam.getTeamSpawn());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!playerTeam.getSpawnVolume().contains(playerLoc)) {
|
||||
if (!playerWarzone.isEnoughPlayers()) {
|
||||
War.war.badMsg(player, "Can't leave spawn until there's a minimum of " + playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINPLAYERS)
|
||||
+" player(s) on at least " + playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINTEAMS) + " team(s).");
|
||||
event.setTo(playerTeam.getTeamSpawn());
|
||||
return;
|
||||
}
|
||||
if (playerWarzone.isRespawning(player)) {
|
||||
int rt = playerTeam.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER);
|
||||
String isS = "s";
|
||||
if (rt==1) isS = "";
|
||||
War.war.badMsg(player, "Can't leave spawn for "+rt+" second"+isS+" after spawning!");
|
||||
event.setTo(playerTeam.getTeamSpawn());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Monuments
|
||||
if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead
|
||||
&& this.random.nextInt(7) == 3) { // one chance out of many of getting healed
|
||||
int currentHp = player.getHealth();
|
||||
int newHp = Math.min(20, currentHp + locZone.getWarzoneConfig().getInt(WarzoneConfig.MONUMENTHEAL));
|
||||
|
||||
player.setHealth(newHp);
|
||||
String isS = "s";
|
||||
String heartNum = ""; // since (newHp-currentHp)/2 won't give the right amount
|
||||
if (newHp - currentHp == 2) { // no 's' in 'hearts' when it's just one heart
|
||||
isS = "";
|
||||
heartNum = "one ";
|
||||
} else if (newHp - currentHp % 2 == 0) {
|
||||
heartNum = ((newHp - currentHp) / 2) + " ";
|
||||
} else {
|
||||
heartNum = ((newHp - currentHp - 1) / 2) + ".5 ";
|
||||
}
|
||||
War.war.msg(player, "Your dance pleases the monument's voodoo. You gain " + heartNum + "heart" + isS + "!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Flag capture
|
||||
if (playerWarzone.isFlagThief(player.getName())) {
|
||||
boolean inSpawn = playerTeam.getSpawnVolume().contains(player.getLocation());
|
||||
boolean inFlag = (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation()));
|
||||
|
||||
if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.BOTH)) {
|
||||
if (!inSpawn && !inFlag) {
|
||||
return;
|
||||
}
|
||||
} else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.SPAWN)) {
|
||||
if (inFlag) {
|
||||
War.war.badMsg(player, "You have to capture the enemy flag at your team's spawn.");
|
||||
return;
|
||||
} else if (!inSpawn) {
|
||||
return;
|
||||
}
|
||||
} else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.FLAG)) {
|
||||
if (inSpawn) {
|
||||
War.war.badMsg(player, "You have to capture the enemy flag at your team's flag.");
|
||||
return;
|
||||
} else if (!inFlag) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerWarzone.isTeamFlagStolen(playerTeam) && playerTeam.getTeamConfig().resolveBoolean(TeamConfig.FLAGMUSTBEHOME)) {
|
||||
War.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned.");
|
||||
} else {
|
||||
// flags can be captured at own spawn or own flag pole
|
||||
playerTeam.addPoint();
|
||||
Team victim = playerWarzone.getVictimTeamForFlagThief(player.getName());
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " captured"),
|
||||
SpoutMessenger.cleanForNotification(victim.getKind().getColor() + victim.getName() + ChatColor.YELLOW + " flag!"),
|
||||
victim.getKind().getMaterial(),
|
||||
victim.getKind().getData(),
|
||||
10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point.");
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(player, playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
|
||||
victim.initializeTeamFlag();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
playerWarzone.removeFlagThief(player.getName());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Bomb detonation
|
||||
if (playerWarzone.isBombThief(player.getName())) {
|
||||
boolean inEnemySpawn = false;
|
||||
Team victim = null;
|
||||
for (Team team : playerWarzone.getTeams()) {
|
||||
if (team != playerTeam
|
||||
&& team.getSpawnVolume().contains(player.getLocation())
|
||||
&& team.getPlayers().size() > 0) {
|
||||
inEnemySpawn = true;
|
||||
victim = team;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (inEnemySpawn) {
|
||||
Bomb bomb = playerWarzone.getBombForThief(player.getName());
|
||||
|
||||
// Boom!
|
||||
playerWarzone.getWorld().createExplosion(player.getLocation(), 2F);
|
||||
|
||||
playerTeam.addPoint();
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " blew up "),
|
||||
SpoutMessenger.cleanForNotification(victim.getKind().getColor() + victim.getName() + ChatColor.YELLOW + "'s spawn!"),
|
||||
victim.getKind().getMaterial(),
|
||||
victim.getKind().getData(),
|
||||
10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " blew up team " + victim.getName() + "'s spawn. Team " + playerTeam.getName() + " scores one point.");
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(player, playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
|
||||
// bring back flag to team that lost it
|
||||
victim.getSpawnVolume().resetBlocks();
|
||||
victim.initializeTeamSpawn();
|
||||
|
||||
// bring back tnt
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.addBombBlocks();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
|
||||
playerWarzone.removeBombThief(player.getName());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Cake retrieval
|
||||
if (playerWarzone.isCakeThief(player.getName())) {
|
||||
boolean inSpawn = playerTeam.getSpawnVolume().contains(player.getLocation());
|
||||
|
||||
if (inSpawn) {
|
||||
boolean hasOpponent = false;
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
if (t != playerTeam && t.getPlayers().size() > 0) {
|
||||
hasOpponent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't let someone alone make points off cakes
|
||||
if (hasOpponent) {
|
||||
Cake cake = playerWarzone.getCakeForThief(player.getName());
|
||||
|
||||
// Woot!
|
||||
playerTeam.addPoint();
|
||||
playerTeam.setRemainingLives(playerTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
|
||||
|
||||
// Notify everyone
|
||||
for (Team t : playerWarzone.getTeams()) {
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " captured"),
|
||||
SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "cake " + ChatColor.GREEN + cake.getName() + ChatColor.YELLOW + "!"),
|
||||
playerTeam.getKind().getMaterial(),
|
||||
playerTeam.getKind().getData(),
|
||||
10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
|
||||
+ " captured cake " + ChatColor.GREEN + cake.getName() + ChatColor.WHITE + ". Team " + playerTeam.getName() + " scores one point and gets a full lifepool.");
|
||||
}
|
||||
|
||||
// Detect win conditions
|
||||
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(player, playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
} else {
|
||||
// just added a point
|
||||
|
||||
// bring back cake
|
||||
cake.getVolume().resetBlocks();
|
||||
cake.addCakeBlocks();
|
||||
|
||||
playerWarzone.respawnPlayer(event, playerTeam, player);
|
||||
playerTeam.resetSign();
|
||||
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
|
||||
playerWarzone.removeCakeThief(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Class selection lock
|
||||
if (!playerTeam.getSpawnVolume().contains(player.getLocation()) &&
|
||||
playerWarzone.getLoadoutSelections().keySet().contains(player.getName())
|
||||
&& playerWarzone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
playerWarzone.getLoadoutSelections().get(player.getName()).setStillInSpawn(false);
|
||||
}
|
||||
|
||||
} else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
|
||||
// player is not in any team, but inside warzone boundaries, get him out
|
||||
Warzone zone = Warzone.getZoneByLocation(playerLoc);
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "You can't be inside a warzone without a team.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(event = PlayerToggleSneakEvent.class)
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
if (War.war.isLoaded() && event.isSneaking()) {
|
||||
Warzone playerWarzone = Warzone.getZoneByLocation(event.getPlayer());
|
||||
Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (playerWarzone != null && playerTeam != null && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1 && playerTeam.getSpawnVolume().contains(event.getPlayer().getLocation())) {
|
||||
if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName())
|
||||
&& playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) {
|
||||
LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName());
|
||||
int currentIndex = (selection.getSelectedIndex() + 1) % (playerTeam.getInventories().resolveLoadouts().keySet().size());
|
||||
selection.setSelectedIndex(currentIndex);
|
||||
|
||||
playerWarzone.equipPlayerLoadoutSelection(event.getPlayer(), playerTeam, false, true);
|
||||
} else {
|
||||
War.war.badMsg(event.getPlayer(), "Can't change loadout after exiting the spawn.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void purgeLatestPositions() {
|
||||
this.latestLocations.clear();
|
||||
}
|
||||
|
||||
private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) {
|
||||
if (zone.getLobby() != null) {
|
||||
War.war.badMsg(player, "This warzone is disabled.");
|
||||
event.setTo(zone.getTeleport());
|
||||
}
|
||||
}
|
||||
|
||||
private void dropFromOldTeamIfAny(Player player) {
|
||||
// drop from old team if any
|
||||
Team previousTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (previousTeam != null) {
|
||||
if (!previousTeam.removePlayer(player.getName())) {
|
||||
War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package bukkit.tommytony.war;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
public class WarServerListener implements Listener {
|
||||
|
||||
@EventHandler(event = PluginDisableEvent.class)
|
||||
public void onPluginDisable(final PluginDisableEvent event) {
|
||||
if (event.getPlugin().getDataFolder().getName().equals("Spout")) {
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player player : War.war.getServer().getOnlinePlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(player);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.getMainScreen().removeWidgets(War.war);
|
||||
}
|
||||
}
|
||||
War.war.getSpoutMessenger().clearAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
/**
|
||||
* Represents a command that may only be used by War admins
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractWarAdminCommand extends AbstractWarCommand {
|
||||
|
||||
public AbstractWarAdminCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (sender instanceof Player) {
|
||||
if (!War.war.isWarAdmin((Player) sender)) {
|
||||
throw new NotWarAdminException();
|
||||
}
|
||||
} else if (!(sender instanceof ConsoleCommandSender)) {
|
||||
throw new NotWarAdminException();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
/**
|
||||
* Represents a war command
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public abstract class AbstractWarCommand {
|
||||
|
||||
/**
|
||||
* The sender of this command
|
||||
*
|
||||
* @var sender
|
||||
*/
|
||||
private CommandSender sender;
|
||||
|
||||
/**
|
||||
* The arguments of this command
|
||||
*
|
||||
* @var args
|
||||
*/
|
||||
protected String[] args;
|
||||
|
||||
/**
|
||||
* Instance of WarCommandHandler
|
||||
*
|
||||
* @var handler
|
||||
*/
|
||||
protected WarCommandHandler handler;
|
||||
|
||||
public AbstractWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
this.handler = handler;
|
||||
this.setSender(sender);
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the command
|
||||
*
|
||||
* @return true if command was used the right way
|
||||
*/
|
||||
abstract public boolean handle();
|
||||
|
||||
/**
|
||||
* Sends a success message
|
||||
*
|
||||
* @param message message to send
|
||||
*/
|
||||
public void msg(String message) {
|
||||
War.war.msg(this.getSender(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a failure message
|
||||
*
|
||||
* @param message message to send
|
||||
*/
|
||||
public void badMsg(String message) {
|
||||
War.war.badMsg(this.getSender(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the command-sender
|
||||
*
|
||||
* @param sender new sender
|
||||
*/
|
||||
public void setSender(CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command-sender
|
||||
*
|
||||
* @return Command-Sender
|
||||
*/
|
||||
public CommandSender getSender() {
|
||||
return this.sender;
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
/**
|
||||
* Represents a command that may only be used by zone makers
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public abstract class AbstractZoneMakerCommand extends AbstractWarCommand {
|
||||
|
||||
public AbstractZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (sender instanceof Player) {
|
||||
// for players check War.isZoneMaker()
|
||||
if (!War.war.isZoneMaker((Player) sender)) {
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
} else if (!(sender instanceof ConsoleCommandSender)) {
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSenderAuthorOfZone(Warzone zone) {
|
||||
if (this.getSender() instanceof Player) {
|
||||
if (War.war.isWarAdmin((Player) this.getSender())) {
|
||||
// War admin has rights over all warzones
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not War admin, is he author?
|
||||
boolean isAuthor = zone.isAuthor((Player) this.getSender());
|
||||
if (!isAuthor) {
|
||||
War.war.badMsg(this.getSender(), "You can't do this because you are not an author of the " + zone.getName() + " warzone." );
|
||||
}
|
||||
return isAuthor;
|
||||
} else {
|
||||
// From console, you can do anything
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Bomb;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Deletes a bomb.
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class DeleteBombCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteBombCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bomb bomb = zone.getBomb(this.args[0]);
|
||||
if (bomb != null) {
|
||||
bomb.getVolume().resetBlocks();
|
||||
zone.getBombs().remove(bomb);
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
this.msg("Bomb " + bomb.getName() + " removed.");
|
||||
} else {
|
||||
this.badMsg("No such bomb.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Cake;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Deletes a cake.
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class DeleteCakeCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteCakeCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Cake cake = zone.getCake(this.args[0]);
|
||||
if (cake != null) {
|
||||
cake.getVolume().resetBlocks();
|
||||
zone.getCakes().remove(cake);
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
this.msg("Cake " + cake.getName() + " removed.");
|
||||
} else {
|
||||
this.badMsg("No such cake.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Deletes a monument.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteMonumentCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteMonumentCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Monument monument = zone.getMonument(this.args[0]);
|
||||
if (monument != null) {
|
||||
monument.getVolume().resetBlocks();
|
||||
zone.getMonuments().remove(monument);
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
this.msg("Monument " + monument.getName() + " removed.");
|
||||
} else {
|
||||
this.badMsg("No such monument.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Deletes a team.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteTeamCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Team team = zone.getTeamByKind(TeamKind.teamKindFromString(this.args[0]));
|
||||
if (team != null) {
|
||||
if (team.getFlagVolume() != null) {
|
||||
team.getFlagVolume().resetBlocks();
|
||||
}
|
||||
team.getSpawnVolume().resetBlocks();
|
||||
zone.getTeams().remove(team);
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
this.msg("Team " + team.getName() + " removed.");
|
||||
} else {
|
||||
this.badMsg("No such team.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Deletes a monument.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteTeamFlagCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Team teamFlagTeam = null;
|
||||
for (Team team : zone.getTeams()) {
|
||||
if (team.getName().startsWith(this.args[0].toLowerCase())) {
|
||||
teamFlagTeam = team;
|
||||
}
|
||||
}
|
||||
if (teamFlagTeam != null) {
|
||||
teamFlagTeam.deleteTeamFlag();
|
||||
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
this.msg(teamFlagTeam.getName() + " flag removed.");
|
||||
} else {
|
||||
this.badMsg("No such team flag.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.VolumeMapper;
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
|
||||
/**
|
||||
* Deletes the warhub.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteWarhubCommand extends AbstractWarAdminCommand {
|
||||
public DeleteWarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null) {
|
||||
// reset existing hub
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
VolumeMapper.delete(War.war.getWarHub().getVolume());
|
||||
War.war.setWarHub((WarHub) null);
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
|
||||
this.msg("War hub removed.");
|
||||
} else {
|
||||
this.badMsg("No War hub to delete.");
|
||||
}
|
||||
WarYmlMapper.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Deletes a warzone.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class DeleteZoneCommand extends AbstractZoneMakerCommand {
|
||||
public DeleteZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Team t : zone.getTeams()) {
|
||||
if (t.getTeamFlag() != null) {
|
||||
t.getFlagVolume().resetBlocks();
|
||||
}
|
||||
t.getSpawnVolume().resetBlocks();
|
||||
|
||||
// reset inventory
|
||||
for (Player p : t.getPlayers()) {
|
||||
zone.restorePlayerState(p);
|
||||
}
|
||||
}
|
||||
for (Monument m : zone.getMonuments()) {
|
||||
m.getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.getVolume().resetBlocks();
|
||||
War.war.getWarzones().remove(zone);
|
||||
WarYmlMapper.save();
|
||||
WarzoneYmlMapper.delete(zone.getName());
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
this.msg("Warzone " + zone.getName() + " removed.");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
|
||||
/**
|
||||
* Joins a team.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class JoinCommand extends AbstractWarCommand {
|
||||
public JoinCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
if (!War.war.canPlayWar(player)) {
|
||||
this.badMsg("Cannot play war. You need the war.player permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Warzone zone;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 2) {
|
||||
// zone by name
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
// move the team-name to first place :)
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String name = this.args[0];
|
||||
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
|
||||
// drop from old team if any
|
||||
Team previousTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (previousTeam != null) {
|
||||
if (previousTeam.getName().startsWith(name) || previousTeam.getKind() == kind) {
|
||||
// trying to join own team
|
||||
War.war.badMsg(player, "Can't join your own team.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Warzone oldZone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (!previousTeam.removePlayer(player.getName())) {
|
||||
War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING);
|
||||
}
|
||||
previousTeam.resetSign();
|
||||
}
|
||||
|
||||
// join new team
|
||||
|
||||
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
this.msg("This warzone is disabled.");
|
||||
} else {
|
||||
List<Team> teams = zone.getTeams();
|
||||
boolean foundTeam = false;
|
||||
for (Team team : teams) {
|
||||
if (team.getName().startsWith(name) || team.getKind() == kind) {
|
||||
if (!zone.hasPlayerState(player.getName())) {
|
||||
zone.keepPlayerState(player);
|
||||
this.msg("Your inventory is in storage until you use '/war leave'.");
|
||||
}
|
||||
if (team.getPlayers().size() < team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE)) {
|
||||
team.addPlayer(player);
|
||||
team.resetSign();
|
||||
zone.respawnPlayer(team, player);
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
foundTeam = true;
|
||||
} else {
|
||||
this.msg("Team " + team.getName() + " is full.");
|
||||
foundTeam = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundTeam) {
|
||||
for (Team team : teams) {
|
||||
team.teamcast("" + player.getName() + " joined " + team.getName());
|
||||
}
|
||||
} else {
|
||||
this.msg("No such team. Try /teams.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Leaves a game.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class LeaveCommand extends AbstractWarCommand {
|
||||
public LeaveCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
zone.handlePlayerLeave(player, zone.getTeleport(), true);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
/**
|
||||
* Loads war.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class LoadWarCommand extends AbstractWarAdminCommand {
|
||||
public LoadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.loadWar();
|
||||
this.msg("War loaded.");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class NextBattleCommand extends AbstractZoneMakerCommand {
|
||||
public NextBattleCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
zone.clearThieves();
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast("The battle was interrupted. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and life pools...");
|
||||
}
|
||||
zone.getVolume().resetBlocksAsJob();
|
||||
zone.initializeZoneAsJob();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
/**
|
||||
* NotZoneMakerException is thrown when a player is no zonemaker.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class NotWarAdminException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5412011034665080340L;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
/**
|
||||
* NotZoneMakerException is thrown when a player is no zonemaker.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class NotZoneMakerException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5412011034665080340L;
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mappers.PropertiesFile;
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
public class RenameZoneCommand extends AbstractZoneMakerCommand {
|
||||
public RenameZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
|
||||
if (this.args.length == 2) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
this.args[0] = this.args[1];
|
||||
} else if (this.args.length == 1) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// kill old reference
|
||||
zone.unload();
|
||||
War.war.getWarzones().remove(zone);
|
||||
|
||||
// rename zone file
|
||||
(new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".yml")).renameTo(new File(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".yml"));
|
||||
// rename zone folder
|
||||
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName())).renameTo(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0]));
|
||||
|
||||
// TODO: Move renaming into ZoneVolumeMapper?
|
||||
// rename volume files
|
||||
String oldStart = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0] + "/volume-" + zone.getName() + ".";
|
||||
String newStart = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0] + "/volume-" + this.args[0] + ".";
|
||||
(new File(oldStart + "corners")).renameTo(new File(newStart + "corners"));
|
||||
(new File(oldStart + "blocks")).renameTo(new File(newStart + "blocks"));
|
||||
(new File(oldStart + "signs")).renameTo(new File(newStart + "signs"));
|
||||
(new File(oldStart + "invs")).renameTo(new File(newStart + "invs"));
|
||||
|
||||
// set new name
|
||||
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".yml");
|
||||
warzoneConfig.setString("name", this.args[0]);
|
||||
warzoneConfig.save();
|
||||
warzoneConfig.close();
|
||||
|
||||
War.war.log("Loading zone " + this.args[0] + "...", Level.INFO);
|
||||
Warzone newZone = WarzoneYmlMapper.load(this.args[0], false);
|
||||
War.war.getWarzones().add(newZone);
|
||||
// zone.getVolume().loadCorners();
|
||||
newZone.getVolume().loadCorners();
|
||||
if (newZone.getLobby() != null) {
|
||||
newZone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
if (newZone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
|
||||
newZone.getVolume().resetBlocks();
|
||||
}
|
||||
newZone.initializeZone();
|
||||
|
||||
// save war config
|
||||
WarYmlMapper.save();
|
||||
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
this.msg("Warzone " + zone.getName() + " renamed to " + this.args[0] + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class ResetZoneCommand extends AbstractZoneMakerCommand {
|
||||
public ResetZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
zone.clearThieves();
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast("The war has ended. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and teams...");
|
||||
for (Player p : team.getPlayers()) {
|
||||
zone.restorePlayerState(p);
|
||||
p.teleport(zone.getTeleport());
|
||||
War.war.msg(p, "You have left the warzone. Your inventory is being restored.");
|
||||
}
|
||||
team.resetPoints();
|
||||
team.getPlayers().clear();
|
||||
}
|
||||
|
||||
this.msg("Reloading warzone " + zone.getName() + ".");
|
||||
zone.getVolume().resetBlocksAsJob();
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocksAsJob();
|
||||
}
|
||||
zone.initializeZoneAsJob();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
public class SaveZoneCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SaveZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
|
||||
if (this.args.length > 0 && !this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if (this.args.length > 1) {
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
}
|
||||
|
||||
// We have a warzone and indexed-from-0 arguments, let's updatethis.msg(player, "Saving warzone " + warzone.getName() + ".");
|
||||
int savedBlocks = zone.saveState(true);
|
||||
|
||||
// changed settings: must reinitialize with new settings
|
||||
String namedParamResult = War.war.updateZoneFromNamedParams(zone, commandSender, this.args);
|
||||
WarzoneYmlMapper.save(zone, true);
|
||||
if (this.args.length > 0) {
|
||||
// the config may have changed, requiring a reset for spawn styles etc.
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone(); // bring back team spawns etc
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
|
||||
this.msg("Warzone " + zone.getName() + " initial state changed. Saved " + savedBlocks + " blocks." + namedParamResult);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Bomb;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Places a bomb
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class SetBombCommand extends AbstractZoneMakerCommand {
|
||||
public SetBombCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasBomb(this.args[0])) {
|
||||
// move the existing bomb
|
||||
Bomb bomb = zone.getBomb(this.args[0]);
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.setLocation(player.getLocation());
|
||||
this.msg("Bomb " + bomb.getName() + " was moved.");
|
||||
} else {
|
||||
// create a new bomb
|
||||
Bomb bomb = new Bomb(this.args[0], zone, player.getLocation());
|
||||
zone.getBombs().add(bomb);
|
||||
this.msg("Bomb " + bomb.getName() + " created.");
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Cake;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Places a cake
|
||||
*
|
||||
* @author tommytony
|
||||
*/
|
||||
public class SetCakeCommand extends AbstractZoneMakerCommand {
|
||||
public SetCakeCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasCake(this.args[0])) {
|
||||
// move the existing cake
|
||||
Cake cake = zone.getCake(this.args[0]);
|
||||
cake.getVolume().resetBlocks();
|
||||
cake.setLocation(player.getLocation());
|
||||
this.msg("Cake " + cake.getName() + " was moved.");
|
||||
} else {
|
||||
// create a new cake
|
||||
Cake cake = new Cake(this.args[0], zone, player.getLocation());
|
||||
zone.getCakes().add(cake);
|
||||
this.msg("Cake " + cake.getName() + " created.");
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Places a monument
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetMonumentCommand extends AbstractZoneMakerCommand {
|
||||
public SetMonumentCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args[0].equals(zone.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zone.hasMonument(this.args[0])) {
|
||||
// move the existing monument
|
||||
Monument monument = zone.getMonument(this.args[0]);
|
||||
monument.getVolume().resetBlocks();
|
||||
monument.setLocation(player.getLocation());
|
||||
this.msg("Monument " + monument.getName() + " was moved.");
|
||||
} else {
|
||||
// create a new monument
|
||||
Monument monument = new Monument(this.args[0], zone, player.getLocation());
|
||||
zone.getMonuments().add(monument);
|
||||
this.msg("Monument " + monument.getName() + " created.");
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Places a soawn
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetTeamCommand extends AbstractZoneMakerCommand {
|
||||
public SetTeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TeamKind teamKind = TeamKind.teamKindFromString(this.args[0]);
|
||||
|
||||
if (teamKind == null) {
|
||||
return false;
|
||||
} else {
|
||||
Team existingTeam = zone.getTeamByKind(teamKind);
|
||||
if (existingTeam != null) {
|
||||
// relocate
|
||||
existingTeam.setTeamSpawn(player.getLocation());
|
||||
this.msg("Team " + existingTeam.getName() + " spawn relocated.");
|
||||
} else {
|
||||
// new team (use default TeamKind name for now)
|
||||
Team newTeam = new Team(teamKind.toString(), teamKind, player.getLocation(), zone);
|
||||
newTeam.setRemainingLives(newTeam.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
|
||||
zone.getTeams().add(newTeam);
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
newTeam.setTeamSpawn(player.getLocation());
|
||||
this.msg("Team " + newTeam.getName() + " created with spawn here.");
|
||||
}
|
||||
}
|
||||
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SetTeamConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
Player player = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
boolean wantsToPrint = false;
|
||||
|
||||
Team team = null;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
if (!this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
} else if (this.args[0].equals("-p") || this.args[0].equals("print")) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
player = (Player) commandSender;
|
||||
|
||||
if (zone == null) {
|
||||
// zone not found, is he standing in it?
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
|
||||
team = Team.getTeamByPlayerName(player.getName());
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if (this.args.length == 1) {
|
||||
// Only one param: the warzone name - pritn usage
|
||||
return false;
|
||||
}
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
// args have been shifted if needed
|
||||
if (this.args.length > 0) {
|
||||
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
Team teamByName = zone.getTeamByKind(kind);
|
||||
|
||||
if (team == null && teamByName == null) {
|
||||
// Team not found
|
||||
this.badMsg("No such team. Use /teams.");
|
||||
return true;
|
||||
} else if (this.args.length == 1 && teamByName != null) {
|
||||
// only team name, print config
|
||||
this.msg(War.war.printConfig(teamByName));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (teamByName != null) {
|
||||
// first param was team, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
if (teamByName != null) {
|
||||
// Named team > player's team
|
||||
team = teamByName;
|
||||
}
|
||||
} else {
|
||||
// No team param, show usage
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
// only printing
|
||||
if (this.args.length == 1) {
|
||||
this.msg(War.war.printConfig(team));
|
||||
return true;
|
||||
} else {
|
||||
// first param was to print, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
// We have a warzone, a team and indexed-from-0 arguments, let's update
|
||||
String namedParamReturn = War.war.updateTeamFromNamedParams(team, player, this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.msg("Saving config and resetting warzone " + zone.getName() + ".");
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
zone.getVolume().resetBlocks();
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone(); // bring back team spawns etc
|
||||
|
||||
if (wantsToPrint) {
|
||||
this.msg("Team config saved. Zone reset." + namedParamReturn + " " + War.war.printConfig(team));
|
||||
} else {
|
||||
this.msg("Team config saved. Zone reset." + namedParamReturn);
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.badMsg("Failed to read named parameter(s).");
|
||||
} else {
|
||||
// empty return means no param was parsed - print command usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Places a teamflag
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetTeamFlagCommand extends AbstractZoneMakerCommand {
|
||||
public SetTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
|
||||
if (zone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TeamKind kind = TeamKind.teamKindFromString(this.args[0]);
|
||||
Team team = zone.getTeamByKind(kind);
|
||||
if (team == null) {
|
||||
// no such team yet
|
||||
this.msg("Place the team spawn first.");
|
||||
} else if (team.getFlagVolume() == null) {
|
||||
// new team flag
|
||||
team.setTeamFlag(player.getLocation());
|
||||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
|
||||
this.msg("Team " + team.getName() + " flag added here.");
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
} else {
|
||||
// relocate flag
|
||||
team.getFlagVolume().resetBlocks();
|
||||
team.setTeamFlag(player.getLocation());
|
||||
Location playerLoc = player.getLocation();
|
||||
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1));
|
||||
this.msg("Team " + team.getName() + " flag moved.");
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
|
||||
public class SetWarConfigCommand extends AbstractWarAdminCommand {
|
||||
|
||||
public SetWarConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
boolean wantsToPrint = false;
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length == 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
String config = War.war.printConfig();
|
||||
this.msg(config);
|
||||
return true;
|
||||
} else if (this.args.length > 1 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
String namedParamReturn = War.war.updateFromNamedParams(this.getSender(), this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
WarYmlMapper.save();
|
||||
if (wantsToPrint) {
|
||||
String config = War.war.printConfig();
|
||||
this.msg("War config saved." + namedParamReturn + " " + config);
|
||||
} else {
|
||||
this.msg("War config saved." + namedParamReturn);
|
||||
}
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.msg("Failed to read named parameters.");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
|
||||
/**
|
||||
* Places the warhub
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetWarHubCommand extends AbstractWarAdminCommand {
|
||||
public SetWarHubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (War.war.getWarzones().size() > 0) {
|
||||
if (War.war.getWarHub() != null) {
|
||||
// reset existing hub
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().setLocation(player.getLocation());
|
||||
War.war.getWarHub().initialize();
|
||||
this.msg("War hub moved.");
|
||||
} else {
|
||||
War.war.setWarHub(new WarHub(player.getLocation()));
|
||||
War.war.getWarHub().initialize();
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
this.msg("War hub created.");
|
||||
}
|
||||
WarYmlMapper.save();
|
||||
} else {
|
||||
this.msg("No warzones yet.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.ZoneSetter;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
public class SetZoneCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SetZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else if (this.args.length > 2) {
|
||||
return false;
|
||||
} else if (this.args.length == 1) {
|
||||
War.war.addWandBearer(player, this.args[0]);
|
||||
} else if (this.args.length == 2) {
|
||||
if (!this.args[1].equals("southeast") && !this.args[1].equals("northwest") && !this.args[1].equals("se") && !this.args[1].equals("nw") && !this.args[1].equals("corner1") && !this.args[1].equals("corner2") && !this.args[1].equals("c1") && !this.args[1].equals("c2") && !this.args[1].equals("pos1") && !this.args[1].equals("pos2") && !this.args[1].equals("wand")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ZoneSetter setter = new ZoneSetter(player, this.args[0]);
|
||||
if (this.args[1].equals("northwest") || this.args[1].equals("nw")) {
|
||||
setter.placeNorthwest();
|
||||
} else if (this.args[1].equals("southeast") || this.args[1].equals("se")) {
|
||||
setter.placeSoutheast();
|
||||
} else if (this.args[1].equals("corner1") || this.args[1].equals("c1") || this.args[1].equals("pos1")) {
|
||||
setter.placeCorner1();
|
||||
} else if (this.args[1].equals("corner2") || this.args[1].equals("c2") || this.args[1].equals("pos2")) {
|
||||
setter.placeCorner2();
|
||||
} else if (this.args[1].equals("wand")) {
|
||||
War.war.addWandBearer(player, this.args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SetZoneConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone = null;
|
||||
Player player = null;
|
||||
CommandSender commandSender = this.getSender();
|
||||
boolean isFirstParamWarzone = false;
|
||||
boolean wantsToPrint = false;
|
||||
|
||||
if (this.args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
if (!this.args[0].contains(":")) {
|
||||
// warzone name maybe in first place
|
||||
Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
|
||||
if (zoneByName != null) {
|
||||
zone = zoneByName;
|
||||
isFirstParamWarzone = true;
|
||||
} else if (this.args[0].equals("-p") || this.args[0].equals("print")) {
|
||||
wantsToPrint = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.getSender() instanceof Player) {
|
||||
player = (Player) commandSender;
|
||||
if (zone == null) {
|
||||
// zone not found, is he standing in it?
|
||||
Warzone zoneByLoc = Warzone.getZoneByLocation(player);
|
||||
ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
|
||||
if (zoneByLoc == null && lobbyByLoc != null) {
|
||||
zoneByLoc = lobbyByLoc.getZone();
|
||||
}
|
||||
if (zoneByLoc != null) {
|
||||
zone = zoneByLoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// No warzone found, whatever the mean, escape
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isFirstParamWarzone) {
|
||||
if (this.args.length == 1) {
|
||||
// Only one param: the warzone name - default to usage
|
||||
return false;
|
||||
}
|
||||
// More than one param: the arguments need to be shifted
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
|
||||
// args have been shifted if needed
|
||||
if (this.args.length > 0 && (this.args[0].equals("-p") || this.args[0].equals("print"))) {
|
||||
// only printing
|
||||
if (this.args.length == 1) {
|
||||
this.msg(War.war.printConfig(zone));
|
||||
return true;
|
||||
} else {
|
||||
// first param was to print, shift again
|
||||
String[] newargs = new String[this.args.length - 1];
|
||||
for (int i = 1; i < this.args.length; i++) {
|
||||
newargs[i - 1] = this.args[i];
|
||||
}
|
||||
this.args = newargs;
|
||||
}
|
||||
wantsToPrint = true;
|
||||
}
|
||||
|
||||
// We have a warzone and indexed-from-0 arguments, let's update
|
||||
String namedParamReturn = War.war.updateZoneFromNamedParams(zone, player, this.args);
|
||||
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.msg("Saving config and resetting warzone " + zone.getName() + ".");
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
zone.getVolume().resetBlocks();
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone(); // bring back team spawns etc
|
||||
|
||||
if (wantsToPrint) {
|
||||
this.msg("Warzone config saved. Zone reset." + namedParamReturn + " " + War.war.printConfig(zone));
|
||||
} else {
|
||||
this.msg("Warzone config saved. Zone reset." + namedParamReturn);
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null) { // maybe the zone was disabled/enabled
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
} else if (namedParamReturn.equals("PARSE-ERROR")) {
|
||||
this.badMsg("Failed to read named parameter(s).");
|
||||
} else {
|
||||
// empty return means no param was parsed - print command usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
/**
|
||||
* Places the zonelobby
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class SetZoneLobbyCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
public SetZoneLobbyCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
Warzone zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby != null) {
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
}
|
||||
|
||||
if (zone == null) {
|
||||
// Zone not where player is standing, maybe player is detaching/relocating the lobby
|
||||
Warzone givenWarzone = Warzone.getZoneByName(this.args[0]);
|
||||
if (givenWarzone == null) {
|
||||
return false;
|
||||
} else if (!this.isSenderAuthorOfZone(givenWarzone)) {
|
||||
return true;
|
||||
} else {
|
||||
// Move the warzone lobby
|
||||
ZoneLobby lobby = givenWarzone.getLobby();
|
||||
if (lobby != null) {
|
||||
// reset existing lobby and save new volume at new location
|
||||
lobby.setLocation(player.getLocation());
|
||||
lobby.initialize();
|
||||
this.msg("Warzone lobby moved to your location.");
|
||||
} else {
|
||||
// new lobby
|
||||
lobby = new ZoneLobby(givenWarzone, player.getLocation());
|
||||
givenWarzone.setLobby(lobby);
|
||||
lobby.initialize();
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
this.msg("Warzone lobby moved to your location.");
|
||||
}
|
||||
WarzoneYmlMapper.save(givenWarzone, false);
|
||||
}
|
||||
} else if (!this.isSenderAuthorOfZone(zone)) {
|
||||
return true;
|
||||
} else {
|
||||
// Inside a warzone: use the classic n/s/e/w mode
|
||||
if (!this.args[0].equals("north") && !this.args[0].equals("n") && !this.args[0].equals("east") && !this.args[0].equals("e") && !this.args[0].equals("south") && !this.args[0].equals("s") && !this.args[0].equals("west") && !this.args[0].equals("w")) {
|
||||
return false;
|
||||
}
|
||||
ZoneLobby lobby = zone.getLobby();
|
||||
|
||||
BlockFace wall = BlockFace.WEST;
|
||||
String wallStr = "";
|
||||
if (this.args[0].equals("north") || this.args[0].equals("n")) {
|
||||
wall = BlockFace.NORTH;
|
||||
wallStr = "north";
|
||||
} else if (this.args[0].equals("east") || this.args[0].equals("e")) {
|
||||
wall = BlockFace.EAST;
|
||||
wallStr = "east";
|
||||
} else if (this.args[0].equals("south") || this.args[0].equals("s")) {
|
||||
wall = BlockFace.SOUTH;
|
||||
wallStr = "south";
|
||||
} else if (this.args[0].equals("west") || this.args[0].equals("w")) {
|
||||
wall = BlockFace.WEST;
|
||||
wallStr = "west";
|
||||
}
|
||||
|
||||
if (lobby != null) {
|
||||
// reset existing lobby
|
||||
lobby.getVolume().resetBlocks();
|
||||
lobby.setWall(wall);
|
||||
lobby.initialize();
|
||||
this.msg("Warzone lobby moved to " + wallStr + " side of zone.");
|
||||
} else {
|
||||
// new lobby
|
||||
lobby = new ZoneLobby(zone, wall);
|
||||
zone.setLobby(lobby);
|
||||
lobby.initialize();
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
this.msg("Warzone lobby created on " + wallStr + "side of zone.");
|
||||
}
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
|
||||
/**
|
||||
* Sends a message to all team-members
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class TeamCommand extends AbstractWarCommand {
|
||||
public TeamCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
Team playerTeam = Team.getTeamByPlayerName(player.getName());
|
||||
if (playerTeam == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ChatColor color = playerTeam.getKind().getColor();
|
||||
String teamMessage = color + player.getName() + ": " + ChatColor.WHITE;
|
||||
for (String part : this.args) {
|
||||
teamMessage += part + " ";
|
||||
}
|
||||
playerTeam.teamcast(teamMessage, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
|
||||
/**
|
||||
* Shows team information
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class TeamsCommand extends AbstractWarCommand {
|
||||
public TeamsCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
Warzone zone;
|
||||
if (this.args.length == 1) {
|
||||
zone = Warzone.getZoneByName(this.args[0]);
|
||||
} else if (this.args.length == 0) {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
zone = Warzone.getZoneByLocation((Player) this.getSender());
|
||||
if (zone == null) {
|
||||
ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
|
||||
if (lobby == null) {
|
||||
return false;
|
||||
}
|
||||
zone = lobby.getZone();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (zone == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.msg(zone.getTeamInformation());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
/**
|
||||
* Unloads war.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class UnloadWarCommand extends AbstractWarAdminCommand {
|
||||
public UnloadWarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.unloadWar();
|
||||
this.msg("War unloaded.");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Warps the player to the warhub.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarhubCommand extends AbstractWarCommand {
|
||||
public WarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
if (War.war.getWarHub() == null) {
|
||||
this.badMsg("No warhub on this War server. Try /zones and /zone.");
|
||||
} else if (!War.war.canWarp(player)) {
|
||||
this.badMsg("Can't warp to warhub. You need the 'war.warp' permission.");
|
||||
} else {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (playerWarzone != null) { // was in zone
|
||||
playerWarzone.handlePlayerLeave(player, War.war.getWarHub().getLocation(), true);
|
||||
}
|
||||
player.teleport(War.war.getWarHub().getLocation());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Warps the player to the given warzone.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarzoneCommand extends AbstractWarCommand {
|
||||
public WarzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.args.length != 1) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (!War.war.canWarp(player)) {
|
||||
this.badMsg("Can't warp to zone. You need the 'war.warp' permission.");
|
||||
} else {
|
||||
Warzone warzone = Warzone.getZoneByName(this.args[0]);
|
||||
if (warzone != null && warzone.getTeleport() != null) {
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (playerWarzone != null) {
|
||||
playerWarzone.handlePlayerLeave(player, warzone.getTeleport(), true);
|
||||
} else {
|
||||
player.teleport(warzone.getTeleport());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this.badMsg("No such warzone.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
/**
|
||||
* Lists all warzones
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class WarzonesCommand extends AbstractWarCommand {
|
||||
public WarzonesCommand(WarCommandHandler handler, CommandSender sender, String[] args) {
|
||||
super(handler, sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
String warzonesMessage = "Warzones: ";
|
||||
if (War.war.getWarzones().isEmpty()) {
|
||||
warzonesMessage += "none.";
|
||||
} else {
|
||||
for (Warzone warzone : War.war.getWarzones()) {
|
||||
warzonesMessage += warzone.getName() + " (" + warzone.getTeams().size() + " teams, ";
|
||||
int playerTotal = 0;
|
||||
for (Team team : warzone.getTeams()) {
|
||||
playerTotal += team.getPlayers().size();
|
||||
}
|
||||
warzonesMessage += playerTotal + " players) ";
|
||||
}
|
||||
}
|
||||
|
||||
this.msg(warzonesMessage + ((this.getSender() instanceof Player) ? " Use /zone <zone-name> to teleport to a warzone." : ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
package bukkit.tommytony.war.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
import bukkit.tommytony.war.WarCommandHandler;
|
||||
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
|
||||
/**
|
||||
* Makes a player zonemaker and other way round.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class ZoneMakerCommand extends AbstractWarCommand {
|
||||
|
||||
public ZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
|
||||
super(handler, sender, args);
|
||||
|
||||
if (sender instanceof Player) { // i hate java for this.
|
||||
if (!War.war.isZoneMaker((Player) sender)) {
|
||||
for (String name : War.war.getZoneMakersImpersonatingPlayers()) {
|
||||
if (((Player) sender).getName().equals(name)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new NotZoneMakerException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle() {
|
||||
if (!(this.getSender() instanceof Player)) {
|
||||
this.badMsg("You can't do this if you are not in-game.");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) this.getSender();
|
||||
|
||||
if (War.war.isZoneMaker(player)) {
|
||||
if (this.args.length == 0) {
|
||||
War.war.getZoneMakersImpersonatingPlayers().add(player.getName());
|
||||
this.msg("You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode.");
|
||||
} else if (this.args.length == 1) {
|
||||
// make someone zonemaker or remove the right
|
||||
if (War.war.getZoneMakerNames().contains(this.args[0])) {
|
||||
// kick
|
||||
War.war.getZoneMakerNames().remove(this.args[0]);
|
||||
this.msg(this.args[0] + " is not a zone maker anymore.");
|
||||
Player kickedMaker = War.war.getServer().getPlayer(this.args[0]);
|
||||
if (kickedMaker != null) {
|
||||
War.war.msg(kickedMaker, player.getName() + " took away your warzone maker priviledges.");
|
||||
}
|
||||
} else {
|
||||
// add
|
||||
War.war.getZoneMakerNames().add(this.args[0]);
|
||||
this.msg(this.args[0] + " is now a zone maker.");
|
||||
Player newMaker = War.war.getServer().getPlayer(this.args[0]);
|
||||
if (newMaker != null) {
|
||||
War.war.msg(newMaker, player.getName() + " made you warzone maker.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
War.war.getZoneMakersImpersonatingPlayers().remove(player.getName());
|
||||
this.msg("You are back as a zone maker.");
|
||||
WarYmlMapper.save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class Bomb {
|
||||
private Location location;
|
||||
private Volume volume;
|
||||
|
||||
private final String name;
|
||||
private Warzone warzone;
|
||||
private Player capturer;
|
||||
|
||||
public Bomb(String name, Warzone warzone, Location location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.warzone = warzone;
|
||||
this.volume = new Volume("bomb-" + name, warzone.getWorld());
|
||||
this.setLocation(location);
|
||||
}
|
||||
|
||||
public void addBombBlocks() {
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
|
||||
int x = this.location.getBlockX();
|
||||
int y = this.location.getBlockY();
|
||||
int z = this.location.getBlockZ();
|
||||
|
||||
// center
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).getState().setType(Material.OBSIDIAN);
|
||||
|
||||
// inner ring
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.GLOWSTONE);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.GLOWSTONE);
|
||||
|
||||
// block holder
|
||||
this.warzone.getWorld().getBlockAt(x, y, z).setType(Material.OBSIDIAN);
|
||||
Block tntBlock = this.warzone.getWorld().getBlockAt(x, y + 1, z);
|
||||
tntBlock.setType(Material.TNT);
|
||||
}
|
||||
|
||||
public boolean isBombBlock(Location otherLocation) {
|
||||
int x = this.location.getBlockX();
|
||||
int y = this.location.getBlockY() + 1;
|
||||
int z = this.location.getBlockZ();
|
||||
int otherX = otherLocation.getBlockX();
|
||||
int otherY = otherLocation.getBlockY();
|
||||
int otherZ = otherLocation.getBlockZ();
|
||||
|
||||
return x == otherX
|
||||
&& y == otherY
|
||||
&& z == otherZ;
|
||||
}
|
||||
|
||||
public void capture(Player capturer) {
|
||||
this.capturer = capturer;
|
||||
}
|
||||
|
||||
public boolean isCaptured() {
|
||||
return this.capturer != null;
|
||||
}
|
||||
|
||||
public void uncapture() {
|
||||
this.capturer = null;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
Block locationBlock = this.warzone.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
this.volume.setCornerOne(locationBlock.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST, 1).getRelative(BlockFace.SOUTH, 1));
|
||||
this.volume.setCornerTwo(locationBlock.getRelative(BlockFace.UP, 2).getRelative(BlockFace.WEST, 1).getRelative(BlockFace.NORTH, 1));
|
||||
this.volume.saveBlocks();
|
||||
this.location = location;
|
||||
this.addBombBlocks();
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setVolume(Volume newVolume) {
|
||||
this.volume = newVolume;
|
||||
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class Cake {
|
||||
private Location location;
|
||||
private Volume volume;
|
||||
|
||||
private final String name;
|
||||
private Warzone warzone;
|
||||
private Player capturer;
|
||||
|
||||
public Cake(String name, Warzone warzone, Location location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.warzone = warzone;
|
||||
this.volume = new Volume("cake-" + name, warzone.getWorld());
|
||||
this.setLocation(location);
|
||||
}
|
||||
|
||||
public void addCakeBlocks() {
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
|
||||
int x = this.location.getBlockX();
|
||||
int y = this.location.getBlockY();
|
||||
int z = this.location.getBlockZ();
|
||||
|
||||
// center
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).getState().setType(Material.OBSIDIAN);
|
||||
|
||||
// inner ring
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
// block holder
|
||||
this.warzone.getWorld().getBlockAt(x, y, z).setType(Material.GLASS);
|
||||
Block cakeBlock = this.warzone.getWorld().getBlockAt(x, y + 1, z);
|
||||
cakeBlock.setType(Material.CAKE_BLOCK);
|
||||
}
|
||||
|
||||
public boolean isCakeBlock(Location otherLocation) {
|
||||
int x = this.location.getBlockX();
|
||||
int y = this.location.getBlockY() + 1;
|
||||
int z = this.location.getBlockZ();
|
||||
int otherX = otherLocation.getBlockX();
|
||||
int otherY = otherLocation.getBlockY();
|
||||
int otherZ = otherLocation.getBlockZ();
|
||||
|
||||
return x == otherX
|
||||
&& y == otherY
|
||||
&& z == otherZ;
|
||||
}
|
||||
|
||||
public void capture(Player capturer) {
|
||||
this.capturer = capturer;
|
||||
}
|
||||
|
||||
public boolean isCaptured() {
|
||||
return this.capturer != null;
|
||||
}
|
||||
|
||||
public void uncapture() {
|
||||
this.capturer = null;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
Block locationBlock = this.warzone.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
this.volume.setCornerOne(locationBlock.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST, 1).getRelative(BlockFace.SOUTH, 1));
|
||||
this.volume.setCornerTwo(locationBlock.getRelative(BlockFace.UP, 2).getRelative(BlockFace.WEST, 1).getRelative(BlockFace.NORTH, 1));
|
||||
this.volume.saveBlocks();
|
||||
this.location = location;
|
||||
this.addCakeBlocks();
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setVolume(Volume newVolume) {
|
||||
this.volume = newVolume;
|
||||
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
public enum FlagReturn {
|
||||
BOTH,
|
||||
FLAG,
|
||||
SPAWN;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static FlagReturn getFromString(String string) {
|
||||
for (FlagReturn flagMode : FlagReturn.values()) {
|
||||
if (string.toLowerCase().equals(flagMode.toString())) {
|
||||
return flagMode;
|
||||
}
|
||||
}
|
||||
|
||||
return FlagReturn.BOTH;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
public class LoadoutSelection {
|
||||
|
||||
private boolean stillInSpawn;
|
||||
private int selectedIndex;
|
||||
|
||||
public LoadoutSelection(boolean stillInSpawn, int selectedIndex) {
|
||||
this.setStillInSpawn(stillInSpawn);
|
||||
this.setSelectedIndex(selectedIndex);
|
||||
|
||||
}
|
||||
|
||||
public void setStillInSpawn(boolean stillInSpawn) {
|
||||
this.stillInSpawn = stillInSpawn;
|
||||
}
|
||||
|
||||
public boolean isStillInSpawn() {
|
||||
return stillInSpawn;
|
||||
}
|
||||
|
||||
public void setSelectedIndex(int selectedIndex) {
|
||||
this.selectedIndex = selectedIndex;
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return selectedIndex;
|
||||
}
|
||||
}
|
@ -1,161 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class Monument {
|
||||
private Location location;
|
||||
private Volume volume;
|
||||
|
||||
private Team ownerTeam = null;
|
||||
private final String name;
|
||||
private Warzone warzone;
|
||||
|
||||
public Monument(String name, Warzone warzone, Location location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.warzone = warzone;
|
||||
this.volume = new Volume(name, warzone.getWorld());
|
||||
this.setLocation(location);
|
||||
}
|
||||
|
||||
public void addMonumentBlocks() {
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
|
||||
this.ownerTeam = null;
|
||||
int x = this.location.getBlockX();
|
||||
int y = this.location.getBlockY();
|
||||
int z = this.location.getBlockZ();
|
||||
|
||||
// center
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).getState().setType(Material.OBSIDIAN);
|
||||
|
||||
// inner ring
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
// outer ring
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z + 2).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 2, y - 1, z - 2).setType(Material.GLOWSTONE);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 2).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 2).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z + 2).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z - 2).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 2).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 2).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z + 2).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2).setType(Material.GLOWSTONE);
|
||||
|
||||
// block holder
|
||||
this.warzone.getWorld().getBlockAt(x, y, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y, z + 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).setType(Material.OBSIDIAN);
|
||||
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z + 1).setType(Material.OBSIDIAN);
|
||||
|
||||
}
|
||||
|
||||
public boolean isNear(Location playerLocation) {
|
||||
int x = this.location.getBlockX();
|
||||
int y = this.location.getBlockY();
|
||||
int z = this.location.getBlockZ();
|
||||
int playerX = playerLocation.getBlockX();
|
||||
int playerY = playerLocation.getBlockY();
|
||||
int playerZ = playerLocation.getBlockZ();
|
||||
int diffX = Math.abs(playerX - x);
|
||||
int diffY = Math.abs(playerY - y);
|
||||
int diffZ = Math.abs(playerZ - z);
|
||||
if (diffX < 6 && diffY < 6 && diffZ < 6) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOwner(Team team) {
|
||||
if (team == this.ownerTeam) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasOwner() {
|
||||
return this.ownerTeam != null;
|
||||
}
|
||||
|
||||
public void capture(Team team) {
|
||||
this.ownerTeam = team;
|
||||
}
|
||||
|
||||
public void uncapture() {
|
||||
this.ownerTeam = null;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public void setOwnerTeam(Team team) {
|
||||
this.ownerTeam = team;
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
Block locationBlock = this.warzone.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
this.volume.setCornerOne(locationBlock.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST, 2).getRelative(BlockFace.SOUTH, 2));
|
||||
this.volume.setCornerTwo(locationBlock.getRelative(BlockFace.UP, 2).getRelative(BlockFace.WEST, 2).getRelative(BlockFace.NORTH, 2));
|
||||
this.volume.saveBlocks();
|
||||
this.location = location;
|
||||
|
||||
this.addMonumentBlocks();
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setVolume(Volume newVolume) {
|
||||
this.volume = newVolume;
|
||||
|
||||
}
|
||||
|
||||
public Team getOwnerTeam() {
|
||||
|
||||
return this.ownerTeam;
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.MobEffect;
|
||||
import net.minecraft.server.MobEffectList;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PotionEffect {
|
||||
|
||||
private int id;
|
||||
private int amplifier;
|
||||
private int time;
|
||||
|
||||
public PotionEffect(int id, int amplifier, int time) {
|
||||
this.setId(id);
|
||||
this.setAmplifier(amplifier);
|
||||
this.setTime(time);
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setAmplifier(int amplifier) {
|
||||
this.amplifier = amplifier;
|
||||
}
|
||||
|
||||
public int getAmplifier() {
|
||||
return amplifier;
|
||||
}
|
||||
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public static List<PotionEffect> getCurrentPotionEffects(Player player) {
|
||||
List<PotionEffect> effects = new ArrayList<PotionEffect>();
|
||||
|
||||
for(int i = 1; i < 20; i++)
|
||||
{
|
||||
if(((CraftPlayer)player).getHandle().hasEffect(enchantIdToList(i)))
|
||||
{
|
||||
MobEffect mobEffect = ((CraftPlayer)player).getHandle().getEffect(enchantIdToList(i));
|
||||
effects.add(new PotionEffect(mobEffect.getEffectId(), mobEffect.getAmplifier(), mobEffect.getDuration()));
|
||||
}
|
||||
}
|
||||
|
||||
return effects;
|
||||
}
|
||||
|
||||
public static void restorePotionEffects(Player player, List<PotionEffect> potionEffects) {
|
||||
clearPotionEffects(player);
|
||||
for (PotionEffect effect : potionEffects) {
|
||||
((CraftPlayer)player).getHandle().addEffect(new MobEffect(effect.getId(), effect.getTime(), effect.getAmplifier()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearPotionEffects(Player player) {
|
||||
for (int i = 1; i < 20; i++) {
|
||||
if(((CraftPlayer)player).getHandle().hasEffect(enchantIdToList(i)))
|
||||
{
|
||||
int amplifier = ((CraftPlayer)player).getHandle().getEffect(enchantIdToList(i)).getAmplifier();
|
||||
((CraftPlayer)player).getHandle().addEffect(new MobEffect(i, -1, amplifier + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static MobEffectList enchantIdToList(int id) {
|
||||
switch (id) {
|
||||
case 1:
|
||||
return MobEffectList.FASTER_MOVEMENT;
|
||||
case 2:
|
||||
return MobEffectList.SLOWER_MOVEMENT;
|
||||
case 3:
|
||||
return MobEffectList.FASTER_DIG;
|
||||
case 4:
|
||||
return MobEffectList.SLOWER_DIG;
|
||||
case 5:
|
||||
return MobEffectList.INCREASE_DAMAGE;
|
||||
case 6:
|
||||
return MobEffectList.HEAL;
|
||||
case 7:
|
||||
return MobEffectList.HARM;
|
||||
case 8:
|
||||
return MobEffectList.JUMP;
|
||||
case 9:
|
||||
return MobEffectList.CONFUSION;
|
||||
case 10:
|
||||
return MobEffectList.REGENERATION;
|
||||
case 11:
|
||||
return MobEffectList.RESISTANCE;
|
||||
case 12:
|
||||
return MobEffectList.FIRE_RESISTANCE;
|
||||
case 13:
|
||||
return MobEffectList.WATER_BREATHING;
|
||||
case 14:
|
||||
return MobEffectList.INVISIBILITY;
|
||||
case 15:
|
||||
return MobEffectList.BLINDNESS;
|
||||
case 16:
|
||||
return MobEffectList.NIGHT_VISION;
|
||||
case 17:
|
||||
return MobEffectList.HUNGER;
|
||||
case 18:
|
||||
return MobEffectList.WEAKNESS;
|
||||
case 19:
|
||||
return MobEffectList.POISON;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,613 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.config.InventoryBag;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.TeamConfigBag;
|
||||
import com.tommytony.war.utils.SignHelper;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class Team {
|
||||
private List<Player> players = new ArrayList<Player>();
|
||||
private Location teamSpawn = null;
|
||||
private Location teamFlag = null;
|
||||
private String name;
|
||||
private int remainingLives;
|
||||
private int points = 0;
|
||||
private Volume spawnVolume;
|
||||
private Volume flagVolume;
|
||||
private final Warzone warzone;
|
||||
private TeamKind kind;
|
||||
|
||||
private TeamConfigBag teamConfig;
|
||||
private InventoryBag inventories;
|
||||
|
||||
public Team(String name, TeamKind kind, Location teamSpawn, Warzone warzone) {
|
||||
this.warzone = warzone;
|
||||
this.teamConfig = new TeamConfigBag(warzone);
|
||||
this.inventories = new InventoryBag(warzone); // important constructors for cascading configs
|
||||
this.setName(name);
|
||||
this.teamSpawn = teamSpawn;
|
||||
this.setSpawnVolume(new Volume(name, warzone.getWorld()));
|
||||
this.kind = kind;
|
||||
this.setFlagVolume(null); // no flag at the start
|
||||
}
|
||||
|
||||
public static Team getTeamByPlayerName(String playerName) {
|
||||
for (Warzone warzone : War.war.getWarzones()) {
|
||||
Team team = warzone.getPlayerTeam(playerName);
|
||||
if (team != null) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TeamKind getKind() {
|
||||
return this.kind;
|
||||
}
|
||||
|
||||
private void setSpawnVolume() {
|
||||
if (this.spawnVolume.isSaved()) {
|
||||
this.spawnVolume.resetBlocks();
|
||||
}
|
||||
int x = this.teamSpawn.getBlockX();
|
||||
int y = this.teamSpawn.getBlockY();
|
||||
int z = this.teamSpawn.getBlockZ();
|
||||
|
||||
TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle();
|
||||
if (style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x, y - 1, z));
|
||||
this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x, y + 3, z));
|
||||
} else if (style.equals(TeamSpawnStyle.SMALL)) {
|
||||
this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1));
|
||||
this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1));
|
||||
} else {
|
||||
// flat or big
|
||||
this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2));
|
||||
this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 2, y + 3, z + 2));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void initializeTeamSpawn() {
|
||||
// make air
|
||||
this.spawnVolume.setToMaterial(Material.AIR);
|
||||
|
||||
// Set the spawn
|
||||
int x = this.teamSpawn.getBlockX();
|
||||
int y = this.teamSpawn.getBlockY();
|
||||
int z = this.teamSpawn.getBlockZ();
|
||||
|
||||
TeamSpawnStyle style = this.getTeamConfig().resolveSpawnStyle();
|
||||
if (style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
// nothing but glowstone
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE);
|
||||
} else {
|
||||
// first ring
|
||||
this.setBlock(x + 1, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x + 1, y - 1, z, this.kind);
|
||||
this.setBlock(x + 1, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x, y - 1, z + 1, this.kind);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE);
|
||||
this.setBlock(x, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z - 1, this.kind);
|
||||
}
|
||||
|
||||
// Orientation
|
||||
int yaw = 0;
|
||||
if (this.teamSpawn.getYaw() >= 0) {
|
||||
yaw = (int) (this.teamSpawn.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (this.teamSpawn.getYaw() % 360));
|
||||
}
|
||||
Block signBlock = null;
|
||||
int signData = 0;
|
||||
|
||||
if (style.equals(TeamSpawnStyle.INVISIBLE)) {
|
||||
// INVISIBLE style
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z);
|
||||
if (yaw >= 0 && yaw < 90) {
|
||||
signData = 10;
|
||||
} else if (yaw >= 90 && yaw <= 180) {
|
||||
signData = 14;
|
||||
} else if (yaw >= 180 && yaw < 270) {
|
||||
signData = 2;
|
||||
} else if (yaw >= 270 && yaw <= 360) {
|
||||
signData = 6;
|
||||
}
|
||||
} else if (style.equals(TeamSpawnStyle.SMALL)) {
|
||||
// SMALL style
|
||||
if (yaw >= 0 && yaw < 90) {
|
||||
signData = 10;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST);
|
||||
} else if (yaw >= 90 && yaw <= 180) {
|
||||
signData = 14;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST);
|
||||
} else if (yaw >= 180 && yaw < 270) {
|
||||
signData = 2;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.SOUTH).getRelative(BlockFace.EAST);
|
||||
} else if (yaw >= 270 && yaw <= 360) {
|
||||
signData = 6;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST);
|
||||
}
|
||||
} else {
|
||||
// outer ring (FLAT or BIG)
|
||||
this.setBlock(x + 2, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x + 2, y - 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x - 1, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x - 1, y - 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x, y - 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x + 1, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y - 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x - 2, y - 1, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z + 1, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y - 1, z - 2, this.kind);
|
||||
|
||||
BlockFace facing = null;
|
||||
BlockFace opposite = null;
|
||||
if (yaw >= 0 && yaw < 90) {
|
||||
facing = BlockFace.NORTH_WEST;
|
||||
opposite = BlockFace.SOUTH_EAST;
|
||||
signData = 10;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.WEST, 2);
|
||||
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x - 2, y, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y, z - 2, this.kind);
|
||||
this.setBlock(x, y, z - 2, this.kind);
|
||||
this.setBlock(x + 1, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 1, this.kind);
|
||||
this.setBlock(x + 2, y, z, this.kind);
|
||||
this.setBlock(x + 2, y, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y, z + 2, this.kind);
|
||||
|
||||
// tower
|
||||
this.setBlock(x, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x + 1, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z - 1, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z, this.kind);
|
||||
|
||||
this.setBlock(x + 1, y + 2, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y + 2, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y + 2, z - 1, this.kind);
|
||||
|
||||
this.setBlock(x + 2, y + 3, z - 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 90 && yaw <= 180) {
|
||||
facing = BlockFace.NORTH_EAST;
|
||||
opposite = BlockFace.SOUTH_WEST;
|
||||
signData = 14;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.EAST, 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x + 1, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 1, this.kind);
|
||||
this.setBlock(x + 2, y, z, this.kind);
|
||||
this.setBlock(x + 2, y, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y, z + 2, this.kind);
|
||||
this.setBlock(x, y, z + 2, this.kind);
|
||||
this.setBlock(x - 1, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 1, this.kind);
|
||||
|
||||
// tower
|
||||
this.setBlock(x + 2, y + 1, z, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x, y + 1, z + 2, this.kind);
|
||||
|
||||
this.setBlock(x + 2, y + 2, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y + 2, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y + 2, z + 2, this.kind);
|
||||
|
||||
this.setBlock(x + 2, y + 3, z + 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 180 && yaw < 270) {
|
||||
facing = BlockFace.SOUTH_EAST;
|
||||
opposite = BlockFace.NORTH_WEST;
|
||||
signData = 2;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.EAST, 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x + 2, y, z + 1, this.kind);
|
||||
this.setBlock(x + 2, y, z + 2, this.kind);
|
||||
this.setBlock(x + 1, y, z + 2, this.kind);
|
||||
this.setBlock(x, y, z + 2, this.kind);
|
||||
this.setBlock(x - 1, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 1, this.kind);
|
||||
this.setBlock(x - 2, y, z, this.kind);
|
||||
this.setBlock(x - 2, y, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y, z - 2, this.kind);
|
||||
|
||||
// tower
|
||||
this.setBlock(x, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x - 1, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z + 1, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z, this.kind);
|
||||
|
||||
this.setBlock(x - 1, y + 2, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y + 2, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y + 2, z + 1, this.kind);
|
||||
|
||||
this.setBlock(x - 2, y + 3, z + 2, this.kind);
|
||||
}
|
||||
} else if (yaw >= 270 && yaw <= 360) {
|
||||
facing = BlockFace.SOUTH_WEST;
|
||||
opposite = BlockFace.NORTH_EAST;
|
||||
signData = 6;
|
||||
signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.WEST, 2);
|
||||
if (style.equals(TeamSpawnStyle.BIG)) {
|
||||
// rim
|
||||
this.setBlock(x - 1, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 2, this.kind);
|
||||
this.setBlock(x - 2, y, z + 1, this.kind);
|
||||
this.setBlock(x - 2, y, z, this.kind);
|
||||
this.setBlock(x - 2, y, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y, z - 2, this.kind);
|
||||
this.setBlock(x, y, z - 2, this.kind);
|
||||
this.setBlock(x + 1, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 2, this.kind);
|
||||
this.setBlock(x + 2, y, z - 1, this.kind);
|
||||
|
||||
// tower
|
||||
this.setBlock(x - 2, y + 1, z, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y + 1, z - 2, this.kind);
|
||||
this.setBlock(x, y + 1, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x - 2, y + 2, z - 1, this.kind);
|
||||
this.setBlock(x - 2, y + 2, z - 2, this.kind);
|
||||
this.setBlock(x - 1, y + 2, z - 2, this.kind);
|
||||
|
||||
this.setBlock(x - 2, y + 3, z - 2, this.kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (signBlock != null) {
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "Team " + this.name;
|
||||
lines[1] = this.players.size() + "/" + this.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE) + " players";
|
||||
lines[2] = this.points + "/" + this.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)+ " pts";
|
||||
if (this.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) == -1) {
|
||||
lines[3] = "unlimited lives";
|
||||
} else {
|
||||
lines[3] = this.remainingLives + "/" + this.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) + " lives left";
|
||||
}
|
||||
|
||||
SignHelper.setToSign(War.war, signBlock, (byte) signData, lines);
|
||||
}
|
||||
|
||||
if (War.war.isSpoutServer()) {
|
||||
War.war.getSpoutMessenger().updateStats(this.warzone);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlock(int x, int y, int z, TeamKind kind) {
|
||||
Block block = this.warzone.getWorld().getBlockAt(x, y, z);
|
||||
block.setType(kind.getMaterial());
|
||||
block.setData(kind.getData());
|
||||
}
|
||||
|
||||
public void setTeamSpawn(Location teamSpawn) {
|
||||
this.teamSpawn = teamSpawn;
|
||||
|
||||
// this resets the block to old state
|
||||
this.setSpawnVolume();
|
||||
this.getSpawnVolume().saveBlocks();
|
||||
|
||||
this.initializeTeamSpawn();
|
||||
}
|
||||
|
||||
public Location getTeamSpawn() {
|
||||
return this.teamSpawn;
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
this.players.add(player);
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return this.players;
|
||||
}
|
||||
|
||||
public void teamcast(String message) {
|
||||
// by default a teamcast is a notification
|
||||
teamcast(message, true);
|
||||
}
|
||||
|
||||
public void teamcast(String message, boolean isNotification) {
|
||||
for (Player player : this.players) {
|
||||
if (War.war.isSpoutServer()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(player);
|
||||
if (sp.isSpoutCraftEnabled() && isNotification) {
|
||||
// team notifications go to the top left for Spout players to lessen War spam in chat box
|
||||
War.war.getSpoutMessenger().msg(sp, message);
|
||||
} else {
|
||||
War.war.msg(player, message);
|
||||
}
|
||||
} else {
|
||||
War.war.msg(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean removePlayer(String name) {
|
||||
Player thePlayer = null;
|
||||
for (Player player : this.players) {
|
||||
if (player.getName().equals(name)) {
|
||||
thePlayer = player;
|
||||
}
|
||||
}
|
||||
if (thePlayer != null) {
|
||||
this.players.remove(thePlayer);
|
||||
|
||||
if (this.warzone.isFlagThief(thePlayer.getName())) {
|
||||
Team victim = this.warzone.getVictimTeamForFlagThief(thePlayer.getName());
|
||||
victim.getFlagVolume().resetBlocks();
|
||||
victim.initializeTeamFlag();
|
||||
this.warzone.removeFlagThief(thePlayer.getName());
|
||||
for (Team t : this.warzone.getTeams()) {
|
||||
t.teamcast("Team " + ChatColor.GREEN + victim.getName() + ChatColor.WHITE + " flag was returned.");
|
||||
}
|
||||
}
|
||||
|
||||
if (this.warzone.isBombThief(thePlayer.getName())) {
|
||||
Bomb bomb = this.warzone.getBombForThief(thePlayer.getName());
|
||||
bomb.getVolume().resetBlocks();
|
||||
bomb.addBombBlocks();
|
||||
this.warzone.removeBombThief(thePlayer.getName());
|
||||
for (Team t : this.warzone.getTeams()) {
|
||||
t.teamcast("Bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.WHITE + " was returned.");
|
||||
}
|
||||
}
|
||||
|
||||
if (this.warzone.isCakeThief(thePlayer.getName())) {
|
||||
Cake cake = this.warzone.getCakeForThief(thePlayer.getName());
|
||||
cake.getVolume().resetBlocks();
|
||||
cake.addCakeBlocks();
|
||||
this.warzone.removeCakeThief(thePlayer.getName());
|
||||
for (Team t : this.warzone.getTeams()) {
|
||||
t.teamcast("Cake " + ChatColor.GREEN + cake.getName() + ChatColor.WHITE + " was returned.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setRemainingLives(int remainingLives) {
|
||||
this.remainingLives = remainingLives;
|
||||
}
|
||||
|
||||
public int getRemainingLifes() {
|
||||
return this.remainingLives;
|
||||
}
|
||||
|
||||
public void addPoint() {
|
||||
boolean atLeastOnePlayerOnTeam = this.players.size() != 0;
|
||||
boolean atLeastOnePlayerOnOtherTeam = false;
|
||||
for (Team team : this.warzone.getTeams()) {
|
||||
if (!team.getName().equals(this.getName()) && team.getPlayers().size() > 0) {
|
||||
atLeastOnePlayerOnOtherTeam = true;
|
||||
}
|
||||
}
|
||||
if (atLeastOnePlayerOnTeam && atLeastOnePlayerOnOtherTeam) {
|
||||
this.points++;
|
||||
} else if (!atLeastOnePlayerOnOtherTeam) {
|
||||
this.teamcast("Can't score until at least one player joins another team.");
|
||||
}
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return this.points;
|
||||
}
|
||||
|
||||
public Volume getSpawnVolume() {
|
||||
|
||||
return this.spawnVolume;
|
||||
}
|
||||
|
||||
public void resetSign() {
|
||||
this.getSpawnVolume().resetBlocks();
|
||||
this.initializeTeamSpawn(); // reset everything instead of just sign
|
||||
|
||||
if (this.warzone.getLobby() != null) {
|
||||
this.warzone.getLobby().resetTeamGateSign(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpawnVolume(Volume volume) {
|
||||
this.spawnVolume = volume;
|
||||
}
|
||||
|
||||
public void resetPoints() {
|
||||
this.points = 0;
|
||||
}
|
||||
|
||||
public void setFlagVolume(Volume flagVolume) {
|
||||
this.flagVolume = flagVolume;
|
||||
}
|
||||
|
||||
public Volume getFlagVolume() {
|
||||
return this.flagVolume;
|
||||
}
|
||||
|
||||
private void setFlagVolume() {
|
||||
if (this.flagVolume == null) {
|
||||
this.flagVolume = new Volume(this.getName() + "flag", this.warzone.getWorld());
|
||||
}
|
||||
if (this.flagVolume.isSaved()) {
|
||||
this.flagVolume.resetBlocks();
|
||||
}
|
||||
int x = this.teamFlag.getBlockX();
|
||||
int y = this.teamFlag.getBlockY();
|
||||
int z = this.teamFlag.getBlockZ();
|
||||
this.flagVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1));
|
||||
this.flagVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void initializeTeamFlag() {
|
||||
// make air
|
||||
this.flagVolume.setToMaterial(Material.AIR);
|
||||
|
||||
// Set the flag blocks
|
||||
int x = this.teamFlag.getBlockX();
|
||||
int y = this.teamFlag.getBlockY();
|
||||
int z = this.teamFlag.getBlockZ();
|
||||
|
||||
// first ring
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE);
|
||||
this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN);
|
||||
|
||||
// flag
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z).setType(this.kind.getMaterial());
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z).setData(this.kind.getData());
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z).setType(Material.FENCE);
|
||||
|
||||
// Flag post using Orientation
|
||||
int yaw = 0;
|
||||
if (this.teamFlag.getYaw() >= 0) {
|
||||
yaw = (int) (this.teamFlag.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (this.teamFlag.getYaw() % 360));
|
||||
}
|
||||
BlockFace facing = null;
|
||||
BlockFace opposite = null;
|
||||
if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
|
||||
facing = BlockFace.WEST;
|
||||
opposite = BlockFace.EAST;
|
||||
this.warzone.getWorld().getBlockAt(x, y, z - 1).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z - 1).setType(Material.FENCE);
|
||||
} else if (yaw >= 45 && yaw < 135) {
|
||||
facing = BlockFace.NORTH;
|
||||
opposite = BlockFace.SOUTH;
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y, z).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y + 1, z).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x + 1, y + 2, z).setType(Material.FENCE);
|
||||
} else if (yaw >= 135 && yaw < 225) {
|
||||
facing = BlockFace.EAST;
|
||||
opposite = BlockFace.WEST;
|
||||
this.warzone.getWorld().getBlockAt(x, y, z + 1).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x, y + 2, z + 1).setType(Material.FENCE);
|
||||
} else if (yaw >= 225 && yaw < 315) {
|
||||
facing = BlockFace.SOUTH;
|
||||
opposite = BlockFace.NORTH;
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y, z).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y + 1, z).setType(Material.FENCE);
|
||||
this.warzone.getWorld().getBlockAt(x - 1, y + 2, z).setType(Material.FENCE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTeamFlag(Location teamFlag) {
|
||||
this.teamFlag = teamFlag;
|
||||
|
||||
// this resets the block to old state
|
||||
this.setFlagVolume();
|
||||
this.getFlagVolume().saveBlocks();
|
||||
|
||||
this.initializeTeamFlag();
|
||||
}
|
||||
|
||||
public boolean isTeamFlagBlock(Block block) {
|
||||
if (this.teamFlag != null) {
|
||||
int flagX = this.teamFlag.getBlockX();
|
||||
int flagY = this.teamFlag.getBlockY() + 1;
|
||||
int flagZ = this.teamFlag.getBlockZ();
|
||||
if (block.getX() == flagX && block.getY() == flagY && block.getZ() == flagZ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Location getTeamFlag() {
|
||||
return this.teamFlag;
|
||||
}
|
||||
|
||||
public void deleteTeamFlag() {
|
||||
this.getFlagVolume().resetBlocks();
|
||||
this.setFlagVolume(null);
|
||||
this.teamFlag = null;
|
||||
|
||||
// remove volume file
|
||||
String filePath = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.warzone.getName() + "/volume-" + this.getName() + "flag.dat";
|
||||
if (!new File(filePath).delete()) {
|
||||
War.war.log("Failed to delete file " + filePath, Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryBag getInventories() {
|
||||
return this.inventories ;
|
||||
}
|
||||
|
||||
public TeamConfigBag getTeamConfig() {
|
||||
return this.teamConfig;
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.getspout.spoutapi.gui.Color;
|
||||
|
||||
public enum TeamKind {
|
||||
WHITE ((byte) 0, Material.WOOL, ChatColor.WHITE),
|
||||
ORANGE ((byte) 1, Material.WOOL, ChatColor.GOLD),
|
||||
MAGENTA ((byte) 2, Material.WOOL, ChatColor.LIGHT_PURPLE),
|
||||
BLUE ((byte) 3, Material.WOOL, ChatColor.BLUE),
|
||||
GOLD ((byte) 4, Material.WOOL, ChatColor.YELLOW), // yellow = gold
|
||||
GREEN ((byte) 5, Material.WOOL, ChatColor.GREEN),
|
||||
PINK ((byte) 6, Material.WOOL, ChatColor.WHITE),
|
||||
GRAY ((byte) 7, Material.WOOL, ChatColor.DARK_GRAY),
|
||||
IRON ((byte) 8, Material.WOOL, ChatColor.GRAY), // lightgrey = iron
|
||||
DIAMOND ((byte) 9, Material.WOOL, ChatColor.DARK_AQUA), // cyan = diamond
|
||||
PURPLE ((byte) 10, Material.WOOL, ChatColor.DARK_PURPLE),
|
||||
NAVY ((byte) 11, Material.WOOL, ChatColor.DARK_BLUE),
|
||||
BROWN ((byte) 12, Material.WOOL, ChatColor.DARK_RED),
|
||||
DARKGREEN ((byte) 13, Material.WOOL, ChatColor.DARK_GREEN),
|
||||
RED ((byte) 14, Material.WOOL, ChatColor.RED),
|
||||
BLACK ((byte) 15, Material.WOOL, ChatColor.BLACK);
|
||||
|
||||
private final byte data;
|
||||
private final ChatColor color;
|
||||
private final Material material;
|
||||
|
||||
private TeamKind(byte data, Material material, ChatColor color) {
|
||||
this.data = data;
|
||||
this.material = material;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public static TeamKind teamKindFromString(String str) {
|
||||
String lowered = str.toLowerCase();
|
||||
for (TeamKind kind : TeamKind.values()) {
|
||||
if (kind.toString().startsWith(lowered)) {
|
||||
return kind;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte getData() {
|
||||
return this.data;
|
||||
}
|
||||
public ChatColor getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't call unless War.war.isSpoutServer() is true
|
||||
* @return
|
||||
*/
|
||||
public Color getSpoutColor() {
|
||||
int colorCode = (int)this.data;
|
||||
switch (colorCode) {
|
||||
case 0:
|
||||
return new Color(255,255,255);
|
||||
case 1:
|
||||
return new Color(255,128,0);
|
||||
case 2:
|
||||
return new Color(255,128,255);
|
||||
case 3:
|
||||
return new Color(0,0,255);
|
||||
case 4:
|
||||
return new Color(0,255,255);
|
||||
case 5:
|
||||
return new Color(0,255,0);
|
||||
case 6:
|
||||
return new Color(255,255,255);
|
||||
case 7:
|
||||
return new Color(100,100,100);
|
||||
case 8:
|
||||
return new Color(200,200,200);
|
||||
case 9:
|
||||
return new Color(128,255,255);
|
||||
case 10:
|
||||
return new Color(128,0,255);
|
||||
case 11:
|
||||
return new Color(0,0,128);
|
||||
case 12:
|
||||
return new Color(128,0,0);
|
||||
case 13:
|
||||
return new Color(0,128,0);
|
||||
case 14:
|
||||
return new Color(255,0,0);
|
||||
case 15:
|
||||
return new Color(0,0,0);
|
||||
default:
|
||||
return new Color(255,255,255);
|
||||
}
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public enum TeamSpawnStyle {
|
||||
INVISIBLE,
|
||||
SMALL,
|
||||
FLAT,
|
||||
BIG;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static TeamSpawnStyle getStyleFromString(String string) {
|
||||
for (TeamSpawnStyle style : TeamSpawnStyle.values()) {
|
||||
if (string.toLowerCase().equals(style.toString())) {
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
return TeamSpawnStyle.SMALL;
|
||||
}
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.utils.SignHelper;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package com.tommytony.war
|
||||
*/
|
||||
public class WarHub {
|
||||
private Location location;
|
||||
private Volume volume;
|
||||
private Map<String, Block> zoneGateBlocks = new HashMap<String, Block>();
|
||||
private BlockFace orientation;
|
||||
|
||||
public WarHub(Location location, String hubOrientation) {
|
||||
int yaw = 0;
|
||||
if (hubOrientation.equals("south")) {
|
||||
yaw = 270;
|
||||
this.setOrientation(BlockFace.SOUTH);
|
||||
} else if (hubOrientation.equals("north")) {
|
||||
yaw = 90;
|
||||
this.setOrientation(BlockFace.NORTH);
|
||||
} else if (hubOrientation.equals("east")) {
|
||||
yaw = 180;
|
||||
this.setOrientation(BlockFace.EAST);
|
||||
} else {
|
||||
yaw = 0;
|
||||
this.setOrientation(BlockFace.WEST);
|
||||
}
|
||||
|
||||
this.location = new Location(location.getWorld(),
|
||||
location.getX(),
|
||||
location.getY(),
|
||||
location.getZ(),
|
||||
yaw, 0);
|
||||
this.volume = new Volume("warhub", location.getWorld());
|
||||
}
|
||||
|
||||
// Use when creating from player location (with yaw)
|
||||
public WarHub(Location location) {
|
||||
this.location = location;
|
||||
this.volume = new Volume("warhub", location.getWorld());
|
||||
|
||||
this.setLocation(location);
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setLocation(Location loc) {
|
||||
this.location = loc;
|
||||
// Lobby orientation
|
||||
int yaw = 0;
|
||||
if (this.location.getYaw() >= 0) {
|
||||
yaw = (int) (this.location.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (this.location.getYaw() % 360));
|
||||
}
|
||||
|
||||
BlockFace facing = null;
|
||||
if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
|
||||
facing = BlockFace.WEST;
|
||||
} else if (yaw >= 45 && yaw < 135) {
|
||||
facing = BlockFace.NORTH;
|
||||
} else if (yaw >= 135 && yaw < 225) {
|
||||
facing = BlockFace.EAST;
|
||||
} else if (yaw >= 225 && yaw < 315) {
|
||||
facing = BlockFace.SOUTH;
|
||||
}
|
||||
this.setOrientation(facing);
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public Warzone getDestinationWarzoneForLocation(Location playerLocation) {
|
||||
Warzone zone = null;
|
||||
for (String zoneName : this.zoneGateBlocks.keySet()) {
|
||||
Block gate = this.zoneGateBlocks.get(zoneName);
|
||||
if (gate.getX() == playerLocation.getBlockX() && gate.getY() == playerLocation.getBlockY() && gate.getZ() == playerLocation.getBlockZ()) {
|
||||
zone = War.war.findWarzone(zoneName);
|
||||
}
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
// for now, draw the wall of gates to the west
|
||||
this.zoneGateBlocks.clear();
|
||||
int disabled = 0;
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
disabled++;
|
||||
}
|
||||
}
|
||||
int noOfWarzones = War.war.getWarzones().size() - disabled;
|
||||
if (noOfWarzones > 0) {
|
||||
int hubWidth = noOfWarzones * 4 + 2;
|
||||
int halfHubWidth = hubWidth / 2;
|
||||
int hubDepth = 6;
|
||||
int hubHeigth = 4;
|
||||
|
||||
BlockFace left;
|
||||
BlockFace right;
|
||||
BlockFace front = this.getOrientation();
|
||||
BlockFace back;
|
||||
byte data;
|
||||
if (this.getOrientation() == BlockFace.SOUTH) {
|
||||
data = (byte) 4;
|
||||
left = BlockFace.EAST;
|
||||
right = BlockFace.WEST;
|
||||
back = BlockFace.NORTH;
|
||||
} else if (this.getOrientation() == BlockFace.NORTH) {
|
||||
data = (byte) 12;
|
||||
left = BlockFace.WEST;
|
||||
right = BlockFace.EAST;
|
||||
back = BlockFace.SOUTH;
|
||||
} else if (this.getOrientation() == BlockFace.EAST) {
|
||||
data = (byte) 0;
|
||||
left = BlockFace.NORTH;
|
||||
right = BlockFace.SOUTH;
|
||||
back = BlockFace.WEST;
|
||||
} else {
|
||||
data = (byte) 8;
|
||||
left = BlockFace.SOUTH;
|
||||
right = BlockFace.NORTH;
|
||||
back = BlockFace.EAST;
|
||||
}
|
||||
|
||||
Block locationBlock = this.location.getWorld().getBlockAt(this.location.getBlockX(), this.location.getBlockY(), this.location.getBlockZ());
|
||||
|
||||
this.volume.setWorld(this.location.getWorld());
|
||||
this.volume.setCornerOne(locationBlock.getRelative(back).getRelative(left, halfHubWidth).getRelative(BlockFace.DOWN));
|
||||
this.volume.setCornerTwo(locationBlock.getRelative(right, halfHubWidth).getRelative(front, hubDepth).getRelative(BlockFace.UP, hubHeigth));
|
||||
this.volume.saveBlocks();
|
||||
|
||||
// glass floor
|
||||
this.volume.clearBlocksThatDontFloat();
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS);
|
||||
|
||||
// draw gates
|
||||
Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(front, hubDepth).getRelative(right, 2);
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) { // gonna use the index to find it again
|
||||
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
this.zoneGateBlocks.put(zone.getName(), currentGateBlock);
|
||||
currentGateBlock.getRelative(BlockFace.DOWN).setType(Material.GLOWSTONE);
|
||||
currentGateBlock.getRelative(left).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getRelative(right).getRelative(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getRelative(left).getRelative(BlockFace.UP).getRelative(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getRelative(right).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getRelative(left).getRelative(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getRelative(right).getRelative(BlockFace.UP).getRelative(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP).setType(Material.OBSIDIAN);
|
||||
currentGateBlock = currentGateBlock.getRelative(right, 4);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// War hub sign
|
||||
Block signBlock = locationBlock.getRelative(front);
|
||||
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "War hub";
|
||||
lines[1] = "(/warhub)";
|
||||
lines[2] = "Pick your";
|
||||
lines[3] = "battle!";
|
||||
SignHelper.setToSign(War.war, signBlock, data, lines);
|
||||
|
||||
// Warzone signs
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) && zone.ready()) {
|
||||
this.resetZoneSign(zone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the sign of the given warzone
|
||||
*
|
||||
* @param Warzone
|
||||
* zone
|
||||
*/
|
||||
public void resetZoneSign(Warzone zone) {
|
||||
BlockFace left;
|
||||
BlockFace back;
|
||||
byte data;
|
||||
if (this.getOrientation() == BlockFace.SOUTH) {
|
||||
data = (byte) 4;
|
||||
left = BlockFace.EAST;
|
||||
back = BlockFace.NORTH;
|
||||
} else if (this.getOrientation() == BlockFace.NORTH) {
|
||||
data = (byte) 12;
|
||||
left = BlockFace.WEST;
|
||||
back = BlockFace.SOUTH;
|
||||
} else if (this.getOrientation() == BlockFace.EAST) {
|
||||
data = (byte) 0;
|
||||
left = BlockFace.NORTH;
|
||||
back = BlockFace.WEST;
|
||||
} else {
|
||||
data = (byte) 8;
|
||||
left = BlockFace.SOUTH;
|
||||
back = BlockFace.EAST;
|
||||
}
|
||||
|
||||
Block zoneGate = this.zoneGateBlocks.get(zone.getName());
|
||||
if (zoneGate != null) {
|
||||
Block block = zoneGate.getRelative(left).getRelative(back, 1);
|
||||
if (block.getType() != Material.SIGN_POST) {
|
||||
block.setType(Material.SIGN_POST);
|
||||
}
|
||||
block.setData(data);
|
||||
|
||||
int zoneCap = 0;
|
||||
int zonePlayers = 0;
|
||||
for (Team t : zone.getTeams()) {
|
||||
zonePlayers += t.getPlayers().size();
|
||||
zoneCap += t.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE);
|
||||
}
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "Warzone";
|
||||
lines[1] = zone.getName();
|
||||
lines[2] = zonePlayers + "/" + zoneCap + " players";
|
||||
lines[3] = zone.getTeams().size() + " teams";
|
||||
SignHelper.setToSign(War.war, block, data, lines);
|
||||
} else {
|
||||
War.war.log("Failed to find warhub gate for " + zone.getName() + " warzone.", Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public void setVolume(Volume vol) {
|
||||
this.volume = vol;
|
||||
}
|
||||
|
||||
public void setOrientation(BlockFace orientation) {
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
public BlockFace getOrientation() {
|
||||
return this.orientation;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,699 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.utils.SignHelper;
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class ZoneLobby {
|
||||
private final Warzone warzone;
|
||||
private BlockFace wall;
|
||||
private Volume volume;
|
||||
BlockInfo lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor
|
||||
|
||||
BlockInfo warHubLinkGate = null;
|
||||
|
||||
Map<String, BlockInfo> teamGateBlocks = new HashMap<String, BlockInfo>();
|
||||
BlockInfo autoAssignGate = null;
|
||||
|
||||
BlockInfo zoneTeleportBlock = null;
|
||||
|
||||
private final int lobbyHeight = 3;
|
||||
private int lobbyHalfSide;
|
||||
private final int lobbyDepth = 10;
|
||||
|
||||
/**
|
||||
* Use this constructor with /setzonelobby <n/s/e/w>
|
||||
*
|
||||
* @param war
|
||||
* @param warzone
|
||||
* @param wall
|
||||
* On which wall of the warzone will the lobby be stuck to at mid-weight
|
||||
*/
|
||||
public ZoneLobby(Warzone warzone, BlockFace wall) {
|
||||
this.warzone = warzone;
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
this.lobbyHalfSide = lobbyWidth / 2;
|
||||
if (this.lobbyHalfSide < 7) {
|
||||
this.lobbyHalfSide = 7;
|
||||
}
|
||||
this.setWall(wall);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor with /setzonelobby <zonename>. Makes sure the lobby is not sticking inside the zone.
|
||||
*
|
||||
* @param war
|
||||
* @param warzone
|
||||
* @param wall
|
||||
* On which wall of the warzone will the lobby be stuck to at mid-weight
|
||||
*/
|
||||
public ZoneLobby(Warzone warzone, Location playerLocation) {
|
||||
this.warzone = warzone;
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
this.lobbyHalfSide = lobbyWidth / 2;
|
||||
if (this.lobbyHalfSide < 7) {
|
||||
this.lobbyHalfSide = 7;
|
||||
}
|
||||
this.setLocation(playerLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience ctor when loading form disk. This figures out the middle wall block of the lobby from the volume instead of the other way around.
|
||||
*/
|
||||
public ZoneLobby(Warzone warzone, BlockFace wall, Volume volume) {
|
||||
this.warzone = warzone;
|
||||
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
|
||||
this.lobbyHalfSide = lobbyWidth / 2;
|
||||
if (this.lobbyHalfSide < 7) {
|
||||
this.lobbyHalfSide = 7;
|
||||
}
|
||||
this.wall = wall;
|
||||
this.setVolume(volume);
|
||||
|
||||
// we're setting the zoneVolume directly, so we need to figure out the lobbyMiddleWallBlock on our own
|
||||
if (wall == BlockFace.NORTH) {
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(BlockFace.EAST, this.lobbyHalfSide));
|
||||
} else if (wall == BlockFace.EAST) {
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(BlockFace.SOUTH, this.lobbyHalfSide));
|
||||
} else if (wall == BlockFace.SOUTH) {
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(BlockFace.WEST, this.lobbyHalfSide));
|
||||
} else if (wall == BlockFace.WEST) {
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(BlockFace.NORTH, this.lobbyHalfSide));
|
||||
}
|
||||
}
|
||||
|
||||
public static ZoneLobby getLobbyByLocation(Location location) {
|
||||
for (Warzone warzone : War.war.getWarzones()) {
|
||||
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null && warzone.getLobby().getVolume().contains(location)) {
|
||||
return warzone.getLobby();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ZoneLobby getLobbyByLocation(Player player) {
|
||||
return ZoneLobby.getLobbyByLocation(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the lobby's position. Orientation is determined from the player location. Creates volume or resets. Saves new lobby blocks.
|
||||
*
|
||||
* @param playerLocation
|
||||
*/
|
||||
public void setLocation(Location playerLocation) {
|
||||
World lobbyWorld = playerLocation.getWorld();
|
||||
this.createVolumeOrReset(lobbyWorld);
|
||||
|
||||
// Lobby orientation
|
||||
int yaw = 0;
|
||||
if (playerLocation.getYaw() >= 0) {
|
||||
yaw = (int) (playerLocation.getYaw() % 360);
|
||||
} else {
|
||||
yaw = (int) (360 + (playerLocation.getYaw() % 360));
|
||||
}
|
||||
BlockFace facing = null;
|
||||
BlockFace opposite = null;
|
||||
if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
|
||||
facing = BlockFace.WEST;
|
||||
opposite = BlockFace.EAST;
|
||||
} else if (yaw >= 45 && yaw < 135) {
|
||||
facing = BlockFace.NORTH;
|
||||
opposite = BlockFace.SOUTH;
|
||||
} else if (yaw >= 135 && yaw < 225) {
|
||||
facing = BlockFace.EAST;
|
||||
opposite = BlockFace.WEST;
|
||||
} else if (yaw >= 225 && yaw < 315) {
|
||||
facing = BlockFace.SOUTH;
|
||||
opposite = BlockFace.NORTH;
|
||||
}
|
||||
|
||||
this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall
|
||||
|
||||
this.calculateLobbyWidth();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(lobbyWorld.getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getRelative(facing, 6));
|
||||
|
||||
Block corner1 = null;
|
||||
Block corner2 = null;
|
||||
int x = this.lobbyMiddleWallBlock.getX();
|
||||
int y = this.lobbyMiddleWallBlock.getY();
|
||||
int z = this.lobbyMiddleWallBlock.getZ();
|
||||
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
corner1 = lobbyWorld.getBlockAt(x, y - 1, z + this.lobbyHalfSide);
|
||||
corner2 = lobbyWorld.getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, z - this.lobbyHalfSide);
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
corner1 = lobbyWorld.getBlockAt(x - this.lobbyHalfSide, y - 1, z);
|
||||
corner2 = lobbyWorld.getBlockAt(x + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth);
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
corner1 = lobbyWorld.getBlockAt(x, y - 1, z - this.lobbyHalfSide);
|
||||
corner2 = lobbyWorld.getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, z + this.lobbyHalfSide);
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
corner1 = lobbyWorld.getBlockAt(x + this.lobbyHalfSide, y - 1, z);
|
||||
corner2 = lobbyWorld.getBlockAt(x - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth);
|
||||
}
|
||||
|
||||
this.saveLobbyBlocks(corner1, corner2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Classic way of creating a lobby. Lobby position goes to middle of zone wall. Creates volume or resets. Saves new lobby blocks.
|
||||
*
|
||||
* @param newWall
|
||||
*/
|
||||
public void setWall(BlockFace newWall) {
|
||||
this.createVolumeOrReset(this.warzone.getWorld()); // when attached to the warzone, lobby is in same world
|
||||
this.wall = newWall;
|
||||
|
||||
ZoneVolume zoneVolume = this.warzone.getVolume();
|
||||
this.calculateLobbyWidth();
|
||||
|
||||
Block corner1 = null;
|
||||
Block corner2 = null;
|
||||
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
int wallStart = zoneVolume.getMinZ();
|
||||
int wallEnd = zoneVolume.getMaxZ();
|
||||
int x = zoneVolume.getMinX();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int y = zoneVolume.getCenterY();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos));
|
||||
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos + this.lobbyHalfSide);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos - this.lobbyHalfSide);
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
int wallStart = zoneVolume.getMinX();
|
||||
int wallEnd = zoneVolume.getMaxX();
|
||||
int z = zoneVolume.getMinZ();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int y = zoneVolume.getCenterY();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z));
|
||||
corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y - 1, z);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth);
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
int wallStart = zoneVolume.getMinZ();
|
||||
int wallEnd = zoneVolume.getMaxZ();
|
||||
int x = zoneVolume.getMaxX();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int y = zoneVolume.getCenterY();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos));
|
||||
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos - this.lobbyHalfSide);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos + this.lobbyHalfSide);
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
int wallStart = zoneVolume.getMinX();
|
||||
int wallEnd = zoneVolume.getMaxX();
|
||||
int z = zoneVolume.getMaxZ();
|
||||
int wallLength = wallEnd - wallStart + 1;
|
||||
int wallCenterPos = wallStart + wallLength / 2;
|
||||
int y = zoneVolume.getCenterY();
|
||||
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z));
|
||||
corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y - 1, z);
|
||||
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth);
|
||||
}
|
||||
|
||||
this.saveLobbyBlocks(corner1, corner2);
|
||||
}
|
||||
|
||||
private void createVolumeOrReset(World lobbyWorld) {
|
||||
if (this.volume == null) {
|
||||
// no previous wall
|
||||
this.volume = new Volume("lobby", lobbyWorld);
|
||||
} else if (this.volume.isSaved()) {
|
||||
this.volume.resetBlocks();
|
||||
this.volume.setWorld(lobbyWorld); // set world for the case where where are changing lobby location between worlds
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateLobbyWidth() {
|
||||
int noOfTeams = this.warzone.getTeams().size();
|
||||
if (this.warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
|
||||
noOfTeams = 1;
|
||||
}
|
||||
int lobbyWidth = noOfTeams * 4 + 5;
|
||||
this.lobbyHalfSide = lobbyWidth / 2;
|
||||
if (this.lobbyHalfSide < 7) {
|
||||
this.lobbyHalfSide = 7;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLobbyBlocks(Block corner1, Block corner2) {
|
||||
if (corner1 != null && corner2 != null) {
|
||||
// save the blocks, wide enough for three team gates, 3+1 high and 10 deep, extruding out from the zone wall.
|
||||
this.volume.setCornerOne(corner1);
|
||||
this.volume.setCornerTwo(corner2);
|
||||
this.volume.saveBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
// maybe the number of teams change, now reset the gate positions
|
||||
if (this.lobbyMiddleWallBlock != null && this.volume != null /* && volume.isSaved() */) {
|
||||
this.setGatePositions(BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock));
|
||||
// flatten the area (set all but floor to air, then replace any floor air blocks with glass)
|
||||
this.volume.clearBlocksThatDontFloat();
|
||||
this.volume.setToMaterial(Material.AIR);
|
||||
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful
|
||||
|
||||
// add war hub link gate
|
||||
if (War.war.getWarHub() != null) {
|
||||
Block linkGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.warHubLinkGate);
|
||||
this.placeGate(linkGateBlock, Material.OBSIDIAN);
|
||||
// add warhub sign
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "";
|
||||
lines[1] = "To War hub";
|
||||
lines[2] = "";
|
||||
lines[3] = "";
|
||||
this.resetGateSign(linkGateBlock, lines, false);
|
||||
}
|
||||
|
||||
// add team gates or single auto assign gate
|
||||
this.placeAutoAssignGate();
|
||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
|
||||
this.placeGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), TeamKind.teamKindFromString(teamName));
|
||||
}
|
||||
for (Team t : this.warzone.getTeams()) {
|
||||
this.resetTeamGateSign(t);
|
||||
}
|
||||
|
||||
// set zone tp
|
||||
this.zoneTeleportBlock = new BlockInfo(BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 6));
|
||||
int yaw = 0;
|
||||
if (this.wall == BlockFace.WEST) {
|
||||
yaw = 180;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
yaw = 90;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
yaw = 0;
|
||||
} else if (this.wall == BlockFace.NORTH) {
|
||||
yaw = 270;
|
||||
}
|
||||
this.warzone.setTeleport(new Location(this.volume.getWorld(), this.zoneTeleportBlock.getX(), this.zoneTeleportBlock.getY(), this.zoneTeleportBlock.getZ(), yaw, 0));
|
||||
|
||||
// set zone sign
|
||||
Block zoneSignBlock = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 4);
|
||||
byte data = 0;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
data = (byte) 4;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
data = (byte) 8;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
data = (byte) 12;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
data = (byte) 0;
|
||||
}
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "Warzone";
|
||||
lines[1] = this.warzone.getName();
|
||||
if (this.autoAssignGate != null) {
|
||||
lines[2] = "Enter the auto-";
|
||||
lines[3] = "assign gate.";
|
||||
} else {
|
||||
lines[2] = "";
|
||||
lines[3] = "Pick your team.";
|
||||
}
|
||||
SignHelper.setToSign(War.war, zoneSignBlock, data, lines);
|
||||
|
||||
// lets get some light in here
|
||||
if (this.wall == BlockFace.NORTH || this.wall == BlockFace.SOUTH) {
|
||||
BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(BlockFace.WEST, this.lobbyHalfSide - 1).getRelative(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST, this.lobbyHalfSide - 1).getRelative(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
} else {
|
||||
BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(BlockFace.NORTH, this.lobbyHalfSide - 1).getRelative(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(BlockFace.SOUTH, this.lobbyHalfSide - 1).getRelative(this.wall, 9).setType(Material.GLOWSTONE);
|
||||
}
|
||||
} else {
|
||||
War.war.log("Failed to initalize zone lobby for zone " + this.warzone.getName(), java.util.logging.Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
private void setGatePositions(Block lobbyMiddleWallBlock) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
this.teamGateBlocks.clear();
|
||||
if (this.warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
|
||||
this.autoAssignGate = new BlockInfo(lobbyMiddleWallBlock);
|
||||
} else {
|
||||
this.autoAssignGate = null;
|
||||
for (int doorIndex = 0; doorIndex < this.warzone.getTeams().size(); doorIndex++) {
|
||||
// 0 at center, 1 to the left, 2 to the right, 3 to the left, etc
|
||||
Team team = this.warzone.getTeams().get(doorIndex);
|
||||
if (this.warzone.getTeams().size() % 2 == 0) {
|
||||
// even number of teams
|
||||
if (doorIndex % 2 == 0) {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2 + 2)));
|
||||
} else {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2)));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (doorIndex == 0) {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock));
|
||||
} else if (doorIndex % 2 == 0) {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2)));
|
||||
} else {
|
||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2 + 2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.warHubLinkGate = new BlockInfo(lobbyMiddleWallBlock.getRelative(this.wall, 9));
|
||||
}
|
||||
|
||||
private void placeGate(Block block, TeamKind teamKind) {
|
||||
if (block != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
block.getRelative(BlockFace.DOWN).setType(Material.GLOWSTONE);
|
||||
this.setBlock(block.getRelative(leftSide), teamKind);
|
||||
this.setBlock(block.getRelative(rightSide).getRelative(BlockFace.UP), teamKind);
|
||||
this.setBlock(block.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), teamKind);
|
||||
this.setBlock(block.getRelative(rightSide), teamKind);
|
||||
this.setBlock(block.getRelative(leftSide).getRelative(BlockFace.UP), teamKind);
|
||||
this.setBlock(block.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), teamKind);
|
||||
this.setBlock(block.getRelative(BlockFace.UP).getRelative(BlockFace.UP), teamKind);
|
||||
}
|
||||
}
|
||||
|
||||
private void placeGate(Block block, Material material) {
|
||||
if (block != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
block.getRelative(BlockFace.DOWN).setType(Material.GLOWSTONE);
|
||||
this.setBlock(block.getRelative(leftSide), material);
|
||||
this.setBlock(block.getRelative(rightSide).getRelative(BlockFace.UP), material);
|
||||
this.setBlock(block.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), material);
|
||||
this.setBlock(block.getRelative(rightSide), material);
|
||||
this.setBlock(block.getRelative(leftSide).getRelative(BlockFace.UP), material);
|
||||
this.setBlock(block.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), material);
|
||||
this.setBlock(block.getRelative(BlockFace.UP).getRelative(BlockFace.UP), material);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlock(Block block, TeamKind kind) {
|
||||
block.setType(kind.getMaterial());
|
||||
block.setData(kind.getData());
|
||||
}
|
||||
|
||||
private void setBlock(Block block, Material material) {
|
||||
block.setType(material);
|
||||
}
|
||||
|
||||
private void placeAutoAssignGate() {
|
||||
if (this.autoAssignGate != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
List<Team> teams = this.warzone.getTeams();
|
||||
|
||||
Block autoAssignGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate);
|
||||
this.setBlock(autoAssignGateBlock.getRelative(BlockFace.DOWN), (Material.GLOWSTONE));
|
||||
int size = teams.size();
|
||||
if (size > 0) {
|
||||
TeamKind[] doorBlockKinds = new TeamKind[7];
|
||||
for (int i = 0; i < 7; i++) {
|
||||
doorBlockKinds[i] = teams.get(i % size).getKind();
|
||||
}
|
||||
this.setBlock(autoAssignGateBlock.getRelative(leftSide), doorBlockKinds[0]);
|
||||
this.setBlock(autoAssignGateBlock.getRelative(leftSide).getRelative(BlockFace.UP), doorBlockKinds[1]);
|
||||
this.setBlock(autoAssignGateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), doorBlockKinds[2]);
|
||||
this.setBlock(autoAssignGateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP), doorBlockKinds[3]);
|
||||
this.setBlock(autoAssignGateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP), doorBlockKinds[4]);
|
||||
this.setBlock(autoAssignGateBlock.getRelative(rightSide).getRelative(BlockFace.UP), doorBlockKinds[5]);
|
||||
this.setBlock(autoAssignGateBlock.getRelative(rightSide), doorBlockKinds[6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInTeamGate(Team team, Location location) {
|
||||
BlockInfo info = this.teamGateBlocks.get(team.getName());
|
||||
if (info != null) {
|
||||
if (location.getBlockX() == info.getX() && location.getBlockY() == info.getY() && location.getBlockZ() == info.getZ()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAutoAssignGate(Location location) {
|
||||
if (this.autoAssignGate != null && (location.getBlockX() == this.autoAssignGate.getX() && location.getBlockY() == this.autoAssignGate.getY() && location.getBlockZ() == this.autoAssignGate.getZ())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setVolume(Volume volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public BlockFace getWall() {
|
||||
return this.wall;
|
||||
}
|
||||
|
||||
public boolean isInWarHubLinkGate(Location location) {
|
||||
if (this.warHubLinkGate != null && location.getBlockX() == this.warHubLinkGate.getX() && location.getBlockY() == this.warHubLinkGate.getY() && location.getBlockZ() == this.warHubLinkGate.getZ()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean blockIsAGateBlock(Block block, BlockFace blockWall) {
|
||||
if (blockWall == this.wall) {
|
||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
|
||||
if (this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), block)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (this.autoAssignGate != null && this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate), block)) {
|
||||
// auto assign
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPartOfGate(Block gateBlock, Block block) {
|
||||
if (gateBlock != null) {
|
||||
BlockFace leftSide = null; // look at the zone
|
||||
BlockFace rightSide = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
leftSide = BlockFace.EAST;
|
||||
rightSide = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
leftSide = BlockFace.SOUTH;
|
||||
rightSide = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
leftSide = BlockFace.WEST;
|
||||
rightSide = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
leftSide = BlockFace.NORTH;
|
||||
rightSide = BlockFace.SOUTH;
|
||||
}
|
||||
return (block.getX() == gateBlock.getX() && block.getY() == gateBlock.getY() && block.getZ() == gateBlock.getZ()) || (block.getX() == gateBlock.getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(leftSide).getX() && block.getY() == gateBlock.getRelative(leftSide).getY() && block.getZ() == gateBlock.getRelative(leftSide).getZ()) || (block.getX() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(leftSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(BlockFace.UP).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getX() && block.getY() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getY() && block.getZ() == gateBlock.getRelative(rightSide).getRelative(BlockFace.UP).getRelative(BlockFace.UP).getZ()) || (block.getX() == gateBlock.getRelative(rightSide).getX() && block.getY() == gateBlock.getRelative(rightSide).getY() && block.getZ() == gateBlock.getRelative(rightSide).getZ()) || (block.getX() == gateBlock.getX() && block.getY() == gateBlock.getY() - 1 && block.getZ() == gateBlock.getZ());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Warzone getZone() {
|
||||
return this.warzone;
|
||||
}
|
||||
|
||||
public void resetTeamGateSign(Team team) {
|
||||
BlockInfo info = this.teamGateBlocks.get(team.getName());
|
||||
if (info != null) {
|
||||
this.resetTeamGateSign(team, BlockInfo.getBlock(this.volume.getWorld(), info));
|
||||
}
|
||||
}
|
||||
|
||||
private void resetTeamGateSign(Team team, Block gate) {
|
||||
if (gate != null) {
|
||||
String[] lines = new String[4];
|
||||
lines[0] = "Team " + team.getName();
|
||||
lines[1] = team.getPlayers().size() + "/" + team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE) + " players";
|
||||
lines[2] = team.getPoints() + "/" + team.getTeamConfig().resolveInt(TeamConfig.MAXSCORE) + " pts";
|
||||
if (team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) == -1) {
|
||||
lines[3] = "unlimited lives";
|
||||
} else {
|
||||
lines[3] = team.getRemainingLifes() + "/" + team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL) + " lives left";
|
||||
}
|
||||
this.resetGateSign(gate, lines, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetGateSign(Block gate, String[] lines, boolean awayFromWall) {
|
||||
Block block = null;
|
||||
BlockFace direction = null;
|
||||
if (awayFromWall) {
|
||||
direction = this.wall;
|
||||
} else if (this.wall == BlockFace.NORTH) {
|
||||
direction = BlockFace.SOUTH;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
direction = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
direction = BlockFace.NORTH;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
direction = BlockFace.EAST;
|
||||
}
|
||||
byte data = 0;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
block = gate.getRelative(direction).getRelative(BlockFace.EAST);
|
||||
if (awayFromWall) {
|
||||
data = (byte) 4;
|
||||
} else {
|
||||
data = (byte) 12;
|
||||
}
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
block = gate.getRelative(direction).getRelative(BlockFace.SOUTH);
|
||||
if (awayFromWall) {
|
||||
data = (byte) 8;
|
||||
} else {
|
||||
data = (byte) 0;
|
||||
}
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
block = gate.getRelative(direction).getRelative(BlockFace.WEST);
|
||||
if (awayFromWall) {
|
||||
data = (byte) 12;
|
||||
} else {
|
||||
data = (byte) 4;
|
||||
}
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
block = gate.getRelative(direction).getRelative(BlockFace.NORTH);
|
||||
if (awayFromWall) {
|
||||
data = (byte) 0;
|
||||
} else {
|
||||
data = (byte) 8;
|
||||
}
|
||||
}
|
||||
|
||||
SignHelper.setToSign(War.war, block, data, lines);
|
||||
}
|
||||
|
||||
public boolean isLeavingZone(Location location) {
|
||||
BlockFace inside = null;
|
||||
BlockFace left = null;
|
||||
BlockFace right = null;
|
||||
if (this.wall == BlockFace.NORTH) {
|
||||
inside = BlockFace.SOUTH;
|
||||
left = BlockFace.WEST;
|
||||
right = BlockFace.EAST;
|
||||
} else if (this.wall == BlockFace.EAST) {
|
||||
inside = BlockFace.WEST;
|
||||
left = BlockFace.NORTH;
|
||||
right = BlockFace.SOUTH;
|
||||
} else if (this.wall == BlockFace.SOUTH) {
|
||||
inside = BlockFace.NORTH;
|
||||
left = BlockFace.EAST;
|
||||
right = BlockFace.WEST;
|
||||
} else if (this.wall == BlockFace.WEST) {
|
||||
inside = BlockFace.EAST;
|
||||
left = BlockFace.SOUTH;
|
||||
right = BlockFace.NORTH;
|
||||
}
|
||||
if (this.autoAssignGate != null) {
|
||||
if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate), inside, left, right)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||
|
||||
BlockInfo info = this.teamGateBlocks.get(teamName);
|
||||
if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), info), inside, left, right)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean leaving(Location location, Block gate, BlockFace inside, BlockFace left, BlockFace right) {
|
||||
// 3x4x1 deep
|
||||
Volume gateExitVolume = new Volume("tempGateExit", location.getWorld());
|
||||
Block out = gate.getRelative(inside);
|
||||
gateExitVolume.setCornerOne(out.getRelative(left).getRelative(BlockFace.DOWN));
|
||||
gateExitVolume.setCornerTwo(gate.getRelative(right, 1).getRelative(BlockFace.UP, 2));
|
||||
|
||||
if (gateExitVolume.contains(location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,262 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
import com.tommytony.war.volumes.NotNorthwestException;
|
||||
import com.tommytony.war.volumes.NotSoutheastException;
|
||||
import com.tommytony.war.volumes.TooBigException;
|
||||
import com.tommytony.war.volumes.TooSmallException;
|
||||
|
||||
public class ZoneSetter {
|
||||
|
||||
private final Player player;
|
||||
private final String zoneName;
|
||||
|
||||
public ZoneSetter(Player player, String zoneName) {
|
||||
this.player = player;
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
public void placeNorthwest() {
|
||||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
Block northwestBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setNorthwest(northwestBlock);
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setNorthwest(northwestBlock);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (NotNorthwestException e) {
|
||||
War.war.badMsg(this.player, "The block you selected is not to the northwest of the existing southeasternmost block.");
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone(); // was reset before changing
|
||||
}
|
||||
} catch (TooSmallException e) {
|
||||
this.handleTooSmall();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
} catch (TooBigException e) {
|
||||
this.handleTooBig();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void placeSoutheast() {
|
||||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
Block southeastBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setSoutheast(southeastBlock);
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setSoutheast(southeastBlock);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (NotSoutheastException e) {
|
||||
War.war.badMsg(this.player, "The block you selected is not to the southeast of the existing northwestnmost block.");
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone(); // was reset before changing
|
||||
}
|
||||
} catch (TooSmallException e) {
|
||||
this.handleTooSmall();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
} catch (TooBigException e) {
|
||||
this.handleTooBig();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void placeCorner1() {
|
||||
Block corner1Block = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
this.placeCorner1(corner1Block);
|
||||
}
|
||||
|
||||
public void placeCorner1(Block corner1Block) {
|
||||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setZoneCornerOne(corner1Block);
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setZoneCornerOne(corner1Block);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (TooSmallException e) {
|
||||
this.handleTooSmall();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
} catch (TooBigException e) {
|
||||
this.handleTooBig();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void placeCorner2() {
|
||||
Block corner2Block = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
|
||||
this.placeCorner2(corner2Block);
|
||||
}
|
||||
|
||||
public void placeCorner2(Block corner2Block) {
|
||||
Warzone warzone = War.war.findWarzone(this.zoneName);
|
||||
StringBuilder msgString = new StringBuilder();
|
||||
try {
|
||||
if (warzone == null && War.war.getWarzones().size() >= War.war.getWarConfig().getInt(WarConfig.MAXZONES)) {
|
||||
// max warzones reached
|
||||
War.war.badMsg(player, "Too many warzones already! To change the maximum, use /warcfg maxzone:20.");
|
||||
return;
|
||||
} else if (warzone == null) {
|
||||
// create the warzone
|
||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||
warzone.addAuthor(player.getName());
|
||||
War.war.getIncompleteZones().add(warzone);
|
||||
warzone.getVolume().setZoneCornerTwo(corner2Block);
|
||||
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
|
||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||
return;
|
||||
} else {
|
||||
// change existing warzone
|
||||
this.resetWarzone(warzone, msgString);
|
||||
warzone.getVolume().setZoneCornerTwo(corner2Block);
|
||||
msgString.append("Warzone " + warzone.getName() + " modified. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
|
||||
}
|
||||
this.saveIfReady(warzone, msgString);
|
||||
} catch (TooSmallException e) {
|
||||
this.handleTooSmall();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
} catch (TooBigException e) {
|
||||
this.handleTooBig();
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
warzone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPlayerAuthorOfZoneOrAdmin(Warzone warzone) {
|
||||
boolean isAuthor = warzone.isAuthor(player);
|
||||
boolean isAdmin = !War.war.isWarAdmin(player);
|
||||
if (!isAuthor && !isAdmin) {
|
||||
War.war.badMsg(player, "You can't do this because you are not an author of the " + warzone.getName() + " warzone." );
|
||||
}
|
||||
return isAuthor || isAdmin;
|
||||
}
|
||||
|
||||
private void resetWarzone(Warzone warzone, StringBuilder msgString) {
|
||||
if (warzone.getVolume().isSaved()) {
|
||||
War.war.msg(this.player, "Resetting " + warzone.getName() + " blocks.");
|
||||
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) {
|
||||
warzone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
int reset = warzone.getVolume().resetBlocks();
|
||||
msgString.append(reset + " blocks reset. ");
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTooSmall() {
|
||||
War.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too small. Sides must be at least 10 blocks and all existing structures (spawns, flags, etc) must fit inside.");
|
||||
}
|
||||
|
||||
private void handleTooBig() {
|
||||
War.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too big. Sides must be less than 750 blocks.");
|
||||
}
|
||||
|
||||
private void saveIfReady(Warzone warzone, StringBuilder msgString) {
|
||||
if (warzone.ready()) {
|
||||
if (!War.war.getWarzones().contains(warzone)) {
|
||||
War.war.addWarzone(warzone);
|
||||
}
|
||||
if (War.war.getIncompleteZones().contains(warzone)) {
|
||||
War.war.getIncompleteZones().remove(warzone);
|
||||
}
|
||||
WarYmlMapper.save();
|
||||
msgString.append("Saving new warzone blocks...");
|
||||
War.war.msg(this.player, msgString.toString());
|
||||
warzone.saveState(false); // we just changed the volume, cant reset walls
|
||||
|
||||
if (warzone.getLobby() == null) {
|
||||
// Set default lobby on south side
|
||||
ZoneLobby lobby = new ZoneLobby(warzone, BlockFace.SOUTH);
|
||||
warzone.setLobby(lobby);
|
||||
if (War.war.getWarHub() != null) { // warhub has to change
|
||||
War.war.getWarHub().getVolume().resetBlocks();
|
||||
War.war.getWarHub().initialize();
|
||||
}
|
||||
War.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position.");
|
||||
}
|
||||
|
||||
warzone.initializeZone();
|
||||
WarzoneYmlMapper.save(warzone, true);
|
||||
War.war.msg(this.player, "Warzone saved.");
|
||||
} else {
|
||||
if (warzone.getVolume().getCornerOne() == null) {
|
||||
msgString.append("Still missing corner 1.");
|
||||
} else if (warzone.getVolume().getCornerTwo() == null) {
|
||||
msgString.append("Still missing corner 2.");
|
||||
}
|
||||
War.war.msg(this.player, msgString.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,224 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class ZoneWallGuard {
|
||||
private Player player;
|
||||
private Warzone warzone;
|
||||
private Location playerLocation;
|
||||
private BlockFace wall;
|
||||
private List<BlockInfo> glassified = new ArrayList<BlockInfo>();
|
||||
|
||||
public ZoneWallGuard(Player player, War war, Warzone warzone, BlockFace wall) {
|
||||
this.player = player;
|
||||
this.wall = wall;
|
||||
this.playerLocation = player.getLocation();
|
||||
this.warzone = warzone;
|
||||
this.activate();
|
||||
}
|
||||
|
||||
private void activate() {
|
||||
List<Block> nearestWallBlocks = this.warzone.getNearestWallBlocks(this.playerLocation);
|
||||
|
||||
// add wall guard blocks
|
||||
for (Block block : nearestWallBlocks) {
|
||||
this.glassify(block, this.wall);
|
||||
if (this.wall != BlockFace.UP && this.wall != BlockFace.DOWN) {
|
||||
this.glassify(block.getRelative(BlockFace.UP), this.wall);
|
||||
this.glassify(block.getRelative(BlockFace.UP, 2), this.wall);
|
||||
this.glassify(block.getRelative(BlockFace.DOWN), this.wall);
|
||||
this.glassify(block.getRelative(BlockFace.DOWN, 2), this.wall);
|
||||
}
|
||||
if (this.wall == BlockFace.NORTH && this.warzone.getVolume().isNorthWallBlock(block)) {
|
||||
this.glassify(block.getRelative(BlockFace.EAST), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.UP), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST, 2).getRelative(BlockFace.UP), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST, 2).getRelative(BlockFace.DOWN), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.UP, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.UP), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST, 2).getRelative(BlockFace.UP), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST, 2).getRelative(BlockFace.DOWN), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.UP, 2), BlockFace.NORTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN, 2), BlockFace.NORTH);
|
||||
} else if (this.wall == BlockFace.SOUTH && this.warzone.getVolume().isSouthWallBlock(block)) {
|
||||
this.glassify(block.getRelative(BlockFace.EAST), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.UP), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST, 2).getRelative(BlockFace.UP), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST, 2).getRelative(BlockFace.DOWN), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.UP, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.EAST).getRelative(BlockFace.DOWN, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.UP), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST, 2).getRelative(BlockFace.UP), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST, 2).getRelative(BlockFace.DOWN), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.UP, 2), BlockFace.SOUTH);
|
||||
this.glassify(block.getRelative(BlockFace.WEST).getRelative(BlockFace.DOWN, 2), BlockFace.SOUTH);
|
||||
} else if (this.wall == BlockFace.EAST && this.warzone.getVolume().isEastWallBlock(block)) {
|
||||
this.glassify(block.getRelative(BlockFace.NORTH), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.UP), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.DOWN), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP, 2), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN, 2), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.UP), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.DOWN), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP, 2), BlockFace.EAST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.EAST);
|
||||
} else if (this.wall == BlockFace.WEST && this.warzone.getVolume().isWestWallBlock(block)) {
|
||||
this.glassify(block.getRelative(BlockFace.NORTH), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.UP), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.DOWN), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.UP, 2), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.DOWN, 2), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.UP), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.DOWN), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP, 2), BlockFace.WEST);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.WEST);
|
||||
} else if (this.wall == BlockFace.UP && this.warzone.getVolume().isUpWallBlock(block)) {
|
||||
this.glassify(block.getRelative(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.EAST, 2), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.WEST, 2), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST, 2), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST, 2), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.EAST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.WEST), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP, 2), BlockFace.UP);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.UP);
|
||||
} else if (this.wall == BlockFace.DOWN && this.warzone.getVolume().isDownWallBlock(block)) {
|
||||
this.glassify(block.getRelative(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.EAST, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.WEST, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH, 2).getRelative(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.NORTH).getRelative(BlockFace.WEST, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.EAST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH, 2).getRelative(BlockFace.WEST), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.DOWN);
|
||||
this.glassify(block.getRelative(BlockFace.SOUTH).getRelative(BlockFace.DOWN, 2), BlockFace.DOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void glassify(Block block, BlockFace wall) {
|
||||
// face here means which wall we are working on
|
||||
|
||||
if ((block.getTypeId() == Material.AIR.getId() || block.getTypeId() == Material.WATER.getId()) && (this.warzone.getLobby() == null || (this.warzone.getLobby() != null && !this.warzone.getLobby().blockIsAGateBlock(block, wall)))) {
|
||||
if (wall == BlockFace.NORTH) {
|
||||
if (this.warzone.getVolume().isNorthWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.SOUTH) {
|
||||
if (this.warzone.getVolume().isSouthWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.EAST) {
|
||||
if (this.warzone.getVolume().isEastWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.WEST) {
|
||||
if (this.warzone.getVolume().isWestWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.UP) {
|
||||
if (this.warzone.getVolume().isUpWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
} else if (wall == BlockFace.DOWN) {
|
||||
if (this.warzone.getVolume().isDownWallBlock(block)) {
|
||||
this.glassified.add(new BlockInfo(block));
|
||||
block.setType(Material.GLASS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerPosition(Location location) {
|
||||
if (this.warzone.isNearWall(location)) {
|
||||
this.playerLocation = location;
|
||||
this.deactivate();
|
||||
this.activate();
|
||||
}
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
for (BlockInfo oldBlock : this.glassified) {
|
||||
// return to original
|
||||
Block glassifiedBlock = this.warzone.getWorld().getBlockAt(oldBlock.getX(), oldBlock.getY(), oldBlock.getZ());
|
||||
glassifiedBlock.setTypeId(oldBlock.getTypeId());
|
||||
glassifiedBlock.setData(oldBlock.getData());
|
||||
}
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public BlockFace getWall() {
|
||||
return this.wall;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
public class BlockResetJob implements Runnable {
|
||||
|
||||
private final Volume volume;
|
||||
|
||||
public BlockResetJob(Volume volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.volume.resetBlocks();
|
||||
}
|
||||
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.ContainerBlock;
|
||||
import org.bukkit.block.NoteBlock;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.tommytony.war.utils.DeferredBlockReset;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
public class DeferredBlockResetsJob implements Runnable {
|
||||
|
||||
List<DeferredBlockReset> deferred = new ArrayList<DeferredBlockReset>();
|
||||
private final World world;
|
||||
|
||||
public DeferredBlockResetsJob(World world) {
|
||||
this.world = world;
|
||||
|
||||
}
|
||||
|
||||
public void add(DeferredBlockReset pleaseResetLater) {
|
||||
this.deferred.add(pleaseResetLater);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.deferred.isEmpty();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
ArrayList<DeferredBlockReset> doors = new ArrayList<DeferredBlockReset>();
|
||||
|
||||
for (DeferredBlockReset reset : this.deferred) {
|
||||
if (this.world != null && reset != null) {
|
||||
Block worldBlock = this.world.getBlockAt(reset.getX(), reset.getY(), reset.getZ());
|
||||
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
|
||||
|
||||
if (reset.getBlockType() == Material.WALL_SIGN.getId() || reset.getBlockType() == Material.SIGN_POST.getId()) {
|
||||
BlockState state = worldBlock.getState();
|
||||
state.setData(new org.bukkit.material.Sign(reset.getBlockType(), reset.getBlockData()));
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if (reset.getLines() != null && sign.getLines() != null) {
|
||||
if (reset.getLines().length > 0) {
|
||||
sign.setLine(0, reset.getLines()[0]);
|
||||
}
|
||||
if (reset.getLines().length > 1) {
|
||||
sign.setLine(1, reset.getLines()[1]);
|
||||
}
|
||||
if (reset.getLines().length > 2) {
|
||||
sign.setLine(2, reset.getLines()[2]);
|
||||
}
|
||||
if (reset.getLines().length > 3) {
|
||||
sign.setLine(3, reset.getLines()[3]);
|
||||
}
|
||||
sign.update(true);
|
||||
}
|
||||
}
|
||||
} else if (reset.getBlockType() == Material.CHEST.getId()
|
||||
|| reset.getBlockType() == Material.DISPENSER.getId()
|
||||
|| reset.getBlockType() == Material.FURNACE.getId()
|
||||
|| reset.getBlockType() == Material.BURNING_FURNACE.getId()) {
|
||||
List<ItemStack> items = reset.getItems();
|
||||
|
||||
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
|
||||
worldBlock.setData(reset.getBlockData());
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof ContainerBlock) {
|
||||
ContainerBlock container = (ContainerBlock) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
container.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
container.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
state.update(true);
|
||||
items.clear();
|
||||
}
|
||||
} else {
|
||||
// normal reset
|
||||
worldBlock.setData(reset.getBlockData());
|
||||
}
|
||||
} else if (reset.getBlockType() == Material.NOTE_BLOCK.getId()) {
|
||||
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
|
||||
worldBlock.setData(reset.getBlockData());
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof NoteBlock && reset.getRawNote() != null) {
|
||||
NoteBlock noteBlock = (NoteBlock) state;
|
||||
noteBlock.setRawNote(reset.getRawNote());
|
||||
noteBlock.update(true);
|
||||
} else {
|
||||
// normal reset
|
||||
worldBlock.setData(reset.getBlockData());
|
||||
}
|
||||
} else if (reset.getBlockType() == Material.WOODEN_DOOR.getId() || reset.getBlockType() == Material.IRON_DOOR_BLOCK.getId()) {
|
||||
// Door blocks
|
||||
doors.add(reset);
|
||||
} else {
|
||||
// normal data reset
|
||||
worldBlock.setData(reset.getBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Take care of doors last
|
||||
for (DeferredBlockReset doorBlock : doors) {
|
||||
Block worldBlock = world.getBlockAt(doorBlock.getX(), doorBlock.getY(), doorBlock.getZ());
|
||||
if (worldBlock.getTypeId() != doorBlock.getBlockType() || worldBlock.getData() != doorBlock.getBlockData()) {
|
||||
// find its friend
|
||||
for (DeferredBlockReset other : doors) {
|
||||
if (other.getX() == doorBlock.getX()
|
||||
&& other.getY() == doorBlock.getY() - 1
|
||||
&& other.getZ() == doorBlock.getZ()) {
|
||||
// doorBlock is above
|
||||
Block above = worldBlock;
|
||||
Block below = world.getBlockAt(other.getX(), other.getY(), other.getZ());
|
||||
above.setTypeId(doorBlock.getBlockType());
|
||||
above.setData(doorBlock.getBlockData());
|
||||
below.setTypeId(other.getBlockType());
|
||||
below.setData(other.getBlockData());
|
||||
scrubDroppedDoors(below);
|
||||
break;
|
||||
} else if (other.getX() == doorBlock.getX()
|
||||
&& other.getY() == doorBlock.getY() + 1
|
||||
&& other.getZ() == doorBlock.getZ()) {
|
||||
// doorBlock is below
|
||||
Block above = world.getBlockAt(other.getX(), other.getY(), other.getZ());
|
||||
Block below = worldBlock;
|
||||
above.setTypeId(doorBlock.getBlockType());
|
||||
above.setData(doorBlock.getBlockData());
|
||||
below.setTypeId(other.getBlockType());
|
||||
below.setData(other.getBlockData());
|
||||
scrubDroppedDoors(below);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void scrubDroppedDoors(Block block) {
|
||||
Chunk chunk = block.getWorld().getChunkAt(block);
|
||||
Volume scrubVolume = new Volume("scrub", block.getWorld());
|
||||
scrubVolume.setCornerOne(block.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST).getRelative(BlockFace.NORTH));
|
||||
scrubVolume.setCornerTwo(block.getRelative(BlockFace.UP).getRelative(BlockFace.WEST).getRelative(BlockFace.SOUTH));
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
if ((entity instanceof Item && (((Item)entity).getItemStack().getTypeId() == Material.IRON_DOOR.getId()
|
||||
|| ((Item)entity).getItemStack().getTypeId() == Material.WOOD_DOOR.getId()))
|
||||
&& scrubVolume.contains(entity.getLocation())) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
/**
|
||||
* Sets the helmet again onto the players heads. Also limits the number of blocks being held.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
*/
|
||||
public class HelmetProtectionTask implements Runnable {
|
||||
|
||||
/**
|
||||
* @see Runnable.run()
|
||||
*/
|
||||
public void run() {
|
||||
if (!War.war.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
for (Team team : zone.getTeams()) {
|
||||
for (Player player : team.getPlayers()) {
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
Material teamBlockMaterial;
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
|
||||
teamBlockMaterial = team.getKind().getMaterial();
|
||||
// 1) Replace missing block head
|
||||
if (playerInv.getHelmet().getType() != teamBlockMaterial) {
|
||||
playerInv.setHelmet(this.createBlockHead(team));
|
||||
}
|
||||
// 2) Get rid of extra blocks in inventory: only keep one
|
||||
HashMap<Integer, ? extends ItemStack> blocks = playerInv.all(teamBlockMaterial);
|
||||
if (blocks.size() > 1 || (blocks.size() == 1 && blocks.get(blocks.keySet().iterator().next()).getAmount() > 1)) {
|
||||
int i = 0;
|
||||
int removed = 0;
|
||||
for (ItemStack item : playerInv.getContents()) {
|
||||
// remove only same colored wool
|
||||
if (item != null && item.getType() == teamBlockMaterial && item.getData().getData() == team.getKind().getData()) {
|
||||
playerInv.clear(i);
|
||||
removed++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
playerInv.setItem(playerInv.firstEmpty(), this.createBlockHead(team));
|
||||
if (removed > 1) {
|
||||
War.war.badMsg(player, "All that " + team.getName() + " wool must have been heavy!");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (team.getKind() == TeamKind.GOLD) {
|
||||
teamBlockMaterial = Material.GOLD_HELMET;
|
||||
} else if (team.getKind() == TeamKind.DIAMOND) {
|
||||
teamBlockMaterial = Material.DIAMOND_HELMET;
|
||||
} else if (team.getKind() == TeamKind.IRON) {
|
||||
teamBlockMaterial = Material.IRON_HELMET;
|
||||
} else {
|
||||
teamBlockMaterial = Material.LEATHER_HELMET;
|
||||
}
|
||||
if (playerInv.getHelmet() != null && playerInv.getHelmet().getType() != teamBlockMaterial) {
|
||||
playerInv.setHelmet(new ItemStack(teamBlockMaterial));
|
||||
}
|
||||
HashMap<Integer, ? extends ItemStack> helmets = playerInv.all(teamBlockMaterial);
|
||||
if (helmets.size() > 1 || (helmets.size() == 1 && helmets.get(helmets.keySet().iterator().next()).getAmount() > 1)) {
|
||||
playerInv.remove(teamBlockMaterial);
|
||||
playerInv.setItem(playerInv.firstEmpty(), new ItemStack(teamBlockMaterial));
|
||||
War.war.badMsg(player, "All those helmets must have been heavy!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack createBlockHead(Team team) {
|
||||
return new ItemStack(team.getKind().getMaterial(), 1, (short) 1, new Byte(team.getKind().getData()));
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class InitZoneJob implements Runnable {
|
||||
|
||||
private final Warzone zone;
|
||||
private final Player respawnExempted;
|
||||
|
||||
public InitZoneJob(Warzone zone) {
|
||||
this.zone = zone;
|
||||
this.respawnExempted = null;
|
||||
}
|
||||
|
||||
public InitZoneJob(Warzone warzone, Player respawnExempted) {
|
||||
this.zone = warzone;
|
||||
this.respawnExempted = respawnExempted;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.zone.initializeZone(this.respawnExempted);
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class LoadoutResetJob implements Runnable {
|
||||
|
||||
private final Player player;
|
||||
private final Warzone zone;
|
||||
private final Team team;
|
||||
private final boolean isFirstRespawn;
|
||||
private final boolean isToggle;
|
||||
|
||||
public LoadoutResetJob(Warzone zone, Team team, Player player, boolean isFirstRespawn, boolean isToggle) {
|
||||
this.zone = zone;
|
||||
this.team = team;
|
||||
this.player = player;
|
||||
this.isFirstRespawn = isFirstRespawn;
|
||||
this.isToggle = isToggle;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.zone.equipPlayerLoadoutSelection(player, team, isFirstRespawn, isToggle);
|
||||
|
||||
// Stop fire here, since doing it in the same tick as death doesn't extinguish it
|
||||
this.player.setFireTicks(0);
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LootDropperTask implements Runnable {
|
||||
|
||||
private final List<ItemStack> drop;
|
||||
private final Location location;
|
||||
|
||||
public LootDropperTask(Location location, List<ItemStack> drop) {
|
||||
this.location = location;
|
||||
this.drop = drop;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (ItemStack item : this.drop) {
|
||||
if (item != null) {
|
||||
this.location.getWorld().dropItemNaturally(this.location, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import com.tommytony.war.volumes.BlockInfo;
|
||||
|
||||
public class ResetCursorJob implements Runnable {
|
||||
|
||||
private final Block cornerBlock;
|
||||
private final BlockInfo[] originalCursorBlocks;
|
||||
private final boolean isSoutheast;
|
||||
|
||||
public ResetCursorJob(Block cornerBlock, BlockInfo[] originalCursorBlocks, boolean isSoutheast) {
|
||||
this.cornerBlock = cornerBlock;
|
||||
this.originalCursorBlocks = originalCursorBlocks;
|
||||
this.isSoutheast = isSoutheast;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (this.isSoutheast) {
|
||||
this.cornerBlock.setType(this.originalCursorBlocks[0].getType());
|
||||
this.cornerBlock.setData(this.originalCursorBlocks[0].getData());
|
||||
this.cornerBlock.getRelative(BlockFace.WEST).setType(this.originalCursorBlocks[1].getType());
|
||||
this.cornerBlock.getRelative(BlockFace.WEST).setData(this.originalCursorBlocks[1].getData());
|
||||
this.cornerBlock.getRelative(BlockFace.NORTH).setType(this.originalCursorBlocks[2].getType());
|
||||
this.cornerBlock.getRelative(BlockFace.NORTH).setData(this.originalCursorBlocks[2].getData());
|
||||
} else {
|
||||
this.cornerBlock.setType(this.originalCursorBlocks[0].getType());
|
||||
this.cornerBlock.setData(this.originalCursorBlocks[0].getData());
|
||||
this.cornerBlock.getRelative(BlockFace.EAST).setType(this.originalCursorBlocks[1].getType());
|
||||
this.cornerBlock.getRelative(BlockFace.EAST).setData(this.originalCursorBlocks[1].getData());
|
||||
this.cornerBlock.getRelative(BlockFace.SOUTH).setType(this.originalCursorBlocks[2].getType());
|
||||
this.cornerBlock.getRelative(BlockFace.SOUTH).setData(this.originalCursorBlocks[2].getData());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class RespawnPlayerJob implements Runnable {
|
||||
|
||||
private final Team team;
|
||||
private final Player player;
|
||||
private final Warzone zone;
|
||||
|
||||
public RespawnPlayerJob(Warzone zone, Team playerTeam, Player player) {
|
||||
this.zone = zone;
|
||||
// TODO Auto-generated constructor stub
|
||||
this.team = playerTeam;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.zone.respawnPlayer(this.team, this.player);
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class RestoreDeadmanInventoryJob implements Runnable {
|
||||
|
||||
private final Player player;
|
||||
private final Warzone zone;
|
||||
|
||||
public RestoreDeadmanInventoryJob(Player player, Warzone zone) {
|
||||
this.player = player;
|
||||
this.zone = zone;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.zone.restoreDeadmanInventory(this.player);
|
||||
this.player.teleport(this.zone.getTeleport());
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.VolumeMapper;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
public class RestoreWarhubJob implements Runnable {
|
||||
|
||||
private final String hubStr;
|
||||
|
||||
public RestoreWarhubJob(String hubStr) {
|
||||
this.hubStr = hubStr;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String[] hubStrSplit = this.hubStr.split(",");
|
||||
|
||||
int hubX = Integer.parseInt(hubStrSplit[0]);
|
||||
int hubY = Integer.parseInt(hubStrSplit[1]);
|
||||
int hubZ = Integer.parseInt(hubStrSplit[2]);
|
||||
World world = null;
|
||||
String worldName;
|
||||
String hubOrientation = "west";
|
||||
if (hubStrSplit.length > 3) {
|
||||
worldName = hubStrSplit[3];
|
||||
world = War.war.getServer().getWorld(worldName);
|
||||
if (hubStrSplit.length > 4) {
|
||||
hubOrientation = hubStrSplit[4];
|
||||
}
|
||||
} else {
|
||||
worldName = "DEFAULT";
|
||||
world = War.war.getServer().getWorlds().get(0); // default to first world
|
||||
}
|
||||
if (world != null) {
|
||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||
WarHub hub = new WarHub(hubLocation, hubOrientation);
|
||||
War.war.setWarHub(hub);
|
||||
Volume vol = VolumeMapper.loadVolume("warhub", "", world);
|
||||
hub.setVolume(vol);
|
||||
hub.getVolume().resetBlocks();
|
||||
hub.initialize();
|
||||
|
||||
// In the previous job started by the mapper, warzones were created, but their lobbies are missing the war hub gate (because it didn't exist yet)
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
War.war.log("Warhub ready.", Level.INFO);
|
||||
} else {
|
||||
War.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mappers.WarYmlMapper;
|
||||
import com.tommytony.war.mappers.WarzoneTxtMapper;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
public class RestoreWarzonesJob implements Runnable {
|
||||
|
||||
private final String warzonesStr;
|
||||
private final boolean newWarInstall;
|
||||
private final boolean convertingToYml;
|
||||
|
||||
public RestoreWarzonesJob(String warzonesStr, boolean newWarInstall, boolean convertingToYml) {
|
||||
this.warzonesStr = warzonesStr;
|
||||
this.newWarInstall = newWarInstall;
|
||||
this.convertingToYml = convertingToYml;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String[] warzoneSplit = this.warzonesStr.split(",");
|
||||
War.war.getWarzones().clear();
|
||||
|
||||
for (String warzoneName : warzoneSplit) {
|
||||
if (warzoneName != null && !warzoneName.equals("")) {
|
||||
War.war.log("Loading zone " + warzoneName + "...", Level.INFO);
|
||||
Warzone zone = WarzoneTxtMapper.load(warzoneName, !this.newWarInstall);
|
||||
if (zone != null) { // could have failed, would've been logged already
|
||||
War.war.getWarzones().add(zone);
|
||||
zone.getVolume().loadCorners();
|
||||
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.getWarzones().size() > 0) {
|
||||
War.war.log("Warzones ready.", Level.INFO);
|
||||
}
|
||||
|
||||
if (convertingToYml) {
|
||||
// Loading process is over, we can convert (i.e. save in new format)
|
||||
WarYmlMapper.save();
|
||||
War.war.log("Converted war.txt to war.yml.", Level.INFO);
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
WarzoneYmlMapper.save(zone, false);
|
||||
War.war.log("Converted warzone-" + zone.getName() + ".txt to warzone-" + zone.getName() + ".yml.", Level.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.VolumeMapper;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
public class RestoreYmlWarhubJob implements Runnable {
|
||||
|
||||
private final ConfigurationSection warhubConfig;
|
||||
|
||||
public RestoreYmlWarhubJob(ConfigurationSection warhubConfig) {
|
||||
this.warhubConfig = warhubConfig;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
int hubX = warhubConfig.getInt("x");
|
||||
int hubY = warhubConfig.getInt("y");
|
||||
int hubZ = warhubConfig.getInt("z");
|
||||
|
||||
String worldName = warhubConfig.getString("world");
|
||||
String hubOrientation = warhubConfig.getString("orientation");
|
||||
|
||||
World world = War.war.getServer().getWorld(worldName);
|
||||
if (world != null) {
|
||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||
WarHub hub = new WarHub(hubLocation, hubOrientation);
|
||||
War.war.setWarHub(hub);
|
||||
Volume vol = VolumeMapper.loadVolume("warhub", "", world);
|
||||
hub.setVolume(vol);
|
||||
hub.getVolume().resetBlocks();
|
||||
hub.initialize();
|
||||
|
||||
// In the previous job started by the mapper, warzones were created, but their lobbies are missing the war hub gate (because it didn't exist yet)
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
zone.getLobby().initialize();
|
||||
}
|
||||
}
|
||||
War.war.log("Warhub ready.", Level.INFO);
|
||||
} else {
|
||||
War.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mappers.WarzoneYmlMapper;
|
||||
|
||||
public class RestoreYmlWarzonesJob implements Runnable {
|
||||
|
||||
private final List<String> warzones;
|
||||
private final boolean newWarInstall;
|
||||
|
||||
public RestoreYmlWarzonesJob(List<String> warzones, boolean newWarInstall) {
|
||||
this.warzones = warzones;
|
||||
this.newWarInstall = newWarInstall;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
War.war.getWarzones().clear();
|
||||
if (this.warzones != null) {
|
||||
for (String warzoneName : this.warzones) {
|
||||
if (warzoneName != null && !warzoneName.equals("")) {
|
||||
War.war.log("Loading zone " + warzoneName + "...", Level.INFO);
|
||||
Warzone zone = WarzoneYmlMapper.load(warzoneName, !this.newWarInstall);
|
||||
if (zone != null) { // could have failed, would've been logged already
|
||||
War.war.getWarzones().add(zone);
|
||||
|
||||
zone.getVolume().loadCorners();
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (War.war.getWarzones().size() > 0) {
|
||||
War.war.log("Warzones ready.", Level.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.spout.SpoutMessenger;
|
||||
|
||||
public class ScoreCapReachedJob implements Runnable {
|
||||
|
||||
private final Warzone zone;
|
||||
private final String winnersStr;
|
||||
|
||||
public ScoreCapReachedJob(Warzone zone, String winnersStr) {
|
||||
this.zone = zone;
|
||||
this.winnersStr = winnersStr;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (Team t : this.zone.getTeams()) {
|
||||
if (War.war.isSpoutServer()) {
|
||||
for (Player p : t.getPlayers()) {
|
||||
SpoutPlayer sp = SpoutManager.getPlayer(p);
|
||||
if (sp.isSpoutCraftEnabled()) {
|
||||
sp.sendNotification(
|
||||
SpoutMessenger.cleanForNotification("Match won! " + ChatColor.WHITE + "Winners:"),
|
||||
SpoutMessenger.cleanForNotification(SpoutMessenger.addMissingColor(winnersStr, zone)),
|
||||
Material.CAKE,
|
||||
(short)0,
|
||||
10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
String winnersStrAndExtra = "Score cap reached. Game is over! Winning team(s): " + this.winnersStr;
|
||||
winnersStrAndExtra += ". Resetting warzone and your inventory...";
|
||||
t.teamcast(winnersStrAndExtra);
|
||||
boolean isSpoutServer = War.war.isSpoutServer();
|
||||
for (Player tp : t.getPlayers()) {
|
||||
// Send everyone to rally point (or zone lobby if not rally point)
|
||||
if (this.zone.getRallyPoint() != null) {
|
||||
tp.teleport(this.zone.getRallyPoint());
|
||||
} else {
|
||||
tp.teleport(this.zone.getTeleport());
|
||||
}
|
||||
tp.setFireTicks(0);
|
||||
tp.setRemainingAir(300);
|
||||
if (this.zone.hasPlayerState(tp.getName())) {
|
||||
this.zone.restorePlayerState(tp);
|
||||
}
|
||||
if (this.winnersStr.contains(t.getName())) {
|
||||
// give reward
|
||||
for (Integer slot : t.getInventories().resolveReward().keySet()) {
|
||||
ItemStack item = t.getInventories().resolveReward().get(slot);
|
||||
if (item != null) {
|
||||
tp.getInventory().addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
t.resetPoints();
|
||||
t.getPlayers().clear(); // empty the team
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
public class SpoutFadeOutMessageJob implements Runnable {
|
||||
|
||||
public SpoutFadeOutMessageJob() {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
War.war.getSpoutMessenger().fadeOutOldMessages();
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.tommytony.war.jobs;
|
||||
|
||||
import com.tommytony.war.mappers.ZoneVolumeMapper;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
public class ZoneVolumeSaveJob extends Thread {
|
||||
private final Volume volume;
|
||||
private final String zoneName;
|
||||
|
||||
public ZoneVolumeSaveJob(Volume volume, String zoneName) {
|
||||
this.volume = volume;
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ZoneVolumeMapper.save(this.volume, this.zoneName);
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LoadoutTxtMapper {
|
||||
|
||||
public static String fromLoadoutToString(HashMap<Integer, ItemStack> loadout) {
|
||||
String loadoutString = "";
|
||||
for (Integer slot : loadout.keySet()) {
|
||||
ItemStack item = loadout.get(slot);
|
||||
if (item != null) {
|
||||
loadoutString += item.getTypeId() + "," + item.getAmount() + "," + slot + "," + item.getDurability() + "," + item.getData().getData();
|
||||
if (item.getEnchantments().keySet().size() > 0) {
|
||||
String enchantmentsStr = "";
|
||||
for (Enchantment enchantment : item.getEnchantments().keySet()) {
|
||||
enchantmentsStr += enchantment.getId() + ":" + item.getEnchantments().get(enchantment) + "::";
|
||||
}
|
||||
loadoutString += "," + enchantmentsStr;
|
||||
}
|
||||
}
|
||||
loadoutString += ";";
|
||||
}
|
||||
return loadoutString;
|
||||
}
|
||||
|
||||
public static void fromStringToLoadout(String loadoutString, HashMap<Integer, ItemStack> destinationLoadout) {
|
||||
String[] rewardStrSplit = loadoutString.split(";");
|
||||
destinationLoadout.clear();
|
||||
for (String itemStr : rewardStrSplit) {
|
||||
if (itemStr != null && !itemStr.equals("")) {
|
||||
String[] itemStrSplit = itemStr.split(",");
|
||||
ItemStack item = null;
|
||||
if (itemStrSplit.length == 3) {
|
||||
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
} else if (itemStrSplit.length == 5) {
|
||||
short durability = Short.parseShort(itemStrSplit[3]);
|
||||
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability, Byte.parseByte(itemStrSplit[4]));
|
||||
item.setDurability(durability);
|
||||
} else if (itemStrSplit.length == 6) {
|
||||
short durability = Short.parseShort(itemStrSplit[3]);
|
||||
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability, Byte.parseByte(itemStrSplit[4]));
|
||||
item.setDurability(durability);
|
||||
|
||||
// enchantments
|
||||
String[] enchantmentsSplit = itemStrSplit[5].split("::");
|
||||
for (String enchantmentStr : enchantmentsSplit) {
|
||||
if (!enchantmentStr.equals("")) {
|
||||
String[] enchantmentSplit = enchantmentStr.split(":");
|
||||
int enchantId = Integer.parseInt(enchantmentSplit[0]);
|
||||
int level = Integer.parseInt(enchantmentSplit[1]);
|
||||
item.addEnchantment(Enchantment.getById(enchantId), level);
|
||||
}
|
||||
}
|
||||
}
|
||||
destinationLoadout.put(Integer.parseInt(itemStrSplit[2]), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class LoadoutYmlMapper {
|
||||
|
||||
public static void fromConfigToLoadouts(ConfigurationSection config, HashMap<String, HashMap<Integer, ItemStack>> loadouts) {
|
||||
List<String> loadoutNames = config.getStringList("names");
|
||||
loadouts.clear();
|
||||
for (String name : loadoutNames) {
|
||||
HashMap<Integer, ItemStack> newLoadout = new HashMap<Integer, ItemStack>();
|
||||
fromConfigToLoadout(config, newLoadout, name);
|
||||
loadouts.put(name, newLoadout);
|
||||
}
|
||||
}
|
||||
|
||||
public static void fromConfigToLoadout(ConfigurationSection config, HashMap<Integer, ItemStack> loadout, String loadoutName) {
|
||||
List<Integer> slots = config.getIntegerList(loadoutName + ".slots");
|
||||
for (Integer slot : slots) {
|
||||
String prefix = loadoutName + "." + slot + ".";
|
||||
|
||||
int id = config.getInt(prefix + "id");
|
||||
byte data = (byte)config.getInt(prefix + "data");
|
||||
int amount = config.getInt(prefix + "amount");
|
||||
short durability = (short)config.getInt(prefix + "durability");
|
||||
|
||||
ItemStack stack = new ItemStack(id, amount, durability, data);
|
||||
stack.setDurability(durability);
|
||||
|
||||
if (config.contains(prefix + "enchantments")) {
|
||||
List<String> enchantmentStringList = config.getStringList(prefix + "enchantments");
|
||||
for (String enchantmentString : enchantmentStringList) {
|
||||
String[] enchantmentStringSplit = enchantmentString.split(",");
|
||||
if (enchantmentStringSplit.length == 2) {
|
||||
int enchantId = Integer.parseInt(enchantmentStringSplit[0]);
|
||||
int level = Integer.parseInt(enchantmentStringSplit[1]);
|
||||
stack.addEnchantment(Enchantment.getById(enchantId), level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadout.put(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
public static void fromLoadoutsToConfig(HashMap<String, HashMap<Integer, ItemStack>> loadouts, ConfigurationSection section) {
|
||||
List<String> sortedNames = sortNames(loadouts);
|
||||
|
||||
section.set("names", sortedNames);
|
||||
for (String name : sortedNames) {
|
||||
fromLoadoutToConfig(name, loadouts.get(name), section);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> sortNames(HashMap<String, HashMap<Integer, ItemStack>> loadouts) {
|
||||
List<String> sortedNames = new ArrayList<String>();
|
||||
|
||||
// default comes first
|
||||
if (loadouts.containsKey("default")) {
|
||||
sortedNames.add("default");
|
||||
}
|
||||
|
||||
for (String name : loadouts.keySet()) {
|
||||
if (!name.equals("default")) {
|
||||
sortedNames.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
return sortedNames;
|
||||
}
|
||||
|
||||
private static List<Integer> toIntList(Set<Integer> keySet) {
|
||||
List<Integer> list = new ArrayList<Integer>();
|
||||
for (Integer key : keySet) {
|
||||
list.add(key);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void fromLoadoutToConfig(String loadoutName, HashMap<Integer, ItemStack> loadout, ConfigurationSection section) {
|
||||
ConfigurationSection loadoutSection = section.createSection(loadoutName);
|
||||
loadoutSection.set("slots", toIntList(loadout.keySet()));
|
||||
for (Integer slot : loadout.keySet()) {
|
||||
ConfigurationSection slotSection = loadoutSection.createSection(slot.toString());
|
||||
ItemStack stack = loadout.get(slot);
|
||||
|
||||
slotSection.set("id", stack.getTypeId());
|
||||
slotSection.set("data", stack.getData().getData());
|
||||
slotSection.set("amount", stack.getAmount());
|
||||
slotSection.set("durability", stack.getDurability());
|
||||
|
||||
if (stack.getEnchantments().keySet().size() > 0) {
|
||||
List<String> enchantmentStringList = new ArrayList<String>();
|
||||
for (Enchantment enchantment : stack.getEnchantments().keySet()) {
|
||||
int level = stack.getEnchantments().get(enchantment);
|
||||
enchantmentStringList.add(enchantment.getId() + "," + level);
|
||||
}
|
||||
slotSection.set("enchantments", enchantmentStringList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,433 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.jobs.DeferredBlockResetsJob;
|
||||
import com.tommytony.war.utils.DeferredBlockReset;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class PreDeGaulleZoneVolumeMapper {
|
||||
|
||||
private static List<ItemStack> readInventoryString(String invString) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
String[] itemsStrSplit = invString.split(";;");
|
||||
for (String itemStr : itemsStrSplit) {
|
||||
String[] itemStrSplit = itemStr.split(";");
|
||||
if (itemStrSplit.length == 4) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
items.add(stack);
|
||||
} else if (itemStrSplit.length == 3) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
items.add(stack);
|
||||
} else {
|
||||
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])));
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
|
||||
BufferedReader in = null;
|
||||
int noOfResetBlocks = 0;
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
String firstLine = in.readLine();
|
||||
|
||||
if (firstLine != null && !firstLine.equals("")) {
|
||||
boolean height129Fix = false;
|
||||
int x1 = Integer.parseInt(in.readLine());
|
||||
int y1 = Integer.parseInt(in.readLine());
|
||||
if (y1 == 128) {
|
||||
height129Fix = true;
|
||||
y1 = 127;
|
||||
}
|
||||
int z1 = Integer.parseInt(in.readLine());
|
||||
in.readLine();
|
||||
int x2 = Integer.parseInt(in.readLine());
|
||||
int y2 = Integer.parseInt(in.readLine());
|
||||
if (y2 == 128) {
|
||||
height129Fix = true;
|
||||
y2 = 127;
|
||||
}
|
||||
int z2 = Integer.parseInt(in.readLine());
|
||||
|
||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
if (!onlyLoadCorners) {
|
||||
DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world);
|
||||
int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0;
|
||||
int diskBlockType;
|
||||
byte diskBlockData;
|
||||
Block worldBlock;
|
||||
int worldBlockId;
|
||||
volume.clearBlocksThatDontFloat();
|
||||
x = volume.getMinX();
|
||||
String blockLine;
|
||||
String[] blockSplit;
|
||||
for (i = 0; i < volume.getSizeX(); i++) {
|
||||
y = volume.getMinY();
|
||||
for (j = 0; j < volume.getSizeY(); j++) {
|
||||
z = volume.getMinZ();
|
||||
for (k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
blockLine = in.readLine();
|
||||
|
||||
if (blockLine != null && !blockLine.equals("")) {
|
||||
blockSplit = blockLine.split(",");
|
||||
if (blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
|
||||
diskBlockType = Integer.parseInt(blockSplit[0]);
|
||||
diskBlockData = Byte.parseByte(blockSplit[1]);
|
||||
worldBlock = volume.getWorld().getBlockAt(x, y, z);
|
||||
worldBlockId = worldBlock.getTypeId();
|
||||
if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) {
|
||||
if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) {
|
||||
// Signs read
|
||||
String linesStr = "";
|
||||
if (blockSplit.length > 2) {
|
||||
for (int o = 2; o < blockSplit.length; o++) {
|
||||
linesStr += blockSplit[o];
|
||||
}
|
||||
String[] lines = linesStr.split(";;");
|
||||
|
||||
// Signs set
|
||||
// A sign post hanging on a wall south of here will
|
||||
if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) {
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
|
||||
} else {
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
BlockState state = worldBlock.getState();
|
||||
state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData));
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if (lines != null && sign.getLines() != null) {
|
||||
if (lines.length > 0) {
|
||||
sign.setLine(0, lines[0]);
|
||||
}
|
||||
if (lines.length > 1) {
|
||||
sign.setLine(1, lines[1]);
|
||||
}
|
||||
if (lines.length > 2) {
|
||||
sign.setLine(2, lines[2]);
|
||||
}
|
||||
if (lines.length > 3) {
|
||||
sign.setLine(3, lines[3]);
|
||||
}
|
||||
sign.update(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.CHEST.getId()) {
|
||||
// Chests read
|
||||
List<ItemStack> items = null;
|
||||
if (blockSplit.length > 2) {
|
||||
String itemsStr = blockSplit[2];
|
||||
items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr);
|
||||
}
|
||||
|
||||
// Chests set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof Chest) {
|
||||
Chest chest = (Chest) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
chest.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
chest.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
chest.update(true);
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.DISPENSER.getId()) {
|
||||
// Dispensers read
|
||||
List<ItemStack> items = null;
|
||||
if (blockSplit.length > 2) {
|
||||
String itemsStr = blockSplit[2];
|
||||
// String itemsStr = lineScanner.nextLine();
|
||||
items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr);
|
||||
}
|
||||
|
||||
// Dispensers set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof Dispenser) {
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
dispenser.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
dispenser.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
dispenser.update(true);
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) {
|
||||
// Door blocks
|
||||
|
||||
if (j - 1 > 0) {
|
||||
Block blockBelow = world.getBlockAt(x, y - 1, z);
|
||||
boolean belowIsGlass = blockBelow.getTypeId() == Material.GLASS.getId();
|
||||
// Set current block to glass if block below isn't glass.
|
||||
// Having a glass block below means the current block is a door top.
|
||||
if (belowIsGlass) {
|
||||
// Top door block. Set both it and the block below as door.
|
||||
blockBelow.setType(Material.getMaterial(diskBlockType));
|
||||
blockBelow.setData(diskBlockData);
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
} else {
|
||||
worldBlock.setType(Material.GLASS);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) {
|
||||
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
|
||||
// Change the block itself later on:
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
|
||||
} else {
|
||||
// regular block
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
}
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
visitedBlocks++;
|
||||
}
|
||||
blockReads++;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
War.war.getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
if (height129Fix && j == volume.getSizeY() - 1) {
|
||||
for (int skip = 0; skip < volume.getSizeZ(); skip++) {
|
||||
in.readLine(); // throw away the extra vertical block I used to save pre 0.8
|
||||
// scanner.nextLine();
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
if (!deferred.isEmpty()) {
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
// if (scanner != null)
|
||||
try {
|
||||
in.close();
|
||||
in = null;
|
||||
// scanner.close();
|
||||
// scanner = null;
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
|
||||
public static int save(Volume volume, String zoneName, War war) {
|
||||
int noOfSavedBlocks = 0;
|
||||
if (volume.hasTwoCorners()) {
|
||||
BufferedWriter out = null;
|
||||
try {
|
||||
(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
|
||||
if (zoneName.equals("")) {
|
||||
out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
|
||||
} else {
|
||||
out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
}
|
||||
|
||||
out.write("corner1");
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getX()));
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getY()));
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getZ()));
|
||||
out.newLine();
|
||||
out.write("corner2");
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerTwo().getX()));
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerTwo().getY()));
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerTwo().getZ()));
|
||||
out.newLine();
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
Block block;
|
||||
int typeId;
|
||||
byte data;
|
||||
BlockState state;
|
||||
|
||||
x = volume.getMinX();
|
||||
for (int i = 0; i < volume.getSizeX(); i++) {
|
||||
y = volume.getMinY();
|
||||
for (int j = 0; j < volume.getSizeY(); j++) {
|
||||
z = volume.getMinZ();
|
||||
for (int k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
block = volume.getWorld().getBlockAt(x, y, z);
|
||||
typeId = block.getTypeId();
|
||||
data = block.getData();
|
||||
state = block.getState();
|
||||
|
||||
out.write(typeId + "," + data + ",");
|
||||
|
||||
if (state instanceof Sign) {
|
||||
// Signs
|
||||
String extra = "";
|
||||
Sign sign = (Sign) state;
|
||||
if (sign.getLines() != null) {
|
||||
for (String line : sign.getLines()) {
|
||||
extra += line + ";;";
|
||||
}
|
||||
out.write(extra);
|
||||
}
|
||||
|
||||
} else if (state instanceof Chest) {
|
||||
// Chests
|
||||
Chest chest = (Chest) state;
|
||||
Inventory inv = chest.getInventory();
|
||||
int size = inv.getSize();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (int invIndex = 0; invIndex < size; invIndex++) {
|
||||
ItemStack item = inv.getItem(invIndex);
|
||||
if (item != null && item.getType().getId() != Material.AIR.getId()) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
String extra = "";
|
||||
if (items != null) {
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability();
|
||||
if (item.getData() != null) {
|
||||
extra += ";" + item.getData().getData();
|
||||
}
|
||||
extra += ";;";
|
||||
}
|
||||
}
|
||||
out.write(extra);
|
||||
}
|
||||
} else if (state instanceof Dispenser) {
|
||||
// Dispensers
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
Inventory inv = dispenser.getInventory();
|
||||
int size = inv.getSize();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (int invIndex = 0; invIndex < size; invIndex++) {
|
||||
ItemStack item = inv.getItem(invIndex);
|
||||
if (item != null && item.getType().getId() != Material.AIR.getId()) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
String extra = "";
|
||||
if (items != null) {
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability();
|
||||
if (item.getData() != null) {
|
||||
extra += ";" + item.getData().getData();
|
||||
}
|
||||
extra += ";;";
|
||||
}
|
||||
}
|
||||
out.write(extra);
|
||||
}
|
||||
}
|
||||
noOfSavedBlocks++;
|
||||
out.newLine();
|
||||
} catch (Exception e) {
|
||||
war.log("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return noOfSavedBlocks;
|
||||
}
|
||||
|
||||
}
|
@ -1,407 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Used for accessing and creating .[properties] files, reads them as utf-8, saves as utf-8. Internationalization is key importance especially for character codes.
|
||||
*
|
||||
* @author Nijikokun
|
||||
* @version 1.0.4, %G%
|
||||
*/
|
||||
public final class PropertiesFile {
|
||||
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
private String fileName;
|
||||
private Properties props = new Properties();
|
||||
private FileInputStream inputStream;
|
||||
private FileOutputStream outputStream;
|
||||
|
||||
// private List<String> lines = new ArrayList<String>();
|
||||
// private Map<String, String> props = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* Creates or opens a properties file using specified filename
|
||||
*
|
||||
* @param fileName
|
||||
*/
|
||||
public PropertiesFile(String fileName) {
|
||||
this.fileName = fileName;
|
||||
|
||||
File file = new File(fileName);
|
||||
|
||||
try {
|
||||
if (file.exists()) {
|
||||
this.load();
|
||||
} else {
|
||||
this.save();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
PropertiesFile.log.severe("[PropertiesFile] Unable to load " + fileName + "!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The loader for property files, it reads the file as UTF8 or converts the string into UTF8. Used for simple runthrough's, loading, or reloading of the file.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load() throws IOException {
|
||||
this.inputStream = new FileInputStream(this.fileName);
|
||||
this.props.load(this.inputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes out the <code>key=value</code> properties that were changed into a .[properties] file in UTF8.
|
||||
*/
|
||||
public void save() {
|
||||
try {
|
||||
this.outputStream = new FileOutputStream(this.fileName);
|
||||
this.props.store(this.outputStream, null);
|
||||
} catch (IOException ex) {
|
||||
PropertiesFile.log.severe("[PropertiesFile] Unable to save " + this.fileName + "!");
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (this.outputStream != null) {
|
||||
try {
|
||||
this.outputStream.close();
|
||||
} catch (IOException e) {
|
||||
PropertiesFile.log.severe("[PropertiesFile] Failed to close " + this.fileName + " writer!");
|
||||
}
|
||||
} else if (this.inputStream != null) {
|
||||
try {
|
||||
this.inputStream.close();
|
||||
} catch (IOException e) {
|
||||
PropertiesFile.log.severe("[PropertiesFile] Failed to close " + this.fileName + " reader!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Map of all <code>key=value</code> properties in the file as <code><key (java.lang.String), value (java.lang.String)></code> <br />
|
||||
* <br />
|
||||
* Example: <blockquote>
|
||||
*
|
||||
* <pre>
|
||||
* PropertiesFile settings = new PropertiesFile("settings.properties");
|
||||
* Map<String, String> mappedSettings;
|
||||
*
|
||||
* try {
|
||||
* mappedSettings = settings.returnMap();
|
||||
* } catch (Exception ex) {
|
||||
* log.info("Failed mapping settings.properties");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* </blockquote>
|
||||
*
|
||||
* @return <code>map</code> - Simple Map HashMap of the entire <code>key=value</code> as <code><key (java.lang.String), value (java.lang.String)></code>
|
||||
* @throws Exception
|
||||
* If the properties file doesn't exist.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, String> returnMap() throws Exception {
|
||||
return (Map<String, String>) this.props.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the .[properties] file contains the given <code>key</code>.
|
||||
*
|
||||
* @param var
|
||||
* The key we are going to be checking the existance of.
|
||||
* @return <code>Boolean</code> - True if the <code>key</code> exists, false if it cannot be found.
|
||||
*/
|
||||
public boolean containsKey(String var) {
|
||||
return this.props.containsKey(var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if this <code>key</code> exists in the .[properties] file.
|
||||
*
|
||||
* @param var
|
||||
* The key we are grabbing the value of.
|
||||
* @return <code>java.lang.String</code> - True if the <code>key</code> exists, false if it cannot be found.
|
||||
*/
|
||||
public String getProperty(String var) {
|
||||
return this.props.getProperty(var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a key from the file if it exists. This will save() which will invoke a load() on the file.
|
||||
*
|
||||
* @see #save()
|
||||
* @param var
|
||||
* The <code>key</code> that will be removed from the file
|
||||
*/
|
||||
public void removeKey(String var) {
|
||||
if (this.props.containsKey(var)) {
|
||||
this.props.remove(var);
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the existance of a <code>key</code>.
|
||||
*
|
||||
* @see #containsKey(java.lang.String)
|
||||
* @param key
|
||||
* The <code>key</code> in question of existance.
|
||||
* @return <code>Boolean</code> - True for existance, false for <code>key</code> found.
|
||||
*/
|
||||
public boolean keyExists(String key) {
|
||||
return this.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the <code>key</code> given as a <code>String</code>, however we do not set a string if no <code>key</code> is found.
|
||||
*
|
||||
* @see #getProperty(java.lang.String)
|
||||
* @param key
|
||||
* The <code>key</code> we will retrieve the property from, if no <code>key</code> is found default to "" or empty.
|
||||
*/
|
||||
public String getString(String key) {
|
||||
if (this.containsKey(key)) {
|
||||
return this.getProperty(key);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the <code>key</code> given as a <code>String</code>. If it is not found, it will invoke saving the default <code>value</code> to the properties file.
|
||||
*
|
||||
* @see #setString(java.lang.String, java.lang.String)
|
||||
* @see #getProperty(java.lang.String)
|
||||
* @param key
|
||||
* The key that we will be grabbing the value from, if no value is found set and return <code>value</code>
|
||||
* @param value
|
||||
* The default value that we will be setting if no prior <code>key</code> is found.
|
||||
* @return java.lang.String Either we will return the default value or a prior existing value depending on existance.
|
||||
*/
|
||||
public String getString(String key, String value) {
|
||||
if (this.containsKey(key)) {
|
||||
return this.getProperty(key);
|
||||
}
|
||||
|
||||
this.setString(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the value given as a <code>String</code> on the specified key.
|
||||
*
|
||||
* @see #save()
|
||||
* @param key
|
||||
* The <code>key</code> that we will be addressing the <code>value</code> to.
|
||||
* @param value
|
||||
* The <code>value</code> we will be setting inside the <code>.[properties]</code> file.
|
||||
*/
|
||||
public void setString(String key, String value) {
|
||||
this.props.put(key, value);
|
||||
this.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the <code>key</code> given in a Integer, however we do not set a string if no <code>key</code> is found.
|
||||
*
|
||||
* @see #getProperty(String var)
|
||||
* @param key
|
||||
* The <code>key</code> we will retrieve the property from, if no <code>key</code> is found default to 0
|
||||
*/
|
||||
public int getInt(String key) {
|
||||
if (this.containsKey(key)) {
|
||||
return Integer.parseInt(this.getProperty(key));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int value of a key
|
||||
*
|
||||
* @see #setInt(String key, int value)
|
||||
* @param key
|
||||
* The key that we will be grabbing the value from, if no value is found set and return <code>value</code>
|
||||
* @param value
|
||||
* The default value that we will be setting if no prior <code>key</code> is found.
|
||||
* @return <code>Integer</code> - Either we will return the default value or a prior existing value depending on existance.
|
||||
*/
|
||||
public int getInt(String key, int value) {
|
||||
if (this.containsKey(key)) {
|
||||
return Integer.parseInt(this.getProperty(key));
|
||||
}
|
||||
|
||||
this.setInt(key, value);
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the value given as a <code>int</code> on the specified key.
|
||||
*
|
||||
* @see #save()
|
||||
* @param key
|
||||
* The <code>key</code> that we will be addressing the <code>value</code> to.
|
||||
* @param value
|
||||
* The <code>value</code> we will be setting inside the <code>.[properties]</code> file.
|
||||
*/
|
||||
public void setInt(String key, int value) {
|
||||
this.props.put(key, String.valueOf(value));
|
||||
|
||||
this.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the <code>key</code> given in a Double, however we do not set a string if no <code>key</code> is found.
|
||||
*
|
||||
* @see #getProperty(String var)
|
||||
* @param key
|
||||
* The <code>key</code> we will retrieve the property from, if no <code>key</code> is found default to 0.0
|
||||
*/
|
||||
public double getDouble(String key) {
|
||||
if (this.containsKey(key)) {
|
||||
return Double.parseDouble(this.getProperty(key));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the double value of a key
|
||||
*
|
||||
* @see #setDouble(String key, double value)
|
||||
* @param key
|
||||
* The key that we will be grabbing the value from, if no value is found set and return <code>value</code>
|
||||
* @param value
|
||||
* The default value that we will be setting if no prior <code>key</code> is found.
|
||||
* @return <code>Double</code> - Either we will return the default value or a prior existing value depending on existance.
|
||||
*/
|
||||
public double getDouble(String key, double value) {
|
||||
if (this.containsKey(key)) {
|
||||
return Double.parseDouble(this.getProperty(key));
|
||||
}
|
||||
|
||||
this.setDouble(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the value given as a <code>double</code> on the specified key.
|
||||
*
|
||||
* @see #save()
|
||||
* @param key
|
||||
* The <code>key</code> that we will be addressing the <code>value</code> to.
|
||||
* @param value
|
||||
* The <code>value</code> we will be setting inside the <code>.[properties]</code> file.
|
||||
*/
|
||||
public void setDouble(String key, double value) {
|
||||
this.props.put(key, String.valueOf(value));
|
||||
|
||||
this.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the <code>key</code> given in a Long, however we do not set a string if no <code>key</code> is found.
|
||||
*
|
||||
* @see #getProperty(String var)
|
||||
* @param key
|
||||
* The <code>key</code> we will retrieve the property from, if no <code>key</code> is found default to 0L
|
||||
*/
|
||||
public long getLong(String key) {
|
||||
if (this.containsKey(key)) {
|
||||
return Long.parseLong(this.getProperty(key));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long value of a key
|
||||
*
|
||||
* @see #setLong(String key, long value)
|
||||
* @param key
|
||||
* The key that we will be grabbing the value from, if no value is found set and return <code>value</code>
|
||||
* @param value
|
||||
* The default value that we will be setting if no prior <code>key</code> is found.
|
||||
* @return <code>Long</code> - Either we will return the default value or a prior existing value depending on existance.
|
||||
*/
|
||||
public long getLong(String key, long value) {
|
||||
if (this.containsKey(key)) {
|
||||
return Long.parseLong(this.getProperty(key));
|
||||
}
|
||||
|
||||
this.setLong(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the value given as a <code>long</code> on the specified key.
|
||||
*
|
||||
* @see #save()
|
||||
* @param key
|
||||
* The <code>key</code> that we will be addressing the <code>value</code> to.
|
||||
* @param value
|
||||
* The <code>value</code> we will be setting inside the <code>.[properties]</code> file.
|
||||
*/
|
||||
public void setLong(String key, long value) {
|
||||
this.props.put(key, String.valueOf(value));
|
||||
|
||||
this.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the <code>key</code> given in a Boolean, however we do not set a string if no <code>key</code> is found.
|
||||
*
|
||||
* @see #getProperty(String var)
|
||||
* @param key
|
||||
* The <code>key</code> we will retrieve the property from, if no <code>key</code> is found default to false
|
||||
*/
|
||||
public boolean getBoolean(String key) {
|
||||
if (this.containsKey(key)) {
|
||||
return Boolean.parseBoolean(this.getProperty(key));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boolean value of a key
|
||||
*
|
||||
* @see #setBoolean(String key, boolean value)
|
||||
* @param key
|
||||
* The key that we will be grabbing the value from, if no value is found set and return <code>value</code>
|
||||
* @param value
|
||||
* The default value that we will be setting if no prior <code>key</code> is found.
|
||||
* @return <code>Boolean</code> - Either we will return the default value or a prior existing value depending on existance.
|
||||
*/
|
||||
public boolean getBoolean(String key, boolean value) {
|
||||
if (this.containsKey(key)) {
|
||||
return Boolean.parseBoolean(this.getProperty(key));
|
||||
}
|
||||
|
||||
this.setBoolean(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the value given as a <code>boolean</code> on the specified key.
|
||||
*
|
||||
* @see #save()
|
||||
* @param key
|
||||
* The <code>key</code> that we will be addressing the <code>value</code> to.
|
||||
* @param value
|
||||
* The <code>value</code> we will be setting inside the <code>.[properties]</code> file.
|
||||
*/
|
||||
public void setBoolean(String key, boolean value) {
|
||||
this.props.put(key, String.valueOf(value));
|
||||
|
||||
this.save();
|
||||
}
|
||||
}
|
@ -1,333 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class VolumeMapper {
|
||||
|
||||
public static Volume loadVolume(String volumeName, String zoneName, World world) {
|
||||
Volume volume = new Volume(volumeName, world);
|
||||
VolumeMapper.load(volume, zoneName, world);
|
||||
return volume;
|
||||
}
|
||||
|
||||
public static void load(Volume volume, String zoneName, World world) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
if (zoneName.equals("")) {
|
||||
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
|
||||
} else {
|
||||
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
}
|
||||
String firstLine = in.readLine();
|
||||
if (firstLine != null && !firstLine.equals("")) {
|
||||
boolean height129Fix = false;
|
||||
int x1 = Integer.parseInt(in.readLine());
|
||||
int y1 = Integer.parseInt(in.readLine());
|
||||
if (y1 == 128) {
|
||||
height129Fix = true;
|
||||
y1 = 127;
|
||||
}
|
||||
int z1 = Integer.parseInt(in.readLine());
|
||||
in.readLine();
|
||||
int x2 = Integer.parseInt(in.readLine());
|
||||
int y2 = Integer.parseInt(in.readLine());
|
||||
if (y2 == 128) {
|
||||
height129Fix = true;
|
||||
y2 = 127;
|
||||
}
|
||||
int z2 = Integer.parseInt(in.readLine());
|
||||
|
||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
volume.setBlockTypes(new int[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
|
||||
volume.setBlockDatas(new byte[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
|
||||
int blockReads = 0;
|
||||
for (int i = 0; i < volume.getSizeX(); i++) {
|
||||
for (int j = 0; j < volume.getSizeY(); j++) {
|
||||
for (int k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
String blockLine = in.readLine();
|
||||
if (blockLine != null && !blockLine.equals("")) {
|
||||
String[] blockSplit = blockLine.split(",");
|
||||
if (blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
|
||||
int typeID = Integer.parseInt(blockSplit[0]);
|
||||
byte data = Byte.parseByte(blockSplit[1]);
|
||||
|
||||
volume.getBlockTypes()[i][j][k] = typeID;
|
||||
volume.getBlockDatas()[i][j][k] = data;
|
||||
|
||||
if (typeID == Material.WALL_SIGN.getId() || typeID == Material.SIGN_POST.getId()) {
|
||||
// Signs
|
||||
String linesStr = "";
|
||||
if (blockSplit.length > 2) {
|
||||
for (int o = 2; o < blockSplit.length; o++) {
|
||||
linesStr += blockSplit[o];
|
||||
}
|
||||
String[] lines = linesStr.split(";;");
|
||||
volume.getSignLines().put("sign-" + i + "-" + j + "-" + k, lines);
|
||||
}
|
||||
} else if (typeID == Material.CHEST.getId()) {
|
||||
// Chests
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
if (blockSplit.length > 2) {
|
||||
items = readInventoryString(blockSplit[2]);
|
||||
}
|
||||
volume.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items);
|
||||
} else if (typeID == Material.DISPENSER.getId()) {
|
||||
// Dispensers
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
if (blockSplit.length > 2) {
|
||||
items = readInventoryString(blockSplit[2]);
|
||||
}
|
||||
volume.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items);
|
||||
}
|
||||
}
|
||||
blockReads++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (height129Fix && j == volume.getSizeY() - 1) {
|
||||
for (int skip = 0; skip < volume.getSizeZ(); skip++) {
|
||||
in.readLine(); // throw away the extra vertical block I used to save pre 0.8
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(Volume volume, String zoneName) {
|
||||
if (volume.hasTwoCorners()) {
|
||||
BufferedWriter out = null;
|
||||
try {
|
||||
if (zoneName.equals("")) {
|
||||
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
|
||||
} else {
|
||||
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
}
|
||||
|
||||
out.write("corner1");
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getX()));
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getY()));
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerOne().getZ()));
|
||||
out.newLine();
|
||||
out.write("corner2");
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerTwo().getX()));
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerTwo().getY()));
|
||||
out.newLine();
|
||||
out.write(Integer.toString(volume.getCornerTwo().getZ()));
|
||||
out.newLine();
|
||||
int blockWrites = 0;
|
||||
for (int i = 0; i < volume.getSizeX(); i++) {
|
||||
for (int j = 0; j < volume.getSizeY(); j++) {
|
||||
for (int k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
int typeId = volume.getBlockTypes()[i][j][k];
|
||||
byte data = volume.getBlockDatas()[i][j][k];
|
||||
out.write(typeId + "," + data + ",");
|
||||
if (typeId == Material.WALL_SIGN.getId() || typeId == Material.SIGN_POST.getId()) {
|
||||
// Signs
|
||||
String extra = "";
|
||||
String[] lines = volume.getSignLines().get("sign-" + i + "-" + j + "-" + k);
|
||||
if (lines != null) {
|
||||
for (String line : lines) {
|
||||
extra += line + ";;";
|
||||
}
|
||||
out.write(extra);
|
||||
}
|
||||
} else if (typeId == Material.CHEST.getId()) {
|
||||
// Chests
|
||||
String extra = "";
|
||||
List<ItemStack> contents = volume.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k);
|
||||
if (contents != null) {
|
||||
out.write(buildInventoryStringFromItemList(contents));
|
||||
out.write(extra);
|
||||
}
|
||||
} else if (typeId == Material.DISPENSER.getId()) {
|
||||
// Dispensers
|
||||
List<ItemStack> contents = volume.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k);
|
||||
if (contents != null) {
|
||||
out.write(buildInventoryStringFromItemList(contents));
|
||||
}
|
||||
}
|
||||
out.newLine();
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error while writing block into volume " + volume.getName() + " file for zone " + zoneName + ". Blocks written so far: " + blockWrites + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an inventory string
|
||||
*
|
||||
* @param String
|
||||
* invString string to parse
|
||||
* @return List<ItemStack> Parsed items
|
||||
*/
|
||||
public static List<ItemStack> readInventoryString(String invString) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
if (invString != null && !invString.equals("")) {
|
||||
String[] itemsStrSplit = invString.split(";;");
|
||||
for (String itemStr : itemsStrSplit) {
|
||||
String[] itemStrSplit = itemStr.split(";");
|
||||
if (itemStrSplit.length == 5) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
|
||||
// enchantments
|
||||
String[] enchantmentsSplit = itemStrSplit[4].split("::");
|
||||
for (String enchantmentStr : enchantmentsSplit) {
|
||||
if (!enchantmentStr.equals("")) {
|
||||
String[] enchantmentSplit = enchantmentStr.split(":");
|
||||
int enchantId = Integer.parseInt(enchantmentSplit[0]);
|
||||
int level = Integer.parseInt(enchantmentSplit[1]);
|
||||
stack.addEnchantment(Enchantment.getById(enchantId), level);
|
||||
}
|
||||
}
|
||||
|
||||
items.add(stack);
|
||||
} else if (itemStrSplit.length == 4) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
items.add(stack);
|
||||
} else if (itemStrSplit.length == 3) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
items.add(stack);
|
||||
} else {
|
||||
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string out of a list of items
|
||||
*
|
||||
* @param items The list of items
|
||||
* @return The list as a string
|
||||
*/
|
||||
public static String buildInventoryStringFromItemList(List<ItemStack> items) {
|
||||
String extra = "";
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability();
|
||||
if (item.getData() != null) {
|
||||
extra += ";" + item.getData().getData();
|
||||
}
|
||||
if (item.getEnchantments().keySet().size() > 0) {
|
||||
String enchantmentsStr = "";
|
||||
for (Enchantment enchantment : item.getEnchantments().keySet()) {
|
||||
enchantmentsStr += enchantment.getId() + ":" + item.getEnchantments().get(enchantment) + "::";
|
||||
}
|
||||
extra += ";" + enchantmentsStr;
|
||||
}
|
||||
extra += ";;";
|
||||
}
|
||||
}
|
||||
|
||||
return extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a list of items from and inventory
|
||||
*
|
||||
* @param inv The inventory
|
||||
* @return The inventory as a list
|
||||
*/
|
||||
public static List<ItemStack> getItemListFromInv(Inventory inv) {
|
||||
int size = inv.getSize();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (int invIndex = 0; invIndex < size; invIndex++) {
|
||||
ItemStack item = inv.getItem(invIndex);
|
||||
if (item != null && item.getType().getId() != Material.AIR.getId()) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public static void delete(Volume volume) {
|
||||
File volFile = new File("War/dat/volume-" + volume.getName());
|
||||
boolean deletedData = volFile.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,459 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.TeamSpawnStyle;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.jobs.RestoreWarhubJob;
|
||||
import com.tommytony.war.jobs.RestoreWarzonesJob;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarTxtMapper {
|
||||
|
||||
public static void load() {
|
||||
load(false);
|
||||
}
|
||||
|
||||
public static void load(boolean convertingToYml) {
|
||||
(War.war.getDataFolder()).mkdir();
|
||||
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();
|
||||
PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt");
|
||||
try {
|
||||
warConfig.load();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to load war.txt file.", Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Create file if need be
|
||||
boolean newWar = false;
|
||||
if (!warConfig.containsKey("warzones")) {
|
||||
newWar = true;
|
||||
WarTxtMapper.save();
|
||||
War.war.log("war.txt settings file created.", Level.INFO);
|
||||
try {
|
||||
warConfig.load();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to reload war.txt file after creating it.", Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// warzones
|
||||
String warzonesStr = warConfig.getString("warzones");
|
||||
RestoreWarzonesJob restoreWarzones = new RestoreWarzonesJob(warzonesStr, newWar, convertingToYml);
|
||||
// make sure warhub job is over before this one ends, because this job will launch conversion (which needs the warhub)
|
||||
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarzones, 20) == -1) {
|
||||
War.war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING);
|
||||
}
|
||||
|
||||
// zone makers
|
||||
String[] makers = warConfig.getString("zoneMakers").split(",");
|
||||
War.war.getZoneMakerNames().clear();
|
||||
for (String makerName : makers) {
|
||||
if (makerName != null && !makerName.equals("")) {
|
||||
War.war.getZoneMakerNames().add(makerName);
|
||||
}
|
||||
}
|
||||
|
||||
// command whitelist
|
||||
String[] whitelist = warConfig.getString("commandWhitelist").split(",");
|
||||
War.war.getCommandWhitelist().clear();
|
||||
for (String command : whitelist) {
|
||||
if (command != null && !command.equals("")) {
|
||||
War.war.getCommandWhitelist().add(command);
|
||||
}
|
||||
}
|
||||
|
||||
// defaultLoadout
|
||||
War.war.getDefaultInventories().getLoadouts().clear();
|
||||
|
||||
String loadoutStr = warConfig.getString("defaultLoadout");
|
||||
if (loadoutStr != null && !loadoutStr.equals("")) {
|
||||
War.war.getDefaultInventories().addLoadout("default", new HashMap<Integer, ItemStack>());
|
||||
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, War.war.getDefaultInventories().getLoadouts().get("default"));
|
||||
}
|
||||
|
||||
// defaultExtraLoadouts
|
||||
String extraLoadoutStr = warConfig.getString("defaultExtraLoadouts");
|
||||
String[] extraLoadoutsSplit = extraLoadoutStr.split(",");
|
||||
|
||||
for (String nameStr : extraLoadoutsSplit) {
|
||||
if (nameStr != null && !nameStr.equals("")) {
|
||||
War.war.getDefaultInventories().addLoadout(nameStr, new HashMap<Integer, ItemStack>());
|
||||
}
|
||||
}
|
||||
|
||||
for (String extraName : extraLoadoutsSplit) {
|
||||
if (extraName != null && !extraName.equals("")) {
|
||||
String loadoutString = warConfig.getString(extraName + "Loadout");
|
||||
HashMap<Integer, ItemStack> loadout = War.war.getDefaultInventories().getLoadouts().get(extraName);
|
||||
LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout);
|
||||
}
|
||||
}
|
||||
|
||||
// maxZones
|
||||
if (warConfig.keyExists("maxZones")) {
|
||||
War.war.getWarConfig().put(WarConfig.MAXZONES, warConfig.getInt("maxZones"));
|
||||
}
|
||||
|
||||
// defaultLifePool
|
||||
if (warConfig.keyExists("defaultLifePool")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.LIFEPOOL, warConfig.getInt("defaultLifePool"));
|
||||
}
|
||||
|
||||
// defaultMonumentHeal
|
||||
if (warConfig.keyExists("defaultMonumentHeal")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MONUMENTHEAL, warConfig.getInt("defaultMonumentHeal"));
|
||||
}
|
||||
|
||||
// defaultFriendlyFire
|
||||
if (warConfig.keyExists("defaultFriendlyFire")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.FRIENDLYFIRE, warConfig.getBoolean("defaultFriendlyFire"));
|
||||
}
|
||||
|
||||
// defaultAutoAssignOnly
|
||||
if (warConfig.keyExists("defaultAutoAssignOnly")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.AUTOASSIGN, warConfig.getBoolean("defaultAutoAssignOnly"));
|
||||
}
|
||||
|
||||
// defaultFlagPointsOnly
|
||||
if (warConfig.keyExists("defaultFlagPointsOnly")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGPOINTSONLY, warConfig.getBoolean("defaultFlagPointsOnly"));
|
||||
}
|
||||
|
||||
// defaultFlagMustBeHome
|
||||
if (warConfig.keyExists("defaultFlagMustBeHome")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGMUSTBEHOME, warConfig.getBoolean("defaultFlagMustBeHome"));
|
||||
}
|
||||
|
||||
// defaultTeamCap
|
||||
if (warConfig.keyExists("defaultTeamCap")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.TEAMSIZE, warConfig.getInt("defaultTeamCap"));
|
||||
}
|
||||
|
||||
// defaultScoreCap
|
||||
if (warConfig.keyExists("defaultScoreCap")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.MAXSCORE, warConfig.getInt("defaultScoreCap"));
|
||||
}
|
||||
|
||||
// defaultRespawnTimer
|
||||
if (warConfig.keyExists("defaultRespawnTimer")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.RESPAWNTIMER, warConfig.getInt("defaultRespawnTimer"));
|
||||
}
|
||||
|
||||
// pvpInZonesOnly
|
||||
if (warConfig.keyExists("pvpInZonesOnly")) {
|
||||
War.war.getWarConfig().put(WarConfig.PVPINZONESONLY, warConfig.getBoolean("pvpInZonesOnly"));
|
||||
}
|
||||
|
||||
// defaultBlockHeads
|
||||
if (warConfig.keyExists("defaultBlockHeads")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.BLOCKHEADS, warConfig.getBoolean("defaultBlockHeads"));
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
if (warConfig.keyExists("buildInZonesOnly")) {
|
||||
War.war.getWarConfig().put(WarConfig.BUILDINZONESONLY, warConfig.getBoolean("buildInZonesOnly"));
|
||||
}
|
||||
|
||||
// disablePVPMessage
|
||||
if (warConfig.keyExists("disablePvpMessage")) {
|
||||
War.war.getWarConfig().put(WarConfig.DISABLEPVPMESSAGE, warConfig.getBoolean("disablePvpMessage"));
|
||||
}
|
||||
|
||||
// disableBuildMessage
|
||||
if (warConfig.keyExists("disableBuildMessage")) {
|
||||
War.war.getWarConfig().put(WarConfig.DISABLEBUILDMESSAGE, warConfig.getBoolean("disableBuildMessage"));
|
||||
}
|
||||
|
||||
// tntInZonesOnly
|
||||
if (warConfig.keyExists("tntInZonesOnly")) {
|
||||
War.war.getWarConfig().put(WarConfig.TNTINZONESONLY, warConfig.getBoolean("tntInZonesOnly"));
|
||||
}
|
||||
|
||||
// defaultSpawnStyle
|
||||
String spawnStyle = warConfig.getString("defaultspawnStyle");
|
||||
if (spawnStyle != null && !spawnStyle.equals("")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.getStyleFromString(spawnStyle));
|
||||
}
|
||||
|
||||
// defaultFlagReturn
|
||||
String flagReturn = warConfig.getString("defaultFlagReturn");
|
||||
if (flagReturn != null && !flagReturn.equals("")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGRETURN, FlagReturn.getFromString(flagReturn));
|
||||
}
|
||||
|
||||
// defaultReward
|
||||
String defaultRewardStr = warConfig.getString("defaultReward");
|
||||
if (defaultRewardStr != null && !defaultRewardStr.equals("")) {
|
||||
LoadoutTxtMapper.fromStringToLoadout(defaultRewardStr, War.war.getDefaultInventories().getReward());
|
||||
}
|
||||
|
||||
// defaultUnbreakableZoneBlocks
|
||||
if (warConfig.keyExists("defaultUnbreakableZoneBlocks")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.UNBREAKABLE, warConfig.getBoolean("defaultUnbreakableZoneBlocks"));
|
||||
}
|
||||
|
||||
// defaultNoCreatures
|
||||
if (warConfig.keyExists("defaultNoCreatures")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.NOCREATURES, warConfig.getBoolean("defaultNoCreatures"));
|
||||
}
|
||||
|
||||
// defaultGlassWalls
|
||||
if (warConfig.keyExists("defaultGlassWalls")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.GLASSWALLS, warConfig.getBoolean("defaultGlassWalls"));
|
||||
}
|
||||
|
||||
// defaultPvpInZone
|
||||
if (warConfig.keyExists("defaultPvpInZone")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.PVPINZONE, warConfig.getBoolean("defaultPvpInZone"));
|
||||
}
|
||||
|
||||
// defaultInstaBreak
|
||||
if (warConfig.keyExists("defaultInstaBreak")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.INSTABREAK, warConfig.getBoolean("defaultInstaBreak"));
|
||||
}
|
||||
|
||||
// defaultNoDrops
|
||||
if (warConfig.keyExists("defaultNoDrops")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.NODROPS, warConfig.getBoolean("defaultNoDrops"));
|
||||
}
|
||||
|
||||
// defaultNoHunger
|
||||
if (warConfig.keyExists("defaultNoHunger")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.NOHUNGER, warConfig.getBoolean("defaultNoHunger"));
|
||||
}
|
||||
|
||||
// defaultSaturation
|
||||
if (warConfig.keyExists("defaultSaturation")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.SATURATION, warConfig.getInt("defaultSaturation"));
|
||||
}
|
||||
|
||||
// defaultMinPlayers
|
||||
if (warConfig.keyExists("defaultMinPlayers")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MINPLAYERS, warConfig.getInt("defaultMinPlayers"));
|
||||
}
|
||||
|
||||
// defaultMinTeams
|
||||
if (warConfig.keyExists("defaultMinTeams")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MINTEAMS, warConfig.getInt("defaultMinTeams"));
|
||||
}
|
||||
|
||||
// defaultResetOnEmpty
|
||||
if (warConfig.keyExists("defaultResetOnEmpty")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONEMPTY, warConfig.getBoolean("defaultResetOnEmpty"));
|
||||
}
|
||||
|
||||
// defaultResetOnLoad
|
||||
if (warConfig.keyExists("defaultResetOnLoad")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONLOAD, warConfig.getBoolean("defaultResetOnLoad"));
|
||||
}
|
||||
|
||||
// defaultResetOnUnload
|
||||
if (warConfig.keyExists("defaultResetOnUnload")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONUNLOAD, warConfig.getBoolean("defaultResetOnUnload"));
|
||||
}
|
||||
|
||||
// warhub
|
||||
String hubStr = warConfig.getString("warhub");
|
||||
if (hubStr != null && !hubStr.equals("")) {
|
||||
RestoreWarhubJob restoreWarhub = new RestoreWarhubJob(hubStr);
|
||||
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarhub) == -1) {
|
||||
War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
warConfig.close();
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
// PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt");
|
||||
// String warzonesStr = "";
|
||||
|
||||
War.war.log("Saving War with WarTxtMapper", Level.SEVERE);
|
||||
|
||||
// // warzones
|
||||
// for (Warzone zone : War.war.getWarzones()) {
|
||||
// warzonesStr += zone.getName() + ",";
|
||||
// }
|
||||
// warConfig.setString("warzones", warzonesStr);
|
||||
//
|
||||
// // zone makers: default is none and it means everyone can use /setzone
|
||||
// String makersStr = ""; // everyone
|
||||
// for (String name : War.war.getZoneMakerNames()) {
|
||||
// makersStr += name + ",";
|
||||
// }
|
||||
// warConfig.setString("zoneMakers", makersStr);
|
||||
//
|
||||
// // whitelisted commands during a game
|
||||
// String commandWhitelistStr = ""; // everyone
|
||||
// for (String command : War.war.getCommandWhitelist()) {
|
||||
// commandWhitelistStr += command + ",";
|
||||
// }
|
||||
// warConfig.setString("commandWhitelist", commandWhitelistStr);
|
||||
//
|
||||
// // defaultLoadout
|
||||
// HashMap<Integer, ItemStack> items = War.war.getDefaultInventories().getLoadouts().get("default");
|
||||
// warConfig.setString("defaultLoadout", LoadoutTxtMapper.fromLoadoutToString(items));
|
||||
//
|
||||
// // defaultExtraLoadouts
|
||||
// String extraLoadoutsStr = "";
|
||||
// for (String name : War.war.getDefaultInventories().getLoadouts().keySet()) {
|
||||
// if (!name.equals("default")) {
|
||||
// extraLoadoutsStr += name + ",";
|
||||
//
|
||||
// HashMap<Integer, ItemStack> loadout = War.war.getDefaultInventories().getLoadouts().get(name);
|
||||
// warConfig.setString(name + "Loadout", LoadoutTxtMapper.fromLoadoutToString(loadout));
|
||||
// }
|
||||
// }
|
||||
// warConfig.setString("defaultExtraLoadouts", extraLoadoutsStr);
|
||||
//
|
||||
// // maxZones
|
||||
// warConfig.setInt("maxZones", War.war.getWarConfig().getInt(WarConfig.MAXZONES));
|
||||
//
|
||||
// // defaultLifepool
|
||||
// warConfig.setInt("defaultLifePool", War.war.getDefaultLifepool());
|
||||
//
|
||||
// // defaultMonumentHeal
|
||||
// warConfig.setInt("defaultMonumentHeal", War.war.getDefaultMonumentHeal());
|
||||
//
|
||||
// // defaultFriendlyFire
|
||||
// warConfig.setBoolean("defaultFriendlyFire", War.war.isDefaultFriendlyFire());
|
||||
//
|
||||
// // defaultAutoAssignOnly
|
||||
// warConfig.setBoolean("defaultAutoAssignOnly", War.war.isDefaultAutoAssignOnly());
|
||||
//
|
||||
// // defaultFlagPointsOnly
|
||||
// warConfig.setBoolean("defaultFlagPointsOnly", War.war.isDefaultFlagPointsOnly());
|
||||
//
|
||||
// // defaultFlagMustBeHome
|
||||
// warConfig.setBoolean("defaultFlagMustBeHome", War.war.isDefaultFlagMustBeHome());
|
||||
//
|
||||
// // defaultTeamCap
|
||||
// warConfig.setInt("defaultTeamCap", War.war.getDefaultTeamCap());
|
||||
//
|
||||
// // defaultScoreCap
|
||||
// warConfig.setInt("defaultScoreCap", War.war.getDefaultScoreCap());
|
||||
//
|
||||
// // defaultRespawnTimer
|
||||
// warConfig.setInt("defaultRespawnTimer", War.war.getDefaultRespawnTimer());
|
||||
//
|
||||
// // pvpInZonesOnly
|
||||
// warConfig.setBoolean("pvpInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.PVPINZONESONLY));
|
||||
//
|
||||
// // defaultBlockHeads
|
||||
// warConfig.setBoolean("defaultBlockHeads", War.war.isDefaultBlockHeads());
|
||||
//
|
||||
// // buildInZonesOnly
|
||||
// warConfig.setBoolean("buildInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY));
|
||||
//
|
||||
// // disablePVPMessage
|
||||
// warConfig.setBoolean("disablePvpMessage", War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE));
|
||||
//
|
||||
// // disableBuildMessage
|
||||
// warConfig.setBoolean("disableBuildMessage", War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE));
|
||||
//
|
||||
// // tntInZonesOnly
|
||||
// warConfig.setBoolean("tntInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.TNTINZONESONLY));
|
||||
//
|
||||
// // spawnStyle
|
||||
// warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle().toString());
|
||||
//
|
||||
// // flagReturn
|
||||
// warConfig.setString("flagReturn", War.war.getDefaultFlagReturn().toString());
|
||||
//
|
||||
// // defaultReward
|
||||
// String defaultRewardStr = "";
|
||||
// HashMap<Integer, ItemStack> rewardItems = War.war.getDefaultInventories().getReward();
|
||||
// for (Integer slot : rewardItems.keySet()) {
|
||||
// ItemStack item = items.get(slot);
|
||||
// if (item != null) {
|
||||
// defaultRewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
|
||||
// }
|
||||
// }
|
||||
// warConfig.setString("defaultReward", defaultRewardStr);
|
||||
//
|
||||
// // defaultUnbreakableZoneBlocks
|
||||
// warConfig.setBoolean("defaultUnbreakableZoneBlocks", War.war.isDefaultUnbreakableZoneBlocks());
|
||||
//
|
||||
// // defaultNoCreatures
|
||||
// warConfig.setBoolean("defaultNoCreatures", War.war.isDefaultNoCreatures());
|
||||
//
|
||||
// // defaultGlassWalls
|
||||
// warConfig.setBoolean("defaultGlassWalls", War.war.isDefaultGlassWalls());
|
||||
//
|
||||
// // defaultPvpInZone
|
||||
// warConfig.setBoolean("defaultPvpInZone", War.war.isDefaultPvpInZone());
|
||||
//
|
||||
// // defaultInstaBreak
|
||||
// warConfig.setBoolean("defaultInstaBreak", War.war.isDefaultInstaBreak());
|
||||
//
|
||||
// // defaultNoDrops
|
||||
// warConfig.setBoolean("defaultNoDrops", War.war.isDefaultNoDrops());
|
||||
//
|
||||
// // defaultNoHunger
|
||||
// warConfig.setBoolean("defaultNoHunger", War.war.isDefaultNoHunger());
|
||||
//
|
||||
// // defaultSaturation
|
||||
// warConfig.setInt("defaultSaturation", War.war.getDefaultSaturation());
|
||||
//
|
||||
// // defaultMinPlayers
|
||||
// warConfig.setInt("defaultMinPlayers", War.war.getDefaultMinPlayers());
|
||||
//
|
||||
// // defaultMinTeams
|
||||
// warConfig.setInt("defaultMinTeams", War.war.getDefaultMinTeams());
|
||||
//
|
||||
// // defaultResetOnEmpty
|
||||
// warConfig.setBoolean("defaultResetOnEmpty", War.war.isDefaultResetOnEmpty());
|
||||
//
|
||||
// // defaultResetOnLoad
|
||||
// warConfig.setBoolean("defaultResetOnLoad", War.war.isDefaultResetOnLoad());
|
||||
//
|
||||
// // defaultResetOnUnload
|
||||
// warConfig.setBoolean("defaultResetOnUnload", War.war.isDefaultResetOnUnload());
|
||||
//
|
||||
// // warhub
|
||||
// String hubStr = "";
|
||||
// WarHub hub = War.war.getWarHub();
|
||||
// if (hub != null) {
|
||||
// String orientationStr = "";
|
||||
// switch (hub.getOrientation()) {
|
||||
// case SOUTH:
|
||||
// orientationStr = "south";
|
||||
// break;
|
||||
// case EAST:
|
||||
// orientationStr = "east";
|
||||
// break;
|
||||
// case NORTH:
|
||||
// orientationStr = "north";
|
||||
// break;
|
||||
// case WEST:
|
||||
// default:
|
||||
// orientationStr = "west";
|
||||
// break;
|
||||
// }
|
||||
// hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + ","
|
||||
// + hub.getLocation().getWorld().getName() + "," + orientationStr;
|
||||
// VolumeMapper.save(hub.getVolume(), "");
|
||||
// }
|
||||
// warConfig.setString("warhub", hubStr);
|
||||
//
|
||||
// warConfig.save();
|
||||
// warConfig.close();
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.WarHub;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.jobs.RestoreYmlWarhubJob;
|
||||
import com.tommytony.war.jobs.RestoreYmlWarzonesJob;
|
||||
|
||||
public class WarYmlMapper {
|
||||
|
||||
public static void load() {
|
||||
(War.war.getDataFolder()).mkdir();
|
||||
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();
|
||||
File warTxtFile = new File(War.war.getDataFolder().getPath() + "/war.txt");
|
||||
File warYmlFile = new File(War.war.getDataFolder().getPath() + "/war.yml");
|
||||
|
||||
boolean newWar = false;
|
||||
if (warTxtFile.exists() && !warYmlFile.exists()) {
|
||||
// Load both War and warzones (with delay) in old format, save War to new format immediatly
|
||||
WarTxtMapper.load(true);
|
||||
// Warzones are getting loaded by TxtMapper launched job. That job will in turn save the Warzones to their new format.
|
||||
return;
|
||||
} else if (!warTxtFile.exists() && !warYmlFile.exists()) {
|
||||
// Save defaults to disk
|
||||
newWar = true;
|
||||
WarYmlMapper.save();
|
||||
War.war.log("war.yml settings file created.", Level.INFO);
|
||||
}
|
||||
|
||||
YamlConfiguration warYmlConfig = YamlConfiguration.loadConfiguration(warYmlFile);
|
||||
ConfigurationSection warRootSection = warYmlConfig.getConfigurationSection("set");
|
||||
|
||||
// warzones
|
||||
List<String> warzones = warRootSection.getStringList("war.info.warzones");
|
||||
RestoreYmlWarzonesJob restoreWarzones = new RestoreYmlWarzonesJob(warzones, newWar); // during conversion, this should execute just after the RestoreTxtWarzonesJob
|
||||
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarzones) == -1) {
|
||||
War.war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING);
|
||||
}
|
||||
|
||||
// zone makers
|
||||
List<String> makers = warRootSection.getStringList("war.info.zonemakers");
|
||||
War.war.getZoneMakerNames().clear();
|
||||
for (String makerName : makers) {
|
||||
if (makerName != null && !makerName.equals("")) {
|
||||
War.war.getZoneMakerNames().add(makerName);
|
||||
}
|
||||
}
|
||||
|
||||
// command whitelist
|
||||
List<String> whitelist = warRootSection.getStringList("war.info.commandwhitelist");
|
||||
War.war.getCommandWhitelist().clear();
|
||||
for (String command : whitelist) {
|
||||
if (command != null && !command.equals("")) {
|
||||
War.war.getCommandWhitelist().add(command);
|
||||
}
|
||||
}
|
||||
|
||||
// defaultLoadouts
|
||||
ConfigurationSection loadoutsSection = warRootSection.getConfigurationSection("team.default.loadout");
|
||||
LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, War.war.getDefaultInventories().getLoadouts());
|
||||
|
||||
// defaultReward
|
||||
ConfigurationSection rewardsSection = warRootSection.getConfigurationSection("team.default.reward");
|
||||
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
|
||||
War.war.getDefaultInventories().setReward(reward);
|
||||
|
||||
// War settings
|
||||
ConfigurationSection warConfigSection = warRootSection.getConfigurationSection("war.config");
|
||||
War.war.getWarConfig().loadFrom(warConfigSection);
|
||||
|
||||
// Warzone default settings
|
||||
ConfigurationSection warzoneConfigSection = warRootSection.getConfigurationSection("warzone.default.config");
|
||||
War.war.getWarzoneDefaultConfig().loadFrom(warzoneConfigSection);
|
||||
|
||||
// Team default settings
|
||||
ConfigurationSection teamConfigSection = warRootSection.getConfigurationSection("team.default.config");
|
||||
War.war.getTeamDefaultConfig().loadFrom(teamConfigSection);
|
||||
|
||||
// warhub
|
||||
ConfigurationSection hubConfigSection = warRootSection.getConfigurationSection("war.info.warhub");
|
||||
if (hubConfigSection != null) {
|
||||
RestoreYmlWarhubJob restoreWarhub = new RestoreYmlWarhubJob(hubConfigSection);
|
||||
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarhub) == -1) {
|
||||
War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
YamlConfiguration warYmlConfig = new YamlConfiguration();
|
||||
ConfigurationSection warRootSection = warYmlConfig.createSection("set");
|
||||
(new File(War.war.getDataFolder().getPath())).mkdir();
|
||||
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();
|
||||
|
||||
// War settings
|
||||
ConfigurationSection warConfigSection = warRootSection.createSection("war.config");
|
||||
War.war.getWarConfig().saveTo(warConfigSection);
|
||||
|
||||
// Warzone default settings
|
||||
ConfigurationSection warzoneConfigSection = warRootSection.createSection("warzone.default.config");
|
||||
War.war.getWarzoneDefaultConfig().saveTo(warzoneConfigSection);
|
||||
|
||||
// Team default settings
|
||||
ConfigurationSection teamDefault = warRootSection.createSection("team.default");
|
||||
ConfigurationSection teamConfigSection = teamDefault.createSection("config");
|
||||
War.war.getTeamDefaultConfig().saveTo(teamConfigSection);
|
||||
|
||||
// defaultLoadouts
|
||||
ConfigurationSection loadoutSection = teamDefault.createSection("loadout");
|
||||
LoadoutYmlMapper.fromLoadoutsToConfig(War.war.getDefaultInventories().getLoadouts(), loadoutSection);
|
||||
|
||||
// defaultReward
|
||||
ConfigurationSection rewardsSection = teamDefault.createSection("reward");
|
||||
LoadoutYmlMapper.fromLoadoutToConfig("default", War.war.getDefaultInventories().getReward(), rewardsSection);
|
||||
|
||||
ConfigurationSection warInfoSection = warRootSection.createSection("war.info");
|
||||
|
||||
// warzones
|
||||
List<String> warzones = new ArrayList<String>();
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
warzones.add(zone.getName());
|
||||
}
|
||||
warInfoSection.set("warzones", warzones);
|
||||
|
||||
// zone makers
|
||||
warInfoSection.set("zonemakers", War.war.getZoneMakerNames());
|
||||
|
||||
// whitelisted commands during a game
|
||||
warInfoSection.set("commandwhitelist", War.war.getCommandWhitelist());
|
||||
|
||||
// warhub
|
||||
WarHub hub = War.war.getWarHub();
|
||||
if (hub != null) {
|
||||
String orientationStr = "";
|
||||
switch (hub.getOrientation()) {
|
||||
case SOUTH:
|
||||
orientationStr = "south";
|
||||
break;
|
||||
case EAST:
|
||||
orientationStr = "east";
|
||||
break;
|
||||
case NORTH:
|
||||
orientationStr = "north";
|
||||
break;
|
||||
case WEST:
|
||||
default:
|
||||
orientationStr = "west";
|
||||
break;
|
||||
}
|
||||
|
||||
ConfigurationSection hubConfigSection = warInfoSection.createSection("warhub");
|
||||
hubConfigSection.set("x", hub.getLocation().getBlockX());
|
||||
hubConfigSection.set("y", hub.getLocation().getBlockY());
|
||||
hubConfigSection.set("z", hub.getLocation().getBlockZ());
|
||||
hubConfigSection.set("world", hub.getLocation().getWorld().getName());
|
||||
hubConfigSection.set("orientation", orientationStr);
|
||||
|
||||
VolumeMapper.save(hub.getVolume(), "");
|
||||
}
|
||||
|
||||
// Save to disk
|
||||
File warConfigFile = new File(War.war.getDataFolder().getPath() + "/war.yml");
|
||||
try {
|
||||
warYmlConfig.save(warConfigFile);
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to save war.yml", Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,627 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.FlagReturn;
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.TeamSpawnStyle;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarzoneTxtMapper {
|
||||
|
||||
public static Warzone load(String name, boolean createNewVolume) {
|
||||
// war.getLogger().info("Loading warzone " + name + " config and blocks...");
|
||||
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||
try {
|
||||
warzoneConfig.load();
|
||||
} catch (IOException e) {
|
||||
War.war.getLogger().info("Failed to load warzone-" + name + ".txt file.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// world
|
||||
String worldStr = warzoneConfig.getProperty("world");
|
||||
World world = null;
|
||||
if (worldStr == null || worldStr.equals("")) {
|
||||
world = War.war.getServer().getWorlds().get(0); // default to first world
|
||||
} else {
|
||||
world = War.war.getServer().getWorld(worldStr);
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
War.war.log("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!", Level.WARNING);
|
||||
} else {
|
||||
// Create the zone
|
||||
Warzone warzone = new Warzone(world, name);
|
||||
|
||||
// Create file if needed
|
||||
if (!warzoneConfig.containsKey("name")) {
|
||||
WarzoneTxtMapper.save(warzone, false);
|
||||
War.war.getLogger().info("Warzone " + name + " config file created.");
|
||||
try {
|
||||
warzoneConfig.load();
|
||||
} catch (IOException e) {
|
||||
// war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// teleport
|
||||
String teleportStr = warzoneConfig.getString("teleport");
|
||||
if (teleportStr != null && !teleportStr.equals("")) {
|
||||
String[] teleportSplit = teleportStr.split(",");
|
||||
int teleX = Integer.parseInt(teleportSplit[0]);
|
||||
int teleY = Integer.parseInt(teleportSplit[1]);
|
||||
int teleZ = Integer.parseInt(teleportSplit[2]);
|
||||
int yaw = Integer.parseInt(teleportSplit[3]);
|
||||
warzone.setTeleport(new Location(world, teleX, teleY, teleZ, yaw, 0));
|
||||
}
|
||||
|
||||
// ff
|
||||
if (warzoneConfig.containsKey("friendlyFire")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.FRIENDLYFIRE, warzoneConfig.getBoolean("friendlyFire"));
|
||||
}
|
||||
|
||||
// loadout
|
||||
warzone.getDefaultInventories().getLoadouts().clear();
|
||||
|
||||
String loadoutStr = warzoneConfig.getString("loadout");
|
||||
if (loadoutStr != null && !loadoutStr.equals("")) {
|
||||
warzone.getDefaultInventories().getLoadouts().put("default", new HashMap<Integer, ItemStack>());
|
||||
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, warzone.getDefaultInventories().getLoadouts().get("default"));
|
||||
}
|
||||
|
||||
// extraLoadouts
|
||||
String extraLoadoutStr = warzoneConfig.getString("extraLoadouts");
|
||||
String[] extraLoadoutsSplit = extraLoadoutStr.split(",");
|
||||
|
||||
for (String nameStr : extraLoadoutsSplit) {
|
||||
if (nameStr != null && !nameStr.equals("")) {
|
||||
warzone.getDefaultInventories().getLoadouts().put(nameStr, new HashMap<Integer, ItemStack>());
|
||||
}
|
||||
}
|
||||
|
||||
for (String extraName : extraLoadoutsSplit) {
|
||||
if (extraName != null && !extraName.equals("")) {
|
||||
String loadoutString = warzoneConfig.getString(extraName + "Loadout");
|
||||
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(extraName);
|
||||
LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout);
|
||||
}
|
||||
}
|
||||
|
||||
// authors
|
||||
if (warzoneConfig.containsKey("author") && !warzoneConfig.getString("author").equals("")) {
|
||||
for(String authorStr : warzoneConfig.getString("author").split(",")) {
|
||||
if (!authorStr.equals("")) {
|
||||
warzone.addAuthor(authorStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// life pool (always set after teams, so the teams' remaining lives get initialized properly by this setter)
|
||||
if (warzoneConfig.containsKey("lifePool")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.LIFEPOOL, warzoneConfig.getInt("lifePool"));
|
||||
}
|
||||
|
||||
// monument heal
|
||||
if (warzoneConfig.containsKey("monumentHeal")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.MONUMENTHEAL, warzoneConfig.getInt("monumentHeal"));
|
||||
}
|
||||
|
||||
// autoAssignOnly
|
||||
if (warzoneConfig.containsKey("autoAssignOnly")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.AUTOASSIGN, warzoneConfig.getBoolean("autoAssignOnly"));
|
||||
}
|
||||
|
||||
// flagPointsOnly
|
||||
if (warzoneConfig.containsKey("flagPointsOnly")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.FLAGPOINTSONLY, warzoneConfig.getBoolean("flagPointsOnly"));
|
||||
}
|
||||
|
||||
// flagMustBeHome
|
||||
if (warzoneConfig.containsKey("flagMustBeHome")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.FLAGMUSTBEHOME, warzoneConfig.getBoolean("flagMustBeHome"));
|
||||
}
|
||||
|
||||
// team cap
|
||||
if (warzoneConfig.containsKey("teamCap")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.TEAMSIZE, warzoneConfig.getInt("teamCap"));
|
||||
}
|
||||
|
||||
// score cap
|
||||
if (warzoneConfig.containsKey("scoreCap")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.MAXSCORE, warzoneConfig.getInt("scoreCap"));
|
||||
}
|
||||
|
||||
// respawn timer
|
||||
if (warzoneConfig.containsKey("respawnTimer")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.RESPAWNTIMER, warzoneConfig.getInt("respawnTimer"));
|
||||
}
|
||||
|
||||
// blockHeads
|
||||
if (warzoneConfig.containsKey("blockHeads")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.BLOCKHEADS, warzoneConfig.getBoolean("blockHeads"));
|
||||
}
|
||||
|
||||
// spawnStyle
|
||||
String spawnStyle = warzoneConfig.getString("spawnStyle");
|
||||
if (spawnStyle != null && !spawnStyle.equals("")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.getStyleFromString(spawnStyle));
|
||||
}
|
||||
|
||||
// flagReturn
|
||||
String flagReturn = warzoneConfig.getString("flagReturn");
|
||||
if (flagReturn != null && !flagReturn.equals("")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.FLAGRETURN, FlagReturn.getFromString(flagReturn));
|
||||
}
|
||||
|
||||
// reward
|
||||
String rewardStr = warzoneConfig.getString("reward");
|
||||
if (rewardStr != null && !rewardStr.equals("")) {
|
||||
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
LoadoutTxtMapper.fromStringToLoadout(rewardStr, reward);
|
||||
warzone.getDefaultInventories().setReward(reward);
|
||||
}
|
||||
|
||||
// unbreakableZoneBlocks
|
||||
if (warzoneConfig.containsKey("unbreakableZoneBlocks")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.UNBREAKABLE, warzoneConfig.getBoolean("unbreakableZoneBlocks"));
|
||||
}
|
||||
|
||||
// disabled
|
||||
if (warzoneConfig.containsKey("disabled")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.DISABLED, warzoneConfig.getBoolean("disabled"));
|
||||
}
|
||||
|
||||
// noCreatures
|
||||
if (warzoneConfig.containsKey("noCreatures")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.NOCREATURES, warzoneConfig.getBoolean("noCreatures"));
|
||||
}
|
||||
|
||||
// glassWalls
|
||||
if (warzoneConfig.containsKey("glassWalls")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.GLASSWALLS, warzoneConfig.getBoolean("glassWalls"));
|
||||
}
|
||||
|
||||
// pvpInZone
|
||||
if (warzoneConfig.containsKey("pvpInZone")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.PVPINZONE, warzoneConfig.getBoolean("pvpInZone"));
|
||||
}
|
||||
|
||||
// instaBreak
|
||||
if (warzoneConfig.containsKey("instaBreak")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.INSTABREAK, warzoneConfig.getBoolean("instaBreak"));
|
||||
}
|
||||
|
||||
// noDrops
|
||||
if (warzoneConfig.containsKey("noDrops")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.NODROPS, warzoneConfig.getBoolean("noDrops"));
|
||||
}
|
||||
|
||||
// noHunger
|
||||
if (warzoneConfig.containsKey("noHunger")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.NOHUNGER, warzoneConfig.getBoolean("noHunger"));
|
||||
}
|
||||
|
||||
// saturation
|
||||
if (warzoneConfig.containsKey("saturation")) {
|
||||
warzone.getTeamDefaultConfig().put(TeamConfig.SATURATION, warzoneConfig.getInt("saturation"));
|
||||
}
|
||||
|
||||
// minPlayers
|
||||
if (warzoneConfig.containsKey("minPlayers")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.MINPLAYERS, warzoneConfig.getInt("minPlayers"));
|
||||
}
|
||||
|
||||
// minTeams
|
||||
if (warzoneConfig.containsKey("minTeams")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.MINTEAMS, warzoneConfig.getInt("minTeams"));
|
||||
}
|
||||
|
||||
// resetOnEmpty
|
||||
if (warzoneConfig.containsKey("resetOnEmpty")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.RESETONEMPTY, warzoneConfig.getBoolean("resetOnEmpty"));
|
||||
}
|
||||
|
||||
// resetOnLoad
|
||||
if (warzoneConfig.containsKey("resetOnLoad")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.RESETONLOAD, warzoneConfig.getBoolean("resetOnLoad"));
|
||||
}
|
||||
|
||||
// resetOnUnload
|
||||
if (warzoneConfig.containsKey("resetOnUnload")) {
|
||||
warzone.getWarzoneConfig().put(WarzoneConfig.RESETONUNLOAD, warzoneConfig.getBoolean("resetOnUnload"));
|
||||
}
|
||||
|
||||
// rallyPoint
|
||||
String rallyPointStr = warzoneConfig.getString("rallyPoint");
|
||||
if (rallyPointStr != null && !rallyPointStr.equals("")) {
|
||||
String[] rallyPointStrSplit = rallyPointStr.split(",");
|
||||
|
||||
int rpX = Integer.parseInt(rallyPointStrSplit[0]);
|
||||
int rpY = Integer.parseInt(rallyPointStrSplit[1]);
|
||||
int rpZ = Integer.parseInt(rallyPointStrSplit[2]);
|
||||
Location rallyPoint = new Location(world, rpX, rpY, rpZ);
|
||||
warzone.setRallyPoint(rallyPoint);
|
||||
}
|
||||
|
||||
// monuments
|
||||
String monumentsStr = warzoneConfig.getString("monuments");
|
||||
if (monumentsStr != null && !monumentsStr.equals("")) {
|
||||
String[] monumentsSplit = monumentsStr.split(";");
|
||||
warzone.getMonuments().clear();
|
||||
for (String monumentStr : monumentsSplit) {
|
||||
if (monumentStr != null && !monumentStr.equals("")) {
|
||||
String[] monumentStrSplit = monumentStr.split(",");
|
||||
int monumentX = Integer.parseInt(monumentStrSplit[1]);
|
||||
int monumentY = Integer.parseInt(monumentStrSplit[2]);
|
||||
int monumentZ = Integer.parseInt(monumentStrSplit[3]);
|
||||
Monument monument = new Monument(monumentStrSplit[0], warzone, new Location(world, monumentX, monumentY, monumentZ));
|
||||
warzone.getMonuments().add(monument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// teams
|
||||
String teamsStr = warzoneConfig.getString("teams");
|
||||
if (teamsStr != null && !teamsStr.equals("")) {
|
||||
String[] teamsSplit = teamsStr.split(";");
|
||||
warzone.getTeams().clear();
|
||||
for (String teamStr : teamsSplit) {
|
||||
if (teamStr != null && !teamStr.equals("")) {
|
||||
String[] teamStrSplit = teamStr.split(",");
|
||||
int teamX = Integer.parseInt(teamStrSplit[1]);
|
||||
int teamY = Integer.parseInt(teamStrSplit[2]);
|
||||
int teamZ = Integer.parseInt(teamStrSplit[3]);
|
||||
Location teamLocation = new Location(world, teamX, teamY, teamZ);
|
||||
if (teamStrSplit.length > 4) {
|
||||
int yaw = Integer.parseInt(teamStrSplit[4]);
|
||||
teamLocation.setYaw(yaw);
|
||||
}
|
||||
Team team = new Team(teamStrSplit[0], TeamKind.teamKindFromString(teamStrSplit[0]), teamLocation, warzone);
|
||||
team.setRemainingLives(warzone.getTeamDefaultConfig().resolveInt(TeamConfig.LIFEPOOL));
|
||||
warzone.getTeams().add(team);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// teamFlags
|
||||
String teamFlagsStr = warzoneConfig.getString("teamFlags");
|
||||
if (teamFlagsStr != null && !teamFlagsStr.equals("")) {
|
||||
String[] teamFlagsSplit = teamFlagsStr.split(";");
|
||||
for (String teamFlagStr : teamFlagsSplit) {
|
||||
if (teamFlagStr != null && !teamFlagStr.equals("")) {
|
||||
String[] teamFlagStrSplit = teamFlagStr.split(",");
|
||||
Team team = warzone.getTeamByKind(TeamKind.teamKindFromString(teamFlagStrSplit[0]));
|
||||
if (team != null) {
|
||||
int teamFlagX = Integer.parseInt(teamFlagStrSplit[1]);
|
||||
int teamFlagY = Integer.parseInt(teamFlagStrSplit[2]);
|
||||
int teamFlagZ = Integer.parseInt(teamFlagStrSplit[3]);
|
||||
Location teamFlagLocation = new Location(world, teamFlagX, teamFlagY, teamFlagZ);
|
||||
if (teamFlagStrSplit.length > 4) {
|
||||
int yaw = Integer.parseInt(teamFlagStrSplit[4]);
|
||||
teamFlagLocation.setYaw(yaw);
|
||||
}
|
||||
team.setTeamFlag(teamFlagLocation); // this may screw things up
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lobby
|
||||
String lobbyStr = warzoneConfig.getString("lobby");
|
||||
|
||||
warzoneConfig.close();
|
||||
|
||||
if (createNewVolume) {
|
||||
ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), world, warzone); // VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone);
|
||||
warzone.setVolume(zoneVolume);
|
||||
}
|
||||
|
||||
// monument blocks
|
||||
for (Monument monument : warzone.getMonuments()) {
|
||||
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
for (Team team : warzone.getTeams()) {
|
||||
team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), world));
|
||||
if (team.getTeamFlag() != null) {
|
||||
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
|
||||
}
|
||||
}
|
||||
|
||||
// lobby
|
||||
BlockFace lobbyFace = null;
|
||||
if (lobbyStr != null && !lobbyStr.equals("")) {
|
||||
String[] lobbyStrSplit = lobbyStr.split(",");
|
||||
if (lobbyStrSplit.length > 0) {
|
||||
// lobby orientation
|
||||
if (lobbyStrSplit[0].equals("south")) {
|
||||
lobbyFace = BlockFace.SOUTH;
|
||||
} else if (lobbyStrSplit[0].equals("east")) {
|
||||
lobbyFace = BlockFace.EAST;
|
||||
} else if (lobbyStrSplit[0].equals("north")) {
|
||||
lobbyFace = BlockFace.NORTH;
|
||||
} else if (lobbyStrSplit[0].equals("west")) {
|
||||
lobbyFace = BlockFace.WEST;
|
||||
}
|
||||
|
||||
// lobby world
|
||||
World lobbyWorld = world; // by default, warzone world
|
||||
if (lobbyStrSplit.length > 1) {
|
||||
World strWorld = War.war.getServer().getWorld(lobbyStrSplit[1]);
|
||||
if (strWorld != null) {
|
||||
lobbyWorld = strWorld;
|
||||
}
|
||||
}
|
||||
|
||||
// create the lobby
|
||||
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld);
|
||||
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
|
||||
warzone.setLobby(lobby);
|
||||
}
|
||||
}
|
||||
|
||||
return warzone;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void save(Warzone warzone, boolean saveAllBlocks) {
|
||||
|
||||
War.war.log("Saving War with WarzoneTxtMapper", Level.SEVERE);
|
||||
// (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir();
|
||||
// PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt");
|
||||
// // war.getLogger().info("Saving warzone " + warzone.getName() + "...");
|
||||
//
|
||||
// // name
|
||||
// warzoneConfig.setString("name", warzone.getName());
|
||||
//
|
||||
// // world
|
||||
// warzoneConfig.setString("world", warzone.getWorld().getName()); // default for now
|
||||
//
|
||||
// // teleport
|
||||
// String teleportStr = "";
|
||||
// Location tele = warzone.getTeleport();
|
||||
// if (tele != null) {
|
||||
// int intYaw = 0;
|
||||
// if (tele.getYaw() >= 0) {
|
||||
// intYaw = (int) (tele.getYaw() % 360);
|
||||
// } else {
|
||||
// intYaw = (int) (360 + (tele.getYaw() % 360));
|
||||
// }
|
||||
// teleportStr = tele.getBlockX() + "," + tele.getBlockY() + "," + tele.getBlockZ() + "," + intYaw;
|
||||
// }
|
||||
// warzoneConfig.setString("teleport", teleportStr);
|
||||
//
|
||||
// // teams
|
||||
// String teamsStr = "";
|
||||
// List<Team> teams = warzone.getTeams();
|
||||
// for (Team team : teams) {
|
||||
// Location spawn = team.getTeamSpawn();
|
||||
// int intYaw = 0;
|
||||
// if (spawn.getYaw() >= 0) {
|
||||
// intYaw = (int) (spawn.getYaw() % 360);
|
||||
// } else {
|
||||
// intYaw = (int) (360 + (spawn.getYaw() % 360));
|
||||
// }
|
||||
// teamsStr += team.getName() + "," + spawn.getBlockX() + "," + spawn.getBlockY() + "," + spawn.getBlockZ() + "," + intYaw + ";";
|
||||
// }
|
||||
// warzoneConfig.setString("teams", teamsStr);
|
||||
//
|
||||
// // team flags
|
||||
// String teamFlagsStr = "";;
|
||||
// for (Team team : teams) {
|
||||
// if (team.getFlagVolume() != null) {
|
||||
// Location flag = team.getTeamFlag();
|
||||
// int intYaw = 0;
|
||||
// if (flag.getYaw() >= 0) {
|
||||
// intYaw = (int) (flag.getYaw() % 360);
|
||||
// } else {
|
||||
// intYaw = (int) (360 + (flag.getYaw() % 360));
|
||||
// }
|
||||
// teamFlagsStr += team.getName() + "," + flag.getBlockX() + "," + flag.getBlockY() + "," + flag.getBlockZ() + "," + intYaw + ";";
|
||||
// }
|
||||
// }
|
||||
// warzoneConfig.setString("teamFlags", teamFlagsStr);
|
||||
//
|
||||
// // ff
|
||||
// warzoneConfig.setBoolean("friendlyFire", warzone.getFriendlyFire());
|
||||
//
|
||||
// // loadout
|
||||
// HashMap<Integer, ItemStack> items = warzone.getDefaultInventories().getLoadouts().get("default");
|
||||
// warzoneConfig.setString("loadout", LoadoutTxtMapper.fromLoadoutToString(items));
|
||||
//
|
||||
// // defaultExtraLoadouts
|
||||
// String extraLoadoutsStr = "";
|
||||
// for (String name : warzone.getDefaultInventories().getLoadouts().keySet()) {
|
||||
// if (!name.equals("default")) {
|
||||
// extraLoadoutsStr += name + ",";
|
||||
//
|
||||
// HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(name);
|
||||
// warzoneConfig.setString(name + "Loadout", LoadoutTxtMapper.fromLoadoutToString(loadout));
|
||||
// }
|
||||
// }
|
||||
// warzoneConfig.setString("extraLoadouts", extraLoadoutsStr);
|
||||
//
|
||||
// // authors
|
||||
// warzoneConfig.setString("author", warzone.getAuthorsString());
|
||||
//
|
||||
// // life pool
|
||||
// warzoneConfig.setInt("lifePool", warzone.getLifePool());
|
||||
//
|
||||
// // monument heal
|
||||
// warzoneConfig.setInt("monumentHeal", warzone.getMonumentHeal());
|
||||
//
|
||||
// // autoAssignOnly
|
||||
// warzoneConfig.setBoolean("autoAssignOnly", warzone.isAutoAssignOnly());
|
||||
//
|
||||
// // flagPointsOnly
|
||||
// warzoneConfig.setBoolean("flagPointsOnly", warzone.isFlagPointsOnly());
|
||||
//
|
||||
// // flagMustBeHome
|
||||
// warzoneConfig.setBoolean("flagMustBeHome", warzone.isFlagMustBeHome());
|
||||
//
|
||||
// // team cap
|
||||
// warzoneConfig.setInt("teamCap", warzone.getTeamCap());
|
||||
//
|
||||
// // score cap
|
||||
// warzoneConfig.setInt("scoreCap", warzone.getScoreCap());
|
||||
//
|
||||
// // respawn timer
|
||||
// warzoneConfig.setInt("respawnTimer", warzone.getRespawnTimer());
|
||||
//
|
||||
// // blockHeads
|
||||
// warzoneConfig.setBoolean("blockHeads", warzone.isBlockHeads());
|
||||
//
|
||||
// // spawnStyle
|
||||
// warzoneConfig.setString("spawnStyle", warzone.getSpawnStyle().toString());
|
||||
//
|
||||
// // flagReturn
|
||||
// warzoneConfig.setString("flagReturn", warzone.getFlagReturn().toString());
|
||||
//
|
||||
// // reward
|
||||
// HashMap<Integer, ItemStack> rewardItems = warzone.getDefaultInventories().getReward();
|
||||
// warzoneConfig.setString("reward", LoadoutTxtMapper.fromLoadoutToString(rewardItems));
|
||||
//
|
||||
// // unbreakableZoneBlocks
|
||||
// warzoneConfig.setBoolean("unbreakableZoneBlocks", warzone.isUnbreakableZoneBlocks());
|
||||
//
|
||||
// // disabled
|
||||
// warzoneConfig.setBoolean("disabled", warzone.isDisabled());
|
||||
//
|
||||
// // noCreatures
|
||||
// warzoneConfig.setBoolean("noCreatures", warzone.isNoCreatures());
|
||||
//
|
||||
// // glassWalls
|
||||
// warzoneConfig.setBoolean("glassWalls", warzone.isGlassWalls());
|
||||
//
|
||||
// // pvpInZone
|
||||
// warzoneConfig.setBoolean("pvpInZone", warzone.isPvpInZone());
|
||||
//
|
||||
// // instaBreak
|
||||
// warzoneConfig.setBoolean("instaBreak", warzone.isInstaBreak());
|
||||
//
|
||||
// // noDrops
|
||||
// warzoneConfig.setBoolean("noDrops", warzone.isNoDrops());
|
||||
//
|
||||
// // noHunger
|
||||
// warzoneConfig.setBoolean("noHunger", warzone.isNoHunger());
|
||||
//
|
||||
// // saturation
|
||||
// warzoneConfig.setInt("saturation", warzone.getSaturation());
|
||||
//
|
||||
// // minPlayers
|
||||
// warzoneConfig.setInt("minPlayers", warzone.getMinPlayers());
|
||||
//
|
||||
// // minTeams
|
||||
// warzoneConfig.setInt("minTeams", warzone.getMinTeams());
|
||||
//
|
||||
// // resetOnEmpty
|
||||
// warzoneConfig.setBoolean("resetOnEmpty", warzone.isResetOnEmpty());
|
||||
//
|
||||
// // resetOnLoad
|
||||
// warzoneConfig.setBoolean("resetOnLoad", warzone.isResetOnLoad());
|
||||
//
|
||||
// // resetOnUnload
|
||||
// warzoneConfig.setBoolean("resetOnUnload", warzone.isResetOnUnload());
|
||||
//
|
||||
// // rallyPoint
|
||||
// String rpStr = "";
|
||||
// Location rp = warzone.getRallyPoint();
|
||||
// if (rp != null) {
|
||||
// rpStr = rp.getBlockX() + "," + rp.getBlockY() + "," + rp.getBlockZ();
|
||||
// }
|
||||
// warzoneConfig.setString("rallyPoint", rpStr);
|
||||
//
|
||||
// // defaultDropLootOnDeath
|
||||
// // warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath());
|
||||
//
|
||||
// // monuments
|
||||
// String monumentsStr = "";
|
||||
// List<Monument> monuments = warzone.getMonuments();
|
||||
// for (Monument monument : monuments) {
|
||||
// Location monumentLoc = monument.getLocation();
|
||||
// monumentsStr += monument.getName() + "," + monumentLoc.getBlockX() + "," + monumentLoc.getBlockY() + "," + monumentLoc.getBlockZ() + ";";
|
||||
// }
|
||||
// warzoneConfig.setString("monuments", monumentsStr);
|
||||
//
|
||||
// // lobby
|
||||
// String lobbyStr = "";
|
||||
// if (warzone.getLobby() != null) {
|
||||
// if (BlockFace.SOUTH == warzone.getLobby().getWall()) {
|
||||
// lobbyStr = "south";
|
||||
// } else if (BlockFace.EAST == warzone.getLobby().getWall()) {
|
||||
// lobbyStr = "east";
|
||||
// } else if (BlockFace.NORTH == warzone.getLobby().getWall()) {
|
||||
// lobbyStr = "north";
|
||||
// } else if (BlockFace.WEST == warzone.getLobby().getWall()) {
|
||||
// lobbyStr = "west";
|
||||
// }
|
||||
// }
|
||||
// warzoneConfig.setString("lobby", lobbyStr + "," + warzone.getLobby().getVolume().getWorld().getName());
|
||||
//
|
||||
// warzoneConfig.save();
|
||||
// warzoneConfig.close();
|
||||
//
|
||||
// // monument blocks
|
||||
// for (Monument monument : monuments) {
|
||||
// VolumeMapper.save(monument.getVolume(), warzone.getName());
|
||||
// }
|
||||
//
|
||||
// // team spawn & flag blocks
|
||||
// for (Team team : teams) {
|
||||
// VolumeMapper.save(team.getSpawnVolume(), warzone.getName());
|
||||
// if (team.getFlagVolume() != null) {
|
||||
// VolumeMapper.save(team.getFlagVolume(), warzone.getName());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (warzone.getLobby() != null) {
|
||||
// VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName());
|
||||
// }
|
||||
}
|
||||
|
||||
public static void delete(String name) {
|
||||
File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name);
|
||||
File[] files = zoneFolder.listFiles();
|
||||
for (File file : files) {
|
||||
boolean deletedData = file.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + file.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
boolean deletedData = zoneFolder.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
|
||||
}
|
||||
File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||
deletedData = zoneFile.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,527 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Bomb;
|
||||
import com.tommytony.war.Cake;
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.TeamKind;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.ZoneLobby;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
public class WarzoneYmlMapper {
|
||||
|
||||
public static Warzone load(String name, boolean createNewVolume) {
|
||||
File warzoneTxtFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||
File warzoneYmlFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml");
|
||||
|
||||
// Convert from TXT to YML if needed
|
||||
if (warzoneTxtFile.exists() && !warzoneYmlFile.exists()) {
|
||||
// Since we're converting, WarTxtMapper didn't load the warzones.
|
||||
// We need to load the old-text-format-Warzone into memory.
|
||||
Warzone zoneToConvert = WarzoneTxtMapper.load(name, false);
|
||||
WarzoneYmlMapper.save(zoneToConvert, false);
|
||||
War.war.log("Converted warzone-" + name + ".txt to warzone-" + name + ".yml", Level.INFO);
|
||||
}
|
||||
|
||||
if (!warzoneYmlFile.exists()) {
|
||||
War.war.log("File warzone-" + name + ".yml not found", Level.WARNING);
|
||||
} else {
|
||||
YamlConfiguration warzoneYmlConfig = YamlConfiguration.loadConfiguration(warzoneYmlFile);
|
||||
ConfigurationSection warzoneRootSection = warzoneYmlConfig.getConfigurationSection("set");
|
||||
|
||||
String zoneInfoPrefix = "warzone." + name + ".info.";
|
||||
|
||||
// world
|
||||
String worldStr = warzoneRootSection.getString(zoneInfoPrefix + "world");
|
||||
World world = War.war.getServer().getWorld(worldStr);
|
||||
|
||||
// Create the zone
|
||||
Warzone warzone = new Warzone(world, name);
|
||||
|
||||
// teleport
|
||||
int teleX = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.x");
|
||||
int teleY = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.y");
|
||||
int teleZ = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.z");
|
||||
int teleYaw = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.yaw");
|
||||
warzone.setTeleport(new Location(world, teleX, teleY, teleZ, teleYaw, 0));
|
||||
|
||||
// defaultLoadouts
|
||||
if (warzoneRootSection.contains("team.default.loadout")) {
|
||||
ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection("team.default.loadout");
|
||||
LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, warzone.getDefaultInventories().getLoadouts());
|
||||
}
|
||||
|
||||
// defaultReward
|
||||
if (warzoneRootSection.contains("team.default.reward")) {
|
||||
ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection("team.default.reward");
|
||||
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
|
||||
warzone.getDefaultInventories().setReward(reward);
|
||||
}
|
||||
|
||||
// Team default settings
|
||||
if (warzoneRootSection.contains("team.default.config")) {
|
||||
ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection("team.default.config");
|
||||
warzone.getTeamDefaultConfig().loadFrom(teamConfigSection);
|
||||
}
|
||||
|
||||
// Warzone settings
|
||||
if (warzoneRootSection.contains("warzone." + warzone.getName() + ".config")) {
|
||||
ConfigurationSection warzoneConfigSection = warzoneRootSection.getConfigurationSection("warzone." + warzone.getName() + ".config");
|
||||
warzone.getWarzoneConfig().loadFrom(warzoneConfigSection);
|
||||
}
|
||||
|
||||
// authors
|
||||
if (warzoneRootSection.contains(zoneInfoPrefix + "authors")) {
|
||||
for(String authorStr : warzoneRootSection.getStringList(zoneInfoPrefix + "authors")) {
|
||||
if (!authorStr.equals("")) {
|
||||
warzone.addAuthor(authorStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rallyPoint
|
||||
if (warzoneRootSection.contains(zoneInfoPrefix + "rallypoint")) {
|
||||
int rpX = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.x");
|
||||
int rpY = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.y");
|
||||
int rpZ = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.z");
|
||||
int rpYaw = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.yaw");
|
||||
Location rallyPoint = new Location(world, rpX, rpY, rpZ, rpYaw, 0);
|
||||
warzone.setRallyPoint(rallyPoint);
|
||||
}
|
||||
|
||||
// monuments
|
||||
if (warzoneRootSection.contains(zoneInfoPrefix + "monument")) {
|
||||
List<String> monunmentNames = warzoneRootSection.getStringList(zoneInfoPrefix + "monument.names");
|
||||
for (String monumentName : monunmentNames) {
|
||||
if (monumentName != null && !monumentName.equals("")) {
|
||||
String monumentPrefix = zoneInfoPrefix + "monument." + monumentName + ".";
|
||||
int monumentX = warzoneRootSection.getInt(monumentPrefix + "x");
|
||||
int monumentY = warzoneRootSection.getInt(monumentPrefix + "y");
|
||||
int monumentZ = warzoneRootSection.getInt(monumentPrefix + "z");
|
||||
int monumentYaw = warzoneRootSection.getInt(monumentPrefix + "yaw");
|
||||
Monument monument = new Monument(monumentName, warzone, new Location(world, monumentX, monumentY, monumentZ, monumentYaw, 0));
|
||||
warzone.getMonuments().add(monument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bombs
|
||||
if (warzoneRootSection.contains(zoneInfoPrefix + "bomb")) {
|
||||
List<String> bombNames = warzoneRootSection.getStringList(zoneInfoPrefix + "bomb.names");
|
||||
for (String bombName : bombNames) {
|
||||
if (bombName != null && !bombName.equals("")) {
|
||||
String bombPrefix = zoneInfoPrefix + "bomb." + bombName + ".";
|
||||
int bombX = warzoneRootSection.getInt(bombPrefix + "x");
|
||||
int bombY = warzoneRootSection.getInt(bombPrefix + "y");
|
||||
int bombZ = warzoneRootSection.getInt(bombPrefix + "z");
|
||||
int bombYaw = warzoneRootSection.getInt(bombPrefix + "yaw");
|
||||
Bomb bomb = new Bomb(bombName, warzone, new Location(world, bombX, bombY, bombZ, bombYaw, 0));
|
||||
warzone.getBombs().add(bomb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cakes
|
||||
if (warzoneRootSection.contains(zoneInfoPrefix + "cake")) {
|
||||
List<String> cakeNames = warzoneRootSection.getStringList(zoneInfoPrefix + "cake.names");
|
||||
for (String cakeName : cakeNames) {
|
||||
if (cakeName != null && !cakeName.equals("")) {
|
||||
String cakePrefix = zoneInfoPrefix + "cake." + cakeName + ".";
|
||||
int cakeX = warzoneRootSection.getInt(cakePrefix + "x");
|
||||
int cakeY = warzoneRootSection.getInt(cakePrefix + "y");
|
||||
int cakeZ = warzoneRootSection.getInt(cakePrefix + "z");
|
||||
int cakeYaw = warzoneRootSection.getInt(cakePrefix + "yaw");
|
||||
Cake cake = new Cake(cakeName, warzone, new Location(world, cakeX, cakeY, cakeZ, cakeYaw, 0));
|
||||
warzone.getCakes().add(cake);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// teams (maybe no teams)
|
||||
if (warzoneRootSection.contains("team.names")) {
|
||||
List<String> teamsNames = warzoneRootSection.getStringList("team.names");
|
||||
for (String teamName : teamsNames) {
|
||||
// team info
|
||||
String teamInfoPrefix = "team." + teamName + ".info.";
|
||||
int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x");
|
||||
int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y");
|
||||
int teamZ = warzoneRootSection.getInt(teamInfoPrefix + "spawn.z");
|
||||
int teamYaw = warzoneRootSection.getInt(teamInfoPrefix + "spawn.yaw");
|
||||
Location teamLocation = new Location(world, teamX, teamY, teamZ, teamYaw, 0);
|
||||
|
||||
Team team = new Team(teamName, TeamKind.teamKindFromString(teamName), teamLocation, warzone);
|
||||
warzone.getTeams().add(team);
|
||||
|
||||
if (warzoneRootSection.contains(teamInfoPrefix + "flag")) {
|
||||
int flagX = warzoneRootSection.getInt(teamInfoPrefix + "flag.x");
|
||||
int flagY = warzoneRootSection.getInt(teamInfoPrefix + "flag.y");
|
||||
int flagZ = warzoneRootSection.getInt(teamInfoPrefix + "flag.z");
|
||||
int flagYaw = warzoneRootSection.getInt(teamInfoPrefix + "flag.yaw");
|
||||
Location flagLocation = new Location(world, flagX, flagY, flagZ, flagYaw, 0);
|
||||
team.setTeamFlag(flagLocation);
|
||||
}
|
||||
|
||||
String teamConfigPrefix = "team." + teamName + ".config";
|
||||
if (warzoneRootSection.contains(teamConfigPrefix)) {
|
||||
// team specific config
|
||||
ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection(teamConfigPrefix);
|
||||
team.getTeamConfig().loadFrom(teamConfigSection);
|
||||
}
|
||||
|
||||
team.setRemainingLives(team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
|
||||
|
||||
String teamLoadoutPrefix = "team." + teamName + ".loadout";
|
||||
if (warzoneRootSection.contains(teamLoadoutPrefix)) {
|
||||
// team specific loadouts
|
||||
ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix);
|
||||
LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, team.getInventories().getLoadouts());
|
||||
}
|
||||
|
||||
String teamRewardPrefix = "team." + teamName + ".reward";
|
||||
if (warzoneRootSection.contains(teamRewardPrefix)) {
|
||||
// team specific reward
|
||||
ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection(teamRewardPrefix);
|
||||
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
|
||||
warzone.getDefaultInventories().setReward(reward);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (createNewVolume) {
|
||||
ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), world, warzone);
|
||||
warzone.setVolume(zoneVolume);
|
||||
}
|
||||
|
||||
// monument blocks
|
||||
for (Monument monument : warzone.getMonuments()) {
|
||||
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
|
||||
}
|
||||
|
||||
// bomb blocks
|
||||
for (Bomb bomb : warzone.getBombs()) {
|
||||
bomb.setVolume(VolumeMapper.loadVolume("bomb-" + bomb.getName(), warzone.getName(), world));
|
||||
}
|
||||
|
||||
// cake blocks
|
||||
for (Cake cake : warzone.getCakes()) {
|
||||
cake.setVolume(VolumeMapper.loadVolume("cake-" + cake.getName(), warzone.getName(), world));
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
for (Team team : warzone.getTeams()) {
|
||||
team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), world));
|
||||
if (team.getTeamFlag() != null) {
|
||||
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
|
||||
}
|
||||
}
|
||||
|
||||
// lobby
|
||||
String lobbyPrefix = zoneInfoPrefix + "lobby.";
|
||||
|
||||
// lobby orientation
|
||||
String lobbyOrientation = warzoneRootSection.getString(lobbyPrefix + "orientation");
|
||||
BlockFace lobbyFace = null;
|
||||
if (lobbyOrientation.equals("south")) {
|
||||
lobbyFace = BlockFace.SOUTH;
|
||||
} else if (lobbyOrientation.equals("east")) {
|
||||
lobbyFace = BlockFace.EAST;
|
||||
} else if (lobbyOrientation.equals("north")) {
|
||||
lobbyFace = BlockFace.NORTH;
|
||||
} else if (lobbyOrientation.equals("west")) {
|
||||
lobbyFace = BlockFace.WEST;
|
||||
}
|
||||
|
||||
// lobby world
|
||||
String lobbyWorldName = warzoneRootSection.getString(lobbyPrefix + "world");
|
||||
World lobbyWorld = War.war.getServer().getWorld(lobbyWorldName);
|
||||
|
||||
// create the lobby
|
||||
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld);
|
||||
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
|
||||
warzone.setLobby(lobby);
|
||||
|
||||
return warzone;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void save(Warzone warzone, boolean saveAllBlocks) {
|
||||
YamlConfiguration warzoneYmlConfig = new YamlConfiguration();
|
||||
ConfigurationSection warzoneRootSection = warzoneYmlConfig.createSection("set");
|
||||
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir(); // create folder
|
||||
|
||||
ConfigurationSection warzoneSection = warzoneRootSection.createSection("warzone." + warzone.getName());
|
||||
|
||||
// Warzone settings
|
||||
if (!warzone.getWarzoneConfig().isEmpty()) {
|
||||
ConfigurationSection warzoneConfigSection = warzoneSection.createSection("config");
|
||||
warzone.getWarzoneConfig().saveTo(warzoneConfigSection);
|
||||
}
|
||||
|
||||
ConfigurationSection warzoneInfoSection = warzoneSection.createSection("info");
|
||||
|
||||
// authors
|
||||
warzoneInfoSection.set("authors", warzone.getAuthors());
|
||||
|
||||
// teleport
|
||||
ConfigurationSection teleSection = warzoneInfoSection.createSection("teleport");
|
||||
teleSection.set("x", warzone.getTeleport().getBlockX());
|
||||
teleSection.set("y", warzone.getTeleport().getBlockY());
|
||||
teleSection.set("z", warzone.getTeleport().getBlockZ());
|
||||
teleSection.set("yaw", toIntYaw(warzone.getTeleport().getYaw()));
|
||||
|
||||
// world
|
||||
warzoneInfoSection.set("world", warzone.getWorld().getName());
|
||||
|
||||
// lobby
|
||||
if (warzone.getLobby() != null) {
|
||||
String lobbyOrientation = "";
|
||||
if (BlockFace.SOUTH == warzone.getLobby().getWall()) {
|
||||
lobbyOrientation = "south";
|
||||
} else if (BlockFace.EAST == warzone.getLobby().getWall()) {
|
||||
lobbyOrientation = "east";
|
||||
} else if (BlockFace.NORTH == warzone.getLobby().getWall()) {
|
||||
lobbyOrientation = "north";
|
||||
} else if (BlockFace.WEST == warzone.getLobby().getWall()) {
|
||||
lobbyOrientation = "west";
|
||||
}
|
||||
|
||||
ConfigurationSection lobbySection = warzoneInfoSection.createSection("lobby");
|
||||
lobbySection.set("orientation", lobbyOrientation);
|
||||
lobbySection.set("world", warzone.getLobby().getVolume().getWorld().getName());
|
||||
}
|
||||
|
||||
// rallyPoint
|
||||
if (warzone.getRallyPoint() != null) {
|
||||
ConfigurationSection rpSection = warzoneInfoSection.createSection("rallypoint");
|
||||
rpSection.set("x", warzone.getRallyPoint().getBlockX());
|
||||
rpSection.set("y", warzone.getRallyPoint().getBlockY());
|
||||
rpSection.set("z", warzone.getRallyPoint().getBlockZ());
|
||||
rpSection.set("yaw", toIntYaw(warzone.getRallyPoint().getYaw()));
|
||||
}
|
||||
|
||||
// monuments
|
||||
if (warzone.getMonuments().size() > 0) {
|
||||
ConfigurationSection monumentsSection = warzoneInfoSection.createSection("monument");
|
||||
|
||||
List<String> monumentNames = new ArrayList<String>();
|
||||
for (Monument monument : warzone.getMonuments()) {
|
||||
monumentNames.add(monument.getName());
|
||||
}
|
||||
monumentsSection.set("names", monumentNames);
|
||||
|
||||
for (Monument monument : warzone.getMonuments()) {
|
||||
|
||||
ConfigurationSection monumentSection = monumentsSection.createSection(monument.getName());
|
||||
monumentSection.set("x", monument.getLocation().getBlockX());
|
||||
monumentSection.set("y", monument.getLocation().getBlockY());
|
||||
monumentSection.set("z", monument.getLocation().getBlockZ());
|
||||
monumentSection.set("yaw", toIntYaw(monument.getLocation().getYaw()));
|
||||
}
|
||||
}
|
||||
|
||||
// bombs
|
||||
if (warzone.getBombs().size() > 0) {
|
||||
ConfigurationSection bombsSection = warzoneInfoSection.createSection("bomb");
|
||||
|
||||
List<String> bombNames = new ArrayList<String>();
|
||||
for (Bomb bomb : warzone.getBombs()) {
|
||||
bombNames.add(bomb.getName());
|
||||
}
|
||||
bombsSection.set("names", bombNames);
|
||||
|
||||
for (Bomb bomb : warzone.getBombs()) {
|
||||
|
||||
ConfigurationSection bombSection = bombsSection.createSection(bomb.getName());
|
||||
bombSection.set("x", bomb.getLocation().getBlockX());
|
||||
bombSection.set("y", bomb.getLocation().getBlockY());
|
||||
bombSection.set("z", bomb.getLocation().getBlockZ());
|
||||
bombSection.set("yaw", toIntYaw(bomb.getLocation().getYaw()));
|
||||
}
|
||||
}
|
||||
|
||||
// cakes
|
||||
if (warzone.getCakes().size() > 0) {
|
||||
ConfigurationSection cakesSection = warzoneInfoSection.createSection("cake");
|
||||
|
||||
List<String> cakeNames = new ArrayList<String>();
|
||||
for (Cake cake : warzone.getCakes()) {
|
||||
cakeNames.add(cake.getName());
|
||||
}
|
||||
cakesSection.set("names", cakeNames);
|
||||
|
||||
for (Cake cake : warzone.getCakes()) {
|
||||
|
||||
ConfigurationSection cakeSection = cakesSection.createSection(cake.getName());
|
||||
cakeSection.set("x", cake.getLocation().getBlockX());
|
||||
cakeSection.set("y", cake.getLocation().getBlockY());
|
||||
cakeSection.set("z", cake.getLocation().getBlockZ());
|
||||
cakeSection.set("yaw", toIntYaw(cake.getLocation().getYaw()));
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationSection teamsSection = warzoneRootSection.createSection("team");
|
||||
|
||||
// teams
|
||||
List<Team> teams = warzone.getTeams();
|
||||
|
||||
List<String> teamNames = new ArrayList<String>();
|
||||
for (Team team : teams) {
|
||||
teamNames.add(team.getName());
|
||||
}
|
||||
if (teamNames.size() > 0) {
|
||||
teamsSection.set("names", teamNames);
|
||||
}
|
||||
|
||||
// Team default settings
|
||||
if (!warzone.getTeamDefaultConfig().isEmpty()) {
|
||||
ConfigurationSection teamConfigSection = teamsSection.createSection("default.config");
|
||||
warzone.getTeamDefaultConfig().saveTo(teamConfigSection);
|
||||
}
|
||||
|
||||
// defaultLoadouts
|
||||
if (warzone.getDefaultInventories().hasLoadouts()) {
|
||||
ConfigurationSection loadoutsSection = teamsSection.createSection("default.loadout");
|
||||
LoadoutYmlMapper.fromLoadoutsToConfig(warzone.getDefaultInventories().getLoadouts(), loadoutsSection);
|
||||
}
|
||||
|
||||
// defaultReward
|
||||
if (warzone.getDefaultInventories().hasReward()) {
|
||||
ConfigurationSection rewardsSection = teamsSection.createSection("default.reward");
|
||||
LoadoutYmlMapper.fromLoadoutToConfig("default", warzone.getDefaultInventories().getReward(), rewardsSection);
|
||||
}
|
||||
|
||||
for (Team team : teams) {
|
||||
if (!team.getTeamConfig().isEmpty()) {
|
||||
// team specific config
|
||||
ConfigurationSection teamConfigSection = teamsSection.createSection(team.getName() + ".config");
|
||||
team.getTeamConfig().saveTo(teamConfigSection);
|
||||
}
|
||||
|
||||
if (team.getInventories().hasLoadouts()) {
|
||||
// team specific loadouts
|
||||
ConfigurationSection loadoutsSection = teamsSection.createSection(team.getName() + ".loadout");
|
||||
LoadoutYmlMapper.fromLoadoutsToConfig(team.getInventories().getLoadouts(), loadoutsSection);
|
||||
}
|
||||
|
||||
if (team.getInventories().hasReward()) {
|
||||
// team specific reward
|
||||
ConfigurationSection rewardsSection = teamsSection.createSection(team.getName() + ".reward");
|
||||
LoadoutYmlMapper.fromLoadoutToConfig("default", team.getInventories().getReward(), rewardsSection);
|
||||
}
|
||||
|
||||
ConfigurationSection teamInfoSection = teamsSection.createSection(team.getName() + ".info");
|
||||
|
||||
ConfigurationSection spawnSection = teamInfoSection.createSection("spawn");
|
||||
Location spawn = team.getTeamSpawn();
|
||||
spawnSection.set("x", spawn.getBlockX());
|
||||
spawnSection.set("y", spawn.getBlockY());
|
||||
spawnSection.set("z", spawn.getBlockZ());
|
||||
spawnSection.set("yaw", toIntYaw(spawn.getYaw()));
|
||||
|
||||
if (team.getTeamFlag() != null) {
|
||||
ConfigurationSection flagSection = teamInfoSection.createSection("flag");
|
||||
Location teamFlag = team.getTeamFlag();
|
||||
flagSection.set("x", teamFlag.getBlockX());
|
||||
flagSection.set("y", teamFlag.getBlockY());
|
||||
flagSection.set("z", teamFlag.getBlockZ());
|
||||
flagSection.set("yaw", toIntYaw(teamFlag.getYaw()));
|
||||
}
|
||||
}
|
||||
|
||||
// monument blocks
|
||||
for (Monument monument : warzone.getMonuments()) {
|
||||
VolumeMapper.save(monument.getVolume(), warzone.getName());
|
||||
}
|
||||
|
||||
// bomb blocks
|
||||
for (Bomb bomb : warzone.getBombs()) {
|
||||
VolumeMapper.save(bomb.getVolume(), warzone.getName());
|
||||
}
|
||||
|
||||
// cake blocks
|
||||
for (Cake cake : warzone.getCakes()) {
|
||||
VolumeMapper.save(cake.getVolume(), warzone.getName());
|
||||
}
|
||||
|
||||
// team spawn & flag blocks
|
||||
for (Team team : teams) {
|
||||
VolumeMapper.save(team.getSpawnVolume(), warzone.getName());
|
||||
if (team.getFlagVolume() != null) {
|
||||
VolumeMapper.save(team.getFlagVolume(), warzone.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (warzone.getLobby() != null) {
|
||||
VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName());
|
||||
}
|
||||
|
||||
// Save to disk
|
||||
try {
|
||||
File warzoneConfigFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".yml");
|
||||
warzoneYmlConfig.save(warzoneConfigFile);
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to save warzone-" + warzone.getName() + ".yml", Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static int toIntYaw(float yaw) {
|
||||
int intYaw = 0;
|
||||
if (yaw >= 0) {
|
||||
intYaw = (int) (yaw % 360);
|
||||
} else {
|
||||
intYaw = (int) (360 + (yaw % 360));
|
||||
}
|
||||
return intYaw;
|
||||
}
|
||||
|
||||
public static void delete(String name) {
|
||||
File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name);
|
||||
File[] files = zoneFolder.listFiles();
|
||||
for (File file : files) {
|
||||
boolean deletedData = file.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + file.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
boolean deletedData = zoneFolder.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
|
||||
}
|
||||
File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||
if (zoneFile.exists()) {
|
||||
deletedData = zoneFile.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml");
|
||||
deletedData = zoneFile.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,443 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.jobs.DeferredBlockResetsJob;
|
||||
import com.tommytony.war.jobs.ZoneVolumeSaveJob;
|
||||
import com.tommytony.war.utils.DeferredBlockReset;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package com.tommytony.war.mappers
|
||||
*/
|
||||
public class ZoneVolumeMapper {
|
||||
|
||||
/**
|
||||
* Loads the given volume
|
||||
*
|
||||
* @param ZoneVolume
|
||||
* volume Volume to load
|
||||
* @param String
|
||||
* zoneName Zone to load the volume from
|
||||
* @param World
|
||||
* world The world the zone is located
|
||||
* @param boolean onlyLoadCorners Should only the corners be loaded
|
||||
* @return integer Changed blocks
|
||||
*/
|
||||
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
|
||||
File cornersFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners");
|
||||
File blocksFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks");
|
||||
File signsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".signs");
|
||||
File invsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".invs");
|
||||
int noOfResetBlocks = 0;
|
||||
if (!blocksFile.exists()) {
|
||||
// The post 1.6 formatted files haven't been created yet so
|
||||
// we need to use the old load.
|
||||
noOfResetBlocks = PreDeGaulleZoneVolumeMapper.load(volume, zoneName, world, onlyLoadCorners);
|
||||
|
||||
// The new 1.6 files aren't created yet. We just reset the zone (except deferred blocks which will soon execute on main thread ),
|
||||
// so let's save to the new format as soon as the zone is fully reset.
|
||||
ZoneVolumeMapper.saveAsJob(volume, zoneName, 2);
|
||||
War.war.log("Warzone " + zoneName + " file converted!", Level.INFO);
|
||||
|
||||
return noOfResetBlocks;
|
||||
} else {
|
||||
// 1.6 file exist, so go ahead with reset
|
||||
BufferedReader cornersReader = null;
|
||||
FileInputStream blocksStream = null;
|
||||
BufferedReader signsReader = null;
|
||||
BufferedReader invsReader = null;
|
||||
try {
|
||||
cornersReader = new BufferedReader(new FileReader(cornersFile));
|
||||
blocksStream = new FileInputStream(blocksFile);
|
||||
signsReader = new BufferedReader(new FileReader(signsFile));
|
||||
invsReader = new BufferedReader(new FileReader(invsFile));
|
||||
|
||||
// Get the corners
|
||||
cornersReader.readLine();
|
||||
int x1 = Integer.parseInt(cornersReader.readLine());
|
||||
int y1 = Integer.parseInt(cornersReader.readLine());
|
||||
int z1 = Integer.parseInt(cornersReader.readLine());
|
||||
cornersReader.readLine();
|
||||
int x2 = Integer.parseInt(cornersReader.readLine());
|
||||
int y2 = Integer.parseInt(cornersReader.readLine());
|
||||
int z2 = Integer.parseInt(cornersReader.readLine());
|
||||
|
||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
// Allocate block byte arrays
|
||||
int noOfBlocks = volume.getSizeX() * volume.getSizeY() * volume.getSizeZ();
|
||||
byte[] blockBytes = new byte[noOfBlocks * 2]; // one byte for type, one for data
|
||||
|
||||
blocksStream.read(blockBytes); // read it all
|
||||
|
||||
// Now use the block bytes to reset the world blocks
|
||||
if (!onlyLoadCorners) {
|
||||
DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world);
|
||||
int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0;
|
||||
int diskBlockType;
|
||||
byte diskBlockData;
|
||||
Block worldBlock;
|
||||
int worldBlockId;
|
||||
volume.clearBlocksThatDontFloat();
|
||||
x = volume.getMinX();
|
||||
for (i = 0; i < volume.getSizeX(); i++) {
|
||||
y = volume.getMinY();
|
||||
for (j = 0; j < volume.getSizeY(); j++) {
|
||||
z = volume.getMinZ();
|
||||
for (k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
diskBlockType = blockBytes[visitedBlocks * 2];
|
||||
diskBlockData = blockBytes[visitedBlocks * 2 + 1];
|
||||
|
||||
worldBlock = volume.getWorld().getBlockAt(x, y, z);
|
||||
worldBlockId = worldBlock.getTypeId();
|
||||
if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) {
|
||||
if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) {
|
||||
// Signs read
|
||||
String linesStr = signsReader.readLine();
|
||||
String[] lines = linesStr.split(";;");
|
||||
|
||||
// Signs set
|
||||
if (diskBlockType == Material.WALL_SIGN.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) {
|
||||
// A sign post hanging on a wall south of here needs that block to be set first
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
|
||||
} else {
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
BlockState state = worldBlock.getState();
|
||||
state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData));
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if (lines != null && sign.getLines() != null) {
|
||||
if (lines.length > 0) {
|
||||
sign.setLine(0, lines[0]);
|
||||
}
|
||||
if (lines.length > 1) {
|
||||
sign.setLine(1, lines[1]);
|
||||
}
|
||||
if (lines.length > 2) {
|
||||
sign.setLine(2, lines[2]);
|
||||
}
|
||||
if (lines.length > 3) {
|
||||
sign.setLine(3, lines[3]);
|
||||
}
|
||||
sign.update(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.CHEST.getId()) {
|
||||
// Chests read
|
||||
List<ItemStack> items = VolumeMapper.readInventoryString(invsReader.readLine());
|
||||
|
||||
// Chests set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof Chest) {
|
||||
Chest chest = (Chest) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
chest.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
chest.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
chest.update(true);
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.DISPENSER.getId()) {
|
||||
// Dispensers read
|
||||
List<ItemStack> items = VolumeMapper.readInventoryString(invsReader.readLine());
|
||||
|
||||
// Dispensers set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof Dispenser) {
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
dispenser.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
dispenser.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
dispenser.update(true);
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) {
|
||||
// Door blocks
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
|
||||
} else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) {
|
||||
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
|
||||
// Change the block itself later on:
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
|
||||
} else {
|
||||
// regular block
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
}
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
visitedBlocks++;
|
||||
|
||||
blockReads++;
|
||||
|
||||
} catch (Exception e) {
|
||||
War.war.getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
if (!deferred.isEmpty()) {
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 2);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
War.war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (cornersReader != null) {
|
||||
cornersReader.close();
|
||||
}
|
||||
if (blocksStream != null) {
|
||||
blocksStream.close();
|
||||
}
|
||||
if (signsReader != null) {
|
||||
signsReader.close();
|
||||
}
|
||||
if (invsReader != null) {
|
||||
invsReader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the given volume
|
||||
*
|
||||
* @param Volume
|
||||
* volume Volume to save
|
||||
* @param String
|
||||
* zoneName The warzone the volume is located
|
||||
* @return integer Number of written blocks
|
||||
*/
|
||||
public static int save(Volume volume, String zoneName) {
|
||||
int noOfSavedBlocks = 0;
|
||||
if (volume.hasTwoCorners()) {
|
||||
BufferedWriter cornersWriter = null;
|
||||
FileOutputStream blocksOutput = null;
|
||||
BufferedWriter signsWriter = null;
|
||||
BufferedWriter invsWriter = null;
|
||||
try {
|
||||
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
|
||||
String path = War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName();
|
||||
cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners")));
|
||||
blocksOutput = new FileOutputStream(new File(path + ".blocks"));
|
||||
signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs")));
|
||||
invsWriter = new BufferedWriter(new FileWriter(new File(path + ".invs")));
|
||||
|
||||
cornersWriter.write("corner1");
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getX()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getY()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getZ()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write("corner2");
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getX()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getY()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getZ()));
|
||||
cornersWriter.newLine();
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
Block block;
|
||||
int typeId;
|
||||
byte data;
|
||||
BlockState state;
|
||||
|
||||
x = volume.getMinX();
|
||||
for (int i = 0; i < volume.getSizeX(); i++) {
|
||||
y = volume.getMinY();
|
||||
for (int j = 0; j < volume.getSizeY(); j++) {
|
||||
z = volume.getMinZ();
|
||||
for (int k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
block = volume.getWorld().getBlockAt(x, y, z);
|
||||
typeId = block.getTypeId();
|
||||
data = block.getData();
|
||||
state = block.getState();
|
||||
|
||||
blocksOutput.write((byte) typeId);
|
||||
blocksOutput.write(data);
|
||||
|
||||
if (state instanceof Sign) {
|
||||
// Signs
|
||||
String extra = "";
|
||||
Sign sign = (Sign) state;
|
||||
if (sign.getLines() != null) {
|
||||
for (String line : sign.getLines()) {
|
||||
extra += line + ";;";
|
||||
}
|
||||
signsWriter.write(extra);
|
||||
signsWriter.newLine();
|
||||
}
|
||||
} else if (state instanceof Chest) {
|
||||
// Chests
|
||||
Chest chest = (Chest) state;
|
||||
Inventory inv = chest.getInventory();
|
||||
List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
|
||||
invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items));
|
||||
invsWriter.newLine();
|
||||
} else if (state instanceof Dispenser) {
|
||||
// Dispensers
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
Inventory inv = dispenser.getInventory();
|
||||
List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
|
||||
invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items));
|
||||
invsWriter.newLine();
|
||||
}
|
||||
noOfSavedBlocks++;
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (cornersWriter != null) {
|
||||
cornersWriter.close();
|
||||
}
|
||||
if (blocksOutput != null) {
|
||||
blocksOutput.close();
|
||||
}
|
||||
if (signsWriter != null) {
|
||||
signsWriter.close();
|
||||
}
|
||||
if (invsWriter != null) {
|
||||
invsWriter.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return noOfSavedBlocks;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Saves the Volume as a background-job
|
||||
*
|
||||
* @param ZoneVolme
|
||||
* volume volume to save
|
||||
* @param String
|
||||
* zoneName The zone the volume is located
|
||||
* @param War
|
||||
* war Instance of war
|
||||
* @param long tickDelay delay before beginning the task
|
||||
*/
|
||||
private static void saveAsJob(ZoneVolume volume, String zoneName, long tickDelay) {
|
||||
ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName);
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given volume
|
||||
*
|
||||
* @param Volume
|
||||
* volume volume to delete
|
||||
* @param War
|
||||
* war Instance of war
|
||||
*/
|
||||
public static void delete(Volume volume) {
|
||||
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat");
|
||||
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".corners");
|
||||
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".blocks");
|
||||
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".signs");
|
||||
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".invs");
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a volume file
|
||||
*
|
||||
* @param String
|
||||
* path path of file
|
||||
* @param War
|
||||
* war Instance of war
|
||||
*/
|
||||
private static void deleteFile(String path) {
|
||||
File volFile = new File(path);
|
||||
if (volFile.exists()) {
|
||||
boolean deletedData = volFile.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
package com.tommytony.war.utils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* The purpose of this tool is twofold: 1: Avoid client crashes due to bad color formating. 2: Make color continue on word wrapping
|
||||
*
|
||||
* In minecraft the degree sign is used as a prefix to another char to create a color. For example the code for white is "\u00A7f". The "\u00A7" is the unicode notation for the degree sign and the "f" means white.
|
||||
*
|
||||
* When does minecraft wrap the text? After how many chars? Answer: Because the font isn't monospace this differs depending on what you write. However we can fit 53 "M" without wrapping and the 54th char would then wrap (be at the beginning of the next line instead) As there is no broader char than "M" we can know for sure the minimum line length is 53. Note that this means the number of DISPLAYED chars per row is 53. A degree sign and the char after will NOT count, as they will not be displayed as chars.
|
||||
*
|
||||
* Good to know: Numbers have the same font width as an M.
|
||||
*
|
||||
* When does the client crash? Answer: When a row ends with a degree char and optionally another sign after. Another way to say the same: When a line ends with either a broken or valid color notation. AND The client will ALWAYS crash if the sign after the last displayed char in a row is a degree char. A goofy way to explatin it: For a line with only "M" and numbers, the fiftyfourth "displayed char" musn't be a degree sign.
|
||||
*
|
||||
* WARNING: Above is a hypothesis I have created based on what my experiments have shown. I am fairly sure it is correct but please help me test it further.
|
||||
*/
|
||||
public class ChatFixUtil {
|
||||
public final static char deg = '\u00A7';
|
||||
public final static int lineLength = 53;
|
||||
|
||||
/**
|
||||
* This method wraps the msg for you at row lengths of 53, avoids client crash scenarios and makes the previous color continue on the next line.
|
||||
*
|
||||
* The upsides with filtering your messages through this method are: - No client crashes. - Line wrapping with preserved color.
|
||||
*
|
||||
* The downsides are: - The width of the chat window will not be used to it's fullest. For example you can fit more that 53 commas (,) in a chatwindow row but the line would break after 53 displayed chars.
|
||||
*
|
||||
* Suggested usage: NO NEED TO USE the fix method for static help pages in your plugin. As the text is static you can make sure there is no client crash yourself and be able to use the full line length.
|
||||
*
|
||||
* DO USE in cases like where you output colored messages with playernames in your plugin. As the player names have different length there is potential for client crash.
|
||||
*/
|
||||
public static ArrayList<String> fix(String msg) {
|
||||
// Make sure the end of msg is good
|
||||
msg = ChatFixUtil.cleanMsgEnding(msg);
|
||||
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
int displen = 0; // The number of displayed chars in row so far.
|
||||
String row = "";
|
||||
String latestColor = null;
|
||||
|
||||
for (int i = 0; i < msg.length(); i++) {
|
||||
if (displen == ChatFixUtil.lineLength) {
|
||||
// it is time to start on the next row!
|
||||
ret.add(row);
|
||||
displen = 0;
|
||||
row = "";
|
||||
if (latestColor != null) {
|
||||
row += ChatFixUtil.deg + latestColor;
|
||||
}
|
||||
}
|
||||
char c = msg.charAt(i);
|
||||
|
||||
if (c == ChatFixUtil.deg) {
|
||||
latestColor = String.valueOf(msg.charAt(i + 1));
|
||||
row += ChatFixUtil.deg + latestColor;
|
||||
i++;
|
||||
} else {
|
||||
displen += 1;
|
||||
row += c;
|
||||
}
|
||||
}
|
||||
ret.add(row);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ArrayList<String> fix(List<String> messages) {
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
for (String message : messages) {
|
||||
ret.addAll(ChatFixUtil.fix(message));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the ending chars as long as they are deg or deg+'anychar' or a space As I see it we would never want those chars at the end of a msg.
|
||||
*/
|
||||
protected static String cleanMsgEnding(String msg) {
|
||||
|
||||
while (msg.length() > 0) {
|
||||
if (msg.endsWith(String.valueOf(ChatFixUtil.deg)) || msg.endsWith(" ")) {
|
||||
msg = msg.substring(0, msg.length() - 1);
|
||||
} else if (msg.length() >= 2 && msg.charAt(msg.length() - 2) == ChatFixUtil.deg) {
|
||||
msg = msg.substring(0, msg.length() - 2);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* This test util assumes line break after 53 displayed chars. The fix method above breaks like that so this method should be a valid way to test if a message row would crash a client.
|
||||
*/
|
||||
public static String thisMsgWouldCrashClient(String str) {
|
||||
// There would always be crash if we end with deg or deg+'anychar'
|
||||
if (str.length() >= 1 && str.charAt(str.length() - 1) == ChatFixUtil.deg) {
|
||||
return "Crash: The str ends with deg.";
|
||||
} else if (str.length() >= 2 && str.charAt(str.length() - 2) == ChatFixUtil.deg) {
|
||||
return "Crash: The str ends with deg+'anychar'.";
|
||||
}
|
||||
|
||||
int displayedChars = 0;
|
||||
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c == ChatFixUtil.deg && displayedChars == ChatFixUtil.lineLength) {
|
||||
return "Crash: Deg as fiftyforth \"displayed\" char";
|
||||
} else if (c == ChatFixUtil.deg) {
|
||||
i++; // this and next: they are not displayed... skip them...
|
||||
} else {
|
||||
displayedChars += 1;
|
||||
}
|
||||
}
|
||||
return "all ok";
|
||||
}
|
||||
|
||||
// ----------------------------------------------//
|
||||
// Methods for effectively sending messages
|
||||
// ----------------------------------------------//
|
||||
// ----------------------------------------------//
|
||||
// One player
|
||||
// ----------------------------------------------//
|
||||
public static void sendMessage(CommandSender player, String message, boolean fix) {
|
||||
if (fix) {
|
||||
List<String> messages = ChatFixUtil.fix(message);
|
||||
ChatFixUtil.sendMessage(player, messages, false);
|
||||
} else {
|
||||
if (player != null) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender player, List<String> messages, boolean fix) {
|
||||
if (fix) {
|
||||
messages = ChatFixUtil.fix(messages);
|
||||
}
|
||||
for (String message : messages) {
|
||||
ChatFixUtil.sendMessage(player, message, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender player, String message) {
|
||||
ChatFixUtil.sendMessage(player, message, true);
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender player, List<String> messages) {
|
||||
ChatFixUtil.sendMessage(player, messages, true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------//
|
||||
// Many CommandSenders
|
||||
// ----------------------------------------------//
|
||||
public static void sendMessage(Collection<CommandSender> players, String message, boolean fix) {
|
||||
if (fix) {
|
||||
List<String> messages = ChatFixUtil.fix(message);
|
||||
ChatFixUtil.sendMessage(players, messages, false);
|
||||
} else {
|
||||
for (CommandSender player : players) {
|
||||
ChatFixUtil.sendMessage(player, message, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(Collection<CommandSender> players, List<String> messages, boolean fix) {
|
||||
if (fix) {
|
||||
messages = ChatFixUtil.fix(messages);
|
||||
}
|
||||
|
||||
for (String message : messages) {
|
||||
ChatFixUtil.sendMessage(players, message, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(Collection<CommandSender> players, String message) {
|
||||
ChatFixUtil.sendMessage(players, message, true);
|
||||
}
|
||||
|
||||
public static void sendMessage(Collection<CommandSender> players, List<String> messages) {
|
||||
ChatFixUtil.sendMessage(players, messages, true);
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package com.tommytony.war.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class DeferredBlockReset {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final int blockType;
|
||||
private final byte blockData;
|
||||
private String[] lines;
|
||||
private List<ItemStack> items;
|
||||
private Byte rawNote;
|
||||
|
||||
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.blockType = blockType;
|
||||
this.blockData = blockData;
|
||||
}
|
||||
|
||||
// Signs
|
||||
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, String[] signLines) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.blockType = blockType;
|
||||
this.blockData = blockData;
|
||||
this.lines = signLines;
|
||||
}
|
||||
|
||||
// Container block
|
||||
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, List<ItemStack> contents) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.blockType = blockType;
|
||||
this.blockData = blockData;
|
||||
this.items = contents;
|
||||
}
|
||||
|
||||
// Noteblock
|
||||
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, byte rawNote) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.blockType = blockType;
|
||||
this.blockData = blockData;
|
||||
this.rawNote = rawNote;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getBlockType() {
|
||||
return this.blockType;
|
||||
}
|
||||
|
||||
public byte getBlockData() {
|
||||
return this.blockData;
|
||||
}
|
||||
|
||||
public String[] getLines() {
|
||||
return this.lines;
|
||||
}
|
||||
|
||||
public List<ItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public Byte getRawNote() {
|
||||
return rawNote;
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
package com.tommytony.war.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.tommytony.war.PotionEffect;
|
||||
|
||||
public class PlayerState {
|
||||
private ItemStack[] contents;
|
||||
private ItemStack helmet;
|
||||
private ItemStack chest;
|
||||
private ItemStack legs;
|
||||
private ItemStack feet;
|
||||
private final float exhaustion;
|
||||
private final float saturation;
|
||||
private final int foodLevel;
|
||||
private final int health;
|
||||
private final GameMode gamemode;
|
||||
private final List<PotionEffect> potionEffects;
|
||||
private final String playerTitle;
|
||||
|
||||
public PlayerState(GameMode gamemode, ItemStack[] contents, ItemStack helmet, ItemStack chest, ItemStack legs, ItemStack feet, int health, float exhaustion, float saturation, int foodLevel, List<PotionEffect> potionEffects, String playerTitle) {
|
||||
this.gamemode = gamemode;
|
||||
this.health = health;
|
||||
this.exhaustion = exhaustion;
|
||||
this.saturation = saturation;
|
||||
this.foodLevel = foodLevel;
|
||||
this.potionEffects = potionEffects;
|
||||
this.playerTitle = playerTitle;
|
||||
this.setContents(contents);
|
||||
this.setHelmet(helmet);
|
||||
this.setChest(chest);
|
||||
this.setLegs(legs);
|
||||
this.setFeet(feet);
|
||||
}
|
||||
|
||||
public void setContents(ItemStack[] contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public ItemStack[] getContents() {
|
||||
return this.contents;
|
||||
}
|
||||
|
||||
public void setHelmet(ItemStack helmet) {
|
||||
this.helmet = helmet;
|
||||
}
|
||||
|
||||
public ItemStack getHelmet() {
|
||||
return this.helmet;
|
||||
}
|
||||
|
||||
public void setChest(ItemStack chest) {
|
||||
this.chest = chest;
|
||||
}
|
||||
|
||||
public ItemStack getChest() {
|
||||
return this.chest;
|
||||
}
|
||||
|
||||
public void setLegs(ItemStack legs) {
|
||||
this.legs = legs;
|
||||
}
|
||||
|
||||
public ItemStack getLegs() {
|
||||
return this.legs;
|
||||
}
|
||||
|
||||
public void setFeet(ItemStack feet) {
|
||||
this.feet = feet;
|
||||
}
|
||||
|
||||
public ItemStack getFeet() {
|
||||
return this.feet;
|
||||
}
|
||||
|
||||
public float getExhaustion() {
|
||||
return exhaustion;
|
||||
}
|
||||
|
||||
public float getSaturation() {
|
||||
return saturation;
|
||||
}
|
||||
|
||||
public int getFoodLevel() {
|
||||
return foodLevel;
|
||||
}
|
||||
|
||||
public int getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public GameMode getGamemode() {
|
||||
return gamemode;
|
||||
}
|
||||
|
||||
public List<PotionEffect> getPotionEffects() {
|
||||
return potionEffects;
|
||||
}
|
||||
|
||||
public String getPlayerTitle() {
|
||||
return playerTitle;
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.tommytony.war.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
public class SignHelper {
|
||||
|
||||
public static void setToSign(War war, Block block, byte data, String[] lines) {
|
||||
if (block.getType() != Material.SIGN_POST) {
|
||||
block.setType(Material.SIGN_POST);
|
||||
}
|
||||
try {
|
||||
BlockState state = block.getState();
|
||||
state.setData(new org.bukkit.material.Sign(Material.SIGN_POST, data));
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
|
||||
if (sign.getLines() != null) {
|
||||
sign.setLine(0, lines[0]);
|
||||
sign.setLine(1, lines[1]);
|
||||
sign.setLine(2, lines[2]);
|
||||
sign.setLine(3, lines[3]);
|
||||
sign.update(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// just can't stand this anymore
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class BlockInfo {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int type;
|
||||
private byte data;
|
||||
|
||||
// private String[] signLines;
|
||||
|
||||
public static Block getBlock(World world, BlockInfo info) {
|
||||
return world.getBlockAt(info.getX(), info.getY(), info.getZ());
|
||||
}
|
||||
|
||||
public BlockInfo(int x, int y, int z, int type, byte data) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public BlockInfo(Block block) {
|
||||
this.x = block.getX();
|
||||
this.y = block.getY();
|
||||
this.z = block.getZ();
|
||||
this.type = block.getTypeId();
|
||||
this.data = block.getData();
|
||||
// if (is(Material.SIGN) || is(Material.SIGN_POST)) {
|
||||
// Sign sign = (Sign)block.getState();
|
||||
// this.signLines = sign.getLines();
|
||||
// }
|
||||
}
|
||||
|
||||
// public BlockInfo(BlockState blockState) {
|
||||
// this.x = blockState.getX();
|
||||
// this.y = blockState.getY();
|
||||
// this.z = blockState.getZ();
|
||||
// this.type = blockState.getTypeId();
|
||||
// this.data = blockState.getData().getData();
|
||||
// // if (is(Material.SIGN) || is(Material.SIGN_POST)) {
|
||||
// // Sign sign = (Sign)blockState;
|
||||
// // this.signLines = sign.getLines();
|
||||
// // }
|
||||
// }
|
||||
|
||||
// public BlockInfo(int typeID, byte data, String[] lines) {
|
||||
// type = typeID;
|
||||
// this.data = data;
|
||||
// //signLines = lines;
|
||||
// }
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
// letting us mutate the BlockInfos might be a bad idea; use setters with care
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setZ(int z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public Material getType() {
|
||||
return Material.getMaterial(this.type);
|
||||
}
|
||||
|
||||
public byte getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public boolean is(Material material) {
|
||||
return this.getType() == material;
|
||||
}
|
||||
|
||||
// public String[] getSignLines() {
|
||||
// if (is(Material.SIGN) || is(Material.SIGN_POST)){
|
||||
// return new String[4] {"", ""};
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
* @deprecated Broken, don't use.
|
||||
*/
|
||||
@Deprecated
|
||||
public class CenteredVolume extends Volume {
|
||||
|
||||
private Block center;
|
||||
private int sideSize = -1;
|
||||
private final World world;
|
||||
|
||||
public CenteredVolume(String name, Block center, int sideSize, World world) {
|
||||
super(name, world);
|
||||
this.world = world;
|
||||
this.setCenter(center);
|
||||
this.setSideSize(sideSize);
|
||||
}
|
||||
|
||||
public void changeCenter(Location newCenter) {
|
||||
this.changeCenter(this.world.getBlockAt(newCenter.getBlockX(), newCenter.getBlockY(), newCenter.getBlockZ()), this.sideSize);
|
||||
}
|
||||
|
||||
public void changeCenter(Block newCenter, int sideSize) {
|
||||
this.resetBlocks();
|
||||
this.center = newCenter;
|
||||
this.sideSize = sideSize;
|
||||
this.calculateCorners();
|
||||
}
|
||||
|
||||
public void setCenter(Block block) {
|
||||
this.center = block;
|
||||
}
|
||||
|
||||
public void calculateCorners() {
|
||||
int topHalfOfSide = this.sideSize / 2;
|
||||
|
||||
int x = this.center.getX() + topHalfOfSide;
|
||||
int y = this.center.getY() + topHalfOfSide;
|
||||
int z = this.center.getZ() + topHalfOfSide;
|
||||
Block cornerOne = this.world.getBlockAt(x, y, z);
|
||||
this.setCornerOne(cornerOne);
|
||||
|
||||
if (this.sideSize % 2 == 0) { // not a real center, bottom half is larger by 1
|
||||
int bottomHalfOfSide = this.sideSize - topHalfOfSide;
|
||||
x = this.center.getX() - bottomHalfOfSide;
|
||||
y = this.center.getY() - bottomHalfOfSide;
|
||||
z = this.center.getZ() - bottomHalfOfSide;
|
||||
Block cornerTwo = this.world.getBlockAt(x, y, z);
|
||||
this.setCornerTwo(cornerTwo);
|
||||
} else {
|
||||
x = this.center.getX() - topHalfOfSide;
|
||||
y = this.center.getY() - topHalfOfSide;
|
||||
z = this.center.getZ() - topHalfOfSide;
|
||||
Block cornerTwo = this.world.getBlockAt(x, y, z);
|
||||
this.setCornerTwo(cornerTwo);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSideSize(int sideSize) {
|
||||
this.sideSize = sideSize;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
public class NotNorthwestException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5736463256274556866L;
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
public class NotSoutheastException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4347064837067648341L;
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
public class TooBigException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 61793179891881015L;
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
public class TooSmallException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1641366536434076088L;
|
||||
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class VerticalVolume extends Volume {
|
||||
|
||||
public VerticalVolume(String name, World world) {
|
||||
super(name, world);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCornerOne(Block block) {
|
||||
// corner one defaults to topmost corner
|
||||
Block topBlock = this.getWorld().getBlockAt(block.getX(), 127, block.getZ());
|
||||
super.setCornerOne(topBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCornerTwo(Block block) {
|
||||
// corner two defaults to bottom most corner
|
||||
Block bottomBlock = this.getWorld().getBlockAt(block.getX(), 0, block.getZ());
|
||||
super.setCornerTwo(bottomBlock);
|
||||
}
|
||||
|
||||
public boolean isWallBlock(Block block) {
|
||||
return this.isEastWallBlock(block) || this.isNorthWallBlock(block) || this.isSouthWallBlock(block) || this.isWestWallBlock(block);
|
||||
}
|
||||
|
||||
public boolean isEastWallBlock(Block block) {
|
||||
if (this.getMinZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) {
|
||||
return true; // east wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSouthWallBlock(Block block) {
|
||||
if (this.getMaxX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) {
|
||||
return true; // south wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isNorthWallBlock(Block block) {
|
||||
if (this.getMinX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) {
|
||||
return true; // north wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isWestWallBlock(Block block) {
|
||||
if (this.getMaxZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) {
|
||||
return true; // west wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int resetWallBlocks(BlockFace wall) {
|
||||
int noOfResetBlocks = 0;
|
||||
try {
|
||||
if (this.hasTwoCorners() && this.getBlockTypes() != null) {
|
||||
if (wall == BlockFace.EAST) {
|
||||
int z = this.getMinZ();
|
||||
int k = 0;
|
||||
int y = this.getMinY();
|
||||
for (int j = 0; j < this.getSizeY(); j++) {
|
||||
int x = this.getMinX();
|
||||
for (int i = 0; i < this.getSizeX(); i++) {
|
||||
int oldBlockType = this.getBlockTypes()[i][j][k];
|
||||
byte oldBlockData = this.getBlockDatas()[i][j][k];
|
||||
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
|
||||
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
} else if (wall == BlockFace.WEST) {
|
||||
int z = this.getMaxZ();
|
||||
int k = this.getSizeZ() - 1;
|
||||
int y = this.getMinY();
|
||||
for (int j = 0; j < this.getSizeY(); j++) {
|
||||
int x = this.getMinX();
|
||||
for (int i = 0; i < this.getSizeX(); i++) {
|
||||
int oldBlockType = this.getBlockTypes()[i][j][k];
|
||||
byte oldBlockData = this.getBlockDatas()[i][j][k];
|
||||
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
|
||||
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
} else if (wall == BlockFace.NORTH) {
|
||||
int x = this.getMinX();
|
||||
int i = 0;
|
||||
int y = this.getMinY();
|
||||
for (int j = 0; j < this.getSizeY(); j++) {
|
||||
int z = this.getMinZ();
|
||||
for (int k = 0; k < this.getSizeZ(); k++) {
|
||||
int oldBlockType = this.getBlockTypes()[i][j][k];
|
||||
byte oldBlockData = this.getBlockDatas()[i][j][k];
|
||||
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
|
||||
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
} else if (wall == BlockFace.SOUTH) {
|
||||
int x = this.getMaxX();
|
||||
int i = this.getSizeX() - 1;
|
||||
int y = this.getMinY();
|
||||
for (int j = 0; j < this.getSizeY(); j++) {
|
||||
int z = this.getMinZ();
|
||||
for (int k = 0; k < this.getSizeZ(); k++) {
|
||||
int oldBlockType = this.getBlockTypes()[i][j][k];
|
||||
byte oldBlockData = this.getBlockDatas()[i][j][k];
|
||||
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
|
||||
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
War.war.log("Failed to reset wall " + wall + " in volume " + this.getName() + ". " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
|
||||
private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) {
|
||||
if (currentBlock.getTypeId() != oldBlockType || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()))) {
|
||||
currentBlock.setTypeId(oldBlockType);
|
||||
currentBlock.setData(oldBlockData);
|
||||
// if (oldBlockInfo.is(Material.SIGN) || oldBlockInfo.is(Material.SIGN_POST)) {
|
||||
// BlockState state = currentBlock.getState();
|
||||
// Sign currentSign = (Sign) state;
|
||||
// currentSign.setLine(0, oldBlockInfo.getSignLines()[0]);
|
||||
// currentSign.setLine(1, oldBlockInfo.getSignLines()[0]);
|
||||
// currentSign.setLine(2, oldBlockInfo.getSignLines()[0]);
|
||||
// currentSign.setLine(3, oldBlockInfo.getSignLines()[0]);
|
||||
// state.update();
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,563 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.jobs.BlockResetJob;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class Volume {
|
||||
private final String name;
|
||||
private World world;
|
||||
// private final Warzone warzone;
|
||||
private BlockInfo cornerOne;
|
||||
private BlockInfo cornerTwo;
|
||||
private int[][][] blockTypes = null;
|
||||
private byte[][][] blockDatas = null;
|
||||
private HashMap<String, String[]> signLines = new HashMap<String, String[]>();
|
||||
private HashMap<String, List<ItemStack>> invBlockContents = new HashMap<String, List<ItemStack>>();
|
||||
|
||||
public Volume(String name, World world) {
|
||||
this.name = name;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public boolean hasTwoCorners() {
|
||||
return this.cornerOne != null && this.cornerTwo != null;
|
||||
}
|
||||
|
||||
public void setCornerOne(Block block) {
|
||||
this.cornerOne = new BlockInfo(block);
|
||||
}
|
||||
|
||||
public void setCornerOne(BlockInfo blockInfo) {
|
||||
this.cornerOne = blockInfo;
|
||||
}
|
||||
|
||||
public int saveBlocks() {
|
||||
// BlockSaveJob job = new BlockSaveJob(this);
|
||||
// war.getServer().getScheduler().scheduleSyncDelayedTask(war, job);
|
||||
// return 0;
|
||||
int noOfSavedBlocks = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
try {
|
||||
if (this.hasTwoCorners()) {
|
||||
this.setBlockTypes(new int[this.getSizeX()][this.getSizeY()][this.getSizeZ()]);
|
||||
this.setBlockDatas(new byte[this.getSizeX()][this.getSizeY()][this.getSizeZ()]);
|
||||
this.getSignLines().clear();
|
||||
this.getInvBlockContents().clear();
|
||||
x = this.getMinX();
|
||||
for (int i = 0; i < this.getSizeX(); i++) {
|
||||
y = this.getMinY();
|
||||
for (int j = 0; j < this.getSizeY(); j++) {
|
||||
z = this.getMinZ();
|
||||
for (int k = 0; k < this.getSizeZ(); k++) {
|
||||
try {
|
||||
Block block = this.getWorld().getBlockAt(x, y, z);
|
||||
this.getBlockTypes()[i][j][k] = block.getTypeId();
|
||||
this.getBlockDatas()[i][j][k] = block.getData();
|
||||
BlockState state = block.getState();
|
||||
if (state instanceof Sign) {
|
||||
// Signs
|
||||
Sign sign = (Sign) state;
|
||||
if (sign.getLines() != null) {
|
||||
this.getSignLines().put("sign-" + i + "-" + j + "-" + k, sign.getLines());
|
||||
}
|
||||
|
||||
} else if (state instanceof Chest) {
|
||||
// Chests
|
||||
Chest chest = (Chest) state;
|
||||
Inventory inv = chest.getInventory();
|
||||
int size = inv.getSize();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (int invIndex = 0; invIndex < size; invIndex++) {
|
||||
ItemStack item = inv.getItem(invIndex);
|
||||
if (item != null && item.getType().getId() != Material.AIR.getId()) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
this.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items);
|
||||
} else if (state instanceof Dispenser) {
|
||||
// Dispensers
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
Inventory inv = dispenser.getInventory();
|
||||
int size = inv.getSize();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (int invIndex = 0; invIndex < size; invIndex++) {
|
||||
ItemStack item = inv.getItem(invIndex);
|
||||
if (item != null && item.getType().getId() != Material.AIR.getId()) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
this.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items);
|
||||
}
|
||||
|
||||
noOfSavedBlocks++;
|
||||
} catch (Exception e) {
|
||||
War.war.getLogger().warning("Failed to save block in volume " + this.getName() + ". Saved blocks so far:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
War.war.getLogger().warning("Failed to save volume " + this.getName() + " blocks. Saved blocks:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return noOfSavedBlocks;
|
||||
}
|
||||
|
||||
public void resetBlocksAsJob() {
|
||||
BlockResetJob job = new BlockResetJob(this);
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
|
||||
}
|
||||
|
||||
public int resetBlocks() {
|
||||
int visitedBlocks = 0, noOfResetBlocks = 0, x = 0, y = 0, z = 0;
|
||||
int currentBlockId = 0;
|
||||
int oldBlockType = 0;
|
||||
this.clearBlocksThatDontFloat();
|
||||
try {
|
||||
if (this.hasTwoCorners() && this.isSaved()) {
|
||||
x = this.getMinX();
|
||||
for (int i = 0; i < this.getSizeX(); i++) {
|
||||
y = this.getMinY();
|
||||
for (int j = 0; j < this.getSizeY(); j++) {
|
||||
z = this.getMinZ();
|
||||
for (int k = 0; k < this.getSizeZ(); k++) {
|
||||
try {
|
||||
oldBlockType = this.getBlockTypes()[i][j][k];
|
||||
byte oldBlockData = this.getBlockDatas()[i][j][k];
|
||||
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
|
||||
currentBlockId = currentBlock.getTypeId();
|
||||
if (currentBlockId != oldBlockType || (currentBlockId == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlockId == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId() || oldBlockType == Material.CHEST.getId() || oldBlockType == Material.DISPENSER.getId()))) {
|
||||
if (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()) {
|
||||
// Signs
|
||||
if (oldBlockType == Material.SIGN_POST.getId() && ((oldBlockData & 0x04) == 0x04) && i + 1 != this.getSizeX()) {
|
||||
Block southBlock = currentBlock.getRelative(BlockFace.SOUTH);
|
||||
int oldSouthBlockType = this.getBlockTypes()[i + 1][j][k];
|
||||
byte oldSouthBlockData = this.getBlockDatas()[i + 1][j][k];
|
||||
if (southBlock.getTypeId() != oldSouthBlockType) {
|
||||
southBlock.setTypeId(oldSouthBlockType);
|
||||
southBlock.setData(oldSouthBlockData);
|
||||
}
|
||||
}
|
||||
currentBlock.setType(Material.getMaterial(oldBlockType));
|
||||
BlockState state = currentBlock.getState();
|
||||
state.setData(new org.bukkit.material.Sign(oldBlockType, oldBlockData));
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k);
|
||||
if (lines != null && sign.getLines() != null) {
|
||||
if (lines.length > 0) {
|
||||
sign.setLine(0, lines[0]);
|
||||
}
|
||||
if (lines.length > 1) {
|
||||
sign.setLine(1, lines[1]);
|
||||
}
|
||||
if (lines.length > 2) {
|
||||
sign.setLine(2, lines[2]);
|
||||
}
|
||||
if (lines.length > 3) {
|
||||
sign.setLine(3, lines[3]);
|
||||
}
|
||||
sign.update(true);
|
||||
}
|
||||
}
|
||||
} else if (oldBlockType == Material.CHEST.getId()) {
|
||||
// Chests
|
||||
currentBlock.setType(Material.getMaterial(oldBlockType));
|
||||
currentBlock.setData(oldBlockData);
|
||||
BlockState state = currentBlock.getState();
|
||||
if (state instanceof Chest) {
|
||||
Chest chest = (Chest) state;
|
||||
List<ItemStack> contents = this.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k);
|
||||
if (contents != null) {
|
||||
int ii = 0;
|
||||
chest.getInventory().clear();
|
||||
for (ItemStack item : contents) {
|
||||
if (item != null) {
|
||||
chest.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
chest.update(true);
|
||||
}
|
||||
}
|
||||
} else if (oldBlockType == Material.DISPENSER.getId()) {
|
||||
// Dispensers
|
||||
currentBlock.setType(Material.getMaterial(oldBlockType));
|
||||
currentBlock.setData(oldBlockData);
|
||||
BlockState state = currentBlock.getState();
|
||||
if (state instanceof Dispenser) {
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
List<ItemStack> contents = this.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k);
|
||||
if (contents != null) {
|
||||
int ii = 0;
|
||||
dispenser.getInventory().clear();
|
||||
for (ItemStack item : contents) {
|
||||
if (item != null) {
|
||||
dispenser.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
dispenser.update(true);
|
||||
}
|
||||
}
|
||||
} else if (oldBlockType == Material.WOODEN_DOOR.getId() || oldBlockType == Material.IRON_DOOR_BLOCK.getId()) {
|
||||
// Door blocks
|
||||
|
||||
// Check if is bottom door block
|
||||
if (j + 1 < this.getSizeY() && this.getBlockTypes()[i][j + 1][k] == oldBlockType) {
|
||||
// set both door blocks right away
|
||||
|
||||
Block blockAbove = this.getWorld().getBlockAt(x, y + 1, z);
|
||||
blockAbove.setType(Material.getMaterial(oldBlockType));
|
||||
blockAbove.setData(this.getBlockDatas()[i][j + 1][k]);
|
||||
|
||||
currentBlock.setType(Material.getMaterial(oldBlockType));
|
||||
currentBlock.setData(oldBlockData);
|
||||
}
|
||||
} else if (((oldBlockType == Material.TORCH.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.REDSTONE_TORCH_ON.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.LEVER.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.STONE_BUTTON.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.LADDER.getId() && ((oldBlockData & 0x04) == 0x04)) || (oldBlockType == Material.RAILS.getId() && ((oldBlockData & 0x02) == 0x02))) && i + 1 != this.getSizeX()) {
|
||||
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
|
||||
Block southBlock = currentBlock.getRelative(BlockFace.SOUTH);
|
||||
int oldSouthBlockType = this.getBlockTypes()[i + 1][j][k];
|
||||
byte oldSouthBlockData = this.getBlockDatas()[i + 1][j][k];
|
||||
if (southBlock.getTypeId() != oldSouthBlockType) {
|
||||
southBlock.setTypeId(oldSouthBlockType);
|
||||
southBlock.setData(oldSouthBlockData);
|
||||
}
|
||||
// change the block itself, now that we have a block to set it on
|
||||
currentBlock.setType(Material.getMaterial(oldBlockType));
|
||||
currentBlock.setData(oldBlockData);
|
||||
} else {
|
||||
// regular block
|
||||
currentBlock.setType(Material.getMaterial(oldBlockType));
|
||||
currentBlock.setData(oldBlockData);
|
||||
}
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
visitedBlocks++;
|
||||
} catch (Exception e) {
|
||||
War.war.getLogger().warning("Failed to reset block in volume " + this.getName() + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
War.war.log("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
|
||||
public byte[][][] getBlockDatas() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.blockDatas;
|
||||
}
|
||||
|
||||
public void setBlockDatas(byte[][][] data) {
|
||||
this.blockDatas = data;
|
||||
}
|
||||
|
||||
public void setCornerTwo(Block block) {
|
||||
this.cornerTwo = new BlockInfo(block);
|
||||
}
|
||||
|
||||
public void setCornerTwo(BlockInfo blockInfo) {
|
||||
this.cornerTwo = blockInfo;
|
||||
}
|
||||
|
||||
public BlockInfo getMinXBlock() {
|
||||
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
|
||||
return this.cornerOne;
|
||||
}
|
||||
return this.cornerTwo;
|
||||
}
|
||||
|
||||
public BlockInfo getMinYBlock() {
|
||||
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
|
||||
return this.cornerOne;
|
||||
}
|
||||
return this.cornerTwo;
|
||||
}
|
||||
|
||||
public BlockInfo getMinZBlock() {
|
||||
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
|
||||
return this.cornerOne;
|
||||
}
|
||||
return this.cornerTwo;
|
||||
}
|
||||
|
||||
public int getMinX() {
|
||||
return this.getMinXBlock().getX();
|
||||
}
|
||||
|
||||
public int getMinY() {
|
||||
return this.getMinYBlock().getY();
|
||||
}
|
||||
|
||||
public int getMinZ() {
|
||||
return this.getMinZBlock().getZ();
|
||||
}
|
||||
|
||||
public BlockInfo getMaxXBlock() {
|
||||
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
|
||||
return this.cornerTwo;
|
||||
}
|
||||
return this.cornerOne;
|
||||
}
|
||||
|
||||
public BlockInfo getMaxYBlock() {
|
||||
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
|
||||
return this.cornerTwo;
|
||||
}
|
||||
return this.cornerOne;
|
||||
}
|
||||
|
||||
public BlockInfo getMaxZBlock() {
|
||||
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
|
||||
return this.cornerTwo;
|
||||
}
|
||||
return this.cornerOne;
|
||||
}
|
||||
|
||||
public int getMaxX() {
|
||||
return this.getMaxXBlock().getX();
|
||||
}
|
||||
|
||||
public int getMaxY() {
|
||||
return this.getMaxYBlock().getY();
|
||||
}
|
||||
|
||||
public int getMaxZ() {
|
||||
return this.getMaxZBlock().getZ();
|
||||
}
|
||||
|
||||
public int getSizeX() {
|
||||
return this.getMaxX() - this.getMinX() + 1;
|
||||
}
|
||||
|
||||
public int getSizeY() {
|
||||
return this.getMaxY() - this.getMinY() + 1;
|
||||
}
|
||||
|
||||
public int getSizeZ() {
|
||||
return this.getMaxZ() - this.getMinZ() + 1;
|
||||
}
|
||||
|
||||
public boolean isSaved() {
|
||||
return this.getBlockTypes() != null;
|
||||
}
|
||||
|
||||
public int[][][] getBlockTypes() {
|
||||
return this.blockTypes;
|
||||
}
|
||||
|
||||
public BlockInfo getCornerOne() {
|
||||
return this.cornerOne;
|
||||
}
|
||||
|
||||
public BlockInfo getCornerTwo() {
|
||||
return this.cornerTwo;
|
||||
}
|
||||
|
||||
public boolean contains(Location location) {
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
return this.hasTwoCorners() && location.getWorld().getName().equals(this.world.getName()) && x <= this.getMaxX() && x >= this.getMinX() && y <= this.getMaxY() && y >= this.getMinY() && z <= this.getMaxZ() && z >= this.getMinZ();
|
||||
}
|
||||
|
||||
public boolean contains(Block block) {
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
return this.hasTwoCorners() && block.getWorld().getName().equals(this.world.getName()) && x <= this.getMaxX() && x >= this.getMinX() && y <= this.getMaxY() && y >= this.getMinY() && z <= this.getMaxZ() && z >= this.getMinZ();
|
||||
}
|
||||
|
||||
public void setBlockTypes(int[][][] blockTypes) {
|
||||
this.blockTypes = blockTypes;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setToMaterial(Material material) {
|
||||
try {
|
||||
if (this.hasTwoCorners() && this.isSaved()) {
|
||||
int x = this.getMinX();
|
||||
for (int i = 0; i < this.getSizeX(); i++) {
|
||||
int y = this.getMaxY();
|
||||
for (int j = this.getSizeY(); j > 0; j--) {
|
||||
int z = this.getMinZ();
|
||||
for (int k = 0; k < this.getSizeZ(); k++) {
|
||||
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
|
||||
currentBlock.setType(material);
|
||||
z++;
|
||||
}
|
||||
y--;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
War.war.log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFaceMaterial(BlockFace face, Material material) {
|
||||
try {
|
||||
if (this.hasTwoCorners() && this.isSaved()) {
|
||||
int x = this.getMinX();
|
||||
for (int i = 0; i < this.getSizeX(); i++) {
|
||||
int y = this.getMinY();
|
||||
for (int j = 0; j < this.getSizeY(); j++) {
|
||||
int z = this.getMinZ();
|
||||
for (int k = 0; k < this.getSizeZ(); k++) {
|
||||
if ((face == BlockFace.DOWN && y == this.getMinY()) || (face == BlockFace.UP && y == this.getMaxY()) || (face == BlockFace.NORTH && x == this.getMinX()) || (face == BlockFace.EAST && z == this.getMinZ()) || (face == BlockFace.SOUTH && x == this.getMaxX()) || (face == BlockFace.WEST && z == this.getMaxZ())) {
|
||||
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
|
||||
currentBlock.setType(material);
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
War.war.log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
private void switchMaterials(Material[] oldTypes, Material newType) {
|
||||
try {
|
||||
int i = 0, j = 0, k = 0;
|
||||
int x, y, z;
|
||||
Block currentBlock = null;
|
||||
if (this.hasTwoCorners() && this.isSaved()) {
|
||||
x = this.getMinX();
|
||||
for (i = 0; i < this.getSizeX(); i++) {
|
||||
y = this.getMaxY();
|
||||
for (j = this.getSizeY(); j > 0; j--) {
|
||||
z = this.getMinZ();
|
||||
for (k = 0; k < this.getSizeZ(); k++) {
|
||||
currentBlock = this.getWorld().getBlockAt(x, y, z);
|
||||
for (Material oldType : oldTypes) {
|
||||
if (currentBlock.getType().getId() == oldType.getId()) {
|
||||
currentBlock.setType(newType);
|
||||
// BlockState state = currentBlock.getState();
|
||||
// if (state != null) {
|
||||
// state.setType(newType);
|
||||
// state.update(true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y--;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
War.war.log("Failed to switch block to " + newType + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearBlocksThatDontFloat() {
|
||||
Material[] toAirMaterials = new Material[22];
|
||||
toAirMaterials[0] = Material.SIGN_POST;
|
||||
toAirMaterials[1] = Material.WALL_SIGN;
|
||||
toAirMaterials[2] = Material.IRON_DOOR;
|
||||
toAirMaterials[3] = Material.WOOD_DOOR;
|
||||
toAirMaterials[4] = Material.LADDER;
|
||||
toAirMaterials[5] = Material.YELLOW_FLOWER;
|
||||
toAirMaterials[6] = Material.RED_ROSE;
|
||||
toAirMaterials[7] = Material.RED_MUSHROOM;
|
||||
toAirMaterials[8] = Material.BROWN_MUSHROOM;
|
||||
toAirMaterials[9] = Material.SAPLING;
|
||||
toAirMaterials[10] = Material.TORCH;
|
||||
toAirMaterials[11] = Material.RAILS;
|
||||
toAirMaterials[12] = Material.STONE_BUTTON;
|
||||
toAirMaterials[13] = Material.STONE_PLATE;
|
||||
toAirMaterials[14] = Material.WOOD_PLATE;
|
||||
toAirMaterials[15] = Material.LEVER;
|
||||
toAirMaterials[16] = Material.REDSTONE;
|
||||
toAirMaterials[17] = Material.REDSTONE_TORCH_ON;
|
||||
toAirMaterials[18] = Material.REDSTONE_TORCH_OFF;
|
||||
toAirMaterials[19] = Material.CACTUS;
|
||||
toAirMaterials[20] = Material.SNOW;
|
||||
toAirMaterials[21] = Material.ICE;
|
||||
this.switchMaterials(toAirMaterials, Material.AIR);
|
||||
}
|
||||
|
||||
public void setSignLines(HashMap<String, String[]> signLines) {
|
||||
this.signLines = signLines;
|
||||
}
|
||||
|
||||
public HashMap<String, String[]> getSignLines() {
|
||||
return this.signLines;
|
||||
}
|
||||
|
||||
public void setInvBlockContents(HashMap<String, List<ItemStack>> invBlockContents) {
|
||||
this.invBlockContents = invBlockContents;
|
||||
}
|
||||
|
||||
public HashMap<String, List<ItemStack>> getInvBlockContents() {
|
||||
return this.invBlockContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finalize() {
|
||||
this.blockDatas = null;
|
||||
this.blockTypes = null;
|
||||
this.signLines.clear();
|
||||
this.signLines = null;
|
||||
this.invBlockContents.clear();
|
||||
this.invBlockContents = null;
|
||||
}
|
||||
}
|
@ -1,306 +0,0 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
import com.tommytony.war.Monument;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.mappers.ZoneVolumeMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class ZoneVolume extends Volume {
|
||||
|
||||
private Warzone zone;
|
||||
private boolean isSaved = false;
|
||||
|
||||
public ZoneVolume(String name, World world, Warzone zone) {
|
||||
super(name, world);
|
||||
this.zone = zone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveBlocks() {
|
||||
// Save blocks directly to disk (i.e. don't put everything in memory)
|
||||
int saved = ZoneVolumeMapper.save(this, this.zone.getName());
|
||||
War.war.log("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
|
||||
this.isSaved = true;
|
||||
return saved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaved() {
|
||||
return this.isSaved;
|
||||
}
|
||||
|
||||
public void loadCorners() {
|
||||
ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), true);
|
||||
this.isSaved = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int resetBlocks() {
|
||||
// Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks)
|
||||
int reset = ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), false);
|
||||
War.war.log("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
|
||||
this.isSaved = true;
|
||||
return reset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockTypes(int[][][] blockTypes) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockDatas(byte[][][] blockData) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void setNorthwest(Block block) throws NotNorthwestException, TooSmallException, TooBigException {
|
||||
// northwest defaults to top block
|
||||
BlockInfo topBlock = new BlockInfo(block.getX(), 127, block.getZ(), block.getTypeId(), block.getData());
|
||||
BlockInfo oldCornerOne = this.getCornerOne();
|
||||
BlockInfo oldCornerTwo = this.getCornerTwo();
|
||||
if (this.getCornerOne() == null) {
|
||||
if (this.getCornerTwo() == null) {
|
||||
// northwest defaults to corner 1
|
||||
super.setCornerOne(topBlock);
|
||||
} else if (this.getCornerTwo().getX() <= block.getX() || this.getCornerTwo().getZ() >= block.getZ()) {
|
||||
throw new NotNorthwestException();
|
||||
} else {
|
||||
// corner 2 already set, but we're sure we're located at the northwest of it
|
||||
super.setCornerOne(topBlock);
|
||||
}
|
||||
} else if (this.getCornerTwo() == null) {
|
||||
// corner 1 already exists, set northwest as corner 2 (only if it's at the northwest of corner 1)
|
||||
if (this.getCornerOne().getX() <= block.getX() || this.getCornerOne().getZ() >= block.getZ()) {
|
||||
throw new NotNorthwestException();
|
||||
}
|
||||
super.setCornerTwo(topBlock);
|
||||
} else {
|
||||
// both corners already set: we are resizing (only if the new block is northwest relative to the southeasternmost block)
|
||||
if (this.getSoutheastX() <= block.getX() || this.getSoutheastZ() >= block.getZ()) {
|
||||
throw new NotNorthwestException();
|
||||
}
|
||||
BlockInfo minXBlock = this.getMinXBlock(); // north means min X
|
||||
minXBlock.setX(block.getX()); // mutating, argh!
|
||||
BlockInfo maxZBlock = this.getMaxZBlock(); // west means max Z
|
||||
maxZBlock.setZ(block.getZ());
|
||||
}
|
||||
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooSmallException();
|
||||
} else if (this.tooBig()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooBigException();
|
||||
}
|
||||
}
|
||||
|
||||
public int getNorthwestX() {
|
||||
if (!this.hasTwoCorners()) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.getMinX();
|
||||
}
|
||||
}
|
||||
|
||||
public int getNorthwestZ() {
|
||||
if (!this.hasTwoCorners()) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.getMaxZ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSoutheast(Block block) throws NotSoutheastException, TooSmallException, TooBigException {
|
||||
// southeast defaults to bottom block
|
||||
BlockInfo bottomBlock = new BlockInfo(block.getX(), 0, block.getZ(), block.getTypeId(), block.getData());
|
||||
BlockInfo oldCornerOne = this.getCornerOne();
|
||||
BlockInfo oldCornerTwo = this.getCornerTwo();
|
||||
if (this.getCornerTwo() == null) {
|
||||
if (this.getCornerOne() == null) {
|
||||
// southeast defaults to corner 2
|
||||
super.setCornerTwo(bottomBlock);
|
||||
} else if (this.getCornerOne().getX() >= block.getX() || this.getCornerOne().getZ() <= block.getZ()) {
|
||||
throw new NotSoutheastException();
|
||||
} else {
|
||||
// corner 1 already set, but we're sure we're located at the southeast of it
|
||||
super.setCornerTwo(bottomBlock);
|
||||
}
|
||||
} else if (this.getCornerOne() == null) {
|
||||
// corner 2 already exists, set northwest as corner 1 (only if it's at the southeast of corner 2)
|
||||
if (this.getCornerTwo().getX() >= block.getX() || this.getCornerTwo().getZ() <= block.getZ()) {
|
||||
throw new NotSoutheastException();
|
||||
}
|
||||
super.setCornerOne(bottomBlock);
|
||||
} else {
|
||||
// both corners already set: we are resizing (only if the new block is southeast relative to the northwesternmost block)
|
||||
if (this.getNorthwestX() >= block.getX() || this.getNorthwestZ() <= block.getZ()) {
|
||||
throw new NotSoutheastException();
|
||||
}
|
||||
BlockInfo maxXBlock = this.getMaxXBlock(); // south means max X
|
||||
maxXBlock.setX(block.getX()); // mutating, argh!
|
||||
BlockInfo minZBlock = this.getMinZBlock(); // east means min Z
|
||||
minZBlock.setZ(block.getZ());
|
||||
}
|
||||
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooSmallException();
|
||||
} else if (this.tooBig()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooBigException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getSoutheastX() {
|
||||
if (!this.hasTwoCorners()) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.getMaxX();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSoutheastZ() {
|
||||
if (!this.hasTwoCorners()) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.getMinZ();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCenterY() {
|
||||
if (!this.hasTwoCorners()) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.getMinY() + (this.getMaxY() - this.getMinY()) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void setZoneCornerOne(Block block) throws TooSmallException, TooBigException {
|
||||
BlockInfo oldCornerOne = this.getCornerOne();
|
||||
super.setCornerOne(block);
|
||||
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
throw new TooSmallException();
|
||||
} else if (this.tooBig()) {
|
||||
super.setCornerOne(oldCornerOne);
|
||||
throw new TooBigException();
|
||||
}
|
||||
}
|
||||
|
||||
public void setZoneCornerTwo(Block block) throws TooSmallException, TooBigException {
|
||||
BlockInfo oldCornerTwo = this.getCornerTwo();
|
||||
super.setCornerTwo(block);
|
||||
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooSmallException();
|
||||
} else if (this.tooBig()) {
|
||||
super.setCornerTwo(oldCornerTwo);
|
||||
throw new TooBigException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tooSmall() {
|
||||
if (this.hasTwoCorners() && ((this.getMaxX() - this.getMinX() < 10) || (this.getMaxY() - this.getMinY() < 10) || (this.getMaxZ() - this.getMinZ() < 10))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tooBig() {
|
||||
if (this.hasTwoCorners() && ((this.getMaxX() - this.getMinX() > 750) || (this.getMaxY() - this.getMinY() > 750) || (this.getMaxZ() - this.getMinZ() > 750))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean zoneStructuresAreOutside() {
|
||||
// check team spawns & flags
|
||||
for (Team team : this.zone.getTeams()) {
|
||||
if (team.getTeamSpawn() != null) {
|
||||
if (!this.isInside(team.getSpawnVolume().getCornerOne()) || !this.isInside(team.getSpawnVolume().getCornerTwo())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (team.getTeamFlag() != null) {
|
||||
if (!this.isInside(team.getFlagVolume().getCornerOne()) || !this.isInside(team.getFlagVolume().getCornerTwo())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check monuments
|
||||
for (Monument monument : this.zone.getMonuments()) {
|
||||
if (monument.getVolume() != null) {
|
||||
if (!this.isInside(monument.getVolume().getCornerOne()) || !this.isInside(monument.getVolume().getCornerTwo())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isInside(BlockInfo info) {
|
||||
if (info.getX() <= this.getMaxX() && info.getX() >= this.getMinX() && info.getY() <= this.getMaxY() && info.getY() >= this.getMinY() && info.getZ() <= this.getMaxZ() && info.getZ() >= this.getMinZ()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isWallBlock(Block block) {
|
||||
return this.isEastWallBlock(block) || this.isNorthWallBlock(block) || this.isSouthWallBlock(block) || this.isWestWallBlock(block) || this.isUpWallBlock(block) || this.isDownWallBlock(block);
|
||||
}
|
||||
|
||||
public boolean isEastWallBlock(Block block) {
|
||||
if (this.getMinZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) {
|
||||
return true; // east wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSouthWallBlock(Block block) {
|
||||
if (this.getMaxX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) {
|
||||
return true; // south wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isNorthWallBlock(Block block) {
|
||||
if (this.getMinX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) {
|
||||
return true; // north wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isWestWallBlock(Block block) {
|
||||
if (this.getMaxZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) {
|
||||
return true; // west wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isUpWallBlock(Block block) {
|
||||
if (this.getMaxY() == block.getY() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getZ() >= this.getMinZ() && block.getZ() <= this.getMaxZ()) {
|
||||
return true; // top wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDownWallBlock(Block block) {
|
||||
if (this.getMinY() == block.getY() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getZ() >= this.getMinZ() && block.getZ() <= this.getMaxZ()) {
|
||||
return true; // bottom wall
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user