Closes gh-271. Added SuperPerms/PermissionsBukkit support, and everything still works properly when no Perms plugin is present, thanks to SuperPerms/built-in perms. Made /warcfg give feedback as well.

This commit is contained in:
taoneill 2011-09-15 00:09:39 -04:00
parent 5abdf43986
commit e0a2d6092b
4 changed files with 104 additions and 30 deletions

View File

@ -370,7 +370,7 @@ public class War extends JavaPlugin {
}
}
public boolean updateFromNamedParams(CommandSender commandSender, String[] arguments) {
public String updateFromNamedParams(CommandSender commandSender, String[] arguments) {
try {
Map<String, String> namedParams = new HashMap<String, String>();
for (String namedPair : arguments) {
@ -511,9 +511,9 @@ public class War extends JavaPlugin {
}
}
return true;
return returnMessage.toString();
} catch (Exception e) {
return false;
return "PARSE-ERROR";
}
}
@ -653,14 +653,16 @@ public class War extends JavaPlugin {
* @return true if the player may play war
*/
public boolean canPlayWar(Player player) {
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.player") || War.permissionHandler.has(player, "War.player"))) {
return true;
}
if (War.permissionHandler == null) {
if (War.permissionHandler != null) {
if (War.permissionHandler.has(player, "war.player") || War.permissionHandler.has(player, "War.player")) {
return true;
} else {
return false;
}
} else {
// w/o Permissions, everyone can play
return true;
return player.hasPermission("war.player");
}
return false;
}
/**
@ -670,14 +672,17 @@ public class War extends JavaPlugin {
* @return true if the player may warp
*/
public boolean canWarp(Player player) {
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.warp") || War.permissionHandler.has(player, "War.warp"))) {
return true;
}
if (War.permissionHandler == null) {
if (War.permissionHandler != null) {
if (War.permissionHandler.has(player, "war.warp") || War.permissionHandler.has(player, "War.warp")) {
return true;
} else {
return false;
}
} else {
// w/o Permissions, everyone can warp
return true;
return player.hasPermission("war.warp");
}
return false;
}
/**
@ -688,11 +693,16 @@ public class War extends JavaPlugin {
*/
public boolean canBuildOutsideZone(Player player) {
if (this.isBuildInZonesOnly()) {
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.build") || War.permissionHandler.has(player, "War.build"))) {
return true;
if (War.permissionHandler != null) {
if (War.permissionHandler.has(player, "war.build") || War.permissionHandler.has(player, "War.build")) {
return true;
} else {
return false;
}
} else {
// w/o Permissions, if buildInZonesOnly, no one can build outside the zone except Zonemakers
return player.hasPermission("war.build");
}
// w/o Permissions, if buildInZonesOnly, no one can build outside the zone except Zonemakers
return this.isZoneMaker(player);
} else {
return true;
}
@ -706,11 +716,16 @@ public class War extends JavaPlugin {
*/
public boolean canPvpOutsideZones(Player player) {
if (this.isPvpInZonesOnly()) {
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.pvp") || War.permissionHandler.has(player, "War.pvp"))) {
return true;
if (War.permissionHandler != null) {
if (War.permissionHandler.has(player, "war.pvp") || War.permissionHandler.has(player, "War.pvp")) {
return true;
} else {
return false;
}
} else {
// w/o Permissions, if pvpInZoneOnly, no one can pvp outside the zone
return player.hasPermission("war.pvp");
}
// w/o Permissions, if pvpInZoneOnly, no one can pvp outside the zone
return false;
} else {
return true;
}
@ -735,11 +750,15 @@ public class War extends JavaPlugin {
return true;
}
}
if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.*") || War.permissionHandler.has(player, "War.*"))) {
return true;
if (War.permissionHandler != null) {
if (War.permissionHandler.has(player, "war.*") || War.permissionHandler.has(player, "War.*")) {
return true;
} else {
return false;
}
} else {
// default to op, if no permissions are found
return player.isOp();
return player.hasPermission("war.*");
}
}

View File

@ -26,16 +26,19 @@ public class SetWarConfigCommand extends AbstractZoneMakerCommand {
wantsToPrint = true;
}
if (War.war.updateFromNamedParams(this.getSender(), this.args)) {
String namedParamReturn = War.war.updateFromNamedParams(this.getSender(), this.args);
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
WarMapper.save();
if (wantsToPrint) {
String config = War.war.printConfig();
this.msg("War config saved. " + config);
this.msg("War config saved." + namedParamReturn + " " + config);
} else {
this.msg("War config saved.");
this.msg("War config saved." + namedParamReturn);
}
} else {
} else if (namedParamReturn.equals("PARSE-ERROR")) {
this.msg("Failed to read named parameters.");
} else {
return false;
}
return true;

View File

@ -4,6 +4,32 @@ description: Lets you create TDM and CTF (warzones) for a more structured PVP ex
author: tommytony
website: war.tommytony.com
main: bukkit.tommytony.war.War
permissions:
war.*:
description: Create and destroy warzones. Change War configuration.
default: op
children:
war.player: true
war.warp: true
war.build: true
war.pvp: false
war.player:
description: Lets you participate in War matches.
default: true
war.warp:
description: Gives you access the /zone and /warhub commands that let you teleport to all warzones.
default: true
war.build:
description:
Useful only after using /warcfg buildinzonesonly:true. This node circumvents the build restriction and lets you build outside warzones.
Give war.build to people that you consider worthy of having build rights.
default: false
war.pvp:
description:
Useful only after using /warcfg pvpinzonesonly:true. This node circumvents the pvp restriction and lets you pvp outside warzones.
To setup a pvp world, give war.pvp to players, but only as a permission specific to the pvp world. Other worlds will remain protected
by the pvpinzonesonly setting. No matter what, pvp must be turned on in your server.properties file, otherwise War won't work.
default: false
commands:
# Player commands
warzones:

View File

@ -4,6 +4,32 @@ description: Lets you create TDM and CTF (warzones) for a more structured PVP ex
author: tommytony
website: war.tommytony.com
main: bukkit.tommytony.war.War
permissions:
war.*:
description: Create and destroy warzones. Change War configuration.
default: op
children:
war.player: true
war.warp: true
war.build: true
war.pvp: false
war.player:
description: Lets you participate in War matches.
default: true
war.warp:
description: Gives you access the /zone and /warhub commands that let you teleport to all warzones.
default: true
war.build:
description:
Useful only after using /warcfg buildinzonesonly:true. This node circumvents the build restriction and lets you build outside warzones.
Give war.build to people that you consider worthy of having build rights.
default: false
war.pvp:
description:
Useful only after using /warcfg pvpinzonesonly:true. This node circumvents the pvp restriction and lets you pvp outside warzones.
To setup a pvp world, give war.pvp to players, but only as a permission specific to the pvp world. Other worlds will remain protected
by the pvpinzonesonly setting. No matter what, pvp must be turned on in your server.properties file, otherwise War won't work.
default: false
commands:
# Player commands
warzones: