Introduced Brigadier Command System. More Formatting Coming in next commit.

This commit is contained in:
Driftay 2019-09-14 15:13:01 -04:00
parent b06e6e0f04
commit 3c9b606bb9
207 changed files with 4465 additions and 4017 deletions

View File

@ -108,7 +108,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../com/massivecraft/factions/zcore/MPlugin.html" title="class in com.massivecraft.factions.zcore">com.massivecraft.factions.zcore.MPlugin</a></li> <li><a href="../../../com/massivecraft/factions/zcore/MPlugin.html" title="class in com.massivecraft.factions.zcore">com.massivecraft.factions.zcore.MPlugin</a></li>
<li> <li>
<ul class="inheritance"> <ul class="inheritance">
<li>com.massivecraft.factions.P</li> <li>com.massivecraft.factions.FactionsPlugin</li>
</ul> </ul>
</li> </li>
</ul> </ul>

27
pom.xml
View File

@ -81,6 +81,18 @@
</build> </build>
<dependencies> <dependencies>
<dependency>
<groupId>me.lucko</groupId>
<artifactId>commodore</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId>
<version>1.0.14</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>com.github.stefvanschie.inventoryframework</groupId> <groupId>com.github.stefvanschie.inventoryframework</groupId>
<artifactId>IF</artifactId> <artifactId>IF</artifactId>
@ -352,7 +364,11 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper</artifactId>
<version>1.1.6-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>
@ -360,6 +376,10 @@
<id>net.coreprotect</id> <id>net.coreprotect</id>
<url>http://maven.playpro.com/</url> <url>http://maven.playpro.com/</url>
</repository> </repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository> <repository>
<id>ess-repo</id> <id>ess-repo</id>
<url>http://ci.ender.zone/plugin/repository/everything/</url> <url>http://ci.ender.zone/plugin/repository/everything/</url>
@ -393,6 +413,11 @@
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
</repository> </repository>
<repository>
<id>minecraft-libraries</id>
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net</url>
</repository>
</repositories> </repositories>
<distributionManagement> <distributionManagement>

View File

@ -386,7 +386,7 @@ public class Conf {
territoryDenyUseageMaterials.add(Material.BUCKET); territoryDenyUseageMaterials.add(Material.BUCKET);
territoryDenyUseageMaterials.add(Material.WATER_BUCKET); territoryDenyUseageMaterials.add(Material.WATER_BUCKET);
territoryDenyUseageMaterials.add(Material.LAVA_BUCKET); territoryDenyUseageMaterials.add(Material.LAVA_BUCKET);
if (!P.p.mc17) { if (!FactionsPlugin.getInstance().mc17) {
territoryDenyUseageMaterials.add(Material.ARMOR_STAND); territoryDenyUseageMaterials.add(Material.ARMOR_STAND);
} }
@ -398,7 +398,7 @@ public class Conf {
territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET);
if (!P.p.mc17) { if (!FactionsPlugin.getInstance().mc17) {
territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND); territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND);
} }
safeZoneNerfedCreatureTypes.add(EntityType.BLAZE); safeZoneNerfedCreatureTypes.add(EntityType.BLAZE);
@ -426,11 +426,11 @@ public class Conf {
} }
public static void load() { public static void load() {
P.p.persist.loadOrSaveDefault(i, Conf.class, "conf"); FactionsPlugin.getInstance().persist.loadOrSaveDefault(i, Conf.class, "conf");
} }
public static void save() { public static void save() {
P.p.persist.save(i); FactionsPlugin.getInstance().persist.save(i);
} }
public enum Backend { public enum Backend {

View File

@ -5,7 +5,9 @@ import ch.njol.skript.SkriptAddon;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.cmd.CmdAutoHelp; import com.massivecraft.factions.cmd.CmdAutoHelp;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.FCmdRoot; import com.massivecraft.factions.cmd.FCmdRoot;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.cmd.check.CheckTask; import com.massivecraft.factions.cmd.check.CheckTask;
import com.massivecraft.factions.cmd.check.WeeWooTask; import com.massivecraft.factions.cmd.check.WeeWooTask;
import com.massivecraft.factions.cmd.chest.ChestLogsHandler; import com.massivecraft.factions.cmd.chest.ChestLogsHandler;
@ -17,16 +19,18 @@ import com.massivecraft.factions.missions.MissionHandler;
import com.massivecraft.factions.shop.ShopClickPersistence; import com.massivecraft.factions.shop.ShopClickPersistence;
import com.massivecraft.factions.shop.ShopConfig; import com.massivecraft.factions.shop.ShopConfig;
import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.*; import com.massivecraft.factions.util.*;
import com.massivecraft.factions.util.Particles.ReflectionUtils; import com.massivecraft.factions.util.Particles.ReflectionUtils;
import com.massivecraft.factions.zcore.CommandVisibility; import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.zcore.MCommand;
import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.MPlugin;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.fupgrades.*; import com.massivecraft.factions.zcore.fupgrades.*;
import com.massivecraft.factions.zcore.util.TextUtil; import com.massivecraft.factions.zcore.util.TextUtil;
import me.lucko.commodore.CommodoreProvider;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.*; import org.bukkit.*;
@ -52,11 +56,11 @@ import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class P extends MPlugin { public class FactionsPlugin extends MPlugin {
// Our single plugin instance. // Our single plugin instance.
// Single 4 life. // Single 4 life.
public static P p; public static FactionsPlugin instance;
public static Permission perms = null; public static Permission perms = null;
// This plugin sets the boolean true when fully enabled. // This plugin sets the boolean true when fully enabled.
// Plugins can check this boolean while hooking in have // Plugins can check this boolean while hooking in have
@ -85,8 +89,12 @@ public class P extends MPlugin {
private Listener[] eventsListener; private Listener[] eventsListener;
public P() { public FactionsPlugin() {
p = this; instance = this;
}
public static FactionsPlugin getInstance() {
return instance;
} }
public boolean getLocked() { public boolean getLocked() {
@ -139,29 +147,29 @@ public class P extends MPlugin {
// Vault dependency check. // Vault dependency check.
if (getServer().getPluginManager().getPlugin("Vault") == null) { if (getServer().getPluginManager().getPlugin("Vault") == null) {
log("Vault is not present, the plugin will not run properly."); log("Vault is not present, the plugin will not run properly.");
getServer().getPluginManager().disablePlugin(p); getServer().getPluginManager().disablePlugin(instance);
return; return;
} }
int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]); int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]);
switch (version) { switch (version) {
case 7: case 7:
P.p.log("Minecraft Version 1.7 found, disabling banners, itemflags inside GUIs, and Titles."); FactionsPlugin.instance.log("Minecraft Version 1.7 found, disabling banners, itemflags inside GUIs, and Titles.");
mc17 = true; mc17 = true;
break; break;
case 8: case 8:
P.p.log("Minecraft Version 1.8 found, Title Fadeouttime etc will not be configurable."); FactionsPlugin.instance.log("Minecraft Version 1.8 found, Title Fadeouttime etc will not be configurable.");
mc18 = true; mc18 = true;
break; break;
case 12: case 12:
mc112 = true; mc112 = true;
break; break;
case 13: case 13:
P.p.log("Minecraft Version 1.13 found, New Items will be used."); FactionsPlugin.instance.log("Minecraft Version 1.13 found, New Items will be used.");
mc113 = true; mc113 = true;
break; break;
case 14: case 14:
P.p.log("Minecraft Version 1.14 found."); FactionsPlugin.instance.log("Minecraft Version 1.14 found.");
mc114 = true; mc114 = true;
break; break;
} }
@ -206,7 +214,6 @@ public class P extends MPlugin {
// Add Base Commands // Add Base Commands
this.cmdBase = new FCmdRoot(); this.cmdBase = new FCmdRoot();
this.cmdAutoHelp = new CmdAutoHelp(); this.cmdAutoHelp = new CmdAutoHelp();
this.getBaseCommands().add(cmdBase);
Econ.setup(); Econ.setup();
setupPermissions(); setupPermissions();
@ -230,7 +237,7 @@ public class P extends MPlugin {
} }
if (getServer().getPluginManager().getPlugin("Skript") != null) { if (getServer().getPluginManager().getPlugin("Skript") != null) {
log("Skript was found! Registering P Addon..."); log("Skript was found! Registering FactionsPlugin Addon...");
skriptAddon = Skript.registerAddon(this); skriptAddon = Skript.registerAddon(this);
try { try {
skriptAddon.loadClasses("com.massivecraft.factions.skript", "expressions"); skriptAddon.loadClasses("com.massivecraft.factions.skript", "expressions");
@ -272,13 +279,13 @@ public class P extends MPlugin {
for (Listener eventListener : eventsListener) for (Listener eventListener : eventsListener)
getServer().getPluginManager().registerEvents(eventListener, this); getServer().getPluginManager().registerEvents(eventListener, this);
// since some other plugins execute commands directly through this command interface, provide it this.getCommand(refCommand).setExecutor(cmdBase);
getCommand(this.refCommand).setExecutor(this);
getCommand(this.refCommand).setTabCompleter(this); if (!CommodoreProvider.isSupported()) this.getCommand(refCommand).setTabCompleter(this);
RegisteredServiceProvider<Economy> rsp = P.this.getServer().getServicesManager().getRegistration(Economy.class); RegisteredServiceProvider<Economy> rsp = FactionsPlugin.this.getServer().getServicesManager().getRegistration(Economy.class);
P.econ = rsp.getProvider(); FactionsPlugin.econ = rsp.getProvider();
if (getDescription().getFullName().contains("BETA")) { if (getDescription().getFullName().contains("BETA")) {
divider(); divider();
@ -292,7 +299,7 @@ public class P extends MPlugin {
this.postEnable(); this.postEnable();
this.loadSuccessful = true; this.loadSuccessful = true;
// Set startup finished to true. to give plugins hooking in a greenlight // Set startup finished to true. to give plugins hooking in a greenlight
P.startupFinished = true; FactionsPlugin.startupFinished = true;
} }
public SkriptAddon getSkriptAddon() { public SkriptAddon getSkriptAddon() {
@ -455,14 +462,14 @@ public class P extends MPlugin {
public ItemStack createLazyItem(Material material, int amount, short datavalue, String name, String lore) { public ItemStack createLazyItem(Material material, int amount, short datavalue, String name, String lore) {
ItemStack item = new ItemStack(material, amount, datavalue); ItemStack item = new ItemStack(material, amount, datavalue);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName(color(P.p.getConfig().getString(name))); meta.setDisplayName(color(FactionsPlugin.instance.getConfig().getString(name)));
meta.setLore(colorList(P.p.getConfig().getStringList(lore))); meta.setLore(colorList(FactionsPlugin.instance.getConfig().getStringList(lore)));
item.setItemMeta(meta); item.setItemMeta(meta);
return item; return item;
} }
public Economy getEcon() { public Economy getEcon() {
RegisteredServiceProvider<Economy> rsp = P.p.getServer().getServicesManager().getRegistration(Economy.class); RegisteredServiceProvider<Economy> rsp = FactionsPlugin.instance.getServer().getServicesManager().getRegistration(Economy.class);
return rsp.getProvider(); return rsp.getProvider();
} }
@ -488,48 +495,62 @@ public class P extends MPlugin {
return handleCommand(sender, cmd + " " + TextUtil.implode(Arrays.asList(split), " "), false); return handleCommand(sender, cmd + " " + TextUtil.implode(Arrays.asList(split), " "), false);
} }
// This method must stay for < 1.12 versions
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer((Player) sender); // Must be a LinkedList to prevent UnsupportedOperationException.
List<String> completions = new ArrayList<>(); List<String> argsList = new LinkedList<>(Arrays.asList(args));
CommandContext context = new CommandContext(sender, argsList, alias);
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0); String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
List<String> argsList = new ArrayList<>(Arrays.asList(args)); // String cmdValid = (cmd + " " + TextUtil.implode(context.args, " ")).trim();
argsList.remove(argsList.size() - 1); List<FCommand> commandsList = cmdBase.subCommands;
String cmdValid = (cmd + " " + TextUtil.implode(argsList, " ")).trim(); FCommand commandsEx = cmdBase;
MCommand<?> commandEx = cmdBase; List<String> completions = new ArrayList<>();
List<MCommand<?>> commandsList = cmdBase.subCommands;
for (; !commandsList.isEmpty() && !argsList.isEmpty(); argsList.remove(0)) { // Check for "" first arg because spigot is mangled.
String cmdName = argsList.get(0).toLowerCase(); if (context.args.get(0).equals("")) {
MCommand<?> commandFounded = commandsList.stream() for (FCommand subCommand : commandsEx.subCommands) {
.filter(c -> c.aliases.contains(cmdName)) if (subCommand.requirements.playerOnly && sender.hasPermission(subCommand.requirements.permission.node) && subCommand.visibility != CommandVisibility.INVISIBLE)
.findFirst().orElse(null);
if (commandFounded != null) {
commandEx = commandFounded;
commandsList = commandFounded.subCommands;
} else break;
}
if (argsList.isEmpty()) {
for (MCommand<?> subCommand : commandEx.subCommands) {
subCommand.setCommandSender(sender);
if (handleCommand(sender, cmdValid + " " + subCommand.aliases.get(0), true)
&& subCommand.visibility != CommandVisibility.INVISIBLE
&& subCommand.validSenderType(sender, false)
&& subCommand.validSenderPermissions(sender, false))
completions.addAll(subCommand.aliases); completions.addAll(subCommand.aliases);
} }
return completions;
} else if (context.args.size() == 1) {
for (; !commandsList.isEmpty() && !context.args.isEmpty(); context.args.remove(0)) {
String cmdName = context.args.get(0).toLowerCase();
boolean toggle = false;
for (FCommand fCommand : commandsList) {
for (String s : fCommand.aliases) {
if (s.startsWith(cmdName)) {
commandsList = fCommand.subCommands;
completions.addAll(fCommand.aliases);
toggle = true;
break;
}
}
if (toggle) break;
}
} }
String lastArg = args[args.length - 1].toLowerCase(); String lastArg = args[args.length - 1].toLowerCase();
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
completions.add(player.getName());
}
completions = completions.stream() completions = completions.stream()
.filter(m -> m.toLowerCase().startsWith(lastArg)) .filter(m -> m.toLowerCase().startsWith(lastArg))
.collect(Collectors.toList()); .collect(Collectors.toList());
return completions; return completions;
} else {
String lastArg = args[args.length - 1].toLowerCase();
for (Role value : Role.values()) completions.add(value.nicename);
for (Relation value : Relation.values()) completions.add(value.nicename);
// The stream and foreach from the old implementation looped 2 times, by looping all players -> filtered -> looped filter and added -> filtered AGAIN at the end.
// This loops them once and just adds, because we are filtering the arguments at the end anyways
for (Player player : Bukkit.getServer().getOnlinePlayers()) completions.add(player.getName());
for (Faction faction : Factions.getInstance().getAllFactions())
completions.add(ChatColor.stripColor(faction.getTag()));
completions = completions.stream().filter(m -> m.toLowerCase().startsWith(lastArg)).collect(Collectors.toList());
return completions;
}
} }
public void createTimedHologram(final Location location, String text, Long timeout) { public void createTimedHologram(final Location location, String text, Long timeout) {
@ -537,11 +558,11 @@ public class P extends MPlugin {
as.setVisible(false); //Makes the ArmorStand invisible as.setVisible(false); //Makes the ArmorStand invisible
as.setGravity(false); //Make sure it doesn't fall as.setGravity(false); //Make sure it doesn't fall
as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it as.setCanPickupItems(false); //I'm not sure what happens if you leave this as it is, but you might as well disable it
as.setCustomName(P.p.color(text)); //Set this to the text you want as.setCustomName(FactionsPlugin.instance.color(text)); //Set this to the text you want
as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not
final ArmorStand armorStand = as; final ArmorStand armorStand = as;
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> {
armorStand.remove(); armorStand.remove();
getLogger().info("Removing Hologram."); getLogger().info("Removing Hologram.");
} }

View File

@ -0,0 +1,92 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.CommandNode;
import me.lucko.commodore.Commodore;
import me.lucko.commodore.CommodoreProvider;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class BrigadierManager {
public Commodore commodore;
public LiteralArgumentBuilder<Object> brigadier = LiteralArgumentBuilder.literal("factions");
public BrigadierManager() {
commodore = CommodoreProvider.getCommodore(FactionsPlugin.getInstance());
}
public void build() {
commodore.register(brigadier.build());
// Add factions children to f alias
LiteralArgumentBuilder<Object> fLiteral = LiteralArgumentBuilder.literal("f");
for (CommandNode<Object> node : brigadier.getArguments()) fLiteral.then(node);
commodore.register(fLiteral.build());
}
public void addSubCommand(FCommand subCommand) {
// Register brigadier to all command aliases
for (String alias : subCommand.aliases) {
LiteralArgumentBuilder<Object> literal = LiteralArgumentBuilder.literal(alias);
if (subCommand.requirements.brigadier != null) {
// If the requirements explicitly provide a BrigadierProvider then use it
Class<? extends BrigadierProvider> brigadierProvider = subCommand.requirements.brigadier;
try {
Constructor<? extends BrigadierProvider> constructor = brigadierProvider.getDeclaredConstructor(subCommand.getClass());
brigadier.then(constructor.newInstance(subCommand).get(literal));
} catch (Exception e) {
e.printStackTrace();
}
} else {
// Generate our own based on args - quite ugly
// We create an orderly stack of all args, required and optional, format them differently
List<RequiredArgumentBuilder<Object, ?>> stack = new ArrayList<>();
for (String required : subCommand.requiredArgs) {
// Simply add the arg name as required
stack.add(RequiredArgumentBuilder.argument(required, StringArgumentType.word()));
}
for (Map.Entry<String, String> optionalEntry : subCommand.optionalArgs.entrySet()) {
RequiredArgumentBuilder<Object, ?> optional;
// Optional without default
if (optionalEntry.getKey().equalsIgnoreCase(optionalEntry.getValue())) {
optional = RequiredArgumentBuilder.argument(":" + optionalEntry.getKey(), StringArgumentType.word());
// Optional with default, explain
} else {
optional = RequiredArgumentBuilder.argument(optionalEntry.getKey() + "|" + optionalEntry.getValue(), StringArgumentType.word());
}
stack.add(optional);
}
// Reverse the stack and apply .then()
RequiredArgumentBuilder<Object, ?> previous = null;
for (int i = stack.size() - 1; i >= 0; i--) {
if (previous == null) {
previous = stack.get(i);
} else {
previous = stack.get(i).then(previous);
}
}
if (previous == null) {
brigadier.then(literal);
} else {
brigadier.then(literal.then(previous));
}
}
}
}
}

View File

@ -0,0 +1,9 @@
package com.massivecraft.factions.cmd;
import com.mojang.brigadier.builder.ArgumentBuilder;
public interface BrigadierProvider {
ArgumentBuilder<Object, ?> get(ArgumentBuilder<Object, ?> parent);
}

View File

@ -12,23 +12,17 @@ public class CmdAHome extends FCommand {
super(); super();
this.aliases.add("ahome"); this.aliases.add("ahome");
this.requiredArgs.add("player name"); this.requiredArgs.add("player");
this.permission = Permission.AHOME.node; this.requirements = new CommandRequirements.Builder(Permission.AHOME).noDisableOnLock().build();
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer target = argAsBestFPlayerMatch(0); FPlayer target = context.argAsBestFPlayerMatch(0);
if (target == null) { if (target == null) {
msg(TL.GENERIC_NOPLAYERMATCH, argAsString(0)); context.msg(TL.GENERIC_NOPLAYERMATCH, context.argAsString(0));
return; return;
} }
@ -36,13 +30,13 @@ public class CmdAHome extends FCommand {
Faction faction = target.getFaction(); Faction faction = target.getFaction();
if (faction.hasHome()) { if (faction.hasHome()) {
target.getPlayer().teleport(faction.getHome(), PlayerTeleportEvent.TeleportCause.PLUGIN); target.getPlayer().teleport(faction.getHome(), PlayerTeleportEvent.TeleportCause.PLUGIN);
msg(TL.COMMAND_AHOME_SUCCESS, target.getName()); context.msg(TL.COMMAND_AHOME_SUCCESS, target.getName());
target.msg(TL.COMMAND_AHOME_TARGET); target.msg(TL.COMMAND_AHOME_TARGET);
} else { } else {
msg(TL.COMMAND_AHOME_NOHOME, target.getName()); context.msg(TL.COMMAND_AHOME_NOHOME, target.getName());
} }
} else { } else {
msg(TL.COMMAND_AHOME_OFFLINE, target.getName()); context.msg(TL.COMMAND_AHOME_OFFLINE, target.getName());
} }
} }

View File

@ -8,7 +8,6 @@ import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
public class CmdAdmin extends FCommand { public class CmdAdmin extends FCommand {
@ -19,52 +18,39 @@ public class CmdAdmin extends FCommand {
this.aliases.add("leader"); this.aliases.add("leader");
this.aliases.add("setleader"); this.aliases.add("setleader");
this.requiredArgs.add("player name"); this.requiredArgs.add("player");
this.permission = Permission.ADMIN.node; this.requirements = new CommandRequirements.Builder(Permission.ADMIN).build();
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer fyou = this.argAsBestFPlayerMatch(0); // Allows admins bypass this.
if (fyou == null || fyou.getFaction().isWarZone() || fyou.getFaction().isWilderness() || fyou.getFaction().isSafeZone()) { if (!context.fPlayer.isAdminBypassing() && !context.fPlayer.getRole().equals(Role.LEADER)) {
context.msg(TL.COMMAND_ADMIN_NOTADMIN);
return;
}
FPlayer fyou = context.argAsBestFPlayerMatch(0);
if (fyou == null) {
return; return;
} }
boolean permAny = Permission.ADMIN_ANY.has(sender, false); boolean permAny = Permission.ADMIN_ANY.has(context.sender, false);
Faction targetFaction = fyou.getFaction(); Faction targetFaction = fyou.getFaction();
if (fyou.isAlt()) { if (targetFaction != context.faction && !permAny) {
msg(ChatColor.RED + "You can not promote alt accounts."); context.msg(TL.COMMAND_ADMIN_NOTMEMBER, fyou.describeTo(context.fPlayer, true));
return; return;
} }
if (targetFaction != myFaction && !permAny) { if (fyou == context.fPlayer && !permAny) {
msg(TL.COMMAND_ADMIN_NOTMEMBER, fyou.describeTo(fme, true)); context.msg(TL.COMMAND_ADMIN_TARGETSELF);
return;
}
if (fme != null && fme.getRole() != Role.LEADER && !permAny) {
msg(TL.COMMAND_ADMIN_NOTADMIN);
return;
}
if (fyou == fme && !permAny) {
msg(TL.COMMAND_ADMIN_TARGETSELF);
return; return;
} }
// only perform a FPlayerJoinEvent when newLeader isn't actually in the faction // only perform a FPlayerJoinEvent when newLeader isn't actually in the faction
if (fyou.getFaction() != targetFaction) { if (fyou.getFaction() != targetFaction) {
FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(me), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER); FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
@ -73,16 +59,11 @@ public class CmdAdmin extends FCommand {
FPlayer admin = targetFaction.getFPlayerAdmin(); FPlayer admin = targetFaction.getFPlayerAdmin();
if (fyou == admin && fyou.getFaction().getSize() == 1) {
msg(TL.COMMAND_ADMIN_NOMEMBERS);
return;
}
// if target player is currently admin, demote and replace him // if target player is currently admin, demote and replace him
if (fyou == admin) { if (fyou == admin) {
targetFaction.promoteNewLeader(); targetFaction.promoteNewLeader();
msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(fme, true)); context.msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(context.fPlayer, true));
fyou.msg(TL.COMMAND_ADMIN_DEMOTED, senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fyou, true)); fyou.msg(TL.COMMAND_ADMIN_DEMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fyou, true));
return; return;
} }
@ -91,11 +72,11 @@ public class CmdAdmin extends FCommand {
admin.setRole(Role.COLEADER); admin.setRole(Role.COLEADER);
} }
fyou.setRole(Role.LEADER); fyou.setRole(Role.LEADER);
msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(fme, true)); context.msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(context.fPlayer, true));
// Inform all players // Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
fplayer.msg(TL.COMMAND_ADMIN_PROMOTED, senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true), fyou.describeTo(fplayer), targetFaction.describeTo(fplayer)); fplayer.msg(TL.COMMAND_ADMIN_PROMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true), fyou.describeTo(fplayer), targetFaction.describeTo(fplayer));
} }
} }

View File

@ -3,6 +3,9 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -15,30 +18,27 @@ public class CmdAnnounce extends FCommand {
this.aliases.add("announce"); this.aliases.add("announce");
this.requiredArgs.add("message"); this.requiredArgs.add("message");
this.errorOnToManyArgs = false;
this.permission = Permission.ANNOUNCE.node; this.requirements = new CommandRequirements.Builder(Permission.ANNOUNCE)
this.disableOnLock = false; .playerOnly()
this.disableOnSpam = false; .memberOnly()
.brigadier(AnnounceBrigadier.class)
senderMustBePlayer = true; .noErrorOnManyArgs()
senderMustBeMember = true; .build();
senderMustBeModerator = false;
senderMustBeColeader = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
String prefix = ChatColor.GREEN + myFaction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + me.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET; String prefix = ChatColor.GREEN + context.faction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + context.player.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET;
String message = StringUtils.join(args, " "); String message = StringUtils.join(context.args, " ");
for (Player player : myFaction.getOnlinePlayers()) { for (Player player : context.faction.getOnlinePlayers()) {
player.sendMessage(prefix + message); player.sendMessage(prefix + message);
} }
// Add for offline players. // Add for offline players.
for (FPlayer fp : myFaction.getFPlayersWhereOnline(false)) { for (FPlayer fp : context.faction.getFPlayersWhereOnline(false)) {
myFaction.addAnnouncement(fp, prefix + message); context.faction.addAnnouncement(fp, prefix + message);
} }
} }
@ -47,4 +47,11 @@ public class CmdAnnounce extends FCommand {
return TL.COMMAND_ANNOUNCE_DESCRIPTION; return TL.COMMAND_ANNOUNCE_DESCRIPTION;
} }
protected class AnnounceBrigadier implements BrigadierProvider {
@Override
public ArgumentBuilder<Object, ?> get(ArgumentBuilder<Object, ?> parent) {
return parent.then(RequiredArgumentBuilder.argument("message", StringArgumentType.greedyString()));
}
}
} }

View File

@ -1,16 +1,14 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.CommandVisibility; import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.zcore.MCommand;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import java.util.ArrayList; import java.util.ArrayList;
public class CmdAutoHelp extends MCommand<P> { public class CmdAutoHelp extends FCommand {
public CmdAutoHelp() { public CmdAutoHelp() {
super(P.p);
this.aliases.add("?"); this.aliases.add("?");
this.aliases.add("h"); this.aliases.add("h");
this.aliases.add("help"); this.aliases.add("help");
@ -21,22 +19,22 @@ public class CmdAutoHelp extends MCommand<P> {
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (context.commandChain.size() == 0) {
if (this.commandChain.size() == 0) {
return; return;
} }
MCommand<?> pcmd = this.commandChain.get(this.commandChain.size() - 1); FCommand pcmd = context.commandChain.get(context.commandChain.size() - 1);
ArrayList<String> lines = new ArrayList<>(pcmd.helpLong); ArrayList<String> lines = new ArrayList<>(pcmd.helpLong);
for (MCommand<?> scmd : pcmd.subCommands) { for (FCommand scmd : pcmd.subCommands) {
if (scmd.visibility == CommandVisibility.VISIBLE || (scmd.visibility == CommandVisibility.SECRET && scmd.validSenderPermissions(sender, false))) { if (scmd.visibility == CommandVisibility.VISIBLE) {
lines.add(scmd.getUseageTemplate(this.commandChain, true)); lines.add(scmd.getUseageTemplate(context, true));
} }
// TODO deal with other visibilities
} }
sendMessage(p.txt.getPage(lines, this.argAsInt(0, 1), TL.COMMAND_AUTOHELP_HELPFOR.toString() + pcmd.aliases.get(0) + "\"")); context.sendMessage(FactionsPlugin.getInstance().txt.getPage(lines, context.argAsInt(0, 1), TL.COMMAND_AUTOHELP_HELPFOR.toString() + pcmd.aliases.get(0) + "\""));
} }
@Override @Override

View File

@ -1,12 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.struct.BanInfo; import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Permission; 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.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -21,78 +19,63 @@ public class CmdBan extends FCommand {
this.requiredArgs.add("target"); this.requiredArgs.add("target");
this.permission = Permission.BAN.node; this.requirements = new CommandRequirements.Builder(Permission.BAN)
this.disableOnLock = true; .playerOnly()
this.disableOnSpam = false; .withAction(PermissableAction.BAN)
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// Adds bypass to admins and clean permission check
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.BAN);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "ban");
return;
}
}
// Good on permission checks. Now lets just ban the player. // Good on permission checks. Now lets just ban the player.
FPlayer target = argAsFPlayer(0); FPlayer target = context.argAsFPlayer(0);
if (target == null) { if (target == null) {
return; // the above method sends a message if fails to find someone. return; // the above method sends a message if fails to find someone.
} }
if (fme == target) { if (context.fPlayer == target) {
// You may not ban yourself // You may not ban yourself
fme.msg(TL.COMMAND_BAN_SELF); context.msg(TL.COMMAND_BAN_SELF);
return; return;
} else if (target.getFaction() == myFaction && target.getRole().value >= fme.getRole().value) { } else if (target.getFaction() == context.faction && target.getRole().value >= context.fPlayer.getRole().value) {
// You may not ban someone that has same or higher faction rank // You may not ban someone that has same or higher faction rank
fme.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName()); context.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName());
return; return;
} }
for (BanInfo banInfo : myFaction.getBannedPlayers()) { for (BanInfo banInfo : context.faction.getBannedPlayers()) {
if (banInfo.getBanned().equals(target.getId())) { if (banInfo.getBanned().equals(target.getId())) {
msg(TL.COMMAND_BAN_ALREADYBANNED); context.msg(TL.COMMAND_BAN_ALREADYBANNED);
return; return;
} }
} }
// Ban the user. // Ban the user.
myFaction.ban(target, fme); context.faction.ban(target, context.fPlayer);
myFaction.deinvite(target); // can't hurt context.faction.deinvite(target); // can't hurt
// If in same Faction, lets make sure to kick them and throw an event. // If in same Faction, lets make sure to kick them and throw an event.
if (target.getFaction() == myFaction) { if (target.getFaction() == context.faction) {
FPlayerLeaveEvent event = new FPlayerLeaveEvent(target, myFaction, FPlayerLeaveEvent.PlayerLeaveReason.BANNED); FPlayerLeaveEvent event = new FPlayerLeaveEvent(target, context.faction, FPlayerLeaveEvent.PlayerLeaveReason.BANNED);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
// if someone cancels a ban, we'll get people complaining here. So lets log it. // if someone cancels a ban, we'll get people complaining here. So lets log it.
P.p.log(Level.WARNING, "Attempted to ban {0} but someone cancelled the kick event. This isn't good.", target.getName()); FactionsPlugin.getInstance().log(Level.WARNING, "Attempted to ban {0} but someone cancelled the kick event. This isn't good.", target.getName());
return; return;
} }
// Didn't get cancelled so remove them and reset their invite. // Didn't get cancelled so remove them and reset their invite.
myFaction.removeFPlayer(target); context.faction.removeFPlayer(target);
target.resetFactionData(); target.resetFactionData();
} }
// Lets inform the people! // Lets inform the people!
target.msg(TL.COMMAND_BAN_TARGET, myFaction.getTag(target.getFaction())); target.msg(TL.COMMAND_BAN_TARGET, context.faction.getTag(target.getFaction()));
myFaction.msg(TL.COMMAND_BAN_BANNED, fme.getName(), target.getName()); context.faction.msg(TL.COMMAND_BAN_BANNED, context.fPlayer.getName(), target.getName());
} }
@Override @Override

View File

@ -21,35 +21,31 @@ public class CmdBanlist extends FCommand {
this.optionalArgs.put("faction", "faction"); this.optionalArgs.put("faction", "faction");
this.permission = Permission.BAN.node; this.requirements = new CommandRequirements.Builder(Permission.BAN)
this.disableOnLock = true; .playerOnly()
this.disableOnSpam = false; .memberOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Faction target = myFaction; Faction target = context.faction;
if (!args.isEmpty()) { if (!context.args.isEmpty()) {
target = argAsFaction(0); target = context.argAsFaction(0);
} }
if (target == Factions.getInstance().getWilderness()) { if (target == Factions.getInstance().getWilderness()) {
sender.sendMessage(TL.COMMAND_BANLIST_NOFACTION.toString()); context.sender.sendMessage(TL.COMMAND_BANLIST_NOFACTION.toString());
return; return;
} }
if (target == null) { if (target == null) {
sender.sendMessage(TL.COMMAND_BANLIST_INVALID.format(argAsString(0))); context.sender.sendMessage(TL.COMMAND_BANLIST_INVALID.format(context.argAsString(0)));
return; return;
} }
List<String> lines = new ArrayList<>(); List<String> lines = new ArrayList<>();
lines.add(TL.COMMAND_BANLIST_HEADER.format(target.getBannedPlayers().size(), target.getTag(myFaction))); lines.add(TL.COMMAND_BANLIST_HEADER.format(target.getBannedPlayers().size(), target.getTag(context.faction)));
int i = 1; int i = 1;
for (BanInfo info : target.getBannedPlayers()) { for (BanInfo info : target.getBannedPlayers()) {
@ -62,7 +58,7 @@ public class CmdBanlist extends FCommand {
} }
for (String s : lines) { for (String s : lines) {
fme.sendMessage(s); context.fPlayer.getPlayer().sendMessage(s);
} }
} }

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.XMaterial; import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -20,50 +20,45 @@ public class CmdBanner extends FCommand {
this.aliases.add("banner"); this.aliases.add("banner");
this.aliases.add("warbanner"); this.aliases.add("warbanner");
this.permission = Permission.BANNER.node; this.requirements = new CommandRequirements.Builder(Permission.BANNER)
this.disableOnLock = false; .playerOnly()
.memberOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fbanners.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Enabled")) {
msg(TL.COMMAND_BANNER_DISABLED); context.msg(TL.COMMAND_BANNER_DISABLED);
return; return;
} }
if (!fme.hasMoney(P.p.getConfig().getInt("fbanners.Banner-Cost", 5000))) { if (!context.fPlayer.hasMoney(FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000))) {
msg(TL.COMMAND_BANNER_NOTENOUGHMONEY); context.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
return; return;
} }
takeMoney(fme, P.p.getConfig().getInt("fbanners.Banner-Cost", 5000)); takeMoney(context.fPlayer, FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000));
//ItemStack warBanner = P.p.createItem(Material.BANNER, 1, (short) 1, P.p.getConfig().getString("fbanners.Item.Name"), P.p.getConfig().getStringList("fbanners.Item.Lore")); //ItemStack warBanner = FactionsPlugin.getInstance().createItem(Material.BANNER, 1, (short) 1, FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"), FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore"));
//BannerMeta bannerMeta = (BannerMeta) warBanner.getItemMeta(); //BannerMeta bannerMeta = (BannerMeta) warBanner.getItemMeta();
ItemStack warBanner = fme.getFaction().getBanner(); ItemStack warBanner = context.fPlayer.getFaction().getBanner();
if (warBanner != null) { if (warBanner != null) {
ItemMeta warmeta = warBanner.getItemMeta(); ItemMeta warmeta = warBanner.getItemMeta();
warmeta.setDisplayName(P.p.color(P.p.getConfig().getString("fbanners.Item.Name"))); warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name")));
warmeta.setLore(P.p.colorList(P.p.getConfig().getStringList("fbanners.Item.Lore"))); warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")));
warBanner.setItemMeta(warmeta); warBanner.setItemMeta(warmeta);
} else { } else {
warBanner = P.p.createItem(XMaterial.BLACK_BANNER.parseMaterial(), 1, (short) 1, P.p.getConfig().getString("fbanners.Item.Name"), P.p.getConfig().getStringList("fbanners.Item.Lore")); warBanner = FactionsPlugin.getInstance().createItem(XMaterial.BLACK_BANNER.parseMaterial(), 1, (short) 1, FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"), FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore"));
} }
fme.msg(TL.COMMAND_BANNER_SUCCESS); context.msg(TL.COMMAND_BANNER_SUCCESS);
warBanner.setAmount(1); warBanner.setAmount(1);
me.getInventory().addItem(warBanner); context.player.getInventory().addItem(warBanner);
} }
public boolean hasMoney(FPlayer fme, int amt) { public boolean hasMoney(FPlayer fme, int amt) {
Economy econ = P.p.getEcon(); Economy econ = FactionsPlugin.getInstance().getEcon();
if (econ.getBalance(fme.getPlayer()) >= amt) { if (econ.getBalance(fme.getPlayer()) >= amt) {
return true; return true;
} else { } else {
@ -74,7 +69,7 @@ public class CmdBanner extends FCommand {
public void takeMoney(FPlayer fme, int amt) { public void takeMoney(FPlayer fme, int amt) {
if (hasMoney(fme, amt)) { if (hasMoney(fme, amt)) {
Economy econ = P.p.getEcon(); Economy econ = FactionsPlugin.getInstance().getEcon();
econ.withdrawPlayer(fme.getPlayer(), amt); econ.withdrawPlayer(fme.getPlayer(), amt);
fme.sendMessage(TL.COMMAND_BANNER_MONEYTAKE.toString().replace("{amount}", amt + "")); fme.sendMessage(TL.COMMAND_BANNER_MONEYTAKE.toString().replace("{amount}", amt + ""));
} }

View File

@ -15,34 +15,29 @@ public class CmdBoom extends FCommand {
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip"); this.optionalArgs.put("on/off", "flip");
this.permission = Permission.NO_BOOM.node; this.requirements = new CommandRequirements.Builder(Permission.NO_BOOM)
this.disableOnLock = true; .playerOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!myFaction.isPeaceful()) { if (!context.faction.isPeaceful()) {
fme.msg(TL.COMMAND_BOOM_PEACEFULONLY); context.msg(TL.COMMAND_BOOM_PEACEFULONLY);
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostNoBoom, TL.COMMAND_BOOM_TOTOGGLE, TL.COMMAND_BOOM_FORTOGGLE)) { if (!context.payForCommand(Conf.econCostNoBoom, TL.COMMAND_BOOM_TOTOGGLE, TL.COMMAND_BOOM_FORTOGGLE)) {
return; return;
} }
myFaction.setPeacefulExplosionsEnabled(this.argAsBool(0, !myFaction.getPeacefulExplosionsEnabled())); context.faction.setPeacefulExplosionsEnabled(context.argAsBool(0, !context.faction.getPeacefulExplosionsEnabled()));
String enabled = myFaction.noExplosionsInTerritory() ? TL.GENERIC_DISABLED.toString() : TL.GENERIC_ENABLED.toString(); String enabled = context.faction.noExplosionsInTerritory() ? TL.GENERIC_DISABLED.toString() : TL.GENERIC_ENABLED.toString();
// Inform // Inform
myFaction.msg(TL.COMMAND_BOOM_ENABLED, fme.describeTo(myFaction), enabled); context.faction.msg(TL.COMMAND_BOOM_ENABLED, context.fPlayer.describeTo(context.faction), enabled);
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -13,27 +13,22 @@ public class CmdBypass extends FCommand {
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip"); this.optionalArgs.put("on/off", "flip");
this.permission = Permission.BYPASS.node; this.requirements = new CommandRequirements.Builder(Permission.BYPASS)
this.disableOnLock = false; .playerOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
fme.setIsAdminBypassing(this.argAsBool(0, !fme.isAdminBypassing())); context.fPlayer.setIsAdminBypassing(context.argAsBool(0, !context.fPlayer.isAdminBypassing()));
// TODO: Move this to a transient field in the model?? // TODO: Move this to a transient field in the model??
if (fme.isAdminBypassing()) { if (context.fPlayer.isAdminBypassing()) {
fme.msg(TL.COMMAND_BYPASS_ENABLE.toString()); context.fPlayer.msg(TL.COMMAND_BYPASS_ENABLE.toString());
P.p.log(fme.getName() + TL.COMMAND_BYPASS_ENABLELOG.toString()); FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_BYPASS_ENABLELOG.toString());
} else { } else {
fme.msg(TL.COMMAND_BYPASS_DISABLE.toString()); context.fPlayer.msg(TL.COMMAND_BYPASS_DISABLE.toString());
P.p.log(fme.getName() + TL.COMMAND_BYPASS_DISABLELOG.toString()); FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_BYPASS_DISABLELOG.toString());
} }
} }

View File

@ -5,6 +5,8 @@ import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
public class CmdChat extends FCommand { public class CmdChat extends FCommand {
@ -16,33 +18,29 @@ public class CmdChat extends FCommand {
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("mode", "next"); this.optionalArgs.put("mode", "next");
this.permission = Permission.CHAT.node; this.requirements = new CommandRequirements.Builder(Permission.CHAT)
this.disableOnLock = false; .playerOnly()
.memberOnly()
.brigadier(ChatBrigadier.class)
senderMustBePlayer = true; .build();
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!Conf.factionOnlyChat) { if (!Conf.factionOnlyChat) {
msg(TL.COMMAND_CHAT_DISABLED.toString()); context.msg(TL.COMMAND_CHAT_DISABLED.toString());
return; return;
} }
String modeString = this.argAsString(0); String modeString = context.argAsString(0);
ChatMode modeTarget = fme.getChatMode().getNext(); ChatMode modeTarget = context.fPlayer.getChatMode().getNext();
if (modeString != null) { if (modeString != null) {
modeString = modeString.toLowerCase(); modeString = modeString.toLowerCase();
// Only allow Mods and higher rank to switch to this channel. // Only allow Mods and higher rank to switch to this channel.
if (modeString.startsWith("m")) { if (modeString.startsWith("m")) {
if (!fme.getRole().isAtLeast(Role.MODERATOR)) { if (!context.fPlayer.getRole().isAtLeast(Role.MODERATOR)) {
msg(TL.COMMAND_CHAT_MOD_ONLY); context.msg(TL.COMMAND_CHAT_MOD_ONLY);
return; return;
} else modeTarget = ChatMode.MOD; } else modeTarget = ChatMode.MOD;
} else if (modeString.startsWith("p")) { } else if (modeString.startsWith("p")) {
@ -54,28 +52,28 @@ public class CmdChat extends FCommand {
} else if (modeString.startsWith("t")) { } else if (modeString.startsWith("t")) {
modeTarget = ChatMode.TRUCE; modeTarget = ChatMode.TRUCE;
} else { } else {
msg(TL.COMMAND_CHAT_INVALIDMODE); context.msg(TL.COMMAND_CHAT_INVALIDMODE);
return; return;
} }
} }
fme.setChatMode(modeTarget); context.fPlayer.setChatMode(modeTarget);
switch (fme.getChatMode()) { switch (context.fPlayer.getChatMode()) {
case MOD: case MOD:
msg(TL.COMMAND_CHAT_MODE_MOD); context.msg(TL.COMMAND_CHAT_MODE_MOD);
break; break;
case PUBLIC: case PUBLIC:
msg(TL.COMMAND_CHAT_MODE_PUBLIC); context.msg(TL.COMMAND_CHAT_MODE_PUBLIC);
break; break;
case ALLIANCE: case ALLIANCE:
msg(TL.COMMAND_CHAT_MODE_ALLIANCE); context.msg(TL.COMMAND_CHAT_MODE_ALLIANCE);
break; break;
case TRUCE: case TRUCE:
msg(TL.COMMAND_CHAT_MODE_TRUCE); context.msg(TL.COMMAND_CHAT_MODE_TRUCE);
break; break;
default: default:
msg(TL.COMMAND_CHAT_MODE_FACTION); context.msg(TL.COMMAND_CHAT_MODE_FACTION);
break; break;
} }
} }
@ -84,4 +82,16 @@ public class CmdChat extends FCommand {
public TL getUsageTranslation() { public TL getUsageTranslation() {
return TL.COMMAND_CHAT_DESCRIPTION; return TL.COMMAND_CHAT_DESCRIPTION;
} }
protected class ChatBrigadier implements BrigadierProvider {
@Override
public ArgumentBuilder<Object, ?> get(ArgumentBuilder<Object, ?> parent) {
return parent.then(LiteralArgumentBuilder.literal("public"))
.then(LiteralArgumentBuilder.literal("mod"))
.then(LiteralArgumentBuilder.literal("alliance"))
.then(LiteralArgumentBuilder.literal("faction"))
.then(LiteralArgumentBuilder.literal("truce"));
}
}
} }

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -12,26 +12,21 @@ public class CmdChatSpy extends FCommand {
this.optionalArgs.put("on/off", "flip"); this.optionalArgs.put("on/off", "flip");
this.permission = Permission.CHATSPY.node; this.requirements = new CommandRequirements.Builder(Permission.CHATSPY)
this.disableOnLock = false; .playerOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
fme.setSpyingChat(this.argAsBool(0, !fme.isSpyingChat())); context.fPlayer.setSpyingChat(context.argAsBool(0, !context.fPlayer.isSpyingChat()));
if (fme.isSpyingChat()) { if (context.fPlayer.isSpyingChat()) {
fme.msg(TL.COMMAND_CHATSPY_ENABLE); context.msg(TL.COMMAND_CHATSPY_ENABLE);
P.p.log(fme.getName() + TL.COMMAND_CHATSPY_ENABLELOG.toString()); FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CHATSPY_ENABLELOG.toString());
} else { } else {
fme.msg(TL.COMMAND_CHATSPY_DISABLE); context.msg(TL.COMMAND_CHATSPY_DISABLE);
P.p.log(fme.getName() + TL.COMMAND_CHATSPY_DISABLELOG.toString()); FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CHATSPY_DISABLELOG.toString());
} }
} }

View File

@ -14,46 +14,45 @@ public class CmdCheckpoint extends FCommand {
this.optionalArgs.put("set", ""); this.optionalArgs.put("set", "");
this.permission = Permission.CHECKPOINT.node; this.requirements = new CommandRequirements.Builder(Permission.CHECKPOINT)
this.disableOnLock = false; .playerOnly()
.memberOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("checkpoints.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("checkpoints.Enabled")) {
fme.msg(TL.COMMAND_CHECKPOINT_DISABLED); context.msg(TL.COMMAND_CHECKPOINT_DISABLED);
return; return;
} }
if (args.size() == 1) { if (context.args.size() == 1) {
FLocation myLocation = new FLocation(fme.getPlayer().getLocation()); FLocation myLocation = new FLocation(context.player.getLocation());
Faction myLocFaction = Board.getInstance().getFactionAt(myLocation); Faction myLocFaction = Board.getInstance().getFactionAt(myLocation);
if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == fme.getFaction()) { if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == context.faction) {
fme.getFaction().setCheckpoint(fme.getPlayer().getLocation()); context.faction.setCheckpoint(context.player.getLocation());
fme.msg(TL.COMMAND_CHECKPOINT_SET); context.msg(TL.COMMAND_CHECKPOINT_SET);
return; return;
} else { } else {
fme.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION); context.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION);
return; return;
} }
} }
if (fme.getFaction().getCheckpoint() == null) { if (context.faction.getCheckpoint() == null) {
fme.msg(TL.COMMAND_CHECKPOINT_NOT_SET); context.msg(TL.COMMAND_CHECKPOINT_NOT_SET);
return; return;
} }
FLocation checkLocation = new FLocation(fme.getFaction().getCheckpoint()); FLocation checkLocation = new FLocation(context.faction.getCheckpoint());
Faction checkfaction = Board.getInstance().getFactionAt(checkLocation); Faction checkfaction = Board.getInstance().getFactionAt(checkLocation);
if (checkfaction.getId().equals(Factions.getInstance().getWilderness().getId()) || checkfaction.getId().equals(fme.getFaction().getId())) { if (checkfaction.getId().equals(Factions.getInstance().getWilderness().getId()) || checkfaction.getId().equals(context.faction.getId())) {
fme.msg(TL.COMMAND_CHECKPOINT_GO); context.msg(TL.COMMAND_CHECKPOINT_GO);
this.doWarmUp(WarmUpUtil.Warmup.CHECKPOINT, TL.WARMUPS_NOTIFY_TELEPORT, "Checkpoint", () -> fme.getPlayer().teleport(fme.getFaction().getCheckpoint()), this.p.getConfig().getLong("warmups.f-checkpoint", 0));
context.doWarmUp(WarmUpUtil.Warmup.CHECKPOINT, TL.WARMUPS_NOTIFY_TELEPORT, "Checkpoint", () -> {
context.player.teleport(context.faction.getCheckpoint());
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-checkpoint", 0));
} else { } else {
fme.msg(TL.COMMAND_CHECKPOINT_CLAIMED); context.msg(TL.COMMAND_CHECKPOINT_CLAIMED);
} }

View File

@ -18,61 +18,51 @@ public class CmdColeader extends FCommand {
this.aliases.add("setco"); this.aliases.add("setco");
this.optionalArgs.put("player name", "name"); this.optionalArgs.put("player name", "name");
//this.optionalArgs.put("", "");
this.permission = Permission.COLEADER.node; this.requirements = new CommandRequirements.Builder(Permission.COLEADER)
this.disableOnLock = true; .memberOnly()
.withRole(Role.LEADER)
.build();
senderMustBePlayer = false;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = true;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = context.argAsBestFPlayerMatch(0);
if (you == null) { if (you == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_COLEADER_CANDIDATES.toString()).color(ChatColor.GOLD); FancyMessage msg = new FancyMessage(TL.COMMAND_COLEADER_CANDIDATES.toString()).color(ChatColor.GOLD);
for (FPlayer player : myFaction.getFPlayersWhereRole(Role.NORMAL)) { for (FPlayer player : context.faction.getFPlayersWhereRole(Role.NORMAL)) {
String s = player.getName(); String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " coleader " + s); msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " coleader " + s);
} }
for (FPlayer player : myFaction.getFPlayersWhereRole(Role.MODERATOR)) { for (FPlayer player : context.faction.getFPlayersWhereRole(Role.MODERATOR)) {
String s = player.getName(); String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " coleader " + s); msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " coleader " + s);
} }
sendFancyMessage(msg); context.sendFancyMessage(msg);
return; return;
} }
boolean permAny = Permission.COLEADER_ANY.has(sender, false); boolean permAny = Permission.COLEADER_ANY.has(context.sender, false);
Faction targetFaction = you.getFaction(); Faction targetFaction = you.getFaction();
if (you.isAlt()) { if (targetFaction != context.faction && !permAny) {
msg(ChatColor.RED + "You can not promote alt accounts."); context.msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(context.fPlayer, true));
return; return;
} }
if (targetFaction != myFaction && !permAny) { if (context.fPlayer != null && context.fPlayer.getRole() != Role.LEADER && !permAny) {
msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(fme, true)); context.msg(TL.COMMAND_COLEADER_NOTADMIN);
return; return;
} }
if (fme != null && fme.getRole() != Role.LEADER && !permAny) { if (you == context.fPlayer && !permAny) {
msg(TL.COMMAND_COLEADER_NOTADMIN); context.msg(TL.COMMAND_COLEADER_SELF);
return;
}
if (you == fme && !permAny) {
msg(TL.COMMAND_COLEADER_SELF);
return; return;
} }
if (you.getRole() == Role.LEADER) { if (you.getRole() == Role.LEADER) {
msg(TL.COMMAND_COLEADER_TARGETISADMIN); context.msg(TL.COMMAND_COLEADER_TARGETISADMIN);
return; return;
} }
@ -80,12 +70,12 @@ public class CmdColeader extends FCommand {
// Revoke // Revoke
you.setRole(Role.MODERATOR); you.setRole(Role.MODERATOR);
targetFaction.msg(TL.COMMAND_COLEADER_REVOKED, you.describeTo(targetFaction, true)); targetFaction.msg(TL.COMMAND_COLEADER_REVOKED, you.describeTo(targetFaction, true));
msg(TL.COMMAND_COLEADER_REVOKES, you.describeTo(fme, true)); context.msg(TL.COMMAND_COLEADER_REVOKES, you.describeTo(context.fPlayer, true));
} else { } else {
// Give // Give
you.setRole(Role.COLEADER); you.setRole(Role.COLEADER);
targetFaction.msg(TL.COMMAND_COLEADER_PROMOTED, you.describeTo(targetFaction, true)); targetFaction.msg(TL.COMMAND_COLEADER_PROMOTED, you.describeTo(targetFaction, true));
msg(TL.COMMAND_COLEADER_PROMOTES, you.describeTo(fme, true)); context.msg(TL.COMMAND_COLEADER_PROMOTES, you.describeTo(context.fPlayer, true));
} }
} }
@ -94,3 +84,4 @@ public class CmdColeader extends FCommand {
return TL.COMMAND_COLEADER_DESCRIPTION; return TL.COMMAND_COLEADER_DESCRIPTION;
} }
} }

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -24,20 +24,14 @@ public class CmdConfig extends FCommand {
this.requiredArgs.add("setting"); this.requiredArgs.add("setting");
this.requiredArgs.add("value"); this.requiredArgs.add("value");
this.errorOnToManyArgs = false;
this.permission = Permission.CONFIG.node; this.requirements = new CommandRequirements.Builder(Permission.CONFIG)
this.disableOnLock = true; .noErrorOnManyArgs()
.build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// store a lookup map of lowercase field names paired with proper capitalization field names // store a lookup map of lowercase field names paired with proper capitalization field names
// that way, if the person using this command messes up the capitalization, we can fix that // that way, if the person using this command messes up the capitalization, we can fix that
if (properFieldNames.isEmpty()) { if (properFieldNames.isEmpty()) {
@ -47,22 +41,22 @@ public class CmdConfig extends FCommand {
} }
} }
String field = this.argAsString(0).toLowerCase(); String field = context.argAsString(0).toLowerCase();
if (field.startsWith("\"") && field.endsWith("\"")) { if (field.startsWith("\"") && field.endsWith("\"")) {
field = field.substring(1, field.length() - 1); field = field.substring(1, field.length() - 1);
} }
String fieldName = properFieldNames.get(field); String fieldName = properFieldNames.get(field);
if (fieldName == null || fieldName.isEmpty()) { if (fieldName == null || fieldName.isEmpty()) {
msg(TL.COMMAND_CONFIG_NOEXIST, field); context.msg(TL.COMMAND_CONFIG_NOEXIST, field);
return; return;
} }
String success; String success;
StringBuilder value = new StringBuilder(args.get(1)); StringBuilder value = new StringBuilder(context.args.get(1));
for (int i = 2; i < args.size(); i++) { for (int i = 2; i < context.args.size(); i++) {
value.append(' ').append(args.get(i)); value.append(' ').append(context.args.get(i));
} }
try { try {
@ -70,7 +64,7 @@ public class CmdConfig extends FCommand {
// boolean // boolean
if (target.getType() == boolean.class) { if (target.getType() == boolean.class) {
boolean targetValue = this.strAsBool(value.toString()); boolean targetValue = context.strAsBool(value.toString());
target.setBoolean(null, targetValue); target.setBoolean(null, targetValue);
if (targetValue) { if (targetValue) {
@ -87,7 +81,7 @@ public class CmdConfig extends FCommand {
target.setInt(null, intVal); target.setInt(null, intVal);
success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + intVal + "."; success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + intVal + ".";
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
sendMessage(TL.COMMAND_CONFIG_INTREQUIRED.format(fieldName)); context.sendMessage(TL.COMMAND_CONFIG_INTREQUIRED.format(fieldName));
return; return;
} }
} }
@ -99,7 +93,7 @@ public class CmdConfig extends FCommand {
target.setLong(null, longVal); target.setLong(null, longVal);
success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + longVal + "."; success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + longVal + ".";
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
sendMessage(TL.COMMAND_CONFIG_LONGREQUIRED.format(fieldName)); context.sendMessage(TL.COMMAND_CONFIG_LONGREQUIRED.format(fieldName));
return; return;
} }
} }
@ -111,7 +105,7 @@ public class CmdConfig extends FCommand {
target.setDouble(null, doubleVal); target.setDouble(null, doubleVal);
success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + doubleVal + "."; success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + doubleVal + ".";
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
sendMessage(TL.COMMAND_CONFIG_DOUBLEREQUIRED.format(fieldName)); context.sendMessage(TL.COMMAND_CONFIG_DOUBLEREQUIRED.format(fieldName));
return; return;
} }
} }
@ -123,7 +117,7 @@ public class CmdConfig extends FCommand {
target.setFloat(null, floatVal); target.setFloat(null, floatVal);
success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + floatVal + "."; success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + floatVal + ".";
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
sendMessage(TL.COMMAND_CONFIG_FLOATREQUIRED.format(fieldName)); context.sendMessage(TL.COMMAND_CONFIG_FLOATREQUIRED.format(fieldName));
return; return;
} }
} }
@ -143,7 +137,7 @@ public class CmdConfig extends FCommand {
} }
if (newColor == null) { if (newColor == null) {
sendMessage(TL.COMMAND_CONFIG_INVALID_COLOUR.format(fieldName, value.toString().toUpperCase())); context.sendMessage(TL.COMMAND_CONFIG_INVALID_COLOUR.format(fieldName, value.toString().toUpperCase()));
return; return;
} }
target.set(null, newColor); target.set(null, newColor);
@ -157,7 +151,7 @@ public class CmdConfig extends FCommand {
// not a Set, somehow, and that should be the only collection we're using in Conf.java // not a Set, somehow, and that should be the only collection we're using in Conf.java
if (targSet.getRawType() != Set.class) { if (targSet.getRawType() != Set.class) {
sendMessage(TL.COMMAND_CONFIG_INVALID_COLLECTION.format(fieldName)); context.sendMessage(TL.COMMAND_CONFIG_INVALID_COLLECTION.format(fieldName));
return; return;
} }
@ -170,7 +164,7 @@ public class CmdConfig extends FCommand {
} }
if (newMat == null) { if (newMat == null) {
sendMessage(TL.COMMAND_CONFIG_INVALID_MATERIAL.format(fieldName, value.toString().toUpperCase())); context.sendMessage(TL.COMMAND_CONFIG_INVALID_MATERIAL.format(fieldName, value.toString().toUpperCase()));
return; return;
} }
@ -210,31 +204,31 @@ public class CmdConfig extends FCommand {
// Set of unknown type // Set of unknown type
else { else {
sendMessage(TL.COMMAND_CONFIG_INVALID_TYPESET.format(fieldName)); context.sendMessage(TL.COMMAND_CONFIG_INVALID_TYPESET.format(fieldName));
return; return;
} }
} }
// unknown type // unknown type
else { else {
sendMessage(TL.COMMAND_CONFIG_ERROR_TYPE.format(fieldName, target.getClass().getName())); context.sendMessage(TL.COMMAND_CONFIG_ERROR_TYPE.format(fieldName, target.getClass().getName()));
return; return;
} }
} catch (NoSuchFieldException ex) { } catch (NoSuchFieldException ex) {
sendMessage(TL.COMMAND_CONFIG_ERROR_MATCHING.format(fieldName)); context.sendMessage(TL.COMMAND_CONFIG_ERROR_MATCHING.format(fieldName));
return; return;
} catch (IllegalAccessException ex) { } catch (IllegalAccessException ex) {
sendMessage(TL.COMMAND_CONFIG_ERROR_SETTING.format(fieldName, value.toString())); context.sendMessage(TL.COMMAND_CONFIG_ERROR_SETTING.format(fieldName, value.toString()));
return; return;
} }
if (!success.isEmpty()) { if (!success.isEmpty()) {
if (sender instanceof Player) { if (context.sender instanceof Player) {
sendMessage(success); context.sendMessage(success);
P.p.log(success + TL.COMMAND_CONFIG_LOG.format((Player) sender)); FactionsPlugin.getInstance().log(success + TL.COMMAND_CONFIG_LOG.format((Player) context.sender));
} else // using P.p.log() instead of sendMessage if run from server console so that "[Factions v#.#.#]" is prepended in server log } else // using FactionsPlugin.getInstance().log() instead of sendMessage if run from server console so that "[Factions v#.#.#]" is prepended in server log
{ {
P.p.log(success); FactionsPlugin.getInstance().log(success);
} }
} }
// save change to disk // save change to disk

View File

@ -11,26 +11,26 @@ public class CmdConvert extends FCommand {
public CmdConvert() { public CmdConvert() {
this.aliases.add("convert"); this.aliases.add("convert");
this.permission = Permission.CONVERT.node;
this.requiredArgs.add("[MYSQL|JSON]"); this.requiredArgs.add("[MYSQL|JSON]");
this.requirements = new CommandRequirements.Builder(Permission.CONVERT)
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!(this.sender instanceof ConsoleCommandSender)) { if (!(context.sender instanceof ConsoleCommandSender)) {
this.sender.sendMessage(TL.GENERIC_CONSOLEONLY.toString()); context.sender.sendMessage(TL.GENERIC_CONSOLEONLY.toString());
} }
Backend nb = Backend.valueOf(this.argAsString(0).toUpperCase()); Backend nb = Backend.valueOf(context.argAsString(0).toUpperCase());
if (nb == Conf.backEnd) { if (nb == Conf.backEnd) {
this.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_RUNNING.toString()); context.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_RUNNING.toString());
return; return;
} }
if (nb == Backend.JSON) { if (nb == Backend.JSON) {
FactionsJSON.convertTo(); FactionsJSON.convertTo();
} else { } else {
this.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_INVALID.toString()); context.sender.sendMessage(TL.COMMAND_CONVERT_BACKEND_INVALID.toString());
return; return;
} }
Conf.backEnd = nb; Conf.backEnd = nb;

View File

@ -12,23 +12,18 @@ public class CmdCoords extends FCommand {
this.aliases.add("coords"); this.aliases.add("coords");
this.aliases.add("coord"); this.aliases.add("coord");
this.permission = Permission.COORD.node; this.requirements = new CommandRequirements.Builder(Permission.COORD)
this.disableOnLock = true; .playerOnly()
.memberOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Location location = fme.getPlayer().getLocation(); Location location = context.player.getLocation();
String message = TL.COMMAND_COORDS_MESSAGE.toString().replace("{player}", fme.getPlayer().getDisplayName()).replace("{x}", (int) location.getX() + "") String message = TL.COMMAND_COORDS_MESSAGE.toString().replace("{player}", context.player.getDisplayName()).replace("{x}", (int) location.getX() + "")
.replace("{y}", (int) location.getY() + "").replace("{z}", (int) location.getZ() + "").replace("{world}", location.getWorld().getName()); .replace("{y}", (int) location.getY() + "").replace("{z}", (int) location.getZ() + "").replace("{world}", location.getWorld().getName());
for (FPlayer fPlayer : fme.getFaction().getFPlayers()) { for (FPlayer fPlayer : context.faction.getFPlayers()) {
fPlayer.sendMessage(message); fPlayer.sendMessage(message);
} }
} }

View File

@ -20,58 +20,46 @@ public class CmdCreate extends FCommand {
this.aliases.add("create"); this.aliases.add("create");
this.requiredArgs.add("faction tag"); this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.CREATE.node; this.requirements = new CommandRequirements.Builder(Permission.CREATE)
this.disableOnLock = true; .playerOnly()
this.disableOnSpam = true; .build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
String tag = this.argAsString(0); String tag = context.argAsString(0);
if (fme.hasFaction()) { if (context.fPlayer.hasFaction()) {
msg(TL.COMMAND_CREATE_MUSTLEAVE); context.msg(TL.COMMAND_CREATE_MUSTLEAVE);
return;
}
if (!fme.isCooldownEnded("create")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("create"));
return; return;
} }
if (Factions.getInstance().isTagTaken(tag)) { if (Factions.getInstance().isTagTaken(tag)) {
msg(TL.COMMAND_CREATE_INUSE); context.msg(TL.COMMAND_CREATE_INUSE);
return; return;
} }
ArrayList<String> tagValidationErrors = MiscUtil.validateTag(tag); ArrayList<String> tagValidationErrors = MiscUtil.validateTag(tag);
if (tagValidationErrors.size() > 0) { if (tagValidationErrors.size() > 0) {
sendMessage(tagValidationErrors); context.sendMessage(tagValidationErrors);
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE.toString())) { if (!context.canAffordCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE.toString())) {
return; return;
} }
// trigger the faction creation event (cancellable) // trigger the faction creation event (cancellable)
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag); FactionCreateEvent createEvent = new FactionCreateEvent(context.player, tag);
Bukkit.getServer().getPluginManager().callEvent(createEvent); Bukkit.getServer().getPluginManager().callEvent(createEvent);
if (createEvent.isCancelled()) { if (createEvent.isCancelled()) {
return; return;
} }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE, TL.COMMAND_CREATE_FORCREATE)) { if (!context.payForCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE, TL.COMMAND_CREATE_FORCREATE)) {
return; return;
} }
@ -79,7 +67,7 @@ public class CmdCreate extends FCommand {
// TODO: Why would this even happen??? Auto increment clash?? // TODO: Why would this even happen??? Auto increment clash??
if (faction == null) { if (faction == null) {
msg(TL.COMMAND_CREATE_ERROR); context.msg(TL.COMMAND_CREATE_ERROR);
return; return;
} }
@ -87,39 +75,29 @@ public class CmdCreate extends FCommand {
faction.setTag(tag); faction.setTag(tag);
// trigger the faction join event for the creator // trigger the faction join event for the creator
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(me), faction, FPlayerJoinEvent.PlayerJoinReason.CREATE); FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), faction, FPlayerJoinEvent.PlayerJoinReason.CREATE);
Bukkit.getServer().getPluginManager().callEvent(joinEvent); Bukkit.getServer().getPluginManager().callEvent(joinEvent);
// join event cannot be cancelled or you'll have an empty faction // join event cannot be cancelled or you'll have an empty faction
// finish setting up the FPlayer // finish setting up the FPlayer
fme.setFaction(faction, false); context.fPlayer.setFaction(faction, false);
// We should consider adding the role just AFTER joining the faction. // We should consider adding the role just AFTER joining the faction.
// That way we don't have to mess up deleting more stuff. // That way we don't have to mess up deleting more stuff.
// And prevent the user from being returned to NORMAL after deleting his old faction. // And prevent the user from being returned to NORMAL after deleting his old faction.
fme.setRole(Role.LEADER); context.fPlayer.setRole(Role.LEADER);
if (P.p.getConfig().getBoolean("faction-creation-broadcast", true)) { if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-creation-broadcast", true)) {
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
follower.msg(TL.COMMAND_CREATE_CREATED, fme.describeTo(follower, true), faction.getTag(follower)); follower.msg(TL.COMMAND_CREATE_CREATED, context.fPlayer.getName(), faction.getTag(follower));
} }
} }
msg(TL.COMMAND_CREATE_YOUSHOULD, p.cmdBase.cmdDescription.getUseageTemplate()); context.msg(TL.COMMAND_CREATE_YOUSHOULD, FactionsPlugin.getInstance().cmdBase.cmdDescription.getUseageTemplate(context));
if (Conf.econEnabled) Econ.setBalance(faction.getAccountId(), Conf.econFactionStartingBalance);
if (Conf.econEnabled)
Econ.setBalance(faction.getAccountId(), Conf.econFactionStartingBalance);
if (Conf.logFactionCreate) if (Conf.logFactionCreate)
P.p.log(fme.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag); FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag);
if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled"))
if (P.p.getConfig().getBoolean("fpaypal.Enabled")) context.msg(TL.COMMAND_PAYPALSET_CREATED);
this.fme.msg(TL.COMMAND_PAYPALSET_CREATED);
if (Conf.useCustomDefaultPermissions) faction.setDefaultPerms(); if (Conf.useCustomDefaultPermissions) faction.setDefaultPerms();
if (Conf.usePermissionHints) fme.msg(TL.COMMAND_HINT_PERMISSION); if (Conf.usePermissionHints) context.msg(TL.COMMAND_HINT_PERMISSION);
fme.setCooldown("create", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-create") * 1000));
} }
@Override @Override

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
@ -19,51 +20,59 @@ public class CmdDeinvite extends FCommand {
this.aliases.add("deinv"); this.aliases.add("deinv");
this.optionalArgs.put("player name", "name"); this.optionalArgs.put("player name", "name");
//this.optionalArgs.put("", "");
this.permission = Permission.DEINVITE.node; this.requirements = new CommandRequirements.Builder(Permission.DEINVITE)
this.disableOnLock = true; .memberOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer you = this.argAsBestFPlayerMatch(0);
if (!fme.isAdminBypassing()) { // Check if arg 0 == null do you don't have
Access access = myFaction.getAccess(fme, PermissableAction.INVITE); // `No player "null" could be found.` message.
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { if (context.args.get(0) == null) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
return;
}
}
if (you == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_DEINVITE_CANDEINVITE.toString()).color(ChatColor.GOLD); FancyMessage msg = new FancyMessage(TL.COMMAND_DEINVITE_CANDEINVITE.toString()).color(ChatColor.GOLD);
for (String id : myFaction.getInvites()) { for (String id : context.faction.getInvites()) {
FPlayer fp = FPlayers.getInstance().getById(id); FPlayer fp = FPlayers.getInstance().getById(id);
String name = fp != null ? fp.getName() : id; String name = fp != null ? fp.getName() : id;
msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_DEINVITE_CLICKTODEINVITE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name); msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_DEINVITE_CLICKTODEINVITE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name);
} }
sendFancyMessage(msg); context.sendFancyMessage(msg);
return; return;
} }
if (you.getFaction() == myFaction) { FPlayer you = context.argAsBestFPlayerMatch(0);
msg(TL.COMMAND_DEINVITE_ALREADYMEMBER, you.getName(), myFaction.getTag()); if (!context.fPlayer.isAdminBypassing()) {
msg(TL.COMMAND_DEINVITE_MIGHTWANT, p.cmdBase.cmdKick.getUseageTemplate(false)); 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 (you == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_DEINVITE_CANDEINVITE.toString()).color(ChatColor.GOLD);
for (String id : context.faction.getInvites()) {
FPlayer fp = FPlayers.getInstance().getById(id);
String name = fp != null ? fp.getName() : id;
msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_DEINVITE_CLICKTODEINVITE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name);
}
context.sendFancyMessage(msg);
return; return;
} }
myFaction.deinvite(you); if (you.getFaction() == context.faction) {
context.msg(TL.COMMAND_DEINVITE_ALREADYMEMBER, you.getName(), context.faction.getTag());
context.msg(TL.COMMAND_DEINVITE_MIGHTWANT, FactionsPlugin.getInstance().cmdBase.cmdKick.getUseageTemplate(context));
return;
}
you.msg(TL.COMMAND_DEINVITE_REVOKED, fme.describeTo(you), myFaction.describeTo(you)); context.faction.deinvite(you);
myFaction.msg(TL.COMMAND_DEINVITE_REVOKES, fme.describeTo(myFaction), you.describeTo(myFaction)); you.msg(TL.COMMAND_DEINVITE_REVOKED, context.fPlayer.describeTo(you), context.faction.describeTo(you));
context.faction.msg(TL.COMMAND_DEINVITE_REVOKES, context.fPlayer.describeTo(context.faction), you.describeTo(context.faction));
} }
@Override @Override
@ -72,3 +81,4 @@ public class CmdDeinvite extends FCommand {
} }
} }

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -13,29 +13,29 @@ public class CmdDelFWarp extends FCommand {
this.aliases.add("dw"); this.aliases.add("dw");
this.aliases.add("deletewarp"); this.aliases.add("deletewarp");
this.requiredArgs.add("warp name"); this.requiredArgs.add("warp name");
this.senderMustBeMember = true;
this.senderMustBeModerator = true;
this.senderMustBePlayer = true;
this.permission = Permission.SETWARP.node;
this.requirements = new CommandRequirements.Builder(Permission.SETWARP)
.playerOnly()
.memberOnly()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
String warp = argAsString(0); String warp = context.argAsString(0);
if (myFaction.isWarp(warp)) { if (context.faction.isWarp(warp)) {
if (!transact(fme)) { if (!transact(context.fPlayer, context)) {
return; return;
} }
myFaction.removeWarp(warp); context.faction.removeWarp(warp);
fme.msg(TL.COMMAND_DELFWARP_DELETED, warp); context.msg(TL.COMMAND_DELFWARP_DELETED, warp);
} else { } else {
fme.msg(TL.COMMAND_DELFWARP_INVALID, warp); context.msg(TL.COMMAND_DELFWARP_INVALID, warp);
} }
} }
private boolean transact(FPlayer player) { private boolean transact(FPlayer player, CommandContext context) {
return !P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(P.p.getConfig().getDouble("warp-cost.delwarp", 5), TL.COMMAND_DELFWARP_TODELETE.toString(), TL.COMMAND_DELFWARP_FORDELETE.toString()); return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.delwarp", 5), TL.COMMAND_DELFWARP_TODELETE.toString(), TL.COMMAND_DELFWARP_FORDELETE.toString());
} }
@Override @Override
@ -43,3 +43,4 @@ public class CmdDelFWarp extends FCommand {
return TL.COMMAND_DELFWARP_DESCRIPTION; return TL.COMMAND_DELFWARP_DESCRIPTION;
} }
} }

View File

@ -15,41 +15,35 @@ public class CmdDescription extends FCommand {
this.aliases.add("description"); this.aliases.add("description");
this.requiredArgs.add("desc"); this.requiredArgs.add("desc");
this.errorOnToManyArgs = false;
//this.optionalArgs
this.permission = Permission.DESCRIPTION.node; this.requirements = new CommandRequirements.Builder(Permission.DESCRIPTION)
this.disableOnLock = true; .playerOnly()
.memberOnly()
.noErrorOnManyArgs()
senderMustBePlayer = true; .build();
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostDesc, TL.COMMAND_DESCRIPTION_TOCHANGE, TL.COMMAND_DESCRIPTION_FORCHANGE)) { if (!context.payForCommand(Conf.econCostDesc, TL.COMMAND_DESCRIPTION_TOCHANGE, TL.COMMAND_DESCRIPTION_FORCHANGE)) {
return; return;
} }
// since "&" color tags seem to work even through plain old FPlayer.sendMessage() for some reason, we need to break those up // since "&" color tags seem to work even through plain old FPlayer.sendMessage() for some reason, we need to break those up
// And replace all the % because it messes with string formatting and this is easy way around that. // And replace all the % because it messes with string formatting and this is easy way around that.
myFaction.setDescription(TextUtil.implode(args, " ").replaceAll("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2")); context.faction.setDescription(TextUtil.implode(context.args, " ").replaceAll("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2"));
if (!Conf.broadcastDescriptionChanges) { if (!Conf.broadcastDescriptionChanges) {
fme.msg(TL.COMMAND_DESCRIPTION_CHANGED, myFaction.describeTo(fme)); context.msg(TL.COMMAND_DESCRIPTION_CHANGED, context.faction.describeTo(context.fPlayer));
fme.sendMessage(myFaction.getDescription()); context.sendMessage(context.faction.getDescription());
return; return;
} }
// Broadcast the description to everyone // Broadcast the description to everyone
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
fplayer.msg(TL.COMMAND_DESCRIPTION_CHANGES, myFaction.describeTo(fplayer)); fplayer.msg(TL.COMMAND_DESCRIPTION_CHANGES, context.faction.describeTo(fplayer));
fplayer.sendMessage(myFaction.getDescription()); // players can inject "&" or "`" or "<i>" or whatever in their description; &k is particularly interesting looking fplayer.sendMessage(context.faction.getDescription()); // players can inject "&" or "`" or "<i>" or whatever in their description; &k is particularly interesting looking
} }
} }

View File

@ -9,6 +9,7 @@ import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import java.util.HashMap; import java.util.HashMap;
@ -23,87 +24,71 @@ public class CmdDisband extends FCommand {
super(); super();
this.aliases.add("disband"); this.aliases.add("disband");
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours"); this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.DISBAND.node; this.requirements = new CommandRequirements.Builder(Permission.DISBAND)
this.disableOnLock = true; .build();
this.disableOnSpam = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// The faction, default to your own.. but null if console sender. // The faction, default to your own.. but null if console sender.
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); Faction faction = context.argAsFaction(0, context.fPlayer == null ? null : context.faction);
if (faction == null) { if (faction == null) return;
return;
}
boolean isMyFaction = context.fPlayer != null && faction == context.faction;
if (!fme.isCooldownEnded("disband")) { if (!isMyFaction) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("disband")); if (!Permission.DISBAND_ANY.has(context.sender, true)) {
return;
}
boolean isMyFaction = fme != null && faction == myFaction;
if (isMyFaction) {
if (!assertMinRole(Role.LEADER)) {
return;
}
} else {
if (!Permission.DISBAND_ANY.has(sender, true)) {
return; return;
} }
} }
if (fme != null && !fme.isAdminBypassing()) { if (context.fPlayer != null && !context.fPlayer.isAdminBypassing()) {
Access access = faction.getAccess(fme, PermissableAction.DISBAND); Access access = faction.getAccess(context.fPlayer, PermissableAction.DISBAND);
if (fme.getRole() != Role.LEADER && faction.getFPlayerLeader() != fme && access != Access.ALLOW) { if (context.fPlayer.getRole() != Role.LEADER && faction.getFPlayerLeader() != context.fPlayer && access != Access.ALLOW) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag()); context.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag());
return; return;
} }
} }
if (!faction.isNormal()) { if (!faction.isNormal()) {
msg(TL.COMMAND_DISBAND_IMMUTABLE.toString()); context.msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
return; return;
} }
if (faction.isPermanent()) { if (faction.isPermanent()) {
msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString()); context.msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
return;
}
// THis means they are a console command sender.
if (context.player == null) {
faction.disband(null, PlayerDisbandReason.PLUGIN);
return; return;
} }
// check for tnt before disbanding. // check for tnt before disbanding.
if (!disbandMap.containsKey(context.player.getUniqueId().toString()) && faction.getTnt() > 0) {
if ((fme != null && !disbandMap.containsKey(me.getUniqueId().toString())) && faction.getTnt() > 0) { context.msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));
msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + "")); disbandMap.put(context.player.getUniqueId().toString(), faction.getId());
disbandMap.put(me.getUniqueId().toString(), faction.getId()); Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> disbandMap.remove(context.player.getUniqueId().toString()), 200L);
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> disbandMap.remove(me.getUniqueId().toString()), 200L); } else if (faction.getId().equals(disbandMap.get(context.player.getUniqueId().toString())) || faction.getTnt() == 0) {
} else if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) { if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast", true)) {
if (P.p.getConfig().getBoolean("faction-disband-broadcast", true)) {
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
String amountString = senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(follower); String amountString = context.sender instanceof ConsoleCommandSender ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(follower);
UtilFly.checkFly(this.fme, Board.getInstance().getFactionAt(new FLocation(follower))); UtilFly.checkFly(context.fPlayer, Board.getInstance().getFactionAt(new FLocation(follower)));
if (follower.getFaction() == faction) { if (follower.getFaction() == faction) {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString); follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString);
fme.setCooldown("disband", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-disband") * 1000));
} else { } else {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower)); follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower));
} }
} }
faction.disband(me, PlayerDisbandReason.COMMAND); faction.disband(context.player, PlayerDisbandReason.COMMAND);
} else { } else {
faction.disband(me, PlayerDisbandReason.COMMAND); faction.disband(context.player, PlayerDisbandReason.COMMAND);
me.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER)); context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER));
} }
} }
} }

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -12,36 +12,28 @@ public class CmdFGlobal extends FCommand {
public static List<UUID> toggled = new ArrayList<>(); public static List<UUID> toggled = new ArrayList<>();
public CmdFGlobal() { public CmdFGlobal() {
super(); super();
this.aliases.add("gchat"); this.aliases.add("gchat");
this.aliases.add("global"); this.aliases.add("global");
this.aliases.add("globalchat"); this.aliases.add("globalchat");
this.disableOnLock = false; this.requirements = new CommandRequirements.Builder(Permission.GLOBALCHAT)
this.disableOnSpam = false; .playerOnly()
.memberOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Player p = (Player) sender;
// /f global // /f global
if (toggled.contains(p.getUniqueId())) { if (toggled.contains(context.player.getUniqueId())) {
toggled.remove(p.getUniqueId()); toggled.remove(context.player.getUniqueId());
} else { } else {
toggled.add(p.getUniqueId()); toggled.add(context.player.getUniqueId());
} }
fme.msg(TL.COMMAND_F_GLOBAL_TOGGLE, toggled.contains(p.getUniqueId()) ? "disabled" : "enabled"); context.msg(TL.COMMAND_F_GLOBAL_TOGGLE, toggled.contains(context.player.getUniqueId()) ? "disabled" : "enabled");
} }
@Override @Override

View File

@ -1,12 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.FactionWarpsFrame; import com.massivecraft.factions.util.FactionWarpsFrame;
import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -23,59 +21,52 @@ public class CmdFWarp extends FCommand {
this.optionalArgs.put("warpname", "warpname"); this.optionalArgs.put("warpname", "warpname");
this.optionalArgs.put("password", "password"); this.optionalArgs.put("password", "password");
this.requirements = new CommandRequirements.Builder(Permission.WARP)
this.permission = Permission.WARP.node; .playerOnly()
this.senderMustBeMember = true; .memberOnly()
this.senderMustBeModerator = false; .withAction(PermissableAction.WARP)
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
//TODO: check if in combat.
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.WARP);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use warps");
return;
}
}
if (context.args.size() == 0) {
if (args.size() == 0) { new FactionWarpsFrame(context.faction).buildGUI(context.fPlayer);
new FactionWarpsFrame(fme.getFaction()).buildGUI(fme); } else if (context.args.size() > 2) {
} else if (args.size() > 2) { context.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
} else { } else {
final String warpName = argAsString(0); final String warpName = context.argAsString(0);
final String passwordAttempt = argAsString(1); final String passwordAttempt = context.argAsString(1);
if (myFaction.isWarp(argAsString(0))) { if (context.faction.isWarp(context.argAsString(0))) {
// Check if requires password and if so, check if valid. CASE SENSITIVE // Check if requires password and if so, check if valid. CASE SENSITIVE
if (myFaction.hasWarpPassword(warpName) && !myFaction.isWarpPassword(warpName, passwordAttempt)) { if (context.faction.hasWarpPassword(warpName) && !context.faction.isWarpPassword(warpName, passwordAttempt)) {
fme.msg(TL.COMMAND_FWARP_INVALID_PASSWORD); context.faction.msg(TL.COMMAND_FWARP_INVALID_PASSWORD);
return; return;
} }
// Check transaction AFTER password check. // Check transaction AFTER password check.
if (!transact(fme)) return; if (!transact(context.fPlayer, context)) return;
final FPlayer fPlayer = fme;
final UUID uuid = fme.getPlayer().getUniqueId(); final FPlayer fPlayer = context.fPlayer;
this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> { final UUID uuid = context.player.getUniqueId();
context.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
Player player = Bukkit.getPlayer(uuid); Player player = Bukkit.getPlayer(uuid);
if (player != null) { if (player != null) {
player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation()); player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation());
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName); fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
} }
}, this.p.getConfig().getLong("warmups.f-warp", 0)); }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-warp", 0));
} else { } else {
fme.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName); context.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName);
} }
} }
} }
private boolean transact(FPlayer player) { private boolean transact(FPlayer player, CommandContext context) {
return !P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(P.p.getConfig().getDouble("warp-cost.warp", 5), TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString()); return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.warp", 5), TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
} }
@Override @Override

View File

@ -4,14 +4,12 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*; import com.massivecraft.factions.*;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.Particles.ParticleEffect;
import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Particle;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -28,52 +26,27 @@ public class CmdFly extends FCommand {
public CmdFly() { public CmdFly() {
super(); super();
this.aliases.add("fly"); this.aliases.add("fly");
this.optionalArgs.put("on/off", "flip"); this.optionalArgs.put("on/off", "flip");
this.requirements = new CommandRequirements.Builder(Permission.FLY)
this.permission = Permission.FLY.node; .playerOnly()
this.senderMustBeMember = true; .memberOnly()
this.senderMustBeModerator = false; .build();
} }
public static void startParticles() { public static void startParticles() {
// Just a secondary check.
if (!P.p.getConfig().getBoolean("ffly.Particles.Enabled")) {
return;
}
id = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { id = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> {
for (String name : flyMap.keySet()) { for (String name : flyMap.keySet()) {
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
if (player == null) { if (player == null) continue;
continue; if (!player.isFlying()) continue;
} if (!FactionsPlugin.getInstance().mc17) {
if (!player.isFlying()) { if (player.getGameMode() == GameMode.SPECTATOR) continue;
continue;
}
if (!P.p.mc17) {
if (player.getGameMode() == GameMode.SPECTATOR) {
continue;
}
} }
if (FPlayers.getInstance().getByPlayer(player).isVanished()) { FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
// Actually, vanished players (such as admins) should not display particles to prevent others from knowing their vanished assistance for moderation. fplayer.isVanished();
// But we can keep it as a config.
if (P.p.getConfig().getBoolean("ffly.Particles.Enable-While-Vanished")) {
return;
}
continue;
}
if (P.p.useNonPacketParticles) {
// 1.9+ based servers will use the built in particleAPI instead of packet based.
// any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working.
// So setting the amount to 0 spawns 1 in the precise location
player.getWorld().spawnParticle(Particle.CLOUD, player.getLocation().add(0, -0.35, 0), 0);
} else {
ParticleEffect.CLOUD.display((float) 0, (float) 0, (float) 0, (float) 0, 3, player.getLocation().add(0, -0.35, 0), 16);
}
} }
if (flyMap.keySet().size() == 0) { if (flyMap.keySet().size() == 0) {
@ -84,7 +57,7 @@ public class CmdFly extends FCommand {
} }
public static void startFlyCheck() { public static void startFlyCheck() {
flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { //threw the exception for now, until I recode fly :( Cringe. flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { //threw the exception for now, until I recode fly :( Cringe.
checkTaskState(); checkTaskState();
if (flyMap.keySet().size() != 0) { if (flyMap.keySet().size() != 0) {
for (String name : flyMap.keySet()) { for (String name : flyMap.keySet()) {
@ -95,7 +68,7 @@ public class CmdFly extends FCommand {
if (player == null if (player == null
|| !player.isFlying() || !player.isFlying()
|| player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.CREATIVE
|| !P.p.mc17 && player.getGameMode() == GameMode.SPECTATOR) { || !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) {
continue; continue;
} }
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
@ -105,7 +78,7 @@ public class CmdFly extends FCommand {
flyMap.remove(name); flyMap.remove(name);
continue; continue;
} }
if (fPlayer.checkIfNearbyEnemies()) { if (player.hasPermission("factions.fly.bypassnearbyenemycheck") || fPlayer.checkIfNearbyEnemies()) {
continue; continue;
} }
FLocation myFloc = new FLocation(player.getLocation()); FLocation myFloc = new FLocation(player.getLocation());
@ -174,57 +147,53 @@ public class CmdFly extends FCommand {
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// Disabled by default. // Disabled by default.
if (!P.p.getConfig().getBoolean("enable-faction-flight", false)) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) {
fme.msg(TL.COMMAND_FLY_DISABLED); context.fPlayer.msg(TL.COMMAND_FLY_DISABLED);
return; return;
} }
FLocation myfloc = new FLocation(me.getLocation()); FLocation myfloc = new FLocation(context.player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc); Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkBypassPerms(fme, me, toFac)) return; if (!checkBypassPerms(context.fPlayer, context.player, toFac)) return;
List<Entity> entities = this.me.getNearbyEntities(16.0D, 256.0D, 16.0D); List<Entity> entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D);
for (int i = 0; i <= entities.size() - 1; ++i) { for (int i = 0; i <= entities.size() - 1; ++i) {
if (entities.get(i) instanceof Player) { if (entities.get(i) instanceof Player) {
Player eplayer = (Player) entities.get(i); Player eplayer = (Player) entities.get(i);
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer); FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
if (efplayer.getRelationTo(this.fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) { if (efplayer.getRelationTo(context.fPlayer) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
this.fme.msg(TL.COMMAND_FLY_CHECK_ENEMY); context.msg(TL.COMMAND_FLY_CHECK_ENEMY);
return; return;
} }
} }
} }
if (args.size() == 0) { if (context.args.size() == 0) {
toggleFlight(fme.isFlying(), me); toggleFlight(context.fPlayer.isFlying(), context.fPlayer, context);
} else if (args.size() == 1) { } else if (context.args.size() == 1) {
toggleFlight(argAsBool(0), me); toggleFlight(context.argAsBool(0), context.fPlayer, context);
} }
} }
private void toggleFlight(final boolean toggle, final Player player) { private void toggleFlight(final boolean toggle, final FPlayer fme, CommandContext context) {
if (toggle) { if (toggle) {
fme.setFlying(false); fme.setFlying(false);
flyMap.remove(player.getName()); flyMap.remove(fme.getPlayer().getName());
return; return;
} }
if (fme.canFlyAtLocation()) if (fme.canFlyAtLocation())
this.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> { context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
fme.setFlying(true); fme.setFlying(true);
flyMap.put(player.getName(), true); flyMap.put(fme.getPlayer().getName(), true);
if (id == -1) {
if (P.p.getConfig().getBoolean("ffly.Particles.Enabled")) {
startParticles();
}
}
if (flyid == -1) { if (flyid == -1) {
startFlyCheck(); startFlyCheck();
} }
}, this.p.getConfig().getLong("warmups.f-fly", 0)); }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
} }
@Override @Override

View File

@ -1,49 +1,45 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.scoreboards.FTeamWrapper; import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
public class CmdFocus public class CmdFocus extends FCommand {
extends FCommand {
public CmdFocus() { public CmdFocus() {
aliases.add("focus"); aliases.add("focus");
requiredArgs.add("player"); requiredArgs.add("player");
permission = Permission.FOCUS.node; this.requirements = new CommandRequirements.Builder(Permission.FOCUS)
.playerOnly()
.memberOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
public void perform() { @Override
if (!P.p.getConfig().getBoolean("ffocus.Enabled")) { public void perform(CommandContext context) {
fme.msg(TL.GENERIC_DISABLED); if (!FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled")) {
context.msg(TL.GENERIC_DISABLED);
return; return;
} }
FPlayer target = argAsFPlayer(0); FPlayer target = context.argAsFPlayer(0);
if (target == null) { if (target == null) {
return; return;
} }
if (target.getFaction().getId().equalsIgnoreCase(myFaction.getId())) { if (target.getFaction().getId().equalsIgnoreCase(context.faction.getId())) {
fme.msg(TL.COMMAND_FOCUS_SAMEFACTION); context.msg(TL.COMMAND_FOCUS_SAMEFACTION);
return; return;
} }
if ((myFaction.getFocused() != null) && (myFaction.getFocused().equalsIgnoreCase(target.getName()))) { if ((context.faction.getFocused() != null) && (context.faction.getFocused().equalsIgnoreCase(target.getName()))) {
myFaction.setFocused(null); context.faction.setFocused(null);
myFaction.msg(TL.COMMAND_FOCUS_NO_LONGER, target.getName()); context.faction.msg(TL.COMMAND_FOCUS_NO_LONGER, target.getName());
FTeamWrapper.updatePrefixes(target.getFaction()); FTeamWrapper.updatePrefixes(target.getFaction());
return; return;
} }
myFaction.msg(TL.COMMAND_FOCUS_FOCUSING, target.getName()); context.faction.msg(TL.COMMAND_FOCUS_FOCUSING, target.getName());
myFaction.setFocused(target.getName()); context.faction.setFocused(target.getName());
FTeamWrapper.updatePrefixes(target.getFaction()); FTeamWrapper.updatePrefixes(target.getFaction());
} }
@ -51,4 +47,3 @@ public class CmdFocus
return TL.COMMAND_FOCUS_DESCRIPTION; return TL.COMMAND_FOCUS_DESCRIPTION;
} }
} }

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location; import org.bukkit.Location;
@ -11,48 +11,42 @@ import org.bukkit.inventory.ItemStack;
public class CmdGetVault extends FCommand { public class CmdGetVault extends FCommand {
public CmdGetVault() { public CmdGetVault() {
super(); super();
this.aliases.add("getvault"); this.aliases.add("getvault");
this.permission = Permission.GETVAULT.node; this.requirements = new CommandRequirements.Builder(Permission.GETVAULT)
this.disableOnLock = true; .playerOnly()
.memberOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fvault.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fvault.Enabled")) {
fme.sendMessage("This command is disabled!"); context.fPlayer.sendMessage("This command is disabled!");
return; return;
} }
Location vaultLocation = fme.getFaction().getVault(); Location vaultLocation = context.faction.getVault();
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")));
//check if vault is set //check if vault is set
if (vaultLocation != null) { if (vaultLocation != null) {
fme.msg(TL.COMMAND_GETVAULT_ALREADYSET); context.msg(TL.COMMAND_GETVAULT_ALREADYSET);
return; return;
} }
//has enough money? //has enough money?
int amount = P.p.getConfig().getInt("fvault.Price"); int amount = FactionsPlugin.getInstance().getConfig().getInt("fvault.Price");
if (!fme.hasMoney(amount)) { if (!context.fPlayer.hasMoney(amount)) {
return; return;
} }
//success :) //success :)
fme.takeMoney(amount); context.fPlayer.takeMoney(amount);
me.getInventory().addItem(vault); context.player.getInventory().addItem(vault);
fme.msg(TL.COMMAND_GETVAULT_RECEIVE); context.fPlayer.msg(TL.COMMAND_GETVAULT_RECEIVE);
} }

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -24,14 +24,8 @@ public class CmdHelp extends FCommand {
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("page", "1"); this.optionalArgs.put("page", "1");
this.permission = Permission.HELP.node; this.requirements = new CommandRequirements.Builder(Permission.HELP)
this.disableOnLock = false; .build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
//----------------------------------------------// //----------------------------------------------//
@ -39,80 +33,80 @@ public class CmdHelp extends FCommand {
//----------------------------------------------// //----------------------------------------------//
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (P.p.getConfig().getBoolean("use-old-help", true)) { if (FactionsPlugin.getInstance().getConfig().getBoolean("use-old-help", true)) {
if (helpPages == null) { if (helpPages == null) {
updateHelp(); updateHelp(context);
} }
int page = this.argAsInt(0, 1); int page = context.argAsInt(0, 1);
sendMessage(p.txt.titleize("Factions Help (" + page + "/" + helpPages.size() + ")")); context.sendMessage(FactionsPlugin.getInstance().txt.titleize("Factions Help (" + page + "/" + helpPages.size() + ")"));
page -= 1; page -= 1;
if (page < 0 || page >= helpPages.size()) { if (page < 0 || page >= helpPages.size()) {
msg(TL.COMMAND_HELP_404.format(String.valueOf(page))); context.msg(TL.COMMAND_HELP_404.format(String.valueOf(page)));
return; return;
} }
sendMessage(helpPages.get(page)); context.sendMessage(helpPages.get(page));
return; return;
} }
ConfigurationSection help = P.p.getConfig().getConfigurationSection("help"); ConfigurationSection help = FactionsPlugin.getInstance().getConfig().getConfigurationSection("help");
if (help == null) { if (help == null) {
help = P.p.getConfig().createSection("help"); // create new help section help = FactionsPlugin.getInstance().getConfig().createSection("help"); // create new help section
List<String> error = new ArrayList<>(); List<String> error = new ArrayList<>();
error.add("&cUpdate help messages in config.yml!"); error.add("&cUpdate help messages in config.yml!");
error.add("&cSet use-old-help for legacy help messages"); error.add("&cSet use-old-help for legacy help messages");
help.set("'1'", error); // add default error messages help.set("'1'", error); // add default error messages
} }
String pageArg = this.argAsString(0, "1"); String pageArg = context.argAsString(0, "1");
List<String> page = help.getStringList(pageArg); List<String> page = help.getStringList(pageArg);
if (page == null || page.isEmpty()) { if (page == null || page.isEmpty()) {
msg(TL.COMMAND_HELP_404.format(pageArg)); context.msg(TL.COMMAND_HELP_404.format(pageArg));
return; return;
} }
for (String helpLine : page) { for (String helpLine : page) {
sendMessage(P.p.txt.parse(helpLine)); context.sendMessage(FactionsPlugin.getInstance().txt.parse(helpLine));
} }
} }
public void updateHelp() { public void updateHelp(CommandContext context) {
helpPages = new ArrayList<>(); helpPages = new ArrayList<>();
ArrayList<String> pageLines; ArrayList<String> pageLines;
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.cmdBase.cmdHelp.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdHelp.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdList.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdList.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdShow.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdShow.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdPower.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPower.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdJoin.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdJoin.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdLeave.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdLeave.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdChat.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdChat.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdToggleAllianceChat.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdToggleAllianceChat.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdHome.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdHome.getUseageTemplate(context));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_NEXTCREATE.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_NEXTCREATE.toString()));
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.cmdBase.cmdCreate.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdCreate.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdDescription.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdDescription.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdTag.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdTag.getUseageTemplate(context));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_INVITATIONS.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_INVITATIONS.toString()));
pageLines.add(p.cmdBase.cmdOpen.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdOpen.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdInvite.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdInvite.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdDeinvite.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdDeinvite.getUseageTemplate(context));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_HOME.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_HOME.toString()));
pageLines.add(p.cmdBase.cmdSethome.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSethome.getUseageTemplate(context));
helpPages.add(pageLines); helpPages.add(pageLines);
if (Econ.isSetup() && Conf.econEnabled && Conf.bankEnabled) { if (Econ.isSetup() && Conf.econEnabled && Conf.bankEnabled) {
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(""); pageLines.add("");
pageLines.add(p.txt.parse(TL.COMMAND_HELP_BANK_1.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_BANK_1.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_BANK_2.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_BANK_2.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_BANK_3.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_BANK_3.toString()));
pageLines.add(""); pageLines.add("");
pageLines.add(p.cmdBase.cmdMoney.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdMoney.getUseageTemplate(context));
pageLines.add(""); pageLines.add("");
pageLines.add(""); pageLines.add("");
pageLines.add(""); pageLines.add("");
@ -120,94 +114,94 @@ public class CmdHelp extends FCommand {
} }
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.cmdBase.cmdClaim.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdClaim.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdAutoClaim.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdAutoClaim.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdUnclaim.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdUnclaim.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdUnclaimall.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdUnclaimall.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdKick.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdKick.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdMod.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdMod.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdAdmin.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdAdmin.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdTitle.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdTitle.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdSB.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSB.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdSeeChunk.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSeeChunk.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdStatus.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdStatus.getUseageTemplate(context));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PLAYERTITLES.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PLAYERTITLES.toString()));
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.cmdBase.cmdMap.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdMap.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdBoom.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdBoom.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdOwner.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdOwner.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdOwnerList.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdOwnerList.getUseageTemplate(context));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_OWNERSHIP_1.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_OWNERSHIP_1.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_OWNERSHIP_2.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_OWNERSHIP_2.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_OWNERSHIP_3.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_OWNERSHIP_3.toString()));
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.cmdBase.cmdDisband.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdDisband.getUseageTemplate(context));
pageLines.add(""); pageLines.add("");
pageLines.add(p.cmdBase.cmdRelationAlly.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdRelationAlly.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdRelationNeutral.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdRelationNeutral.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdRelationEnemy.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdRelationEnemy.getUseageTemplate(context));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_1.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_1.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_2.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_2.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_3.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_3.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_4.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_4.toString()));
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_5.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_5.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_6.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_6.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_7.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_7.toString()));
pageLines.add(TL.COMMAND_HELP_RELATIONS_8.toString()); pageLines.add(TL.COMMAND_HELP_RELATIONS_8.toString());
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_9.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_9.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_10.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_10.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_11.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_11.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_12.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_12.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_RELATIONS_13.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_RELATIONS_13.toString()));
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_1.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_1.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_2.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_2.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_3.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_3.toString()));
pageLines.add(TL.COMMAND_HELP_PERMISSIONS_4.toString()); pageLines.add(TL.COMMAND_HELP_PERMISSIONS_4.toString());
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_5.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_5.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_6.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_6.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_7.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_7.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_8.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_8.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_PERMISSIONS_9.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_PERMISSIONS_9.toString()));
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(TL.COMMAND_HELP_MOAR_1.toString()); pageLines.add(TL.COMMAND_HELP_MOAR_1.toString());
pageLines.add(p.cmdBase.cmdBypass.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdBypass.getUseageTemplate(context));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_ADMIN_1.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_ADMIN_1.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_ADMIN_2.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_ADMIN_2.toString()));
pageLines.add(p.txt.parse(TL.COMMAND_HELP_ADMIN_3.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_ADMIN_3.toString()));
pageLines.add(p.cmdBase.cmdSafeunclaimall.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSafeunclaimall.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdWarunclaimall.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdWarunclaimall.getUseageTemplate(context));
//TODO:TL //TODO:TL
pageLines.add(p.txt.parse("<i>Note: " + p.cmdBase.cmdUnclaim.getUseageTemplate(false) + P.p.txt.parse("<i>") + " works on safe/war zones as well.")); pageLines.add(FactionsPlugin.getInstance().txt.parse("<i>Note: " + FactionsPlugin.getInstance().cmdBase.cmdUnclaim.getUseageTemplate(context) + FactionsPlugin.getInstance().txt.parse("<i>") + " works on safe/war zones as well."));
pageLines.add(p.cmdBase.cmdPeaceful.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPeaceful.getUseageTemplate(context));
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.txt.parse(TL.COMMAND_HELP_MOAR_2.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_MOAR_2.toString()));
pageLines.add(p.cmdBase.cmdChatSpy.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdChatSpy.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdPermanent.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPermanent.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdPermanentPower.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPermanentPower.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdPowerBoost.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdPowerBoost.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdConfig.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdConfig.getUseageTemplate(context));
helpPages.add(pageLines); helpPages.add(pageLines);
pageLines = new ArrayList<>(); pageLines = new ArrayList<>();
pageLines.add(p.txt.parse(TL.COMMAND_HELP_MOAR_3.toString())); pageLines.add(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_HELP_MOAR_3.toString()));
pageLines.add(p.cmdBase.cmdLock.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdLock.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdReload.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdReload.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdSaveAll.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdSaveAll.getUseageTemplate(context));
pageLines.add(p.cmdBase.cmdVersion.getUseageTemplate(true)); pageLines.add(FactionsPlugin.getInstance().cmdBase.cmdVersion.getUseageTemplate(context));
helpPages.add(pageLines); helpPages.add(pageLines);
} }

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*; import com.massivecraft.factions.*;
import com.massivecraft.factions.integration.Essentials;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
@ -23,106 +24,68 @@ public class CmdHome extends FCommand {
super(); super();
this.aliases.add("home"); this.aliases.add("home");
this.optionalArgs.put("faction", "yours"); this.requirements = new CommandRequirements.Builder(Permission.HOME)
//this.requiredArgs.add(""); .playerOnly()
//this.optionalArgs.put("", ""); .memberOnly()
.withAction(PermissableAction.HOME)
this.permission = Permission.HOME.node; .build();
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// TODO: Hide this command on help also. // TODO: Hide this command on help also.
if (!Conf.homesEnabled) { if (!Conf.homesEnabled) {
fme.msg(TL.COMMAND_HOME_DISABLED); context.msg(TL.COMMAND_HOME_DISABLED);
return; return;
} }
if (!Conf.homesTeleportCommandEnabled) { if (!Conf.homesTeleportCommandEnabled) {
fme.msg(TL.COMMAND_HOME_TELEPORTDISABLED); context.msg(TL.COMMAND_HOME_TELEPORTDISABLED);
return; return;
} }
Faction factionArg; if (!context.faction.hasHome()) {
context.msg(TL.COMMAND_HOME_NOHOME.toString() + (context.fPlayer.getRole().value < Role.MODERATOR.value ? TL.GENERIC_ASKYOURLEADER.toString() : TL.GENERIC_YOUSHOULD.toString()));
if (args.isEmpty()) context.sendMessage(FactionsPlugin.getInstance().cmdBase.cmdSethome.getUseageTemplate(context));
factionArg = myFaction;
else
factionArg = argAsFaction(0);
if (factionArg.isSystemFaction()) {
fme.msg(TL.GENERIC_NOPERMISSION, "teleport to system faction home");
return; return;
} }
myFaction = factionArg; if (!Conf.homesTeleportAllowedFromEnemyTerritory && context.fPlayer.isInEnemyTerritory()) {
context.msg(TL.COMMAND_HOME_INENEMY);
if (myFaction.isWilderness())
return; return;
}
if (!fme.isAdminBypassing()) { if (!Conf.homesTeleportAllowedFromDifferentWorld && context.player.getWorld().getUID() != context.faction.getHome().getWorld().getUID()) {
Access access = myFaction.getAccess(fme, PermissableAction.HOME); context.msg(TL.COMMAND_HOME_WRONGWORLD);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { return;
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home"); }
if (!context.fPlayer.isAdminBypassing()) {
Access access = context.faction.getAccess(context.fPlayer, PermissableAction.HOME);
if (access != Access.ALLOW && context.fPlayer.getRole() != Role.LEADER) {
context.fPlayer.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home");
return; return;
} }
} }
if (!myFaction.hasHome()) { Faction faction = Board.getInstance().getFactionAt(new FLocation(context.player.getLocation()));
fme.msg(TL.COMMAND_HOME_NOHOME.toString() + (fme.getRole().value < Role.MODERATOR.value ? TL.GENERIC_ASKYOURLEADER.toString() : TL.GENERIC_YOUSHOULD.toString())); final Location loc = context.player.getLocation().clone();
fme.sendMessage(p.cmdBase.cmdSethome.getUseageTemplate());
return;
}
if (!Conf.homesTeleportAllowedFromEnemyTerritory && fme.isInEnemyTerritory()) {
fme.msg(TL.COMMAND_HOME_INENEMY);
return;
}
if (!Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID()) {
fme.msg(TL.COMMAND_HOME_WRONGWORLD);
return;
}
if (!fme.isAdminBypassing()) {
Access access = fme.getFaction().getAccess(fme, PermissableAction.HOME);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home");
return;
}
}
Faction faction = Board.getInstance().getFactionAt(new FLocation(me.getLocation()));
final Location loc = me.getLocation().clone();
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
if (Conf.homesTeleportAllowedEnemyDistance > 0 && !faction.isSafeZone() && (!fme.isInOwnTerritory() || !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)) { if (Conf.homesTeleportAllowedEnemyDistance > 0 && !faction.isSafeZone() && (!context.fPlayer.isInOwnTerritory() || !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)) {
World w = loc.getWorld(); World w = loc.getWorld();
double x = loc.getX(); double x = loc.getX();
double y = loc.getY(); double y = loc.getY();
double z = loc.getZ(); double z = loc.getZ();
for (Player p : me.getServer().getOnlinePlayers()) { for (Player p : context.player.getServer().getOnlinePlayers()) {
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) { if (p == null || !p.isOnline() || p.isDead() || p == context.player || p.getWorld() != w) {
continue; continue;
} }
FPlayer fp = FPlayers.getInstance().getByPlayer(p); FPlayer fp = FPlayers.getInstance().getByPlayer(p);
if (fme.getRelationTo(fp) != Relation.ENEMY || fp.isVanished()) { if (context.fPlayer.getRelationTo(fp) != Relation.ENEMY || fp.isVanished()) {
continue; continue;
} }
@ -137,37 +100,33 @@ public class CmdHome extends FCommand {
continue; continue;
} }
fme.msg(TL.COMMAND_HOME_ENEMYNEAR, String.valueOf(Conf.homesTeleportAllowedEnemyDistance)); context.msg(TL.COMMAND_HOME_ENEMYNEAR, String.valueOf(Conf.homesTeleportAllowedEnemyDistance));
return; return;
} }
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostHome, TL.COMMAND_HOME_TOTELEPORT.toString(), TL.COMMAND_HOME_FORTELEPORT.toString())) { if (!context.payForCommand(Conf.econCostHome, TL.COMMAND_HOME_TOTELEPORT.toString(), TL.COMMAND_HOME_FORTELEPORT.toString())) {
return; return;
} }
// TODO: Need to document this better confusing everyone, removed for now. // if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown)
// // if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown) if (Essentials.handleTeleport(context.player, context.faction.getHome())) {
// if (Essentials.handleTeleport(me, myFaction.getHome())) { return;
// return; }
// }
context.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", () -> {
this.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", () -> {
// Create a smoke effect // Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled) { if (Conf.homesTeleportCommandSmokeEffectEnabled) {
List<Location> smokeLocations = new ArrayList<>(); List<Location> smokeLocations = new ArrayList<>();
smokeLocations.add(loc); smokeLocations.add(loc);
smokeLocations.add(loc.add(0, 1, 0)); smokeLocations.add(loc.add(0, 1, 0));
smokeLocations.add(CmdHome.this.myFaction.getHome()); smokeLocations.add(context.faction.getHome());
smokeLocations.add(CmdHome.this.myFaction.getHome().clone().add(0, 1, 0)); smokeLocations.add(context.faction.getHome().clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness); SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
} }
context.player.teleport(context.faction.getHome());
CmdHome.this.me.teleport(CmdHome.this.myFaction.getHome()); }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-home", 0));
}, this.p.getConfig().getLong("warmups.f-home", 0));
} }
@Override @Override

View File

@ -9,26 +9,21 @@ public class CmdInspect extends FCommand {
this.aliases.add("inspect"); this.aliases.add("inspect");
this.aliases.add("ins"); this.aliases.add("ins");
this.permission = Permission.INSPECT.node; this.requirements = new CommandRequirements.Builder(Permission.INSPECT)
this.disableOnLock = true; .playerOnly()
.memberOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (fme.isInspectMode()) { if (context.fPlayer.isInspectMode()) {
fme.setInspectMode(false); context.fPlayer.setInspectMode(false);
msg(TL.COMMAND_INSPECT_DISABLED_MSG); context.msg(TL.COMMAND_INSPECT_DISABLED_MSG);
} else { } else {
fme.setInspectMode(true); context.fPlayer.setInspectMode(true);
msg(TL.COMMAND_INSPECT_ENABLED); context.msg(TL.COMMAND_INSPECT_ENABLED);
} }
} }
@ -38,3 +33,4 @@ public class CmdInspect extends FCommand {
return TL.COMMAND_INSPECT_DESCRIPTION; return TL.COMMAND_INSPECT_DESCRIPTION;
} }
} }

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
@ -24,44 +24,38 @@ public class CmdInventorySee extends FCommand {
this.requiredArgs.add("member name"); this.requiredArgs.add("member name");
this.permission = Permission.INVSEE.node; this.requirements = new CommandRequirements.Builder(Permission.INVSEE)
this.disableOnLock = true; .playerOnly()
this.disableOnSpam = false; .build();
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("f-inventory-see.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled")) {
fme.msg(TL.GENERIC_DISABLED); context.msg(TL.GENERIC_DISABLED);
return; return;
} }
Access use = myFaction.getAccess(fme, PermissableAction.TERRITORY); Access use = context.fPlayer.getFaction().getAccess(context.fPlayer, PermissableAction.TERRITORY);
if (use == Access.DENY || (use == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) { if (use == Access.DENY || (use == Access.UNDEFINED && !context.assertMinRole(Role.MODERATOR))) {
fme.msg(TL.GENERIC_NOPERMISSION, "territory"); context.msg(TL.GENERIC_NOPERMISSION, "territory");
return; return;
} }
ArrayList<Player> fplayers = myFaction.getOnlinePlayers(); ArrayList<Player> fplayers = context.fPlayer.getFaction().getOnlinePlayers();
FPlayer targetInv = argAsFPlayer(0); FPlayer targetInv = context.argAsFPlayer(0);
if (targetInv == null || !fplayers.contains(targetInv.getPlayer())) { if (targetInv == null || !fplayers.contains(targetInv.getPlayer())) {
fme.msg(TL.PLAYER_NOT_FOUND, Objects.requireNonNull(targetInv).toString()); context.msg(TL.PLAYER_NOT_FOUND, Objects.requireNonNull(targetInv).toString());
return; return;
} }
Inventory inventory = Bukkit.createInventory(me, 36, targetInv.getName() + "'s Inventory"); Inventory inventory = Bukkit.createInventory(context.player, 36, targetInv.getName() + "'s Inventory");
for (int i = 0; i < 36; i++) for (int i = 0; i < 36; i++)
if (targetInv.getPlayer().getInventory().getItem(i) != null) if (targetInv.getPlayer().getInventory().getItem(i) != null)
inventory.setItem(i, targetInv.getPlayer().getInventory().getItem(i)); inventory.setItem(i, targetInv.getPlayer().getInventory().getItem(i));
me.openInventory(inventory); context.player.openInventory(inventory);
} }
@Override @Override

View File

@ -2,9 +2,8 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; 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.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage; import mkremins.fanciful.FancyMessage;
@ -18,72 +17,58 @@ public class CmdInvite extends FCommand {
this.aliases.add("inv"); this.aliases.add("inv");
this.requiredArgs.add("player name"); this.requiredArgs.add("player name");
//this.optionalArgs.put("", "");
this.permission = Permission.INVITE.node; this.requirements = new CommandRequirements.Builder(Permission.INVITE)
this.disableOnLock = true; .playerOnly()
.withAction(PermissableAction.INVITE)
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer target = this.argAsBestFPlayerMatch(0); FPlayer target = context.argAsBestFPlayerMatch(0);
if (target == null) { if (target == null) {
return; return;
} }
if (target.getFaction() == myFaction) { if (target.getFaction() == context.faction) {
msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), myFaction.getTag()); context.msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), context.faction.getTag());
msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdKick.getUseageTemplate(false)); context.msg(TL.GENERIC_YOUMAYWANT.toString() + FactionsPlugin.getInstance().cmdBase.cmdKick.getUseageTemplate(context));
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // 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; return;
} }
if (!fme.isAdminBypassing()) { if (context.faction.isInvited(target)) {
Access access = myFaction.getAccess(fme, PermissableAction.INVITE); context.msg(TL.COMMAND_INVITE_ALREADYINVITED, target.getName());
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage invites");
return; return;
} }
} if (context.faction.isBanned(target)) {
context.msg(TL.COMMAND_INVITE_BANNED, target.getName());
if (myFaction.isInvited(target)) {
fme.msg(TL.COMMAND_INVITE_ALREADYINVITED, target.getName());
return;
}
if (myFaction.isBanned(target)) {
fme.msg(TL.COMMAND_INVITE_BANNED, target.getName());
return; return;
} }
myFaction.invite(target); context.faction.invite(target);
// Send the invitation to the target player when online, otherwise just ignore // Send the invitation to the target player when online, otherwise just ignore
if (target.isOnline()) { if (target.isOnline()) {
// Tooltips, colors, and commands only apply to the string immediately before it. // Tooltips, colors, and commands only apply to the string immediately before it.
FancyMessage message = new FancyMessage(fme.describeTo(target, true)) FancyMessage message = new FancyMessage(context.fPlayer.describeTo(target, true))
.tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) .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()) .then(TL.COMMAND_INVITE_INVITEDYOU.toString())
.color(ChatColor.YELLOW) .color(ChatColor.YELLOW)
.tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) .tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
.command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()) .command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag())
.then(myFaction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()) .then(context.faction.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());
message.send(target.getPlayer()); message.send(target.getPlayer());
} }
myFaction.msg(TL.COMMAND_INVITE_INVITED, fme.describeTo(myFaction, true), target.describeTo(myFaction)); context.faction.msg(TL.COMMAND_INVITE_INVITED, context.fPlayer.describeTo(context.faction, true), target.describeTo(context.faction));
} }
@Override @Override

View File

@ -12,120 +12,96 @@ public class CmdJoin extends FCommand {
public CmdJoin() { public CmdJoin() {
super(); super();
this.aliases.add("join"); this.aliases.add("join");
this.requiredArgs.add("faction name"); this.requiredArgs.add("faction name");
this.optionalArgs.put("player", "you"); this.optionalArgs.put("player", "you");
this.permission = Permission.JOIN.node; this.requirements = new CommandRequirements.Builder(Permission.JOIN)
this.disableOnLock = true; .playerOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Faction faction = this.argAsFaction(0); Faction faction = context.argAsFaction(0);
if (faction == null) { if (faction == null) {
return; return;
} }
FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false); FPlayer fplayer = context.argAsBestFPlayerMatch(1, context.fPlayer, false);
boolean samePlayer = fplayer == fme; boolean samePlayer = fplayer == context.fPlayer;
if (!samePlayer && !Permission.JOIN_OTHERS.has(sender, false)) { if (!samePlayer && !Permission.JOIN_OTHERS.has(context.sender, false)) {
msg(TL.COMMAND_JOIN_CANNOTFORCE); context.msg(TL.COMMAND_JOIN_CANNOTFORCE);
return; return;
} }
if (!faction.isNormal()) { if (!faction.isNormal()) {
msg(TL.COMMAND_JOIN_SYSTEMFACTION); context.msg(TL.COMMAND_JOIN_SYSTEMFACTION);
return; return;
} }
if (faction == fplayer.getFaction()) { if (faction == fplayer.getFaction()) {
//TODO:TL context.msg(TL.COMMAND_JOIN_ALREADYMEMBER, fplayer.describeTo(context.fPlayer, true), (samePlayer ? "are" : "is"), faction.getTag(context.fPlayer));
msg(TL.COMMAND_JOIN_ALREADYMEMBER, fplayer.describeTo(fme, true), (samePlayer ? "are" : "is"), faction.getTag(fme));
return; return;
} }
if (Conf.factionMemberLimit > 0 && faction.getFPlayers().size() >= Conf.factionMemberLimit) { if (Conf.factionMemberLimit > 0 && faction.getFPlayers().size() >= getFactionMemberLimit(faction)) {
msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(fme), Conf.factionMemberLimit, fplayer.describeTo(fme, false)); context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), getFactionMemberLimit(faction), fplayer.describeTo(context.fPlayer, false));
return; return;
} }
if (fplayer.hasFaction()) { if (fplayer.hasFaction()) {
//TODO:TL context.msg(TL.COMMAND_JOIN_INOTHERFACTION, fplayer.describeTo(context.fPlayer, true), (samePlayer ? "your" : "their"));
msg(TL.COMMAND_JOIN_INOTHERFACTION, fplayer.describeTo(fme, true), (samePlayer ? "your" : "their"));
return; return;
} }
if (!Conf.canLeaveWithNegativePower && fplayer.getPower() < 0) { if (!Conf.canLeaveWithNegativePower && fplayer.getPower() < 0) {
msg(TL.COMMAND_JOIN_NEGATIVEPOWER, fplayer.describeTo(fme, true)); context.msg(TL.COMMAND_JOIN_NEGATIVEPOWER, fplayer.describeTo(context.fPlayer, true));
return; return;
} }
if (!(faction.getOpen() || faction.isInvited(fplayer) || fme.isAdminBypassing() || Permission.JOIN_ANY.has(sender, false))) { if (!(faction.getOpen() || faction.isInvited(fplayer) || context.fPlayer.isAdminBypassing() || Permission.JOIN_ANY.has(context.sender, false))) {
msg(TL.COMMAND_JOIN_REQUIRESINVITATION); context.msg(TL.COMMAND_JOIN_REQUIRESINVITATION);
if (samePlayer) { if (samePlayer) {
faction.msg(TL.COMMAND_JOIN_ATTEMPTEDJOIN, fplayer.describeTo(faction, true)); faction.msg(TL.COMMAND_JOIN_ATTEMPTEDJOIN, fplayer.describeTo(faction, true));
} }
return; return;
} }
int level = faction.getUpgrade(UpgradeType.MEMBERS);
int limit = 0;
if (level == 0) {
limit = Conf.factionMemberLimit;
} else {
limit = P.p.getConfig().getInt("fupgrades.MainMenu.Members.Members-Limit.level-" + level);
}
if (limit > 0 && faction.getFPlayers().size() >= limit && !faction.altInvited(fme)) {
msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(fme), limit, fplayer.describeTo(fme, false));
return;
}
int altLimit = Conf.factionAltMemberLimit; int altLimit = Conf.factionAltMemberLimit;
if (altLimit > 0 && faction.getAltPlayers().size() >= altLimit && !faction.altInvited(fme)) { if (altLimit > 0 && faction.getAltPlayers().size() >= altLimit && !faction.altInvited(context.fPlayer)) {
msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(fme), altLimit, fplayer.describeTo(fme, false)); context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), altLimit, fplayer.describeTo(context.fPlayer, false));
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (samePlayer && !canAffordCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString())) { if (samePlayer && !context.canAffordCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString())) {
return; return;
} }
// Check for ban // Check for ban
if (!fme.isAdminBypassing() && faction.isBanned(fme)) { if (!context.fPlayer.isAdminBypassing() && faction.isBanned(context.fPlayer)) {
fme.msg(TL.COMMAND_JOIN_BANNED, faction.getTag(fme)); context.msg(TL.COMMAND_JOIN_BANNED, faction.getTag(context.fPlayer));
return; return;
} }
// trigger the join event (cancellable) // trigger the join event (cancellable)
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(me), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND); FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND);
Bukkit.getServer().getPluginManager().callEvent(joinEvent); Bukkit.getServer().getPluginManager().callEvent(joinEvent);
if (joinEvent.isCancelled()) { if (joinEvent.isCancelled()) {
return; return;
} }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (samePlayer && !payForCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString(), TL.COMMAND_JOIN_FORJOIN.toString())) { if (samePlayer && !context.payForCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString(), TL.COMMAND_JOIN_FORJOIN.toString())) {
return; return;
} }
fme.msg(TL.COMMAND_JOIN_SUCCESS, fplayer.describeTo(fme, true), faction.getTag(fme)); context.msg(TL.COMMAND_JOIN_SUCCESS, fplayer.describeTo(context.fPlayer, true), faction.getTag(context.fPlayer));
if (!samePlayer) { if (!samePlayer) {
fplayer.msg(TL.COMMAND_JOIN_MOVED, fme.describeTo(fplayer, true), faction.getTag(fplayer)); fplayer.msg(TL.COMMAND_JOIN_MOVED, context.fPlayer.describeTo(fplayer, true), faction.getTag(fplayer));
} }
faction.msg(TL.COMMAND_JOIN_JOINED, fplayer.describeTo(faction, true)); faction.msg(TL.COMMAND_JOIN_JOINED, fplayer.describeTo(faction, true));
@ -140,18 +116,25 @@ public class CmdJoin extends FCommand {
} }
faction.deinvite(fplayer); faction.deinvite(fplayer);
fplayer.setRole(faction.getDefaultRole()); context.fPlayer.setRole(faction.getDefaultRole());
if (Conf.logFactionJoin) { if (Conf.logFactionJoin) {
if (samePlayer) { if (samePlayer) {
P.p.log(TL.COMMAND_JOIN_JOINEDLOG.toString(), fplayer.getName(), faction.getTag()); FactionsPlugin.getInstance().log(TL.COMMAND_JOIN_JOINEDLOG.toString(), fplayer.getName(), faction.getTag());
} else { } else {
P.p.log(TL.COMMAND_JOIN_MOVEDLOG.toString(), fme.getName(), fplayer.getName(), faction.getTag()); FactionsPlugin.getInstance().log(TL.COMMAND_JOIN_MOVEDLOG.toString(), context.fPlayer.getName(), fplayer.getName(), faction.getTag());
} }
} }
} }
private int getFactionMemberLimit(Faction f) {
if (f.getUpgrade(UpgradeType.MEMBERS) == 0) return Conf.factionMemberLimit;
return Conf.factionMemberLimit + FactionsPlugin.getInstance().getConfig().getInt("fupgrades.MainMenu.Members.Member-Boost.level-" + f.getUpgrade(UpgradeType.MEMBERS));
}
@Override @Override
public TL getUsageTranslation() { public TL getUsageTranslation() {
return TL.COMMAND_JOIN_DESCRIPTION; return TL.COMMAND_JOIN_DESCRIPTION;
} }
} }

View File

@ -3,80 +3,69 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; 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.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage; import mkremins.fanciful.FancyMessage;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
public class CmdKick extends FCommand { public class CmdKick extends FCommand {
public CmdKick() { public CmdKick() {
super(); super();
this.aliases.add("kick"); this.aliases.add("kick");
this.optionalArgs.put("player name", "player name"); this.optionalArgs.put("player name", "player name");
//this.optionalArgs.put("", "");
this.permission = Permission.KICK.node; this.requirements = new CommandRequirements.Builder(Permission.KICK)
this.disableOnLock = false; .playerOnly()
.withAction(PermissableAction.KICK)
.memberOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer toKick = this.argIsSet(0) ? this.argAsBestFPlayerMatch(0) : null; FPlayer toKick = context.argIsSet(0) ? context.argAsBestFPlayerMatch(0) : null;
if (toKick == null) { if (toKick == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_KICK_CANDIDATES.toString()).color(ChatColor.GOLD); FancyMessage msg = new FancyMessage(TL.COMMAND_KICK_CANDIDATES.toString()).color(ChatColor.GOLD);
for (FPlayer player : myFaction.getFPlayersWhereRole(Role.NORMAL)) { for (FPlayer player : context.faction.getFPlayersWhereRole(Role.NORMAL)) {
String s = player.getName(); String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s); msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s);
} }
if (fme.getRole().isAtLeast(Role.COLEADER)) { if (context.fPlayer.getRole().isAtLeast(Role.COLEADER)) {
// For both coleader and admin, add mods. // For both coleader and admin, add mods.
for (FPlayer player : myFaction.getFPlayersWhereRole(Role.MODERATOR)) { for (FPlayer player : context.faction.getFPlayersWhereRole(Role.MODERATOR)) {
String s = player.getName(); String s = player.getName();
msg.then(s + " ").color(ChatColor.GRAY).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s); msg.then(s + " ").color(ChatColor.GRAY).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s);
} }
if (fme.getRole() == Role.LEADER) { if (context.fPlayer.getRole() == Role.LEADER) {
// Only add coleader to this for the leader. // Only add coleader to this for the leader.
for (FPlayer player : myFaction.getFPlayersWhereRole(Role.COLEADER)) { for (FPlayer player : context.faction.getFPlayersWhereRole(Role.COLEADER)) {
String s = player.getName(); String s = player.getName();
msg.then(s + " ").color(ChatColor.RED).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s); msg.then(s + " ").color(ChatColor.RED).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s);
} }
} }
} }
sendFancyMessage(msg); context.sendFancyMessage(msg);
return; return;
} }
if (fme == toKick) { if (context.fPlayer == toKick) {
msg(TL.COMMAND_KICK_SELF); context.msg(TL.COMMAND_KICK_SELF);
msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdLeave.getUseageTemplate(false)); context.msg(TL.GENERIC_YOUMAYWANT.toString() + FactionsPlugin.getInstance().cmdBase.cmdLeave.getUseageTemplate(context));
return;
}
if (toKick.isAlt()) {
msg(P.p.color("&cToo few arguments, &eUse like this:"));
msg(P.p.color("&b/f alts,alt kick &3<player name>"));
return; return;
} }
Faction toKickFaction = toKick.getFaction(); Faction toKickFaction = toKick.getFaction();
if (toKickFaction.isWilderness()) { if (toKickFaction.isWilderness()) {
sender.sendMessage(TL.COMMAND_KICK_NONE.toString()); context.sender.sendMessage(TL.COMMAND_KICK_NONE.toString());
return; return;
} }
@ -85,28 +74,23 @@ public class CmdKick extends FCommand {
// - Check for the kick permission. // - Check for the kick permission.
// - Make sure the player is in the faction. // - Make sure the player is in the faction.
// - Make sure the kicked player has lower rank than the kicker. // - Make sure the kicked player has lower rank than the kicker.
if (!fme.isAdminBypassing()) { if (!context.fPlayer.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.KICK); if (toKickFaction != context.faction) {
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { context.msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(context.fPlayer, true), context.faction.describeTo(context.fPlayer));
fme.msg(TL.GENERIC_NOPERMISSION, "kick");
return; return;
} }
if (toKickFaction != myFaction) { if (toKick.getRole().value >= context.fPlayer.getRole().value) {
msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(fme, true), myFaction.describeTo(fme)); context.msg(TL.COMMAND_KICK_INSUFFICIENTRANK);
return;
}
if (toKick.getRole().value >= fme.getRole().value) {
msg(TL.COMMAND_KICK_INSUFFICIENTRANK);
return; return;
} }
if (!Conf.canLeaveWithNegativePower && toKick.getPower() < 0) { if (!Conf.canLeaveWithNegativePower && toKick.getPower() < 0) {
msg(TL.COMMAND_KICK_NEGATIVEPOWER); context.msg(TL.COMMAND_KICK_NEGATIVEPOWER);
return; return;
} }
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString())) { if (!context.canAffordCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString())) {
return; return;
} }
@ -118,18 +102,18 @@ public class CmdKick extends FCommand {
} }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString(), TL.COMMAND_KICK_FORKICK.toString())) { if (!context.payForCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString(), TL.COMMAND_KICK_FORKICK.toString())) {
return; return;
} }
toKickFaction.msg(TL.COMMAND_KICK_FACTION, fme.describeTo(toKickFaction, true), toKick.describeTo(toKickFaction, true)); toKickFaction.msg(TL.COMMAND_KICK_FACTION, context.fPlayer.describeTo(toKickFaction, true), toKick.describeTo(toKickFaction, true));
toKick.msg(TL.COMMAND_KICK_KICKED, fme.describeTo(toKick, true), toKickFaction.describeTo(toKick)); toKick.msg(TL.COMMAND_KICK_KICKED, context.fPlayer.describeTo(toKick, true), toKickFaction.describeTo(toKick));
if (toKickFaction != myFaction) { if (toKickFaction != context.faction) {
fme.msg(TL.COMMAND_KICK_KICKS, toKick.describeTo(fme), toKickFaction.describeTo(fme)); context.fPlayer.msg(TL.COMMAND_KICK_KICKS, toKick.describeTo(context.fPlayer), toKickFaction.describeTo(context.fPlayer));
} }
if (Conf.logFactionKick) { if (Conf.logFactionKick) {
P.p.log((senderIsConsole ? "A console command" : fme.getName()) + " kicked " + toKick.getName() + " from the faction: " + toKickFaction.getTag()); FactionsPlugin.getInstance().log((context.sender instanceof ConsoleCommandSender ? "A console command" : context.fPlayer.getName()) + " kicked " + toKick.getName() + " from the faction: " + toKickFaction.getTag());
} }
if (toKick.getRole() == Role.LEADER) { if (toKick.getRole() == Role.LEADER) {
toKickFaction.promoteNewLeader(); toKickFaction.promoteNewLeader();

View File

@ -6,25 +6,18 @@ import com.massivecraft.factions.zcore.util.TL;
public class CmdKillHolograms extends FCommand { public class CmdKillHolograms extends FCommand {
public CmdKillHolograms() { public CmdKillHolograms() {
super(); super();
this.aliases.add("killholos"); this.aliases.add("killholos");
this.requiredArgs.add("radius"); this.requiredArgs.add("radius");
this.permission = Permission.KILLHOLOS.node; this.requirements = new CommandRequirements.Builder(Permission.KILLHOLOS)
this.disableOnLock = true; .playerOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
me.sendMessage("Killing Invisible Armor Stands.."); context.player.sendMessage("Killing Invisible Armor Stands..");
me.chat("/minecraft:kill @e[type=ArmorStand,r=" + argAsInt(0) + "]"); context.player.chat("/minecraft:kill @e[type=ArmorStand,r=" + context.argAsInt(0) + "]");
} }
@ -33,3 +26,4 @@ public class CmdKillHolograms extends FCommand {
return TL.COMMAND_KILLHOLOGRAMS_DESCRIPTION; return TL.COMMAND_KILLHOLOGRAMS_DESCRIPTION;
} }
} }

View File

@ -9,23 +9,15 @@ public class CmdLeave extends FCommand {
super(); super();
this.aliases.add("leave"); this.aliases.add("leave");
//this.requiredArgs.add(""); this.requirements = new CommandRequirements.Builder(Permission.LEAVE)
//this.optionalArgs.put("", ""); .playerOnly()
.memberOnly()
this.permission = Permission.LEAVE.node; .build();
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
fme.leave(true); context.fPlayer.leave(true);
} }
@Override @Override

View File

@ -3,13 +3,12 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagUtil; import com.massivecraft.factions.zcore.util.TagUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
@ -30,20 +29,15 @@ public class CmdList extends FCommand {
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("page", "1"); this.optionalArgs.put("page", "1");
this.permission = Permission.LIST.node; this.requirements = new CommandRequirements.Builder(Permission.LIST)
this.disableOnLock = false; .playerOnly()
.build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) if (!context.payForCommand(Conf.econCostList, "to list the factions", "for listing the factions"))
return; return;
ArrayList<Faction> factionList = Factions.getInstance().getAllFactions(); ArrayList<Faction> factionList = Factions.getInstance().getAllFactions();
@ -52,14 +46,14 @@ public class CmdList extends FCommand {
factionList.remove(Factions.getInstance().getWarZone()); factionList.remove(Factions.getInstance().getWarZone());
// remove exempt factions // remove exempt factions
if (fme != null && fme.getPlayer() != null && !fme.getPlayer().hasPermission("factions.show.bypassexempt")) { if (context.fPlayer != null && context.fPlayer.getPlayer() != null && !context.fPlayer.getPlayer().hasPermission("factions.show.bypassexempt")) {
List<String> exemptFactions = P.p.getConfig().getStringList("show-exempt"); List<String> exemptFactions = FactionsPlugin.getInstance().getConfig().getStringList("show-exempt");
factionList.removeIf(next -> exemptFactions.contains(next.getTag())); factionList.removeIf(next -> exemptFactions.contains(next.getTag()));
} }
// Sort by total followers first // Sort by total followers first
Collections.sort(factionList, (f1, f2) -> { factionList.sort((f1, f2) -> {
int f1Size = f1.getFPlayers().size(); int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size(); int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) { if (f1Size < f2Size) {
@ -87,7 +81,7 @@ public class CmdList extends FCommand {
factionList.add(0, Factions.getInstance().getWilderness()); factionList.add(0, Factions.getInstance().getWilderness());
final int pageheight = 9; final int pageheight = 9;
int pagenumber = this.argAsInt(0, 1); int pagenumber = context.argAsInt(0, 1);
int pagecount = (factionList.size() / pageheight) + 1; int pagecount = (factionList.size() / pageheight) + 1;
if (pagenumber > pagecount) { if (pagenumber > pagecount) {
pagenumber = pagecount; pagenumber = pagecount;
@ -101,18 +95,18 @@ public class CmdList extends FCommand {
} }
String header = p.getConfig().getString("list.header", defaults[0]); String header = FactionsPlugin.getInstance().getConfig().getString("list.header", defaults[0]);
header = header.replace("{pagenumber}", String.valueOf(pagenumber)).replace("{pagecount}", String.valueOf(pagecount)); header = header.replace("{pagenumber}", String.valueOf(pagenumber)).replace("{pagecount}", String.valueOf(pagecount));
lines.add(p.txt.parse(header)); lines.add(FactionsPlugin.getInstance().txt.parse(header));
for (Faction faction : factionList.subList(start, end)) { for (Faction faction : factionList.subList(start, end)) {
if (faction.isWilderness()) { if (faction.isWilderness()) {
lines.add(p.txt.parse(TagUtil.parsePlain(faction, p.getConfig().getString("list.factionless", defaults[1])))); lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, FactionsPlugin.getInstance().getConfig().getString("list.factionless", defaults[1]))));
continue; continue;
} }
lines.add(p.txt.parse(TagUtil.parsePlain(faction, fme, p.getConfig().getString("list.entry", defaults[2])))); lines.add(FactionsPlugin.getInstance().txt.parse(TagUtil.parsePlain(faction, context.fPlayer, FactionsPlugin.getInstance().getConfig().getString("list.entry", defaults[2]))));
} }
sendMessage(lines); context.sendMessage(lines);
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -15,25 +16,17 @@ public class CmdLock extends FCommand {
public CmdLock() { public CmdLock() {
super(); super();
this.aliases.add("lock"); this.aliases.add("lock");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip"); this.optionalArgs.put("on/off", "flip");
this.permission = Permission.LOCK.node; this.requirements = new CommandRequirements.Builder(Permission.LOCK)
this.disableOnLock = false; .playerOnly()
.build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
p.setLocked(this.argAsBool(0, !p.getLocked())); FactionsPlugin.getInstance().setLocked(context.argAsBool(0, !FactionsPlugin.getInstance().getLocked()));
msg(p.getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED); context.msg(FactionsPlugin.getInstance().getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED);
} }
@Override @Override
@ -42,3 +35,4 @@ public class CmdLock extends FCommand {
} }
} }

View File

@ -11,17 +11,18 @@ public class CmdLogins extends FCommand {
this.aliases.add("logins"); this.aliases.add("logins");
this.aliases.add("logout"); this.aliases.add("logout");
this.aliases.add("logouts"); this.aliases.add("logouts");
this.senderMustBePlayer = true;
this.senderMustBeMember = true; this.requirements = new CommandRequirements.Builder(Permission.MONITOR_LOGINS)
this.permission = Permission.MONITOR_LOGINS.node; .playerOnly()
.memberOnly()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
boolean monitor = fme.isMonitoringJoins(); boolean monitor = context.fPlayer.isMonitoringJoins();
fme.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor)); context.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor));
fme.setMonitorJoins(!monitor); context.fPlayer.setMonitorJoins(!monitor);
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
public class CmdLowPower extends FCommand { public class CmdLowPower extends FCommand {
@ -10,26 +11,21 @@ public class CmdLowPower extends FCommand {
super(); super();
this.aliases.add("lowpower"); this.aliases.add("lowpower");
this.requirements = new CommandRequirements.Builder(Permission.POWER_ANY)
this.disableOnLock = false; .playerOnly()
.memberOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
double maxPower = Conf.powerPlayerMax; double maxPower = Conf.powerPlayerMax;
String format = TL.COMMAND_LOWPOWER_FORMAT.toString(); String format = TL.COMMAND_LOWPOWER_FORMAT.toString();
msg(TL.COMMAND_LOWPOWER_HEADER.toString().replace("{maxpower}", (int) maxPower + "")); context.msg(TL.COMMAND_LOWPOWER_HEADER.toString().replace("{maxpower}", (int) maxPower + ""));
for (FPlayer fPlayer : fme.getFaction().getFPlayers()) { for (FPlayer fPlayer : context.faction.getFPlayers()) {
if (fPlayer.getPower() < maxPower) { if (fPlayer.getPower() < maxPower) {
sendMessage(format.replace("{player}", fPlayer.getName()).replace("{player_power}", (int) fPlayer.getPower() + "").replace("{maxpower}", (int) maxPower + "")); context.sendMessage(format.replace("{player}", fPlayer.getName()).replace("{player_power}", (int) fPlayer.getPower() + "").replace("{maxpower}", (int) maxPower + ""));
} }
} }
} }

View File

@ -12,54 +12,47 @@ public class CmdMap extends FCommand {
public CmdMap() { public CmdMap() {
super(); super();
this.aliases.add("map"); this.aliases.add("map");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "once"); this.optionalArgs.put("on/off", "once");
this.permission = Permission.MAP.node; this.requirements = new CommandRequirements.Builder(Permission.MAP)
this.disableOnLock = false; .playerOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (this.argIsSet(0)) { if (context.argIsSet(0)) {
if (this.argAsBool(0, !fme.isMapAutoUpdating())) { if (context.argAsBool(0, !context.fPlayer.isMapAutoUpdating())) {
// Turn on // Turn on
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) { if (!context.payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) {
return; return;
} }
fme.setMapAutoUpdating(true); context.fPlayer.setMapAutoUpdating(true);
msg(TL.COMMAND_MAP_UPDATE_ENABLED); context.msg(TL.COMMAND_MAP_UPDATE_ENABLED);
// And show the map once // And show the map once
showMap(); showMap(context);
} else { } else {
// Turn off // Turn off
fme.setMapAutoUpdating(false); context.fPlayer.setMapAutoUpdating(false);
msg(TL.COMMAND_MAP_UPDATE_DISABLED); context.msg(TL.COMMAND_MAP_UPDATE_DISABLED);
} }
} else { } else {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostMap, TL.COMMAND_MAP_TOSHOW, TL.COMMAND_MAP_FORSHOW)) { if (!context.payForCommand(Conf.econCostMap, TL.COMMAND_MAP_TOSHOW, TL.COMMAND_MAP_FORSHOW)) {
return; return;
} }
showMap(); showMap(context);
} }
} }
public void showMap() { public void showMap(CommandContext context) {
sendFancyMessage(Board.getInstance().getMap(fme, new FLocation(fme), fme.getPlayer().getLocation().getYaw())); context.sendFancyMessage(Board.getInstance().getMap(context.fPlayer, new FLocation(context.fPlayer), context.player.getLocation().getYaw()));
} }
@Override @Override

View File

@ -10,26 +10,24 @@ public class CmdMapHeight extends FCommand {
this.aliases.add("mapheight"); this.aliases.add("mapheight");
this.aliases.add("mh"); this.aliases.add("mh");
this.optionalArgs.put("height", "height"); this.optionalArgs.put("height", "height");
this.permission = Permission.MAPHEIGHT.node; this.requirements = new CommandRequirements.Builder(Permission.MAPHEIGHT)
.playerOnly()
.build();
this.senderMustBePlayer = true;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (args.size() == 0) { if (context.args.size() == 0) {
fme.sendMessage(TL.COMMAND_MAPHEIGHT_CURRENT.format(fme.getMapHeight())); context.fPlayer.sendMessage(TL.COMMAND_MAPHEIGHT_CURRENT.format(context.fPlayer.getMapHeight()));
return; return;
} }
int height = argAsInt(0); int height = context.argAsInt(0);
fme.setMapHeight(height); context.fPlayer.setMapHeight(height);
fme.sendMessage(TL.COMMAND_MAPHEIGHT_SET.format(fme.getMapHeight())); context.msg(TL.COMMAND_MAPHEIGHT_SET.format(context.fPlayer.getMapHeight()));
} }
@Override @Override

View File

@ -19,58 +19,46 @@ public class CmdMod extends FCommand {
this.aliases.add("setofficer"); this.aliases.add("setofficer");
this.optionalArgs.put("player name", "name"); this.optionalArgs.put("player name", "name");
//this.optionalArgs.put("", "");
this.permission = Permission.MOD.node; this.requirements = new CommandRequirements.Builder(Permission.MOD)
this.disableOnLock = true; .playerOnly()
.memberOnly()
.build();
senderMustBePlayer = false;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = context.argAsBestFPlayerMatch(0);
if (you == null) { if (you == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_MOD_CANDIDATES.toString()).color(ChatColor.GOLD); FancyMessage msg = new FancyMessage(TL.COMMAND_MOD_CANDIDATES.toString()).color(ChatColor.GOLD);
for (FPlayer player : myFaction.getFPlayersWhereRole(Role.NORMAL)) { for (FPlayer player : context.faction.getFPlayersWhereRole(Role.NORMAL)) {
String s = player.getName(); String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " mod " + s); msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " mod " + s);
} }
sendFancyMessage(msg); context.sendFancyMessage(msg);
return; return;
} }
boolean permAny = Permission.MOD_ANY.has(sender, false); boolean permAny = Permission.MOD_ANY.has(context.sender, false);
Faction targetFaction = you.getFaction(); Faction targetFaction = you.getFaction();
if (targetFaction != context.faction && !permAny) {
if (you.isAlt()) { context.msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(context.fPlayer, true));
msg(ChatColor.RED + "You can not promote alt accounts.");
return; return;
} }
if (targetFaction != myFaction && !permAny) { if (context.fPlayer != null && context.fPlayer.getRole() != Role.LEADER && !permAny) {
msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(fme, true)); context.msg(TL.COMMAND_MOD_NOTADMIN);
return; return;
} }
if (fme != null && fme.getRole() != Role.LEADER && !permAny) { if (you == context.fPlayer && !permAny) {
msg(TL.COMMAND_MOD_NOTADMIN); context.msg(TL.COMMAND_MOD_SELF);
return;
}
if (you == fme && !permAny) {
msg(TL.COMMAND_MOD_SELF);
return; return;
} }
if (you.getRole() == Role.LEADER) { if (you.getRole() == Role.LEADER) {
msg(TL.COMMAND_MOD_TARGETISADMIN); context.msg(TL.COMMAND_MOD_TARGETISADMIN);
return; return;
} }
@ -78,12 +66,12 @@ public class CmdMod extends FCommand {
// Revoke // Revoke
you.setRole(Role.NORMAL); you.setRole(Role.NORMAL);
targetFaction.msg(TL.COMMAND_MOD_REVOKED, you.describeTo(targetFaction, true)); targetFaction.msg(TL.COMMAND_MOD_REVOKED, you.describeTo(targetFaction, true));
msg(TL.COMMAND_MOD_REVOKES, you.describeTo(fme, true)); context.msg(TL.COMMAND_MOD_REVOKES, you.describeTo(context.fPlayer, true));
} else { } else {
// Give // Give
you.setRole(Role.MODERATOR); you.setRole(Role.MODERATOR);
targetFaction.msg(TL.COMMAND_MOD_PROMOTED, you.describeTo(targetFaction, true)); targetFaction.msg(TL.COMMAND_MOD_PROMOTED, you.describeTo(targetFaction, true));
msg(TL.COMMAND_MOD_PROMOTES, you.describeTo(fme, true)); context.msg(TL.COMMAND_MOD_PROMOTES, you.describeTo(context.fPlayer, true));
} }
} }

View File

@ -17,30 +17,24 @@ public class CmdModifyPower extends FCommand {
this.requiredArgs.add("name"); this.requiredArgs.add("name");
this.requiredArgs.add("power"); this.requiredArgs.add("power");
this.permission = Permission.MODIFY_POWER.node; // admin only perm. this.requirements = new CommandRequirements.Builder(Permission.MODIFY_POWER)
.build();
// Let's not require anything and let console modify this as well.
this.senderMustBeAdmin = false;
this.senderMustBePlayer = false;
this.senderMustBeMember = false;
senderMustBeColeader = false;
this.senderMustBeModerator = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// /f modify <name> # // /f modify <name> #
FPlayer player = argAsBestFPlayerMatch(0); FPlayer player = context.argAsBestFPlayerMatch(0);
Double number = argAsDouble(1); // returns null if not a Double. Double number = context.argAsDouble(1); // returns null if not a Double.
if (player == null || number == null) { if (player == null || number == null) {
sender.sendMessage(getHelpShort()); context.sender.sendMessage(getHelpShort());
return; return;
} }
player.alterPower(number); player.alterPower(number);
int newPower = player.getPowerRounded(); // int so we don't have super long doubles. int newPower = player.getPowerRounded(); // int so we don't have super long doubles.
msg(TL.COMMAND_MODIFYPOWER_ADDED, number, player.getName(), newPower); context.msg(TL.COMMAND_MODIFYPOWER_ADDED, number, player.getName(), newPower);
} }
@Override @Override

View File

@ -2,7 +2,8 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -10,37 +11,32 @@ import org.bukkit.entity.Player;
public class CmdNear extends FCommand { public class CmdNear extends FCommand {
public CmdNear() { public CmdNear() {
super(); super();
this.aliases.add("near"); this.aliases.add("near");
this.aliases.add("nearby"); this.aliases.add("nearby");
this.disableOnLock = true; this.requirements = new CommandRequirements.Builder(Permission.NEAR)
.playerOnly()
.memberOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fnear.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fnear.Enabled")) {
fme.msg(TL.COMMAND_NEAR_DISABLED_MSG); context.msg(TL.COMMAND_NEAR_DISABLED_MSG);
return; return;
} }
double range = P.p.getConfig().getInt("fnear.Radius"); double range = FactionsPlugin.getInstance().getConfig().getInt("fnear.Radius");
String format = TL.COMMAND_NEAR_FORMAT.toString(); String format = TL.COMMAND_NEAR_FORMAT.toString();
fme.msg(TL.COMMAND_NEAR_USE_MSG); context.msg(TL.COMMAND_NEAR_USE_MSG);
for (Entity e : me.getNearbyEntities(range, 255, range)) { for (Entity e : context.player.getNearbyEntities(range, 255, range)) {
if (e instanceof Player) { if (e instanceof Player) {
Player player = (((Player) e).getPlayer()); Player player = (((Player) e).getPlayer());
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
if (fme.getFaction() == fplayer.getFaction()) { if (context.faction == fplayer.getFaction()) {
double distance = me.getLocation().distance(player.getLocation()); double distance = context.player.getLocation().distance(player.getLocation());
fme.sendMessage(format.replace("{playername}", player.getDisplayName()).replace("{distance}", (int) distance + "")); context.sendMessage(format.replace("{playername}", player.getDisplayName()).replace("{distance}", (int) distance + ""));
} }
} }

View File

@ -1,37 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.zcore.util.TL;
public class CmdNotifications extends FCommand {
public CmdNotifications() {
this.aliases.add("notifications");
this.aliases.add("messages");
this.optionalArgs.put("on/off", "flip");
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
}
@Override
public void perform() {
if (args.size() == 0) {
toggleNotifications(!fme.hasNotificationsEnabled());
} else if (args.size() == 1) {
toggleNotifications(argAsBool(0));
}
}
private void toggleNotifications(boolean toggle) {
fme.setNotificationsEnabled(toggle);
if (toggle) {
fme.msg(TL.COMMAND_NOTIFICATIONS_TOGGLED_ON);
} else {
fme.msg(TL.COMMAND_NOTIFICATIONS_TOGGLED_OFF);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_NOTIFICATIONS_DESCRIPTION;
}
}

View File

@ -3,8 +3,8 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
public class CmdOpen extends FCommand { public class CmdOpen extends FCommand {
@ -12,47 +12,34 @@ public class CmdOpen extends FCommand {
public CmdOpen() { public CmdOpen() {
super(); super();
this.aliases.add("open"); this.aliases.add("open");
//this.requiredArgs.add("");
this.optionalArgs.put("yes/no", "flip"); this.optionalArgs.put("yes/no", "flip");
this.permission = Permission.OPEN.node; this.requirements = new CommandRequirements.Builder(Permission.OPEN)
this.disableOnLock = false; .withRole(Role.COLEADER)
this.disableOnSpam = true; .playerOnly()
.memberOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostOpen, TL.COMMAND_OPEN_TOOPEN, TL.COMMAND_OPEN_FOROPEN)) { if (!context.payForCommand(Conf.econCostOpen, TL.COMMAND_OPEN_TOOPEN, TL.COMMAND_OPEN_FOROPEN)) {
return; return;
} }
if (!fme.isCooldownEnded("open")) { context.faction.setOpen(context.argAsBool(0, !context.faction.getOpen()));
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("open"));
return;
}
myFaction.setOpen(this.argAsBool(0, !myFaction.getOpen())); String open = context.faction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString();
String open = myFaction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString();
// Inform // Inform
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(myFaction.getId())) { if (fplayer.getFactionId().equals(context.faction.getId())) {
fplayer.msg(TL.COMMAND_OPEN_CHANGES, fme.getName(), open); fplayer.msg(TL.COMMAND_OPEN_CHANGES, context.fPlayer.getName(), open);
continue; continue;
} }
fplayer.msg(TL.COMMAND_OPEN_CHANGED, myFaction.getTag(fplayer.getFaction()), open); fplayer.msg(TL.COMMAND_OPEN_CHANGED, context.faction.getTag(fplayer.getFaction()), open);
} }
fme.setCooldown("open", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-open") * 1000));
} }
@Override @Override

View File

@ -11,93 +11,87 @@ public class CmdOwner extends FCommand {
public CmdOwner() { public CmdOwner() {
super(); super();
this.aliases.add("owner"); this.aliases.add("owner");
//this.requiredArgs.add("");
this.optionalArgs.put("player name", "you"); this.optionalArgs.put("player name", "you");
this.permission = Permission.OWNER.node; this.requirements = new CommandRequirements.Builder(Permission.OWNER)
this.disableOnLock = true; .withRole(Role.LEADER)
.playerOnly()
.memberOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
// TODO: Fix colors! // TODO: Fix colors!
@Override @Override
public void perform() { public void perform(CommandContext context) {
boolean hasBypass = fme.isAdminBypassing(); boolean hasBypass = context.fPlayer.isAdminBypassing();
if (!hasBypass && !assertHasFaction()) { if (!hasBypass && !context.assertHasFaction()) {
return; return;
} }
if (!Conf.ownedAreasEnabled) { if (!Conf.ownedAreasEnabled) {
fme.msg(TL.COMMAND_OWNER_DISABLED); context.msg(TL.COMMAND_OWNER_DISABLED);
return; return;
} }
if (!hasBypass && Conf.ownedAreasLimitPerFaction > 0 && myFaction.getCountOfClaimsWithOwners() >= Conf.ownedAreasLimitPerFaction) { if (!hasBypass && Conf.ownedAreasLimitPerFaction > 0 && context.faction.getCountOfClaimsWithOwners() >= Conf.ownedAreasLimitPerFaction) {
fme.msg(TL.COMMAND_OWNER_LIMIT, Conf.ownedAreasLimitPerFaction); context.msg(TL.COMMAND_OWNER_LIMIT, Conf.ownedAreasLimitPerFaction);
return; return;
} }
if (!hasBypass && !assertMinRole(Conf.ownedAreasModeratorsCanSet ? Role.MODERATOR : Role.LEADER)) { if (!hasBypass && !context.assertMinRole(Conf.ownedAreasModeratorsCanSet ? Role.MODERATOR : Role.LEADER)) {
return; return;
} }
FLocation flocation = new FLocation(fme); FLocation flocation = new FLocation(context.fPlayer);
Faction factionHere = Board.getInstance().getFactionAt(flocation); Faction factionHere = Board.getInstance().getFactionAt(flocation);
if (factionHere != myFaction) { if (factionHere != context.faction) {
if (!factionHere.isNormal()) { if (!factionHere.isNormal()) {
fme.msg(TL.COMMAND_OWNER_NOTCLAIMED); context.msg(TL.COMMAND_OWNER_NOTCLAIMED);
return; return;
} }
if (!hasBypass) { if (!hasBypass) {
fme.msg(TL.COMMAND_OWNER_WRONGFACTION); context.msg(TL.COMMAND_OWNER_WRONGFACTION);
return; return;
} }
} }
FPlayer target = this.argAsBestFPlayerMatch(0, fme); FPlayer target = context.argAsBestFPlayerMatch(0, context.fPlayer);
if (target == null) { if (target == null) {
return; return;
} }
String playerName = target.getName(); String playerName = target.getName();
if (target.getFaction() != myFaction) { if (target.getFaction() != context.faction) {
fme.msg(TL.COMMAND_OWNER_NOTMEMBER, playerName); context.msg(TL.COMMAND_OWNER_NOTMEMBER, playerName);
return; return;
} }
// if no player name was passed, and this claim does already have owners set, clear them // if no player name was passed, and this claim does already have owners set, clear them
if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation)) { if (context.args.isEmpty() && context.faction.doesLocationHaveOwnersSet(flocation)) {
myFaction.clearClaimOwnership(flocation); context.faction.clearClaimOwnership(flocation);
fme.msg(TL.COMMAND_OWNER_CLEARED); context.msg(TL.COMMAND_OWNER_CLEARED);
return; return;
} }
if (myFaction.isPlayerInOwnerList(target, flocation)) { if (context.faction.isPlayerInOwnerList(target, flocation)) {
myFaction.removePlayerAsOwner(target, flocation); context.faction.removePlayerAsOwner(target, flocation);
fme.msg(TL.COMMAND_OWNER_REMOVED, playerName); context.msg(TL.COMMAND_OWNER_REMOVED, playerName);
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostOwner, TL.COMMAND_OWNER_TOSET, TL.COMMAND_OWNER_FORSET)) { if (!context.payForCommand(Conf.econCostOwner, TL.COMMAND_OWNER_TOSET, TL.COMMAND_OWNER_FORSET)) {
return; return;
} }
myFaction.setPlayerAsOwner(target, flocation); context.faction.setPlayerAsOwner(target, flocation);
fme.msg(TL.COMMAND_OWNER_ADDED, playerName); context.msg(TL.COMMAND_OWNER_ADDED, playerName);
} }
@Override @Override

View File

@ -13,56 +13,48 @@ public class CmdOwnerList extends FCommand {
super(); super();
this.aliases.add("ownerlist"); this.aliases.add("ownerlist");
//this.requiredArgs.add(""); this.requirements = new CommandRequirements.Builder(Permission.OWNERLIST)
//this.optionalArgs.put("", ""); .playerOnly()
.memberOnly()
this.permission = Permission.OWNERLIST.node; .build();
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
boolean hasBypass = fme.isAdminBypassing(); boolean hasBypass = context.fPlayer.isAdminBypassing();
if (!hasBypass && !assertHasFaction()) { if (!hasBypass && !context.assertHasFaction()) {
return; return;
} }
if (!Conf.ownedAreasEnabled) { if (!Conf.ownedAreasEnabled) {
fme.msg(TL.COMMAND_OWNERLIST_DISABLED); context.msg(TL.COMMAND_OWNERLIST_DISABLED);
return; return;
} }
FLocation flocation = new FLocation(fme); FLocation flocation = new FLocation(context.fPlayer);
if (Board.getInstance().getFactionAt(flocation) != myFaction) { if (Board.getInstance().getFactionAt(flocation) != context.faction) {
if (!hasBypass) { if (!hasBypass) {
fme.msg(TL.COMMAND_OWNERLIST_WRONGFACTION); context.msg(TL.COMMAND_OWNERLIST_WRONGFACTION);
return; return;
} }
//TODO: This code won't ever be called. //TODO: This code won't ever be called.
myFaction = Board.getInstance().getFactionAt(flocation); context.faction = Board.getInstance().getFactionAt(flocation);
if (!myFaction.isNormal()) { if (!context.faction.isNormal()) {
fme.msg(TL.COMMAND_OWNERLIST_NOTCLAIMED); context.msg(TL.COMMAND_OWNERLIST_NOTCLAIMED);
return; return;
} }
} }
String owners = myFaction.getOwnerListString(flocation); String owners = context.faction.getOwnerListString(flocation);
if (owners == null || owners.isEmpty()) { if (owners == null || owners.isEmpty()) {
fme.msg(TL.COMMAND_OWNERLIST_NONE); context.msg(TL.COMMAND_OWNERLIST_NONE);
return; return;
} }
fme.msg(TL.COMMAND_OWNERLIST_OWNERS, owners); context.msg(TL.COMMAND_OWNERLIST_OWNERS, owners);
} }
@Override @Override

View File

@ -1,57 +1,50 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
public class CmdPaypalSee extends FCommand { public class CmdPaypalSee extends FCommand {
public CmdPaypalSee() { public CmdPaypalSee() {
aliases.add("seepaypal"); this.aliases.add("seepaypal");
aliases.add("paypal"); this.aliases.add("paypal");
optionalArgs.put("faction", "yours"); this.optionalArgs.put("faction", "yours");
permission = Permission.PAYPAL.node;
disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = true;
this.requirements = new CommandRequirements.Builder(Permission.PAYPAL)
.memberOnly()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fpaypal.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) {
fme.msg(TL.GENERIC_DISABLED); context.msg(TL.GENERIC_DISABLED);
return; return;
} }
if (args.size() == 0) { if (context.args.size() == 0) {
if (myFaction.getPaypal().isEmpty()) { if (context.fPlayer.getFaction().getPaypal().isEmpty()) {
msg(TL.COMMAND_PAYPAL_NOTSET); context.msg(TL.COMMAND_PAYPAL_NOTSET);
} else { } else {
msg(TL.PAYPALSEE_PLAYER_PAYPAL, myFaction.getPaypal()); context.msg(TL.PAYPALSEE_PLAYER_PAYPAL, context.fPlayer.getFaction().getPaypal());
} }
} else if (args.size() == 1) { } else if (context.args.size() == 1) {
if (fme.isAdminBypassing()) { if (context.fPlayer.isAdminBypassing()) {
Faction faction = argAsFaction(0); Faction faction = context.argAsFaction(0);
if (faction != null) { if (faction != null) {
if (faction.getPaypal().isEmpty()) { if (faction.getPaypal().isEmpty()) {
msg(TL.COMMAND_PAYPALSEE_FACTION_NOTSET, faction.getTag()); context.msg(TL.COMMAND_PAYPALSEE_FACTION_NOTSET, faction.getTag());
} else { } else {
msg(TL.COMMAND_PAYPALSEE_FACTION_PAYPAL.toString(), faction.getTag(), faction.getPaypal()); context.msg(TL.COMMAND_PAYPALSEE_FACTION_PAYPAL.toString(), faction.getTag(), faction.getPaypal());
} }
} }
} else { } else {
msg(TL.GENERIC_NOPERMISSION, "see another factions paypal."); context.msg(TL.GENERIC_NOPERMISSION, "see another factions paypal.");
} }
} else { } else {
msg(P.p.cmdBase.cmdPaypalSee.getUseageTemplate()); context.msg(FactionsPlugin.getInstance().cmdBase.cmdPaypalSee.getUseageTemplate(context));
} }
} }

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -14,47 +14,43 @@ public class CmdPaypalSet extends FCommand {
this.requiredArgs.add("email"); this.requiredArgs.add("email");
this.permission = Permission.PAYPALSET.node; this.requirements = new CommandRequirements.Builder(Permission.PAYPALSET)
.playerOnly()
this.disableOnLock = false; .memberOnly()
this.senderMustBePlayer = true; .build();
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
this.senderMustBeColeader = false;
this.senderMustBeAdmin = true;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fpaypal.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) {
fme.msg(TL.GENERIC_DISABLED); context.fPlayer.msg(TL.GENERIC_DISABLED);
return; return;
} }
if (args.size() == 1) { if (context.args.size() == 1) {
if (isEmail(argAsString(0))) { if (isEmail(context.argAsString(0))) {
myFaction.paypalSet(argAsString(0)); context.fPlayer.getFaction().paypalSet(context.argAsString(0));
msg(TL.COMMAND_PAYPALSET_SUCCESSFUL, argAsString(0)); context.msg(TL.COMMAND_PAYPALSET_SUCCESSFUL, context.argAsString(0));
} else { } else {
msg(TL.COMMAND_PAYPALSET_NOTEMAIL, argAsString(0)); context.msg(TL.COMMAND_PAYPALSET_NOTEMAIL, context.argAsString(0));
} }
} else if (args.size() == 2) { } else if (context.args.size() == 2) {
if (fme.isAdminBypassing()) { if (context.fPlayer.isAdminBypassing()) {
Faction faction = argAsFaction(1); Faction faction = context.argAsFaction(1);
if (faction != null) { if (faction != null) {
if (isEmail(argAsString(0))) { if (isEmail(context.argAsString(0))) {
myFaction.paypalSet(argAsString(0)); context.fPlayer.getFaction().paypalSet(context.argAsString(0));
msg(TL.COMMAND_PAYPALSET_ADMIN_SUCCESSFUL, faction.getTag(), argAsString(0)); context.msg(TL.COMMAND_PAYPALSET_ADMIN_SUCCESSFUL, faction.getTag(), context.argAsString(0));
} else { } else {
msg(TL.COMMAND_PAYPALSET_ADMIN_FAILED, argAsString(0)); context.msg(TL.COMMAND_PAYPALSET_ADMIN_FAILED, context.argAsString(0));
} }
} }
} else { } else {
msg(TL.GENERIC_NOPERMISSION, "set another factions paypal!"); context.msg(TL.GENERIC_NOPERMISSION, "set another factions paypal!");
} }
} else { } else {
msg(P.p.cmdBase.cmdPaypalSet.getUseageTemplate()); context.msg(FactionsPlugin.getInstance().cmdBase.cmdPaypalSet.getUseageTemplate(context));
} }
} }

View File

@ -11,24 +11,16 @@ public class CmdPeaceful extends FCommand {
public CmdPeaceful() { public CmdPeaceful() {
super(); super();
this.aliases.add("peaceful"); this.aliases.add("peaceful");
this.requiredArgs.add("faction tag"); this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.SET_PEACEFUL.node; this.requirements = new CommandRequirements.Builder(Permission.SET_PEACEFUL)
this.disableOnLock = true; .build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Faction faction = this.argAsFaction(0); Faction faction = context.argAsFaction(0);
if (faction == null) { if (faction == null) {
return; return;
} }
@ -44,7 +36,7 @@ public class CmdPeaceful extends FCommand {
// Inform all players // Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
String blame = (fme == null ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true)); String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true));
if (fplayer.getFaction() == faction) { if (fplayer.getFaction() == faction) {
fplayer.msg(TL.COMMAND_PEACEFUL_YOURS, blame, change); fplayer.msg(TL.COMMAND_PEACEFUL_YOURS, blame, change);
} else { } else {

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
@ -27,46 +28,43 @@ public class CmdPerm extends FCommand {
this.optionalArgs.put("action", "action"); this.optionalArgs.put("action", "action");
this.optionalArgs.put("access", "access"); this.optionalArgs.put("access", "access");
this.requirements = new CommandRequirements.Builder(Permission.PERMISSIONS)
this.disableOnLock = true; .playerOnly()
.memberOnly()
senderMustBePlayer = true; .withRole(Role.LEADER)
senderMustBeMember = true; .build();
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = true;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (args.size() == 0) {
new PermissableRelationFrame(fme.getFaction()).buildGUI(fme); if (context.args.size() == 0) {
new PermissableRelationFrame(context.faction).buildGUI(context.fPlayer);
return; return;
} else if (args.size() == 1 && getPermissable(argAsString(0)) != null) { } else if (context.args.size() == 1 && getPermissable(context.argAsString(0)) != null) {
new PermissableActionFrame(fme.getFaction()).buildGUI(fme, getPermissable(argAsString(0))); new PermissableActionFrame(context.faction).buildGUI(context.fPlayer, getPermissable(context.argAsString(0)));
return; return;
} }
// If not opening GUI, then setting the permission manually. // If not opening GUI, then setting the permission manually.
if (args.size() != 3) { if (context.args.size() != 3) {
fme.msg(TL.COMMAND_PERM_DESCRIPTION); context.msg(TL.COMMAND_PERM_DESCRIPTION);
return; return;
} }
Set<Permissable> permissables = new HashSet<>(); Set<Permissable> permissables = new HashSet<>();
Set<PermissableAction> permissableActions = new HashSet<>(); Set<PermissableAction> permissableActions = new HashSet<>();
boolean allRelations = argAsString(0).equalsIgnoreCase("all"); boolean allRelations = context.argAsString(0).equalsIgnoreCase("all");
boolean allActions = argAsString(1).equalsIgnoreCase("all"); boolean allActions = context.argAsString(1).equalsIgnoreCase("all");
if (allRelations) { if (allRelations) {
permissables.addAll(myFaction.getPermissions().keySet()); permissables.addAll(context.faction.getPermissions().keySet());
} else { } else {
Permissable permissable = getPermissable(argAsString(0)); Permissable permissable = getPermissable(context.argAsString(0));
if (permissable == null) { if (permissable == null) {
fme.msg(TL.COMMAND_PERM_INVALID_RELATION); context.msg(TL.COMMAND_PERM_INVALID_RELATION);
return; return;
} }
@ -76,29 +74,30 @@ public class CmdPerm extends FCommand {
if (allActions) { if (allActions) {
permissableActions.addAll(Arrays.asList(PermissableAction.values())); permissableActions.addAll(Arrays.asList(PermissableAction.values()));
} else { } else {
PermissableAction permissableAction = PermissableAction.fromString(argAsString(1)); PermissableAction permissableAction = PermissableAction.fromString(context.argAsString(1));
if (permissableAction == null) { if (permissableAction == null) {
fme.msg(TL.COMMAND_PERM_INVALID_ACTION); context.msg(TL.COMMAND_PERM_INVALID_ACTION);
return; return;
} }
permissableActions.add(permissableAction); permissableActions.add(permissableAction);
} }
Access access = Access.fromString(argAsString(2)); Access access = Access.fromString(context.argAsString(2));
if (access == null) { if (access == null) {
fme.msg(TL.COMMAND_PERM_INVALID_ACCESS); context.msg(TL.COMMAND_PERM_INVALID_ACCESS);
return; return;
} }
for (Permissable permissable : permissables) { for (Permissable permissable : permissables) {
for (PermissableAction permissableAction : permissableActions) { for (PermissableAction permissableAction : permissableActions) {
fme.getFaction().setPermission(permissable, permissableAction, access); context.faction.setPermission(permissable, permissableAction, access);
} }
} }
fme.msg(TL.COMMAND_PERM_SET, argAsString(1), access.name(), argAsString(0));
P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), argAsString(1), access.name(), argAsString(0)) + " for faction " + fme.getTag()); context.msg(TL.COMMAND_PERM_SET, context.argAsString(1), access.name(), context.argAsString(0));
FactionsPlugin.getInstance().log(String.format(TL.COMMAND_PERM_SET.toString(), context.argAsString(1), access.name(), context.argAsString(0)) + " for faction " + context.fPlayer.getTag());
} }
private Permissable getPermissable(String name) { private Permissable getPermissable(String name) {

View File

@ -3,7 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -13,23 +13,15 @@ public class CmdPermanent extends FCommand {
public CmdPermanent() { public CmdPermanent() {
super(); super();
this.aliases.add("permanent"); this.aliases.add("permanent");
this.requiredArgs.add("faction tag"); this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.SET_PERMANENT.node; this.requirements = new CommandRequirements.Builder(Permission.SET_PERMANENT)
this.disableOnLock = true; .build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Faction faction = this.argAsFaction(0); Faction faction = context.argAsFaction(0);
if (faction == null) { if (faction == null) {
return; return;
} }
@ -43,11 +35,11 @@ public class CmdPermanent extends FCommand {
faction.setPermanent(true); faction.setPermanent(true);
} }
P.p.log((fme == null ? "A server admin" : fme.getName()) + " " + change + " the faction \"" + faction.getTag() + "\"."); FactionsPlugin.getInstance().log((context.fPlayer == null ? "A server admin" : context.fPlayer.getName()) + " " + change + " the faction \"" + faction.getTag() + "\".");
// Inform all players // Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
String blame = (fme == null ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true)); String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true));
if (fplayer.getFaction() == faction) { if (fplayer.getFaction() == faction) {
fplayer.msg(TL.COMMAND_PERMANENT_YOURS, blame, change); fplayer.msg(TL.COMMAND_PERMANENT_YOURS, blame, change);
} else { } else {
@ -61,3 +53,4 @@ public class CmdPermanent extends FCommand {
return TL.COMMAND_PERMANENT_DESCRIPTION; return TL.COMMAND_PERMANENT_DESCRIPTION;
} }
} }

View File

@ -9,28 +9,21 @@ public class CmdPermanentPower extends FCommand {
public CmdPermanentPower() { public CmdPermanentPower() {
super(); super();
this.aliases.add("permanentpower"); this.aliases.add("permanentpower");
this.requiredArgs.add("faction"); this.requiredArgs.add("faction");
this.requiredArgs.add("power"); this.requiredArgs.add("power");
this.permission = Permission.SET_PERMANENTPOWER.node; this.requirements = new CommandRequirements.Builder(Permission.SET_PERMANENTPOWER)
this.disableOnLock = true; .build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Faction targetFaction = this.argAsFaction(0); Faction targetFaction = context.argAsFaction(0);
if (targetFaction == null) { if (targetFaction == null) {
return; return;
} }
Integer targetPower = this.argAsInt(1); Integer targetPower = context.argAsInt(1);
targetFaction.setPermanentPower(targetPower); targetFaction.setPermanentPower(targetPower);
@ -40,14 +33,14 @@ public class CmdPermanentPower extends FCommand {
} }
// Inform sender // Inform sender
msg(TL.COMMAND_PERMANENTPOWER_SUCCESS, change, targetFaction.describeTo(fme)); context.msg(TL.COMMAND_PERMANENTPOWER_SUCCESS, change, targetFaction.describeTo(context.fPlayer));
// Inform all other players // Inform all other players
for (FPlayer fplayer : targetFaction.getFPlayersWhereOnline(true)) { for (FPlayer fplayer : targetFaction.getFPlayersWhereOnline(true)) {
if (fplayer == fme) { if (fplayer == context.fPlayer) {
continue; continue;
} }
String blame = (fme == null ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer, true)); String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true));
fplayer.msg(TL.COMMAND_PERMANENTPOWER_FACTION, blame, change); fplayer.msg(TL.COMMAND_PERMANENTPOWER_FACTION, blame, change);
} }
} }

View File

@ -11,41 +11,33 @@ public class CmdPower extends FCommand {
super(); super();
this.aliases.add("power"); this.aliases.add("power");
this.aliases.add("pow"); this.aliases.add("pow");
//this.requiredArgs.add("faction tag");
this.optionalArgs.put("player name", "you"); this.optionalArgs.put("player name", "you");
this.permission = Permission.POWER.node; this.requirements = new CommandRequirements.Builder(Permission.POWER)
this.disableOnLock = false; .build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer target = this.argAsBestFPlayerMatch(0, fme); FPlayer target = context.argAsBestFPlayerMatch(0, context.fPlayer);
if (target == null) { if (target == null) {
return; return;
} }
if (target != fme && !Permission.POWER_ANY.has(sender, true)) { if (target != context.fPlayer && !Permission.POWER_ANY.has(context.sender, true)) {
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostPower, TL.COMMAND_POWER_TOSHOW, TL.COMMAND_POWER_FORSHOW)) { if (!context.payForCommand(Conf.econCostPower, TL.COMMAND_POWER_TOSHOW, TL.COMMAND_POWER_FORSHOW)) {
return; return;
} }
double powerBoost = target.getPowerBoost(); double powerBoost = target.getPowerBoost();
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_POWER_BONUS.toString() : TL.COMMAND_POWER_PENALTY.toString()) + powerBoost + ")"; String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_POWER_BONUS.toString() : TL.COMMAND_POWER_PENALTY.toString()) + powerBoost + ")";
msg(TL.COMMAND_POWER_POWER, target.describeTo(fme, true), target.getPowerRounded(), target.getPowerMaxRounded(), boost); context.msg(TL.COMMAND_POWER_POWER, target.describeTo(context.fPlayer, true), target.getPowerRounded(), target.getPowerMaxRounded(), boost);
} }
@Override @Override

View File

@ -2,48 +2,42 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.command.ConsoleCommandSender;
public class CmdPowerBoost extends FCommand { public class CmdPowerBoost extends FCommand {
public CmdPowerBoost() { public CmdPowerBoost() {
super(); super();
this.aliases.add("powerboost"); this.aliases.add("powerboost");
this.requiredArgs.add("plugin|f|player|faction"); this.requiredArgs.add("plugin|f|player|faction");
this.requiredArgs.add("name"); this.requiredArgs.add("name");
this.requiredArgs.add("# or reset"); this.requiredArgs.add("# or reset");
this.permission = Permission.POWERBOOST.node; this.requirements = new CommandRequirements.Builder(Permission.POWERBOOST)
this.disableOnLock = true; .build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
String type = this.argAsString(0).toLowerCase(); String type = context.argAsString(0).toLowerCase();
boolean doPlayer = true; boolean doPlayer = true;
if (type.equals("f") || type.equals("faction")) { if (type.equals("f") || type.equals("faction")) {
doPlayer = false; doPlayer = false;
} else if (!type.equals("plugin") && !type.equals("player")) { } else if (!type.equals("plugin") && !type.equals("player")) {
msg(TL.COMMAND_POWERBOOST_HELP_1); context.msg(TL.COMMAND_POWERBOOST_HELP_1);
msg(TL.COMMAND_POWERBOOST_HELP_2); context.msg(TL.COMMAND_POWERBOOST_HELP_2);
return; return;
} }
Double targetPower = this.argAsDouble(2); Double targetPower = context.argAsDouble(2);
if (targetPower == null) { if (targetPower == null) {
if (this.argAsString(2).equalsIgnoreCase("reset")) { if (context.argAsString(2).equalsIgnoreCase("reset")) {
targetPower = 0D; targetPower = 0D;
} else { } else {
msg(TL.COMMAND_POWERBOOST_INVALIDNUM); context.msg(TL.COMMAND_POWERBOOST_INVALIDNUM);
return; return;
} }
} }
@ -51,7 +45,7 @@ public class CmdPowerBoost extends FCommand {
String target; String target;
if (doPlayer) { if (doPlayer) {
FPlayer targetPlayer = this.argAsBestFPlayerMatch(1); FPlayer targetPlayer = context.argAsBestFPlayerMatch(1);
if (targetPlayer == null) { if (targetPlayer == null) {
return; return;
} }
@ -62,7 +56,7 @@ public class CmdPowerBoost extends FCommand {
targetPlayer.setPowerBoost(targetPower); targetPlayer.setPowerBoost(targetPower);
target = TL.COMMAND_POWERBOOST_PLAYER.format(targetPlayer.getName()); target = TL.COMMAND_POWERBOOST_PLAYER.format(targetPlayer.getName());
} else { } else {
Faction targetFaction = this.argAsFaction(1); Faction targetFaction = context.argAsFaction(1);
if (targetFaction == null) { if (targetFaction == null) {
return; return;
} }
@ -75,9 +69,9 @@ public class CmdPowerBoost extends FCommand {
} }
int roundedPower = (int) Math.round(targetPower); int roundedPower = (int) Math.round(targetPower);
msg(TL.COMMAND_POWERBOOST_BOOST, target, roundedPower); context.msg(TL.COMMAND_POWERBOOST_BOOST, target, roundedPower);
if (!senderIsConsole) { if (!(context.sender instanceof ConsoleCommandSender)) {
P.p.log(TL.COMMAND_POWERBOOST_BOOSTLOG.toString(), fme.getName(), target, roundedPower); FactionsPlugin.getInstance().log(TL.COMMAND_POWERBOOST_BOOSTLOG.toString(), context.fPlayer.getName(), target, roundedPower);
} }
} }

View File

@ -1,8 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.shop.ShopConfig;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -12,32 +11,24 @@ public class CmdReload extends FCommand {
super(); super();
this.aliases.add("reload"); this.aliases.add("reload");
this.permission = Permission.RELOAD.node; this.requirements = new CommandRequirements.Builder(Permission.RELOAD).build();
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
long timeInitStart = System.currentTimeMillis(); long timeInitStart = System.currentTimeMillis();
Conf.load(); Conf.load();
Conf.save(); Conf.save();
P.p.reloadConfig(); FactionsPlugin.getInstance().reloadConfig();
P.p.loadLang(); FactionsPlugin.getInstance().loadLang();
ShopConfig.loadShop();
if (P.p.getConfig().getBoolean("enable-faction-flight")) { if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) {
P.p.factionsFlight = true; FactionsPlugin.getInstance().factionsFlight = true;
} }
long timeReload = (System.currentTimeMillis() - timeInitStart); long timeReload = (System.currentTimeMillis() - timeInitStart);
msg(TL.COMMAND_RELOAD_TIME, timeReload); context.msg(TL.COMMAND_RELOAD_TIME, timeReload);
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -15,69 +15,65 @@ public class CmdRules extends FCommand {
aliases.add("rules"); aliases.add("rules");
this.optionalArgs.put("add/remove/set/clear", ""); this.optionalArgs.put("add/remove/set/clear", "");
this.errorOnToManyArgs = false;
permission = Permission.RULES.node;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.RULES)
.playerOnly()
.memberOnly()
.noErrorOnManyArgs()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("frules.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("frules.Enabled")) {
fme.msg(TL.COMMAND_RULES_DISABLED_MSG); context.msg(TL.COMMAND_RULES_DISABLED_MSG);
return; return;
} }
if (this.args.size() == 0) { if (context.args.size() == 0) {
HashMap<Integer, String> rules = fme.getFaction().getRulesMap(); HashMap<Integer, String> rules = context.faction.getRulesMap();
if (rules.size() == 0) { if (rules.size() == 0) {
List<String> ruleList = P.p.getConfig().getStringList("frules.default-rules"); List<String> ruleList = FactionsPlugin.getInstance().getConfig().getStringList("frules.default-rules");
fme.sendMessage(P.p.colorList(ruleList)); context.sendMessage(FactionsPlugin.getInstance().colorList(ruleList));
} else { } else {
for (int i = 0; i <= rules.size() - 1; i++) { for (int i = 0; i <= rules.size() - 1; i++) {
fme.sendMessage(P.p.color(rules.get(i))); context.sendMessage(FactionsPlugin.getInstance().color(rules.get(i)));
} }
} }
} }
if (this.args.size() == 1) { if (context.args.size() == 1) {
if (args.get(0).equalsIgnoreCase("add")) { if (context.args.get(0).equalsIgnoreCase("add")) {
fme.msg(TL.COMMAND_RULES_ADD_INVALIDARGS); context.msg(TL.COMMAND_RULES_ADD_INVALIDARGS);
} }
if (args.get(0).equalsIgnoreCase("set")) { if (context.args.get(0).equalsIgnoreCase("set")) {
fme.msg(TL.COMMAND_RULES_SET_INVALIDARGS); context.msg(TL.COMMAND_RULES_SET_INVALIDARGS);
} }
if (args.get(0).equalsIgnoreCase("remove")) { if (context.args.get(0).equalsIgnoreCase("remove")) {
fme.msg(TL.COMMAND_RULES_REMOVE_INVALIDARGS); context.msg(TL.COMMAND_RULES_REMOVE_INVALIDARGS);
} }
if (args.get(0).equalsIgnoreCase("clear")) { if (context.args.get(0).equalsIgnoreCase("clear")) {
fme.getFaction().clearRules(); context.faction.clearRules();
fme.msg(TL.COMMAND_RULES_CLEAR_SUCCESS); context.msg(TL.COMMAND_RULES_CLEAR_SUCCESS);
} }
} }
if (this.args.size() >= 2) { if (context.args.size() >= 2) {
if (args.get(0).equalsIgnoreCase("add")) { if (context.args.get(0).equalsIgnoreCase("add")) {
String message = ""; String message = "";
StringBuilder string = new StringBuilder(message); StringBuilder string = new StringBuilder(message);
for (int i = 1; i <= args.size() - 1; i++) { for (int i = 1; i <= context.args.size() - 1; i++) {
string.append(" ").append(args.get(i)); string.append(" " + context.args.get(i));
} }
fme.getFaction().addRule(string.toString()); context.faction.addRule(string.toString());
fme.msg(TL.COMMAND_RULES_ADD_SUCCESS); context.msg(TL.COMMAND_RULES_ADD_SUCCESS);
} }
if (this.args.size() == 2) { if (context.args.size() == 2) {
if (args.get(0).equalsIgnoreCase("remove")) { if (context.args.get(0).equalsIgnoreCase("remove")) {
int index = argAsInt(1); int index = context.argAsInt(1);
fme.getFaction().removeRule(index - 1); context.faction.removeRule(index - 1);
fme.msg(TL.COMMAND_RULES_REMOVE_SUCCESS); context.msg(TL.COMMAND_RULES_REMOVE_SUCCESS);
} }
} }

View File

@ -9,21 +9,23 @@ public class CmdSB extends FCommand {
public CmdSB() { public CmdSB() {
this.aliases.add("sb"); this.aliases.add("sb");
this.aliases.add("scoreboard"); this.aliases.add("scoreboard");
this.permission = Permission.SCOREBOARD.node;
this.senderMustBePlayer = true; this.requirements = new CommandRequirements.Builder(Permission.SCOREBOARD)
.playerOnly()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
boolean toggleTo = !fme.showScoreboard(); boolean toggleTo = !context.fPlayer.showScoreboard();
FScoreboard board = FScoreboard.get(fme); FScoreboard board = FScoreboard.get(context.fPlayer);
if (board == null) { if (board == null) {
me.sendMessage(TL.COMMAND_TOGGLESB_DISABLED.toString()); context.msg(TL.COMMAND_TOGGLESB_DISABLED.toString());
} else { } else {
me.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggleTo))); context.msg(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggleTo)));
board.setSidebarVisibility(toggleTo); board.setSidebarVisibility(toggleTo);
} }
fme.setShowScoreboard(toggleTo); context.fPlayer.setShowScoreboard(toggleTo);
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.shop.ShopConfig;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -14,26 +15,18 @@ public class CmdSaveAll extends FCommand {
this.aliases.add("saveall"); this.aliases.add("saveall");
this.aliases.add("save"); this.aliases.add("save");
//this.requiredArgs.add(""); this.requirements = new CommandRequirements.Builder(Permission.SAVE)
//this.optionalArgs.put("", ""); .build();
this.permission = Permission.SAVE.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayers.getInstance().forceSave(false); FPlayers.getInstance().forceSave(false);
Factions.getInstance().forceSave(false); Factions.getInstance().forceSave(false);
Board.getInstance().forceSave(false); Board.getInstance().forceSave(false);
Conf.save(); Conf.save();
msg(TL.COMMAND_SAVEALL_SUCCESS); ShopConfig.saveShop();
context.msg(TL.COMMAND_SAVEALL_SUCCESS);
} }
@Override @Override

View File

@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.Particles.ParticleEffect; import com.massivecraft.factions.util.Particles.ParticleEffect;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.util.VisualizeUtil;
@ -17,7 +17,7 @@ public class CmdSeeChunk extends FCommand {
//Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn. //Used a hashmap cuz imma make a particle selection gui later, will store it where the boolean is rn.
public static HashMap<String, Boolean> seeChunkMap = new HashMap<>(); public static HashMap<String, Boolean> seeChunkMap = new HashMap<>();
Long interval; private long interval;
private boolean useParticles; private boolean useParticles;
private ParticleEffect effect; private ParticleEffect effect;
private int taskID = -1; private int taskID = -1;
@ -31,30 +31,26 @@ public class CmdSeeChunk extends FCommand {
aliases.add("seechunk"); aliases.add("seechunk");
aliases.add("sc"); aliases.add("sc");
permission = Permission.SEECHUNK.node; this.useParticles = FactionsPlugin.getInstance().getConfig().getBoolean("see-chunk.particles", true);
interval = FactionsPlugin.getInstance().getConfig().getLong("see-chunk.interval", 10L);
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.useParticles = p.getConfig().getBoolean("see-chunk.particles", true);
interval = P.p.getConfig().getLong("see-chunk.interval", 10L);
if (effect == null) { if (effect == null) {
effect = ParticleEffect.REDSTONE; effect = ParticleEffect.REDSTONE;
} }
this.requirements = new CommandRequirements.Builder(Permission.SEECHUNK)
.playerOnly()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (seeChunkMap.containsKey(me.getName())) { if (seeChunkMap.containsKey(context.player.getName())) {
seeChunkMap.remove(me.getName()); seeChunkMap.remove(context.player.getName());
msg(TL.COMMAND_SEECHUNK_DISABLED); context.msg(TL.COMMAND_SEECHUNK_DISABLED);
} else { } else {
seeChunkMap.put(me.getName(), true); seeChunkMap.put(context.player.getName(), true);
msg(TL.COMMAND_SEECHUNK_ENABLED); context.msg(TL.COMMAND_SEECHUNK_ENABLED);
manageTask(); manageTask();
} }
} }
@ -71,7 +67,7 @@ public class CmdSeeChunk extends FCommand {
} }
private void startTask() { private void startTask() {
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> { taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> {
for (Object nameObject : seeChunkMap.keySet()) { for (Object nameObject : seeChunkMap.keySet()) {
String name = nameObject + ""; String name = nameObject + "";
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
@ -115,10 +111,10 @@ public class CmdSeeChunk extends FCommand {
continue; continue;
} }
if (useParticles) { if (useParticles) {
if (P.p.useNonPacketParticles) { if (FactionsPlugin.getInstance().useNonPacketParticles) {
// Dust options only exists in the 1.13 API, so we use an // Dust options only exists in the 1.13 API, so we use an
// alternative method to achieve this in lower versions. // alternative method to achieve this in lower versions.
if (P.p.mc113) { if (FactionsPlugin.getInstance().mc113 || FactionsPlugin.getInstance().mc114) {
player.spawnParticle(Particle.REDSTONE, loc, 0, new Particle.DustOptions(Color.RED, 1)); player.spawnParticle(Particle.REDSTONE, loc, 0, new Particle.DustOptions(Color.RED, 1));
} else { } else {
player.getWorld().spawnParticle(Particle.REDSTONE, loc, 0, 255, 0, 0, 1); player.getWorld().spawnParticle(Particle.REDSTONE, loc, 0, 255, 0, 0, 1);

View File

@ -9,24 +9,20 @@ public class CmdSetBanner extends FCommand {
super(); super();
aliases.add("setbanner"); aliases.add("setbanner");
permission = Permission.BANNER.node; this.requirements = new CommandRequirements.Builder(Permission.BANNER)
.playerOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = true;
} }
public void perform() { @Override
if (!me.getItemInHand().getType().toString().contains("BANNER")) { public void perform(CommandContext context) {
fme.msg(TL.COMMAND_SETBANNER_NOTBANNER); if (!context.player.getItemInHand().getType().toString().contains("BANNER")) {
context.msg(TL.COMMAND_SETBANNER_NOTBANNER);
return; return;
} }
fme.getFaction().setBannerPattern(me.getItemInHand()); context.faction.setBannerPattern(context.player.getItemInHand());
fme.msg(TL.COMMAND_SETBANNER_SUCCESS); context.msg(TL.COMMAND_SETBANNER_SUCCESS);
} }

View File

@ -15,30 +15,28 @@ public class CmdSetDefaultRole extends FCommand {
this.aliases.add("def"); this.aliases.add("def");
this.requiredArgs.add("role"); this.requiredArgs.add("role");
this.senderMustBeAdmin = true; this.requirements = new CommandRequirements.Builder(Permission.DEFAULTRANK)
this.senderMustBePlayer = true; .playerOnly()
senderMustBeColeader = false; .memberOnly()
.build();
this.permission = Permission.DEFAULTRANK.node;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Role target = Role.fromString(argAsString(0).toUpperCase()); Role target = Role.fromString(context.argAsString(0).toUpperCase());
if (target == null) { if (target == null) {
msg(TL.COMMAND_SETDEFAULTROLE_INVALIDROLE, argAsString(0)); context.msg(TL.COMMAND_SETDEFAULTROLE_INVALIDROLE, context.argAsString(0));
return; return;
} }
if (target == Role.LEADER) { if (target == Role.LEADER) {
msg(TL.COMMAND_SETDEFAULTROLE_NOTTHATROLE, argAsString(0)); context.msg(TL.COMMAND_SETDEFAULTROLE_NOTTHATROLE, context.argAsString(0));
return; return;
} }
myFaction.setDefaultRole(target); context.faction.setDefaultRole(target);
msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename); context.msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename);
} }
@Override @Override

View File

@ -1,12 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.LazyLocation; import com.massivecraft.factions.util.LazyLocation;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -17,63 +15,51 @@ public class CmdSetFWarp extends FCommand {
this.aliases.add("setwarp"); this.aliases.add("setwarp");
this.aliases.add("sw"); this.aliases.add("sw");
this.requiredArgs.add("warp name"); this.requiredArgs.add("warp name");
this.optionalArgs.put("password", "password"); this.optionalArgs.put("password", "password");
this.senderMustBeMember = true; this.requirements = new CommandRequirements.Builder(Permission.SETWARP)
this.senderMustBeModerator = false; .playerOnly()
.memberOnly()
this.senderMustBePlayer = true; .withAction(PermissableAction.SETWARP)
.build();
this.permission = Permission.SETWARP.node;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!(fme.getRelationToLocation() == Relation.MEMBER)) { if (!(context.fPlayer.getRelationToLocation() == Relation.MEMBER)) {
fme.msg(TL.COMMAND_SETFWARP_NOTCLAIMED); context.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
return; return;
} }
// This statement allows us to check if they've specifically denied it, or default to String warp = context.argAsString(0);
// the old setting of allowing moderators to set warps.
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.SETWARP);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps");
return;
}
}
String warp = argAsString(0);
// Checks if warp with same name already exists and ignores maxWarp check if it does. // Checks if warp with same name already exists and ignores maxWarp check if it does.
boolean warpExists = myFaction.isWarp(warp); boolean warpExists = context.faction.isWarp(warp);
int maxWarps = P.p.getConfig().getInt("max-warps", 5); int maxWarps = FactionsPlugin.getInstance().getConfig().getInt("max-warps", 5);
boolean tooManyWarps = maxWarps <= myFaction.getWarps().size(); boolean tooManyWarps = maxWarps <= context.faction.getWarps().size();
if (tooManyWarps && !warpExists) { if (tooManyWarps && !warpExists) {
fme.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps); context.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
return; return;
} }
if (!transact(fme)) { if (!transact(context.fPlayer, context)) {
return; return;
} }
String password = argAsString(1); String password = context.argAsString(1);
LazyLocation loc = new LazyLocation(fme.getPlayer().getLocation()); LazyLocation loc = new LazyLocation(context.player.getLocation());
myFaction.setWarp(warp, loc); context.faction.setWarp(warp, loc);
if (password != null) { if (password != null) {
myFaction.setWarpPassword(warp, password); context.faction.setWarpPassword(warp, password);
} }
fme.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : ""); context.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : "");
} }
private boolean transact(FPlayer player) { private boolean transact(FPlayer player, CommandContext context) {
return !P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(P.p.getConfig().getDouble("warp-cost.setwarp", 5), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString()); return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.setwarp", 5), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString());
} }
@Override @Override
@ -81,3 +67,4 @@ public class CmdSetFWarp extends FCommand {
return TL.COMMAND_SETFWARP_DESCRIPTION; return TL.COMMAND_SETFWARP_DESCRIPTION;
} }
} }

View File

@ -10,37 +10,29 @@ public class CmdSetMaxVaults extends FCommand {
public CmdSetMaxVaults() { public CmdSetMaxVaults() {
this.aliases.add("setmaxvaults"); this.aliases.add("setmaxvaults");
this.aliases.add("smv"); this.aliases.add("smv");
this.requiredArgs.add("faction"); this.requiredArgs.add("faction");
this.requiredArgs.add("number"); this.requiredArgs.add("number");
this.permission = Permission.SETMAXVAULTS.node; this.requirements = new CommandRequirements.Builder(Permission.SETMAXVAULTS)
this.disableOnLock = false; .build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Faction targetFaction = argAsFaction(0); Faction targetFaction = context.argAsFaction(0);
int value = argAsInt(1, -1); int value = context.argAsInt(1, -1);
if (value < 0) { if (value < 0) {
sender.sendMessage(ChatColor.RED + "Number must be greater than 0."); context.sender.sendMessage(ChatColor.RED + "Number must be greater than 0.");
return; return;
} }
if (targetFaction == null) { if (targetFaction == null) {
sender.sendMessage(ChatColor.RED + "Couldn't find Faction: " + ChatColor.YELLOW + argAsString(0)); context.sender.sendMessage(ChatColor.RED + "Couldn't find Faction: " + ChatColor.YELLOW + context.argAsString(0));
return; return;
} }
targetFaction.setMaxVaults(value); targetFaction.setMaxVaults(value);
sender.sendMessage(TL.COMMAND_SETMAXVAULTS_SUCCESS.format(targetFaction.getTag(), value)); context.sender.sendMessage(TL.COMMAND_SETMAXVAULTS_SUCCESS.format(targetFaction.getTag(), value));
} }
@Override @Override

View File

@ -1,12 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board; import com.massivecraft.factions.*;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission; 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.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -14,60 +9,46 @@ public class CmdSethome extends FCommand {
public CmdSethome() { public CmdSethome() {
this.aliases.add("sethome"); this.aliases.add("sethome");
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "mine"); this.optionalArgs.put("faction tag", "mine");
this.permission = Permission.SETHOME.node; this.requirements = new CommandRequirements.Builder(Permission.SETHOME)
this.disableOnLock = true; .playerOnly()
.memberOnly()
senderMustBePlayer = true; .withAction(PermissableAction.SETHOME)
senderMustBeMember = false; .build();
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!Conf.homesEnabled) { if (!Conf.homesEnabled) {
fme.msg(TL.COMMAND_SETHOME_DISABLED); context.msg(TL.COMMAND_SETHOME_DISABLED);
return; return;
} }
Faction faction = this.argAsFaction(0, myFaction); Faction faction = context.argAsFaction(0, context.faction);
if (faction == null) { if (faction == null) {
return; return;
} }
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.SETHOME);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER && !Permission.SETHOME_ANY.has(sender, true)) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set home");
return;
}
}
// Can the player set the faction home HERE? // Can the player set the faction home HERE?
if (!Permission.BYPASS.has(me) && if (!Permission.BYPASS.has(context.player) &&
Conf.homesMustBeInClaimedTerritory && Conf.homesMustBeInClaimedTerritory &&
Board.getInstance().getFactionAt(new FLocation(me)) != faction) { Board.getInstance().getFactionAt(new FLocation(context.player)) != faction) {
fme.msg(TL.COMMAND_SETHOME_NOTCLAIMED); context.msg(TL.COMMAND_SETHOME_NOTCLAIMED);
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostSethome, TL.COMMAND_SETHOME_TOSET, TL.COMMAND_SETHOME_FORSET)) { if (!context.payForCommand(Conf.econCostSethome, TL.COMMAND_SETHOME_TOSET, TL.COMMAND_SETHOME_FORSET)) {
return; return;
} }
faction.setHome(me.getLocation()); faction.setHome(context.player.getLocation());
faction.msg(TL.COMMAND_SETHOME_SET, fme.describeTo(myFaction, true)); faction.msg(TL.COMMAND_SETHOME_SET, context.fPlayer.describeTo(context.faction, true));
faction.sendMessage(p.cmdBase.cmdHome.getUseageTemplate()); faction.sendMessage(FactionsPlugin.getInstance().cmdBase.cmdHome.getUseageTemplate(context));
if (faction != myFaction) { if (faction != context.faction) {
fme.msg(TL.COMMAND_SETHOME_SETOTHER, faction.getTag(fme)); context.msg(TL.COMMAND_SETHOME_SETOTHER, faction.getTag(context.fPlayer));
} }
} }

View File

@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagReplacer; import com.massivecraft.factions.zcore.util.TagReplacer;
@ -19,14 +19,12 @@ public class CmdShow extends FCommand {
public CmdShow() { public CmdShow() {
this.aliases.add("show"); this.aliases.add("show");
this.aliases.add("who"); this.aliases.add("who");
this.aliases.add("f");
// add defaults to /f show in case config doesnt have it // add defaults to /f show in case config doesnt have it
defaults.add("{header}"); defaults.add("{header}");
defaults.add("<a>Description: <i>{description}"); defaults.add("<a>Description: <i>{description}");
defaults.add("<a>Joining: <i>{joining} {peaceful}"); defaults.add("<a>Joining: <i>{joining} {peaceful}");
defaults.add("<a>Land / Power / Maxpower: <i> {chunks} / {power} / {maxPower}"); defaults.add("<a>Land / Power / Maxpower: <i> {chunks} / {power} / {maxPower}");
defaults.add("<a>Faction Strikes: {strikes}");
defaults.add("<a>Founded: <i>{create-date}"); defaults.add("<a>Founded: <i>{create-date}");
defaults.add("<a>This faction is permanent, remaining even with no members."); defaults.add("<a>This faction is permanent, remaining even with no members.");
defaults.add("<a>Land value: <i>{land-value} {land-refund}"); defaults.add("<a>Land value: <i>{land-value} {land-refund}");
@ -34,69 +32,63 @@ public class CmdShow extends FCommand {
defaults.add("<a>Allies(<i>{allies}<a>/<i>{max-allies}<a>): {allies-list}"); defaults.add("<a>Allies(<i>{allies}<a>/<i>{max-allies}<a>): {allies-list}");
defaults.add("<a>Online: (<i>{online}<a>/<i>{members}<a>): {online-list}"); defaults.add("<a>Online: (<i>{online}<a>/<i>{members}<a>): {online-list}");
defaults.add("<a>Offline: (<i>{offline}<a>/<i>{members}<a>): {offline-list}"); defaults.add("<a>Offline: (<i>{offline}<a>/<i>{members}<a>): {offline-list}");
defaults.add("<a>Alt List: <i>{alts}");
// this.requiredArgs.add(""); // this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours"); this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.SHOW.node; this.requirements = new CommandRequirements.Builder(Permission.SHOW).build();
this.disableOnLock = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
Faction faction = myFaction; Faction faction = context.faction;
if (this.argIsSet(0)) if (context.argIsSet(0))
faction = this.argAsFaction(0); faction = context.argAsFaction(0);
if (faction == null) if (faction == null)
return; return;
if (fme != null && !fme.getPlayer().hasPermission("factions.show.bypassexempt") if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt")
&& P.p.getConfig().getStringList("show-exempt").contains(faction.getTag())) { && FactionsPlugin.getInstance().getConfig().getStringList("show-exempt").contains(faction.getTag())) {
msg(TL.COMMAND_SHOW_EXEMPT); context.msg(TL.COMMAND_SHOW_EXEMPT);
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) { if (!context.payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) {
return; return;
} }
List<String> show = P.p.getConfig().getStringList("show"); List<String> show = FactionsPlugin.getInstance().getConfig().getStringList("show");
if (show == null || show.isEmpty()) if (show == null || show.isEmpty())
show = defaults; show = defaults;
if (!faction.isNormal()) { if (!faction.isNormal()) {
String tag = faction.getTag(fme); String tag = faction.getTag(context.fPlayer);
// send header and that's all // send header and that's all
String header = show.get(0); String header = show.get(0);
if (TagReplacer.HEADER.contains(header)) { if (TagReplacer.HEADER.contains(header)) {
msg(p.txt.titleize(tag)); context.msg(FactionsPlugin.getInstance().txt.titleize(tag));
} else { } else {
msg(p.txt.parse(TagReplacer.FACTION.replace(header, tag))); context.msg(FactionsPlugin.getInstance().txt.parse(TagReplacer.FACTION.replace(header, tag)));
} }
return; // we only show header for non-normal factions return; // we only show header for non-normal factions
} }
for (String raw : show) { for (String raw : show) {
String parsed = TagUtil.parsePlain(faction, fme, raw); // use relations String parsed = TagUtil.parsePlain(faction, context.fPlayer, raw); // use relations
if (parsed == null) { if (parsed == null) {
continue; // Due to minimal f show. continue; // Due to minimal f show.
} }
if (fme != null) { if (context.fPlayer != null) {
parsed = TagUtil.parsePlaceholders(fme.getPlayer(), parsed); parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed);
} }
if (TagUtil.hasFancy(parsed)) { if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> fancy = TagUtil.parseFancy(faction, fme, parsed); List<FancyMessage> fancy = TagUtil.parseFancy(faction, context.fPlayer, parsed);
if (fancy != null) if (fancy != null)
sendFancyMessage(fancy); context.sendFancyMessage(fancy);
continue; continue;
} }
@ -108,7 +100,7 @@ public class CmdShow extends FCommand {
if (parsed.contains("%")) { if (parsed.contains("%")) {
parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it.
} }
msg(p.txt.parse(parsed)); context.msg(FactionsPlugin.getInstance().txt.parse(parsed));
} }
} }
} }

View File

@ -9,39 +9,37 @@ import com.massivecraft.factions.zcore.util.TL;
public class CmdShowClaims extends FCommand { public class CmdShowClaims extends FCommand {
public CmdShowClaims() { public CmdShowClaims() {
this.aliases.add("showclaims"); this.aliases.add("showclaims");
this.aliases.add("showclaim"); this.aliases.add("showclaim");
permission = Permission.SHOWCLAIMS.node; this.requirements = new CommandRequirements.Builder(Permission.SHOWCLAIMS)
.playerOnly()
this.senderMustBePlayer = true; .memberOnly()
this.senderMustBeMember = true; .build();
this.senderMustBeModerator = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}", fme.getFaction().describeTo(fme))); context.sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}", context.faction.describeTo(context.fPlayer)));
ListMultimap<String, String> chunkMap = ArrayListMultimap.create(); ListMultimap<String, String> chunkMap = ArrayListMultimap.create();
String format = TL.COMMAND_SHOWCLAIMS_CHUNKSFORMAT.toString(); String format = TL.COMMAND_SHOWCLAIMS_CHUNKSFORMAT.toString();
for (FLocation fLocation : fme.getFaction().getAllClaims()) { for (FLocation fLocation : context.faction.getAllClaims()) {
chunkMap.put(fLocation.getWorldName(), format.replace("{x}", fLocation.getX() + "").replace("{z}", fLocation.getZ() + "")); chunkMap.put(fLocation.getWorldName(), format.replace("{x}", fLocation.getX() + "").replace("{z}", fLocation.getZ() + ""));
} }
for (String world : chunkMap.keySet()) { for (String world : chunkMap.keySet()) {
String message = TL.COMMAND_SHOWCLAIMS_FORMAT.toString().replace("{world}", world); String message = TL.COMMAND_SHOWCLAIMS_FORMAT.toString().replace("{world}", world);
// made {chunks} blank as I removed the placeholder and people wont update their config :shrug: // made {chunks} blank as I removed the placeholder and people wont update their config :shrug:
sendMessage(message.replace("{chunks}", "")); context.sendMessage(message.replace("{chunks}", ""));
StringBuilder chunks = new StringBuilder(); StringBuilder chunks = new StringBuilder();
for (String chunkString : chunkMap.get(world)) { for (String chunkString : chunkMap.get(world)) {
chunks.append(chunkString).append(", "); chunks.append(chunkString).append(", ");
if (chunks.toString().length() >= 2000) { if (chunks.toString().length() >= 2000) {
sendMessage(chunks.toString()); context.sendMessage(chunks.toString());
chunks.setLength(0); chunks.setLength(0);
} }
} }
if (chunks.length() != 0) sendMessage(chunks.toString()); if (chunks.length() != 0) context.sendMessage(chunks.toString());
sendMessage(""); context.sendMessage("");
} }
@ -54,3 +52,4 @@ public class CmdShowClaims extends FCommand {
} }

View File

@ -13,23 +13,24 @@ public class CmdShowInvites extends FCommand {
public CmdShowInvites() { public CmdShowInvites() {
super(); super();
aliases.add("showinvites"); aliases.add("showinvites");
permission = Permission.SHOW_INVITES.node;
senderMustBePlayer = true; this.requirements = new CommandRequirements.Builder(Permission.SHOW_INVITES)
senderMustBeMember = true; .playerOnly()
.memberOnly()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FancyMessage msg = new FancyMessage(TL.COMMAND_SHOWINVITES_PENDING.toString()).color(ChatColor.GOLD); FancyMessage msg = new FancyMessage(TL.COMMAND_SHOWINVITES_PENDING.toString()).color(ChatColor.GOLD);
for (String id : myFaction.getInvites()) { for (String id : context.faction.getInvites()) {
FPlayer fp = FPlayers.getInstance().getById(id); FPlayer fp = FPlayers.getInstance().getById(id);
String name = fp != null ? fp.getName() : id; String name = fp != null ? fp.getName() : id;
msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_SHOWINVITES_CLICKTOREVOKE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name); msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_SHOWINVITES_CLICKTOREVOKE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name);
} }
sendFancyMessage(msg); context.sendFancyMessage(msg);
} }
@Override @Override
@ -39,3 +40,4 @@ public class CmdShowInvites extends FCommand {
} }

View File

@ -1,33 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdSpam extends FCommand {
public CmdSpam() {
this.aliases.add("spam");
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.SPAM.node;
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
p.setSpam(this.argAsBool(0, !p.getSpam()));
msg(p.getSpam() ? TL.COMMAND_SPAM_ENABLED : TL.COMMAND_SPAM_DISABLED);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SPAM_DESCRIPTION;
}
}

View File

@ -15,25 +15,22 @@ public class CmdStatus extends FCommand {
this.aliases.add("status"); this.aliases.add("status");
this.aliases.add("s"); this.aliases.add("s");
this.permission = Permission.STATUS.node; this.requirements = new CommandRequirements.Builder(Permission.STATUS)
.playerOnly()
senderMustBePlayer = true; .memberOnly()
senderMustBeMember = true; .build();
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
ArrayList<String> ret = new ArrayList<>(); ArrayList<String> ret = new ArrayList<>();
for (FPlayer fp : myFaction.getFPlayers()) { for (FPlayer fp : context.faction.getFPlayers()) {
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX; String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
String last = fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized); String last = fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
String power = ChatColor.YELLOW + String.valueOf(fp.getPowerRounded()) + " / " + fp.getPowerMaxRounded() + ChatColor.RESET; String power = ChatColor.YELLOW + String.valueOf(fp.getPowerRounded()) + " / " + fp.getPowerMaxRounded() + ChatColor.RESET;
ret.add(String.format(TL.COMMAND_STATUS_FORMAT.toString(), ChatColor.GOLD + fp.getRole().getPrefix() + fp.getName() + ChatColor.RESET, power, last).trim()); ret.add(String.format(TL.COMMAND_STATUS_FORMAT.toString(), ChatColor.GOLD + fp.getRole().getPrefix() + fp.getName() + ChatColor.RESET, power, last).trim());
} }
fme.sendMessage(ret); context.fPlayer.sendMessage(ret);
} }
@Override @Override

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -8,27 +7,19 @@ public class CmdStealth extends FCommand {
public CmdStealth() { public CmdStealth() {
this.aliases.add("ninja"); this.aliases.add("ninja");
this.aliases.add("stealth"); this.aliases.add("stealth");
this.permission = Permission.STEALTH.node;
this.disableOnLock = true;
this.senderMustBePlayer = true;
this.senderMustBeMember = false;
this.senderMustBeModerator = false;
this.senderMustBeColeader = false;
this.senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.STEALTH)
.playerOnly()
.build();
} }
public void perform() { @Override
public void perform(CommandContext context) {
if (context.faction != null && !context.faction.getId().equalsIgnoreCase("0") && !context.faction.getId().equalsIgnoreCase("none") && !context.faction.getId().equalsIgnoreCase("safezone") && !context.faction.getId().equalsIgnoreCase("warzone")) {
Faction faction = fme.getFaction(); context.fPlayer.setStealth(!context.fPlayer.isStealthEnabled());
if (faction != null && !faction.getId().equalsIgnoreCase("0") && !faction.getId().equalsIgnoreCase("none") && !faction.getId().equalsIgnoreCase("safezone") && !faction.getId().equalsIgnoreCase("warzone")) { context.msg(context.fPlayer.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE);
fme.setStealth(!fme.isStealthEnabled());
fme.msg(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE);
} else { } else {
fme.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER); context.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER);
} }
} }

View File

@ -1,52 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.zcore.util.TL;
public class CmdStrike extends FCommand {
public CmdStrike() {
super();
this.aliases.add("strike");
this.aliases.add("strikes");
this.optionalArgs.put("faction", "tag");
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
if (args.size() == 0) {
if (myFaction.isWilderness()) {
fme.msg(TL.COMMAND_STRIKE_NEEDFACTION);
return;
}
fme.msg(TL.COMMAND_STRIKE_MESSAGE.toString().replace("{faction}", fme.getFaction().getTag()).replace("{strikes}", fme.getFaction().getStrikes() + ""));
return;
}
Faction faction = Factions.getInstance().getByTag(args.get(0));
if (faction != null) {
fme.msg(TL.COMMAND_STRIKE_MESSAGE.toString().replace("{faction}", faction.getTag()).replace("{strikes}", faction.getStrikes() + ""));
} else {
fme.msg(TL.COMMAND_STRIKE_NOTFOUND.toString().replace("{faction}", args.get(0)));
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STUCK_DESCRIPTION;
}
}

View File

@ -1,86 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdStrikeSet extends FCommand {
public CmdStrikeSet() {
super();
this.aliases.add("setstrikes");
this.aliases.add("setstrike");
this.requiredArgs.add("set,give,remove");
this.requiredArgs.add("faction");
this.requiredArgs.add("# of strikes");
this.requiredArgs.add("reason");
this.errorOnToManyArgs = false;
//this.optionalArgs
this.permission = Permission.SETSTRIKES.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(1));
boolean success = false;
if (faction == null) {
fme.msg(TL.COMMAND_SETSTRIKES_FAILURE.toString().replace("{faction}", args.get(1)));
}
if (faction != null) {
if (args.get(0).equalsIgnoreCase("set")) {
faction.setStrikes(argAsInt(2));
success = true;
} else if (args.get(0).equalsIgnoreCase("give")) {
faction.setStrikes(faction.getStrikes() + argAsInt(2));
success = true;
} else if (args.get(0).equalsIgnoreCase("take")) {
faction.setStrikes(faction.getStrikes() - argAsInt(2));
success = true;
}
if (success) {
for (FPlayer fPlayer : FPlayers.getInstance().getOnlinePlayers()) {
fPlayer.msg(TL.COMMAND_SETSTRIKES_BROADCAST.toString()
.replace("{faction}", faction.getTag())
.replace("{reason}", getReason()));
}
fme.msg(TL.COMMAND_SETSTRIKES_SUCCESS.toString()
.replace("{faction}", faction.getTag())
.replace("{strikes}", faction.getStrikes() + ""));
}
}
}
private String getReason() {
StringBuilder reason = new StringBuilder();
for (int i = 3; i < args.size(); i++) {
reason.append(args.get(i)).append(" ");
}
return reason.toString();
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SETSTRIKES_DESCRIPTION;
}
}

View File

@ -0,0 +1,41 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdStrikes extends FCommand {
public CmdStrikesGive cmdStrikesGive = new CmdStrikesGive();
public CmdStrikesInfo cmdStrikesInfo = new CmdStrikesInfo();
public CmdStrikesSet cmdStrikesSet = new CmdStrikesSet();
public CmdStrikesTake cmdStrikesTake = new CmdStrikesTake();
public CmdStrikes() {
super();
this.aliases.add("strikes");
this.addSubCommand(cmdStrikesGive);
this.addSubCommand(cmdStrikesInfo);
this.addSubCommand(cmdStrikesSet);
this.addSubCommand(cmdStrikesTake);
this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
context.commandChain.add(this);
FactionsPlugin.getInstance().cmdAutoHelp.execute(context);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STRIKES_DESCRIPTION;
}
}

View File

@ -0,0 +1,37 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdStrikesGive extends FCommand {
public CmdStrikesGive() {
super();
this.aliases.add("give");
this.requiredArgs.add(0, "faction");
this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
Faction target = context.argAsFaction(0);
if (target == null || target.isSystemFaction()) {
context.msg(TL.COMMAND_STRIKES_TARGET_INVALID, context.argAsString(0));
return;
}
target.setStrikes(target.getStrikes() + 1);
context.msg(TL.COMMAND_STRIKES_CHANGED, target.getTag(), target.getStrikes());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STRIKESGIVE_DESCRIPTION;
}
}

View File

@ -0,0 +1,37 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdStrikesInfo extends FCommand {
public CmdStrikesInfo() {
super();
this.aliases.add("info");
this.optionalArgs.put("target", "faction");
this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
Faction target = context.argAsFaction(0);
if (target == null) target = context.faction;
if (target.isSystemFaction()) {
context.msg(TL.COMMAND_STRIKES_TARGET_INVALID, context.argAsString(0));
return;
}
context.msg(TL.COMMAND_STRIKES_INFO, target.getTag(), target.getStrikes());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STRIKESINFO_DESCRIPTION;
}
}

View File

@ -0,0 +1,37 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdStrikesSet extends FCommand {
public CmdStrikesSet() {
super();
this.aliases.add("set");
this.requiredArgs.add(0, "faction");
this.requiredArgs.add(1, "amount");
this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
Faction target = context.argAsFaction(0);
if (target == null || target.isSystemFaction()) {
context.msg(TL.COMMAND_STRIKES_TARGET_INVALID, context.argAsString(0));
return;
}
target.setStrikes(context.argAsInt(1));
context.msg(TL.COMMAND_STRIKES_CHANGED, target.getTag(), target.getStrikes());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STRIKESET_DESCRIPTION;
}
}

View File

@ -0,0 +1,38 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdStrikesTake extends FCommand {
public CmdStrikesTake() {
super();
this.aliases.add("take");
this.requiredArgs.add(0, "faction");
this.requiredArgs.add(1, "number of strikes");
this.requirements = new CommandRequirements.Builder(Permission.SETSTRIKES)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
Faction target = context.argAsFaction(0);
if (target == null || target.isSystemFaction()) {
context.msg(TL.COMMAND_STRIKES_TARGET_INVALID, context.argAsString(0));
return;
}
target.setStrikes(target.getStrikes() - context.argAsInt(1));
context.msg(TL.COMMAND_STRIKES_CHANGED, target.getTag(), target.getStrikes());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STRIKETAKE_DESCRIPTION;
}
}

View File

@ -10,87 +10,75 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class CmdStuck extends FCommand { public class CmdStuck extends FCommand {
public CmdStuck() { public CmdStuck() {
super(); super();
this.aliases.add("stuck"); this.aliases.add("stuck");
this.aliases.add("halp!"); // halp!c: this.aliases.add("halp!"); // halp!c:
this.permission = Permission.STUCK.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.STUCK)
.playerOnly()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
final Player player = fme.getPlayer(); final Player player = context.player;
final Location sentAt = player.getLocation(); final Location sentAt = player.getLocation();
final FLocation chunk = fme.getLastStoodAt(); final FLocation chunk = context.fPlayer.getLastStoodAt();
final long delay = P.p.getConfig().getLong("hcf.stuck.delay", 30); final long delay = FactionsPlugin.getInstance().getConfig().getLong("hcf.stuck.delay", 30);
final int radius = P.p.getConfig().getInt("hcf.stuck.radius", 10); final int radius = FactionsPlugin.getInstance().getConfig().getInt("hcf.stuck.radius", 10);
if (P.p.getStuckMap().containsKey(player.getUniqueId())) { if (FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) {
long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis(); long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true); String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
msg(TL.COMMAND_STUCK_EXISTS, time); context.msg(TL.COMMAND_STUCK_EXISTS, time);
} else { } else {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostStuck, TL.COMMAND_STUCK_TOSTUCK.format(fme.getName()), TL.COMMAND_STUCK_FORSTUCK.format(fme.getName()))) { if (!context.payForCommand(Conf.econCostStuck, TL.COMMAND_STUCK_TOSTUCK.format(context.fPlayer.getName()), TL.COMMAND_STUCK_FORSTUCK.format(context.fPlayer.getName()))) {
return; return;
} }
final int id = Bukkit.getScheduler().runTaskLater(P.p, new BukkitRunnable() { final int id = Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), new Runnable() {
@Override @Override
public void run() { public void run() {
if (!P.p.getStuckMap().containsKey(player.getUniqueId())) { if (!FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) {
return; return;
} }
// check for world difference or radius exceeding // check for world difference or radius exceeding
final World world = chunk.getWorld(); final World world = chunk.getWorld();
if (world.getUID() != player.getWorld().getUID() || sentAt.distance(player.getLocation()) > radius) { if (world.getUID() != player.getWorld().getUID() || sentAt.distance(player.getLocation()) > radius) {
msg(TL.COMMAND_STUCK_OUTSIDE.format(radius)); context.msg(TL.COMMAND_STUCK_OUTSIDE.format(radius));
P.p.getTimers().remove(player.getUniqueId()); FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId());
P.p.getStuckMap().remove(player.getUniqueId()); FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId());
return; return;
} }
final Board board = Board.getInstance(); final Board board = Board.getInstance();
// spiral task to find nearest wilderness chunk // spiral task to find nearest wilderness chunk
new SpiralTask(new FLocation(me), radius * 2) { new SpiralTask(new FLocation(context.player), radius * 2) {
final int buffer = P.p.getConfig().getInt("world-border.buffer", 0);
@Override @Override
public boolean work() { public boolean work() {
FLocation chunk = currentFLocation(); FLocation chunk = currentFLocation();
if (chunk.isOutsideWorldBorder(buffer)) {
return true;
}
Faction faction = board.getFactionAt(chunk); Faction faction = board.getFactionAt(chunk);
int buffer = P.p.getConfig().getInt("world-border.buffer", 0); int buffer = FactionsPlugin.getInstance().getConfig().getInt("world-border.buffer", 0) - 1;
if (faction.isWilderness() && !chunk.isOutsideWorldBorder(buffer)) { if (faction.isWilderness() && !chunk.isOutsideWorldBorder(buffer)) {
int cx = FLocation.chunkToBlock((int) chunk.getX()); int cx = FLocation.chunkToBlock((int) chunk.getX());
int cz = FLocation.chunkToBlock((int) chunk.getZ()); int cz = FLocation.chunkToBlock((int) chunk.getZ());
int y = world.getHighestBlockYAt(cx, cz); int y = world.getHighestBlockYAt(cx, cz);
Location tp = new Location(world, cx, y, cz); Location tp = new Location(world, cx, y, cz);
msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ()); context.msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ());
P.p.getTimers().remove(player.getUniqueId()); FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId());
P.p.getStuckMap().remove(player.getUniqueId()); FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId());
if (!Essentials.handleTeleport(player, tp)) { if (!Essentials.handleTeleport(player, tp)) {
player.teleport(tp); player.teleport(tp);
P.p.debug("/f stuck used regular teleport, not essentials!"); FactionsPlugin.getInstance().debug("/f stuck used regular teleport, not essentials!");
} }
this.stop(); this.stop();
return false; return false;
@ -101,11 +89,11 @@ public class CmdStuck extends FCommand {
} }
}, delay * 20).getTaskId(); }, delay * 20).getTaskId();
P.p.getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000)); FactionsPlugin.getInstance().getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000));
long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis(); long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true); String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
msg(TL.COMMAND_STUCK_START, time); context.msg(TL.COMMAND_STUCK_START, time);
P.p.getStuckMap().put(player.getUniqueId(), id); FactionsPlugin.getInstance().getStuckMap().put(player.getUniqueId(), id);
} }
} }
@ -114,3 +102,4 @@ public class CmdStuck extends FCommand {
return TL.COMMAND_STUCK_DESCRIPTION; return TL.COMMAND_STUCK_DESCRIPTION;
} }
} }

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FactionRenameEvent; import com.massivecraft.factions.event.FactionRenameEvent;
import com.massivecraft.factions.scoreboards.FTeamWrapper; import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -17,77 +18,65 @@ public class CmdTag extends FCommand {
this.aliases.add("rename"); this.aliases.add("rename");
this.requiredArgs.add("faction tag"); this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.TAG.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.TAG)
.withRole(Role.COLEADER)
.playerOnly()
.memberOnly()
.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
String tag = this.argAsString(0); String tag = context.argAsString(0);
if (!fme.isCooldownEnded("tag")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("tag"));
return;
}
// TODO does not first test cover selfcase? // TODO does not first test cover selfcase?
if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) { if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(context.faction.getComparisonTag())) {
msg(TL.COMMAND_TAG_TAKEN); context.msg(TL.COMMAND_TAG_TAKEN);
return; return;
} }
ArrayList<String> errors = MiscUtil.validateTag(tag); ArrayList<String> errors = MiscUtil.validateTag(tag);
if (errors.size() > 0) { if (errors.size() > 0) {
sendMessage(errors); context.sendMessage(errors);
return; return;
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE.toString())) { if (!context.canAffordCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE.toString())) {
return; return;
} }
// trigger the faction rename event (cancellable) // trigger the faction rename event (cancellable)
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag); FactionRenameEvent renameEvent = new FactionRenameEvent(context.fPlayer, tag);
Bukkit.getServer().getPluginManager().callEvent(renameEvent); Bukkit.getServer().getPluginManager().callEvent(renameEvent);
if (renameEvent.isCancelled()) { if (renameEvent.isCancelled()) {
return; return;
} }
// then make 'em pay (if applicable) // then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE, TL.COMMAND_TAG_FORCHANGE)) { if (!context.payForCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE, TL.COMMAND_TAG_FORCHANGE)) {
return; return;
} }
String oldtag = myFaction.getTag(); String oldtag = context.faction.getTag();
myFaction.setTag(tag); context.faction.setTag(tag);
// Inform // Inform
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(myFaction.getId())) { if (fplayer.getFactionId().equals(context.faction.getId())) {
fplayer.msg(TL.COMMAND_TAG_FACTION, fme.describeTo(myFaction, true), myFaction.getTag(myFaction)); fplayer.msg(TL.COMMAND_TAG_FACTION, context.fPlayer.describeTo(context.faction, true), context.faction.getTag(context.faction));
continue; continue;
} }
// Broadcast the tag change (if applicable) // Broadcast the tag change (if applicable)
if (Conf.broadcastTagChanges) { if (Conf.broadcastTagChanges) {
Faction faction = fplayer.getFaction(); Faction faction = fplayer.getFaction();
fplayer.msg(TL.COMMAND_TAG_CHANGED, fme.getColorTo(faction) + oldtag, myFaction.getTag(faction)); fplayer.msg(TL.COMMAND_TAG_CHANGED, context.fPlayer.getColorTo(faction) + oldtag, context.faction.getTag(faction));
} }
} }
fme.setCooldown("tag", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-tag") * 1000));
FTeamWrapper.updatePrefixes(myFaction); FTeamWrapper.updatePrefixes(context.faction);
} }
@Override @Override

View File

@ -10,45 +10,26 @@ public class CmdTitle extends FCommand {
public CmdTitle() { public CmdTitle() {
this.aliases.add("title"); this.aliases.add("title");
this.requiredArgs.add("player name"); this.requiredArgs.add("player name");
this.optionalArgs.put("title", ""); this.optionalArgs.put("title", "");
this.permission = Permission.TITLE.node; this.requirements = new CommandRequirements.Builder(Permission.TITLE)
this.disableOnLock = true; .playerOnly()
.build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = context.argAsBestFPlayerMatch(0);
if (you == null) { if (you == null) return;
return; context.args.remove(0);
} String title = TextUtil.implode(context.args, " ");
if (!context.canIAdministerYou(context.fPlayer, you)) return;
args.remove(0);
String title = TextUtil.implode(args, " ");
title = title.replaceAll(",", "");
if (!canIAdministerYou(fme, you)) {
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostTitle, TL.COMMAND_TITLE_TOCHANGE, TL.COMMAND_TITLE_FORCHANGE)) { if (!context.payForCommand(Conf.econCostTitle, TL.COMMAND_TITLE_TOCHANGE, TL.COMMAND_TITLE_FORCHANGE)) return;
return; you.setTitle(context.sender, title);
}
you.setTitle(sender, title);
// Inform // Inform
myFaction.msg(TL.COMMAND_TITLE_CHANGED, fme.describeTo(myFaction, true), you.describeTo(myFaction, true)); context.faction.msg(TL.COMMAND_TITLE_CHANGED, context.fPlayer.describeTo(context.faction, true), you.describeTo(context.faction, true));
} }
@Override @Override

View File

@ -12,16 +12,10 @@ public class CmdToggleAllianceChat extends FCommand {
this.aliases.add("togglealliancechat"); this.aliases.add("togglealliancechat");
this.aliases.add("ac"); this.aliases.add("ac");
this.disableOnLock = false; this.requirements = new CommandRequirements.Builder(Permission.TOGGLE_ALLIANCE_CHAT)
.playerOnly()
this.permission = Permission.TOGGLE_ALLIANCE_CHAT.node; .memberOnly()
this.disableOnLock = false; .build();
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
@ -30,15 +24,16 @@ public class CmdToggleAllianceChat extends FCommand {
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!Conf.factionOnlyChat) { if (!Conf.factionOnlyChat) {
msg(TL.COMMAND_CHAT_DISABLED.toString()); context.msg(TL.COMMAND_CHAT_DISABLED.toString());
return; return;
} }
boolean ignoring = fme.isIgnoreAllianceChat(); boolean ignoring = context.fPlayer.isIgnoreAllianceChat();
msg(ignoring ? TL.COMMAND_TOGGLEALLIANCECHAT_UNIGNORE : TL.COMMAND_TOGGLEALLIANCECHAT_IGNORE); context.msg(ignoring ? TL.COMMAND_TOGGLEALLIANCECHAT_UNIGNORE : TL.COMMAND_TOGGLEALLIANCECHAT_IGNORE);
fme.setIgnoreAllianceChat(!ignoring); context.fPlayer.setIgnoreAllianceChat(!ignoring);
} }
} }

View File

@ -16,24 +16,16 @@ public class CmdTop extends FCommand {
super(); super();
this.aliases.add("top"); this.aliases.add("top");
this.aliases.add("t"); this.aliases.add("t");
//this.requiredArgs.add("");
this.requiredArgs.add("criteria"); this.requiredArgs.add("criteria");
this.optionalArgs.put("page", "1"); this.optionalArgs.put("page", "1");
this.permission = Permission.TOP.node; this.requirements = new CommandRequirements.Builder(Permission.TOP)
this.disableOnLock = false; .build();
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
// Can sort by: money, members, online, allies, enemies, power, land. // Can sort by: money, members, online, allies, enemies, power, land.
// Get all Factions and remove non player ones. // Get all Factions and remove non player ones.
ArrayList<Faction> factionList = Factions.getInstance().getAllFactions(); ArrayList<Faction> factionList = Factions.getInstance().getAllFactions();
@ -41,7 +33,7 @@ public class CmdTop extends FCommand {
factionList.remove(Factions.getInstance().getSafeZone()); factionList.remove(Factions.getInstance().getSafeZone());
factionList.remove(Factions.getInstance().getWarZone()); factionList.remove(Factions.getInstance().getWarZone());
String criteria = argAsString(0); String criteria = context.argAsString(0);
// TODO: Better way to sort? // TODO: Better way to sort?
if (criteria.equalsIgnoreCase("members")) { if (criteria.equalsIgnoreCase("members")) {
@ -119,14 +111,13 @@ public class CmdTop extends FCommand {
return 0; return 0;
}); });
} else { } else {
msg(TL.COMMAND_TOP_INVALID, criteria); context.msg(TL.COMMAND_TOP_INVALID, criteria);
return;
} }
ArrayList<String> lines = new ArrayList<>(); ArrayList<String> lines = new ArrayList<>();
final int pageheight = 9; final int pageheight = 9;
int pagenumber = this.argAsInt(1, 1); int pagenumber = context.argAsInt(1, 1);
int pagecount = (factionList.size() / pageheight) + 1; int pagecount = (factionList.size() / pageheight) + 1;
if (pagenumber > pagecount) { if (pagenumber > pagecount) {
pagenumber = pagecount; pagenumber = pagecount;
@ -144,12 +135,12 @@ public class CmdTop extends FCommand {
int rank = 1; int rank = 1;
for (Faction faction : factionList.subList(start, end)) { for (Faction faction : factionList.subList(start, end)) {
// Get the relation color if player is executing this. // Get the relation color if player is executing this.
String fac = sender instanceof Player ? faction.getRelationTo(fme).getColor() + faction.getTag() : faction.getTag(); String fac = context.sender instanceof Player ? faction.getRelationTo(context.fPlayer).getColor() + faction.getTag() : faction.getTag();
lines.add(TL.COMMAND_TOP_LINE.format(rank, fac, getValue(faction, criteria))); lines.add(TL.COMMAND_TOP_LINE.format(rank, fac, getValue(faction, criteria)));
rank++; rank++;
} }
sendMessage(lines); context.sendMessage(lines);
} }
private String getValue(Faction faction, String criteria) { private String getValue(Faction faction, String criteria) {

View File

@ -1,39 +1,39 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.listeners.FactionsBlockListener; import com.massivecraft.factions.listeners.FactionsBlockListener;
import com.massivecraft.factions.listeners.FactionsPlayerListener;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
public class CmdTpBanner extends FCommand { public class CmdTpBanner extends FCommand {
public CmdTpBanner() { public CmdTpBanner() {
super(); super();
this.aliases.add("tpbanner"); this.aliases.add("tpbanner");
this.permission = Permission.TPBANNER.node; this.requirements = new CommandRequirements.Builder(Permission.TPBANNER)
this.disableOnLock = true; .playerOnly()
.memberOnly()
senderMustBePlayer = true; .build();
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fbanners.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Enabled")) {
return; return;
} }
if (FactionsBlockListener.bannerLocations.containsKey(fme.getTag())) { final FactionsPlayerListener fpl = new FactionsPlayerListener();
fme.msg(TL.COMMAND_TPBANNER_SUCCESS);
this.doWarmUp(WarmUpUtil.Warmup.BANNER, TL.WARMUPS_NOTIFY_TELEPORT, "Banner", () -> me.teleport(FactionsBlockListener.bannerLocations.get(fme.getTag())), this.p.getConfig().getLong("warmups.f-banner", 0)); if (FactionsBlockListener.bannerLocations.containsKey(context.fPlayer.getTag())) {
context.msg(TL.COMMAND_TPBANNER_SUCCESS);
context.doWarmUp(WarmUpUtil.Warmup.BANNER, TL.WARMUPS_NOTIFY_TELEPORT, "Banner", () -> {
context.player.teleport(FactionsBlockListener.bannerLocations.get(context.fPlayer.getTag()));
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-banner", 0));
} else { } else {
fme.msg(TL.COMMAND_TPBANNER_NOTSET); context.msg(TL.COMMAND_TPBANNER_NOTSET);
} }
} }

View File

@ -2,7 +2,6 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission; 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.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -12,44 +11,40 @@ public class CmdUnban extends FCommand {
public CmdUnban() { public CmdUnban() {
super(); super();
this.aliases.add("unban"); this.aliases.add("unban");
this.requiredArgs.add("target"); this.requiredArgs.add("target");
this.permission = Permission.BAN.node; this.requirements = new CommandRequirements.Builder(Permission.BAN)
this.disableOnLock = true; .playerOnly()
.memberOnly()
senderMustBePlayer = true; .withAction(PermissableAction.BAN)
senderMustBeMember = false; .build();
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.BAN);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER && !Permission.BAN.has(sender, true)) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "manage bans");
return;
}
}
// Good on permission checks. Now lets just ban the player. // Good on permission checks. Now lets just ban the player.
FPlayer target = argAsFPlayer(0); FPlayer target = context.argAsFPlayer(0);
if (target == null) { if (target == null) {
return; // the above method sends a message if fails to find someone. return; // the above method sends a message if fails to find someone.
} }
if (!myFaction.isBanned(target)) { if (target.getFaction() != context.fPlayer.getFaction()) {
fme.msg(TL.COMMAND_UNBAN_NOTBANNED, target.getName()); if (target.getFaction().getAccess(context.fPlayer, PermissableAction.BAN) != Access.ALLOW) {
if (!context.fPlayer.isAdminBypassing()) {
context.fPlayer.msg(TL.COMMAND_UNBAN_TARGET_IN_OTHER_FACTION);
}
}
}
if (!context.faction.isBanned(target)) {
context.msg(TL.COMMAND_UNBAN_NOTBANNED, target.getName());
return; return;
} }
myFaction.unban(target); context.faction.unban(target);
myFaction.msg(TL.COMMAND_UNBAN_UNBANNED, fme.getName(), target.getName()); context.msg(TL.COMMAND_UNBAN_UNBANNED, context.fPlayer.getName(), target.getName());
target.msg(TL.COMMAND_UNBAN_TARGET, myFaction.getTag(target)); target.msg(TL.COMMAND_UNBAN_TARGET, context.faction.getTag(target));
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.fupgrades.FUpgradesGUI; import com.massivecraft.factions.zcore.fupgrades.FUpgradesGUI;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -11,26 +11,20 @@ public class CmdUpgrades extends FCommand {
this.aliases.add("upgrades"); this.aliases.add("upgrades");
this.aliases.add("upgrade"); this.aliases.add("upgrade");
//this.requiredArgs.add(""); this.requirements = new CommandRequirements.Builder(Permission.UPGRADES)
this.optionalArgs.put("mobs/crops/exp/power", ""); .playerOnly()
.memberOnly()
this.permission = Permission.UPGRADES.node; .build();
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fupgrades.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fupgrades.Enabled")) {
fme.sendMessage("This command is disabled!"); context.fPlayer.sendMessage("This command is disabled!");
return; return;
} }
new FUpgradesGUI().openMainMenu(fme); new FUpgradesGUI().openMainMenu(context.fPlayer);
} }
@Override @Override

View File

@ -2,9 +2,8 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board; import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; 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.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location; import org.bukkit.Location;
@ -17,57 +16,48 @@ public class CmdVault extends FCommand {
public CmdVault() { public CmdVault() {
this.aliases.add("vault"); this.aliases.add("vault");
//this.requiredArgs.add(""); this.requirements = new CommandRequirements.Builder(Permission.VAULT)
.playerOnly()
.memberOnly()
this.permission = Permission.VAULT.node; .withAction(PermissableAction.VAULT)
this.disableOnLock = false; .build();
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fvault.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fvault.Enabled")) {
fme.sendMessage("This command is disabled!"); context.fPlayer.sendMessage("This command is disabled!");
return;
}
Access access = fme.getFaction().getAccess(fme, PermissableAction.VAULT);
if (access.equals(Access.DENY)) {
fme.msg(TL.GENERIC_NOPERMISSION, "vault");
return; return;
} }
if (fme.isInVault()) { if (context.fPlayer.isInVault()) {
me.closeInventory(); context.player.closeInventory();
return; return;
} }
fme.setInVault(true);
Location vaultLocation = fme.getFaction().getVault(); context.fPlayer.setInVault(true);
Location vaultLocation = context.faction.getVault();
if (vaultLocation == null) { if (vaultLocation == null) {
fme.msg(TL.COMMAND_VAULT_INVALID); context.msg(TL.COMMAND_VAULT_INVALID);
return; return;
} }
FLocation vaultFLocation = new FLocation(vaultLocation); FLocation vaultFLocation = new FLocation(vaultLocation);
if (Board.getInstance().getFactionAt(vaultFLocation) != fme.getFaction()) { if (Board.getInstance().getFactionAt(vaultFLocation) != context.faction) {
fme.getFaction().setVault(null); context.faction.setVault(null);
fme.msg(TL.COMMAND_VAULT_INVALID); context.msg(TL.COMMAND_VAULT_INVALID);
return; return;
} }
if (vaultLocation.getBlock().getType() != Material.CHEST) { if (vaultLocation.getBlock().getType() != Material.CHEST) {
fme.getFaction().setVault(null); context.faction.setVault(null);
fme.msg(TL.COMMAND_VAULT_INVALID); context.msg(TL.COMMAND_VAULT_INVALID);
return; return;
} }
Chest chest = (Chest) vaultLocation.getBlock().getState(); Chest chest = (Chest) vaultLocation.getBlock().getState();
Inventory chestInv = chest.getBlockInventory(); Inventory chestInv = chest.getBlockInventory();
fme.msg(TL.COMMAND_VAULT_OPENING); context.msg(TL.COMMAND_VAULT_OPENING);
me.openInventory(chestInv); context.player.openInventory(chestInv);
} }
@ -76,4 +66,5 @@ public class CmdVault extends FCommand {
public TL getUsageTranslation() { public TL getUsageTranslation() {
return TL.COMMAND_VAULT_DESCRIPTION; return TL.COMMAND_VAULT_DESCRIPTION;
} }
} }

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -11,22 +11,14 @@ public class CmdVersion extends FCommand {
this.aliases.add("version"); this.aliases.add("version");
this.aliases.add("ver"); this.aliases.add("ver");
//this.requiredArgs.add(""); this.requirements = new CommandRequirements.Builder(Permission.VERSION)
//this.optionalArgs.put("", ""); .build();
this.permission = Permission.VERSION.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
msg(TL.COMMAND_VERSION_NAME); // Did this so people can differentiate between P and FactionsUUID (( Requested Feature )) context.msg(TL.COMMAND_VERSION_NAME); // Did this so people can differentiate between SavageFactions and FactionsUUID (( Requested Feature ))
msg(TL.COMMAND_VERSION_VERSION, P.p.getDescription().getFullName()); context.msg(TL.COMMAND_VERSION_VERSION, FactionsPlugin.getInstance().getDescription().getFullName());
} }
@Override @Override

View File

@ -1,40 +1,38 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
public class CmdViewChest extends FCommand { public class CmdViewChest extends FCommand {
public CmdViewChest() { public CmdViewChest() {
super();
this.aliases.add("viewchest"); this.aliases.add("viewchest");
this.aliases.add("viewpv"); this.aliases.add("viewpv");
this.requiredArgs.add("faction name"); this.requiredArgs.add("faction name");
this.requirements = new CommandRequirements.Builder(Permission.VIEWCHEST)
this.permission = Permission.VIEWCHEST.node; .playerOnly()
this.disableOnLock = false; .build();
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
if (!P.p.getConfig().getBoolean("fchest.Enabled")) { if (!FactionsPlugin.getInstance().getConfig().getBoolean("fchest.Enabled")) {
fme.msg(TL.GENERIC_DISABLED); context.msg(TL.GENERIC_DISABLED);
return; return;
} }
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); Faction myFaction = context.fPlayer.getFaction();
Faction faction = context.argAsFaction(0, context.fPlayer == null ? null : myFaction);
if (faction == null) { if (faction == null) {
return; return;
} }
me.openInventory(faction.getChestInventory()); context.player.openInventory(context.faction.getChestInventory());
} }
@Override @Override

View File

@ -0,0 +1,418 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
/*
Object that contains information about a command being executed,
args, player, faction
*/
public class CommandContext {
public CommandSender sender;
public Player player;
public FPlayer fPlayer;
public Faction faction;
public List<String> args;
public String alias;
public List<FCommand> commandChain = new ArrayList<>(); // The command chain used to execute this command
public CommandContext(CommandSender sender, List<String> args, String alias) {
this.sender = sender;
this.args = args;
this.alias = alias;
if (sender instanceof Player) {
this.player = (Player) sender;
this.fPlayer = FPlayers.getInstance().getByPlayer(player);
this.faction = fPlayer.getFaction();
}
}
// -------------------------------------------- //
// Message Sending Helpers
// -------------------------------------------- //
public void msg(String str, Object... args) {
sender.sendMessage(FactionsPlugin.getInstance().txt.parse(str, args));
}
public void msg(TL translation, Object... args) {
sender.sendMessage(FactionsPlugin.getInstance().txt.parse(translation.toString(), args));
}
public void sendMessage(String msg) {
sender.sendMessage(msg);
}
public void sendMessage(List<String> msgs) {
for (String msg : msgs) {
this.sendMessage(msg);
}
}
public void sendFancyMessage(FancyMessage message) {
message.send(sender);
}
public void sendFancyMessage(List<FancyMessage> messages) {
for (FancyMessage m : messages) {
sendFancyMessage(m);
}
}
// TODO: Clean this UP
// -------------------------------------------- //
// Argument Readers
// -------------------------------------------- //
// Is set? ======================
public boolean argIsSet(int idx) {
return args.size() >= idx + 1;
}
// STRING ======================
public String argAsString(int idx, String def) {
if (args.size() < idx + 1) {
return def;
}
return args.get(idx);
}
public String argAsString(int idx) {
return argAsString(idx, null);
}
// INT ======================
public Integer strAsInt(String str, Integer def) {
if (str == null) {
return def;
}
try {
return Integer.parseInt(str);
} catch (Exception e) {
return def;
}
}
public Integer argAsInt(int idx, Integer def) {
return strAsInt(argAsString(idx), def);
}
public Integer argAsInt(int idx) {
return argAsInt(idx, null);
}
// Double ======================
public Double strAsDouble(String str, Double def) {
if (str == null) {
return def;
}
try {
return Double.parseDouble(str);
} catch (Exception e) {
return def;
}
}
public Double argAsDouble(int idx, Double def) {
return strAsDouble(argAsString(idx), def);
}
public Double argAsDouble(int idx) {
return argAsDouble(idx, null);
}
// TODO: Go through the str conversion for the other arg-readers as well.
// Boolean ======================
public Boolean strAsBool(String str) {
str = str.toLowerCase();
return str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1");
}
public Boolean argAsBool(int idx, boolean def) {
String str = argAsString(idx);
if (str == null) {
return def;
}
return strAsBool(str);
}
public Boolean argAsBool(int idx) {
return argAsBool(idx, false);
}
// PLAYER ======================
public Player strAsPlayer(String name, Player def, boolean msg) {
Player ret = def;
if (name != null) {
Player player = Bukkit.getServer().getPlayer(name);
if (player != null) {
ret = player;
}
}
if (msg && ret == null) {
sender.sendMessage(TL.GENERIC_NOPLAYERFOUND.format(name));
}
return ret;
}
public Player argAsPlayer(int idx, Player def, boolean msg) {
return this.strAsPlayer(argAsString(idx), def, msg);
}
public Player argAsPlayer(int idx, Player def) {
return argAsPlayer(idx, def, true);
}
public Player argAsPlayer(int idx) {
return argAsPlayer(idx, null);
}
// BEST PLAYER MATCH ======================
public Player strAsBestPlayerMatch(String name, Player def, boolean msg) {
Player ret = def;
if (name != null) {
List<Player> players = Bukkit.getServer().matchPlayer(name);
if (players.size() > 0) {
ret = players.get(0);
}
}
if (msg && ret == null) {
sender.sendMessage(TL.GENERIC_NOPLAYERMATCH.format(name));
}
return ret;
}
public Player argAsBestPlayerMatch(int idx, Player def, boolean msg) {
return this.strAsBestPlayerMatch(argAsString(idx), def, msg);
}
public Player argAsBestPlayerMatch(int idx, Player def) {
return argAsBestPlayerMatch(idx, def, true);
}
public Player argAsBestPlayerMatch(int idx) {
return argAsPlayer(idx, null);
}
// -------------------------------------------- //
// Faction 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;
}
}
}
if (msg && ret == null) {
msg(TL.GENERIC_NOPLAYERFOUND, name);
}
return ret;
}
public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) {
return this.strAsFPlayer(argAsString(idx), def, msg);
}
public FPlayer argAsFPlayer(int idx, FPlayer def) {
return argAsFPlayer(idx, def, true);
}
public FPlayer argAsFPlayer(int idx) {
return 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(argAsString(idx), def, msg);
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) {
return argAsBestFPlayerMatch(idx, def, true);
}
public FPlayer argAsBestFPlayerMatch(int idx) {
return 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 (msg && ret == null) {
sender.sendMessage(TL.GENERIC_NOFACTION_FOUND.format(name));
}
return ret;
}
public Faction argAsFaction(int idx, Faction def, boolean msg) {
return this.strAsFaction(argAsString(idx), def, msg);
}
public Faction argAsFaction(int idx, Faction def) {
return argAsFaction(idx, def, true);
}
public Faction argAsFaction(int idx) {
return argAsFaction(idx, null);
}
/*
Assertions
*/
public boolean assertHasFaction() {
if (player == null) {
return true;
}
if (!fPlayer.hasFaction()) {
sendMessage("You are not member of any faction.");
return false;
}
return true;
}
public boolean assertMinRole(Role role) {
if (player == null) {
return true;
}
if (fPlayer.getRole().value < role.value) {
msg("<b>You <h>must be " + role);
return false;
}
return true;
}
/*
Common Methods
*/
public boolean canIAdministerYou(FPlayer i, FPlayer you) {
if (!i.getFaction().equals(you.getFaction())) {
i.msg(TL.COMMAND_CONTEXT_ADMINISTER_DIF_FACTION, you.describeTo(i, true));
return false;
}
if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.LEADER)) return true;
if (you.getRole().equals(Role.LEADER)) i.msg(TL.COMMAND_CONTEXT_ADMINISTER_ADMIN_REQUIRED);
else if (i.getRole().equals(Role.MODERATOR)) {
if (i == you) return true; //Moderators can control themselves
else i.msg(TL.COMMAND_CONTEXT_ADMINISTER_SAME_RANK_CONTROL);
} else i.msg(TL.COMMAND_CONTEXT_ADMINISTER_MOD_REQUIRED);
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.fPlayer == null || cost == 0.0 || fPlayer.isAdminBypassing()) {
return true;
}
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fPlayer.hasFaction()) {
return Econ.modifyMoney(faction, -cost, toDoThis, forDoingThis);
} else {
return Econ.modifyMoney(fPlayer, -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() || fPlayer == null || cost == 0.0 || fPlayer.isAdminBypassing()) {
return true;
}
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fPlayer.hasFaction()) {
return Econ.hasAtLeast(faction, cost, toDoThis);
} else {
return Econ.hasAtLeast(fPlayer, cost, toDoThis);
}
}
public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
this.doWarmUp(fPlayer, warmup, translationKey, action, runnable, delay);
}
public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay);
}
}

View File

@ -0,0 +1,155 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
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 CommandRequirements {
// Permission required to execute command
public Permission permission;
// Must be player
public boolean playerOnly;
// Must be member of faction
public boolean memberOnly;
// Must be atleast this role
public Role role;
// PermissableAction check if the player has allow for this before checking the role
public PermissableAction action;
// Commodore stuffs
public Class<? extends BrigadierProvider> brigadier;
// Edge case handling
public boolean errorOnManyArgs;
public boolean disableOnLock;
private CommandRequirements(Permission permission, boolean playerOnly, boolean memberOnly, Role role, PermissableAction action, Class<? extends BrigadierProvider> brigadier) {
this.permission = permission;
this.playerOnly = playerOnly;
this.memberOnly = memberOnly;
this.role = role;
this.action = action;
this.brigadier = brigadier;
}
public boolean computeRequirements(CommandContext context, boolean informIfNot) {
// Did not modify CommandRequirements return true
if (permission == null) {
return true;
}
if (context.player != null) {
// Is Player
if (!context.fPlayer.hasFaction() && memberOnly) {
if (informIfNot) context.msg(TL.GENERIC_MEMBERONLY);
return false;
}
if (!FactionsPlugin.getInstance().perm.has(context.sender, permission.node, informIfNot)) return false;
// Permissable Action provided compute that before role
if (action != null) {
if (context.fPlayer.getRole() == Role.LEADER) return true;
Access access = context.faction.getAccess(context.fPlayer, action);
if (access == Access.DENY) {
if (informIfNot) context.msg(TL.GENERIC_FPERM_NOPERMISSION, action.getName());
return false;
}
if (access != Access.ALLOW) {
// They have undefined assert their role
if (role != null && !context.fPlayer.getRole().isAtLeast(role)) {
// They do not fullfill the role
if (informIfNot) context.msg(TL.GENERIC_YOUMUSTBE, role.translation);
return false;
}
}
// They have been explicitly allowed
return true;
} else {
if ((role != null && !context.fPlayer.getRole().isAtLeast(role)) && informIfNot) {
context.msg(TL.GENERIC_YOUMUSTBE, role.translation);
}
return role == null || context.fPlayer.getRole().isAtLeast(role);
}
} else {
if (playerOnly) {
if (informIfNot) context.sender.sendMessage(TL.GENERIC_PLAYERONLY.toString());
return false;
}
return context.sender.hasPermission(permission.node);
}
}
public static class Builder {
private Permission permission;
private boolean playerOnly = false;
private boolean memberOnly = false;
private Role role = null;
private PermissableAction action;
private Class<? extends BrigadierProvider> brigadier;
private boolean errorOnManyArgs = true;
private boolean disableOnLock = true;
public Builder(Permission permission) {
this.permission = permission;
}
public Builder playerOnly() {
playerOnly = true;
return this;
}
public Builder memberOnly() {
playerOnly = true;
memberOnly = true;
return this;
}
public Builder withRole(Role role) {
this.role = role;
return this;
}
public Builder withAction(PermissableAction action) {
this.action = action;
return this;
}
public Builder brigadier(Class<? extends BrigadierProvider> brigadier) {
this.brigadier = brigadier;
return this;
}
public CommandRequirements build() {
CommandRequirements requirements = new CommandRequirements(permission, playerOnly, memberOnly, role, action, brigadier);
requirements.errorOnManyArgs = errorOnManyArgs;
requirements.disableOnLock = disableOnLock;
return requirements;
}
public Builder noErrorOnManyArgs() {
errorOnManyArgs = false;
return this;
}
public Builder noDisableOnLock() {
disableOnLock = false;
return this;
}
}
}

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P; import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.cmd.alts.CmdAlts; import com.massivecraft.factions.cmd.alts.CmdAlts;
import com.massivecraft.factions.cmd.check.CmdCheck; import com.massivecraft.factions.cmd.check.CmdCheck;
import com.massivecraft.factions.cmd.check.CmdWeeWoo; import com.massivecraft.factions.cmd.check.CmdWeeWoo;
@ -22,12 +22,20 @@ import com.massivecraft.factions.cmd.tnt.CmdTntFill;
import com.massivecraft.factions.missions.CmdMissions; import com.massivecraft.factions.missions.CmdMissions;
import com.massivecraft.factions.shop.CmdShop; import com.massivecraft.factions.shop.CmdShop;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import me.lucko.commodore.CommodoreProvider;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.logging.Level; import java.util.logging.Level;
public class FCmdRoot extends FCommand { public class FCmdRoot extends FCommand implements CommandExecutor {
public BrigadierManager brigadierManager;
public CmdAdmin cmdAdmin = new CmdAdmin(); public CmdAdmin cmdAdmin = new CmdAdmin();
public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim(); public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim();
@ -124,43 +132,33 @@ public class FCmdRoot extends FCommand {
public CmdTntFill cmdTntFill = new CmdTntFill(); public CmdTntFill cmdTntFill = new CmdTntFill();
public CmdChest cmdChest = new CmdChest(); public CmdChest cmdChest = new CmdChest();
public CmdSetBanner cmdSetBanner = new CmdSetBanner(); public CmdSetBanner cmdSetBanner = new CmdSetBanner();
public CmdStrike cmdStrike = new CmdStrike();
public CmdStrikeSet cmdStrikeSet = new CmdStrikeSet();
public CmdAlts cmdAlts = new CmdAlts(); public CmdAlts cmdAlts = new CmdAlts();
public CmdSpam cmdSpam = new CmdSpam();
public CmdCorner cmdCorner = new CmdCorner(); public CmdCorner cmdCorner = new CmdCorner();
public CmdInventorySee cmdInventorySee = new CmdInventorySee(); public CmdInventorySee cmdInventorySee = new CmdInventorySee();
public CmdFGlobal cmdFGlobal = new CmdFGlobal(); public CmdFGlobal cmdFGlobal = new CmdFGlobal();
public CmdViewChest cmdViewChest = new CmdViewChest(); public CmdViewChest cmdViewChest = new CmdViewChest();
public CmdPoints cmdPoints = new CmdPoints(); public CmdPoints cmdPoints = new CmdPoints();
public CmdLogout cmdLogout = new CmdLogout(); public CmdLogout cmdLogout = new CmdLogout();
public CmdNotifications cmdNotifications = new CmdNotifications();
public CmdShop cmdShop = new CmdShop(); public CmdShop cmdShop = new CmdShop();
public CmdMissions cmdMissions = new CmdMissions(); public CmdMissions cmdMissions = new CmdMissions();
public CmdStrikes cmdStrikes = new CmdStrikes();
public CmdCheck cmdCheck = new CmdCheck(); public CmdCheck cmdCheck = new CmdCheck();
public CmdWeeWoo cmdWeeWoo = new CmdWeeWoo(); public CmdWeeWoo cmdWeeWoo = new CmdWeeWoo();
public FCmdRoot() { public FCmdRoot() {
super(); super();
if (CommodoreProvider.isSupported()) brigadierManager = new BrigadierManager();
this.aliases.addAll(Conf.baseCommandAliases); this.aliases.addAll(Conf.baseCommandAliases);
this.aliases.removeAll(Collections.<String>singletonList(null)); // remove any nulls from extra commas this.aliases.removeAll(Collections.<String>singletonList(null));
this.allowNoSlashAccess = Conf.allowNoSlashCommand;
//this.requiredArgs.add("");
//this.optionalArgs.put("","")
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.disableOnLock = false;
this.setHelpShort("The faction base command"); this.setHelpShort("The faction base command");
this.helpLong.add(p.txt.parseTags("<i>This command contains all faction stuff.")); this.helpLong.add(FactionsPlugin.getInstance().txt.parseTags("<i>This command contains all faction stuff."));
//this.subCommands.add(plugin.cmdHelp); if (CommodoreProvider.isSupported()) brigadierManager = new BrigadierManager();
this.addSubCommand(this.cmdAdmin); this.addSubCommand(this.cmdAdmin);
this.addSubCommand(this.cmdAutoClaim); this.addSubCommand(this.cmdAutoClaim);
@ -175,7 +173,6 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdDeinvite); this.addSubCommand(this.cmdDeinvite);
this.addSubCommand(this.cmdDescription); this.addSubCommand(this.cmdDescription);
this.addSubCommand(this.cmdDisband); this.addSubCommand(this.cmdDisband);
this.addSubCommand(this.cmdStrike);
this.addSubCommand(this.cmdHelp); this.addSubCommand(this.cmdHelp);
this.addSubCommand(this.cmdHome); this.addSubCommand(this.cmdHome);
this.addSubCommand(this.cmdInvite); this.addSubCommand(this.cmdInvite);
@ -187,7 +184,6 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdMap); this.addSubCommand(this.cmdMap);
this.addSubCommand(this.cmdMod); this.addSubCommand(this.cmdMod);
this.addSubCommand(this.cmdMoney); this.addSubCommand(this.cmdMoney);
this.addSubCommand(this.cmdNotifications);
this.addSubCommand(this.cmdOpen); this.addSubCommand(this.cmdOpen);
this.addSubCommand(this.cmdOwner); this.addSubCommand(this.cmdOwner);
this.addSubCommand(this.cmdOwnerList); this.addSubCommand(this.cmdOwnerList);
@ -253,9 +249,8 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdTntFill); this.addSubCommand(this.cmdTntFill);
this.addSubCommand(this.cmdChest); this.addSubCommand(this.cmdChest);
this.addSubCommand(this.cmdSetBanner); this.addSubCommand(this.cmdSetBanner);
this.addSubCommand(this.cmdStrikeSet);
this.addSubCommand(this.cmdSpam);
this.addSubCommand(this.cmdCorner); this.addSubCommand(this.cmdCorner);
this.addSubCommand(this.cmdStrikes);
this.addSubCommand(this.cmdFGlobal); this.addSubCommand(this.cmdFGlobal);
this.addSubCommand(this.cmdViewChest); this.addSubCommand(this.cmdViewChest);
@ -264,61 +259,77 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdWeeWoo); this.addSubCommand(this.cmdWeeWoo);
} }
if (P.p.getConfig().getBoolean("Missions-Enabled")) { if (FactionsPlugin.getInstance().getConfig().getBoolean("Missions-Enabled")) {
this.addSubCommand(this.cmdMissions); this.addSubCommand(this.cmdMissions);
} }
if (P.p.getConfig().getBoolean("F-Shop.Enabled")) { if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) {
this.addSubCommand(this.cmdShop); 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); this.addSubCommand(this.cmdInventorySee);
} }
if (P.p.getConfig().getBoolean("f-points.Enabled")) { if (FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled")) {
this.addSubCommand(this.cmdPoints); this.addSubCommand(this.cmdPoints);
} }
if (P.p.getConfig().getBoolean("f-alts.Enabled")) { if (FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled")) {
this.addSubCommand(this.cmdAlts); this.addSubCommand(this.cmdAlts);
} }
if (P.p.getConfig().getBoolean("f-grace.Enabled")) { if (FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) {
this.addSubCommand(this.cmdGrace); this.addSubCommand(this.cmdGrace);
} }
if (Bukkit.getServer().getPluginManager().getPlugin("CoreProtect") != null) { 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); this.addSubCommand(this.cmdInspect);
} else { } 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); 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); this.addSubCommand(this.cmdFly);
} }
if (Bukkit.getServer().getPluginManager().getPlugin("FactionsTop") != null || Bukkit.getServer().getPluginManager().getPlugin("SavageFTOP") != null || Bukkit.getServer().getPluginManager().getPlugin("SaberFTOP") != null) { 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 { } 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); 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.cmdPaypalSet);
this.addSubCommand(this.cmdPaypalSee); this.addSubCommand(this.cmdPaypalSee);
} }
if (CommodoreProvider.isSupported()) brigadierManager.build();
} }
@Override @Override
public void perform() { public void perform(CommandContext context) {
this.commandChain.add(this); context.commandChain.add(this);
this.cmdHelp.execute(this.sender, this.args, this.commandChain); 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 @Override

View File

@ -1,351 +1,248 @@
package com.massivecraft.factions.cmd; 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.integration.Econ;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.MCommand;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.command.CommandSender; import com.massivecraft.factions.zcore.util.TextUtil;
import org.bukkit.entity.Player; import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.List; import java.util.*;
public abstract class FCommand extends MCommand<P> { 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; // Command Aliases
public boolean disableOnSpam; public List<String> aliases;
public FPlayer fme; // Information on the args
public Faction myFaction; public List<String> requiredArgs;
public boolean senderMustBeMember; public LinkedHashMap<String, String> optionalArgs;
public boolean senderMustBeModerator;
public boolean senderMustBeAdmin;
public boolean senderMustBeColeader;
// Requirements to execute this command
public boolean isMoneyCommand; public CommandRequirements requirements;
/*
Subcommands
*/
public List<FCommand> subCommands;
/*
Help
*/
public List<String> helpLong;
public CommandVisibility visibility;
private String helpShort;
public FCommand() { public FCommand() {
super(P.p);
// Due to safety reasons it defaults to disable on lock. requirements = new CommandRequirements.Builder(null).build();
disableOnLock = true;
disableOnSpam = false;
// The money commands must be disabled if money should not be used. this.subCommands = new ArrayList<>();
isMoneyCommand = false; this.aliases = new ArrayList<>();
senderMustBeMember = false; this.requiredArgs = new ArrayList<>();
senderMustBeModerator = false; this.optionalArgs = new LinkedHashMap<>();
senderMustBeColeader = false;
senderMustBeAdmin = false; this.helpShort = null;
this.helpLong = new ArrayList<>();
this.visibility = CommandVisibility.VISIBLE;
} }
@Override public abstract void perform(CommandContext context);
public void setCommandSender(CommandSender sender) {
super.setCommandSender(sender); public void execute(CommandContext context) {
if (sender instanceof Player) { // Is there a matching sub command?
this.fme = FPlayers.getInstance().getByPlayer((Player) sender); if (context.args.size() > 0) {
this.myFaction = this.fme.getFaction(); 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 (!validCall(context)) {
return;
}
if (!this.isEnabled(context)) {
return;
}
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("<b>Factions was locked by an admin. Please try again later.");
return false;
}
return 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 (context.args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.requirements.errorOnManyArgs) {
if (context.sender != null) {
// Get the to many string slice
List<String> 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();
}
return this.helpShort;
}
public void setHelpShort(String val) {
this.helpShort = val;
}
public abstract TL getUsageTranslation();
/*
Common Logic
*/
public List<String> getToolTips(FPlayer player) {
List<String> lines = new ArrayList<>();
for (String s : FactionsPlugin.getInstance().getConfig().getStringList("tooltips.show")) {
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFPlayerTags(s, player)));
}
return lines;
}
public List<String> getToolTips(Faction faction) {
List<String> 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<String> args = new ArrayList<>();
for (String requiredArg : this.requiredArgs) {
args.add("<" + requiredArg + ">");
}
for (Map.Entry<String, String> optionalArg : this.optionalArgs.entrySet()) {
String val = optionalArg.getValue();
if (val == null) {
val = "";
} else { } else {
this.fme = null; val = "=" + val;
this.myFaction = null;
} }
args.add("[" + optionalArg.getKey() + val + "]");
} }
@Override if (args.size() > 0) {
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) { ret.append(FactionsPlugin.getInstance().txt.parseTags(" "));
setCommandSender(sender); ret.append(TextUtil.implode(args, " "));
super.execute(sender, args, commandChain);
} }
@Override if (addShortHelp) {
public boolean isEnabled() { ret.append(FactionsPlugin.getInstance().txt.parseTags(" "));
if (p.getLocked() && this.disableOnLock) { ret.append(this.getHelpShort());
msg("<b>Factions was locked by an admin. Please try again later.");
return false;
} }
if (p.getSpam() && this.disableOnSpam) { return ret.toString();
msg("<b>Anti-Spam is currently enabled! Please try again later.");
return false;
} }
if (this.isMoneyCommand && !Conf.econEnabled) { public String getUseageTemplate(CommandContext context) {
msg("<b>Faction economy features are disabled on this server."); return getUseageTemplate(context, false);
return false;
} }
if (this.isMoneyCommand && !Conf.bankEnabled) {
msg("<b>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;
}
}
}
if (msg && ret == null) {
this.msg("<b>No player \"<plugin>%s<b>\" could be found.", name);
}
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 (msg && ret == null) {
this.msg("<b>The faction or player \"<plugin>%s<b>\" could not be found.", name);
}
return ret;
}
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 <b>is not in the same faction as you.", you.describeTo(i, true)));
return false;
}
if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.LEADER)) {
return true;
}
if (you.getRole().equals(Role.LEADER)) {
i.sendMessage(p.txt.parse(TL.ACTIONS_MUSTBE.toString().replace("{role}", "leader").replace("{action}", "do that")));
} else if ((you.getRole().equals(Role.COLEADER))) {
if (i == you) {
return true;
} else {
i.sendMessage(p.txt.parse(TL.ACTIONS_NOSAMEROLE.toString().replace("{role}", i.getRole().nicename)));
}
} 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")));
}
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 (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 (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
return Econ.hasAtLeast(myFaction, cost, toDoThis);
} else {
return Econ.hasAtLeast(fme, cost, toDoThis);
}
}
public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
this.doWarmUp(this.fme, warmup, translationKey, action, runnable, delay);
}
public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay);
}
} }

Some files were not shown because too many files have changed in this diff Show More