mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-26 04:05:56 +01:00
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:
commit
b23c531e97
@ -26,6 +26,7 @@ import org.mcteam.factions.commands.FCommandClaim;
|
||||
import org.mcteam.factions.commands.FCommandCreate;
|
||||
import org.mcteam.factions.commands.FCommandDeinvite;
|
||||
import org.mcteam.factions.commands.FCommandDescription;
|
||||
import org.mcteam.factions.commands.FCommandDisband;
|
||||
import org.mcteam.factions.commands.FCommandHelp;
|
||||
import org.mcteam.factions.commands.FCommandHome;
|
||||
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.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 +89,8 @@ public class Factions extends JavaPlugin {
|
||||
|
||||
private String baseCommand;
|
||||
|
||||
private static boolean lock = false;
|
||||
|
||||
public Factions() {
|
||||
Factions.instance = this;
|
||||
}
|
||||
@ -95,8 +101,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());
|
||||
@ -106,18 +110,22 @@ public class Factions extends JavaPlugin {
|
||||
commands.add(new FCommandCreate());
|
||||
commands.add(new FCommandDeinvite());
|
||||
commands.add(new FCommandDescription());
|
||||
commands.add(new FCommandDisband());
|
||||
commands.add(new FCommandHome());
|
||||
commands.add(new FCommandInvite());
|
||||
commands.add(new FCommandJoin());
|
||||
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 +135,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 +222,22 @@ 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);
|
||||
}
|
||||
|
||||
public static boolean hasPermDisband(CommandSender sender) {
|
||||
return hasPerm(sender, "factions.disband", true);
|
||||
}
|
||||
|
||||
private static boolean hasPerm(CommandSender sender, String permNode, boolean fallbackOnlyOp) {
|
||||
if (Factions.Permissions == null || ! (sender instanceof Player)) {
|
||||
return fallbackOnlyOp == false || sender.isOp();
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,11 @@ public class FCommandAdmin extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.ADMIN)) {
|
||||
return;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -26,6 +26,12 @@ public class FCommandCreate extends FBaseCommand {
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
String tag = parameters.get(0);
|
||||
|
||||
if (me.hasFaction()) {
|
||||
|
@ -21,6 +21,11 @@ public class FCommandDeinvite extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
String playerName = parameters.get(0);
|
||||
|
||||
FPlayer you = findFPlayer(playerName, false);
|
||||
|
@ -20,6 +20,11 @@ public class FCommandDescription extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
35
src/org/mcteam/factions/commands/FCommandDisband.java
Normal file
35
src/org/mcteam/factions/commands/FCommandDisband.java
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,11 @@ public class FCommandInvite extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -20,6 +20,11 @@ public class FCommandLeave extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
me.leave();
|
||||
}
|
||||
|
||||
|
33
src/org/mcteam/factions/commands/FCommandLock.java
Normal file
33
src/org/mcteam/factions/commands/FCommandLock.java
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -20,6 +20,11 @@ public class FCommandMod extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.ADMIN)) {
|
||||
return;
|
||||
}
|
||||
|
@ -18,6 +18,11 @@ public class FCommandOpen extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
@ -9,6 +9,12 @@ public class FCommandRelationAlly extends FRelationCommand {
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
relation(Relation.ALLY, parameters.get(0));
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,12 @@ public class FCommandRelationEnemy extends FRelationCommand {
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
relation(Relation.ENEMY, parameters.get(0));
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,12 @@ public class FCommandRelationNeutral extends FRelationCommand {
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
relation(Relation.NEUTRAL, parameters.get(0));
|
||||
}
|
||||
|
||||
|
38
src/org/mcteam/factions/commands/FCommandReload.java
Normal file
38
src/org/mcteam/factions/commands/FCommandReload.java
Normal 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");
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
|
26
src/org/mcteam/factions/commands/FCommandSaveAll.java
Normal file
26
src/org/mcteam/factions/commands/FCommandSaveAll.java
Normal 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!");
|
||||
}
|
||||
|
||||
}
|
@ -17,6 +17,11 @@ public class FCommandSethome extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
@ -23,6 +23,11 @@ public class FCommandTag extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -19,6 +19,11 @@ public class FCommandUnclaimall extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
@ -21,6 +21,11 @@ public class FRelationCommand extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isLocked() ) {
|
||||
sendLockMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! assertMinRole(Role.MODERATOR)) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user