Merge pull request #14 from derenix/master

New commands:

/f lock on|off
/f save|saveall
/f reload
/f disband     (with permission node "faction.disband")
This commit is contained in:
Brett Flannigan 2011-05-10 16:25:31 -07:00
commit b23c531e97
27 changed files with 292 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import org.mcteam.factions.commands.FCommandClaim;
import org.mcteam.factions.commands.FCommandCreate; import org.mcteam.factions.commands.FCommandCreate;
import org.mcteam.factions.commands.FCommandDeinvite; import org.mcteam.factions.commands.FCommandDeinvite;
import org.mcteam.factions.commands.FCommandDescription; import org.mcteam.factions.commands.FCommandDescription;
import org.mcteam.factions.commands.FCommandDisband;
import org.mcteam.factions.commands.FCommandHelp; import org.mcteam.factions.commands.FCommandHelp;
import org.mcteam.factions.commands.FCommandHome; import org.mcteam.factions.commands.FCommandHome;
import org.mcteam.factions.commands.FCommandInvite; import org.mcteam.factions.commands.FCommandInvite;
@ -33,13 +34,16 @@ import org.mcteam.factions.commands.FCommandJoin;
import org.mcteam.factions.commands.FCommandKick; import org.mcteam.factions.commands.FCommandKick;
import org.mcteam.factions.commands.FCommandLeave; import org.mcteam.factions.commands.FCommandLeave;
import org.mcteam.factions.commands.FCommandList; import org.mcteam.factions.commands.FCommandList;
import org.mcteam.factions.commands.FCommandLock;
import org.mcteam.factions.commands.FCommandMap; import org.mcteam.factions.commands.FCommandMap;
import org.mcteam.factions.commands.FCommandMod; import org.mcteam.factions.commands.FCommandMod;
import org.mcteam.factions.commands.FCommandOpen; import org.mcteam.factions.commands.FCommandOpen;
import org.mcteam.factions.commands.FCommandRelationAlly; import org.mcteam.factions.commands.FCommandRelationAlly;
import org.mcteam.factions.commands.FCommandRelationEnemy; import org.mcteam.factions.commands.FCommandRelationEnemy;
import org.mcteam.factions.commands.FCommandRelationNeutral; import org.mcteam.factions.commands.FCommandRelationNeutral;
import org.mcteam.factions.commands.FCommandReload;
import org.mcteam.factions.commands.FCommandSafeclaim; import org.mcteam.factions.commands.FCommandSafeclaim;
import org.mcteam.factions.commands.FCommandSaveAll;
import org.mcteam.factions.commands.FCommandSethome; import org.mcteam.factions.commands.FCommandSethome;
import org.mcteam.factions.commands.FCommandShow; import org.mcteam.factions.commands.FCommandShow;
import org.mcteam.factions.commands.FCommandTag; import org.mcteam.factions.commands.FCommandTag;
@ -85,6 +89,8 @@ public class Factions extends JavaPlugin {
private String baseCommand; private String baseCommand;
private static boolean lock = false;
public Factions() { public Factions() {
Factions.instance = this; Factions.instance = this;
} }
@ -95,8 +101,6 @@ public class Factions extends JavaPlugin {
log("=== INIT START ==="); log("=== INIT START ===");
long timeInitStart = System.currentTimeMillis(); long timeInitStart = System.currentTimeMillis();
// log("asdfasdas"+MiscUtil.range(-1, 1));
// Add the commands // Add the commands
commands.add(new FCommandHelp()); commands.add(new FCommandHelp());
commands.add(new FCommandAdmin()); commands.add(new FCommandAdmin());
@ -106,18 +110,22 @@ public class Factions extends JavaPlugin {
commands.add(new FCommandCreate()); commands.add(new FCommandCreate());
commands.add(new FCommandDeinvite()); commands.add(new FCommandDeinvite());
commands.add(new FCommandDescription()); commands.add(new FCommandDescription());
commands.add(new FCommandDisband());
commands.add(new FCommandHome()); commands.add(new FCommandHome());
commands.add(new FCommandInvite()); commands.add(new FCommandInvite());
commands.add(new FCommandJoin()); commands.add(new FCommandJoin());
commands.add(new FCommandKick()); commands.add(new FCommandKick());
commands.add(new FCommandLeave()); commands.add(new FCommandLeave());
commands.add(new FCommandList()); commands.add(new FCommandList());
commands.add(new FCommandLock());
commands.add(new FCommandMap()); commands.add(new FCommandMap());
commands.add(new FCommandMod()); commands.add(new FCommandMod());
commands.add(new FCommandOpen()); commands.add(new FCommandOpen());
commands.add(new FCommandRelationAlly()); commands.add(new FCommandRelationAlly());
commands.add(new FCommandRelationEnemy()); commands.add(new FCommandRelationEnemy());
commands.add(new FCommandRelationNeutral()); commands.add(new FCommandRelationNeutral());
commands.add(new FCommandReload());
commands.add(new FCommandSaveAll());
commands.add(new FCommandSafeclaim()); commands.add(new FCommandSafeclaim());
commands.add(new FCommandSethome()); commands.add(new FCommandSethome());
commands.add(new FCommandShow()); commands.add(new FCommandShow());
@ -214,6 +222,22 @@ public class Factions extends JavaPlugin {
return hasPerm(sender, "factions.adminBypass", true); 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);
}
public static boolean hasPermDisband(CommandSender sender) {
return hasPerm(sender, "factions.disband", true);
}
private static boolean hasPerm(CommandSender sender, String permNode, boolean fallbackOnlyOp) { private static boolean hasPerm(CommandSender sender, String permNode, boolean fallbackOnlyOp) {
if (Factions.Permissions == null || ! (sender instanceof Player)) { if (Factions.Permissions == null || ! (sender instanceof Player)) {
return fallbackOnlyOp == false || sender.isOp(); return fallbackOnlyOp == false || sender.isOp();

View File

@ -28,6 +28,7 @@ public class FBaseCommand {
public List<String> parameters; public List<String> parameters;
private static boolean lock = false;
public FBaseCommand() { public FBaseCommand() {
aliases = new ArrayList<String>(); aliases = new ArrayList<String>();
@ -232,4 +233,22 @@ public class FBaseCommand {
return aliasTrue.contains(str.toLowerCase()); 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; return;
} }
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! assertMinRole(Role.ADMIN)) { if ( ! assertMinRole(Role.ADMIN)) {
return; return;
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,35 @@
package org.mcteam.factions.commands;
import org.bukkit.command.CommandSender;
import org.mcteam.factions.Faction;
import org.mcteam.factions.Factions;
public class FCommandDisband extends FBaseCommand {
public FCommandDisband() {
aliases.add("disband");
requiredParameters.add("faction tag");
helpDescription = "Disband a faction";
}
@Override
public boolean hasPermission(CommandSender sender) {
return Factions.hasPermDisband(sender);
}
public void perform() {
if( parameters.size() > 0) {
Faction faction = Faction.findByTag(parameters.get(0));
if( faction.getId() > 0 ) {
me.sendMessage("Faction " + faction.getTag() + " got disbanded");
Faction.delete( faction.getId() );
} else {
me.sendMessage("Faction " + parameters.get(0) + "not found");
}
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,33 @@
package org.mcteam.factions.commands;
import org.bukkit.command.CommandSender;
import org.mcteam.factions.Factions;
public class FCommandLock extends FBaseCommand {
public FCommandLock() {
aliases.add("lock");
optionalParameters.add("on|off");
helpDescription = "lock all write stuff";
}
@Override
public boolean hasPermission(CommandSender sender) {
return Factions.hasPermLock(sender);
}
public void perform() {
if( parameters.size() > 0 ) {
setLock( parseBool( parameters.get(0) ));
} else {
if( isLocked() ) {
me.sendMessage("Factions is locked");
} else {
me.sendMessage("Factions is not locked");
}
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,38 @@
package org.mcteam.factions.commands;
import org.bukkit.command.CommandSender;
import org.mcteam.factions.Board;
import org.mcteam.factions.Conf;
import org.mcteam.factions.FPlayer;
import org.mcteam.factions.Faction;
import org.mcteam.factions.Factions;
public class FCommandReload extends FBaseCommand {
public FCommandReload() {
aliases.add("reload");
helpDescription = "reloads the config";
}
@Override
public boolean hasPermission(CommandSender sender) {
return Factions.hasPermReload(sender);
}
public void perform() {
Factions.log("=== RELOAD START ===");
long timeInitStart = System.currentTimeMillis();
Conf.load();
FPlayer.load();
Faction.load();
Board.load();
long timeReload = (System.currentTimeMillis()-timeInitStart);
Factions.log("=== RELOAD DONE (Took "+timeReload+"ms) ===");
me.sendMessage("FACTIONS RELOAD DONE IN " + timeReload + "ms");
}
}

View File

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

View File

@ -0,0 +1,26 @@
package org.mcteam.factions.commands;
import org.bukkit.command.CommandSender;
import org.mcteam.factions.Factions;
public class FCommandSaveAll extends FBaseCommand {
public FCommandSaveAll() {
aliases.add("saveall");
aliases.add("save");
helpDescription = "save factions to disk";
}
@Override
public boolean hasPermission(CommandSender sender) {
return Factions.hasPermSaveAll(sender);
}
public void perform() {
Factions.saveAll();
me.sendMessage("Factions saved to disk!");
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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