From 97a2ed1fd85ec9a50caa0261374b50ec81c743bb Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 16 Apr 2013 11:27:03 +0200 Subject: [PATCH] No More ZCore --- src/com/massivecraft/factions/FPerm.java | 4 +- src/com/massivecraft/factions/FPlayer.java | 14 +- src/com/massivecraft/factions/Factions.java | 42 +- .../factions/cmd/CmdFactionsAdmin.java | 8 +- .../factions/cmd/CmdFactionsAutoClaim.java | 3 +- .../factions/cmd/CmdFactionsClaim.java | 2 +- .../factions/cmd/CmdFactionsCreate.java | 3 +- .../factions/cmd/CmdFactionsDeinvite.java | 3 +- .../factions/cmd/CmdFactionsFlag.java | 7 +- .../factions/cmd/CmdFactionsHome.java | 3 +- .../factions/cmd/CmdFactionsInvite.java | 3 +- .../factions/cmd/CmdFactionsJoin.java | 2 +- .../factions/cmd/CmdFactionsKick.java | 4 +- .../factions/cmd/CmdFactionsLeader.java | 2 +- .../factions/cmd/CmdFactionsMap.java | 46 +- .../factions/cmd/CmdFactionsPerm.java | 10 +- .../factions/cmd/CmdFactionsPowerBoost.java | 20 +- .../factions/cmd/CmdFactionsSethome.java | 5 +- .../massivecraft/factions/cmd/FCommand.java | 4 +- .../factions/integration/Econ.java | 2 +- .../listeners/FactionsBlockListener.java | 2 +- .../listeners/FactionsPlayerListener.java | 6 +- .../factions/zcore/CommandVisibility.java | 9 - src/com/massivecraft/factions/zcore/Lang.java | 11 - .../massivecraft/factions/zcore/MCommand.java | 469 ------------------ .../massivecraft/factions/zcore/MPlugin.java | 89 ---- 26 files changed, 97 insertions(+), 676 deletions(-) delete mode 100644 src/com/massivecraft/factions/zcore/CommandVisibility.java delete mode 100644 src/com/massivecraft/factions/zcore/Lang.java delete mode 100644 src/com/massivecraft/factions/zcore/MCommand.java delete mode 100644 src/com/massivecraft/factions/zcore/MPlugin.java diff --git a/src/com/massivecraft/factions/FPerm.java b/src/com/massivecraft/factions/FPerm.java index d94235fd..fc2490a6 100644 --- a/src/com/massivecraft/factions/FPerm.java +++ b/src/com/massivecraft/factions/FPerm.java @@ -155,7 +155,7 @@ public enum FPerm // TODO: Create better description messages like: "You must at least be officer". boolean ret = hostFaction.getPermittedRelations(this).contains(rel); - if (rpSubject instanceof FPlayer && ret == false && ((FPlayer)rpSubject).hasAdminMode()) ret = true; + if (rpSubject instanceof FPlayer && ret == false && ((FPlayer)rpSubject).isUsingAdminMode()) ret = true; if (!ret && informIfNot && rpSubject instanceof FPlayer) { @@ -163,7 +163,7 @@ public enum FPerm fplayer.msg(errorpattern, hostFaction.describeTo(fplayer, true), this.getDescription()); if (Perm.ADMIN.has(fplayer.getPlayer())) { - fplayer.msg("You can bypass by using " + Factions.get().cmdBase.cmdFactionsAdmin.getUseageTemplate(false)); + fplayer.msg("You can bypass by using " + Factions.get().getOuterCmdFactions().cmdFactionsAdmin.getUseageTemplate(false)); } } return ret; diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 84d50c40..eb11a452 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -123,9 +123,9 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public Faction getAutoClaimFor() { return autoClaimFor; } public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; } - private transient boolean hasAdminMode = false; - public boolean hasAdminMode() { return this.hasAdminMode; } - public void setHasAdminMode(boolean val) { this.hasAdminMode = val; } + private transient boolean usingAdminMode = false; + public boolean isUsingAdminMode() { return this.usingAdminMode; } + public void setUsingAdminMode(boolean val) { this.usingAdminMode = val; } // FIELD: loginPvpDisabled private transient boolean loginPvpDisabled; @@ -490,7 +490,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public void leave(boolean makePay) { Faction myFaction = this.getFaction(); - makePay = makePay && Econ.shouldBeUsed() && ! this.hasAdminMode(); + makePay = makePay && Econ.shouldBeUsed() && ! this.isUsingAdminMode(); if (myFaction == null) { @@ -575,7 +575,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato { error = Txt.parse("Sorry, this world has land claiming disabled."); } - else if (this.hasAdminMode()) + else if (this.isUsingAdminMode()) { return true; } @@ -610,7 +610,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato else if ( ConfServer.claimsMustBeConnected - && ! this.hasAdminMode() + && ! this.isUsingAdminMode() && myFaction.getLandRoundedInWorld(ps.getWorld()) > 0 && !BoardColl.get().isConnectedPs(ps, myFaction) && (!ConfServer.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) @@ -655,7 +655,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // TODO: Add flag no costs?? // if economy is enabled and they're not on the bypass list, make sure they can pay - boolean mustPay = Econ.shouldBeUsed() && ! this.hasAdminMode(); + boolean mustPay = Econ.shouldBeUsed() && ! this.isUsingAdminMode(); double cost = 0.0; EconomyParticipator payee = null; if (mustPay) diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 56c332b2..88f5ec46 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -1,9 +1,5 @@ package com.massivecraft.factions; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; - import com.massivecraft.factions.adapters.BoardAdapter; import com.massivecraft.factions.adapters.BoardMapAdapter; import com.massivecraft.factions.adapters.FFlagAdapter; @@ -26,11 +22,8 @@ import com.massivecraft.factions.listeners.FactionsPlayerListener; import com.massivecraft.factions.util.AutoLeaveTask; import com.massivecraft.factions.util.EconLandRewardTask; import com.massivecraft.factions.util.LazyLocation; -import com.massivecraft.factions.zcore.MPlugin; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; +import com.massivecraft.mcore.MPlugin; import com.massivecraft.mcore.xlib.gson.GsonBuilder; @@ -48,6 +41,10 @@ public class Factions extends MPlugin // FIELDS // -------------------------------------------- // + // Commands + private CmdFactions outerCmdFactions; + public CmdFactions getOuterCmdFactions() { return this.outerCmdFactions; } + // Listeners public FactionsPlayerListener playerListener; public FactionsChatListener chatListener; @@ -58,10 +55,6 @@ public class Factions extends MPlugin // Task Ids private Integer AutoLeaveTask = null; private Integer econLandRewardTaskID = null; - - // Commands - public CmdFactions cmdBase; - public CmdFactionsAutoHelp cmdAutoHelp; // -------------------------------------------- // // OVERRIDE @@ -75,14 +68,14 @@ public class Factions extends MPlugin // Load Server Config ConfServer.get().load(); - // Load Conf from disk + // Initialize Collections FPlayerColl.get().init(); FactionColl.get().init(); BoardColl.get().init(); - - // Add Base Commands - this.cmdAutoHelp = new CmdFactionsAutoHelp(); - this.cmdBase = new CmdFactions(); + + // Commands + this.outerCmdFactions = new CmdFactions(); + this.outerCmdFactions.register(this); EssentialsFeatures.setup(); SpoutFeatures.setup(); @@ -125,17 +118,15 @@ public class Factions extends MPlugin @Override public GsonBuilder getGsonBuilder() { - return new GsonBuilder() - .setPrettyPrinting() - .disableHtmlEscaping() - .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE) + return super.getGsonBuilder() .registerTypeAdapter(LazyLocation.class, new LazyLocationAdapter()) .registerTypeAdapter(TerritoryAccess.class, TerritoryAccessAdapter.get()) .registerTypeAdapter(Board.class, BoardAdapter.get()) .registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get()) .registerTypeAdapter(Rel.class, new RelAdapter()) .registerTypeAdapter(FPerm.class, new FPermAdapter()) - .registerTypeAdapter(FFlag.class, new FFlagAdapter()); + .registerTypeAdapter(FFlag.class, new FFlagAdapter()) + ; } @Override @@ -186,13 +177,6 @@ public class Factions extends MPlugin econLandRewardTaskID = getServer().getScheduler().scheduleSyncRepeatingTask(this, new EconLandRewardTask(), ticks, ticks); } } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] split) - { - this.cmdBase.execute(sender, new ArrayList(Arrays.asList(split))); - return true; - } // -------------------------------------------- // // Functions for other plugins to hook into diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAdmin.java b/src/com/massivecraft/factions/cmd/CmdFactionsAdmin.java index 7f2ac2e2..501ca785 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAdmin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAdmin.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; +import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsAdmin extends FCommand @@ -18,9 +19,12 @@ public class CmdFactionsAdmin extends FCommand @Override public void perform() { - fme.setHasAdminMode(this.argAsBool(0, ! fme.hasAdminMode())); + Boolean target = this.arg(0, ARBoolean.get(), !fme.isUsingAdminMode()); + if (target == null) return; - if ( fme.hasAdminMode()) + fme.setUsingAdminMode(target); + + if ( fme.isUsingAdminMode()) { fme.msg("You have enabled admin bypass mode."); Factions.get().log(fme.getName() + " has ENABLED admin bypass mode."); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java index 4496ff98..a4129924 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; @@ -21,7 +22,7 @@ public class CmdFactionsAutoClaim extends FCommand @Override public void perform() { - Faction forFaction = this.argAsFaction(0, myFaction); + Faction forFaction = this.arg(0, ARFaction.get(), myFaction); if (forFaction == null || forFaction == fme.getAutoClaimFor()) { fme.setAutoClaimFor(null); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java index eff2279e..ad8fa7ef 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java @@ -28,7 +28,7 @@ public class CmdFactionsClaim extends FCommand @Override public void perform() { - Faction forFaction = this.arg(0, ARFaction.get()); + final Faction forFaction = this.arg(0, ARFaction.get()); if (forFaction == null) return; Integer radius = this.arg(1, ARInteger.get(), 1); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index 73e3a8d6..c5a2c9fb 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -15,7 +15,6 @@ import com.massivecraft.factions.Rel; import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FactionCreateEvent; import com.massivecraft.mcore.cmd.req.ReqHasPerm; -import com.massivecraft.mcore.cmd.req.ReqIsPlayer; public class CmdFactionsCreate extends FCommand { @@ -91,7 +90,7 @@ public class CmdFactionsCreate extends FCommand follower.msg("%s created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower)); } - msg("You should now: %s", p.cmdBase.cmdFactionsDescription.getUseageTemplate()); + msg("You should now: %s", Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate()); if (ConfServer.logFactionCreate) Factions.get().log(fme.getName()+" created a new faction: "+tag); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java index 13a6039c..964bdabe 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -31,7 +32,7 @@ public class CmdFactionsDeinvite extends FCommand if (you.getFaction() == myFaction) { msg("%s is already a member of %s", you.getName(), myFaction.getTag()); - msg("You might want to: %s", p.cmdBase.cmdFactionsKick.getUseageTemplate(false)); + msg("You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false)); return; } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java index 9464a4c3..c9df1592 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java @@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFFlag; import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -37,8 +39,9 @@ public class CmdFactionsFlag extends FCommand return; } - FFlag flag = this.argAsFactionFlag(1); + FFlag flag = this.arg(1, ARFFlag.get()); if (flag == null) return; + if ( ! this.argIsSet(2)) { msg(Txt.titleize("Flag for " + faction.describeTo(fme, true))); @@ -46,7 +49,7 @@ public class CmdFactionsFlag extends FCommand return; } - Boolean targetValue = this.argAsBool(2); + Boolean targetValue = this.arg(2, ARBoolean.get()); if (targetValue == null) return; // Do the sender have the right to change flags? diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java index 7c1604fc..39b2b35b 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -13,6 +13,7 @@ import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.integration.EssentialsFeatures; @@ -53,7 +54,7 @@ public class CmdFactionsHome extends FCommand if ( ! myFaction.hasHome()) { fme.msg("Your faction does not have a home. " + (fme.getRole().isLessThan(Rel.OFFICER) ? " Ask your leader to:" : "You should:")); - fme.sendMessage(p.cmdBase.cmdFactionsSethome.getUseageTemplate()); + fme.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsSethome.getUseageTemplate()); return; } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java index 59a4bd64..51c9c21c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFaction; @@ -33,7 +34,7 @@ public class CmdFactionsInvite extends FCommand if (you.getFaction() == myFaction) { msg("%s is already a member of %s", you.getName(), myFaction.getTag()); - msg("You might want to: " + p.cmdBase.cmdFactionsKick.getUseageTemplate(false)); + msg("You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false)); return; } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index decbe244..b03b615b 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -66,7 +66,7 @@ public class CmdFactionsJoin extends FCommand return; } - if( ! (faction.isOpen() || faction.isInvited(fplayer) || fme.hasAdminMode() || Perm.JOIN_ANY.has(sender, false))) + if( ! (faction.isOpen() || faction.isInvited(fplayer) || fme.isUsingAdminMode() || Perm.JOIN_ANY.has(sender, false))) { msg("This faction requires invitation."); if (samePlayer) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java index 6f7d3f7b..9cd761d6 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -34,11 +34,11 @@ public class CmdFactionsKick extends FCommand if (fme == you) { msg("You cannot kick yourself."); - msg("You might want to: %s", p.cmdBase.cmdFactionsLeave.getUseageTemplate(false)); + msg("You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsLeave.getUseageTemplate(false)); return; } - if (you.getRole() == Rel.LEADER && !(this.senderIsConsole || fme.hasAdminMode())) + if (you.getRole() == Rel.LEADER && !(this.senderIsConsole || fme.isUsingAdminMode())) { msg("The leader can not be kicked."); return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java index ab1f6f4a..82fec7e3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java @@ -38,7 +38,7 @@ public class CmdFactionsLeader extends FCommand FPlayer targetFactionCurrentLeader = targetFaction.getFPlayerLeader(); // We now have fplayer and the target faction - if (this.senderIsConsole || fme.hasAdminMode() || Perm.LEADER_ANY.has(sender, false)) + if (this.senderIsConsole || fme.isUsingAdminMode() || Perm.LEADER_ANY.has(sender, false)) { // Do whatever you wish } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index c2de6684..04a4846f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.BoardColl; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Perm; +import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -23,34 +24,33 @@ public class CmdFactionsMap extends FCommand @Override public void perform() { - if (this.argIsSet(0)) - { - if (this.argAsBool(0, ! fme.isMapAutoUpdating())) - { - // Turn on - - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return; - - fme.setMapAutoUpdating(true); - msg("Map auto update ENABLED."); - - // And show the map once - showMap(); - } - else - { - // Turn off - fme.setMapAutoUpdating(false); - msg("Map auto update DISABLED."); - } - } - else + if (!this.argIsSet(0)) { // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return; showMap(); + return; + } + + if (this.arg(0, ARBoolean.get(), !fme.isMapAutoUpdating())) + { + // Turn on + + // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay + if ( ! payForCommand(ConfServer.econCostMap, "to show the map", "for showing the map")) return; + + fme.setMapAutoUpdating(true); + msg("Map auto update ENABLED."); + + // And show the map once + showMap(); + } + else + { + // Turn off + fme.setMapAutoUpdating(false); + msg("Map auto update DISABLED."); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java index 80737562..30054a56 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java @@ -4,7 +4,10 @@ import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.arg.ARFPerm; import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.cmd.arg.ARRel; +import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -40,8 +43,9 @@ public class CmdFactionsPerm extends FCommand return; } - FPerm perm = this.argAsFactionPerm(1); + FPerm perm = this.arg(1, ARFPerm.get()); if (perm == null) return; + if ( ! this.argIsSet(2)) { msg(Txt.titleize("Perm for " + faction.describeTo(fme, true))); @@ -53,10 +57,10 @@ public class CmdFactionsPerm extends FCommand // Do the sender have the right to change perms for this faction? if ( ! FPerm.PERMS.has(sender, faction, true)) return; - Rel rel = this.argAsRel(2); + Rel rel = this.arg(2, ARRel.get()); if (rel == null) return; - Boolean val = this.argAsBool(3, null); + Boolean val = this.arg(3, ARBoolean.get(), null); if (val == null) return; // Do the change diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java index 23203565..f96aa5c6 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java @@ -4,6 +4,9 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFPlayer; +import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.mcore.cmd.arg.ARDouble; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsPowerBoost extends FCommand @@ -35,32 +38,29 @@ public class CmdFactionsPowerBoost extends FCommand return; } - Double targetPower = this.argAsDouble(2); - if (targetPower == null) - { - msg("You must specify a valid numeric value for the power bonus/penalty amount."); - return; - } + Double targetPower = this.arg(2, ARDouble.get()); + if (targetPower == null) return; String target; if (doPlayer) { - FPlayer targetPlayer = this.argAsBestFPlayerMatch(1); + FPlayer targetPlayer = this.arg(1, ARFPlayer.getStartAny()); if (targetPlayer == null) return; + targetPlayer.setPowerBoost(targetPower); target = "Player \""+targetPlayer.getName()+"\""; } else { - Faction targetFaction = this.argAsFaction(1); + Faction targetFaction = this.arg(1, ARFaction.get()); if (targetFaction == null) return; + targetFaction.setPowerBoost(targetPower); target = "Faction \""+targetFaction.getTag()+"\""; } msg(""+target+" now has a power bonus/penalty of "+targetPower+" to min and max power levels."); - if (!senderIsConsole) - Factions.get().log(fme.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+"."); + Factions.get().log(fme.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+"."); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java index d8b7b140..0e6afbc8 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.BoardColl; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -40,7 +41,7 @@ public class CmdFactionsSethome extends FCommand // Can the player set the faction home HERE? if ( - ! fme.hasAdminMode() + ! fme.isUsingAdminMode() && ConfServer.homesMustBeInClaimedTerritory && @@ -57,7 +58,7 @@ public class CmdFactionsSethome extends FCommand faction.setHome(me.getLocation()); faction.msg("%s set the home for your faction. You can now use:", fme.describeTo(myFaction, true)); - faction.sendMessage(p.cmdBase.cmdFactionsHome.getUseageTemplate()); + faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate()); if (faction != myFaction) { fme.msg("You have set the home for the "+faction.getTag(fme)+" faction."); diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index 15b39eff..6b89bb51 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -64,7 +64,7 @@ public abstract class FCommand extends MCommand // if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost public boolean payForCommand(double cost, String toDoThis, String forDoingThis) { - if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true; + if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isUsingAdminMode()) return true; if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction()) return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis); @@ -75,7 +75,7 @@ public abstract class FCommand extends MCommand // like above, but just make sure they can pay; returns true unless person can't afford the cost public boolean canAffordCommand(double cost, String toDoThis) { - if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true; + if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isUsingAdminMode()) return true; if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction()) return Econ.hasAtLeast(myFaction, cost, toDoThis); diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index 85c72760..07fd11fe 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -90,7 +90,7 @@ public class Econ if (fI == null) return true; // Bypassing players can do any kind of transaction - if (i instanceof FPlayer && ((FPlayer)i).hasAdminMode()) return true; + if (i instanceof FPlayer && ((FPlayer)i).isUsingAdminMode()) return true; // You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again. if (i == you) return true; diff --git a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java index 2f940b3d..b49a2056 100644 --- a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -88,7 +88,7 @@ public class FactionsBlockListener implements Listener if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true; FPlayer me = FPlayer.get(name); - if (me.hasAdminMode()) return true; + if (me.isUsingAdminMode()) return true; PS ps = PS.valueOf(location); Faction factionHere = BoardColl.get().getFactionAt(ps); diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index e1a2cca9..1bc2b8c0 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -205,7 +205,7 @@ public class FactionsPlayerListener implements Listener if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true; FPlayer me = FPlayerColl.get().get(name); - if (me.hasAdminMode()) return true; + if (me.isUsingAdminMode()) return true; if (Const.MATERIALS_EDIT_TOOLS.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; return true; } @@ -215,7 +215,7 @@ public class FactionsPlayerListener implements Listener if (ConfServer.playersWhoBypassAllProtection.contains(name)) return true; FPlayer me = FPlayerColl.get().get(name); - if (me.hasAdminMode()) return true; + if (me.isUsingAdminMode()) return true; Location loc = block.getLocation(); Material material = block.getType(); @@ -293,7 +293,7 @@ public class FactionsPlayerListener implements Listener FPlayer me = FPlayerColl.get().get(player); // With adminmode no commands are denied. - if (me.hasAdminMode()) return; + if (me.isUsingAdminMode()) return; // The full command is converted to lowercase and does include the slash in the front String fullCmd = event.getMessage().toLowerCase(); diff --git a/src/com/massivecraft/factions/zcore/CommandVisibility.java b/src/com/massivecraft/factions/zcore/CommandVisibility.java deleted file mode 100644 index f63964be..00000000 --- a/src/com/massivecraft/factions/zcore/CommandVisibility.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.massivecraft.factions.zcore; - -public enum CommandVisibility -{ - VISIBLE, // Visible commands are visible to anyone. Even those who don't have permission to use it or is of invalid sender type. - SECRET, // Secret commands are visible only to those who can use the command. These commands are usually some kind of admin commands. - INVISIBLE, // Invisible commands are invisible to everyone, even those who can use the command. - ; -} diff --git a/src/com/massivecraft/factions/zcore/Lang.java b/src/com/massivecraft/factions/zcore/Lang.java deleted file mode 100644 index 5605f9ce..00000000 --- a/src/com/massivecraft/factions/zcore/Lang.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.massivecraft.factions.zcore; - -public class Lang -{ - public static final String permForbidden = "You don't have permission to %s."; - public static final String permDoThat = "do that"; - - public static final String commandSenderMustBePlayer = "This command can only be used by ingame players."; - public static final String commandToFewArgs = "Too few arguments. Use like this:"; - public static final String commandToManyArgs = "Strange argument \"

%s\". Use the command like this:"; -} diff --git a/src/com/massivecraft/factions/zcore/MCommand.java b/src/com/massivecraft/factions/zcore/MCommand.java deleted file mode 100644 index a346a95a..00000000 --- a/src/com/massivecraft/factions/zcore/MCommand.java +++ /dev/null @@ -1,469 +0,0 @@ -package com.massivecraft.factions.zcore; - -import java.util.*; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.massivecraft.factions.zcore.MCommand; -import com.massivecraft.factions.zcore.MPlugin; -import com.massivecraft.mcore.util.PermUtil; -import com.massivecraft.mcore.util.Txt; - - -public abstract class MCommand -{ - public T p; - - // The sub-commands to this command - public List> subCommands; - public void addSubCommand(MCommand subCommand) - { - subCommand.commandChain.addAll(this.commandChain); - subCommand.commandChain.add(this); - this.subCommands.add(subCommand); - } - - // The different names this commands will react to - public List aliases; - - // Information on the args - public List requiredArgs; - public LinkedHashMap optionalArgs; - public boolean errorOnToManyArgs = true; - - // FIELD: Help Short - // This field may be left blank and will in such case be loaded from the permissions node instead. - // Thus make sure the permissions node description is an action description like "eat hamburgers" or "do admin stuff". - private String helpShort; - public void setHelpShort(String val) { this.helpShort = val; } - public String getHelpShort() - { - if (this.helpShort == null) - { - String pdesc = PermUtil.getDescription(permission); - if (pdesc != null) - { - return pdesc; - } - return "*info unavailable*"; - } - return this.helpShort; - } - - public List helpLong; - public CommandVisibility visibility; - - // Some information on permissions - public boolean senderMustBePlayer; - public String permission; - - // Information available on execution of the command - public CommandSender sender; // Will always be set - public Player me; // Will only be set when the sender is a player - public boolean senderIsConsole; - public List args; // Will contain the arguments, or and empty list if there are none. - public List> commandChain = new ArrayList>(); // The command chain used to execute this command - - public MCommand(T p) - { - this.p = p; - - this.permission = null; - - this.subCommands = new ArrayList>(); - this.aliases = new ArrayList(); - - this.requiredArgs = new ArrayList(); - this.optionalArgs = new LinkedHashMap(); - - this.helpShort = null; - this.helpLong = new ArrayList(); - this.visibility = CommandVisibility.VISIBLE; - } - - // The commandChain is a list of the parent command chain used to get to this command. - public void execute(CommandSender sender, List args, List> commandChain) - { - // Set the execution-time specific variables - this.sender = sender; - if (sender instanceof Player) - { - this.me = (Player)sender; - this.senderIsConsole = false; - } - else - { - this.me = null; - this.senderIsConsole = true; - } - this.args = args; - this.commandChain = commandChain; - - // Is there a matching sub command? - if (args.size() > 0 ) - { - for (MCommand subCommand: this.subCommands) - { - if (subCommand.aliases.contains(args.get(0))) - { - args.remove(0); - commandChain.add(this); - subCommand.execute(sender, args, commandChain); - return; - } - } - } - - if ( ! validCall(this.sender, this.args)) return; - - if ( ! this.isEnabled()) return; - - perform(); - } - - public void execute(CommandSender sender, List args) - { - execute(sender, args, new ArrayList>()); - } - - // This is where the command action is performed. - public abstract void perform(); - - - // -------------------------------------------- // - // Call Validation - // -------------------------------------------- // - - /** - * In this method we validate that all prerequisites to perform this command has been met. - */ - // TODO: There should be a boolean for silence - public boolean validCall(CommandSender sender, List args) - { - if ( ! validSenderType(sender, true)) - { - return false; - } - - if ( ! validSenderPermissions(sender, true)) - { - return false; - } - - if ( ! validArgs(args, sender)) - { - return false; - } - - return true; - } - - public boolean isEnabled() - { - return true; - } - - public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) - { - if (this.senderMustBePlayer && ! (sender instanceof Player)) - { - if (informSenderIfNot) - { - msg(Lang.commandSenderMustBePlayer); - } - return false; - } - return true; - } - - public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) - { - if (this.permission == null) return true; - return PermUtil.has(sender, this.permission, informSenderIfNot); - } - - public boolean validArgs(List args, CommandSender sender) - { - if (args.size() < this.requiredArgs.size()) - { - if (sender != null) - { - msg(Lang.commandToFewArgs); - sender.sendMessage(this.getUseageTemplate()); - } - return false; - } - - if (args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.errorOnToManyArgs) - { - if (sender != null) - { - // Get the to many string slice - List theToMany = args.subList(this.requiredArgs.size() + this.optionalArgs.size(), args.size()); - msg(Lang.commandToManyArgs, Txt.implode(theToMany, " ")); - sender.sendMessage(this.getUseageTemplate()); - } - return false; - } - return true; - } - public boolean validArgs(List args) - { - return this.validArgs(args, null); - } - - // -------------------------------------------- // - // Help and Usage information - // -------------------------------------------- // - - public String getUseageTemplate(List> commandChain, boolean addShortHelp) - { - StringBuilder ret = new StringBuilder(); - ret.append(Txt.parse("")); - ret.append('/'); - - for (MCommand mc : commandChain) - { - ret.append(Txt.implode(mc.aliases, ",")); - ret.append(' '); - } - - ret.append(Txt.implode(this.aliases, ",")); - - List args = new ArrayList(); - - for (String requiredArg : this.requiredArgs) - { - args.add("<"+requiredArg+">"); - } - - for (Entry optionalArg : this.optionalArgs.entrySet()) - { - String val = optionalArg.getValue(); - if (val == null) - { - val = ""; - } - else - { - val = "="+val; - } - args.add("["+optionalArg.getKey()+val+"]"); - } - - if (args.size() > 0) - { - ret.append(Txt.parse("

")); - ret.append(Txt.implode(args, " ")); - } - - if (addShortHelp) - { - ret.append(Txt.parse(" ")); - ret.append(this.getHelpShort()); - } - - return ret.toString(); - } - - public String getUseageTemplate(boolean addShortHelp) - { - return getUseageTemplate(this.commandChain, addShortHelp); - } - - public String getUseageTemplate() - { - return getUseageTemplate(false); - } - - // -------------------------------------------- // - // Message Sending Helpers - // -------------------------------------------- // - - public void msg(String str, Object... args) - { - sender.sendMessage(Txt.parse(str, args)); - } - - public void sendMessage(String msg) - { - sender.sendMessage(msg); - } - - public void sendMessage(List msgs) - { - for(String msg : msgs) - { - this.sendMessage(msg); - } - } - - // -------------------------------------------- // - // Argument Readers - // -------------------------------------------- // - - // Is set? ====================== - public boolean argIsSet(int idx) - { - if (this.args.size() < idx+1) - { - return false; - } - return true; - } - - // STRING ====================== - public String argAsString(int idx, String def) - { - if (this.args.size() < idx+1) - { - return def; - } - return this.args.get(idx); - } - public String argAsString(int idx) - { - return this.argAsString(idx, null); - } - - // INT ====================== - public Integer strAsInt(String str, Integer def) - { - if (str == null) return def; - try - { - Integer ret = Integer.parseInt(str); - return ret; - } - catch (Exception e) - { - return def; - } - } - public Integer argAsInt(int idx, Integer def) - { - return strAsInt(this.argAsString(idx), def); - } - public Integer argAsInt(int idx) - { - return this.argAsInt(idx, null); - } - - // Double ====================== - public Double strAsDouble(String str, Double def) - { - if (str == null) return def; - try - { - Double ret = Double.parseDouble(str); - return ret; - } - catch (Exception e) - { - return def; - } - } - public Double argAsDouble(int idx, Double def) - { - return strAsDouble(this.argAsString(idx), def); - } - public Double argAsDouble(int idx) - { - return this.argAsDouble(idx, null); - } - - // TODO: Go through the str conversion for the other arg-readers as well. - // Boolean ====================== - public Boolean strAsBool(String str) - { - str = str.toLowerCase(); - if (str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1")) - { - return true; - } - return false; - } - public Boolean argAsBool(int idx, Boolean def) - { - String str = this.argAsString(idx); - if (str == null) return def; - - return strAsBool(str); - } - public Boolean argAsBool(int idx) - { - return this.argAsBool(idx, false); - } - - // PLAYER ====================== - public Player strAsPlayer(String name, Player def, boolean msg) - { - Player ret = def; - - if (name != null) - { - Player player = Bukkit.getServer().getPlayer(name); - if (player != null) - { - ret = player; - } - } - - if (msg && ret == null) - { - this.msg("No player \"

%s\" could not be found.", name); - } - - return ret; - } - - public Player argAsPlayer(int idx, Player def, boolean msg) - { - return this.strAsPlayer(this.argAsString(idx), def, msg); - } - public Player argAsPlayer(int idx, Player def) - { - return this.argAsPlayer(idx, def, true); - } - public Player argAsPlayer(int idx) - { - return this.argAsPlayer(idx, null); - } - - // BEST PLAYER MATCH ====================== - public Player strAsBestPlayerMatch(String name, Player def, boolean msg) - { - Player ret = def; - - if (name != null) - { - List players = Bukkit.getServer().matchPlayer(name); - if (players.size() > 0) - { - ret = players.get(0); - } - } - - if (msg && ret == null) - { - this.msg("No player match found for \"

%s\".", name); - } - - return ret; - } - public Player argAsBestPlayerMatch(int idx, Player def, boolean msg) - { - return this.strAsBestPlayerMatch(this.argAsString(idx), def, msg); - } - public Player argAsBestPlayerMatch(int idx, Player def) - { - return this.argAsBestPlayerMatch(idx, def, true); - } - public Player argAsBestPlayerMatch(int idx) - { - return this.argAsPlayer(idx, null); - } -} diff --git a/src/com/massivecraft/factions/zcore/MPlugin.java b/src/com/massivecraft/factions/zcore/MPlugin.java deleted file mode 100644 index e1c5e785..00000000 --- a/src/com/massivecraft/factions/zcore/MPlugin.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.massivecraft.factions.zcore; - -import java.lang.reflect.Modifier; -import java.util.logging.Level; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; - -import com.massivecraft.mcore.util.Txt; -import com.massivecraft.mcore.xlib.gson.Gson; -import com.massivecraft.mcore.xlib.gson.GsonBuilder; - - -public abstract class MPlugin extends JavaPlugin -{ - // Persist related - public Gson gson; - - // -------------------------------------------- // - // ENABLE - // -------------------------------------------- // - private long timeEnableStart; - public boolean preEnable() - { - log("=== ENABLE START ==="); - timeEnableStart = System.currentTimeMillis(); - - // Ensure basefolder exists! - this.getDataFolder().mkdirs(); - - this.gson = this.getGsonBuilder().create(); - - return true; - } - - public void postEnable() - { - log("=== ENABLE DONE (Took "+(System.currentTimeMillis()-timeEnableStart)+"ms) ==="); - } - - public void onDisable() - { - log("Disabled"); - } - - public void suicide() - { - log("Now I suicide!"); - this.getServer().getPluginManager().disablePlugin(this); - } - - // -------------------------------------------- // - // Some inits... - // You are supposed to override these in the plugin if you aren't satisfied with the defaults - // The goal is that you always will be satisfied though. - // -------------------------------------------- // - - public GsonBuilder getGsonBuilder() - { - return new GsonBuilder() - .setPrettyPrinting() - .disableHtmlEscaping() - .serializeNulls() - .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE); - } - - // -------------------------------------------- // - // LOGGING - // -------------------------------------------- // - public void log(Object msg) - { - log(Level.INFO, msg); - } - - public void log(String str, Object... args) - { - log(Level.INFO, Txt.parse(str, args)); - } - - public void log(Level level, String str, Object... args) - { - log(level, Txt.parse(str, args)); - } - - public void log(Level level, Object msg) - { - Bukkit.getLogger().log(level, "["+this.getDescription().getFullName()+"] "+msg); - } -}