Cleanup of War class

This commit is contained in:
Tim Düsterhus 2011-07-17 10:30:42 +02:00
parent 38b93ce16d
commit 57f81479fe
2 changed files with 44 additions and 43 deletions

View File

@ -38,11 +38,9 @@ import com.tommytony.war.utils.*;
*/ */
public class War extends JavaPlugin { public class War extends JavaPlugin {
public static PermissionHandler permissionHandler; public static PermissionHandler permissionHandler;
public static War war;
public War() { // general
super();
}
private WarPlayerListener playerListener = new WarPlayerListener(this); private WarPlayerListener playerListener = new WarPlayerListener(this);
private WarEntityListener entityListener = new WarEntityListener(this); private WarEntityListener entityListener = new WarEntityListener(this);
private WarBlockListener blockListener = new WarBlockListener(this); private WarBlockListener blockListener = new WarBlockListener(this);
@ -50,7 +48,9 @@ public class War extends JavaPlugin {
private PluginDescriptionFile desc = null; private PluginDescriptionFile desc = null;
private boolean loaded = false; private boolean loaded = false;
// Zones and hub
private List<Warzone> warzones; private List<Warzone> warzones;
private WarHub warHub;
private final List<Warzone> incompleteZones = new ArrayList<Warzone>(); private final List<Warzone> incompleteZones = new ArrayList<Warzone>();
private final List<String> zoneMakerNames = new ArrayList<String>(); private final List<String> zoneMakerNames = new ArrayList<String>();
private final List<String> commandWhitelist = new ArrayList<String>(); private final List<String> commandWhitelist = new ArrayList<String>();
@ -60,7 +60,7 @@ public class War extends JavaPlugin {
// Default warzone settings // Default warzone settings
private final HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>(); private final HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
private int defaultLifepool = 21; private int defaultLifepool = 7;
private boolean defaultFriendlyFire = false; private boolean defaultFriendlyFire = false;
private boolean defaultAutoAssignOnly = false; private boolean defaultAutoAssignOnly = false;
private int defaultTeamCap = 7; private int defaultTeamCap = 7;
@ -81,33 +81,20 @@ public class War extends JavaPlugin {
private boolean disablePvpMessage = false; private boolean disablePvpMessage = false;
private boolean buildInZonesOnly = false; private boolean buildInZonesOnly = false;
private WarHub warHub; public War() {
super();
public void onDisable() { War.war = this;
this.unloadWar();
}
/**
* Cleans up war
*/
public void unloadWar() {
this.setLoaded(false);
for (Warzone warzone : this.warzones) {
warzone.unload();
}
this.warzones.clear();
if (this.warHub != null) {
this.warHub.getVolume().resetBlocks();
}
this.logInfo("Done. War v" + this.desc.getVersion() + " is off.");
} }
public void onEnable() { public void onEnable() {
this.loadWar(); this.loadWar();
} }
public void onDisable() {
this.unloadWar();
}
/** /**
* Initializes war * Initializes war
*/ */
@ -140,17 +127,32 @@ public class War extends JavaPlugin {
// Load files from disk or create them (using these defaults) // Load files from disk or create them (using these defaults)
this.defaultLoadout.put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8)); this.getDefaultLoadout().put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8));
this.defaultLoadout.put(1, new ItemStack(Material.BOW, 1, (byte) 8)); this.getDefaultLoadout().put(1, new ItemStack(Material.BOW, 1, (byte) 8));
this.defaultLoadout.put(2, new ItemStack(Material.ARROW, 7)); this.getDefaultLoadout().put(2, new ItemStack(Material.ARROW, 7));
this.defaultLoadout.put(3, new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8)); this.getDefaultLoadout().put(3, new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8));
this.defaultLoadout.put(4, new ItemStack(Material.STONE_SPADE, 1, (byte) 8)); this.getDefaultLoadout().put(4, new ItemStack(Material.STONE_SPADE, 1, (byte) 8));
this.defaultLifepool = 7;
this.defaultFriendlyFire = false;
this.defaultAutoAssignOnly = false;
this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1)); this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1));
WarMapper.load(this); WarMapper.load(this);
this.logInfo("War v" + this.desc.getVersion() + " is on."); this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
}
/**
* Cleans up war
*/
public void unloadWar() {
this.setLoaded(false);
for (Warzone warzone : this.warzones) {
warzone.unload();
}
this.warzones.clear();
if (this.warHub != null) {
this.warHub.getVolume().resetBlocks();
}
this.log("Done. War v" + this.desc.getVersion() + " is off.", Level.INFO);
} }
/** /**
@ -162,7 +164,7 @@ public class War extends JavaPlugin {
if (permissionsPlugin != null) { if (permissionsPlugin != null) {
War.permissionHandler = ((Permissions) permissionsPlugin).getHandler(); War.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
} else { } else {
this.logInfo("Permissions system not enabled. Defaulting to regular War config."); this.log("Permissions system not enabled. Defaulting to regular War config.", Level.INFO);
} }
} }
} }
@ -1046,10 +1048,7 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("resetonunload"); String onOff = namedParams.get("resetonunload");
warzone.setResetOnUnload(onOff.equals("on") || onOff.equals("true")); warzone.setResetOnUnload(onOff.equals("on") || onOff.equals("true"));
} }
// if (namedParams.containsKey("dropLootOnDeath")){
// String onOff = namedParams.get("dropLootOnDeath");
// warzone.setDropLootOnDeath(onOff.equals("on") || onOff.equals("true"));
// }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
return false; return false;
@ -1143,10 +1142,7 @@ public class War extends JavaPlugin {
// String rewardType = namedParams.get("reward"); // String rewardType = namedParams.get("reward");
this.setZoneRallyPoint(namedParams.get("rallypoint"), player); this.setZoneRallyPoint(namedParams.get("rallypoint"), player);
} }
// if (namedParams.containsKey("dropLootOnDeath")){
// String onOff = namedParams.get("dropLootOnDeath");
// setDefaultDropLootOnDeath(onOff.equals("on") || onOff.equals("true"));
// }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
return false; return false;

View File

@ -186,6 +186,11 @@ public class WarHub {
} }
} }
/**
* Resets the sign of the given warzone
*
* @param Warzone zone
*/
public void resetZoneSign(Warzone zone) { public void resetZoneSign(Warzone zone) {
BlockFace left; BlockFace left;