From bffa9df8f794dbed793d0b6034eda53f5aefdf61 Mon Sep 17 00:00:00 2001 From: Andy Buchholz Date: Sun, 8 May 2011 17:16:43 +0200 Subject: [PATCH] * added lock switch to all write actions * added saveall command to save everything to disk * added reload command to reload everything from disk --- src/org/mcteam/factions/Factions.java | 26 ++++++++++++++++--- .../factions/commands/FBaseCommand.java | 19 ++++++++++++++ .../factions/commands/FCommandAdmin.java | 5 ++++ .../factions/commands/FCommandClaim.java | 5 ++++ .../factions/commands/FCommandCreate.java | 6 +++++ .../factions/commands/FCommandDeinvite.java | 5 ++++ .../commands/FCommandDescription.java | 5 ++++ .../factions/commands/FCommandInvite.java | 5 ++++ .../factions/commands/FCommandJoin.java | 6 +++++ .../factions/commands/FCommandKick.java | 6 +++++ .../factions/commands/FCommandLeave.java | 5 ++++ .../mcteam/factions/commands/FCommandMod.java | 5 ++++ .../factions/commands/FCommandOpen.java | 5 ++++ .../commands/FCommandRelationAlly.java | 6 +++++ .../commands/FCommandRelationEnemy.java | 6 +++++ .../commands/FCommandRelationNeutral.java | 6 +++++ .../factions/commands/FCommandSafeclaim.java | 6 +++++ .../factions/commands/FCommandSethome.java | 5 ++++ .../mcteam/factions/commands/FCommandTag.java | 5 ++++ .../factions/commands/FCommandTitle.java | 5 ++++ .../factions/commands/FCommandUnclaim.java | 6 +++++ .../factions/commands/FCommandUnclaimall.java | 5 ++++ .../factions/commands/FRelationCommand.java | 5 ++++ 23 files changed, 154 insertions(+), 4 deletions(-) diff --git a/src/org/mcteam/factions/Factions.java b/src/org/mcteam/factions/Factions.java index 0120685a..01f68430 100644 --- a/src/org/mcteam/factions/Factions.java +++ b/src/org/mcteam/factions/Factions.java @@ -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(); } - + } diff --git a/src/org/mcteam/factions/commands/FBaseCommand.java b/src/org/mcteam/factions/commands/FBaseCommand.java index 3ab5da5b..3b42d89c 100644 --- a/src/org/mcteam/factions/commands/FBaseCommand.java +++ b/src/org/mcteam/factions/commands/FBaseCommand.java @@ -28,6 +28,7 @@ public class FBaseCommand { public List parameters; + private static boolean lock = false; public FBaseCommand() { aliases = new ArrayList(); @@ -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"); + } } diff --git a/src/org/mcteam/factions/commands/FCommandAdmin.java b/src/org/mcteam/factions/commands/FCommandAdmin.java index b2b53f51..f45f08c8 100644 --- a/src/org/mcteam/factions/commands/FCommandAdmin.java +++ b/src/org/mcteam/factions/commands/FCommandAdmin.java @@ -20,6 +20,11 @@ public class FCommandAdmin extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.ADMIN)) { return; } diff --git a/src/org/mcteam/factions/commands/FCommandClaim.java b/src/org/mcteam/factions/commands/FCommandClaim.java index 4aae73f6..1c92edf9 100644 --- a/src/org/mcteam/factions/commands/FCommandClaim.java +++ b/src/org/mcteam/factions/commands/FCommandClaim.java @@ -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); diff --git a/src/org/mcteam/factions/commands/FCommandCreate.java b/src/org/mcteam/factions/commands/FCommandCreate.java index e5a64ba9..3c7db979 100644 --- a/src/org/mcteam/factions/commands/FCommandCreate.java +++ b/src/org/mcteam/factions/commands/FCommandCreate.java @@ -26,6 +26,12 @@ public class FCommandCreate extends FBaseCommand { } public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + String tag = parameters.get(0); if (me.hasFaction()) { diff --git a/src/org/mcteam/factions/commands/FCommandDeinvite.java b/src/org/mcteam/factions/commands/FCommandDeinvite.java index 59a1f5d4..178de7ca 100644 --- a/src/org/mcteam/factions/commands/FCommandDeinvite.java +++ b/src/org/mcteam/factions/commands/FCommandDeinvite.java @@ -21,6 +21,11 @@ public class FCommandDeinvite extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + String playerName = parameters.get(0); FPlayer you = findFPlayer(playerName, false); diff --git a/src/org/mcteam/factions/commands/FCommandDescription.java b/src/org/mcteam/factions/commands/FCommandDescription.java index bd10ade3..d97e75c9 100644 --- a/src/org/mcteam/factions/commands/FCommandDescription.java +++ b/src/org/mcteam/factions/commands/FCommandDescription.java @@ -20,6 +20,11 @@ public class FCommandDescription extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.MODERATOR)) { return; } diff --git a/src/org/mcteam/factions/commands/FCommandInvite.java b/src/org/mcteam/factions/commands/FCommandInvite.java index 673e29c7..29192cbb 100644 --- a/src/org/mcteam/factions/commands/FCommandInvite.java +++ b/src/org/mcteam/factions/commands/FCommandInvite.java @@ -21,6 +21,11 @@ public class FCommandInvite extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.MODERATOR)) { return; } diff --git a/src/org/mcteam/factions/commands/FCommandJoin.java b/src/org/mcteam/factions/commands/FCommandJoin.java index 3ebe2500..cc62e6cb 100644 --- a/src/org/mcteam/factions/commands/FCommandJoin.java +++ b/src/org/mcteam/factions/commands/FCommandJoin.java @@ -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); diff --git a/src/org/mcteam/factions/commands/FCommandKick.java b/src/org/mcteam/factions/commands/FCommandKick.java index c19b72a3..663b7239 100644 --- a/src/org/mcteam/factions/commands/FCommandKick.java +++ b/src/org/mcteam/factions/commands/FCommandKick.java @@ -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); diff --git a/src/org/mcteam/factions/commands/FCommandLeave.java b/src/org/mcteam/factions/commands/FCommandLeave.java index cf4acada..0771bf9e 100644 --- a/src/org/mcteam/factions/commands/FCommandLeave.java +++ b/src/org/mcteam/factions/commands/FCommandLeave.java @@ -20,6 +20,11 @@ public class FCommandLeave extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + me.leave(); } diff --git a/src/org/mcteam/factions/commands/FCommandMod.java b/src/org/mcteam/factions/commands/FCommandMod.java index b5aff16a..dc356265 100644 --- a/src/org/mcteam/factions/commands/FCommandMod.java +++ b/src/org/mcteam/factions/commands/FCommandMod.java @@ -20,6 +20,11 @@ public class FCommandMod extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.ADMIN)) { return; } diff --git a/src/org/mcteam/factions/commands/FCommandOpen.java b/src/org/mcteam/factions/commands/FCommandOpen.java index d07e75af..f635683a 100644 --- a/src/org/mcteam/factions/commands/FCommandOpen.java +++ b/src/org/mcteam/factions/commands/FCommandOpen.java @@ -18,6 +18,11 @@ public class FCommandOpen extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.MODERATOR)) { return; } diff --git a/src/org/mcteam/factions/commands/FCommandRelationAlly.java b/src/org/mcteam/factions/commands/FCommandRelationAlly.java index 8726e004..3958046e 100644 --- a/src/org/mcteam/factions/commands/FCommandRelationAlly.java +++ b/src/org/mcteam/factions/commands/FCommandRelationAlly.java @@ -9,6 +9,12 @@ public class FCommandRelationAlly extends FRelationCommand { } public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + relation(Relation.ALLY, parameters.get(0)); } diff --git a/src/org/mcteam/factions/commands/FCommandRelationEnemy.java b/src/org/mcteam/factions/commands/FCommandRelationEnemy.java index 03d99d72..1244df98 100644 --- a/src/org/mcteam/factions/commands/FCommandRelationEnemy.java +++ b/src/org/mcteam/factions/commands/FCommandRelationEnemy.java @@ -9,6 +9,12 @@ public class FCommandRelationEnemy extends FRelationCommand { } public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + relation(Relation.ENEMY, parameters.get(0)); } diff --git a/src/org/mcteam/factions/commands/FCommandRelationNeutral.java b/src/org/mcteam/factions/commands/FCommandRelationNeutral.java index 067dd6d3..9978416e 100644 --- a/src/org/mcteam/factions/commands/FCommandRelationNeutral.java +++ b/src/org/mcteam/factions/commands/FCommandRelationNeutral.java @@ -9,6 +9,12 @@ public class FCommandRelationNeutral extends FRelationCommand { } public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + relation(Relation.NEUTRAL, parameters.get(0)); } diff --git a/src/org/mcteam/factions/commands/FCommandSafeclaim.java b/src/org/mcteam/factions/commands/FCommandSafeclaim.java index a93587f8..c5bce0d5 100644 --- a/src/org/mcteam/factions/commands/FCommandSafeclaim.java +++ b/src/org/mcteam/factions/commands/FCommandSafeclaim.java @@ -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); diff --git a/src/org/mcteam/factions/commands/FCommandSethome.java b/src/org/mcteam/factions/commands/FCommandSethome.java index 0ee79724..b4700545 100644 --- a/src/org/mcteam/factions/commands/FCommandSethome.java +++ b/src/org/mcteam/factions/commands/FCommandSethome.java @@ -17,6 +17,11 @@ public class FCommandSethome extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.MODERATOR)) { return; } diff --git a/src/org/mcteam/factions/commands/FCommandTag.java b/src/org/mcteam/factions/commands/FCommandTag.java index 0574fda7..3cc3938f 100644 --- a/src/org/mcteam/factions/commands/FCommandTag.java +++ b/src/org/mcteam/factions/commands/FCommandTag.java @@ -23,6 +23,11 @@ public class FCommandTag extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.MODERATOR)) { return; } diff --git a/src/org/mcteam/factions/commands/FCommandTitle.java b/src/org/mcteam/factions/commands/FCommandTitle.java index ad013cbf..c5ad7c9d 100644 --- a/src/org/mcteam/factions/commands/FCommandTitle.java +++ b/src/org/mcteam/factions/commands/FCommandTitle.java @@ -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); diff --git a/src/org/mcteam/factions/commands/FCommandUnclaim.java b/src/org/mcteam/factions/commands/FCommandUnclaim.java index d4e5e84e..cb67c5d5 100644 --- a/src/org/mcteam/factions/commands/FCommandUnclaim.java +++ b/src/org/mcteam/factions/commands/FCommandUnclaim.java @@ -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); diff --git a/src/org/mcteam/factions/commands/FCommandUnclaimall.java b/src/org/mcteam/factions/commands/FCommandUnclaimall.java index 8162dc9f..fa4f3e75 100644 --- a/src/org/mcteam/factions/commands/FCommandUnclaimall.java +++ b/src/org/mcteam/factions/commands/FCommandUnclaimall.java @@ -19,6 +19,11 @@ public class FCommandUnclaimall extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.MODERATOR)) { return; } diff --git a/src/org/mcteam/factions/commands/FRelationCommand.java b/src/org/mcteam/factions/commands/FRelationCommand.java index 1be56863..ba317bf0 100644 --- a/src/org/mcteam/factions/commands/FRelationCommand.java +++ b/src/org/mcteam/factions/commands/FRelationCommand.java @@ -21,6 +21,11 @@ public class FRelationCommand extends FBaseCommand { return; } + if( isLocked() ) { + sendLockMessage(); + return; + } + if ( ! assertMinRole(Role.MODERATOR)) { return; }