Closes gh-132. Added war.pvp permission, which works like war.build to override the pvpinzonesonly setting. Added disablePvpMessage to /warcfg named parameters.

This commit is contained in:
taoneill 2011-07-16 10:57:36 -04:00
parent 067dffb3a1
commit 4447cb8344
5 changed files with 34 additions and 85 deletions

View File

@ -58,7 +58,6 @@ public class War extends JavaPlugin {
private final HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
private int defaultLifepool = 21;
private boolean defaultFriendlyFire = false;
private boolean defaultDrawZoneOutline = true;
private boolean defaultAutoAssignOnly = false;
private int defaultTeamCap = 7;
private int defaultScoreCap = 10;
@ -73,7 +72,7 @@ public class War extends JavaPlugin {
private boolean pvpInZonesOnly = false;
private boolean buildInZonesOnly = false;
private boolean disablePVPMessage = false;
private boolean disablePvpMessage = false;
private WarHub warHub;
@ -92,30 +91,6 @@ public class War extends JavaPlugin {
warHub.getVolume().resetBlocks();
}
Thread thread = new Thread(new Runnable()
{
public void run()
{
try
{
Thread.sleep(2000);
Runtime rt = Runtime.getRuntime();
double mem = rt.freeMemory();
rt.runFinalization();
rt.gc();
mem = rt.freeMemory() - mem;
mem /= 1024 * 1024;
logInfo("Freed " + mem + " MB.");
}
catch (InterruptedException ex)
{
return;
}
}
});
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
this.logInfo("Done. War v" + desc.getVersion() + " is off.");
}
@ -1055,10 +1030,6 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("autoassign");
warzone.setAutoAssignOnly(onOff.equals("on") || onOff.equals("true"));
}
if(namedParams.containsKey("outline")){
String onOff = namedParams.get("outline");
warzone.setDrawZoneOutline(onOff.equals("on") || onOff.equals("true"));
}
if(namedParams.containsKey("blockheads")){
String onOff = namedParams.get("blockheads");
warzone.setBlockHeads(onOff.equals("on") || onOff.equals("true"));
@ -1134,14 +1105,14 @@ public class War extends JavaPlugin {
String onOff = namedParams.get("autoassign");
setDefaultAutoAssignOnly(onOff.equals("on") || onOff.equals("true"));
}
if(namedParams.containsKey("outline")){
String onOff = namedParams.get("outline");
setDefaultDrawZoneOutline(onOff.equals("on") || onOff.equals("true"));
}
if(namedParams.containsKey("pvpinzonesonly")){
String onOff = namedParams.get("pvpinzonesonly");
setPvpInZonesOnly(onOff.equals("on") || onOff.equals("true"));
}
if(namedParams.containsKey("disablepvpmessage")){
String onOff = namedParams.get("disablepvpmessage");
setDisablePvpMessage(onOff.equals("on") || onOff.equals("true"));
}
if(namedParams.containsKey("blockheads")){
String onOff = namedParams.get("blockheads");
setDefaultBlockHeads(onOff.equals("on") || onOff.equals("true"));
@ -1438,6 +1409,20 @@ public class War extends JavaPlugin {
}
}
public boolean canPvpOutsideZones(Player player) {
if(isPvpInZonesOnly()) {
if(War.permissionHandler != null
&& (War.permissionHandler.has(player, "war.pvp")
|| War.permissionHandler.has(player, "War.pvp"))) {
return true;
}
// w/o Permissions, if pvpInZoneOnly, no one can pvp outside the zone
return false;
} else {
return true;
}
}
public boolean isZoneMaker(Player player) {
boolean isPlayerImpersonator = false;
for(String disguised : zoneMakersImpersonatingPlayers) {
@ -1456,10 +1441,6 @@ public class War extends JavaPlugin {
return false;
}
public boolean getDefaultDrawZoneOutline() {
return isDefaultDrawZoneOutline() ;
}
public boolean getDefaultAutoAssignOnly() {
return defaultAutoAssignOnly;
@ -1528,14 +1509,6 @@ public class War extends JavaPlugin {
return defaultScoreCap;
}
public void setDefaultDrawZoneOutline(boolean defaultDrawZoneOutline) {
this.defaultDrawZoneOutline = defaultDrawZoneOutline;
}
public boolean isDefaultDrawZoneOutline() {
return defaultDrawZoneOutline;
}
public List<String> getZoneMakersImpersonatingPlayers() {
return zoneMakersImpersonatingPlayers;
}
@ -1591,12 +1564,12 @@ public class War extends JavaPlugin {
return buildInZonesOnly;
}
public void setDisablePVPMessage(boolean disablePVPMessage) {
this.disablePVPMessage = disablePVPMessage;
public void setDisablePvpMessage(boolean disablePvpMessage) {
this.disablePvpMessage = disablePvpMessage;
}
public boolean isDisablePVPMessage() {
return disablePVPMessage;
public boolean isDisablePvpMessage() {
return disablePvpMessage;
}
public void setDefaultUnbreakableZoneBlocks(boolean defaultUnbreakableZoneBlocks) {
@ -1634,4 +1607,5 @@ public class War extends JavaPlugin {
public boolean isLoaded() {
return loaded;
}
}

View File

@ -17,7 +17,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
//import org.bukkit.event.entity.EntityRegainHealthEvent;
import com.tommytony.war.Team;
import com.tommytony.war.Warzone;
@ -103,11 +102,11 @@ public class WarEntityListener extends EntityListener {
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.isPvpInZonesOnly() || a.getLocation().getWorld().getName().equals("pvp"))){
// let normal PVP through is its not turned off
} else if (attackerTeam == null && defenderTeam == null && war.isPvpInZonesOnly()) {
if (!war.isDisablePVPMessage()) {
war.badMsg(a, "Your attack missed! Global PVP is turned off. You can only attack other players in warzones. Try /warhub, /zones and /zone.");
} else if (attackerTeam == null && defenderTeam == null && war.canPvpOutsideZones(a)){
// let normal PVP through is its not turned off or if you have perms
} else if (attackerTeam == null && defenderTeam == null && !war.canPvpOutsideZones(a)) {
if (!war.isDisablePvpMessage()) {
war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones.");
}
event.setCancelled(true); // global pvp is off
} else {
@ -227,9 +226,7 @@ public class WarEntityListener extends EntityListener {
Location location = player.getLocation();
Warzone zone = war.warzone(location);
if(zone != null) {
if (((CraftPlayer) player).getHandle().ticksLived % 20 * 12 == 0) {
event.setCancelled(true);
}
event.setCancelled(true);
}
}
}

View File

@ -37,7 +37,6 @@ public class Warzone {
private boolean friendlyFire;
private int lifePool;
private HashMap<Integer, ItemStack> loadout = new HashMap<Integer, ItemStack>();
private boolean drawZoneOutline;
private int teamCap = 5;
private int scoreCap = 5;
private int monumentHeal = 5;
@ -68,7 +67,6 @@ public class Warzone {
this.friendlyFire = war.getDefaultFriendlyFire();
this.setLifePool(war.getDefaultLifepool());
this.setLoadout(war.getDefaultLoadout());
this.setDrawZoneOutline(war.getDefaultDrawZoneOutline());
this.setAutoAssignOnly(war.getDefaultAutoAssignOnly());
this.teamCap = war.getDefaultTeamCap();
this.scoreCap = war.getDefaultScoreCap();
@ -734,14 +732,6 @@ public class Warzone {
public boolean isAutoAssignOnly() {
return autoAssignOnly;
}
public void setDrawZoneOutline(boolean drawZoneOutline) {
this.drawZoneOutline = drawZoneOutline;
}
public boolean isDrawZoneOutline() {
return drawZoneOutline;
}
public void handleDeath(Player player) {
Team playerTeam = war.getPlayerTeam(player.getName());

View File

@ -85,9 +85,6 @@ public class WarMapper {
// defaultFriendlyFire
war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire"));
// defaultDrawZoneOutline
war.setDefaultDrawZoneOutline(warConfig.getBoolean("defaultDrawZoneOutline"));
// defaultAutoAssignOnly
war.setDefaultAutoAssignOnly(warConfig.getBoolean("defaultAutoAssignOnly"));
@ -107,7 +104,7 @@ public class WarMapper {
war.setBuildInZonesOnly(warConfig.getBoolean("buildInZonesOnly"));
// disablePVPMessage
war.setDisablePVPMessage(warConfig.getBoolean("disablePVPMessage"));
war.setDisablePvpMessage(warConfig.getBoolean("disablePvpMessage"));
// defaultSpawnStyle
String spawnStyle = warConfig.getString("defaultspawnStyle");
@ -195,10 +192,7 @@ public class WarMapper {
// defaultFriendlyFire
warConfig.setBoolean("defaultFriendlyFire", war.getDefaultFriendlyFire());
// defaultFriendlyFire
warConfig.setBoolean("defaultDrawZoneOutline", war.getDefaultDrawZoneOutline());
// defaultAutoAssignOnly
warConfig.setBoolean("defaultAutoAssignOnly", war.getDefaultAutoAssignOnly());
@ -218,7 +212,7 @@ public class WarMapper {
warConfig.setBoolean("buildInZonesOnly", war.isBuildInZonesOnly());
// disablePVPMessage
warConfig.setBoolean("disablePVPMessage", war.isDisablePVPMessage());
warConfig.setBoolean("disablePvpMessage", war.isDisablePvpMessage());
// spawnStyle
warConfig.setString("spawnStyle", war.getDefaultSpawnStyle());

View File

@ -149,9 +149,6 @@ public class WarzoneMapper {
// monument heal
warzone.setMonumentHeal(warzoneConfig.getInt("monumentHeal"));
// drawZoneOutline
warzone.setDrawZoneOutline(warzoneConfig.getBoolean("drawZoneOutline"));
// autoAssignOnly
warzone.setAutoAssignOnly(warzoneConfig.getBoolean("autoAssignOnly"));
@ -355,10 +352,7 @@ public class WarzoneMapper {
// monument heal
warzoneConfig.setInt("monumentHeal", warzone.getMonumentHeal());
// drawZoneOutline
warzoneConfig.setBoolean("drawZoneOutline", warzone.isDrawZoneOutline());
// autoAssignOnly
warzoneConfig.setBoolean("autoAssignOnly", warzone.isAutoAssignOnly());