Everyone can /warcfg -p, /zonecfg -p, /teamcfg -p

Closes gh-499. Now all players have read access to the game rules and
settings. Awesome!
This commit is contained in:
taoneill 2012-06-23 02:12:52 -04:00
parent afa82ce13f
commit 6304b39fc8
7 changed files with 137 additions and 60 deletions

View File

@ -0,0 +1,39 @@
package com.tommytony.war.command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
/**
* Represents a command that may only be used by War admins
*
*/
public abstract class AbstractOptionalWarAdminCommand extends AbstractWarCommand {
public AbstractOptionalWarAdminCommand(WarCommandHandler handler, CommandSender sender, String[] args, boolean mustBeWarAdmin) throws NotWarAdminException {
super(handler, sender, args);
if (mustBeWarAdmin && !isSenderWarAdmin()) {
throw new NotWarAdminException();
}
}
public boolean isSenderWarAdmin() {
if (this.getSender() instanceof Player) {
if (!War.war.isWarAdmin((Player) this.getSender())) {
return false;
} else {
return true;
}
} else if (!(this.getSender() instanceof ConsoleCommandSender)) {
return false;
} else {
// ConsoleCommandSender is admin
return true;
}
}
}

View File

@ -0,0 +1,68 @@
package com.tommytony.war.command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
/**
* Represents a command that may only used by zone makers or regular users
*
* @author tommytony
*/
public abstract class AbstractOptionalZoneMakerCommand extends AbstractWarCommand {
public AbstractOptionalZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args, boolean zoneMakersOnly) throws NotZoneMakerException {
super(handler, sender, args);
if (zoneMakersOnly) {
this.throwIfNotZoneMaker();
}
}
public void throwIfNotZoneMaker() throws NotZoneMakerException {
if (!this.isSenderZoneMaker()) {
throw new NotZoneMakerException();
} else if (!(this.getSender() instanceof ConsoleCommandSender)) {
throw new NotZoneMakerException();
}
}
public boolean isSenderZoneMaker() {
if (this.getSender() instanceof Player) {
// for players check War.isZoneMaker()
if (!War.war.isZoneMaker((Player) this.getSender())) {
return false;
} else {
return true;
}
} else if (!(this.getSender() instanceof ConsoleCommandSender)) {
return false;
} else {
// ConsoleCommandSender is admin
return true;
}
}
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;
}
}
}

View File

@ -1,27 +1,15 @@
package com.tommytony.war.command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
/**
* Represents a command that may only be used by War admins
*
*/
public abstract class AbstractWarAdminCommand extends AbstractWarCommand {
public abstract class AbstractWarAdminCommand extends AbstractOptionalWarAdminCommand {
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();
}
super(handler, sender, args, true);
}
}

View File

@ -1,11 +1,6 @@
package com.tommytony.war.command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
/**
@ -13,37 +8,9 @@ import com.tommytony.war.Warzone;
*
* @author Tim Düsterhus
*/
public abstract class AbstractZoneMakerCommand extends AbstractWarCommand {
public abstract class AbstractZoneMakerCommand extends AbstractOptionalZoneMakerCommand {
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;
}
super(handler, sender, args, true);
}
}

View File

@ -14,10 +14,10 @@ import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.ZoneLobby;
public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
public class SetTeamConfigCommand extends AbstractOptionalZoneMakerCommand {
public SetTeamConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
super(handler, sender, args);
super(handler, sender, args, false);
}
@Override
@ -65,10 +65,8 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
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
@ -131,6 +129,13 @@ public class SetTeamConfigCommand extends AbstractZoneMakerCommand {
wantsToPrint = true;
}
if (!this.isSenderZoneMaker()) {
War.war.badMsg(this.getSender(), "You can't do this if you are not a warzone maker (permission war.zonemaker).");
return true;
} else if (!this.isSenderAuthorOfZone(zone)) {
return 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")) {

View File

@ -8,10 +8,10 @@ import org.bukkit.command.CommandSender;
import com.tommytony.war.War;
import com.tommytony.war.mapper.WarYmlMapper;
public class SetWarConfigCommand extends AbstractWarAdminCommand {
public class SetWarConfigCommand extends AbstractOptionalWarAdminCommand {
public SetWarConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotWarAdminException {
super(handler, sender, args);
super(handler, sender, args, false);
}
@Override
@ -27,6 +27,11 @@ public class SetWarConfigCommand extends AbstractWarAdminCommand {
wantsToPrint = true;
}
if (!this.isSenderWarAdmin()) {
War.war.badMsg(this.getSender(), "You can't do this if you are not a War admin (permission war.admin).");
return true;
}
String namedParamReturn = War.war.updateFromNamedParams(this.getSender(), this.args);
if (!namedParamReturn.equals("") && !namedParamReturn.equals("PARSE-ERROR")) {
WarYmlMapper.save();

View File

@ -12,10 +12,10 @@ import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.structure.ZoneLobby;
public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
public class SetZoneConfigCommand extends AbstractOptionalZoneMakerCommand {
public SetZoneConfigCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
super(handler, sender, args);
super(handler, sender, args, false);
}
@Override
@ -58,8 +58,6 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
if (zone == null) {
// No warzone found, whatever the mean, escape
return false;
} else if (!this.isSenderAuthorOfZone(zone)) {
return true;
}
if (isFirstParamWarzone) {
@ -92,6 +90,13 @@ public class SetZoneConfigCommand extends AbstractZoneMakerCommand {
wantsToPrint = true;
}
if (!this.isSenderZoneMaker()) {
War.war.badMsg(this.getSender(), "You can't do this if you are not a warzone maker (permission war.zonemaker).");
return true;
} else if (!this.isSenderAuthorOfZone(zone)) {
return 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")) {