Quick and dirty attempt to reduce hits on PLAYER_MOVE. Beginnings of a glasswalls setting.

This commit is contained in:
taoneill 2011-09-12 22:52:08 -04:00
parent 8788c9c4b6
commit 880f7ce528
3 changed files with 43 additions and 6 deletions

View File

@ -75,11 +75,11 @@ public class War extends JavaPlugin {
private boolean defaultAutoAssignOnly = false;
private boolean defaultUnbreakableZoneBlocks = false;
private boolean defaultNoCreatures = false;
private boolean defaultGlassWalls = true;
private FlagReturn defaultFlagReturn = FlagReturn.BOTH;
private boolean defaultResetOnEmpty = false, defaultResetOnLoad = false, defaultResetOnUnload = false;
private TeamSpawnStyle defaultSpawnStyle = TeamSpawnStyle.BIG;
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
private int helmetProtectionTask;
public War() {
super();
@ -146,7 +146,7 @@ public class War extends JavaPlugin {
WarMapper.load();
HelmetProtectionTask helmetProtectionTask = new HelmetProtectionTask();
this.helmetProtectionTask = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, helmetProtectionTask, 250, 100);
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, helmetProtectionTask, 250, 100);
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
}
@ -290,6 +290,10 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("nocreatures");
warzone.setNoCreatures(onOff.equals("on") || onOff.equals("true"));
}
if (namedParams.containsKey("glasswalls")) {
String onOff = namedParams.get("glasswalls");
warzone.setGlassWalls(onOff.equals("on") || onOff.equals("true"));
}
if (namedParams.containsKey("resetonempty")) {
String onOff = namedParams.get("resetonempty");
@ -888,4 +892,12 @@ public class War extends JavaPlugin {
public void setDisconnected(HashMap<String, InventoryStash> disconnected) {
this.disconnected = disconnected;
}
public void setDefaultGlassWalls(boolean defaultGlassWalls) {
this.defaultGlassWalls = defaultGlassWalls;
}
public boolean isDefaultGlassWalls() {
return defaultGlassWalls;
}
}

View File

@ -1,5 +1,7 @@
package bukkit.tommytony.war;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -34,6 +36,7 @@ import com.tommytony.war.ZoneSetter;
*/
public class WarPlayerListener extends PlayerListener {
private java.util.Random random = new java.util.Random();
private HashMap<String, Location> latestLocations = new HashMap<String, Location>();
/**
* Correctly removes quitting players from warzones
@ -220,6 +223,17 @@ public class WarPlayerListener extends PlayerListener {
}
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()) {
// we only care when people change location
return;
}
latestLocations.put(player.getName(), playerLoc);
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
@ -231,11 +245,12 @@ public class WarPlayerListener extends PlayerListener {
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) {
// Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc);
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
if (playerWarzone.isGlassWalls()) {
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
}
} else {
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
if (nearbyZone != null && !isMaker) {
if (nearbyZone != null && nearbyZone.isGlassWalls() && !isMaker) {
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
}
}

View File

@ -58,7 +58,8 @@ public class Warzone {
private boolean blockHeads;
private boolean unbreakableZoneBlocks;
private boolean disabled = false;
private boolean noCreatures;
private boolean noCreatures = false;
private boolean glassWalls = true;
private boolean resetOnEmpty = false;
private boolean resetOnLoad = false;
@ -82,6 +83,7 @@ public class Warzone {
this.setBlockHeads(War.war.isDefaultBlockHeads());
this.setUnbreakableZoneBlocks(War.war.isDefaultUnbreakableZoneBlocks());
this.setNoCreatures(War.war.isDefaultNoCreatures());
this.setGlassWalls(War.war.isDefaultGlassWalls());
this.setResetOnEmpty(War.war.isDefaultResetOnEmpty());
this.setResetOnLoad(War.war.isDefaultResetOnLoad());
this.setResetOnUnload(War.war.isDefaultResetOnUnload());
@ -1075,4 +1077,12 @@ public class Warzone {
public boolean isResetOnEmpty() {
return this.resetOnEmpty;
}
public void setGlassWalls(boolean glassWalls) {
this.glassWalls = glassWalls;
}
public boolean isGlassWalls() {
return glassWalls;
}
}