* added lock switch to all write actions

* added saveall command to save everything to disk
* added reload command to reload everything from disk
This commit is contained in:
Andy Buchholz 2011-05-08 17:16:43 +02:00
parent d38f855b28
commit bffa9df8f7
23 changed files with 154 additions and 4 deletions

View File

@ -33,13 +33,16 @@ import org.mcteam.factions.commands.FCommandJoin;
import org.mcteam.factions.commands.FCommandKick;
import org.mcteam.factions.commands.FCommandLeave;
import org.mcteam.factions.commands.FCommandList;
import org.mcteam.factions.commands.FCommandLock;
import org.mcteam.factions.commands.FCommandMap;
import org.mcteam.factions.commands.FCommandMod;
import org.mcteam.factions.commands.FCommandOpen;
import org.mcteam.factions.commands.FCommandRelationAlly;
import org.mcteam.factions.commands.FCommandRelationEnemy;
import org.mcteam.factions.commands.FCommandRelationNeutral;
import org.mcteam.factions.commands.FCommandReload;
import org.mcteam.factions.commands.FCommandSafeclaim;
import org.mcteam.factions.commands.FCommandSaveAll;
import org.mcteam.factions.commands.FCommandSethome;
import org.mcteam.factions.commands.FCommandShow;
import org.mcteam.factions.commands.FCommandTag;
@ -85,6 +88,8 @@ public class Factions extends JavaPlugin {
private String baseCommand;
private static boolean lock = false;
public Factions() {
Factions.instance = this;
}
@ -95,8 +100,6 @@ public class Factions extends JavaPlugin {
log("=== INIT START ===");
long timeInitStart = System.currentTimeMillis();
// log("asdfasdas"+MiscUtil.range(-1, 1));
// Add the commands
commands.add(new FCommandHelp());
commands.add(new FCommandAdmin());
@ -112,12 +115,15 @@ public class Factions extends JavaPlugin {
commands.add(new FCommandKick());
commands.add(new FCommandLeave());
commands.add(new FCommandList());
commands.add(new FCommandLock());
commands.add(new FCommandMap());
commands.add(new FCommandMod());
commands.add(new FCommandOpen());
commands.add(new FCommandRelationAlly());
commands.add(new FCommandRelationEnemy());
commands.add(new FCommandRelationNeutral());
commands.add(new FCommandReload());
commands.add(new FCommandSaveAll());
commands.add(new FCommandSafeclaim());
commands.add(new FCommandSethome());
commands.add(new FCommandShow());
@ -127,7 +133,7 @@ public class Factions extends JavaPlugin {
commands.add(new FCommandUnclaimall());
commands.add(new FCommandVersion());
// Ensure basefolder exists!
// Ensure base folder exists!
this.getDataFolder().mkdirs();
Conf.load();
@ -214,6 +220,18 @@ public class Factions extends JavaPlugin {
return hasPerm(sender, "factions.adminBypass", true);
}
public static boolean hasPermReload(CommandSender sender) {
return hasPerm(sender, "factions.reload", true);
}
public static boolean hasPermSaveAll(CommandSender sender) {
return hasPerm(sender, "factions.saveall", true);
}
public static boolean hasPermLock(CommandSender sender) {
return hasPerm(sender, "factions.lock", true);
}
private static boolean hasPerm(CommandSender sender, String permNode, boolean fallbackOnlyOp) {
if (Factions.Permissions == null || ! (sender instanceof Player)) {
return fallbackOnlyOp == false || sender.isOp();
@ -289,5 +307,5 @@ public class Factions extends JavaPlugin {
Board.save();
Conf.save();
}
}

View File

@ -28,6 +28,7 @@ public class FBaseCommand {
public List<String> parameters;
private static boolean lock = false;
public FBaseCommand() {
aliases = new ArrayList<String>();
@ -232,4 +233,22 @@ public class FBaseCommand {
return aliasTrue.contains(str.toLowerCase());
}
public void setLock(boolean newLock) {
if( newLock ) {
me.sendMessage("Factions is now locked");
} else {
me.sendMessage("Factions in now unlocked");
}
lock = newLock;
}
public boolean isLocked() {
return lock;
}
public void sendLockMessage() {
me.sendMessage("Factions is locked. Please try again later");
}
}

View File

@ -20,6 +20,11 @@ public class FCommandAdmin extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.ADMIN)) {
return;
}

View File

@ -20,6 +20,11 @@ public class FCommandClaim extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
Faction myFaction = me.getFaction();
FLocation flocation = new FLocation(me);
Faction otherFaction = Board.getFactionAt(flocation);

View File

@ -26,6 +26,12 @@ public class FCommandCreate extends FBaseCommand {
}
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
String tag = parameters.get(0);
if (me.hasFaction()) {

View File

@ -21,6 +21,11 @@ public class FCommandDeinvite extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
String playerName = parameters.get(0);
FPlayer you = findFPlayer(playerName, false);

View File

@ -20,6 +20,11 @@ public class FCommandDescription extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.MODERATOR)) {
return;
}

View File

@ -21,6 +21,11 @@ public class FCommandInvite extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.MODERATOR)) {
return;
}

View File

@ -14,6 +14,12 @@ public class FCommandJoin extends FBaseCommand {
}
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
String factionName = parameters.get(0);
Faction faction = findFaction(factionName);

View File

@ -15,6 +15,12 @@ public class FCommandKick extends FBaseCommand {
}
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
String playerName = parameters.get(0);
FPlayer you = findFPlayer(playerName, false);

View File

@ -20,6 +20,11 @@ public class FCommandLeave extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
me.leave();
}

View File

@ -20,6 +20,11 @@ public class FCommandMod extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.ADMIN)) {
return;
}

View File

@ -18,6 +18,11 @@ public class FCommandOpen extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.MODERATOR)) {
return;
}

View File

@ -9,6 +9,12 @@ public class FCommandRelationAlly extends FRelationCommand {
}
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
relation(Relation.ALLY, parameters.get(0));
}

View File

@ -9,6 +9,12 @@ public class FCommandRelationEnemy extends FRelationCommand {
}
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
relation(Relation.ENEMY, parameters.get(0));
}

View File

@ -9,6 +9,12 @@ public class FCommandRelationNeutral extends FRelationCommand {
}
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
relation(Relation.NEUTRAL, parameters.get(0));
}

View File

@ -23,6 +23,12 @@ public class FCommandSafeclaim extends FBaseCommand {
}
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
// The current location of the player
FLocation playerFlocation = new FLocation(me);

View File

@ -17,6 +17,11 @@ public class FCommandSethome extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.MODERATOR)) {
return;
}

View File

@ -23,6 +23,11 @@ public class FCommandTag extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.MODERATOR)) {
return;
}

View File

@ -22,6 +22,11 @@ public class FCommandTitle extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
String playerName = parameters.get(0);
parameters.remove(0);
String title = TextUtil.implode(parameters);

View File

@ -17,6 +17,12 @@ public class FCommandUnclaim extends FBaseCommand {
}
public void perform() {
if( isLocked() ) {
sendLockMessage();
return;
}
FLocation flocation = new FLocation(me);
Faction otherFaction = Board.getFactionAt(flocation);

View File

@ -19,6 +19,11 @@ public class FCommandUnclaimall extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.MODERATOR)) {
return;
}

View File

@ -21,6 +21,11 @@ public class FRelationCommand extends FBaseCommand {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.MODERATOR)) {
return;
}