singletonList(null));
this.setHelpShort("The faction base command");
- this.helpLong.add(p.txt.parseTags("This command contains all faction stuff."));
+ this.helpLong.add(FactionsPlugin.getInstance().txt.parseTags("This command contains all faction stuff."));
- //this.subCommands.add(plugin.cmdHelp);
+ if (CommodoreProvider.isSupported()) brigadierManager = new BrigadierManager();
this.addSubCommand(this.cmdAdmin);
this.addSubCommand(this.cmdAutoClaim);
@@ -175,7 +174,6 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdDeinvite);
this.addSubCommand(this.cmdDescription);
this.addSubCommand(this.cmdDisband);
- this.addSubCommand(this.cmdStrike);
this.addSubCommand(this.cmdHelp);
this.addSubCommand(this.cmdHome);
this.addSubCommand(this.cmdInvite);
@@ -187,7 +185,6 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdMap);
this.addSubCommand(this.cmdMod);
this.addSubCommand(this.cmdMoney);
- this.addSubCommand(this.cmdNotifications);
this.addSubCommand(this.cmdOpen);
this.addSubCommand(this.cmdOwner);
this.addSubCommand(this.cmdOwnerList);
@@ -253,72 +250,88 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdTntFill);
this.addSubCommand(this.cmdChest);
this.addSubCommand(this.cmdSetBanner);
- this.addSubCommand(this.cmdStrikeSet);
- this.addSubCommand(this.cmdSpam);
this.addSubCommand(this.cmdCorner);
+ this.addSubCommand(this.cmdStrikes);
this.addSubCommand(this.cmdFGlobal);
this.addSubCommand(this.cmdViewChest);
+ this.addSubCommand(this.cmdConvertConfig);
if (Conf.useCheckSystem) {
this.addSubCommand(this.cmdCheck);
this.addSubCommand(this.cmdWeeWoo);
}
- if (P.p.getConfig().getBoolean("Missions-Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("Missions-Enabled")) {
this.addSubCommand(this.cmdMissions);
}
- if (P.p.getConfig().getBoolean("F-Shop.Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) {
this.addSubCommand(this.cmdShop);
}
- if (P.p.getConfig().getBoolean("f-inventory-see.Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled")) {
this.addSubCommand(this.cmdInventorySee);
}
- if (P.p.getConfig().getBoolean("f-points.Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled")) {
this.addSubCommand(this.cmdPoints);
}
- if (P.p.getConfig().getBoolean("f-alts.Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled")) {
this.addSubCommand(this.cmdAlts);
}
- if (P.p.getConfig().getBoolean("f-grace.Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) {
this.addSubCommand(this.cmdGrace);
}
if (Bukkit.getServer().getPluginManager().getPlugin("CoreProtect") != null) {
- P.p.log("Found CoreProtect, enabling Inspect");
+ FactionsPlugin.getInstance().log("Found CoreProtect, enabling Inspect");
this.addSubCommand(this.cmdInspect);
} else {
- P.p.log("CoreProtect not found, disabling Inspect");
+ FactionsPlugin.getInstance().log("CoreProtect not found, disabling Inspect");
}
- if (P.p.getConfig().getBoolean("ffocus.Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled")) {
addSubCommand(this.cmdFocus);
}
- if (P.p.getConfig().getBoolean("enable-faction-flight", false)) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) {
this.addSubCommand(this.cmdFly);
}
if (Bukkit.getServer().getPluginManager().getPlugin("FactionsTop") != null || Bukkit.getServer().getPluginManager().getPlugin("SavageFTOP") != null || Bukkit.getServer().getPluginManager().getPlugin("SaberFTOP") != null) {
- P.p.log(Level.INFO, "Found FactionsTop plugin. Disabling our own /f top command.");
+ FactionsPlugin.getInstance().log(Level.INFO, "Found FactionsTop plugin. Disabling our own /f top command.");
} else {
- P.p.log(Level.INFO, "Enabling FactionsTop command, this is a very basic /f top please get a dedicated /f top resource if you want land calculation etc.");
+ FactionsPlugin.getInstance().log(Level.INFO, "Enabling FactionsTop command, this is a very basic /f top please get a dedicated /f top resource if you want land calculation etc.");
this.addSubCommand(this.cmdTop);
}
- if (P.p.getConfig().getBoolean("fpaypal.Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) {
this.addSubCommand(this.cmdPaypalSet);
this.addSubCommand(this.cmdPaypalSee);
}
+ if (CommodoreProvider.isSupported()) brigadierManager.build();
}
@Override
- public void perform() {
- this.commandChain.add(this);
- this.cmdHelp.execute(this.sender, this.args, this.commandChain);
+ public void perform(CommandContext context) {
+ context.commandChain.add(this);
+ this.cmdHelp.execute(context);
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ this.execute(new CommandContext(sender, new ArrayList<>(Arrays.asList(args)), label));
+ return true;
+ }
+
+ @Override
+ public void addSubCommand(FCommand subCommand) {
+ super.addSubCommand(subCommand);
+ // People were getting NPE's as somehow CommodoreProvider#isSupported returned true on legacy versions.
+ if (CommodoreProvider.isSupported()) {
+ brigadierManager.addSubCommand(subCommand);
+ }
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/FCommand.java b/src/main/java/com/massivecraft/factions/cmd/FCommand.java
index ac716da8..f2553930 100644
--- a/src/main/java/com/massivecraft/factions/cmd/FCommand.java
+++ b/src/main/java/com/massivecraft/factions/cmd/FCommand.java
@@ -1,351 +1,248 @@
package com.massivecraft.factions.cmd;
-import com.massivecraft.factions.*;
+import com.massivecraft.factions.FPlayer;
+import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.integration.Econ;
-import com.massivecraft.factions.struct.Role;
-import com.massivecraft.factions.util.WarmUpUtil;
-import com.massivecraft.factions.zcore.MCommand;
+import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.zcore.util.TL;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
+import com.massivecraft.factions.zcore.util.TextUtil;
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
import java.text.SimpleDateFormat;
-import java.util.List;
+import java.util.*;
-public abstract class FCommand extends MCommand {
+public abstract class FCommand {
- public static final SimpleDateFormat sdf = new SimpleDateFormat(TL.DATE_FORMAT.toString());
+ public SimpleDateFormat sdf = new SimpleDateFormat(TL.DATE_FORMAT.toString());
- public boolean disableOnLock;
- public boolean disableOnSpam;
+ // Command Aliases
+ public List aliases;
- public FPlayer fme;
- public Faction myFaction;
- public boolean senderMustBeMember;
- public boolean senderMustBeModerator;
- public boolean senderMustBeAdmin;
- public boolean senderMustBeColeader;
+ // Information on the args
+ public List requiredArgs;
+ public LinkedHashMap optionalArgs;
-
- public boolean isMoneyCommand;
+ // Requirements to execute this command
+ public CommandRequirements requirements;
+ /*
+ Subcommands
+ */
+ public List subCommands;
+ /*
+ Help
+ */
+ public List helpLong;
+ public CommandVisibility visibility;
+ private String helpShort;
public FCommand() {
- super(P.p);
- // Due to safety reasons it defaults to disable on lock.
- disableOnLock = true;
- disableOnSpam = false;
+ requirements = new CommandRequirements.Builder(null).build();
- // The money commands must be disabled if money should not be used.
- isMoneyCommand = false;
+ this.subCommands = new ArrayList<>();
+ this.aliases = new ArrayList<>();
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requiredArgs = new ArrayList<>();
+ this.optionalArgs = new LinkedHashMap<>();
+
+ this.helpShort = null;
+ this.helpLong = new ArrayList<>();
+ this.visibility = CommandVisibility.VISIBLE;
}
- @Override
- public void setCommandSender(CommandSender sender) {
- super.setCommandSender(sender);
- if (sender instanceof Player) {
- this.fme = FPlayers.getInstance().getByPlayer((Player) sender);
- this.myFaction = this.fme.getFaction();
- } else {
- this.fme = null;
- this.myFaction = null;
- }
- }
+ public abstract void perform(CommandContext context);
- @Override
- public void execute(CommandSender sender, List args, List> commandChain) {
- setCommandSender(sender);
- super.execute(sender, args, commandChain);
- }
-
- @Override
- public boolean isEnabled() {
- if (p.getLocked() && this.disableOnLock) {
- msg("Factions was locked by an admin. Please try again later.");
- return false;
- }
-
- if (p.getSpam() && this.disableOnSpam) {
- msg("Anti-Spam is currently enabled! Please try again later.");
- return false;
- }
-
- if (this.isMoneyCommand && !Conf.econEnabled) {
- msg("Faction economy features are disabled on this server.");
- return false;
- }
-
- if (this.isMoneyCommand && !Conf.bankEnabled) {
- msg("The faction bank system is disabled on this server.");
- return false;
- }
-
- return true;
- }
-
- @Override
- public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) {
- boolean superValid = super.validSenderType(sender, informSenderIfNot);
- if (!superValid) {
- return false;
- }
-
- if (!(this.senderMustBeMember || this.senderMustBeModerator || this.senderMustBeAdmin || this.senderMustBeColeader)) {
- return true;
- }
-
- if (!(sender instanceof Player)) {
- return false;
- }
-
- if (!fme.hasFaction()) {
- if (informSenderIfNot) {
- sender.sendMessage(p.txt.parse(TL.ACTIONS_NOFACTION.toString()));
- }
- return false;
- }
-
-
- if (this.senderMustBeModerator && !fme.getRole().isAtLeast(Role.MODERATOR)) {
- if (informSenderIfNot) {
- sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "moderator").replace("{action}", this.getHelpShort())));
- }
- return false;
- }
-
- if (this.senderMustBeColeader && !fme.getRole().isAtLeast(Role.COLEADER)) {
- if (informSenderIfNot) {
- sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "coleader").replace("{action}", this.getHelpShort())));
- }
- return false;
- }
-
- if (this.senderMustBeAdmin && !fme.getRole().isAtLeast(Role.LEADER)) {
- if (informSenderIfNot) {
- sender.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "admin").replace("{action}", this.getHelpShort())));
- }
- return false;
- }
-
-
- return true;
- }
-
- // -------------------------------------------- //
- // Assertions
- // -------------------------------------------- //
-
- public boolean assertHasFaction() {
- if (me == null) {
- return true;
- }
-
- if (!fme.hasFaction()) {
- msg(TL.ACTIONS_NOFACTION);
- return false;
- }
- return true;
- }
-
- public boolean assertMinRole(Role role) {
- if (me == null) {
- return true;
- }
-
- if (fme.getRole().value < role.value) {
- msg(TL.ACTIONS_MUSTBE.toString().replace("{role}", role.nicename).replace("{action}", this.getHelpShort()));
- return false;
- }
- return true;
- }
-
- // -------------------------------------------- //
- // Argument Readers
- // -------------------------------------------- //
-
- // FPLAYER ======================
- public FPlayer strAsFPlayer(String name, FPlayer def, boolean msg) {
- FPlayer ret = def;
-
- if (name != null) {
- for (FPlayer fplayer : FPlayers.getInstance().getAllFPlayers()) {
- if (fplayer.getName().equalsIgnoreCase(name)) {
- ret = fplayer;
- break;
+ public void execute(CommandContext context) {
+ // Is there a matching sub command?
+ if (context.args.size() > 0) {
+ for (FCommand subCommand : this.subCommands) {
+ if (subCommand.aliases.contains(context.args.get(0).toLowerCase())) {
+ context.args.remove(0);
+ context.commandChain.add(this);
+ subCommand.execute(context);
+ return;
}
}
}
- if (msg && ret == null) {
- this.msg("No player \"%s\" could be found.", name);
+ if (!validCall(context)) {
+ return;
}
- return ret;
- }
-
- public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) {
- return this.strAsFPlayer(this.argAsString(idx), def, msg);
- }
-
- public FPlayer argAsFPlayer(int idx, FPlayer def) {
- return this.argAsFPlayer(idx, def, true);
- }
-
- public FPlayer argAsFPlayer(int idx) {
- return this.argAsFPlayer(idx, null);
- }
-
- // BEST FPLAYER MATCH ======================
- public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg) {
- return strAsFPlayer(name, def, msg);
- }
-
- public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg) {
- return this.strAsBestFPlayerMatch(this.argAsString(idx), def, msg);
- }
-
- public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) {
- return this.argAsBestFPlayerMatch(idx, def, true);
- }
-
- public FPlayer argAsBestFPlayerMatch(int idx) {
- return this.argAsBestFPlayerMatch(idx, null);
- }
-
- // FACTION ======================
- public Faction strAsFaction(String name, Faction def, boolean msg) {
- Faction ret = def;
-
- if (name != null) {
- // First we try an exact match
- Faction faction = Factions.getInstance().getByTag(name); // Checks for faction name match.
-
- // Now lets try for warzone / safezone. Helpful for custom warzone / safezone names.
- // Do this after we check for an exact match in case they rename the warzone / safezone
- // and a player created faction took one of the names.
- if (faction == null) {
- if (name.equalsIgnoreCase("warzone")) {
- faction = Factions.getInstance().getWarZone();
- } else if (name.equalsIgnoreCase("safezone")) {
- faction = Factions.getInstance().getSafeZone();
- }
- }
-
- // Next we match faction tags
- if (faction == null) {
- faction = Factions.getInstance().getBestTagMatch(name);
- }
-
- // Next we match player names
- if (faction == null) {
- FPlayer fplayer = strAsFPlayer(name, null, false);
- if (fplayer != null) {
- faction = fplayer.getFaction();
- }
- }
-
- if (faction != null) {
- ret = faction;
- }
+ if (!this.isEnabled(context)) {
+ return;
}
- if (msg && ret == null) {
- this.msg("The faction or player \"%s\" could not be found.", name);
+ perform(context);
+ }
+
+ public boolean validCall(CommandContext context) {
+ return requirements.computeRequirements(context, true) && validArgs(context);
+ }
+
+ public boolean isEnabled(CommandContext context) {
+ if (FactionsPlugin.getInstance().getLocked() && requirements.disableOnLock) {
+ context.msg("Factions was locked by an admin. Please try again later.");
+ return false;
}
-
- return ret;
+ return true;
}
- public Faction argAsFaction(int idx, Faction def, boolean msg) {
- return this.strAsFaction(this.argAsString(idx), def, msg);
- }
-
- public Faction argAsFaction(int idx, Faction def) {
- return this.argAsFaction(idx, def, true);
- }
-
- public Faction argAsFaction(int idx) {
- return this.argAsFaction(idx, null);
- }
-
- // -------------------------------------------- //
- // Commonly used logic
- // -------------------------------------------- //
-
- public boolean canIAdministerYou(FPlayer i, FPlayer you) {
- if (!i.getFaction().equals(you.getFaction())) {
- i.sendMessage(p.txt.parse("%s is not in the same faction as you.", you.describeTo(i, true)));
+ public boolean validArgs(CommandContext context) {
+ if (context.args.size() < this.requiredArgs.size()) {
+ if (context.sender != null) {
+ context.msg(TL.GENERIC_ARGS_TOOFEW);
+ context.sender.sendMessage(this.getUseageTemplate(context));
+ }
return false;
}
- if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.LEADER)) {
- return true;
+ if (context.args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.requirements.errorOnManyArgs) {
+ if (context.sender != null) {
+ // Get the to many string slice
+ List theToMany = context.args.subList(this.requiredArgs.size() + this.optionalArgs.size(), context.args.size());
+ context.msg(TL.GENERIC_ARGS_TOOMANY, TextUtil.implode(theToMany, " "));
+ context.sender.sendMessage(this.getUseageTemplate(context));
+ }
+ return false;
+ }
+ return true;
+ }
+
+ public void addSubCommand(FCommand subCommand) {
+ this.subCommands.add(subCommand);
+ }
+
+ public String getHelpShort() {
+ if (this.helpShort == null) {
+ return getUsageTranslation().toString();
}
- if (you.getRole().equals(Role.LEADER)) {
- i.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "leader").replace("{action}", "do that")));
+ return this.helpShort;
+ }
- } else if ((you.getRole().equals(Role.COLEADER))) {
- if (i == you) {
- return true;
+ public void setHelpShort(String val) {
+ this.helpShort = val;
+ }
+
+ public abstract TL getUsageTranslation();
+
+
+ /*
+ Common Logic
+ */
+ public List getToolTips(FPlayer player) {
+ List lines = new ArrayList<>();
+ for (String s : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.show")) {
+ lines.add(ChatColor.translateAlternateColorCodes('&', replaceFPlayerTags(s, player)));
+ }
+ return lines;
+ }
+
+ public List getToolTips(Faction faction) {
+ List lines = new ArrayList<>();
+ for (String s : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.list")) {
+ lines.add(ChatColor.translateAlternateColorCodes('&', replaceFactionTags(s, faction)));
+ }
+ return lines;
+ }
+
+ public String replaceFPlayerTags(String s, FPlayer player) {
+ if (s.contains("{balance}")) {
+ String balance = Econ.isSetup() ? Econ.getFriendlyBalance(player) : "no balance";
+ s = s.replace("{balance}", balance);
+ }
+ if (s.contains("{lastSeen}")) {
+ String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - player.getLastLoginTime(), true, true) + " ago";
+ String lastSeen = player.isOnline() ? ChatColor.GREEN + "Online" : (System.currentTimeMillis() - player.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
+ s = s.replace("{lastSeen}", lastSeen);
+ }
+ if (s.contains("{power}")) {
+ String power = player.getPowerRounded() + "/" + player.getPowerMaxRounded();
+ s = s.replace("{power}", power);
+ }
+ if (s.contains("{group}")) {
+ String group = FactionsPlugin.getInstance().getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(player.getId())));
+ s = s.replace("{group}", group);
+ }
+ return s;
+ }
+
+ public String replaceFactionTags(String s, Faction faction) {
+ if (s.contains("{power}")) {
+ s = s.replace("{power}", String.valueOf(faction.getPowerRounded()));
+ }
+ if (s.contains("{maxPower}")) {
+ s = s.replace("{maxPower}", String.valueOf(faction.getPowerMaxRounded()));
+ }
+ if (s.contains("{leader}")) {
+ FPlayer fLeader = faction.getFPlayerAdmin();
+ String leader = fLeader == null ? "Server" : fLeader.getName().substring(0, fLeader.getName().length() > 14 ? 13 : fLeader.getName().length());
+ s = s.replace("{leader}", leader);
+ }
+ if (s.contains("{chunks}")) {
+ s = s.replace("{chunks}", String.valueOf(faction.getLandRounded()));
+ }
+ if (s.contains("{members}")) {
+ s = s.replace("{members}", String.valueOf(faction.getSize()));
+
+ }
+ if (s.contains("{online}")) {
+ s = s.replace("{online}", String.valueOf(faction.getOnlinePlayers().size()));
+ }
+ return s;
+ }
+
+ /*
+ Help and Usage information
+ */
+ public String getUseageTemplate(CommandContext context, boolean addShortHelp) {
+ StringBuilder ret = new StringBuilder();
+ ret.append(FactionsPlugin.getInstance().color(TL.COMMAND_USEAGE_TEMPLATE_COLOR.toString()));
+ ret.append('/');
+
+ for (FCommand fc : context.commandChain) {
+ ret.append(TextUtil.implode(fc.aliases, ","));
+ ret.append(' ');
+ }
+
+ ret.append(TextUtil.implode(this.aliases, ","));
+
+ List args = new ArrayList<>();
+
+ for (String requiredArg : this.requiredArgs) {
+ args.add("<" + requiredArg + ">");
+ }
+
+ for (Map.Entry optionalArg : this.optionalArgs.entrySet()) {
+ String val = optionalArg.getValue();
+ if (val == null) {
+ val = "";
} else {
- i.sendMessage(p.txt.parse(TL.ACTIONS_NOSAMEROLE.toString().replace("{role}", i.getRole().nicename)));
+ val = "=" + val;
}
-
- } else if (i.getRole().equals(Role.MODERATOR)) {
- if (i == you) {
- return true; //Moderators can control themselves
- } else {
- i.sendMessage(p.txt.parse(TL.ACTIONS_NOSAMEROLE.toString().replace("{role}", i.getRole().nicename)));
- }
- } else {
- i.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "moderator").replace("{action}", "do that")));
+ args.add("[" + optionalArg.getKey() + val + "]");
}
- return false;
- }
-
- // 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.isAdminBypassing()) {
- return true;
+ if (args.size() > 0) {
+ ret.append(FactionsPlugin.getInstance().txt.parseTags(" "));
+ ret.append(TextUtil.implode(args, " "));
}
- if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
- return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
- } else {
- return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis);
- }
- }
-
- public boolean payForCommand(double cost, TL toDoThis, TL forDoingThis) {
- return payForCommand(cost, toDoThis.toString(), forDoingThis.toString());
- }
-
- // 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.isAdminBypassing()) {
- return true;
+ if (addShortHelp) {
+ ret.append(FactionsPlugin.getInstance().txt.parseTags(" "));
+ ret.append(this.getHelpShort());
}
- if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
- return Econ.hasAtLeast(myFaction, cost, toDoThis);
- } else {
- return Econ.hasAtLeast(fme, cost, toDoThis);
- }
+ return ret.toString();
}
- public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
- this.doWarmUp(this.fme, warmup, translationKey, action, runnable, delay);
+ public String getUseageTemplate(CommandContext context) {
+ return getUseageTemplate(context, false);
}
- public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
- WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay);
- }
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAlts.java b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAlts.java
index 537560b7..1a2232b2 100644
--- a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAlts.java
+++ b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAlts.java
@@ -1,6 +1,8 @@
package com.massivecraft.factions.cmd.alts;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -18,29 +20,24 @@ public class CmdAlts extends FCommand {
this.aliases.add("alts");
this.aliases.add("alt");
- this.permission = Permission.ALTS.node;
- this.disableOnLock = false;
- this.disableOnSpam = false;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
-
-
this.addSubCommand(this.cmdInviteAlt);
this.addSubCommand(this.cmdAltsList);
+
+ this.requirements = new CommandRequirements.Builder(Permission.ALTS)
+ .playerOnly()
+ .memberOnly()
+ .build();
}
@Override
- public void perform() {
- if (!P.p.getConfig().getBoolean("f-alts.Enabled", false)) {
- fme.msg(TL.GENERIC_DISABLED);
+ public void perform(CommandContext context) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled", false)) {
+ context.msg(TL.GENERIC_DISABLED);
return;
}
- this.commandChain.add(this);
- P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain);
+ context.commandChain.add(this);
+ FactionsPlugin.getInstance().cmdAutoHelp.execute(context);
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java
index a6d1a061..57151ebd 100644
--- a/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java
+++ b/src/main/java/com/massivecraft/factions/cmd/alts/CmdAltsList.java
@@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.alts;
import com.google.common.base.Joiner;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -19,37 +21,33 @@ public class CmdAltsList extends FCommand {
this.optionalArgs.put("faction", "yours");
- this.permission = Permission.LIST.node;
- this.disableOnLock = false;
- this.disableOnSpam = false;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.LIST)
+ .playerOnly()
+ .memberOnly()
+ .build();
}
@Override
- public void perform() {
- Faction faction = myFaction;
- if (argIsSet(0)) {
- faction = argAsFaction(0);
+ public void perform(CommandContext context) {
+ Faction faction = context.faction;
+ if (context.argIsSet(0)) {
+ faction = context.argAsFaction(0);
}
if (faction == null)
return;
- if (faction != myFaction && !fme.isAdminBypassing()) {
+ if (faction != context.faction && !context.fPlayer.isAdminBypassing()) {
return;
}
if (faction.getAltPlayers().size() == 0) {
- msg(TL.COMMAND_ALTS_LIST_NOALTS, faction.getTag());
+ context.msg(TL.COMMAND_ALTS_LIST_NOALTS, faction.getTag());
return;
}
- msg("There are " + faction.getAltPlayers().size() + " alts in " + faction.getTag() + ":");
- msg(Joiner.on(", ").join(faction.getAltPlayers().stream().map(FPlayer::getName).collect(Collectors.toList())));
+ context.msg("There are " + faction.getAltPlayers().size() + " alts in " + faction.getTag() + ":");
+ context.msg(Joiner.on(", ").join(faction.getAltPlayers().stream().map(FPlayer::getName).collect(Collectors.toList())));
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/alts/CmdInviteAlt.java b/src/main/java/com/massivecraft/factions/cmd/alts/CmdInviteAlt.java
index ff8e9492..8bd44283 100644
--- a/src/main/java/com/massivecraft/factions/cmd/alts/CmdInviteAlt.java
+++ b/src/main/java/com/massivecraft/factions/cmd/alts/CmdInviteAlt.java
@@ -2,7 +2,9 @@ package com.massivecraft.factions.cmd.alts;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
@@ -17,75 +19,69 @@ public class CmdInviteAlt extends FCommand {
public CmdInviteAlt() {
super();
this.aliases.add("invite");
-
this.requiredArgs.add("player name");
- // this.optionalArgs.put("", "");
- this.permission = Permission.INVITE.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.INVITE)
+ .playerOnly()
+ .memberOnly()
+ .build();
}
@Override
- public void perform() {
- if (!P.p.getConfig().getBoolean("f-alts.Enabled", false)) {
- fme.msg(TL.GENERIC_DISABLED);
+ public void perform(CommandContext context) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled", false)) {
+ context.fPlayer.msg(TL.GENERIC_DISABLED);
return;
}
- FPlayer target = this.argAsBestFPlayerMatch(0);
+ FPlayer target = context.argAsBestFPlayerMatch(0);
if (target == null) {
return;
}
- if (target.getFaction() == myFaction) {
- msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), myFaction.getTag());
+ if (target.getFaction() == context.faction) {
+ context.msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), context.faction.getTag());
return;
}
// if economy is enabled, they're not on the bypass list, and this
// command has a cost set, make 'em pay
- if (!payForCommand(Conf.econCostInvite, TL.COMMAND_INVITE_TOINVITE.toString(), TL.COMMAND_INVITE_FORINVITE.toString())) {
+ if (!context.payForCommand(Conf.econCostInvite, TL.COMMAND_INVITE_TOINVITE.toString(), TL.COMMAND_INVITE_FORINVITE.toString())) {
return;
}
- if (!fme.isAdminBypassing()) {
- Access access = myFaction.getAccess(fme, PermissableAction.INVITE);
- if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
- fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
+ if (!context.fPlayer.isAdminBypassing()) {
+ Access access = context.faction.getAccess(context.fPlayer, PermissableAction.INVITE);
+ if (access != Access.ALLOW && context.fPlayer.getRole() != Role.LEADER) {
+ context.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
return;
}
}
- if (myFaction.isBanned(target)) {
- fme.msg(TL.COMMAND_INVITE_BANNED, target.getName());
+ if (context.faction.isBanned(target)) {
+ context.msg(TL.COMMAND_INVITE_BANNED, target.getName());
return;
}
- myFaction.deinvite(target);
- myFaction.altInvite(target);
+ context.faction.deinvite(target);
+ context.faction.altInvite(target);
if (!target.isOnline()) {
return;
}
- FancyMessage message = new FancyMessage(fme.describeTo(target, true))
+ FancyMessage message = new FancyMessage(context.fPlayer.describeTo(target, true))
.tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
- .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag())
+ .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag())
.then(TL.COMMAND_INVITE_INVITEDYOU.toString())
.color(ChatColor.YELLOW)
.tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
- .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag())
- .then(myFaction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
- .command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag());
+ .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag())
+ .then(context.faction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
+ .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag());
message.send(target.getPlayer());
- myFaction.msg(TL.COMMAND_ALTINVITE_INVITED_ALT, fme.describeTo(myFaction, true), target.describeTo(myFaction));
+ context.faction.msg(TL.COMMAND_ALTINVITE_INVITED_ALT, context.fPlayer.describeTo(context.faction, true), target.describeTo(context.faction));
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java b/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java
index 25a96b58..5a883892 100644
--- a/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java
+++ b/src/main/java/com/massivecraft/factions/cmd/check/CheckHistoryFrame.java
@@ -3,7 +3,7 @@ package com.massivecraft.factions.cmd.check;
import com.google.common.collect.Lists;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.FactionGUI;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
@@ -18,12 +18,12 @@ import java.text.SimpleDateFormat;
import java.util.*;
public class CheckHistoryFrame implements FactionGUI {
- private P plugin;
+ private FactionsPlugin plugin;
private Faction faction;
private Inventory inventory;
private SimpleDateFormat simpleDateFormat;
- public CheckHistoryFrame(P plugin, Faction faction) {
+ public CheckHistoryFrame(FactionsPlugin plugin, Faction faction) {
this.simpleDateFormat = new SimpleDateFormat(Conf.dateFormat);
this.plugin = plugin;
this.faction = faction;
diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java b/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java
index 2e198fff..858d9244 100644
--- a/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java
+++ b/src/main/java/com/massivecraft/factions/cmd/check/CheckSettingsFrame.java
@@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd.check;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.FactionGUI;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
@@ -16,11 +16,11 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.Collections;
public class CheckSettingsFrame implements InventoryHolder, FactionGUI {
- private P plugin;
+ private FactionsPlugin plugin;
private FPlayer fPlayer;
private Inventory inventory;
- public CheckSettingsFrame(P plugin, FPlayer fPlayer) {
+ public CheckSettingsFrame(FactionsPlugin plugin, FPlayer fPlayer) {
this.plugin = plugin;
this.fPlayer = fPlayer;
this.inventory = plugin.getServer().createInventory(this, plugin.getConfig().getInt("f-check.gui-rows") * 9, TL.CHECK_SETTINGS_GUI_TITLE.toString());
@@ -28,16 +28,16 @@ public class CheckSettingsFrame implements InventoryHolder, FactionGUI {
public void onClick(int slot, ClickType action) {
Faction faction = this.fPlayer.getFaction();
- if (slot == P.p.getConfig().getInt("f-check.wall-check.slot")) {
+ if (slot == FactionsPlugin.getInstance().getConfig().getInt("f-check.wall-check.slot")) {
faction.setWallCheckMinutes(getNext(faction.getWallCheckMinutes()));
} else {
- if (slot == P.p.getConfig().getInt("f-check.history.slot")) {
+ if (slot == FactionsPlugin.getInstance().getConfig().getInt("f-check.history.slot")) {
CheckHistoryFrame checkHistoryFrame = new CheckHistoryFrame(plugin, fPlayer.getFaction());
checkHistoryFrame.build();
fPlayer.getPlayer().openInventory(checkHistoryFrame.getInventory());
return;
}
- if (slot == P.p.getConfig().getInt("f-check.buffer-check.slot")) {
+ if (slot == FactionsPlugin.getInstance().getConfig().getInt("f-check.buffer-check.slot")) {
faction.setBufferCheckMinutes(getNext(faction.getBufferCheckMinutes()));
}
}
@@ -47,23 +47,23 @@ public class CheckSettingsFrame implements InventoryHolder, FactionGUI {
public void build() {
Faction faction = fPlayer.getFaction();
- ItemStack wallsStack = XMaterial.matchXMaterial(P.p.getConfig().getString("f-check.wall-check.Type")).parseItem();
+ ItemStack wallsStack = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("f-check.wall-check.Type")).parseItem();
ItemMeta wallsMeta = wallsStack.getItemMeta();
wallsMeta.setDisplayName(TL.CHECK_WALL_CHECK_GUI_ICON.toString());
wallsMeta.setLore(Collections.singletonList(TL.CHECK_CHECK_LORE_LINE.format(getFormatted(faction.getWallCheckMinutes()))));
wallsStack.setItemMeta(wallsMeta);
- inventory.setItem(P.p.getConfig().getInt("f-check.wall-check.slot"), wallsStack);
- ItemStack bufferStack = XMaterial.matchXMaterial(P.p.getConfig().getString("f-check.buffer-check.Type")).parseItem();
+ inventory.setItem(FactionsPlugin.getInstance().getConfig().getInt("f-check.wall-check.slot"), wallsStack);
+ ItemStack bufferStack = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("f-check.buffer-check.Type")).parseItem();
ItemMeta bufferMeta = bufferStack.getItemMeta();
bufferMeta.setDisplayName(TL.CHECK_BUFFER_CHECK_GUI_ICON.toString());
bufferMeta.setLore(Collections.singletonList(TL.CHECK_CHECK_LORE_LINE.format(getFormatted(faction.getBufferCheckMinutes()))));
bufferStack.setItemMeta(bufferMeta);
- inventory.setItem(P.p.getConfig().getInt("f-check.buffer-check.slot"), bufferStack);
- ItemStack historyStack = XMaterial.matchXMaterial(P.p.getConfig().getString("f-check.history.Type")).parseItem();
+ inventory.setItem(FactionsPlugin.getInstance().getConfig().getInt("f-check.buffer-check.slot"), bufferStack);
+ ItemStack historyStack = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("f-check.history.Type")).parseItem();
ItemMeta historyMeta = historyStack.getItemMeta();
historyMeta.setDisplayName(TL.CHECK_HISTORY_GUI_ICON.toString());
historyStack.setItemMeta(historyMeta);
- inventory.setItem(P.p.getConfig().getInt("f-check.history.slot"), historyStack);
+ inventory.setItem(FactionsPlugin.getInstance().getConfig().getInt("f-check.history.slot"), historyStack);
}
public Inventory getInventory() {
diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CheckTask.java b/src/main/java/com/massivecraft/factions/cmd/check/CheckTask.java
index bcbac60e..7d5a895c 100644
--- a/src/main/java/com/massivecraft/factions/cmd/check/CheckTask.java
+++ b/src/main/java/com/massivecraft/factions/cmd/check/CheckTask.java
@@ -4,7 +4,7 @@ import com.google.common.collect.Lists;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import java.text.SimpleDateFormat;
@@ -16,10 +16,10 @@ public class CheckTask implements Runnable {
private static List wallChecks = new CopyOnWriteArrayList<>();
private static List bufferChecks = new CopyOnWriteArrayList<>();
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Conf.dateFormat);
- private P plugin;
+ private FactionsPlugin plugin;
private int minute;
- public CheckTask(P plugin, int minute) {
+ public CheckTask(FactionsPlugin plugin, int minute) {
this.plugin = plugin;
this.minute = minute;
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CmdCheck.java b/src/main/java/com/massivecraft/factions/cmd/check/CmdCheck.java
index e42caa72..36e7bd8a 100644
--- a/src/main/java/com/massivecraft/factions/cmd/check/CmdCheck.java
+++ b/src/main/java/com/massivecraft/factions/cmd/check/CmdCheck.java
@@ -1,9 +1,12 @@
package com.massivecraft.factions.cmd.check;
import com.massivecraft.factions.Conf;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
+import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
-import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.OfflinePlayer;
@@ -20,34 +23,28 @@ public class CmdCheck extends FCommand {
this.aliases.add("check");
this.requiredArgs.add("walls/buffers/settings/leaderboard");
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.CHECK)
+ .playerOnly()
+ .withAction(PermissableAction.CHECK)
+ .memberOnly()
+ .build();
}
- public void perform() {
- if (myFaction == null || !myFaction.isNormal()) {
- return;
- }
- String subCommand = argAsString(0, null);
- Access access = myFaction.getAccess(fme, PermissableAction.CHECK);
- if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
- fme.msg(TL.GENERIC_NOPERMISSION, "check");
+ public void perform(CommandContext context) {
+ if (context.faction == null || !context.faction.isNormal()) {
return;
}
+ String subCommand = context.argAsString(0, null);
+
long currentTime = System.currentTimeMillis();
if (subCommand.equalsIgnoreCase("leaderboard")) {
- msg(TL.CHECK_LEADERBOARD_HEADER);
+ context.msg(TL.CHECK_LEADERBOARD_HEADER);
Map players = new HashMap<>();
- for (Map.Entry entry : myFaction.getPlayerWallCheckCount().entrySet()) {
+ for (Map.Entry entry : context.faction.getPlayerWallCheckCount().entrySet()) {
players.put(entry.getKey(), entry.getValue());
}
- for (Map.Entry entry : myFaction.getPlayerBufferCheckCount().entrySet()) {
+ for (Map.Entry entry : context.faction.getPlayerBufferCheckCount().entrySet()) {
if (players.containsKey(entry.getKey())) {
players.replace(entry.getKey(), players.get(entry.getKey()) + entry.getValue());
} else {
@@ -57,54 +54,54 @@ public class CmdCheck extends FCommand {
List> entryList = players.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());
for (int max = (entryList.size() > 10) ? 10 : entryList.size(), current = 0; current < max; ++current) {
Map.Entry entry = entryList.get(current);
- OfflinePlayer offlinePlayer = p.getServer().getOfflinePlayer(entry.getKey());
- msg(TL.CHECK_LEADERBOARD_LINE.format(current + 1, offlinePlayer.getName(), entry.getValue(), myFaction.getPlayerBufferCheckCount().getOrDefault(entry.getKey(), 0), myFaction.getPlayerWallCheckCount().getOrDefault(entry.getKey(), 0)));
+ OfflinePlayer offlinePlayer = FactionsPlugin.getInstance().getServer().getOfflinePlayer(entry.getKey());
+ context.msg(TL.CHECK_LEADERBOARD_LINE.format(current + 1, offlinePlayer.getName(), entry.getValue(), context.faction.getPlayerBufferCheckCount().getOrDefault(entry.getKey(), 0), context.faction.getPlayerWallCheckCount().getOrDefault(entry.getKey(), 0)));
}
if (entryList.isEmpty()) {
- msg(TL.CHECK_LEADERBOARD_NO_DATA);
+ context.msg(TL.CHECK_LEADERBOARD_NO_DATA);
}
} else if (subCommand.equalsIgnoreCase("walls")) {
- if (!CheckTask.wallCheck(myFaction.getId())) {
- if (myFaction.getChecks().isEmpty()) {
- msg(TL.CHECK_NO_CHECKS);
+ if (!CheckTask.wallCheck(context.faction.getId())) {
+ if (context.faction.getChecks().isEmpty()) {
+ context.msg(TL.CHECK_NO_CHECKS);
return;
}
- msg(TL.CHECK_ALREADY_CHECKED);
+ context.msg(TL.CHECK_ALREADY_CHECKED);
} else {
- int current = myFaction.getPlayerWallCheckCount().getOrDefault(me.getUniqueId(), 0);
+ int current = context.faction.getPlayerWallCheckCount().getOrDefault(context.player.getUniqueId(), 0);
if (current == 0) {
- myFaction.getPlayerWallCheckCount().put(me.getUniqueId(), 1);
+ context.faction.getPlayerWallCheckCount().put(context.player.getUniqueId(), 1);
} else {
- myFaction.getPlayerWallCheckCount().replace(me.getUniqueId(), current + 1);
+ context.faction.getPlayerWallCheckCount().replace(context.player.getUniqueId(), current + 1);
}
- myFaction.getChecks().put(currentTime, "U" + fme.getNameAndTag());
- msg(TL.CHECK_WALLS_MARKED_CHECKED);
+ context.faction.getChecks().put(currentTime, "U" + context.fPlayer.getNameAndTag());
+ context.msg(TL.CHECK_WALLS_MARKED_CHECKED);
}
} else if (subCommand.equalsIgnoreCase("buffers")) {
- if (!CheckTask.bufferCheck(myFaction.getId())) {
- if (myFaction.getChecks().isEmpty()) {
- msg(TL.CHECK_NO_CHECKS);
+ if (!CheckTask.bufferCheck(context.faction.getId())) {
+ if (context.faction.getChecks().isEmpty()) {
+ context.msg(TL.CHECK_NO_CHECKS);
return;
}
- msg(TL.CHECK_ALREADY_CHECKED);
+ context.msg(TL.CHECK_ALREADY_CHECKED);
} else {
- int current = myFaction.getPlayerBufferCheckCount().getOrDefault(me.getUniqueId(), 0);
+ int current = context.faction.getPlayerBufferCheckCount().getOrDefault(context.player.getUniqueId(), 0);
if (current == 0) {
- myFaction.getPlayerBufferCheckCount().put(me.getUniqueId(), 1);
+ context.faction.getPlayerBufferCheckCount().put(context.player.getUniqueId(), 1);
} else {
- myFaction.getPlayerBufferCheckCount().replace(me.getUniqueId(), current + 1);
+ context.faction.getPlayerBufferCheckCount().replace(context.player.getUniqueId(), current + 1);
}
- myFaction.getChecks().put(System.currentTimeMillis(), "Y" + fme.getNameAndTag());
- msg(TL.CHECK_BUFFERS_MARKED_CHECKED);
+ context.faction.getChecks().put(System.currentTimeMillis(), "Y" + context.fPlayer.getNameAndTag());
+ context.msg(TL.CHECK_BUFFERS_MARKED_CHECKED);
}
} else if (subCommand.equalsIgnoreCase("settings")) {
- if (!fme.getRole().isAtLeast(Role.COLEADER)) {
- msg(TL.CHECK_MUST_BE_ATLEAST_COLEADER);
+ if (!context.fPlayer.getRole().isAtLeast(Role.COLEADER)) {
+ context.msg(TL.CHECK_MUST_BE_ATLEAST_COLEADER);
return;
}
- CheckSettingsFrame checkGUI = new CheckSettingsFrame(p, fme);
+ CheckSettingsFrame checkGUI = new CheckSettingsFrame(FactionsPlugin.getInstance(), context.fPlayer);
checkGUI.build();
- fme.getPlayer().openInventory(checkGUI.getInventory());
+ context.fPlayer.getPlayer().openInventory(checkGUI.getInventory());
}
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/check/CmdWeeWoo.java b/src/main/java/com/massivecraft/factions/cmd/check/CmdWeeWoo.java
index 20695df1..f52c6c2a 100644
--- a/src/main/java/com/massivecraft/factions/cmd/check/CmdWeeWoo.java
+++ b/src/main/java/com/massivecraft/factions/cmd/check/CmdWeeWoo.java
@@ -1,6 +1,9 @@
package com.massivecraft.factions.cmd.check;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
+import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdWeeWoo extends FCommand {
@@ -8,38 +11,35 @@ public class CmdWeeWoo extends FCommand {
this.aliases.add("weewoo");
this.requiredArgs.add("start/stop");
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.CHECK)
+ .playerOnly()
+ .memberOnly()
+ .build();
}
- public void perform() {
- if (myFaction == null || !myFaction.isNormal()) {
+ public void perform(CommandContext context) {
+ if (context.faction == null || !context.faction.isNormal()) {
return;
}
- String argument = argAsString(0);
- boolean weewoo = myFaction.isWeeWoo();
+ String argument = context.argAsString(0);
+ boolean weewoo = context.faction.isWeeWoo();
if (argument.equalsIgnoreCase("start")) {
if (weewoo) {
- msg(TL.COMMAND_WEEWOO_ALREADY_STARTED);
+ context.msg(TL.COMMAND_WEEWOO_ALREADY_STARTED);
return;
}
- myFaction.setWeeWoo(true);
- msg(TL.COMMAND_WEEWOO_STARTED, fme.getNameAndTag());
+ context.faction.setWeeWoo(true);
+ context.msg(TL.COMMAND_WEEWOO_STARTED, context.fPlayer.getNameAndTag());
} else if (argument.equalsIgnoreCase("stop")) {
if (!weewoo) {
- msg(TL.COMMAND_WEEWOO_ALREADY_STOPPED);
+ context.msg(TL.COMMAND_WEEWOO_ALREADY_STOPPED);
return;
}
- myFaction.setWeeWoo(false);
- msg(TL.COMMAND_WEEWOO_STOPPED, fme.getNameAndTag());
+ context.faction.setWeeWoo(false);
+ context.msg(TL.COMMAND_WEEWOO_STOPPED, context.fPlayer.getNameAndTag());
} else {
- msg("/f weewoo ");
+ context.msg("/f weewoo ");
}
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java b/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java
index 68a12c95..ffce2553 100644
--- a/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java
+++ b/src/main/java/com/massivecraft/factions/cmd/check/WeeWooTask.java
@@ -2,14 +2,14 @@ package com.massivecraft.factions.cmd.check;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
public class WeeWooTask implements Runnable {
- private P plugin;
+ private FactionsPlugin plugin;
- public WeeWooTask(P plugin) {
+ public WeeWooTask(FactionsPlugin plugin) {
this.plugin = plugin;
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/chest/CmdChest.java b/src/main/java/com/massivecraft/factions/cmd/chest/CmdChest.java
index b952a326..5c970910 100644
--- a/src/main/java/com/massivecraft/factions/cmd/chest/CmdChest.java
+++ b/src/main/java/com/massivecraft/factions/cmd/chest/CmdChest.java
@@ -1,10 +1,10 @@
package com.massivecraft.factions.cmd.chest;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
-import com.massivecraft.factions.struct.Role;
-import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
@@ -14,36 +14,23 @@ public class CmdChest extends FCommand {
this.aliases.add("chest");
this.aliases.add("pv");
- //this.requiredArgs.add("");
-
-
- this.permission = Permission.CHEST.node;
- this.disableOnLock = false;
-
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.CHEST)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.CHEST)
+ .build();
}
@Override
- public void perform() {
+ public void perform(CommandContext context) {
- if (!P.p.getConfig().getBoolean("fchest.Enabled")) {
- fme.sendMessage("This command is disabled!");
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("fchest.Enabled")) {
+ context.fPlayer.sendMessage("This command is disabled!");
return;
}
// This permission check is way too explicit but it's clean
- if (!fme.isAdminBypassing()) {
- Access access = myFaction.getAccess(fme, PermissableAction.CHEST);
- if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
- fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "access chest");
- return;
- }
- }
- me.openInventory(fme.getFaction().getChestInventory());
+ context.player.openInventory(context.faction.getChestInventory());
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java
index fb9296ee..74ecd1d8 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdAutoClaim.java
@@ -1,9 +1,13 @@
package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
+import com.massivecraft.factions.zcore.fperms.Access;
+import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
public class CmdAutoClaim extends FCommand {
@@ -15,39 +19,45 @@ public class CmdAutoClaim extends FCommand {
//this.requiredArgs.add("");
this.optionalArgs.put("faction", "your");
- this.permission = Permission.AUTOCLAIM.node;
- this.disableOnLock = true;
- this.disableOnSpam = false;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.AUTOCLAIM)
+ .playerOnly()
+ .withAction(PermissableAction.TERRITORY)
+ .build();
}
@Override
- public void perform() {
- Faction forFaction = this.argAsFaction(0, myFaction);
- if (forFaction == null || forFaction == fme.getAutoClaimFor()) {
- fme.setAutoClaimFor(null);
- msg(TL.COMMAND_AUTOCLAIM_DISABLED);
+ public void perform(CommandContext context) {
+ Faction forFaction = context.argAsFaction(0, context.faction);
+
+ if (forFaction != context.fPlayer.getFaction()) {
+ if (!context.fPlayer.isAdminBypassing()) {
+ if (forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) {
+ context.msg(TL.COMMAND_CLAIM_DENIED);
+ return;
+ }
+ }
+ }
+
+ if (forFaction == null || forFaction == context.fPlayer.getAutoClaimFor()) {
+ context.fPlayer.setAutoClaimFor(null);
+ context.msg(TL.COMMAND_AUTOCLAIM_DISABLED);
return;
}
- if (!fme.canClaimForFaction(forFaction)) {
- if (myFaction == forFaction) {
- msg(TL.COMMAND_AUTOCLAIM_REQUIREDRANK, Role.MODERATOR.getTranslation());
+ if (!context.fPlayer.canClaimForFaction(forFaction)) {
+ if (context.faction == forFaction) {
+ context.msg(TL.COMMAND_AUTOCLAIM_REQUIREDRANK, Role.MODERATOR.getTranslation());
} else {
- msg(TL.COMMAND_AUTOCLAIM_OTHERFACTION, forFaction.describeTo(fme));
+ context.msg(TL.COMMAND_AUTOCLAIM_OTHERFACTION, forFaction.describeTo(context.fPlayer));
}
return;
}
- fme.setAutoClaimFor(forFaction);
+ context.fPlayer.setAutoClaimFor(forFaction);
- msg(TL.COMMAND_AUTOCLAIM_ENABLED, forFaction.describeTo(fme));
- fme.attemptClaim(forFaction, me.getLocation(), true);
+ context.msg(TL.COMMAND_AUTOCLAIM_ENABLED, forFaction.describeTo(context.fPlayer));
+ context.fPlayer.attemptClaim(forFaction, context.fPlayer.getPlayer().getLocation(), true);
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java
index 0bb79b65..26cc7b04 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaim.java
@@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
@@ -22,59 +24,56 @@ public class CmdClaim extends FCommand {
this.optionalArgs.put("radius", "1");
this.optionalArgs.put("faction", "your");
- this.permission = Permission.CLAIM.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.CLAIM)
+ .playerOnly()
+ .build();
}
@Override
- public void perform() {
- // Read and validate input
- int radius = this.argAsInt(0, 1); // Default to 1
- final Faction forFaction = this.argAsFaction(1, myFaction); // Default to own
+ public void perform(CommandContext context) {
- if (!fme.isAdminBypassing()) {
- Access access = myFaction.getAccess(fme, PermissableAction.TERRITORY);
- if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
- fme.msg(TL.GENERIC_NOPERMISSION, "change faction territory");
- return;
+ // Read and validate input
+ int radius = context.argAsInt(0, 1); // Default to 1
+ final Faction forFaction = context.argAsFaction(1, context.faction); // Default to own
+
+ if (!context.fPlayer.isAdminBypassing()) {
+ if (!(context.fPlayer.getFaction().equals(forFaction) && context.fPlayer.getRole() == Role.LEADER)) {
+ if (forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) {
+ context.msg(TL.COMMAND_CLAIM_DENIED);
+ return;
+ }
}
}
if (radius < 1) {
- msg(TL.COMMAND_CLAIM_INVALIDRADIUS);
+ context.msg(TL.COMMAND_CLAIM_INVALIDRADIUS);
return;
}
if (radius < 2) {
// single chunk
- fme.attemptClaim(forFaction, me.getLocation(), true);
+ context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true);
} else {
// radius claim
- if (!Permission.CLAIM_RADIUS.has(sender, false)) {
- msg(TL.COMMAND_CLAIM_DENIED);
+ if (!Permission.CLAIM_RADIUS.has(context.sender, true)) {
return;
}
- new SpiralTask(new FLocation(me), radius) {
+ new SpiralTask(new FLocation(context.player), radius) {
private final int limit = Conf.radiusClaimFailureLimit - 1;
private int failCount = 0;
@Override
public boolean work() {
- boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
+ boolean success = context.fPlayer.attemptClaim(forFaction, this.currentLocation(), true);
if (success) {
failCount = 0;
} else if (failCount++ >= limit) {
this.stop();
return false;
}
+
return true;
}
};
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimAt.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimAt.java
index b489faa5..b3759607 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimAt.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimAt.java
@@ -2,8 +2,11 @@ package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
+import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
public class CmdClaimAt extends FCommand {
@@ -16,28 +19,26 @@ public class CmdClaimAt extends FCommand {
this.requiredArgs.add("x");
this.requiredArgs.add("z");
- this.permission = Permission.CLAIMAT.node;
- this.disableOnLock = true;
-
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.CLAIMAT)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.TERRITORY)
+ .build();
}
@Override
- public void perform() {
- int x = argAsInt(1);
- int z = argAsInt(2);
- FLocation location = new FLocation(argAsString(0), x, z);
- if (!((fme.getPlayer().getLocation().getX() + (x * 16)) > (fme.getPlayer().getLocation().getX() + (Conf.mapWidth * 16))) &&
- !((fme.getPlayer().getLocation().getZ() + (z * 16)) > (fme.getPlayer().getLocation().getZ() + (Conf.mapHeight * 16)))) {
- fme.attemptClaim(myFaction, location, true);
- } else fme.msg(TL.COMMAND_CLAIM_DENIED);
+ public void perform(CommandContext context) {
+ int x = context.argAsInt(1);
+ int z = context.argAsInt(2);
+ FLocation location = new FLocation(context.argAsString(0), x, z);
+ if (!((context.player.getLocation().getX() + (x * 16)) > (context.player.getLocation().getX() + (Conf.mapWidth * 16))) &&
+ !((context.player.getLocation().getZ() + (z * 16)) > (context.player.getLocation().getZ() + (Conf.mapHeight * 16))) &&
+ !context.argAsString(0).equals(context.player.getLocation().getWorld().getName())) {
+ context.fPlayer.attemptClaim(context.faction, location, true);
+ } else context.fPlayer.msg(TL.COMMAND_CLAIM_DENIED);
}
+
@Override
public TL getUsageTranslation() {
return null;
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java
index 32b234a9..6f153d79 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdClaimLine.java
@@ -2,8 +2,12 @@ package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
+import com.massivecraft.factions.zcore.fperms.Access;
+import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
@@ -23,32 +27,28 @@ public class CmdClaimLine extends FCommand {
this.optionalArgs.put("direction", "facing");
this.optionalArgs.put("faction", "you");
- this.permission = Permission.CLAIM_LINE.node;
- this.disableOnLock = true;
-
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.CLAIM_LINE)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.TERRITORY)
+ .build();
}
@Override
- public void perform() {
+ public void perform(CommandContext context) {
// Args
- Integer amount = this.argAsInt(0, 1); // Default to 1
+ Integer amount = context.argAsInt(0, 1); // Default to 1
if (amount > Conf.lineClaimLimit) {
- fme.msg(TL.COMMAND_CLAIMLINE_ABOVEMAX, Conf.lineClaimLimit);
+ context.fPlayer.msg(TL.COMMAND_CLAIMLINE_ABOVEMAX, Conf.lineClaimLimit);
return;
}
- String direction = this.argAsString(1);
+ String direction = context.argAsString(1);
BlockFace blockFace;
if (direction == null) {
- blockFace = axis[Math.round(me.getLocation().getYaw() / 90f) & 0x3];
+ blockFace = axis[Math.round(context.player.getLocation().getYaw() / 90f) & 0x3];
} else if (direction.equalsIgnoreCase("north")) {
blockFace = BlockFace.NORTH;
} else if (direction.equalsIgnoreCase("east")) {
@@ -58,16 +58,26 @@ public class CmdClaimLine extends FCommand {
} else if (direction.equalsIgnoreCase("west")) {
blockFace = BlockFace.WEST;
} else {
- fme.msg(TL.COMMAND_CLAIMLINE_NOTVALID, direction);
+ context.msg(TL.COMMAND_CLAIMLINE_NOTVALID, direction);
return;
}
- final Faction forFaction = this.argAsFaction(2, myFaction);
- Location location = me.getLocation();
+ final Faction forFaction = context.argAsFaction(2, context.faction);
+
+ if (forFaction != context.fPlayer.getFaction()) {
+ if (!context.fPlayer.isAdminBypassing()) {
+ if (forFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) != Access.ALLOW) {
+ context.msg(TL.COMMAND_CLAIM_DENIED);
+ return;
+ }
+ }
+ }
+
+ Location location = context.player.getLocation();
// TODO: make this a task like claiming a radius?
for (int i = 0; i < amount; i++) {
- fme.attemptClaim(forFaction, location, true);
+ context.fPlayer.attemptClaim(forFaction, location, true);
location = location.add(blockFace.getModX() * 16, 0, blockFace.getModZ() * 16);
}
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdCorner.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdCorner.java
index 75ed7754..e1641790 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdCorner.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdCorner.java
@@ -2,9 +2,12 @@ package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.*;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.CornerTask;
+import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import java.util.ArrayList;
@@ -16,29 +19,29 @@ public class CmdCorner extends FCommand {
public CmdCorner() {
this.aliases.add("corner");
- this.permission = Permission.CLAIM_RADIUS.node;
- this.senderMustBePlayer = true;
- this.senderMustBeMember = true;
- this.senderMustBeModerator = false;
- this.senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.CORNER)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.TERRITORY)
+ .build();
}
@Override
- public void perform() {
- FLocation to = new FLocation(me.getLocation());
- if (P.p.getFactionsPlayerListener().getCorners().contains(to)) {
+ public void perform(CommandContext context) {
+ FLocation to = new FLocation(context.player.getLocation());
+ if (FactionsPlugin.getInstance().getFactionsPlayerListener().getCorners().contains(to)) {
Faction cornerAt = Board.getInstance().getFactionAt(to);
- if (cornerAt != null && cornerAt.isNormal() && !cornerAt.equals(fme.getFaction())) {
- msg(TL.COMMAND_CORNER_CANT_CLAIM);
+ if (cornerAt != null && cornerAt.isNormal() && !cornerAt.equals(context.fPlayer.getFaction())) {
+ context.msg(TL.COMMAND_CORNER_CANT_CLAIM);
} else {
- msg(TL.COMMAND_CORNER_ATTEMPTING_CLAIM);
+ context.msg(TL.COMMAND_CORNER_ATTEMPTING_CLAIM);
List surrounding = new ArrayList<>(400);
for (int x = 0; x < Conf.factionBufferSize; ++x) {
for (int z = 0; z < Conf.factionBufferSize; ++z) {
int newX = (int) ((to.getX() > 0L) ? (to.getX() - x) : (to.getX() + x));
int newZ = (int) ((to.getZ() > 0L) ? (to.getZ() - z) : (to.getZ() + z));
- FLocation location = new FLocation(me.getWorld().getName(), newX, newZ);
+ FLocation location = new FLocation(context.player.getWorld().getName(), newX, newZ);
Faction at = Board.getInstance().getFactionAt(location);
if (at == null || !at.isNormal()) {
surrounding.add(location);
@@ -47,13 +50,13 @@ public class CmdCorner extends FCommand {
}
surrounding.sort(Comparator.comparingInt(fLocation -> (int) fLocation.getDistanceTo(to)));
if (surrounding.isEmpty()) {
- msg(TL.COMMAND_CORNER_CANT_CLAIM);
+ context.msg(TL.COMMAND_CORNER_CANT_CLAIM);
} else {
- new CornerTask(fme, surrounding).runTaskTimer(P.p, 1L, 1L);
+ new CornerTask(context.fPlayer, surrounding).runTaskTimer(FactionsPlugin.getInstance(), 1L, 1L);
}
}
} else {
- msg(TL.COMMAND_CORNER_NOT_CORNER);
+ context.msg(TL.COMMAND_CORNER_NOT_CORNER);
}
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdSafeunclaimall.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdSafeunclaimall.java
index d19c2b73..bb210593 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdSafeunclaimall.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdSafeunclaimall.java
@@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Factions;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -15,25 +17,15 @@ public class CmdSafeunclaimall extends FCommand {
public CmdSafeunclaimall() {
this.aliases.add("safeunclaimall");
this.aliases.add("safedeclaimall");
-
- //this.requiredArgs.add("");
this.optionalArgs.put("world", "all");
- this.permission = Permission.MANAGE_SAFE_ZONE.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
-
-
+ this.requirements = new CommandRequirements.Builder(Permission.MANAGE_SAFE_ZONE)
+ .build();
}
@Override
- public void perform() {
- String worldName = argAsString(0);
+ public void perform(CommandContext context) {
+ String worldName = context.argAsString(0);
World world = null;
if (worldName != null) {
@@ -48,10 +40,10 @@ public class CmdSafeunclaimall extends FCommand {
Board.getInstance().unclaimAllInWorld(id, world);
}
- msg(TL.COMMAND_SAFEUNCLAIMALL_UNCLAIMED);
+ context.msg(TL.COMMAND_SAFEUNCLAIMALL_UNCLAIMED);
if (Conf.logLandUnclaims) {
- P.p.log(TL.COMMAND_SAFEUNCLAIMALL_UNCLAIMEDLOG.format(sender.getName()));
+ FactionsPlugin.getInstance().log(TL.COMMAND_SAFEUNCLAIMALL_UNCLAIMEDLOG.format(context.sender.getName()));
}
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaim.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaim.java
index dcf45518..01bb5ad6 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaim.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaim.java
@@ -1,6 +1,8 @@
package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.*;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.event.LandUnclaimEvent;
import com.massivecraft.factions.integration.Econ;
@@ -19,51 +21,54 @@ public class CmdUnclaim extends FCommand {
this.aliases.add("declaim");
this.optionalArgs.put("radius", "1");
+ this.optionalArgs.put("faction", "yours");
- this.permission = Permission.UNCLAIM.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.UNCLAIM)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.TERRITORY)
+ .build();
}
@Override
- public void perform() {
- // Read and validate input
- int radius = this.argAsInt(0, 1); // Default to 1
+ public void perform(CommandContext context) {
- if (!fme.isAdminBypassing()) {
- Access access = myFaction.getAccess(fme, PermissableAction.TERRITORY);
- if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
- fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage faction territory");
+ if (context.args.size() == 2) {
+ Faction target = context.argAsFaction(1);
+ // Dont have to say anything since the argsAsFaction method will tell the player for me.
+ if (target == null) return;
+ context.faction = target;
+ if (context.faction != context.fPlayer.getFaction() && !context.fPlayer.isAdminBypassing()) {
+ context.msg(TL.COMMAND_UNCLAIM_WRONGFACTION);
return;
}
}
+ // Read and validate input
+ int radius = context.argAsInt(0, 1); // Default to 1
+
if (radius < 1) {
- msg(TL.COMMAND_CLAIM_INVALIDRADIUS);
+ context.msg(TL.COMMAND_CLAIM_INVALIDRADIUS);
return;
}
- if (radius < 2) {
+ if (radius == 1) {
// single chunk
- unClaim(new FLocation(me));
+ unClaim(new FLocation(context.player), context);
} else {
// radius claim
- if (!Permission.CLAIM_RADIUS.has(sender, false)) {
- msg(TL.COMMAND_CLAIM_DENIED);
+ if (!Permission.CLAIM_RADIUS.has(context.sender, false)) {
+ context.msg(TL.COMMAND_CLAIM_DENIED);
return;
}
- new SpiralTask(new FLocation(me), radius) {
+ new SpiralTask(new FLocation(context.player), radius) {
private final int limit = Conf.radiusClaimFailureLimit - 1;
private int failCount = 0;
@Override
public boolean work() {
- boolean success = unClaim(this.currentFLocation());
+ boolean success = unClaim(currentFLocation(), context);
if (success) {
failCount = 0;
} else if (failCount++ >= limit) {
@@ -77,101 +82,101 @@ public class CmdUnclaim extends FCommand {
}
}
- private boolean unClaim(FLocation target) {
+ private boolean unClaim(FLocation target, CommandContext context) {
Faction targetFaction = Board.getInstance().getFactionAt(target);
if (targetFaction.isSafeZone()) {
- if (Permission.MANAGE_SAFE_ZONE.has(sender)) {
+ if (Permission.MANAGE_SAFE_ZONE.has(context.sender)) {
Board.getInstance().removeAt(target);
- msg(TL.COMMAND_UNCLAIM_SAFEZONE_SUCCESS);
+ context.msg(TL.COMMAND_UNCLAIM_SAFEZONE_SUCCESS);
if (Conf.logLandUnclaims) {
- P.p.log(TL.COMMAND_UNCLAIM_LOG.format(fme.getName(), target.getCoordString(), targetFaction.getTag()));
+ FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag()));
}
return true;
} else {
- msg(TL.COMMAND_UNCLAIM_SAFEZONE_NOPERM);
+ context.msg(TL.COMMAND_UNCLAIM_SAFEZONE_NOPERM);
return false;
}
} else if (targetFaction.isWarZone()) {
- if (Permission.MANAGE_WAR_ZONE.has(sender)) {
+ if (Permission.MANAGE_WAR_ZONE.has(context.sender)) {
Board.getInstance().removeAt(target);
- msg(TL.COMMAND_UNCLAIM_WARZONE_SUCCESS);
+ context.msg(TL.COMMAND_UNCLAIM_WARZONE_SUCCESS);
if (Conf.logLandUnclaims) {
- P.p.log(TL.COMMAND_UNCLAIM_LOG.format(fme.getName(), target.getCoordString(), targetFaction.getTag()));
+ FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag()));
}
return true;
} else {
- msg(TL.COMMAND_UNCLAIM_WARZONE_NOPERM);
+ context.msg(TL.COMMAND_UNCLAIM_WARZONE_NOPERM);
return false;
}
}
- if (fme.isAdminBypassing()) {
- LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(target, targetFaction, fme);
- Bukkit.getScheduler().runTask(P.p, () -> Bukkit.getServer().getPluginManager().callEvent(unclaimEvent));
+ if (context.fPlayer.isAdminBypassing()) {
+ LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(target, targetFaction, context.fPlayer);
+ Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
if (unclaimEvent.isCancelled()) {
return false;
}
Board.getInstance().removeAt(target);
- targetFaction.msg(TL.COMMAND_UNCLAIM_UNCLAIMED, fme.describeTo(targetFaction, true));
- msg(TL.COMMAND_UNCLAIM_UNCLAIMS);
+ targetFaction.msg(TL.COMMAND_UNCLAIM_UNCLAIMED, context.fPlayer.describeTo(targetFaction, true));
+ context.msg(TL.COMMAND_UNCLAIM_UNCLAIMS);
if (Conf.logLandUnclaims) {
- P.p.log(TL.COMMAND_UNCLAIM_LOG.format(fme.getName(), target.getCoordString(), targetFaction.getTag()));
+ FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag()));
}
return true;
}
+ if (targetFaction.getClaimOwnership().containsKey(target) && !targetFaction.isPlayerInOwnerList(context.fPlayer, target)) {
+ context.msg(TL.GENERIC_FPERM_OWNER_NOPERMISSION, "unclaim");
+ return false;
+ }
- if (targetFaction.getAccess(fme, PermissableAction.TERRITORY) == Access.DENY) {
+ if (targetFaction.getAccess(context.fPlayer, PermissableAction.TERRITORY) == Access.DENY && context.fPlayer.getRole() != Role.LEADER) {
+ context.msg(TL.GENERIC_FPERM_NOPERMISSION, "unclaim");
+ return false;
+ }
+
+ if (!context.assertHasFaction()) {
+ context.msg(TL.ACTIONS_NOFACTION);
+ return false;
+ }
+
+ if (context.faction != targetFaction) {
+ context.msg(TL.COMMAND_UNCLAIM_WRONGFACTION);
return false;
}
- if (!assertHasFaction()) {
- return false;
- }
-
- if (targetFaction.getAccess(fme, PermissableAction.TERRITORY) != Access.ALLOW && !assertMinRole(Role.MODERATOR)) {
- return false;
- }
-
-
- if (myFaction != targetFaction) {
- msg(TL.COMMAND_UNCLAIM_WRONGFACTION);
- return false;
- }
-
-
- LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(target, targetFaction, fme);
- Bukkit.getServer().getPluginManager().callEvent(unclaimEvent);
+ LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(target, targetFaction, context.fPlayer);
+ Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(unclaimEvent));
if (unclaimEvent.isCancelled()) {
return false;
}
if (Econ.shouldBeUsed()) {
- double refund = Econ.calculateClaimRefund(myFaction.getLandRounded());
+ double refund = Econ.calculateClaimRefund(context.faction.getLandRounded());
if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts) {
- if (!Econ.modifyMoney(myFaction, refund, TL.COMMAND_UNCLAIM_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIM_FORUNCLAIM.toString())) {
+ if (!Econ.modifyMoney(context.faction, refund, TL.COMMAND_UNCLAIM_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIM_FORUNCLAIM.toString())) {
return false;
}
} else {
- if (!Econ.modifyMoney(fme, refund, TL.COMMAND_UNCLAIM_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIM_FORUNCLAIM.toString())) {
+ if (!Econ.modifyMoney(context.fPlayer, refund, TL.COMMAND_UNCLAIM_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIM_FORUNCLAIM.toString())) {
return false;
}
}
}
Board.getInstance().removeAt(target);
- myFaction.msg(TL.COMMAND_UNCLAIM_FACTIONUNCLAIMED, fme.describeTo(myFaction, true));
+ context.faction.msg(TL.COMMAND_UNCLAIM_FACTIONUNCLAIMED, context.fPlayer.describeTo(context.faction, true));
if (Conf.logLandUnclaims) {
- P.p.log(TL.COMMAND_UNCLAIM_LOG.format(fme.getName(), target.getCoordString(), targetFaction.getTag()));
+ FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag()));
}
return true;
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaimall.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaimall.java
index 48de06c5..8df9fba8 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaimall.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdUnclaimall.java
@@ -2,11 +2,15 @@ package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.event.LandUnclaimAllEvent;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
+import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
@@ -16,45 +20,61 @@ public class CmdUnclaimall extends FCommand {
this.aliases.add("unclaimall");
this.aliases.add("declaimall");
- //this.requiredArgs.add("");
- //this.optionalArgs.put("", "");
-
- this.permission = Permission.UNCLAIM_ALL.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = true;
- senderMustBeAdmin = false;
+ this.optionalArgs.put("faction", "yours");
+ this.requirements = new CommandRequirements.Builder(Permission.UNCLAIM_ALL)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.TERRITORY) //TODO: Add Unclaimall PermissableAction
+ .build();
}
@Override
- public void perform() {
+ public void perform(CommandContext context) {
+ Faction target = context.faction;
+ if (context.args.size() == 1) {
+ target = context.argAsFaction(0);
+ if (target == null) {
+ context.msg(TL.GENERIC_NOFACTION_FOUND);
+ return;
+ }
+
+ if (!context.fPlayer.isAdminBypassing()) {
+ context.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", target.getTag()).replace("{action}", "unclaimall land"));
+ return;
+ }
+
+ Board.getInstance().unclaimAll(target.getId());
+ context.faction.msg(TL.COMMAND_UNCLAIMALL_LOG, context.fPlayer.describeTo(target, true), target.getTag());
+ if (Conf.logLandUnclaims)
+ FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIMALL_LOG.format(context.fPlayer.getName(), context.faction.getTag()));
+ return;
+
+ }
if (Econ.shouldBeUsed()) {
- double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded());
+ double refund = Econ.calculateTotalLandRefund(target.getLandRounded());
if (Conf.bankEnabled && Conf.bankFactionPaysLandCosts) {
- if (!Econ.modifyMoney(myFaction, refund, TL.COMMAND_UNCLAIMALL_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIMALL_FORUNCLAIM.toString())) {
+ if (!Econ.modifyMoney(target, refund, TL.COMMAND_UNCLAIMALL_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIMALL_FORUNCLAIM.toString())) {
return;
}
} else {
- if (!Econ.modifyMoney(fme, refund, TL.COMMAND_UNCLAIMALL_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIMALL_FORUNCLAIM.toString())) {
+ if (!Econ.modifyMoney(target, refund, TL.COMMAND_UNCLAIMALL_TOUNCLAIM.toString(), TL.COMMAND_UNCLAIMALL_FORUNCLAIM.toString())) {
return;
}
}
}
- LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(myFaction, fme);
- Bukkit.getScheduler().runTask(P.p, () -> Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent));
+ LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(target, context.fPlayer);
+ Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent));
if (unclaimAllEvent.isCancelled()) {
return;
}
- Board.getInstance().unclaimAll(myFaction.getId());
- myFaction.msg(TL.COMMAND_UNCLAIMALL_UNCLAIMED, fme.describeTo(myFaction, true));
+ Board.getInstance().unclaimAll(target.getId());
+ context.faction.msg(TL.COMMAND_UNCLAIMALL_UNCLAIMED, context.fPlayer.describeTo(context.faction, true));
if (Conf.logLandUnclaims) {
- P.p.log(TL.COMMAND_UNCLAIMALL_LOG.format(fme.getName(), myFaction.getTag()));
+ FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIMALL_LOG.format(context.fPlayer.getName(), context.faction.getTag()));
}
}
@@ -64,3 +84,4 @@ public class CmdUnclaimall extends FCommand {
}
}
+
diff --git a/src/main/java/com/massivecraft/factions/cmd/claim/CmdWarunclaimall.java b/src/main/java/com/massivecraft/factions/cmd/claim/CmdWarunclaimall.java
index 99d6e0ba..5c15eca4 100644
--- a/src/main/java/com/massivecraft/factions/cmd/claim/CmdWarunclaimall.java
+++ b/src/main/java/com/massivecraft/factions/cmd/claim/CmdWarunclaimall.java
@@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Factions;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -15,28 +17,18 @@ public class CmdWarunclaimall extends FCommand {
public CmdWarunclaimall() {
this.aliases.add("warunclaimall");
this.aliases.add("wardeclaimall");
-
- //this.requiredArgs.add("");
this.optionalArgs.put("world", "all");
- this.permission = Permission.MANAGE_WAR_ZONE.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
-
+ this.requirements = new CommandRequirements.Builder(Permission.MANAGE_WAR_ZONE)
+ .build();
}
@Override
- public void perform() {
- String worldName = argAsString(0);
+ public void perform(CommandContext context) {
+ String worldName = context.argAsString(0);
World world = null;
- if (worldName != null) {
- world = Bukkit.getWorld(worldName);
- }
+ if (worldName != null) world = Bukkit.getWorld(worldName);
String id = Factions.getInstance().getWarZone().getId();
@@ -46,12 +38,9 @@ public class CmdWarunclaimall extends FCommand {
Board.getInstance().unclaimAllInWorld(id, world);
}
- fme.msg(TL.COMMAND_WARUNCLAIMALL_SUCCESS);
-
-
- if (Conf.logLandUnclaims) {
- P.p.log(TL.COMMAND_WARUNCLAIMALL_LOG.format(fme.getName()));
- }
+ context.msg(TL.COMMAND_WARUNCLAIMALL_SUCCESS);
+ if (Conf.logLandUnclaims)
+ FactionsPlugin.getInstance().log(TL.COMMAND_WARUNCLAIMALL_LOG.format(context.fPlayer.getName()));
}
@Override
@@ -60,3 +49,4 @@ public class CmdWarunclaimall extends FCommand {
}
}
+
diff --git a/src/main/java/com/massivecraft/factions/cmd/config/CmdConvertConfig.java b/src/main/java/com/massivecraft/factions/cmd/configsf/CmdConvertConfig.java
similarity index 51%
rename from src/main/java/com/massivecraft/factions/cmd/config/CmdConvertConfig.java
rename to src/main/java/com/massivecraft/factions/cmd/configsf/CmdConvertConfig.java
index 256cfb90..73ada76e 100644
--- a/src/main/java/com/massivecraft/factions/cmd/config/CmdConvertConfig.java
+++ b/src/main/java/com/massivecraft/factions/cmd/configsf/CmdConvertConfig.java
@@ -1,27 +1,29 @@
-package com.massivecraft.factions.cmd.config;
+package com.massivecraft.factions.cmd.configsf;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdConvertConfig extends FCommand {
- public CmdConvertConfig() {
+ public CmdConvertConfig() {
super();
this.aliases.add("convertconfig");
- this.permission = Permission.CONVERTCONFIG.node;
- this.disableOnLock = false;
- senderMustBePlayer = true;
+
+ this.requirements = new CommandRequirements.Builder(Permission.CONVERTCONFIG)
+ .playerOnly()
+ .build();
}
@Override
- public void perform() {
- ConvertConfigHandler.convertconfig(fme.getPlayer());
+ public void perform(CommandContext context) {
+ ConvertConfigHandler.convertconfig(context.player);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_CONVERTCONFIG_DESCRIPTION;
}
-
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/config/ConvertConfigHandler.java b/src/main/java/com/massivecraft/factions/cmd/configsf/ConvertConfigHandler.java
similarity index 95%
rename from src/main/java/com/massivecraft/factions/cmd/config/ConvertConfigHandler.java
rename to src/main/java/com/massivecraft/factions/cmd/configsf/ConvertConfigHandler.java
index 94a0c07b..e176682c 100644
--- a/src/main/java/com/massivecraft/factions/cmd/config/ConvertConfigHandler.java
+++ b/src/main/java/com/massivecraft/factions/cmd/configsf/ConvertConfigHandler.java
@@ -1,6 +1,6 @@
-package com.massivecraft.factions.cmd.config;
+package com.massivecraft.factions.cmd.configsf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
@@ -13,6 +13,7 @@ import org.bukkit.scheduler.BukkitScheduler;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
@@ -32,7 +33,7 @@ public class ConvertConfigHandler {
ConfigurationSection cs = sv.getConfigurationSection(s);
sb.set(s, cs);
}
- static JavaPlugin plugin = JavaPlugin.getProvidingPlugin(P.class);
+ static JavaPlugin plugin = JavaPlugin.getProvidingPlugin(FactionsPlugin.class);
public static void setBoolean(String s){
sb.set(s, sv.getBoolean(s));
}
@@ -126,10 +127,10 @@ public class ConvertConfigHandler {
setConfigSec("Tntfill");
try {
sb.save(configFile);
- P.p.reloadConfig();
+ plugin.reloadConfig();
} catch (IOException e) {
player.sendMessage(TL.COMMAND_CONVERTCONFIG_FAIL.toString());
- Bukkit.getLogger().log(Level.SEVERE, e.getStackTrace().toString());
+ Bukkit.getLogger().log(Level.SEVERE, Arrays.toString(e.getStackTrace()));
}
player.sendMessage(TL.COMMAND_CONVERTCONFIG_SUCCESS.toString());
}, 0L);
diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoney.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoney.java
index 7bec6639..3b3380b7 100644
--- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoney.java
+++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoney.java
@@ -1,6 +1,8 @@
package com.massivecraft.factions.cmd.econ;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.Conf;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.zcore.util.TL;
@@ -21,15 +23,7 @@ public class CmdMoney extends FCommand {
//this.requiredArgs.add("");
//this.optionalArgs.put("","")
- this.isMoneyCommand = true;
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
-
- this.helpLong.add(p.txt.parseTags(TL.COMMAND_MONEY_LONG.toString()));
+ this.helpLong.add(FactionsPlugin.getInstance().txt.parseTags(TL.COMMAND_MONEY_LONG.toString()));
this.addSubCommand(this.cmdMoneyBalance);
this.addSubCommand(this.cmdMoneyDeposit);
@@ -37,13 +31,16 @@ public class CmdMoney extends FCommand {
this.addSubCommand(this.cmdMoneyTransferFf);
this.addSubCommand(this.cmdMoneyTransferFp);
this.addSubCommand(this.cmdMoneyTransferPf);
-
}
@Override
- public void perform() {
- this.commandChain.add(this);
- P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain);
+ public void perform(CommandContext context) {
+ if (!Conf.econEnabled) {
+ context.msg(TL.ECON_OFF, "economy option is enabled, please set \'econEnabled\' to true in conf.json");
+ return;
+ }
+ context.commandChain.add(this);
+ FactionsPlugin.getInstance().cmdAutoHelp.execute(context);
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyBalance.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyBalance.java
index f314026a..cde68cd3 100644
--- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyBalance.java
+++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyBalance.java
@@ -1,6 +1,8 @@
package com.massivecraft.factions.cmd.econ;
import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
@@ -16,36 +18,30 @@ public class CmdMoneyBalance extends FCommand {
//this.requiredArgs.add("");
this.optionalArgs.put("faction", "yours");
- this.isMoneyCommand = true;
- this.permission = Permission.MONEY_BALANCE.node;
this.setHelpShort(TL.COMMAND_MONEYBALANCE_SHORT.toString());
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.MONEY_BALANCE).build();
}
@Override
- public void perform() {
- Faction faction = myFaction;
- if (this.argIsSet(0)) {
- faction = this.argAsFaction(0);
+ public void perform(CommandContext context) {
+ Faction faction = context.faction;
+ if (context.argIsSet(0)) {
+ faction = context.argAsFaction(0);
}
if (faction == null) {
return;
}
- if (faction != myFaction && !Permission.MONEY_BALANCE_ANY.has(sender, true)) {
+ if (faction != context.faction && !Permission.MONEY_BALANCE_ANY.has(context.sender, true)) {
return;
}
- if (fme != null) {
- Econ.sendBalanceInfo((CommandSender) fme, faction);
+ if (context.fPlayer != null) {
+ Econ.sendBalanceInfo((CommandSender) context.fPlayer, faction);
} else {
- Econ.sendBalanceInfo(sender, faction);
+ Econ.sendBalanceInfo(context.sender, faction);
}
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyDeposit.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyDeposit.java
index f4742f1a..24becf24 100644
--- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyDeposit.java
+++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyDeposit.java
@@ -1,7 +1,9 @@
package com.massivecraft.factions.cmd.econ;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.integration.Econ;
@@ -20,29 +22,22 @@ public class CmdMoneyDeposit extends FCommand {
this.requiredArgs.add("amount");
this.optionalArgs.put("faction", "yours");
- this.isMoneyCommand = true;
-
- this.permission = Permission.MONEY_DEPOSIT.node;
-
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.MONEY_DEPOSIT)
+ .memberOnly()
+ .build();
}
@Override
- public void perform() {
- double amount = this.argAsDouble(0, 0d);
- EconomyParticipator faction = this.argAsFaction(1, myFaction);
+ public void perform(CommandContext context) {
+ double amount = context.argAsDouble(0, 0d);
+ EconomyParticipator faction = context.argAsFaction(1, context.faction);
if (faction == null) {
return;
}
- boolean success = Econ.transferMoney(fme, fme, faction, amount);
+ boolean success = Econ.transferMoney(context.fPlayer, context.fPlayer, faction, amount);
if (success && Conf.logMoneyTransactions) {
- P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYDEPOSIT_DEPOSITED.toString(), fme.getName(), Econ.moneyString(amount), faction.describeTo(null))));
+ FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYDEPOSIT_DEPOSITED.toString(), context.fPlayer.getName(), Econ.moneyString(amount), faction.describeTo(null))));
}
}
@@ -52,3 +47,4 @@ public class CmdMoneyDeposit extends FCommand {
}
}
+
diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFf.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFf.java
index 169dc61e..9da896b5 100644
--- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFf.java
+++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFf.java
@@ -1,7 +1,9 @@
package com.massivecraft.factions.cmd.econ;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.integration.Econ;
@@ -13,6 +15,7 @@ import org.bukkit.entity.Player;
public class CmdMoneyTransferFf extends FCommand {
+
public CmdMoneyTransferFf() {
this.aliases.add("ff");
@@ -20,45 +23,32 @@ public class CmdMoneyTransferFf extends FCommand {
this.requiredArgs.add("faction");
this.requiredArgs.add("faction");
- //this.optionalArgs.put("", "");
-
- this.permission = Permission.MONEY_F2F.node;
-
- this.isMoneyCommand = true;
-
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.MONEY_F2F).build();
}
@Override
- public void perform() {
- double amount = this.argAsDouble(0, 0d);
- EconomyParticipator from = this.argAsFaction(1);
+ public void perform(CommandContext context) {
+ double amount = context.argAsDouble(0, 0d);
+ EconomyParticipator from = context.argAsFaction(1);
if (from == null) {
return;
}
- EconomyParticipator to = this.argAsFaction(2);
+ EconomyParticipator to = context.argAsFaction(2);
if (to == null) {
return;
}
- if (Conf.econFactionStartingBalance != 0 && (System.currentTimeMillis() - myFaction.getFoundedDate()) <= (Conf.econDenyWithdrawWhenMinutesAgeLessThan * 6000)) {
- msg("Your faction is too young to transfer money like this");
- return;
- }
- boolean success = Econ.transferMoney(fme, from, to, amount);
+
+ boolean success = Econ.transferMoney(context.fPlayer, from, to, amount);
if (success && Conf.logMoneyTransactions) {
- String name = sender instanceof Player ? fme.getName() : sender.getName();
- P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYTRANSFERFF_TRANSFER.toString(), name, Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
+ String name = context.sender instanceof Player ? context.fPlayer.getName() : context.sender.getName();
+ FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYTRANSFERFF_TRANSFER.toString(), name, Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
}
}
+
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MONEYTRANSFERFF_DESCRIPTION;
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFp.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFp.java
index aae46aea..2eac623b 100644
--- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFp.java
+++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferFp.java
@@ -1,7 +1,9 @@
package com.massivecraft.factions.cmd.econ;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.integration.Econ;
@@ -11,7 +13,6 @@ import org.bukkit.ChatColor;
public class CmdMoneyTransferFp extends FCommand {
-
public CmdMoneyTransferFp() {
this.aliases.add("fp");
@@ -19,39 +20,25 @@ public class CmdMoneyTransferFp extends FCommand {
this.requiredArgs.add("faction");
this.requiredArgs.add("player");
- //this.optionalArgs.put("", "");
-
- this.permission = Permission.MONEY_F2P.node;
-
- this.isMoneyCommand = true;
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.MONEY_F2P).build();
}
@Override
- public void perform() {
- double amount = this.argAsDouble(0, 0d);
- EconomyParticipator from = this.argAsFaction(1);
+ public void perform(CommandContext context) {
+ double amount = context.argAsDouble(0, 0d);
+ EconomyParticipator from = context.argAsFaction(1);
if (from == null) {
return;
}
- EconomyParticipator to = this.argAsBestFPlayerMatch(2);
+ EconomyParticipator to = context.argAsBestFPlayerMatch(2);
if (to == null) {
return;
}
- if (Conf.econFactionStartingBalance != 0 && (System.currentTimeMillis() - myFaction.getFoundedDate()) <= (Conf.econDenyWithdrawWhenMinutesAgeLessThan * 6000)) {
- msg("Your faction is too young to transfer money like this");
- return;
- }
- boolean success = Econ.transferMoney(fme, from, to, amount);
+ boolean success = Econ.transferMoney(context.fPlayer, from, to, amount);
if (success && Conf.logMoneyTransactions) {
- P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYTRANSFERFP_TRANSFER.toString(), fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
+ FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYTRANSFERFP_TRANSFER.toString(), context.fPlayer.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
}
}
@@ -60,3 +47,4 @@ public class CmdMoneyTransferFp extends FCommand {
return TL.COMMAND_MONEYTRANSFERFP_DESCRIPTION;
}
}
+
diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferPf.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferPf.java
index 1efabe96..ab67d6be 100644
--- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferPf.java
+++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyTransferPf.java
@@ -1,7 +1,9 @@
package com.massivecraft.factions.cmd.econ;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.integration.Econ;
@@ -19,39 +21,25 @@ public class CmdMoneyTransferPf extends FCommand {
this.requiredArgs.add("player");
this.requiredArgs.add("faction");
- //this.optionalArgs.put("", "");
-
- this.permission = Permission.MONEY_P2F.node;
- this.isMoneyCommand = true;
-
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.MONEY_P2F).build();
}
@Override
- public void perform() {
- double amount = this.argAsDouble(0, 0d);
- EconomyParticipator from = this.argAsBestFPlayerMatch(1);
+ public void perform(CommandContext context) {
+ double amount = context.argAsDouble(0, 0d);
+ EconomyParticipator from = context.argAsBestFPlayerMatch(1);
if (from == null) {
return;
}
- EconomyParticipator to = this.argAsFaction(2);
+ EconomyParticipator to = context.argAsFaction(2);
if (to == null) {
return;
}
- if (Conf.econFactionStartingBalance != 0 && (System.currentTimeMillis() - myFaction.getFoundedDate()) <= (Conf.econDenyWithdrawWhenMinutesAgeLessThan * 6000)) {
- msg("Your faction is too young to transfer money like this");
- return;
- }
- boolean success = Econ.transferMoney(fme, from, to, amount);
+ boolean success = Econ.transferMoney(context.fPlayer, from, to, amount);
if (success && Conf.logMoneyTransactions) {
- P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYTRANSFERPF_TRANSFER.toString(), fme.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
+ FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYTRANSFERPF_TRANSFER.toString(), context.fPlayer.getName(), Econ.moneyString(amount), from.describeTo(null), to.describeTo(null))));
}
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java
index 97df7d48..a3cc0686 100644
--- a/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java
+++ b/src/main/java/com/massivecraft/factions/cmd/econ/CmdMoneyWithdraw.java
@@ -1,11 +1,14 @@
package com.massivecraft.factions.cmd.econ;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
+import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
@@ -21,41 +24,30 @@ public class CmdMoneyWithdraw extends FCommand {
this.requiredArgs.add("amount");
this.optionalArgs.put("faction", "yours");
- this.permission = Permission.MONEY_WITHDRAW.node;
- this.isMoneyCommand = true;
-
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.MONEY_F2P)
+ .playerOnly()
+ .build();
}
@Override
- public void perform() {
-
- double amount = this.argAsDouble(0, 0d);
- EconomyParticipator faction = this.argAsFaction(1, myFaction);
+ public void perform(CommandContext context) {
+ double amount = context.argAsDouble(0, 0d);
+ EconomyParticipator faction = context.argAsFaction(1, context.faction);
if (faction == null) {
return;
}
- Access access = myFaction.getAccess(fme, PermissableAction.WITHDRAW);
- if (access == Access.DENY) {
- fme.msg(TL.GENERIC_NOPERMISSION, "withdraw");
- return;
+ Access access = context.faction.getAccess(context.fPlayer, PermissableAction.WITHDRAW);
+ if (context.fPlayer.getRole() != Role.LEADER) {
+ if (access == Access.DENY) {
+ context.msg(TL.GENERIC_NOPERMISSION, "withdraw", "withdraw money from the bank");
+ return;
+ }
}
-
- if (Conf.econFactionStartingBalance != 0 && (System.currentTimeMillis() - myFaction.getFoundedDate()) <= (Conf.econDenyWithdrawWhenMinutesAgeLessThan * 6000)) {
- msg("Your faction is too young to withdraw money like this");
- return;
- }
-
- boolean success = Econ.transferMoney(fme, faction, fme, amount);
+ boolean success = Econ.transferMoney(context.fPlayer, faction, context.fPlayer, amount);
if (success && Conf.logMoneyTransactions) {
- P.p.log(ChatColor.stripColor(P.p.txt.parse(TL.COMMAND_MONEYWITHDRAW_WITHDRAW.toString(), fme.getName(), Econ.moneyString(amount), faction.describeTo(null))));
+ FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYWITHDRAW_WITHDRAW.toString(), context.fPlayer.getName(), Econ.moneyString(amount), faction.describeTo(null))));
}
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java b/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java
index dc4d2911..d64a456e 100644
--- a/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java
+++ b/src/main/java/com/massivecraft/factions/cmd/grace/CmdGrace.java
@@ -1,7 +1,8 @@
package com.massivecraft.factions.cmd.grace;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -9,37 +10,24 @@ import com.massivecraft.factions.zcore.util.TL;
public class CmdGrace extends FCommand {
public CmdGrace() {
-
super();
this.aliases.add("grace");
- this.permission = Permission.GRACE.node;
- this.disableOnLock = false;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.GRACE)
+ .playerOnly()
+ .build();
}
@Override
- public void perform() {
- if (!P.p.getConfig().getBoolean("f-grace.Enabled")) {
- fme.msg(TL.GENERIC_DISABLED);
- return;
- }
-
- boolean gracePeriod = Conf.gracePeriod;
-
- if (args.size() == 0) {
- Conf.gracePeriod = !gracePeriod;
- }
- fme.msg(TL.COMMAND_GRACE_TOGGLE, gracePeriod ? "enabled" : "disabled");
+ public void perform(CommandContext context) {
+ Conf.gracePeriod = !Conf.gracePeriod;
+ context.msg(TL.COMMAND_GRACE_TOGGLE, Conf.gracePeriod ? TL.GENERIC_ENABLED : TL.GENERIC_DISABLED);
}
+
@Override
public TL getUsageTranslation() {
return TL.COMMAND_GRACE_DESCRIPTION;
}
+
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java b/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java
index 04362fca..e1ed15c4 100644
--- a/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java
+++ b/src/main/java/com/massivecraft/factions/cmd/logout/CmdLogout.java
@@ -1,6 +1,8 @@
package com.massivecraft.factions.cmd.logout;
import com.massivecraft.factions.Conf;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -11,27 +13,22 @@ public class CmdLogout extends FCommand {
super();
this.aliases.add("logout");
- this.permission = Permission.LOGOUT.node;
- this.disableOnLock = true;
- this.disableOnSpam = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.LOGOUT)
+ .playerOnly()
+ .build();
}
@Override
- public void perform() {
- LogoutHandler handler = LogoutHandler.getByName(fme.getPlayer().getName());
+ public void perform(CommandContext context) {
+ LogoutHandler handler = LogoutHandler.getByName(context.player.getName());
- if (handler.isLogoutActive(fme.getPlayer())) {
- fme.msg(TL.COMMAND_LOGOUT_ACTIVE);
+ if (handler.isLogoutActive(context.player)) {
+ context.msg(TL.COMMAND_LOGOUT_ACTIVE);
return;
}
- handler.applyLogoutCooldown(fme.getPlayer());
- fme.msg(TL.COMMAND_LOGOUT_LOGGING, Conf.logoutCooldown);
+ handler.applyLogoutCooldown(context.player);
+ context.msg(TL.COMMAND_LOGOUT_LOGGING, Conf.logoutCooldown);
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java b/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java
index 1cf724e9..0596e2c6 100644
--- a/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java
+++ b/src/main/java/com/massivecraft/factions/cmd/logout/LogoutHandler.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd.logout;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -38,9 +38,9 @@ public class LogoutHandler {
public void applyLogoutCooldown(Player player) {
logoutCooldown.put(player.getUniqueId(), System.currentTimeMillis() + (30 * 1000));
- Bukkit.getScheduler().runTaskLater(P.p, () -> {
+ Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> {
if (isLogoutActive(player)) {
- player.setMetadata("Logout", new FixedMetadataValue(P.p, true));
+ player.setMetadata("Logout", new FixedMetadataValue(FactionsPlugin.getInstance(), true));
player.kickPlayer(String.valueOf(TL.COMMAND_LOGOUT_KICK_MESSAGE));
cancelLogout(player);
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/points/CmdPoints.java b/src/main/java/com/massivecraft/factions/cmd/points/CmdPoints.java
index 2db4ca02..762a06d8 100644
--- a/src/main/java/com/massivecraft/factions/cmd/points/CmdPoints.java
+++ b/src/main/java/com/massivecraft/factions/cmd/points/CmdPoints.java
@@ -1,7 +1,10 @@
package com.massivecraft.factions.cmd.points;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
+import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdPoints extends FCommand {
@@ -14,13 +17,9 @@ public class CmdPoints extends FCommand {
super();
this.aliases.add("points");
- this.disableOnLock = false;
- this.disableOnSpam = false;
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.POINTS)
+ .playerOnly()
+ .build();
this.addSubCommand(this.cmdPointsAdd);
@@ -30,13 +29,13 @@ public class CmdPoints extends FCommand {
@Override
- public void perform() {
- if (!P.p.getConfig().getBoolean("f-points.Enabled", true)) {
- msg(TL.GENERIC_DISABLED);
+ public void perform(CommandContext context) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled", true)) {
+ context.msg(TL.GENERIC_DISABLED);
return;
}
- this.commandChain.add(this);
- P.p.cmdAutoHelp.execute(this.sender, this.args, this.commandChain);
+ context.commandChain.add(this);
+ FactionsPlugin.getInstance().cmdAutoHelp.execute(context);
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsAdd.java b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsAdd.java
index e999ae99..f1964ae3 100644
--- a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsAdd.java
+++ b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsAdd.java
@@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.points;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -17,44 +19,34 @@ public class CmdPointsAdd extends FCommand {
this.requiredArgs.add("# of points");
- this.errorOnToManyArgs = false;
- //this.optionalArgs
-
- this.permission = Permission.ADDPOINTS.node;
-
- this.disableOnLock = true;
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.ADDPOINTS)
+ .build();
}
@Override
- public void perform() {
- Faction faction = Factions.getInstance().getByTag(args.get(0));
+ public void perform(CommandContext context) {
+ Faction faction = Factions.getInstance().getByTag(context.args.get(0));
if (faction == null) {
- FPlayer fPlayer = this.argAsFPlayer(0);
+ FPlayer fPlayer = context.argAsFPlayer(0);
if (fPlayer != null) {
faction = fPlayer.getFaction();
}
}
if (faction == null || faction.isWilderness()) {
- msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0)));
+ context.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", context.args.get(0)));
return;
}
- if (argAsInt(1) <= 0) {
- msg(TL.COMMAND_POINTS_INSUFFICIENT);
+ if (context.argAsInt(1) <= 0) {
+ context.msg(TL.COMMAND_POINTS_INSUFFICIENT);
return;
}
- faction.setPoints(faction.getPoints() + argAsInt(1));
+ faction.setPoints(faction.getPoints() + context.argAsInt(1));
- msg(TL.COMMAND_POINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints());
+ context.msg(TL.COMMAND_POINTS_SUCCESSFUL, context.argAsInt(1), faction.getTag(), faction.getPoints());
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsRemove.java b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsRemove.java
index 10fe5e0c..6320a256 100644
--- a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsRemove.java
+++ b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsRemove.java
@@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.points;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -16,44 +18,34 @@ public class CmdPointsRemove extends FCommand {
this.requiredArgs.add("faction/player");
this.requiredArgs.add("# of points");
+ this.requirements = new CommandRequirements.Builder(Permission.REMOVEPOINTS)
+ .build();
- this.errorOnToManyArgs = false;
- //this.optionalArgs
-
- this.permission = Permission.REMOVEPOINTS.node;
-
- this.disableOnLock = true;
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
}
@Override
- public void perform() {
- Faction faction = Factions.getInstance().getByTag(args.get(0));
+ public void perform(CommandContext context) {
+ Faction faction = Factions.getInstance().getByTag(context.args.get(0));
- FPlayer fPlayer = this.argAsFPlayer(0);
+ FPlayer fPlayer = context.argAsFPlayer(0);
if (fPlayer != null) {
faction = fPlayer.getFaction();
}
if (faction == null || faction.isWilderness()) {
- msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0)));
+ context.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", context.args.get(0)));
return;
}
- if (argAsInt(1) <= 0) {
- msg(TL.COMMAND_POINTS_INSUFFICIENT);
+ if (context.argAsInt(1) <= 0) {
+ context.msg(TL.COMMAND_POINTS_INSUFFICIENT);
return;
}
- faction.setPoints(faction.getPoints() - argAsInt(1));
- msg(TL.COMMAND_REMOVEPOINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints());
+ faction.setPoints(faction.getPoints() - context.argAsInt(1));
+ context.msg(TL.COMMAND_REMOVEPOINTS_SUCCESSFUL, context.argAsInt(1), faction.getTag(), faction.getPoints());
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsSet.java b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsSet.java
index d8a304a2..e3fde0f5 100644
--- a/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsSet.java
+++ b/src/main/java/com/massivecraft/factions/cmd/points/CmdPointsSet.java
@@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd.points;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -17,42 +19,32 @@ public class CmdPointsSet extends FCommand {
this.requiredArgs.add("# of points");
- this.errorOnToManyArgs = false;
- //this.optionalArgs
-
- this.permission = Permission.SETPOINTS.node;
-
- this.disableOnLock = true;
-
- senderMustBePlayer = false;
- senderMustBeMember = false;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.SETPOINTS)
+ .build();
}
@Override
- public void perform() {
- Faction faction = Factions.getInstance().getByTag(args.get(0));
+ public void perform(CommandContext context) {
+ Faction faction = Factions.getInstance().getByTag(context.args.get(0));
- FPlayer fPlayer = this.argAsFPlayer(0);
+ FPlayer fPlayer = context.argAsFPlayer(0);
if (fPlayer != null) {
faction = fPlayer.getFaction();
}
if (faction == null || faction.isWilderness()) {
- msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", args.get(0)));
+ context.msg(TL.COMMAND_POINTS_FAILURE.toString().replace("{faction}", context.args.get(0)));
return;
}
- if (argAsInt(1) < 0) {
- msg(TL.COMMAND_POINTS_INSUFFICIENT);
+ if (context.argAsInt(1) < 0) {
+ context.msg(TL.COMMAND_POINTS_INSUFFICIENT);
return;
}
- faction.setPoints(argAsInt(1));
- msg(TL.COMMAND_SETPOINTS_SUCCESSFUL, argAsInt(1), faction.getTag(), faction.getPoints());
+ faction.setPoints(context.argAsInt(1));
+ context.msg(TL.COMMAND_SETPOINTS_SUCCESSFUL, context.argAsInt(1), faction.getTag(), faction.getPoints());
}
diff --git a/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java b/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java
index fdc979b9..4e5e21a3 100644
--- a/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java
+++ b/src/main/java/com/massivecraft/factions/cmd/relational/FRelationCommand.java
@@ -2,13 +2,16 @@ package com.massivecraft.factions.cmd.relational;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.event.FactionRelationEvent;
import com.massivecraft.factions.event.FactionRelationWishEvent;
import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
+import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -20,99 +23,96 @@ public abstract class FRelationCommand extends FCommand {
public FRelationCommand() {
super();
this.requiredArgs.add("faction tag");
- //this.optionalArgs.put("player name", "you");
- this.permission = Permission.RELATION.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = true;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.RELATION)
+ .withRole(Role.MODERATOR)
+ .playerOnly()
+ .memberOnly()
+ .build();
}
@Override
- public void perform() {
- Faction them = this.argAsFaction(0);
+ public void perform(CommandContext context) {
+ Faction them = context.argAsFaction(0);
if (them == null) {
return;
}
if (!them.isNormal()) {
- msg(TL.COMMAND_RELATIONS_ALLTHENOPE);
+ context.msg(TL.COMMAND_RELATIONS_ALLTHENOPE);
return;
}
- if (them == myFaction) {
- msg(TL.COMMAND_RELATIONS_MORENOPE);
+ if (them == context.faction) {
+ context.msg(TL.COMMAND_RELATIONS_MORENOPE);
return;
}
- if (myFaction.getRelationWish(them) == targetRelation) {
- msg(TL.COMMAND_RELATIONS_ALREADYINRELATIONSHIP, them.getTag());
+ if (context.faction.getRelationWish(them) == targetRelation) {
+ context.msg(TL.COMMAND_RELATIONS_ALREADYINRELATIONSHIP, them.getTag());
return;
}
- if (hasMaxRelations(them, targetRelation)) {
+ if (hasMaxRelations(context.faction, them, targetRelation)) {
// We message them down there with the count.
return;
}
- Relation oldRelation = myFaction.getRelationTo(them, true);
- FactionRelationWishEvent wishEvent = new FactionRelationWishEvent(fme, myFaction, them, oldRelation, targetRelation);
+ Relation oldRelation = context.faction.getRelationTo(them, true);
+ FactionRelationWishEvent wishEvent = new FactionRelationWishEvent(context.fPlayer, context.faction, them, oldRelation, targetRelation);
Bukkit.getPluginManager().callEvent(wishEvent);
if (wishEvent.isCancelled()) {
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
- if (!payForCommand(targetRelation.getRelationCost(), TL.COMMAND_RELATIONS_TOMARRY, TL.COMMAND_RELATIONS_FORMARRY)) {
+ if (!context.payForCommand(targetRelation.getRelationCost(), TL.COMMAND_RELATIONS_TOMARRY, TL.COMMAND_RELATIONS_FORMARRY)) {
return;
}
// try to set the new relation
- myFaction.setRelationWish(them, targetRelation);
- Relation currentRelation = myFaction.getRelationTo(them, true);
+ context.faction.setRelationWish(them, targetRelation);
+ Relation currentRelation = context.faction.getRelationTo(them, true);
ChatColor currentRelationColor = currentRelation.getColor();
// if the relation change was successful
if (targetRelation.value == currentRelation.value) {
// trigger the faction relation event
- FactionRelationEvent relationEvent = new FactionRelationEvent(myFaction, them, oldRelation, currentRelation);
+ FactionRelationEvent relationEvent = new FactionRelationEvent(context.faction, them, oldRelation, currentRelation);
Bukkit.getServer().getPluginManager().callEvent(relationEvent);
- them.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + myFaction.getTag());
- myFaction.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + them.getTag());
+ them.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + context.faction.getTag());
+ context.faction.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + them.getTag());
} else {
// inform the other faction of your request
- them.msg(TL.COMMAND_RELATIONS_PROPOSAL_1, currentRelationColor + myFaction.getTag(), targetRelation.getColor() + targetRelation.getTranslation());
- them.msg(TL.COMMAND_RELATIONS_PROPOSAL_2, Conf.baseCommandAliases.get(0), targetRelation, myFaction.getTag());
- myFaction.msg(TL.COMMAND_RELATIONS_PROPOSAL_SENT, currentRelationColor + them.getTag(), "" + targetRelation.getColor() + targetRelation);
+ them.msg(TL.COMMAND_RELATIONS_PROPOSAL_1, currentRelationColor + context.faction.getTag(), targetRelation.getColor() + targetRelation.getTranslation());
+ them.msg(TL.COMMAND_RELATIONS_PROPOSAL_2, Conf.baseCommandAliases.get(0), targetRelation, context.faction.getTag());
+ context.faction.msg(TL.COMMAND_RELATIONS_PROPOSAL_SENT, currentRelationColor + them.getTag(), "" + targetRelation.getColor() + targetRelation);
}
if (!targetRelation.isNeutral() && them.isPeaceful()) {
them.msg(TL.COMMAND_RELATIONS_PEACEFUL);
- myFaction.msg(TL.COMMAND_RELATIONS_PEACEFULOTHER);
+ context.faction.msg(TL.COMMAND_RELATIONS_PEACEFULOTHER);
}
- if (!targetRelation.isNeutral() && myFaction.isPeaceful()) {
+ if (!targetRelation.isNeutral() && context.faction.isPeaceful()) {
them.msg(TL.COMMAND_RELATIONS_PEACEFULOTHER);
- myFaction.msg(TL.COMMAND_RELATIONS_PEACEFUL);
+ context.faction.msg(TL.COMMAND_RELATIONS_PEACEFUL);
}
- FTeamWrapper.updatePrefixes(myFaction);
+ FTeamWrapper.updatePrefixes(context.faction);
FTeamWrapper.updatePrefixes(them);
}
- private boolean hasMaxRelations(Faction them, Relation targetRelation) {
- int max = P.p.getConfig().getInt("max-relations." + targetRelation.toString(), -1);
- if (P.p.getConfig().getBoolean("max-relations.enabled", false)) {
+ private boolean hasMaxRelations(Faction us, Faction them, Relation targetRelation) {
+ int max = FactionsPlugin.getInstance().getConfig().getInt("max-relations." + targetRelation.toString(), -1);
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("max-relations.enabled", false)) {
if (max != -1) {
- if (myFaction.getRelationCount(targetRelation) >= max) {
- msg(TL.COMMAND_RELATIONS_EXCEEDS_ME, max, targetRelation.getPluralTranslation());
+ if (us.getRelationCount(targetRelation) >= max) {
+ us.msg(TL.COMMAND_RELATIONS_EXCEEDS_ME, max, targetRelation.getPluralTranslation());
return true;
}
if (them.getRelationCount(targetRelation) >= max) {
- msg(TL.COMMAND_RELATIONS_EXCEEDS_THEY, max, targetRelation.getPluralTranslation());
+ them.msg(TL.COMMAND_RELATIONS_EXCEEDS_THEY, max, targetRelation.getPluralTranslation());
return true;
}
}
@@ -125,3 +125,4 @@ public abstract class FRelationCommand extends FCommand {
return TL.COMMAND_RELATIONS_DESCRIPTION;
}
}
+
diff --git a/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java b/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java
index 7899a1a5..360f2d3c 100644
--- a/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java
+++ b/src/main/java/com/massivecraft/factions/cmd/roles/FPromoteCommand.java
@@ -1,13 +1,13 @@
package com.massivecraft.factions.cmd.roles;
import com.massivecraft.factions.FPlayer;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
-import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
-import org.bukkit.ChatColor;
public class FPromoteCommand extends FCommand {
@@ -15,33 +15,25 @@ public class FPromoteCommand extends FCommand {
public FPromoteCommand() {
super();
-
this.requiredArgs.add("player");
- this.permission = Permission.PROMOTE.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.PROMOTE)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.PROMOTE)
+ .build();
}
@Override
- public void perform() {
- FPlayer target = this.argAsBestFPlayerMatch(0);
+ public void perform(CommandContext context) {
+ FPlayer target = context.argAsBestFPlayerMatch(0);
if (target == null) {
- msg(TL.GENERIC_NOPLAYERFOUND, this.argAsString(0));
+ context.msg(TL.GENERIC_NOPLAYERFOUND, context.argAsString(0));
return;
}
- if (!target.getFaction().equals(myFaction)) {
- msg(TL.COMMAND_PROMOTE_WRONGFACTION, target.getName());
- return;
- }
-
- if (target.isAlt()) {
- msg(ChatColor.RED + "You can not edit the rank of alt accounts.");
+ if (!target.getFaction().equals(context.faction)) {
+ context.msg(TL.COMMAND_PROMOTE_WRONGFACTION, target.getName());
return;
}
@@ -49,36 +41,31 @@ public class FPromoteCommand extends FCommand {
Role promotion = Role.getRelative(current, +relative);
// Now it ain't that messy
- if (!fme.isAdminBypassing()) {
- Access access = myFaction.getAccess(fme, PermissableAction.PROMOTE);
- if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
- fme.msg(TL.GENERIC_NOPERMISSION, "manage ranks");
- return;
- }
- if (target == fme) {
- fme.msg(TL.COMMAND_PROMOTE_NOTSELF);
+ if (!context.fPlayer.isAdminBypassing()) {
+ if (target == context.fPlayer) {
+ context.msg(TL.COMMAND_PROMOTE_NOTSELF);
return;
}
// Don't allow people to manage role of their same rank
- if (fme.getRole() == current) {
- fme.msg(TL.COMMAND_PROMOTE_NOT_SAME);
+ if (context.fPlayer.getRole() == current) {
+ context.msg(TL.COMMAND_PROMOTE_NOT_SAME);
return;
}
// Don't allow people to promote people to their same or higher rank.
- if (fme.getRole().value <= promotion.value) {
- fme.msg(TL.COMMAND_PROMOTE_NOT_ALLOWED);
+ if (context.fPlayer.getRole().value <= promotion.value) {
+ context.msg(TL.COMMAND_PROMOTE_NOT_ALLOWED);
return;
}
}
if (promotion == null) {
- fme.msg(TL.COMMAND_PROMOTE_NOTTHATPLAYER);
+ context.msg(TL.COMMAND_PROMOTE_NOTTHATPLAYER);
return;
}
// Don't allow people to promote people to their same or higher rnak.
- if (fme.getRole().value <= promotion.value) {
- fme.msg(TL.COMMAND_PROMOTE_NOT_ALLOWED);
+ if (context.fPlayer.getRole().value <= promotion.value) {
+ context.msg(TL.COMMAND_PROMOTE_NOT_ALLOWED);
return;
}
@@ -90,7 +77,7 @@ public class FPromoteCommand extends FCommand {
target.msg(TL.COMMAND_PROMOTE_TARGET, action, promotion.nicename);
}
- fme.msg(TL.COMMAND_PROMOTE_SUCCESS, action, target.getName(), promotion.nicename);
+ context.msg(TL.COMMAND_PROMOTE_SUCCESS, action, target.getName(), promotion.nicename);
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java
index 35bad43b..cbb091e5 100644
--- a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java
+++ b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java
@@ -1,11 +1,11 @@
package com.massivecraft.factions.cmd.tnt;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
-import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.XMaterial;
-import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Material;
@@ -14,54 +14,40 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class CmdTnt extends FCommand {
-
public CmdTnt() {
super();
this.aliases.add("tnt");
-
this.optionalArgs.put("add/take", "");
this.optionalArgs.put("amount", "number");
-
- this.permission = Permission.TNT.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = false;
- senderMustBeModerator = true;
- senderMustBeAdmin = false;
-
+ this.requirements = new CommandRequirements.Builder(Permission.TNT)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.TNTBANK)
+ .build();
}
@Override
- public void perform() {
- if (!P.p.getConfig().getBoolean("ftnt.Enabled")) {
- fme.msg(TL.COMMAND_TNT_DISABLED_MSG);
+ public void perform(CommandContext context) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("ftnt.Enabled")) {
+ context.msg(TL.COMMAND_TNT_DISABLED_MSG);
return;
}
- if (!fme.isAdminBypassing()) {
- Access access = myFaction.getAccess(fme, PermissableAction.TNTBANK);
- if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
- fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use tnt bank");
- return;
- }
- }
-
- if (args.size() == 2) {
- if (args.get(0).equalsIgnoreCase("add") || args.get(0).equalsIgnoreCase("a")) {
+ if (context.args.size() == 2) {
+ if (context.args.get(0).equalsIgnoreCase("add") || context.args.get(0).equalsIgnoreCase("a")) {
try {
- Integer.parseInt(args.get(1));
+ Integer.parseInt(context.args.get(1));
} catch (NumberFormatException e) {
- fme.msg(TL.COMMAND_TNT_INVALID_NUM);
+ context.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
- int amount = Integer.parseInt(args.get(1));
+ int amount = Integer.parseInt(context.args.get(1));
if (amount < 0) {
- fme.msg(TL.COMMAND_TNT_POSITIVE);
+ context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
- Inventory inv = me.getInventory();
+ Inventory inv = context.player.getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
if (inv.getItem(i) == null) {
@@ -72,69 +58,83 @@ public class CmdTnt extends FCommand {
}
}
if (amount > invTnt) {
- fme.msg(TL.COMMAND_TNT_DEPOSIT_NOTENOUGH);
+ context.msg(TL.COMMAND_TNT_DEPOSIT_NOTENOUGH);
return;
}
ItemStack tnt = new ItemStack(Material.TNT, amount);
- if (fme.getFaction().getTnt() + amount > P.p.getConfig().getInt("ftnt.Bank-Limit")) {
- msg(TL.COMMAND_TNT_EXCEEDLIMIT);
+ if (context.faction.getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
+ context.msg(TL.COMMAND_TNT_EXCEEDLIMIT);
return;
}
- removeFromInventory(me.getInventory(), tnt);
- me.updateInventory();
+ removeFromInventory(context.player.getInventory(), tnt);
+ context.player.updateInventory();
- fme.getFaction().addTnt(amount);
- fme.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
- fme.sendMessage(P.p.color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", fme.getFaction().getTnt() + "")));
+ context.faction.addTnt(amount);
+ context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
+ context.fPlayer.sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
return;
}
- if (args.get(0).equalsIgnoreCase("take") || args.get(0).equalsIgnoreCase("t")) {
+ if (context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t")) {
try {
- Integer.parseInt(args.get(1));
+ Integer.parseInt(context.args.get(1));
} catch (NumberFormatException e) {
- fme.msg(TL.COMMAND_TNT_INVALID_NUM);
+ context.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
- int amount = Integer.parseInt(args.get(1));
+ int amount = Integer.parseInt(context.args.get(1));
if (amount < 0) {
- fme.msg(TL.COMMAND_TNT_POSITIVE);
+ context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
- if (fme.getFaction().getTnt() < amount) {
- fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
+ if (context.faction.getTnt() < amount) {
+ context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString());
return;
}
- int fullStacks = Math.round(amount / 6);
+ int fullStacks = Math.round(amount / 64);
int remainderAmt = amount - (fullStacks * 64);
- if ((remainderAmt == 0 && !hasAvaliableSlot(me, fullStacks))) {
- fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
+ if ((remainderAmt == 0 && !hasAvaliableSlot(context.player, fullStacks))) {
+ context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
return;
}
- if (!hasAvaliableSlot(me, fullStacks + 1)) {
- fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
+ if (!hasAvaliableSlot(context.player, fullStacks + 1)) {
+ context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
return;
}
for (int i = 0; i <= fullStacks - 1; i++)
- me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
+ context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
if (remainderAmt != 0)
- me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
+ context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
- fme.getFaction().takeTnt(amount);
- me.updateInventory();
- fme.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS);
+ context.faction.takeTnt(amount);
+ context.player.updateInventory();
+ context.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS);
}
- } else if (args.size() == 1) {
- fme.msg(TL.GENERIC_ARGS_TOOFEW);
- fme.msg(args.get(0).equalsIgnoreCase("take") || args.get(0).equalsIgnoreCase("t") ? TL.COMMAND_TNT_TAKE_DESCRIPTION : TL.COMMAND_TNT_ADD_DESCRIPTION);
+ } else if (context.args.size() == 1) {
+ context.msg(TL.GENERIC_ARGS_TOOFEW);
+ context.msg(context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t") ? TL.COMMAND_TNT_TAKE_DESCRIPTION : TL.COMMAND_TNT_ADD_DESCRIPTION);
}
- fme.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", fme.getFaction().getTnt() + ""));
+ context.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.faction.getTnt() + ""));
}
+ public boolean inventoryContains(Inventory inventory, ItemStack item) {
+ int count = 0;
+ ItemStack[] items = inventory.getContents();
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) {
+ count += items[i].getAmount();
+ }
+ if (count >= item.getAmount()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public boolean hasAvaliableSlot(Player player, int howmany) {
- int check = 0;
+ Integer check = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item == null) {
check++;
@@ -168,3 +168,4 @@ public class CmdTnt extends FCommand {
return TL.COMMAND_TNT_DESCRIPTION;
}
}
+
diff --git a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java
index 7377ac24..edd9f749 100644
--- a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java
+++ b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java
@@ -1,20 +1,27 @@
package com.massivecraft.factions.cmd.tnt;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FPlayer;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
-import com.massivecraft.factions.struct.Role;
-import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location;
import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
public class CmdTntFill extends FCommand {
public CmdTntFill() {
@@ -24,146 +31,137 @@ public class CmdTntFill extends FCommand {
this.requiredArgs.add("radius");
this.requiredArgs.add("amount");
- this.permission = Permission.TNTFILL.node;
- this.disableOnLock = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
-
+ this.requirements = new CommandRequirements.Builder(Permission.TNTFILL)
+ .playerOnly()
+ .memberOnly()
+ .withAction(PermissableAction.TNTFILL)
+ .build();
}
@Override
- public void perform() {
- if (!P.p.getConfig().getBoolean("Tntfill.enabled")) {
- this.fme.msg(TL.GENERIC_DISABLED);
+ public void perform(CommandContext context) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("Tntfill.enabled")) {
+ context.msg(TL.GENERIC_DISABLED);
return;
}
- if (!fme.isAdminBypassing()) {
- Access access = myFaction.getAccess(fme, PermissableAction.TNTFILL);
- if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
- fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use tnt fill");
+
+ // Don't do I/O unless necessary
+ try {
+ Integer.parseInt(context.args.get(0));
+ Integer.parseInt(context.args.get(1));
+ } catch (NumberFormatException e) {
+ context.msg(TL.COMMAND_TNT_INVALID_NUM);
+ return;
+ }
+
+ context.msg(TL.COMMAND_TNTFILL_HEADER);
+ int radius = context.argAsInt(0, 0); // We don't know the max yet, so let's not assume.
+ int amount = context.argAsInt(1, 0); // We don't know the max yet, so let's not assume.
+
+ if (amount < 0) {
+ context.msg(TL.COMMAND_TNT_POSITIVE);
+ return;
+ }
+ if (radius > FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-radius")) {
+ context.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-radius") + ""));
+ return;
+ }
+ if (amount > FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-amount")) {
+ context.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-amount") + ""));
+ return;
+ }
+
+ // How many dispensers are we to fill in?
+
+ Location start = context.player.getLocation();
+ // Keep it on the stack for CPU saving.
+ List opDispensers = new ArrayList<>();
+
+ Block startBlock = start.getBlock();
+ for (int x = -radius; x <= radius; x++)
+ for (int y = -radius; y <= radius; y++)
+ for (int z = -radius; z <= radius; z++) {
+ Block block = startBlock.getRelative(x, y, z);
+ if (block == null) continue;
+ BlockState blockState = block.getState();
+ if (!(blockState instanceof Dispenser)) continue;
+ opDispensers.add((Dispenser) blockState);
+ }
+ if (opDispensers.isEmpty()) {
+ context.fPlayer.msg(TL.COMMAND_TNTFILL_NODISPENSERS.toString().replace("{radius}", radius + ""));
+ return;
+ }
+
+ // What's the required amount of resources
+ int requiredTnt = (opDispensers.size() * amount);
+
+ // Do I have enough tnt in my inventory?
+ int playerTnt = inventoryItemCount(context.player.getInventory(), Material.TNT);
+ if (playerTnt < requiredTnt) {
+ // How much TNT will I take from bank?
+ int getFactionTnt = requiredTnt - playerTnt;
+
+ // Do I have enough tnt in bank?
+ if ((context.faction.getTnt() < getFactionTnt)) {
+ context.fPlayer.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString());
return;
}
- }
-
- msg(TL.COMMAND_TNTFILL_HEADER);
- int radius = argAsInt(0, 16);
- int amount = argAsInt(1, 16);
- if (radius > P.p.getConfig().getInt("Tntfill.max-radius")) {
- fme.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", P.p.getConfig().getInt("Tntfill.max-radius") + ""));
- return;
+ // Take TNT from the bank.
+ removeFromBank(context, getFactionTnt);
}
- if (amount > P.p.getConfig().getInt("Tntfill.max-amount")) {
- fme.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", P.p.getConfig().getInt("Tntfill.max-amount") + ""));
- return;
- }
-
- try {
- Integer.parseInt(args.get(1));
- } catch (NumberFormatException e) {
- fme.msg(TL.COMMAND_TNT_INVALID_NUM);
- return;
- }
- if (amount < 0) {
- fme.msg(TL.COMMAND_TNT_POSITIVE);
- return;
- }
- boolean bankMode = fme.getRole().isAtLeast(Role.MODERATOR);
- Location start = me.getLocation();
- int counter = 0;
- for (double x = start.getX() - radius; x <= start.getX() + radius; x++) {
- for (double y = start.getY() - radius; y <= start.getY() + radius; y++) {
- for (double z = start.getZ() - radius; z <= start.getZ() + radius; z++) {
- Location blockLoc = new Location(start.getWorld(), x, y, z);
- if (blockLoc.getBlock().getState() instanceof Dispenser) {
- Dispenser disp = (Dispenser) blockLoc.getBlock().getState();
- Inventory dispenser = disp.getInventory();
- if (canHold(dispenser, amount)) {
- int fullStacks = amount / 64;
- int remainderAmt = amount % 64;
- if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT, amount))) {
- if (!fme.getRole().isAtLeast(Role.MODERATOR)) {
- fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
- sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
- me.updateInventory();
- return;
- } else if (bankMode) {
- //msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}",fme.getRole().nicename));
- bankMode = true;
- removeFromBank(amount);
- if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT, amount))) {
- fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
- sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
- me.updateInventory();
- return;
- }
- }
- }
- ItemStack tnt64 = new ItemStack(Material.TNT, 64);
- for (int i = 0; i <= fullStacks - 1; i++) {
- dispenser.addItem(tnt64);
- takeTnt(64);
- }
- if (remainderAmt != 0) {
- ItemStack tnt = new ItemStack(Material.TNT, remainderAmt);
- dispenser.addItem(tnt);
- takeTnt(remainderAmt);
- }
- counter++;
- }
- }
- }
- }
- }
- if (bankMode) {
- msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}", fme.getRole().nicename));
- }
- sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
- me.updateInventory();
+ fillDispensers(context.fPlayer, opDispensers, amount);
+ // Remove used TNT from player inventory.
+ context.sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", requiredTnt + "").replace("{dispensers}", opDispensers.size() + ""));
}
- private void removeFromBank(int amount) {
+ // Actually fill every dispenser with the precise amount.
+ private void fillDispensers(FPlayer fPlayer, List dispensers, int count) {
+ for (Dispenser dispenser : dispensers) {
+ takeTnt(fPlayer, count);
+ dispenser.getInventory().addItem(new ItemStack(Material.TNT, count));
+ }
+ }
+
+ private void removeFromBank(CommandContext context, int amount) {
try {
- Integer.parseInt(args.get(1));
+ Integer.parseInt(context.args.get(1));
} catch (NumberFormatException e) {
- fme.msg(TL.COMMAND_TNT_INVALID_NUM);
+ context.fPlayer.msg(TL.COMMAND_TNT_INVALID_NUM.toString());
return;
}
if (amount < 0) {
- fme.msg(TL.COMMAND_TNT_POSITIVE);
+ context.fPlayer.msg(TL.COMMAND_TNT_POSITIVE.toString());
return;
}
- if (fme.getFaction().getTnt() < amount) {
- fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
+ if (context.faction.getTnt() < amount) {
+ context.fPlayer.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString());
return;
}
int fullStacks = amount / 64;
int remainderAmt = amount % 64;
- if ((remainderAmt == 0 && getEmptySlots(me) <= fullStacks)) {
- fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
+ if ((remainderAmt == 0 && getEmptySlots(context.player) <= fullStacks)) {
+ context.fPlayer.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString());
return;
}
- if (getEmptySlots(me) + 1 <= fullStacks) {
- fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
+ if (getEmptySlots(context.player) + 1 <= fullStacks) {
+ context.fPlayer.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString());
return;
}
ItemStack tnt64 = new ItemStack(Material.TNT, 64);
for (int i = 0; i <= fullStacks - 1; i++) {
- me.getInventory().addItem(tnt64);
+ context.player.getInventory().addItem(tnt64);
}
if (remainderAmt != 0) {
ItemStack tnt = new ItemStack(Material.TNT, remainderAmt);
- me.getInventory().addItem(tnt);
+ context.player.getInventory().addItem(tnt);
}
- fme.getFaction().takeTnt(amount);
- me.updateInventory();
+ context.faction.takeTnt(amount);
+ context.player.updateInventory();
}
- public void takeTnt(int amount) {
- Inventory inv = me.getInventory();
+ private void takeTnt(FPlayer fme, int amount) {
+ Inventory inv = fme.getPlayer().getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
if (inv.getItem(i) == null) {
@@ -174,46 +172,27 @@ public class CmdTntFill extends FCommand {
}
}
if (amount > invTnt) {
- fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH);
+ fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
return;
}
ItemStack tnt = new ItemStack(Material.TNT, amount);
- if (fme.getFaction().getTnt() + amount > P.p.getConfig().getInt("ftnt.Bank-Limit")) {
- msg(TL.COMMAND_TNT_EXCEEDLIMIT);
+ if (fme.getFaction().getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
+ fme.msg(TL.COMMAND_TNT_EXCEEDLIMIT.toString());
return;
}
- removeFromInventory(me.getInventory(), tnt);
+ removeFromInventory(fme.getPlayer().getInventory(), tnt);
}
- public boolean canHold(Inventory inventory, int amount) {
- int fullStacks = amount / 64;
- int remainderAmt = amount % 64;
- if ((remainderAmt == 0 && getEmptySlots(me) <= fullStacks)) {
- return false;
- }
- if (getEmptySlots(me) + 1 <= fullStacks) {
- fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
- return false;
- }
- return true;
- }
-
- public boolean inventoryContains(Inventory inventory, ItemStack item) {
+ // Counts the item type available in the inventory.
+ private int inventoryItemCount(Inventory inventory, Material mat) {
int count = 0;
- ItemStack[] items = inventory.getContents();
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) {
- count += items[i].getAmount();
- }
- if (count >= item.getAmount()) {
- return true;
- }
- }
- return false;
+ HashMap items = inventory.all(mat);
+ for (int item : items.keySet())
+ count += inventory.getItem(item).getAmount();
+ return count;
}
-
- public void removeFromInventory(Inventory inventory, ItemStack item) {
+ private void removeFromInventory(Inventory inventory, ItemStack item) {
int amt = item.getAmount();
ItemStack[] items = inventory.getContents();
for (int i = 0; i < items.length; i++) {
@@ -233,7 +212,7 @@ public class CmdTntFill extends FCommand {
inventory.setContents(items);
}
- public int getEmptySlots(Player p) {
+ private int getEmptySlots(Player p) {
PlayerInventory inventory = p.getInventory();
ItemStack[] cont = inventory.getContents();
int i = 0;
@@ -248,4 +227,5 @@ public class CmdTntFill extends FCommand {
public TL getUsageTranslation() {
return TL.COMMAND_TNTFILL_DESCRIPTION;
}
+
}
\ No newline at end of file
diff --git a/src/main/java/com/massivecraft/factions/integration/Econ.java b/src/main/java/com/massivecraft/factions/integration/Econ.java
index 216163a3..d499542b 100644
--- a/src/main/java/com/massivecraft/factions/integration/Econ.java
+++ b/src/main/java/com/massivecraft/factions/integration/Econ.java
@@ -3,7 +3,7 @@ package com.massivecraft.factions.integration;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
@@ -35,24 +35,24 @@ public class Econ {
String integrationFail = "Economy integration is " + (Conf.econEnabled ? "enabled, but" : "disabled, and") + " the plugin \"Vault\" ";
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
- P.p.log(integrationFail + "is not installed.");
+ FactionsPlugin.getInstance().log(integrationFail + "is not installed.");
return;
}
RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
- P.p.log(integrationFail + "is not hooked into an economy plugin.");
+ FactionsPlugin.getInstance().log(integrationFail + "is not hooked into an economy plugin.");
return;
}
econ = rsp.getProvider();
- P.p.log("Economy integration through Vault plugin successful.");
+ FactionsPlugin.getInstance().log("Economy integration through Vault plugin successful.");
if (!Conf.econEnabled) {
- P.p.log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true");
+ FactionsPlugin.getInstance().log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true");
}
- P.p.cmdBase.cmdHelp.updateHelp();
+ //FactionsPlugin.getInstance().cmdBase.cmdHelp.updateHelp();
}
public static boolean shouldBeUsed() {
@@ -83,7 +83,7 @@ public class Econ {
public static void sendBalanceInfo(CommandSender to, Faction about) {
if (!shouldBeUsed()) {
- P.p.log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin.");
+ FactionsPlugin.getInstance().log(Level.WARNING, "Vault does not appear to be hooked into an economy plugin.");
return;
}
to.sendMessage(String.format("%s's balance is %s.", about.getTag(), Econ.moneyString(econ.getBalance(about.getAccountId()))));
diff --git a/src/main/java/com/massivecraft/factions/integration/Worldguard.java b/src/main/java/com/massivecraft/factions/integration/Worldguard.java
index 2718b3c5..457f2a7d 100644
--- a/src/main/java/com/massivecraft/factions/integration/Worldguard.java
+++ b/src/main/java/com/massivecraft/factions/integration/Worldguard.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.integration;
import com.massivecraft.factions.FLocation;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
@@ -38,11 +38,11 @@ public class Worldguard {
if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) {
enabled = false;
wg = null;
- P.p.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
+ FactionsPlugin.getInstance().log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
} else {
wg = (WorldGuardPlugin) wgplug;
enabled = true;
- P.p.log("Successfully hooked to WorldGuard.");
+ FactionsPlugin.getInstance().log("Successfully hooked to WorldGuard.");
}
}
diff --git a/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java
index a4774969..120c8564 100644
--- a/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java
+++ b/src/main/java/com/massivecraft/factions/integration/dynmap/EngineDynmap.java
@@ -113,7 +113,7 @@ public class EngineDynmap {
}
// Shedule non thread safe sync at the end!
- Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> {
+ Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> {
final Map homes = createHomes();
final Map areas = createAreas();
diff --git a/src/main/java/com/massivecraft/factions/listeners/EssentialsHomeHandler.java b/src/main/java/com/massivecraft/factions/listeners/EssentialsHomeHandler.java
index fa173c14..61ea94f5 100644
--- a/src/main/java/com/massivecraft/factions/listeners/EssentialsHomeHandler.java
+++ b/src/main/java/com/massivecraft/factions/listeners/EssentialsHomeHandler.java
@@ -5,7 +5,7 @@ import com.earth2me.essentials.User;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
@@ -37,7 +37,7 @@ public class EssentialsHomeHandler implements Listener {
Faction factionAt = Board.getInstance().getFactionAt(floc);
if (factionAt.equals(faction) && factionAt.isNormal()) {
user.delHome(homeName);
- P.p.log(Level.INFO, "FactionLeaveEvent: Removing home %s, player %s, in territory of %s", homeName, event.getfPlayer().getName(), faction.getTag());
+ FactionsPlugin.getInstance().log(Level.INFO, "FactionLeaveEvent: Removing home %s, player %s, in territory of %s", homeName, event.getfPlayer().getName(), faction.getTag());
}
}
}
diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java
index e1029648..9accabe8 100644
--- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java
+++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java
@@ -87,7 +87,7 @@ public class FactionsBlockListener implements Listener {
return false;
} else if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own
- if (P.p.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
return true;
// Get faction pain build access relation to me
boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
@@ -215,7 +215,7 @@ public class FactionsBlockListener implements Listener {
@EventHandler
public void onVaultPlace(BlockPlaceEvent e) {
if (e.getItemInHand().getType() == Material.CHEST) {
- ItemStack vault = P.p.createItem(Material.CHEST, 1, (short) 0, P.p.color(P.p.getConfig().getString("fvault.Item.Name")), P.p.colorList(P.p.getConfig().getStringList("fvault.Item.Lore")));
+ ItemStack vault = FactionsPlugin.getInstance().createItem(Material.CHEST, 1, (short) 0, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fvault.Item.Name")), FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fvault.Item.Lore")));
if (e.getItemInHand().isSimilar(vault)) {
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
if (fme.getFaction().getVault() != null) {
@@ -241,7 +241,7 @@ public class FactionsBlockListener implements Listener {
Material blockMaterial = blockLoc.getBlock().getType();
- if (blockMaterial == Material.CHEST || (P.p.getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) {
+ if (blockMaterial == Material.CHEST || (FactionsPlugin.getInstance().getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) {
e.setCancelled(true);
fme.msg(TL.COMMAND_GETVAULT_CHESTNEAR);
return;
@@ -260,7 +260,7 @@ public class FactionsBlockListener implements Listener {
@EventHandler
public void onHopperPlace(BlockPlaceEvent e) {
- if (e.getItemInHand().getType() != Material.HOPPER && !P.p.getConfig().getBoolean("fvault.No-Hoppers-near-vault")) {
+ if (e.getItemInHand().getType() != Material.HOPPER && !FactionsPlugin.getInstance().getConfig().getBoolean("fvault.No-Hoppers-near-vault")) {
return;
}
@@ -310,7 +310,7 @@ public class FactionsBlockListener implements Listener {
Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(targetLoc));
// Check if the piston is moving in a faction's territory. This disables pistons entirely in faction territory.
- if (otherFaction.isNormal() && P.p.getConfig().getBoolean("disable-pistons-in-territory", false)) {
+ if (otherFaction.isNormal() && FactionsPlugin.getInstance().getConfig().getBoolean("disable-pistons-in-territory", false)) {
event.setCancelled(true);
return;
}
@@ -329,7 +329,7 @@ public class FactionsBlockListener implements Listener {
@EventHandler
public void onBannerPlace(BlockPlaceEvent e) {
- if (P.p.mc17) {
+ if (FactionsPlugin.getInstance().mc17) {
return;
}
if (e.getItemInHand().getType().name().contains("BANNER")) {
@@ -340,8 +340,8 @@ public class FactionsBlockListener implements Listener {
return;
}
ItemMeta warmeta = warBanner.getItemMeta();
- warmeta.setDisplayName(P.p.color(P.p.getConfig().getString("fbanners.Item.Name")));
- warmeta.setLore(P.p.colorList(P.p.getConfig().getStringList("fbanners.Item.Lore")));
+ warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name")));
+ warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")));
warBanner.setItemMeta(warmeta);
if (warBanner.isSimilar(bannerInHand)) {
if (fme.getFaction().isWilderness()) {
@@ -349,10 +349,10 @@ public class FactionsBlockListener implements Listener {
e.setCancelled(true);
return;
}
- int bannerTime = P.p.getConfig().getInt("fbanners.Banner-Time") * 20;
+ int bannerTime = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Time") * 20;
Location placedLoc = e.getBlockPlaced().getLocation();
FLocation fplacedLoc = new FLocation(placedLoc);
- if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && P.p.getConfig().getBoolean("fbanners.Placeable.Warzone")) || (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY && P.p.getConfig().getBoolean("fbanners.Placeable.Enemy"))) {
+ if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Warzone")) || (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Enemy"))) {
if (bannerCooldownMap.containsKey(fme.getTag())) {
fme.msg(TL.WARBANNER_COOLDOWN);
e.setCancelled(true);
@@ -360,29 +360,29 @@ public class FactionsBlockListener implements Listener {
}
for (FPlayer fplayer : fme.getFaction().getFPlayers()) {
if (XMaterial.isVersionOrHigher(XMaterial.MinecraftVersion.VERSION_1_9)) {
- fplayer.getPlayer().sendTitle(P.p.color(fme.getTag() + " Placed A WarBanner!"), P.p.color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20);
+ fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20);
} else {
- fplayer.getPlayer().sendTitle(P.p.color(fme.getTag() + " Placed A WarBanner!"), P.p.color("&7use &c/f tpbanner&7 to tp to the banner!"));
+ fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!"));
}
}
bannerCooldownMap.put(fme.getTag(), true);
FactionsBlockListener.bannerLocations.put(fme.getTag(), e.getBlockPlaced().getLocation());
- int bannerCooldown = P.p.getConfig().getInt("fbanners.Banner-Place-Cooldown");
+ int bannerCooldown = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Place-Cooldown");
ArmorStand as = (ArmorStand) e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5).getWorld().spawnEntity(e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5), EntityType.ARMOR_STAND);
as.setVisible(false);
as.setGravity(false);
as.setCanPickupItems(false);
- as.setCustomName(P.p.color(P.p.getConfig().getString("fbanners.BannerHolo").replace("{Faction}", fme.getTag())));
+ as.setCustomName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.BannerHolo").replace("{Faction}", fme.getTag())));
as.setCustomNameVisible(true);
String tag = fme.getTag();
- Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + ""));
+ Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + ""));
Block banner = e.getBlockPlaced();
Material bannerType = banner.getType();
Faction bannerFaction = fme.getFaction();
banner.getWorld().strikeLightningEffect(banner.getLocation());
- int radius = P.p.getConfig().getInt("fbanners.Banner-Effect-Radius");
- List effects = P.p.getConfig().getStringList("fbanners.Effects");
- int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> {
+ int radius = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Effect-Radius");
+ List effects = FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Effects");
+ int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> {
for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), (double) radius, 255.0, (double) radius)) {
if (e1 instanceof Player) {
Player player = (Player) e1;
@@ -403,7 +403,7 @@ public class FactionsBlockListener implements Listener {
}
}
}, 0L, 20L);
- Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> {
+ Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> {
banner.setType(Material.AIR);
as.remove();
banner.getWorld().strikeLightningEffect(banner.getLocation());
@@ -442,7 +442,7 @@ public class FactionsBlockListener implements Listener {
@EventHandler
public void onFallingBlock(EntityChangeBlockEvent event) {
- if (!P.p.getConfig().getBoolean("Falling-Block-Fix.Enabled"))
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("Falling-Block-Fix.Enabled"))
return;
Faction faction = Board.getInstance().getFactionAt(new FLocation(event.getBlock()));
@@ -455,7 +455,7 @@ public class FactionsBlockListener implements Listener {
//Grace
@EventHandler
public void onBreak(EntityExplodeEvent e) {
- if (!P.p.getConfig().getBoolean("f-grace.Enabled"))
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled"))
return;
if (!graceisEnabled()) {
@@ -465,7 +465,7 @@ public class FactionsBlockListener implements Listener {
@EventHandler
public void entityDamage(EntityDamageEvent e) {
- if (!P.p.getConfig().getBoolean("f-grace.Enabled"))
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled"))
return;
if (!graceisEnabled()) {
@@ -480,7 +480,7 @@ public class FactionsBlockListener implements Listener {
@EventHandler
public void onTNTPlace(BlockPlaceEvent e1) {
FPlayer fp = FPlayers.getInstance().getByPlayer(e1.getPlayer());
- if (!P.p.getConfig().getBoolean("f-grace.Enabled"))
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled"))
return;
if (!graceisEnabled() && !fp.isAdminBypassing()) {
@@ -547,4 +547,4 @@ public class FactionsBlockListener implements Listener {
}
}
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java
index 8a25f56f..4b8227cb 100644
--- a/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java
+++ b/src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java
@@ -180,9 +180,9 @@ public class FactionsChatListener implements Listener {
listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
} catch (UnknownFormatConversionException ex) {
Conf.chatTagInsertIndex = 0;
- P.p.log(Level.SEVERE, "Critical error in chat message formatting!");
- P.p.log(Level.SEVERE, "NOTE: This has been automatically fixed right now by setting chatTagInsertIndex to 0.");
- P.p.log(Level.SEVERE, "For a more proper fix, please read this regarding chat configuration: http://massivecraft.com/plugins/factions/config#Chat_configuration");
+ FactionsPlugin.getInstance().log(Level.SEVERE, "Critical error in chat message formatting!");
+ FactionsPlugin.getInstance().log(Level.SEVERE, "NOTE: This has been automatically fixed right now by setting chatTagInsertIndex to 0.");
+ FactionsPlugin.getInstance().log(Level.SEVERE, "For a more proper fix, please read this regarding chat configuration: http://massivecraft.com/plugins/factions/config#Chat_configuration");
return;
}
}
@@ -202,7 +202,7 @@ public class FactionsChatListener implements Listener {
player.teleport(fme.getFaction().getWarp(warp).getLocation());
fme.msg(TL.COMMAND_FWARP_WARPED, warp);
}
- }, P.p.getConfig().getLong("warmups.f-warp", 0));
+ }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-warp", 0));
}
}
\ No newline at end of file
diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java
index e1d709ed..1d8daa28 100644
--- a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java
+++ b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java
@@ -226,9 +226,9 @@ public class FactionsEntityListener implements Listener {
return;
}
UUID uuid = player.getUniqueId();
- if (P.p.getStuckMap().containsKey(uuid)) {
+ if (FactionsPlugin.getInstance().getStuckMap().containsKey(uuid)) {
FPlayers.getInstance().getByPlayer(player).msg(TL.COMMAND_STUCK_CANCELLED);
- P.p.getStuckMap().remove(uuid);
+ FactionsPlugin.getInstance().getStuckMap().remove(uuid);
}
}
@@ -644,7 +644,7 @@ public class FactionsEntityListener implements Listener {
@EventHandler
public void onTravel(PlayerPortalEvent event) {
- if (!P.p.getConfig().getBoolean("portals.limit", false)) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("portals.limit", false)) {
return; // Don't do anything if they don't want us to.
}
@@ -663,7 +663,7 @@ public class FactionsEntityListener implements Listener {
}
FPlayer fp = FPlayers.getInstance().getByPlayer(event.getPlayer());
- String mininumRelation = P.p.getConfig().getString("portals.minimum-relation", "MEMBER"); // Defaults to Neutral if typed wrong.
+ String mininumRelation = FactionsPlugin.getInstance().getConfig().getString("portals.minimum-relation", "MEMBER"); // Defaults to Neutral if typed wrong.
if (!fp.getFaction().getRelationTo(faction).isAtLeast(Relation.fromString(mininumRelation))) {
event.setCancelled(true);
}
diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsExploitListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsExploitListener.java
index 30081750..7804cc73 100644
--- a/src/main/java/com/massivecraft/factions/listeners/FactionsExploitListener.java
+++ b/src/main/java/com/massivecraft/factions/listeners/FactionsExploitListener.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.listeners;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -30,7 +30,7 @@ public class FactionsExploitListener implements Listener {
Block block = event.getToBlock();
// Added this so it wont die on 1.14 :)
- if (P.p.mc114) {
+ if (FactionsPlugin.getInstance().mc114) {
Material source = event.getBlock().getType();
Material target = block.getType();
if ((target == Material.REDSTONE_WIRE || target == Material.TRIPWIRE) && (source == Material.AIR || source == Material.LEGACY_STATIONARY_LAVA || source == Material.LEGACY_LAVA)) {
diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java
index d0eac9ea..918b5e77 100644
--- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java
+++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java
@@ -55,10 +55,10 @@ public class FactionsPlayerListener implements Listener {
public FactionsPlayerListener() {
this.corners = new HashSet<>();
- for (Player player : P.p.getServer().getOnlinePlayers()) {
+ for (Player player : FactionsPlugin.getInstance().getServer().getOnlinePlayers()) {
initPlayer(player);
}
- for (World world : P.p.getServer().getWorlds()) {
+ for (World world : FactionsPlugin.getInstance().getServer().getWorlds()) {
WorldBorder border = world.getWorldBorder();
if (border != null) {
int cornerCoord = (int) ((border.getSize() - 1.0) / 2.0);
@@ -103,7 +103,7 @@ public class FactionsPlayerListener implements Listener {
if (me.getFaction() == otherFaction) return true;
- if (P.p.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) {
return true;
}
@@ -185,7 +185,7 @@ public class FactionsPlayerListener implements Listener {
return false;
}
- if (P.p.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
return true;
if (otherFaction.getId().equals(myFaction.getId()) && me.getRole() == Role.LEADER) return true;
@@ -345,7 +345,7 @@ public class FactionsPlayerListener implements Listener {
return PermissableAction.DOOR;
if (material.name().toUpperCase().contains("BUTTON") || material.name().toUpperCase().contains("PRESSURE"))
return PermissableAction.BUTTON;
- if (P.p.mc113) {
+ if (FactionsPlugin.getInstance().mc113) {
switch (material) {
case LEVER:
return PermissableAction.LEVER;
@@ -477,15 +477,15 @@ public class FactionsPlayerListener implements Listener {
me.login(); // set kills / deaths
// Check for Faction announcements. Let's delay this so they actually see it.
- Bukkit.getScheduler().runTaskLater(P.p, () -> {
+ Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> {
if (me.isOnline()) {
me.getFaction().sendUnreadAnnouncements(me);
}
}, 33L); // Don't ask me why.
- if (P.p.getConfig().getBoolean("scoreboard.default-enabled", false)) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-enabled", false)) {
FScoreboard.init(me);
- FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar(), P.p.getConfig().getInt("scoreboard.default-update-interval", 20));
+ FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar(), FactionsPlugin.getInstance().getConfig().getInt("scoreboard.default-update-interval", 20));
FScoreboard.get(me).setSidebarVisibility(me.showScoreboard());
}
@@ -500,17 +500,17 @@ public class FactionsPlayerListener implements Listener {
fallMap.put(me.getPlayer(), false);
- Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> fallMap.remove(me.getPlayer()), 180L);
+ Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> fallMap.remove(me.getPlayer()), 180L);
if (me.isSpyingChat() && !player.hasPermission(Permission.CHATSPY.node)) {
me.setSpyingChat(false);
- P.p.log(Level.INFO, "Found %s spying chat without permission on login. Disabled their chat spying.", player.getName());
+ FactionsPlugin.getInstance().log(Level.INFO, "Found %s spying chat without permission on login. Disabled their chat spying.", player.getName());
}
if (me.isAdminBypassing() && !player.hasPermission(Permission.BYPASS.node)) {
me.setIsAdminBypassing(false);
- P.p.log(Level.INFO, "Found %s on admin Bypass without permission on login. Disabled it for them.", player.getName());
+ FactionsPlugin.getInstance().log(Level.INFO, "Found %s on admin Bypass without permission on login. Disabled it for them.", player.getName());
}
@@ -544,10 +544,10 @@ public class FactionsPlayerListener implements Listener {
me.logout(); // cache kills / deaths
// if player is waiting for fstuck teleport but leaves, remove
- if (P.p.getStuckMap().containsKey(me.getPlayer().getUniqueId())) {
+ if (FactionsPlugin.getInstance().getStuckMap().containsKey(me.getPlayer().getUniqueId())) {
FPlayers.getInstance().getByPlayer(me.getPlayer()).msg(TL.COMMAND_STUCK_CANCELLED);
- P.p.getStuckMap().remove(me.getPlayer().getUniqueId());
- P.p.getTimers().remove(me.getPlayer().getUniqueId());
+ FactionsPlugin.getInstance().getStuckMap().remove(me.getPlayer().getUniqueId());
+ FactionsPlugin.getInstance().getTimers().remove(me.getPlayer().getUniqueId());
}
Faction myFaction = me.getFaction();
@@ -584,11 +584,11 @@ public class FactionsPlayerListener implements Listener {
public void enableFly(FPlayer me) {
if (!me.getPlayer().hasPermission("factions.fly")) return;
- if (P.p.getConfig().getBoolean("ffly.AutoEnable")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("ffly.AutoEnable")) {
me.setFlying(true);
CmdFly.flyMap.put(me.getName(), true);
if (CmdFly.id == -1) {
- if (P.p.getConfig().getBoolean("ffly.Particles.Enabled")) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("ffly.Particles.Enabled")) {
CmdFly.startParticles();
}
}
@@ -702,25 +702,25 @@ public class FactionsPlayerListener implements Listener {
if (changedFaction) {
Bukkit.getServer().getPluginManager().callEvent(new FPlayerEnteredFactionEvent(factionTo, factionFrom, me));
- if (P.p.getConfig().getBoolean("Title.Show-Title")) {
- String title = P.p.getConfig().getString("Title.Format.Title");
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("Title.Show-Title")) {
+ String title = FactionsPlugin.getInstance().getConfig().getString("Title.Format.Title");
title = title.replace("{Faction}", factionTo.getColorTo(me) + factionTo.getTag());
title = parseAllPlaceholders(title, factionTo, player);
- String subTitle = P.p.getConfig().getString("Title.Format.Subtitle").replace("{Description}", factionTo.getDescription()).replace("{Faction}", factionTo.getColorTo(me) + factionTo.getTag());
+ String subTitle = FactionsPlugin.getInstance().getConfig().getString("Title.Format.Subtitle").replace("{Description}", factionTo.getDescription()).replace("{Faction}", factionTo.getColorTo(me) + factionTo.getTag());
subTitle = parseAllPlaceholders(subTitle, factionTo, player);
- if (!P.p.mc17) {
- if (!P.p.mc18) {
- me.getPlayer().sendTitle(P.p.color(title), P.p.color(subTitle), P.p.getConfig().getInt("Title.Options.FadeInTime"),
- P.p.getConfig().getInt("Title.Options.ShowTime"),
- P.p.getConfig().getInt("Title.Options.FadeOutTime"));
+ if (!FactionsPlugin.getInstance().mc17) {
+ if (!FactionsPlugin.getInstance().mc18) {
+ me.getPlayer().sendTitle(FactionsPlugin.getInstance().color(title), FactionsPlugin.getInstance().color(subTitle), FactionsPlugin.getInstance().getConfig().getInt("Title.Options.FadeInTime"),
+ FactionsPlugin.getInstance().getConfig().getInt("Title.Options.ShowTime"),
+ FactionsPlugin.getInstance().getConfig().getInt("Title.Options.FadeOutTime"));
} else {
- me.getPlayer().sendTitle(P.p.color(title), P.p.color(subTitle));
+ me.getPlayer().sendTitle(FactionsPlugin.getInstance().color(title), FactionsPlugin.getInstance().color(subTitle));
}
}
}
// enable fly :)
- if (P.p.factionsFlight && me.hasFaction() && !me.isFlying()) {
+ if (FactionsPlugin.getInstance().factionsFlight && me.hasFaction() && !me.isFlying()) {
if (factionTo == me.getFaction()) enableFly(me);
// bypass checks
Relation relationTo = factionTo.getRelationTo(me);
@@ -761,12 +761,12 @@ public class FactionsPlayerListener implements Listener {
if (me.isMapAutoUpdating()) {
if (showTimes.containsKey(player.getUniqueId()) && (showTimes.get(player.getUniqueId()) > System.currentTimeMillis())) {
- if (P.p.getConfig().getBoolean("findfactionsexploit.log", false)) {
- P.p.log(Level.WARNING, "%s tried to show a faction map too soon and triggered exploit blocker.", player.getName());
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("findfactionsexploit.log", false)) {
+ FactionsPlugin.getInstance().log(Level.WARNING, "%s tried to show a faction map too soon and triggered exploit blocker.", player.getName());
}
} else {
me.sendFancyMessage(Board.getInstance().getMap(me, to, player.getLocation().getYaw()));
- showTimes.put(player.getUniqueId(), System.currentTimeMillis() + P.p.getConfig().getLong("findfactionsexploit.cooldown", 2000));
+ showTimes.put(player.getUniqueId(), System.currentTimeMillis() + FactionsPlugin.getInstance().getConfig().getLong("findfactionsexploit.cooldown", 2000));
}
} else {
Faction myFaction = me.getFaction();
@@ -805,7 +805,9 @@ public class FactionsPlayerListener implements Listener {
Player player = event.getPlayer();
// Check if the material is bypassing protection
if (block == null) return; // clicked in air, apparently
- if (Conf.territoryBypassProtectedMaterials.contains(event.getItem().getType())) return;
+ if(event.getItem() != null) {
+ if (Conf.territoryBypassProtectedMaterials.contains(event.getItem().getType())) return;
+ }
if (GetPermissionFromUsableBlock(event.getClickedBlock().getType()) != null) {
if (!canPlayerUseBlock(player, block, false)) {
event.setCancelled(true);
diff --git a/src/main/java/com/massivecraft/factions/missions/CmdMissions.java b/src/main/java/com/massivecraft/factions/missions/CmdMissions.java
index 1513e63a..6b816121 100644
--- a/src/main/java/com/massivecraft/factions/missions/CmdMissions.java
+++ b/src/main/java/com/massivecraft/factions/missions/CmdMissions.java
@@ -1,5 +1,8 @@
package com.massivecraft.factions.missions;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@@ -12,28 +15,24 @@ public class CmdMissions extends FCommand {
this.aliases.add("objectives");
this.aliases.add("objective");
- this.permission = Permission.MISSIONS.node;
-
- this.disableOnLock = true;
- this.disableOnSpam = true;
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.MISSIONS)
+ .memberOnly()
+ .playerOnly()
+ .build();
}
@Override
- public void perform() {
- if (myFaction == null) {
+ public void perform(CommandContext context) {
+ if (context.faction == null) {
return;
}
- final MissionGUI missionsGUI = new MissionGUI(p, fme);
+ final MissionGUI missionsGUI = new MissionGUI(FactionsPlugin.getInstance(), context.fPlayer);
missionsGUI.build();
- fme.getPlayer().openInventory(missionsGUI.getInventory());
+ context.player.openInventory(missionsGUI.getInventory());
}
+
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MISSION_DESCRIPTION;
diff --git a/src/main/java/com/massivecraft/factions/missions/MissionGUI.java b/src/main/java/com/massivecraft/factions/missions/MissionGUI.java
index fde9db12..3e5163a6 100644
--- a/src/main/java/com/massivecraft/factions/missions/MissionGUI.java
+++ b/src/main/java/com/massivecraft/factions/missions/MissionGUI.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.missions;
import com.massivecraft.factions.FPlayer;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.FactionGUI;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
@@ -20,12 +20,12 @@ import java.util.List;
import java.util.Map;
public class MissionGUI implements FactionGUI {
- private P plugin;
+ private FactionsPlugin plugin;
private FPlayer fPlayer;
private Inventory inventory;
private Map slots;
- public MissionGUI(P plugin, FPlayer fPlayer) {
+ public MissionGUI(FactionsPlugin plugin, FPlayer fPlayer) {
this.slots = new HashMap<>();
this.plugin = plugin;
this.fPlayer = fPlayer;
diff --git a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java
index 771e3c61..c06770f1 100644
--- a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java
+++ b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java
@@ -2,9 +2,11 @@ package com.massivecraft.factions.missions;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -12,6 +14,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityBreedEvent;
import org.bukkit.event.entity.EntityDeathEvent;
+import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.player.PlayerFishEvent;
import java.util.List;
@@ -19,9 +22,9 @@ import java.util.stream.Collectors;
public class MissionHandler implements Listener {
- private P plugin;
+ private FactionsPlugin plugin;
- public MissionHandler(P plugin) {
+ public MissionHandler(FactionsPlugin plugin) {
this.plugin = plugin;
}
@@ -116,12 +119,32 @@ public class MissionHandler implements Listener {
}
}
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPlayerTame(EntityTameEvent event) {
+ if (!(event.getOwner() instanceof Player)) {
+ return;
+ }
+ FPlayer fPlayer = FPlayers.getInstance().getByPlayer((Player)event.getOwner());
+ if (fPlayer == null) {
+ return;
+ }
+ List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("tame")).collect(Collectors.toList());
+ for (Mission mission2 : missions) {
+ ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName());
+ if (!event.getEntityType().toString().equals(section.getConfigurationSection("Mission").getString("EntityType"))) {
+ continue;
+ }
+ mission2.incrementProgress();
+ checkIfDone(fPlayer, mission2, section);
+ }
+ }
+
private void checkIfDone(FPlayer fPlayer, Mission mission, ConfigurationSection section) {
if (mission.getProgress() < section.getConfigurationSection("Mission").getLong("Amount")) {
return;
}
for (String command : section.getConfigurationSection("Reward").getStringList("Commands")) {
- P.p.getServer().dispatchCommand(P.p.getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag()));
+ FactionsPlugin.getInstance().getServer().dispatchCommand(FactionsPlugin.getInstance().getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag()));
}
fPlayer.getFaction().getMissions().remove(mission.getName());
fPlayer.getFaction().msg(TL.MISSION_MISSION_FINISHED, plugin.color(section.getString("Name")));
diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java b/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java
index 2225137a..58c5d269 100644
--- a/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java
+++ b/src/main/java/com/massivecraft/factions/scoreboards/FScoreboard.java
@@ -2,7 +2,7 @@ package com.massivecraft.factions.scoreboards;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@@ -109,7 +109,7 @@ public class FScoreboard {
updateObjective();
}
}
- }.runTaskTimer(P.p, updateInterval, updateInterval);
+ }.runTaskTimer(FactionsPlugin.getInstance(), updateInterval, updateInterval);
}
public void setTemporarySidebar(final FSidebarProvider provider) {
@@ -132,7 +132,7 @@ public class FScoreboard {
updateObjective();
}
}
- }.runTaskLater(P.p, P.p.getConfig().getInt("scoreboard.expiration", 7) * 20);
+ }.runTaskLater(FactionsPlugin.getInstance(), FactionsPlugin.getInstance().getConfig().getInt("scoreboard.expiration", 7) * 20);
}
private void updateObjective() {
diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FSidebarProvider.java b/src/main/java/com/massivecraft/factions/scoreboards/FSidebarProvider.java
index 1a71af86..720df2ac 100644
--- a/src/main/java/com/massivecraft/factions/scoreboards/FSidebarProvider.java
+++ b/src/main/java/com/massivecraft/factions/scoreboards/FSidebarProvider.java
@@ -2,7 +2,7 @@ package com.massivecraft.factions.scoreboards;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagUtil;
@@ -37,6 +37,6 @@ public abstract class FSidebarProvider {
// we assume it's broken up into two lines, so returning our tl will suffice.
return TL.COMMAND_SHOW_NOHOME.toString();
}
- return P.p.txt.parse(line); // finally add color :)
+ return FactionsPlugin.getInstance().txt.parse(line); // finally add color :)
}
}
\ No newline at end of file
diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java b/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java
index 8cde29fa..c91501b0 100644
--- a/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java
+++ b/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java
@@ -39,13 +39,13 @@ public class FTeamWrapper {
return;
}
- if (!P.p.getConfig().getBoolean("scoreboard.default-prefixes", false) || P.p.getConfig().getBoolean("See-Invisible-Faction-Members")) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false) || FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members")) {
return;
}
if (updating.add(faction)) {
- Bukkit.getScheduler().runTask(P.p, () -> {
+ Bukkit.getScheduler().runTask(FactionsPlugin.getInstance(), () -> {
updating.remove(faction);
applyUpdates(faction);
});
@@ -61,7 +61,7 @@ public class FTeamWrapper {
return;
}
- if (!P.p.getConfig().getBoolean("scoreboard.default-prefixes", false) || P.p.getConfig().getBoolean("See-Invisible-Faction-Members")) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false) || FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members")) {
return;
}
@@ -153,7 +153,7 @@ public class FTeamWrapper {
}
private void updatePrefixes() {
- if (P.p.getConfig().getBoolean("scoreboard.default-prefixes", false)) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) {
for (FScoreboard fboard : teams.keySet()) {
updatePrefix(fboard);
}
@@ -161,19 +161,19 @@ public class FTeamWrapper {
}
private void updatePrefix(FScoreboard fboard) {
- if (P.p.getConfig().getBoolean("scoreboard.default-prefixes", false)) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-prefixes", false)) {
FPlayer fplayer = fboard.getFPlayer();
Team team = teams.get(fboard);
boolean focused = false;
- if (P.p.getConfig().getBoolean("See-Invisible-Faction-Members", false)) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("See-Invisible-Faction-Members", false)) {
team.setCanSeeFriendlyInvisibles(true);
}
- if ((P.p.getConfig().getBoolean("ffocus.Enabled")) && (fplayer.getFaction() != null) && (fplayer.getFaction().getFocused() != null)) {
+ if ((FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled")) && (fplayer.getFaction() != null) && (fplayer.getFaction().getFocused() != null)) {
for (FPlayer fp : faction.getFPlayersWhereOnline(true)) {
if (fplayer.getFaction().getFocused().equalsIgnoreCase(fp.getName())) {
- team.setPrefix(ChatColor.translateAlternateColorCodes('&', P.p.getConfig().getString("ffocus.Prefix", "&7»&b")));
+ team.setPrefix(ChatColor.translateAlternateColorCodes('&', FactionsPlugin.getInstance().getConfig().getString("ffocus.Prefix", "&7»&b")));
focused = true;
}
}
diff --git a/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FDefaultSidebar.java b/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FDefaultSidebar.java
index 55e16938..40903582 100644
--- a/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FDefaultSidebar.java
+++ b/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FDefaultSidebar.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.scoreboards.sidebar;
import com.massivecraft.factions.FPlayer;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.scoreboards.FSidebarProvider;
import java.util.ArrayList;
@@ -12,21 +12,21 @@ public class FDefaultSidebar extends FSidebarProvider {
@Override
public String getTitle(FPlayer fplayer) {
- return replaceTags(fplayer, P.p.getConfig().getString("scoreboard.default-title", "{name}"));
+ return replaceTags(fplayer, FactionsPlugin.getInstance().getConfig().getString("scoreboard.default-title", "{name}"));
}
@Override
public List getLines(FPlayer fplayer) {
if (fplayer.hasFaction()) {
return getOutput(fplayer, "scoreboard.default");
- } else if (P.p.getConfig().getBoolean("scoreboard.factionless-enabled", false)) {
+ } else if (FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.factionless-enabled", false)) {
return getOutput(fplayer, "scoreboard.factionless");
}
return getOutput(fplayer, "scoreboard.default"); // no faction, factionless-board disabled
}
public List getOutput(FPlayer fplayer, String list) {
- List lines = P.p.getConfig().getStringList(list);
+ List lines = FactionsPlugin.getInstance().getConfig().getStringList(list);
if (lines == null || lines.isEmpty()) {
return new ArrayList<>();
diff --git a/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FInfoSidebar.java b/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FInfoSidebar.java
index d3752728..56ccbb5f 100644
--- a/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FInfoSidebar.java
+++ b/src/main/java/com/massivecraft/factions/scoreboards/sidebar/FInfoSidebar.java
@@ -2,7 +2,7 @@ package com.massivecraft.factions.scoreboards.sidebar;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.scoreboards.FSidebarProvider;
import java.util.List;
@@ -22,7 +22,7 @@ public class FInfoSidebar extends FSidebarProvider {
@Override
public List getLines(FPlayer fplayer) {
- List lines = P.p.getConfig().getStringList("scoreboard.finfo");
+ List lines = FactionsPlugin.getInstance().getConfig().getStringList("scoreboard.finfo");
ListIterator it = lines.listIterator();
while (it.hasNext()) {
diff --git a/src/main/java/com/massivecraft/factions/shop/CmdShop.java b/src/main/java/com/massivecraft/factions/shop/CmdShop.java
index 3010502b..a795308d 100644
--- a/src/main/java/com/massivecraft/factions/shop/CmdShop.java
+++ b/src/main/java/com/massivecraft/factions/shop/CmdShop.java
@@ -1,7 +1,10 @@
package com.massivecraft.factions.shop;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.cmd.CommandContext;
+import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
+import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdShop extends FCommand {
@@ -9,22 +12,19 @@ public class CmdShop extends FCommand {
public CmdShop() {
super();
this.aliases.add("shop");
- this.disableOnLock = false;
-
- senderMustBePlayer = true;
- senderMustBeMember = true;
- senderMustBeModerator = false;
- senderMustBeColeader = false;
- senderMustBeAdmin = false;
+ this.requirements = new CommandRequirements.Builder(Permission.SHOP)
+ .memberOnly()
+ .playerOnly()
+ .build();
}
@Override
- public void perform() {
- if (!P.p.getConfig().getBoolean("F-Shop.Enabled")) {
+ public void perform(CommandContext context) {
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) {
return;
}
- ShopGUI.openShop(fme);
+ ShopGUI.openShop(context.fPlayer);
}
@Override
diff --git a/src/main/java/com/massivecraft/factions/shop/ShopClickPersistence.java b/src/main/java/com/massivecraft/factions/shop/ShopClickPersistence.java
index 9f874e22..9387b0c9 100644
--- a/src/main/java/com/massivecraft/factions/shop/ShopClickPersistence.java
+++ b/src/main/java/com/massivecraft/factions/shop/ShopClickPersistence.java
@@ -2,7 +2,7 @@ package com.massivecraft.factions.shop;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -41,7 +41,7 @@ public class ShopClickPersistence implements Listener {
public void click(InventoryClickEvent e) {
Inventory i = e.getClickedInventory();
Player p = (Player) e.getWhoClicked();
- FileConfiguration config = P.p.getConfig();
+ FileConfiguration config = FactionsPlugin.getInstance().getConfig();
FPlayer fplayer = FPlayers.getInstance().getByPlayer(p);
if (e.getView().getTitle().equalsIgnoreCase(color(config.getString("F-Shop.GUI.Name")))) {
diff --git a/src/main/java/com/massivecraft/factions/shop/ShopGUI.java b/src/main/java/com/massivecraft/factions/shop/ShopGUI.java
index 449427e7..d5db5891 100644
--- a/src/main/java/com/massivecraft/factions/shop/ShopGUI.java
+++ b/src/main/java/com/massivecraft/factions/shop/ShopGUI.java
@@ -2,7 +2,7 @@ package com.massivecraft.factions.shop;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -23,16 +23,16 @@ public class ShopGUI {
*/
public static void openShop(FPlayer p) {
- FileConfiguration config = P.p.getConfig();
+ FileConfiguration config = FactionsPlugin.getInstance().getConfig();
Faction fac = p.getFaction();
- Inventory i = Bukkit.createInventory(null, P.p.getConfig().getInt("F-Shop.GUI.Size"), color(config.getString("F-Shop.GUI.Name")));
+ Inventory i = Bukkit.createInventory(null, FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Size"), color(config.getString("F-Shop.GUI.Name")));
ItemStack glass = new ItemStack(XMaterial.BLACK_STAINED_GLASS_PANE.parseMaterial(), 1, (short) 7);
ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName(ChatColor.GOLD + " ");
glass.setItemMeta(glassmeta);
- for (int fill = 0; fill < P.p.getConfig().getInt("F-Shop.GUI.Size"); ++fill) {
+ for (int fill = 0; fill < FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Size"); ++fill) {
i.setItem(fill, glass);
}
@@ -59,7 +59,7 @@ public class ShopGUI {
}
countmeta.setLore(colorList(PointInfo));
count.setItemMeta(countmeta);
- i.setItem(P.p.getConfig().getInt("F-Shop.GUI.Information.slot"), count);
+ i.setItem(FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Information.slot"), count);
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
@@ -77,7 +77,7 @@ public class ShopGUI {
if (lore.contains("")) {
meta.setLore(null);
} else {
- meta.setLore(P.p.colorList(lore));
+ meta.setLore(FactionsPlugin.getInstance().colorList(lore));
}
item.setItemMeta(meta);
i.setItem(slot, item);
diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java
index c67a7f3b..125a556a 100644
--- a/src/main/java/com/massivecraft/factions/struct/Permission.java
+++ b/src/main/java/com/massivecraft/factions/struct/Permission.java
@@ -1,6 +1,6 @@
package com.massivecraft.factions.struct;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.command.CommandSender;
public enum Permission {
@@ -18,21 +18,25 @@ public enum Permission {
BYPASS("bypass"),
CHAT("chat"),
CHATSPY("chatspy"),
+ CHECK("check"),
CLAIM("claim"),
CLAIMAT("claimat"),
CLAIM_LINE("claim.line"),
CLAIM_RADIUS("claim.radius"),
CONFIG("config"),
CONVERT("convert"),
+ CONVERTCONFIG("convertconfig"),
CREATE("create"),
CORNER("corner"),
DEFAULTRANK("defaultrank"),
DEINVITE("deinvite"),
+ DELHOME("delhome"),
DESCRIPTION("description"),
DISBAND("disband"),
DISBAND_ANY("disband.any"),
FLY("fly"),
FOCUS("focus"),
+ GLOBALCHAT("globalchat"),
GRACE("grace"),
HELP("help"),
HOME("home"),
@@ -64,6 +68,7 @@ public enum Permission {
MONEY_F2P("money.f2p"),
MONEY_P2F("money.p2f"),
MONITOR_LOGINS("monitorlogins"),
+ NEAR("near"),
NO_BOOM("noboom"),
OPEN("open"),
OWNER("owner"),
@@ -75,6 +80,7 @@ public enum Permission {
PAYPAL("paypal"),
PAYPALSET("setpaypal"),
PERMISSIONS("permissions"),
+ POINTS("points"),
POWERBOOST("powerboost"),
POWER("power"),
POWER_ANY("power.any"),
@@ -101,6 +107,7 @@ public enum Permission {
SCOREBOARD("scoreboard"),
SEECHUNK("seechunk"),
SETWARP("setwarp"),
+ SHOP("shop"),
TOP("top"),
VIEWCHEST("viewchest"),
ADDPOINTS("addpoints"),
@@ -120,8 +127,7 @@ public enum Permission {
COORD("coords"),
SHOWCLAIMS("showclaims"),
WARP("warp"),
- CHEST("chest"),
- CONVERTCONFIG("convertconfig");
+ CHEST("chest");
public final String node;
@@ -130,7 +136,7 @@ public enum Permission {
}
public boolean has(CommandSender sender, boolean informSenderIfNot) {
- return P.p.perm.has(sender, this.node, informSenderIfNot);
+ return FactionsPlugin.getInstance().perm.has(sender, this.node, informSenderIfNot);
}
public boolean has(CommandSender sender) {
diff --git a/src/main/java/com/massivecraft/factions/struct/Relation.java b/src/main/java/com/massivecraft/factions/struct/Relation.java
index 10d81048..7f32cb04 100644
--- a/src/main/java/com/massivecraft/factions/struct/Relation.java
+++ b/src/main/java/com/massivecraft/factions/struct/Relation.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.struct;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.util.TL;
@@ -199,7 +199,7 @@ public enum Relation implements Permissable {
// Utility method to build items for F Perm GUI
@Override
public ItemStack buildItem() {
- final ConfigurationSection RELATION_CONFIG = P.p.getConfig().getConfigurationSection("fperm-gui.relation");
+ final ConfigurationSection RELATION_CONFIG = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.relation");
String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", ""));
List lore = new ArrayList<>();
diff --git a/src/main/java/com/massivecraft/factions/struct/Role.java b/src/main/java/com/massivecraft/factions/struct/Role.java
index 45048fc3..cbf33bde 100644
--- a/src/main/java/com/massivecraft/factions/struct/Role.java
+++ b/src/main/java/com/massivecraft/factions/struct/Role.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.struct;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.util.TL;
@@ -113,7 +113,7 @@ public enum Role implements Permissable {
// Utility method to build items for F Perm GUI
@Override
public ItemStack buildItem() {
- final ConfigurationSection RELATION_CONFIG = P.p.getConfig().getConfigurationSection("fperm-gui.relation");
+ final ConfigurationSection RELATION_CONFIG = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fperm-gui.relation");
String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", ""));
List lore = new ArrayList<>();
@@ -132,7 +132,7 @@ public enum Role implements Permissable {
itemMeta.setDisplayName(displayName);
itemMeta.setLore(lore);
- if (!P.p.mc17) {
+ if (!FactionsPlugin.getInstance().mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
}
diff --git a/src/main/java/com/massivecraft/factions/tag/FactionTag.java b/src/main/java/com/massivecraft/factions/tag/FactionTag.java
new file mode 100644
index 00000000..1224444e
--- /dev/null
+++ b/src/main/java/com/massivecraft/factions/tag/FactionTag.java
@@ -0,0 +1,135 @@
+package com.massivecraft.factions.tag;
+
+import com.massivecraft.factions.Conf;
+import com.massivecraft.factions.FPlayer;
+import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.integration.Econ;
+import com.massivecraft.factions.struct.Relation;
+import com.massivecraft.factions.zcore.util.TL;
+
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
+public enum FactionTag implements Tag {
+ HOME_X("{x}", (fac) -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockX()) : Tag.isMinimalShow() ? null : "{ig}"),
+ HOME_Y("{y}", (fac) -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockY()) : Tag.isMinimalShow() ? null : "{ig}"),
+ HOME_Z("{z}", (fac) -> fac.hasHome() ? String.valueOf(fac.getHome().getBlockZ()) : Tag.isMinimalShow() ? null : "{ig}"),
+ CHUNKS("{chunks}", (fac) -> String.valueOf(fac.getLandRounded())),
+ WARPS("{warps}", (fac) -> String.valueOf(fac.getWarps().size())),
+ HEADER("{header}", (fac, fp) -> FactionsPlugin.getInstance().txt.titleize(fac.getTag(fp))),
+ POWER("{power}", (fac) -> String.valueOf(fac.getPowerRounded())),
+ MAX_POWER("{maxPower}", (fac) -> String.valueOf(fac.getPowerMaxRounded())),
+ POWER_BOOST("{power-boost}", (fac) -> {
+ double powerBoost = fac.getPowerBoost();
+ return (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString() + powerBoost + ")");
+ }),
+ LEADER("{leader}", (fac) -> {
+ FPlayer fAdmin = fac.getFPlayerAdmin();
+ return fAdmin == null ? "Server" : fAdmin.getName().substring(0, fAdmin.getName().length() > 14 ? 13 : fAdmin.getName().length());
+ }),
+ JOINING("{joining}", (fac) -> (fac.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString())),
+ FACTION("{faction}", (Function) Faction::getTag),
+ FACTION_RELATION_COLOR("{faction-relation-color}", (fac, fp) -> fp == null ? "" : fp.getColorTo(fac).toString()),
+ HOME_WORLD("{world}", (fac) -> fac.hasHome() ? fac.getHome().getWorld().getName() : Tag.isMinimalShow() ? null : "{ig}"),
+ RAIDABLE("{raidable}", (fac) -> {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false)) {
+ boolean raidable = fac.getLandRounded() >= fac.getPowerRounded();
+ String str = raidable ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString();
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.dtr", false)) {
+ int dtr = raidable ? 0 : (int) Math.ceil(((double) (fac.getPowerRounded() - fac.getLandRounded())) / Conf.powerPerDeath);
+ str += ' ' + TL.COMMAND_SHOW_DEATHS_TIL_RAIDABLE.format(dtr);
+ }
+ return str;
+ }
+ return null;
+ }),
+ PEACEFUL("{peaceful}", (fac) -> fac.isPeaceful() ? Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString() : ""),
+ PERMANENT("permanent", (fac) -> fac.isPermanent() ? "permanent" : "{notPermanent}"), // no braces needed
+ LAND_VALUE("{land-value}", (fac) -> Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(fac.getLandRounded())) : Tag.isMinimalShow() ? null : TL.ECON_OFF.format("value")),
+ DESCRIPTION("{description}", Faction::getDescription),
+ CREATE_DATE("{create-date}", (fac) -> TL.sdf.format(fac.getFoundedDate())),
+ LAND_REFUND("{land-refund}", (fac) -> Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(fac.getLandRounded())) : Tag.isMinimalShow() ? null : TL.ECON_OFF.format("refund")),
+ BANK_BALANCE("{faction-balance}", (fac) -> {
+ if (Econ.shouldBeUsed()) {
+ return Conf.bankEnabled ? Econ.moneyString(Econ.getBalance(fac.getAccountId())) : Tag.isMinimalShow() ? null : TL.ECON_OFF.format("balance");
+ }
+ return Tag.isMinimalShow() ? null : TL.ECON_OFF.format("balance");
+ }),
+ ALLIES_COUNT("{allies}", (fac) -> String.valueOf(fac.getRelationCount(Relation.ALLY))),
+ ENEMIES_COUNT("{enemies}", (fac) -> String.valueOf(fac.getRelationCount(Relation.ENEMY))),
+ TRUCES_COUNT("{truces}", (fac) -> String.valueOf(fac.getRelationCount(Relation.TRUCE))),
+ ONLINE_COUNT("{online}", (fac, fp) -> {
+ if (fp != null && fp.isOnline()) {
+ return String.valueOf(fac.getFPlayersWhereOnline(true, fp).size());
+ } else {
+ // Only console should ever get here.
+ return String.valueOf(fac.getFPlayersWhereOnline(true).size());
+ }
+ }),
+ OFFLINE_COUNT("{offline}", (fac) -> String.valueOf(fac.getFPlayers().size() - fac.getOnlinePlayers().size())),
+ FACTION_SIZE("{members}", (fac) -> String.valueOf(fac.getFPlayers().size())),
+ FACTION_KILLS("{faction-kills}", (fac) -> String.valueOf(fac.getKills())),
+ FACTION_DEATHS("{faction-deaths}", (fac) -> String.valueOf(fac.getDeaths())),
+ FACTION_BANCOUNT("{faction-bancount}", (fac) -> String.valueOf(fac.getBannedPlayers().size())),
+ ;
+
+ private final String tag;
+ private final BiFunction biFunction;
+ private final Function function;
+
+ FactionTag(String tag, BiFunction function) {
+ this.tag = tag;
+ this.biFunction = function;
+ this.function = null;
+ }
+
+ FactionTag(String tag, Function function) {
+ this.tag = tag;
+ this.biFunction = null;
+ this.function = function;
+ }
+
+ public static String parse(String text, Faction faction, FPlayer player) {
+ for (FactionTag tag : FactionTag.values()) {
+ text = tag.replace(text, faction, player);
+ }
+ return text;
+ }
+
+ public static String parse(String text, Faction faction) {
+ for (FactionTag tag : FactionTag.values()) {
+ text = tag.replace(text, faction);
+ }
+ return text;
+ }
+
+ @Override
+ public String getTag() {
+ return this.tag;
+ }
+
+ @Override
+ public boolean foundInString(String test) {
+ return test != null && test.contains(this.tag);
+ }
+
+ public String replace(String text, Faction faction, FPlayer player) {
+ if (!this.foundInString(text)) {
+ return text;
+ }
+ if (this.biFunction == null) {
+ return this.replace(text, faction);
+ }
+ String result = this.biFunction.apply(faction, player);
+ return result == null ? null : text.replace(this.tag, result);
+ }
+
+ public String replace(String text, Faction faction) {
+ if (this.function == null || !this.foundInString(text)) {
+ return text;
+ }
+ String result = this.function.apply(faction);
+ return result == null ? null : text.replace(this.tag, result);
+ }
+}
diff --git a/src/main/java/com/massivecraft/factions/tag/FancyTag.java b/src/main/java/com/massivecraft/factions/tag/FancyTag.java
new file mode 100644
index 00000000..49e6beaf
--- /dev/null
+++ b/src/main/java/com/massivecraft/factions/tag/FancyTag.java
@@ -0,0 +1,178 @@
+package com.massivecraft.factions.tag;
+
+import com.massivecraft.factions.FPlayer;
+import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.Factions;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.struct.Relation;
+import com.massivecraft.factions.util.MiscUtil;
+import com.massivecraft.factions.util.QuadFunction;
+import mkremins.fanciful.FancyMessage;
+import org.bukkit.ChatColor;
+
+import java.util.*;
+
+public enum FancyTag implements Tag {
+ ALLIES_LIST("{allies-list}", (target, fme, prefix, gm) -> processRelation(prefix, target, fme, Relation.ALLY)),
+ ENEMIES_LIST("{enemies-list}", (target, fme, prefix, gm) -> processRelation(prefix, target, fme, Relation.ENEMY)),
+ TRUCES_LIST("{truces-list}", (target, fme, prefix, gm) -> processRelation(prefix, target, fme, Relation.TRUCE)),
+ ONLINE_LIST("{online-list}", (target, fme, prefix, gm) -> {
+ List fancyMessages = new ArrayList<>();
+ FancyMessage currentOnline = FactionsPlugin.getInstance().txt.parseFancy(prefix);
+ boolean firstOnline = true;
+ for (FPlayer p : MiscUtil.rankOrder(target.getFPlayersWhereOnline(true, fme))) {
+ if (fme.getPlayer() != null && !fme.getPlayer().canSee(p.getPlayer())) {
+ continue; // skip
+ }
+ String name = p.getNameAndTitle();
+ currentOnline.then(firstOnline ? name : ", " + name);
+ currentOnline.tooltip(tipPlayer(p, gm)).color(fme.getColorTo(p));
+ firstOnline = false;
+ if (currentOnline.toJSONString().length() > ARBITRARY_LIMIT) {
+ fancyMessages.add(currentOnline);
+ currentOnline = new FancyMessage("");
+ }
+ }
+ fancyMessages.add(currentOnline);
+ return firstOnline && Tag.isMinimalShow() ? null : fancyMessages;
+ }),
+ OFFLINE_LIST("{offline-list}", (target, fme, prefix, gm) -> {
+ List fancyMessages = new ArrayList<>();
+ FancyMessage currentOffline = FactionsPlugin.getInstance().txt.parseFancy(prefix);
+ boolean firstOffline = true;
+ for (FPlayer p : MiscUtil.rankOrder(target.getFPlayers())) {
+ String name = p.getNameAndTitle();
+ // Also make sure to add players that are online BUT can't be seen.
+ if (!p.isOnline() || (fme.getPlayer() != null && p.isOnline() && !fme.getPlayer().canSee(p.getPlayer()))) {
+ currentOffline.then(firstOffline ? name : ", " + name);
+ currentOffline.tooltip(tipPlayer(p, gm)).color(fme.getColorTo(p));
+ firstOffline = false;
+ if (currentOffline.toJSONString().length() > ARBITRARY_LIMIT) {
+ fancyMessages.add(currentOffline);
+ currentOffline = new FancyMessage("");
+ }
+ }
+ }
+ fancyMessages.add(currentOffline);
+ return firstOffline && Tag.isMinimalShow() ? null : fancyMessages;
+ }),
+ ;
+
+ private final String tag;
+ private final QuadFunction, List> function;
+
+ FancyTag(String tag, QuadFunction, List> function) {
+ this.tag = tag;
+ this.function = function;
+ }
+
+ private static List processRelation(String prefix, Faction faction, FPlayer fPlayer, Relation relation) {
+ List fancyMessages = new ArrayList<>();
+ FancyMessage message = FactionsPlugin.getInstance().txt.parseFancy(prefix);
+ boolean first = true;
+ for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
+ if (otherFaction == faction) {
+ continue;
+ }
+ String s = otherFaction.getTag(fPlayer);
+ if (otherFaction.getRelationTo(faction) == relation) {
+ message.then(first ? s : ", " + s);
+ message.tooltip(tipFaction(otherFaction, fPlayer)).color(fPlayer.getColorTo(otherFaction));
+ first = false;
+ if (message.toJSONString().length() > ARBITRARY_LIMIT) {
+ fancyMessages.add(message);
+ message = new FancyMessage("");
+ }
+ }
+ }
+ fancyMessages.add(message);
+ return first && Tag.isMinimalShow() ? null : fancyMessages;
+ }
+
+ public static List parse(String text, Faction faction, FPlayer player, Map groupMap) {
+ for (FancyTag tag : FancyTag.values()) {
+ if (tag.foundInString(text)) {
+ return tag.getMessage(text, faction, player, groupMap);
+ }
+ }
+ return Collections.EMPTY_LIST; // We really shouldn't be here.
+ }
+
+ public static boolean anyMatch(String text) {
+ return getMatch(text) != null;
+ }
+
+ public static FancyTag getMatch(String text) {
+ for (FancyTag tag : FancyTag.values()) {
+ if (tag.foundInString(text)) {
+ return tag;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Parses tooltip variables from config
Supports variables for factions only (type 2)
+ *
+ * @param faction faction to tooltip for
+ * @return list of tooltips for a fancy message
+ */
+ private static List tipFaction(Faction faction, FPlayer player) {
+ List lines = new ArrayList<>();
+ for (String line : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.list")) {
+ String string = Tag.parsePlain(faction, player, line);
+ if (string == null) {
+ continue;
+ }
+ lines.add(ChatColor.translateAlternateColorCodes('&', string));
+ }
+ return lines;
+ }
+
+ /**
+ * Parses tooltip variables from config
Supports variables for players and factions (types 1 and 2)
+ *
+ * @param fplayer player to tooltip for
+ * @return list of tooltips for a fancy message
+ */
+ private static List tipPlayer(FPlayer fplayer, Map groupMap) {
+ List lines = new ArrayList<>();
+ for (String line : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.show")) {
+ String newLine = line;
+ everythingOnYourWayOut:
+ if (line.contains("{group}")) {
+ if (groupMap != null) {
+ String group = groupMap.get(UUID.fromString(fplayer.getId()));
+ if (!group.trim().isEmpty()) {
+ newLine = newLine.replace("{group}", group);
+ break everythingOnYourWayOut;
+ }
+ }
+ continue;
+ }
+ String string = Tag.parsePlain(fplayer, newLine);
+ if (string == null) {
+ continue;
+ }
+ lines.add(ChatColor.translateAlternateColorCodes('&', string));
+ }
+ return lines;
+ }
+
+ @Override
+ public String getTag() {
+ return this.tag;
+ }
+
+ @Override
+ public boolean foundInString(String test) {
+ return test != null && test.contains(this.tag);
+ }
+
+ public List getMessage(String text, Faction faction, FPlayer player, Map groupMap) {
+ if (!this.foundInString(text)) {
+ return Collections.EMPTY_LIST; // We really, really shouldn't be here.
+ }
+ return this.function.apply(faction, player, text.replace(this.getTag(), ""), groupMap);
+ }
+}
diff --git a/src/main/java/com/massivecraft/factions/tag/GeneralTag.java b/src/main/java/com/massivecraft/factions/tag/GeneralTag.java
new file mode 100644
index 00000000..36d22286
--- /dev/null
+++ b/src/main/java/com/massivecraft/factions/tag/GeneralTag.java
@@ -0,0 +1,58 @@
+package com.massivecraft.factions.tag;
+
+import com.massivecraft.factions.Factions;
+import com.massivecraft.factions.FactionsPlugin;
+import com.massivecraft.factions.zcore.util.TL;
+import org.bukkit.Bukkit;
+
+import java.util.function.Supplier;
+
+public enum GeneralTag implements Tag {
+ MAX_WARPS("{max-warps}", () -> String.valueOf(FactionsPlugin.getInstance().getConfig().getInt("max-warps", 5))),
+ MAX_ALLIES("{max-allies}", () -> getRelation("ally")),
+ MAX_ENEMIES("{max-enemies}", () -> getRelation("enemy")),
+ MAX_TRUCES("{max-truces}", () -> getRelation("truce")),
+ FACTIONLESS("{factionless}", () -> String.valueOf(Factions.getInstance().getNone().getFPlayersWhereOnline(true).size())),
+ TOTAL_ONLINE("{total-online}", () -> String.valueOf(Bukkit.getOnlinePlayers().size())),
+ ;
+
+ private final String tag;
+ private final Supplier supplier;
+
+ GeneralTag(String tag, Supplier supplier) {
+ this.tag = tag;
+ this.supplier = supplier;
+ }
+
+ private static String getRelation(String relation) {
+ if (FactionsPlugin.getInstance().getConfig().getBoolean("max-relations.enabled", true)) {
+ return String.valueOf(FactionsPlugin.getInstance().getConfig().getInt("max-relations." + relation, 10));
+ }
+ return TL.GENERIC_INFINITY.toString();
+ }
+
+ public static String parse(String text) {
+ for (GeneralTag tag : GeneralTag.values()) {
+ text = tag.replace(text);
+ }
+ return text;
+ }
+
+ @Override
+ public String getTag() {
+ return this.tag;
+ }
+
+ @Override
+ public boolean foundInString(String test) {
+ return test != null && test.contains(this.tag);
+ }
+
+ public String replace(String text) {
+ if (!this.foundInString(text)) {
+ return text;
+ }
+ String result = this.supplier.get();
+ return result == null ? null : text.replace(this.tag, result);
+ }
+}
diff --git a/src/main/java/com/massivecraft/factions/tag/PlayerTag.java b/src/main/java/com/massivecraft/factions/tag/PlayerTag.java
new file mode 100644
index 00000000..d51cca19
--- /dev/null
+++ b/src/main/java/com/massivecraft/factions/tag/PlayerTag.java
@@ -0,0 +1,56 @@
+package com.massivecraft.factions.tag;
+
+import com.massivecraft.factions.FPlayer;
+import com.massivecraft.factions.integration.Econ;
+import com.massivecraft.factions.zcore.util.TL;
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.bukkit.ChatColor;
+
+import java.util.function.Function;
+
+public enum PlayerTag implements Tag {
+ LAST_SEEN("{lastSeen}", (fp) -> {
+ String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
+ return fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
+ }),
+ PLAYER_BALANCE("{balance}", (fp) -> Econ.isSetup() ? Econ.getFriendlyBalance(fp) : (Tag.isMinimalShow() ? null : TL.ECON_OFF.format("balance"))),
+ PLAYER_POWER("{player-power}", (fp) -> String.valueOf(fp.getPowerRounded())),
+ PLAYER_MAXPOWER("{player-maxpower}", (fp) -> String.valueOf(fp.getPowerMaxRounded())),
+ PLAYER_KILLS("{player-kills}", (fp) -> String.valueOf(fp.getKills())),
+ PLAYER_DEATHS("{player-deaths}", (fp) -> String.valueOf(fp.getDeaths())),
+ PLAYER_NAME("{name}", FPlayer::getName),
+ ;
+
+ private final String tag;
+ private final Function function;
+
+ PlayerTag(String tag, Function function) {
+ this.tag = tag;
+ this.function = function;
+ }
+
+ public static String parse(String text, FPlayer player) {
+ for (PlayerTag tag : PlayerTag.values()) {
+ text = tag.replace(text, player);
+ }
+ return text;
+ }
+
+ @Override
+ public String getTag() {
+ return this.tag;
+ }
+
+ @Override
+ public boolean foundInString(String test) {
+ return test != null && test.contains(this.tag);
+ }
+
+ public String replace(String text, FPlayer player) {
+ if (!this.foundInString(text)) {
+ return text;
+ }
+ String result = this.function.apply(player);
+ return result == null ? null : text.replace(this.tag, result);
+ }
+}
diff --git a/src/main/java/com/massivecraft/factions/tag/Tag.java b/src/main/java/com/massivecraft/factions/tag/Tag.java
new file mode 100644
index 00000000..39b573e5
--- /dev/null
+++ b/src/main/java/com/massivecraft/factions/tag/Tag.java
@@ -0,0 +1,80 @@
+package com.massivecraft.factions.tag;
+
+import com.massivecraft.factions.FPlayer;
+import com.massivecraft.factions.Faction;
+import com.massivecraft.factions.FactionsPlugin;
+import me.clip.placeholderapi.PlaceholderAPI;
+import org.bukkit.entity.Player;
+
+public interface Tag {
+ int ARBITRARY_LIMIT = 25000;
+
+ /**
+ * Replaces all variables in a plain raw line for a faction
+ *
+ * @param faction for faction
+ * @param line raw line from config with variables to replace for
+ * @return clean line
+ */
+ static String parsePlain(Faction faction, String line) {
+ return GeneralTag.parse(FactionTag.parse(line, faction));
+ }
+
+ /**
+ * Replaces all variables in a plain raw line for a player
+ *
+ * @param fplayer for player
+ * @param line raw line from config with variables to replace for
+ * @return clean line
+ */
+ static String parsePlain(FPlayer fplayer, String line) {
+ return parsePlain(fplayer.getFaction(), fplayer, line);
+ }
+
+ /**
+ * Replaces all variables in a plain raw line for a faction, using relations from fplayer
+ *
+ * @param faction for faction
+ * @param fplayer from player
+ * @param line raw line from config with variables to replace for
+ * @return clean line
+ */
+ static String parsePlain(Faction faction, FPlayer fplayer, String line) {
+ return GeneralTag.parse(PlayerTag.parse(FactionTag.parse(line, faction, fplayer), fplayer));
+ }
+
+ static String parsePlaceholders(Player player, String line) {
+ if (player == null || line == null) {
+ return line;
+ }
+
+ if (FactionsPlugin.getInstance().isClipPlaceholderAPIHooked() && player.isOnline()) {
+ line = PlaceholderAPI.setPlaceholders(player, line);
+ }
+
+ if (FactionsPlugin.getInstance().isMVdWPlaceholderAPIHooked() && player.isOnline()) {
+ line = be.maximvdw.placeholderapi.PlaceholderAPI.replacePlaceholders(player, line);
+ }
+
+ return line;
+ }
+
+ static boolean isMinimalShow() {
+ return FactionsPlugin.getInstance().getConfig().getBoolean("minimal-show", false);
+ }
+
+ /**
+ * Gets the Tag's string representation.
+ *
+ * @return tag
+ */
+ String getTag();
+
+ /**
+ * Gets if the Tag can be found in the given String.
+ *
+ * @param test string to test
+ * @return true if the tag is found in this string
+ */
+ boolean foundInString(String test);
+}
diff --git a/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java b/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java
index e9946a1e..33ca2fd2 100644
--- a/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java
+++ b/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java
@@ -50,13 +50,13 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
// Check if they should be exempt from this.
if (!fplayer.willAutoLeave()) {
- P.p.debug(Level.INFO, fplayer.getName() + " was going to be auto-removed but was set not to.");
+ FactionsPlugin.getInstance().debug(Level.INFO, fplayer.getName() + " was going to be auto-removed but was set not to.");
continue;
}
if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis) {
if (Conf.logFactionLeave || Conf.logFactionKick) {
- P.p.log("Player " + fplayer.getName() + " was auto-removed due to inactivity.");
+ FactionsPlugin.getInstance().log("Player " + fplayer.getName() + " was auto-removed due to inactivity.");
}
// if player is faction admin, sort out the faction since he's going away
diff --git a/src/main/java/com/massivecraft/factions/util/AutoLeaveTask.java b/src/main/java/com/massivecraft/factions/util/AutoLeaveTask.java
index 6a1bda45..c24be121 100644
--- a/src/main/java/com/massivecraft/factions/util/AutoLeaveTask.java
+++ b/src/main/java/com/massivecraft/factions/util/AutoLeaveTask.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.util;
import com.massivecraft.factions.Conf;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
public class AutoLeaveTask implements Runnable {
@@ -18,11 +18,11 @@ public class AutoLeaveTask implements Runnable {
}
task = new AutoLeaveProcessTask();
- task.runTaskTimer(P.p, 1, 1);
+ task.runTaskTimer(FactionsPlugin.getInstance(), 1, 1);
// maybe setting has been changed? if so, restart this task at new rate
if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes) {
- P.p.startAutoLeaveTask(true);
+ FactionsPlugin.getInstance().startAutoLeaveTask(true);
}
}
}
diff --git a/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java b/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java
index b7117dc8..13b59e6f 100644
--- a/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java
+++ b/src/main/java/com/massivecraft/factions/util/ClipPlaceholderAPIManager.java
@@ -35,7 +35,7 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
// Return the plugin version since this expansion is bundled with the dependency
@Override
public String getVersion() {
- return P.p.getDescription().getVersion();
+ return FactionsPlugin.getInstance().getDescription().getVersion();
}
@Override
@@ -84,7 +84,7 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fPlayer.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
return fPlayer.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fPlayer.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
case "player_group":
- return P.p.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fPlayer.getId())));
+ return FactionsPlugin.getInstance().getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fPlayer.getId())));
case "player_balance":
return Econ.isSetup() ? Econ.getFriendlyBalance(fPlayer) : TL.ECON_OFF.format("balance");
case "player_power":
@@ -131,7 +131,7 @@ public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements R
case "faction_warps":
return String.valueOf(faction.getWarps().size());
case "faction_raidable":
- boolean raid = P.p.getConfig().getBoolean("hcf.raidable", false) && faction.getLandRounded() >= faction.getPowerRounded();
+ boolean raid = FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && faction.getLandRounded() >= faction.getPowerRounded();
return raid ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString();
case "faction_home_world":
return faction.hasHome() ? faction.getHome().getWorld().getName() : "";
diff --git a/src/main/java/com/massivecraft/factions/util/FactionWarpsFrame.java b/src/main/java/com/massivecraft/factions/util/FactionWarpsFrame.java
index e4790637..1aa83f3f 100644
--- a/src/main/java/com/massivecraft/factions/util/FactionWarpsFrame.java
+++ b/src/main/java/com/massivecraft/factions/util/FactionWarpsFrame.java
@@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
@@ -25,8 +25,8 @@ public class FactionWarpsFrame {
private ConfigurationSection section;
public FactionWarpsFrame(final Faction f) {
- this.section = P.p.getConfig().getConfigurationSection("fwarp-gui");
- this.gui = new Gui(P.p, section.getInt("rows", 3), P.p.color(this.section.getString("name").replace("{faction}", f.getTag())));
+ this.section = FactionsPlugin.getInstance().getConfig().getConfigurationSection("fwarp-gui");
+ this.gui = new Gui(FactionsPlugin.getInstance(), section.getInt("rows", 3), FactionsPlugin.getInstance().color(this.section.getString("name").replace("{faction}", f.getTag())));
}
public void buildGUI(final FPlayer fplayer) {
@@ -50,12 +50,12 @@ public class FactionWarpsFrame {
} else {
fplayer.setEnteringPassword(true, warp.getKey());
fplayer.msg(TL.COMMAND_FWARP_PASSWORD_REQUIRED);
- Bukkit.getScheduler().runTaskLater(P.p, () -> {
+ Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> {
if (fplayer.isEnteringPassword()) {
fplayer.msg(TL.COMMAND_FWARP_PASSWORD_TIMEOUT);
fplayer.setEnteringPassword(false, "");
}
- }, P.p.getConfig().getInt("fwarp-gui.password-timeout", 5) * 20);
+ }, FactionsPlugin.getInstance().getConfig().getInt("fwarp-gui.password-timeout", 5) * 20);
}
}));
++count;
@@ -70,8 +70,8 @@ public class FactionWarpsFrame {
final ConfigurationSection config = this.section.getConfigurationSection("warp-item");
final ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
final ItemMeta meta = item.getItemMeta();
- meta.setLore(P.p.colorList(P.p.replacePlaceholders(config.getStringList("Lore"), new Placeholder("{warp-protected}", faction.hasWarpPassword(warp.getKey()) ? "Enabled" : "Disabled"), new Placeholder("{warp-cost}", P.p.getConfig().getBoolean("warp-cost.enabled", false) ? Integer.toString(P.p.getConfig().getInt("warp-cost.warp", 5)) : "Disabled"))));
- meta.setDisplayName(P.p.color(config.getString("Name").replace("{warp}", warp.getKey())));
+ meta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().replacePlaceholders(config.getStringList("Lore"), new Placeholder("{warp-protected}", faction.hasWarpPassword(warp.getKey()) ? "Enabled" : "Disabled"), new Placeholder("{warp-cost}", FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) ? Integer.toString(FactionsPlugin.getInstance().getConfig().getInt("warp-cost.warp", 5)) : "Disabled"))));
+ meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name").replace("{warp}", warp.getKey())));
item.setItemMeta(meta);
return item;
}
@@ -80,8 +80,8 @@ public class FactionWarpsFrame {
final ConfigurationSection config = this.section.getConfigurationSection("dummy-item");
final ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
final ItemMeta meta = item.getItemMeta();
- meta.setLore(P.p.colorList(config.getStringList("Lore")));
- meta.setDisplayName(P.p.color(config.getString("Name")));
+ meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore")));
+ meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name")));
item.setItemMeta(meta);
return item;
}
@@ -93,12 +93,13 @@ public class FactionWarpsFrame {
player.teleport(fme.getFaction().getWarp(warp).getLocation());
fme.msg(TL.COMMAND_FWARP_WARPED, warp);
}
- }, P.p.getConfig().getLong("warmups.f-warp", 0));
+ }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-warp", 0));
}
private boolean transact(FPlayer player) {
- if (!P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing()) return true;
- double cost = P.p.getConfig().getDouble("warp-cost.warp", 5);
+ if (!FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing())
+ return true;
+ double cost = FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.warp", 5);
if (!Econ.shouldBeUsed() || cost == 0.0 || player.isAdminBypassing()) return true;
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && player.hasFaction()) {
diff --git a/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java
index a5862681..d04383a0 100644
--- a/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java
+++ b/src/main/java/com/massivecraft/factions/util/LocationTypeAdapter.java
@@ -1,7 +1,7 @@
package com.massivecraft.factions.util;
import com.google.gson.*;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -21,7 +21,7 @@ public class LocationTypeAdapter implements JsonSerializer, JsonDeseri
return object;
} catch (Exception ex) {
ex.printStackTrace();
- P.p.log(Level.WARNING, "Error encountered while serializing a Location.");
+ FactionsPlugin.getInstance().log(Level.WARNING, "Error encountered while serializing a Location.");
return object;
}
}
@@ -38,7 +38,7 @@ public class LocationTypeAdapter implements JsonSerializer, JsonDeseri
object.get("z").getAsDouble());
} catch (Exception ex) {
ex.printStackTrace();
- P.p.log(Level.WARNING, "Error encountered while" +
+ FactionsPlugin.getInstance().log(Level.WARNING, "Error encountered while" +
" deserializing a Location.");
return null;
}
diff --git a/src/main/java/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java b/src/main/java/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java
index d70d2cba..2006a898 100644
--- a/src/main/java/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java
+++ b/src/main/java/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java
@@ -2,7 +2,7 @@ package com.massivecraft.factions.util;
import com.google.gson.*;
import com.massivecraft.factions.FLocation;
-import com.massivecraft.factions.P;
+import com.massivecraft.factions.FactionsPlugin;
import java.lang.reflect.Type;
import java.util.HashSet;
@@ -50,7 +50,7 @@ public class MapFLocToStringSetTypeAdapter implements JsonDeserializer