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>
<ul class="inheritance">
<li>com.massivecraft.factions.P</li>
<li>com.massivecraft.factions.FactionsPlugin</li>
</ul>
</li>
</ul>

27
pom.xml
View File

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

View File

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

View File

@ -5,7 +5,9 @@ import ch.njol.skript.SkriptAddon;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.cmd.CmdAutoHelp;
import com.massivecraft.factions.cmd.CommandContext;
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.WeeWooTask;
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.ShopConfig;
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.Particles.ReflectionUtils;
import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.zcore.MCommand;
import com.massivecraft.factions.zcore.MPlugin;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.fupgrades.*;
import com.massivecraft.factions.zcore.util.TextUtil;
import me.lucko.commodore.CommodoreProvider;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.*;
@ -52,11 +56,11 @@ import java.util.logging.Level;
import java.util.stream.Collectors;
public class P extends MPlugin {
public class FactionsPlugin extends MPlugin {
// Our single plugin instance.
// Single 4 life.
public static P p;
public static FactionsPlugin instance;
public static Permission perms = null;
// This plugin sets the boolean true when fully enabled.
// Plugins can check this boolean while hooking in have
@ -85,8 +89,12 @@ public class P extends MPlugin {
private Listener[] eventsListener;
public P() {
p = this;
public FactionsPlugin() {
instance = this;
}
public static FactionsPlugin getInstance() {
return instance;
}
public boolean getLocked() {
@ -139,29 +147,29 @@ public class P extends MPlugin {
// Vault dependency check.
if (getServer().getPluginManager().getPlugin("Vault") == null) {
log("Vault is not present, the plugin will not run properly.");
getServer().getPluginManager().disablePlugin(p);
getServer().getPluginManager().disablePlugin(instance);
return;
}
int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]);
switch (version) {
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;
break;
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;
break;
case 12:
mc112 = true;
break;
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;
break;
case 14:
P.p.log("Minecraft Version 1.14 found.");
FactionsPlugin.instance.log("Minecraft Version 1.14 found.");
mc114 = true;
break;
}
@ -206,7 +214,6 @@ public class P extends MPlugin {
// Add Base Commands
this.cmdBase = new FCmdRoot();
this.cmdAutoHelp = new CmdAutoHelp();
this.getBaseCommands().add(cmdBase);
Econ.setup();
setupPermissions();
@ -230,7 +237,7 @@ public class P extends MPlugin {
}
if (getServer().getPluginManager().getPlugin("Skript") != null) {
log("Skript was found! Registering P Addon...");
log("Skript was found! Registering FactionsPlugin Addon...");
skriptAddon = Skript.registerAddon(this);
try {
skriptAddon.loadClasses("com.massivecraft.factions.skript", "expressions");
@ -272,13 +279,13 @@ public class P extends MPlugin {
for (Listener eventListener : eventsListener)
getServer().getPluginManager().registerEvents(eventListener, this);
// since some other plugins execute commands directly through this command interface, provide it
getCommand(this.refCommand).setExecutor(this);
getCommand(this.refCommand).setTabCompleter(this);
this.getCommand(refCommand).setExecutor(cmdBase);
if (!CommodoreProvider.isSupported()) this.getCommand(refCommand).setTabCompleter(this);
RegisteredServiceProvider<Economy> rsp = P.this.getServer().getServicesManager().getRegistration(Economy.class);
P.econ = rsp.getProvider();
RegisteredServiceProvider<Economy> rsp = FactionsPlugin.this.getServer().getServicesManager().getRegistration(Economy.class);
FactionsPlugin.econ = rsp.getProvider();
if (getDescription().getFullName().contains("BETA")) {
divider();
@ -292,7 +299,7 @@ public class P extends MPlugin {
this.postEnable();
this.loadSuccessful = true;
// Set startup finished to true. to give plugins hooking in a greenlight
P.startupFinished = true;
FactionsPlugin.startupFinished = true;
}
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) {
ItemStack item = new ItemStack(material, amount, datavalue);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(color(P.p.getConfig().getString(name)));
meta.setLore(colorList(P.p.getConfig().getStringList(lore)));
meta.setDisplayName(color(FactionsPlugin.instance.getConfig().getString(name)));
meta.setLore(colorList(FactionsPlugin.instance.getConfig().getStringList(lore)));
item.setItemMeta(meta);
return item;
}
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();
}
@ -488,48 +495,62 @@ public class P extends MPlugin {
return handleCommand(sender, cmd + " " + TextUtil.implode(Arrays.asList(split), " "), false);
}
// This method must stay for < 1.12 versions
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer((Player) sender);
List<String> completions = new ArrayList<>();
// Must be a LinkedList to prevent UnsupportedOperationException.
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);
List<String> argsList = new ArrayList<>(Arrays.asList(args));
argsList.remove(argsList.size() - 1);
String cmdValid = (cmd + " " + TextUtil.implode(argsList, " ")).trim();
MCommand<?> commandEx = cmdBase;
List<MCommand<?>> commandsList = cmdBase.subCommands;
// String cmdValid = (cmd + " " + TextUtil.implode(context.args, " ")).trim();
List<FCommand> commandsList = cmdBase.subCommands;
FCommand commandsEx = cmdBase;
List<String> completions = new ArrayList<>();
for (; !commandsList.isEmpty() && !argsList.isEmpty(); argsList.remove(0)) {
String cmdName = argsList.get(0).toLowerCase();
MCommand<?> commandFounded = commandsList.stream()
.filter(c -> c.aliases.contains(cmdName))
.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))
// Check for "" first arg because spigot is mangled.
if (context.args.get(0).equals("")) {
for (FCommand subCommand : commandsEx.subCommands) {
if (subCommand.requirements.playerOnly && sender.hasPermission(subCommand.requirements.permission.node) && subCommand.visibility != CommandVisibility.INVISIBLE)
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();
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
completions.add(player.getName());
}
completions = completions.stream()
.filter(m -> m.toLowerCase().startsWith(lastArg))
.collect(Collectors.toList());
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) {
@ -537,11 +558,11 @@ public class P extends MPlugin {
as.setVisible(false); //Makes the ArmorStand invisible
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.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
final ArmorStand armorStand = as;
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> {
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> {
armorStand.remove();
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();
this.aliases.add("ahome");
this.requiredArgs.add("player name");
this.requiredArgs.add("player");
this.permission = Permission.AHOME.node;
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.AHOME).noDisableOnLock().build();
}
@Override
public void perform() {
FPlayer target = argAsBestFPlayerMatch(0);
public void perform(CommandContext context) {
FPlayer target = context.argAsBestFPlayerMatch(0);
if (target == null) {
msg(TL.GENERIC_NOPLAYERMATCH, argAsString(0));
context.msg(TL.GENERIC_NOPLAYERMATCH, context.argAsString(0));
return;
}
@ -36,13 +30,13 @@ public class CmdAHome extends FCommand {
Faction faction = target.getFaction();
if (faction.hasHome()) {
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);
} else {
msg(TL.COMMAND_AHOME_NOHOME, target.getName());
context.msg(TL.COMMAND_AHOME_NOHOME, target.getName());
}
} 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.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
public class CmdAdmin extends FCommand {
@ -19,52 +18,39 @@ public class CmdAdmin extends FCommand {
this.aliases.add("leader");
this.aliases.add("setleader");
this.requiredArgs.add("player name");
this.requiredArgs.add("player");
this.permission = Permission.ADMIN.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.ADMIN).build();
}
@Override
public void perform() {
FPlayer fyou = this.argAsBestFPlayerMatch(0);
if (fyou == null || fyou.getFaction().isWarZone() || fyou.getFaction().isWilderness() || fyou.getFaction().isSafeZone()) {
public void perform(CommandContext context) {
// Allows admins bypass this.
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;
}
boolean permAny = Permission.ADMIN_ANY.has(sender, false);
boolean permAny = Permission.ADMIN_ANY.has(context.sender, false);
Faction targetFaction = fyou.getFaction();
if (fyou.isAlt()) {
msg(ChatColor.RED + "You can not promote alt accounts.");
if (targetFaction != context.faction && !permAny) {
context.msg(TL.COMMAND_ADMIN_NOTMEMBER, fyou.describeTo(context.fPlayer, true));
return;
}
if (targetFaction != myFaction && !permAny) {
msg(TL.COMMAND_ADMIN_NOTMEMBER, fyou.describeTo(fme, true));
return;
}
if (fme != null && fme.getRole() != Role.LEADER && !permAny) {
msg(TL.COMMAND_ADMIN_NOTADMIN);
return;
}
if (fyou == fme && !permAny) {
msg(TL.COMMAND_ADMIN_TARGETSELF);
if (fyou == context.fPlayer && !permAny) {
context.msg(TL.COMMAND_ADMIN_TARGETSELF);
return;
}
// only perform a FPlayerJoinEvent when newLeader isn't actually in the faction
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);
if (event.isCancelled()) {
return;
@ -73,16 +59,11 @@ public class CmdAdmin extends FCommand {
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 (fyou == admin) {
targetFaction.promoteNewLeader();
msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(fme, true));
fyou.msg(TL.COMMAND_ADMIN_DEMOTED, senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fyou, true));
context.msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(context.fPlayer, true));
fyou.msg(TL.COMMAND_ADMIN_DEMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fyou, true));
return;
}
@ -91,11 +72,11 @@ public class CmdAdmin extends FCommand {
admin.setRole(Role.COLEADER);
}
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
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.struct.Permission;
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.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -15,30 +18,27 @@ public class CmdAnnounce extends FCommand {
this.aliases.add("announce");
this.requiredArgs.add("message");
this.errorOnToManyArgs = false;
this.permission = Permission.ANNOUNCE.node;
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
this.requirements = new CommandRequirements.Builder(Permission.ANNOUNCE)
.playerOnly()
.memberOnly()
.brigadier(AnnounceBrigadier.class)
.noErrorOnManyArgs()
.build();
}
@Override
public void perform() {
String prefix = ChatColor.GREEN + myFaction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + me.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET;
String message = StringUtils.join(args, " ");
public void perform(CommandContext context) {
String prefix = ChatColor.GREEN + context.faction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + context.player.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET;
String message = StringUtils.join(context.args, " ");
for (Player player : myFaction.getOnlinePlayers()) {
for (Player player : context.faction.getOnlinePlayers()) {
player.sendMessage(prefix + message);
}
// Add for offline players.
for (FPlayer fp : myFaction.getFPlayersWhereOnline(false)) {
myFaction.addAnnouncement(fp, prefix + message);
for (FPlayer fp : context.faction.getFPlayersWhereOnline(false)) {
context.faction.addAnnouncement(fp, prefix + message);
}
}
@ -47,4 +47,11 @@ public class CmdAnnounce extends FCommand {
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;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.zcore.MCommand;
import com.massivecraft.factions.zcore.util.TL;
import java.util.ArrayList;
public class CmdAutoHelp extends MCommand<P> {
public class CmdAutoHelp extends FCommand {
public CmdAutoHelp() {
super(P.p);
this.aliases.add("?");
this.aliases.add("h");
this.aliases.add("help");
@ -21,22 +19,22 @@ public class CmdAutoHelp extends MCommand<P> {
}
@Override
public void perform() {
if (this.commandChain.size() == 0) {
public void perform(CommandContext context) {
if (context.commandChain.size() == 0) {
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);
for (MCommand<?> scmd : pcmd.subCommands) {
if (scmd.visibility == CommandVisibility.VISIBLE || (scmd.visibility == CommandVisibility.SECRET && scmd.validSenderPermissions(sender, false))) {
lines.add(scmd.getUseageTemplate(this.commandChain, true));
for (FCommand scmd : pcmd.subCommands) {
if (scmd.visibility == CommandVisibility.VISIBLE) {
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

View File

@ -1,12 +1,10 @@
package com.massivecraft.factions.cmd;
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.struct.BanInfo;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
@ -21,78 +19,63 @@ public class CmdBan extends FCommand {
this.requiredArgs.add("target");
this.permission = Permission.BAN.node;
this.disableOnLock = true;
this.disableOnSpam = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.BAN)
.playerOnly()
.withAction(PermissableAction.BAN)
.build();
}
@Override
public void perform() {
// 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;
}
}
public void perform(CommandContext context) {
// Good on permission checks. Now lets just ban the player.
FPlayer target = argAsFPlayer(0);
FPlayer target = context.argAsFPlayer(0);
if (target == null) {
return; // the above method sends a message if fails to find someone.
}
if (fme == target) {
if (context.fPlayer == target) {
// You may not ban yourself
fme.msg(TL.COMMAND_BAN_SELF);
context.msg(TL.COMMAND_BAN_SELF);
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
fme.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName());
context.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName());
return;
}
for (BanInfo banInfo : myFaction.getBannedPlayers()) {
for (BanInfo banInfo : context.faction.getBannedPlayers()) {
if (banInfo.getBanned().equals(target.getId())) {
msg(TL.COMMAND_BAN_ALREADYBANNED);
context.msg(TL.COMMAND_BAN_ALREADYBANNED);
return;
}
}
// Ban the user.
myFaction.ban(target, fme);
myFaction.deinvite(target); // can't hurt
context.faction.ban(target, context.fPlayer);
context.faction.deinvite(target); // can't hurt
// 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);
if (event.isCancelled()) {
// 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;
}
// Didn't get cancelled so remove them and reset their invite.
myFaction.removeFPlayer(target);
context.faction.removeFPlayer(target);
target.resetFactionData();
}
// Lets inform the people!
target.msg(TL.COMMAND_BAN_TARGET, myFaction.getTag(target.getFaction()));
myFaction.msg(TL.COMMAND_BAN_BANNED, fme.getName(), target.getName());
target.msg(TL.COMMAND_BAN_TARGET, context.faction.getTag(target.getFaction()));
context.faction.msg(TL.COMMAND_BAN_BANNED, context.fPlayer.getName(), target.getName());
}
@Override

View File

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

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd;
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.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
@ -20,50 +20,45 @@ public class CmdBanner extends FCommand {
this.aliases.add("banner");
this.aliases.add("warbanner");
this.permission = Permission.BANNER.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.BANNER)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("fbanners.Enabled")) {
msg(TL.COMMAND_BANNER_DISABLED);
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Enabled")) {
context.msg(TL.COMMAND_BANNER_DISABLED);
return;
}
if (!fme.hasMoney(P.p.getConfig().getInt("fbanners.Banner-Cost", 5000))) {
msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
if (!context.fPlayer.hasMoney(FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000))) {
context.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
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();
ItemStack warBanner = fme.getFaction().getBanner();
ItemStack warBanner = context.fPlayer.getFaction().getBanner();
if (warBanner != null) {
ItemMeta warmeta = warBanner.getItemMeta();
warmeta.setDisplayName(P.p.color(P.p.getConfig().getString("fbanners.Item.Name")));
warmeta.setLore(P.p.colorList(P.p.getConfig().getStringList("fbanners.Item.Lore")));
warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name")));
warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")));
warBanner.setItemMeta(warmeta);
} 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);
me.getInventory().addItem(warBanner);
context.player.getInventory().addItem(warBanner);
}
public boolean hasMoney(FPlayer fme, int amt) {
Economy econ = P.p.getEcon();
Economy econ = FactionsPlugin.getInstance().getEcon();
if (econ.getBalance(fme.getPlayer()) >= amt) {
return true;
} else {
@ -74,7 +69,7 @@ public class CmdBanner extends FCommand {
public void takeMoney(FPlayer fme, int amt) {
if (hasMoney(fme, amt)) {
Economy econ = P.p.getEcon();
Economy econ = FactionsPlugin.getInstance().getEcon();
econ.withdrawPlayer(fme.getPlayer(), 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.optionalArgs.put("on/off", "flip");
this.permission = Permission.NO_BOOM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.NO_BOOM)
.playerOnly()
.build();
}
@Override
public void perform() {
if (!myFaction.isPeaceful()) {
fme.msg(TL.COMMAND_BOOM_PEACEFULONLY);
public void perform(CommandContext context) {
if (!context.faction.isPeaceful()) {
context.msg(TL.COMMAND_BOOM_PEACEFULONLY);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostNoBoom, TL.COMMAND_BOOM_TOTOGGLE, TL.COMMAND_BOOM_FORTOGGLE)) {
if (!context.payForCommand(Conf.econCostNoBoom, TL.COMMAND_BOOM_TOTOGGLE, TL.COMMAND_BOOM_FORTOGGLE)) {
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
myFaction.msg(TL.COMMAND_BOOM_ENABLED, fme.describeTo(myFaction), enabled);
context.faction.msg(TL.COMMAND_BOOM_ENABLED, context.fPlayer.describeTo(context.faction), enabled);
}
@Override

View File

@ -1,6 +1,6 @@
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.zcore.util.TL;
@ -13,27 +13,22 @@ public class CmdBypass extends FCommand {
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.BYPASS.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.BYPASS)
.playerOnly()
.build();
}
@Override
public void perform() {
fme.setIsAdminBypassing(this.argAsBool(0, !fme.isAdminBypassing()));
public void perform(CommandContext context) {
context.fPlayer.setIsAdminBypassing(context.argAsBool(0, !context.fPlayer.isAdminBypassing()));
// TODO: Move this to a transient field in the model??
if (fme.isAdminBypassing()) {
fme.msg(TL.COMMAND_BYPASS_ENABLE.toString());
P.p.log(fme.getName() + TL.COMMAND_BYPASS_ENABLELOG.toString());
if (context.fPlayer.isAdminBypassing()) {
context.fPlayer.msg(TL.COMMAND_BYPASS_ENABLE.toString());
FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_BYPASS_ENABLELOG.toString());
} else {
fme.msg(TL.COMMAND_BYPASS_DISABLE.toString());
P.p.log(fme.getName() + TL.COMMAND_BYPASS_DISABLELOG.toString());
context.fPlayer.msg(TL.COMMAND_BYPASS_DISABLE.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.Role;
import com.massivecraft.factions.zcore.util.TL;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
public class CmdChat extends FCommand {
@ -16,33 +18,29 @@ public class CmdChat extends FCommand {
//this.requiredArgs.add("");
this.optionalArgs.put("mode", "next");
this.permission = Permission.CHAT.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.CHAT)
.playerOnly()
.memberOnly()
.brigadier(ChatBrigadier.class)
.build();
}
@Override
public void perform() {
public void perform(CommandContext context) {
if (!Conf.factionOnlyChat) {
msg(TL.COMMAND_CHAT_DISABLED.toString());
context.msg(TL.COMMAND_CHAT_DISABLED.toString());
return;
}
String modeString = this.argAsString(0);
ChatMode modeTarget = fme.getChatMode().getNext();
String modeString = context.argAsString(0);
ChatMode modeTarget = context.fPlayer.getChatMode().getNext();
if (modeString != null) {
modeString = modeString.toLowerCase();
// Only allow Mods and higher rank to switch to this channel.
if (modeString.startsWith("m")) {
if (!fme.getRole().isAtLeast(Role.MODERATOR)) {
msg(TL.COMMAND_CHAT_MOD_ONLY);
if (!context.fPlayer.getRole().isAtLeast(Role.MODERATOR)) {
context.msg(TL.COMMAND_CHAT_MOD_ONLY);
return;
} else modeTarget = ChatMode.MOD;
} else if (modeString.startsWith("p")) {
@ -54,28 +52,28 @@ public class CmdChat extends FCommand {
} else if (modeString.startsWith("t")) {
modeTarget = ChatMode.TRUCE;
} else {
msg(TL.COMMAND_CHAT_INVALIDMODE);
context.msg(TL.COMMAND_CHAT_INVALIDMODE);
return;
}
}
fme.setChatMode(modeTarget);
context.fPlayer.setChatMode(modeTarget);
switch (fme.getChatMode()) {
switch (context.fPlayer.getChatMode()) {
case MOD:
msg(TL.COMMAND_CHAT_MODE_MOD);
context.msg(TL.COMMAND_CHAT_MODE_MOD);
break;
case PUBLIC:
msg(TL.COMMAND_CHAT_MODE_PUBLIC);
context.msg(TL.COMMAND_CHAT_MODE_PUBLIC);
break;
case ALLIANCE:
msg(TL.COMMAND_CHAT_MODE_ALLIANCE);
context.msg(TL.COMMAND_CHAT_MODE_ALLIANCE);
break;
case TRUCE:
msg(TL.COMMAND_CHAT_MODE_TRUCE);
context.msg(TL.COMMAND_CHAT_MODE_TRUCE);
break;
default:
msg(TL.COMMAND_CHAT_MODE_FACTION);
context.msg(TL.COMMAND_CHAT_MODE_FACTION);
break;
}
}
@ -84,4 +82,16 @@ public class CmdChat extends FCommand {
public TL getUsageTranslation() {
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;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@ -12,26 +12,21 @@ public class CmdChatSpy extends FCommand {
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.CHATSPY.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.CHATSPY)
.playerOnly()
.build();
}
@Override
public void perform() {
fme.setSpyingChat(this.argAsBool(0, !fme.isSpyingChat()));
public void perform(CommandContext context) {
context.fPlayer.setSpyingChat(context.argAsBool(0, !context.fPlayer.isSpyingChat()));
if (fme.isSpyingChat()) {
fme.msg(TL.COMMAND_CHATSPY_ENABLE);
P.p.log(fme.getName() + TL.COMMAND_CHATSPY_ENABLELOG.toString());
if (context.fPlayer.isSpyingChat()) {
context.msg(TL.COMMAND_CHATSPY_ENABLE);
FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CHATSPY_ENABLELOG.toString());
} else {
fme.msg(TL.COMMAND_CHATSPY_DISABLE);
P.p.log(fme.getName() + TL.COMMAND_CHATSPY_DISABLELOG.toString());
context.msg(TL.COMMAND_CHATSPY_DISABLE);
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.permission = Permission.CHECKPOINT.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.CHECKPOINT)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("checkpoints.Enabled")) {
fme.msg(TL.COMMAND_CHECKPOINT_DISABLED);
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("checkpoints.Enabled")) {
context.msg(TL.COMMAND_CHECKPOINT_DISABLED);
return;
}
if (args.size() == 1) {
FLocation myLocation = new FLocation(fme.getPlayer().getLocation());
if (context.args.size() == 1) {
FLocation myLocation = new FLocation(context.player.getLocation());
Faction myLocFaction = Board.getInstance().getFactionAt(myLocation);
if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == fme.getFaction()) {
fme.getFaction().setCheckpoint(fme.getPlayer().getLocation());
fme.msg(TL.COMMAND_CHECKPOINT_SET);
if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == context.faction) {
context.faction.setCheckpoint(context.player.getLocation());
context.msg(TL.COMMAND_CHECKPOINT_SET);
return;
} else {
fme.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION);
context.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION);
return;
}
}
if (fme.getFaction().getCheckpoint() == null) {
fme.msg(TL.COMMAND_CHECKPOINT_NOT_SET);
if (context.faction.getCheckpoint() == null) {
context.msg(TL.COMMAND_CHECKPOINT_NOT_SET);
return;
}
FLocation checkLocation = new FLocation(fme.getFaction().getCheckpoint());
FLocation checkLocation = new FLocation(context.faction.getCheckpoint());
Faction checkfaction = Board.getInstance().getFactionAt(checkLocation);
if (checkfaction.getId().equals(Factions.getInstance().getWilderness().getId()) || checkfaction.getId().equals(fme.getFaction().getId())) {
fme.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));
if (checkfaction.getId().equals(Factions.getInstance().getWilderness().getId()) || checkfaction.getId().equals(context.faction.getId())) {
context.msg(TL.COMMAND_CHECKPOINT_GO);
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 {
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.optionalArgs.put("player name", "name");
//this.optionalArgs.put("", "");
this.permission = Permission.COLEADER.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = true;
this.requirements = new CommandRequirements.Builder(Permission.COLEADER)
.memberOnly()
.withRole(Role.LEADER)
.build();
}
@Override
public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0);
public void perform(CommandContext context) {
FPlayer you = context.argAsBestFPlayerMatch(0);
if (you == null) {
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();
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();
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;
}
boolean permAny = Permission.COLEADER_ANY.has(sender, false);
boolean permAny = Permission.COLEADER_ANY.has(context.sender, false);
Faction targetFaction = you.getFaction();
if (you.isAlt()) {
msg(ChatColor.RED + "You can not promote alt accounts.");
if (targetFaction != context.faction && !permAny) {
context.msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(context.fPlayer, true));
return;
}
if (targetFaction != myFaction && !permAny) {
msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(fme, true));
if (context.fPlayer != null && context.fPlayer.getRole() != Role.LEADER && !permAny) {
context.msg(TL.COMMAND_COLEADER_NOTADMIN);
return;
}
if (fme != null && fme.getRole() != Role.LEADER && !permAny) {
msg(TL.COMMAND_COLEADER_NOTADMIN);
return;
}
if (you == fme && !permAny) {
msg(TL.COMMAND_COLEADER_SELF);
if (you == context.fPlayer && !permAny) {
context.msg(TL.COMMAND_COLEADER_SELF);
return;
}
if (you.getRole() == Role.LEADER) {
msg(TL.COMMAND_COLEADER_TARGETISADMIN);
context.msg(TL.COMMAND_COLEADER_TARGETISADMIN);
return;
}
@ -80,12 +70,12 @@ public class CmdColeader extends FCommand {
// Revoke
you.setRole(Role.MODERATOR);
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 {
// Give
you.setRole(Role.COLEADER);
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;
}
}

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd;
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.zcore.util.TL;
import org.bukkit.ChatColor;
@ -24,20 +24,14 @@ public class CmdConfig extends FCommand {
this.requiredArgs.add("setting");
this.requiredArgs.add("value");
this.errorOnToManyArgs = false;
this.permission = Permission.CONFIG.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.CONFIG)
.noErrorOnManyArgs()
.build();
}
@Override
public void perform() {
public void perform(CommandContext context) {
// 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
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("\"")) {
field = field.substring(1, field.length() - 1);
}
String fieldName = properFieldNames.get(field);
if (fieldName == null || fieldName.isEmpty()) {
msg(TL.COMMAND_CONFIG_NOEXIST, field);
context.msg(TL.COMMAND_CONFIG_NOEXIST, field);
return;
}
String success;
StringBuilder value = new StringBuilder(args.get(1));
for (int i = 2; i < args.size(); i++) {
value.append(' ').append(args.get(i));
StringBuilder value = new StringBuilder(context.args.get(1));
for (int i = 2; i < context.args.size(); i++) {
value.append(' ').append(context.args.get(i));
}
try {
@ -70,7 +64,7 @@ public class CmdConfig extends FCommand {
// boolean
if (target.getType() == boolean.class) {
boolean targetValue = this.strAsBool(value.toString());
boolean targetValue = context.strAsBool(value.toString());
target.setBoolean(null, targetValue);
if (targetValue) {
@ -87,7 +81,7 @@ public class CmdConfig extends FCommand {
target.setInt(null, intVal);
success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + intVal + ".";
} catch (NumberFormatException ex) {
sendMessage(TL.COMMAND_CONFIG_INTREQUIRED.format(fieldName));
context.sendMessage(TL.COMMAND_CONFIG_INTREQUIRED.format(fieldName));
return;
}
}
@ -99,7 +93,7 @@ public class CmdConfig extends FCommand {
target.setLong(null, longVal);
success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + longVal + ".";
} catch (NumberFormatException ex) {
sendMessage(TL.COMMAND_CONFIG_LONGREQUIRED.format(fieldName));
context.sendMessage(TL.COMMAND_CONFIG_LONGREQUIRED.format(fieldName));
return;
}
}
@ -111,7 +105,7 @@ public class CmdConfig extends FCommand {
target.setDouble(null, doubleVal);
success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + doubleVal + ".";
} catch (NumberFormatException ex) {
sendMessage(TL.COMMAND_CONFIG_DOUBLEREQUIRED.format(fieldName));
context.sendMessage(TL.COMMAND_CONFIG_DOUBLEREQUIRED.format(fieldName));
return;
}
}
@ -123,7 +117,7 @@ public class CmdConfig extends FCommand {
target.setFloat(null, floatVal);
success = "\"" + fieldName + TL.COMMAND_CONFIG_OPTIONSET.toString() + floatVal + ".";
} catch (NumberFormatException ex) {
sendMessage(TL.COMMAND_CONFIG_FLOATREQUIRED.format(fieldName));
context.sendMessage(TL.COMMAND_CONFIG_FLOATREQUIRED.format(fieldName));
return;
}
}
@ -143,7 +137,7 @@ public class CmdConfig extends FCommand {
}
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;
}
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
if (targSet.getRawType() != Set.class) {
sendMessage(TL.COMMAND_CONFIG_INVALID_COLLECTION.format(fieldName));
context.sendMessage(TL.COMMAND_CONFIG_INVALID_COLLECTION.format(fieldName));
return;
}
@ -170,7 +164,7 @@ public class CmdConfig extends FCommand {
}
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;
}
@ -210,31 +204,31 @@ public class CmdConfig extends FCommand {
// Set of unknown type
else {
sendMessage(TL.COMMAND_CONFIG_INVALID_TYPESET.format(fieldName));
context.sendMessage(TL.COMMAND_CONFIG_INVALID_TYPESET.format(fieldName));
return;
}
}
// unknown type
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;
}
} catch (NoSuchFieldException ex) {
sendMessage(TL.COMMAND_CONFIG_ERROR_MATCHING.format(fieldName));
context.sendMessage(TL.COMMAND_CONFIG_ERROR_MATCHING.format(fieldName));
return;
} 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;
}
if (!success.isEmpty()) {
if (sender instanceof Player) {
sendMessage(success);
P.p.log(success + TL.COMMAND_CONFIG_LOG.format((Player) sender));
} else // using P.p.log() instead of sendMessage if run from server console so that "[Factions v#.#.#]" is prepended in server log
if (context.sender instanceof Player) {
context.sendMessage(success);
FactionsPlugin.getInstance().log(success + TL.COMMAND_CONFIG_LOG.format((Player) context.sender));
} 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

View File

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

View File

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

View File

@ -20,58 +20,46 @@ public class CmdCreate extends FCommand {
this.aliases.add("create");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.CREATE.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.CREATE)
.playerOnly()
.build();
}
@Override
public void perform() {
String tag = this.argAsString(0);
public void perform(CommandContext context) {
String tag = context.argAsString(0);
if (fme.hasFaction()) {
msg(TL.COMMAND_CREATE_MUSTLEAVE);
return;
}
if (!fme.isCooldownEnded("create")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("create"));
if (context.fPlayer.hasFaction()) {
context.msg(TL.COMMAND_CREATE_MUSTLEAVE);
return;
}
if (Factions.getInstance().isTagTaken(tag)) {
msg(TL.COMMAND_CREATE_INUSE);
context.msg(TL.COMMAND_CREATE_INUSE);
return;
}
ArrayList<String> tagValidationErrors = MiscUtil.validateTag(tag);
if (tagValidationErrors.size() > 0) {
sendMessage(tagValidationErrors);
context.sendMessage(tagValidationErrors);
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 (!canAffordCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE.toString())) {
if (!context.canAffordCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE.toString())) {
return;
}
// trigger the faction creation event (cancellable)
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
FactionCreateEvent createEvent = new FactionCreateEvent(context.player, tag);
Bukkit.getServer().getPluginManager().callEvent(createEvent);
if (createEvent.isCancelled()) {
return;
}
// 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;
}
@ -79,7 +67,7 @@ public class CmdCreate extends FCommand {
// TODO: Why would this even happen??? Auto increment clash??
if (faction == null) {
msg(TL.COMMAND_CREATE_ERROR);
context.msg(TL.COMMAND_CREATE_ERROR);
return;
}
@ -87,39 +75,29 @@ public class CmdCreate extends FCommand {
faction.setTag(tag);
// 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);
// join event cannot be cancelled or you'll have an empty faction
// 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.
// 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.
fme.setRole(Role.LEADER);
if (P.p.getConfig().getBoolean("faction-creation-broadcast", true)) {
context.fPlayer.setRole(Role.LEADER);
if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-creation-broadcast", true)) {
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());
if (Conf.econEnabled)
Econ.setBalance(faction.getAccountId(), Conf.econFactionStartingBalance);
context.msg(TL.COMMAND_CREATE_YOUSHOULD, FactionsPlugin.getInstance().cmdBase.cmdDescription.getUseageTemplate(context));
if (Conf.econEnabled) Econ.setBalance(faction.getAccountId(), Conf.econFactionStartingBalance);
if (Conf.logFactionCreate)
P.p.log(fme.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag);
if (P.p.getConfig().getBoolean("fpaypal.Enabled"))
this.fme.msg(TL.COMMAND_PAYPALSET_CREATED);
FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag);
if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled"))
context.msg(TL.COMMAND_PAYPALSET_CREATED);
if (Conf.useCustomDefaultPermissions) faction.setDefaultPerms();
if (Conf.usePermissionHints) fme.msg(TL.COMMAND_HINT_PERMISSION);
fme.setCooldown("create", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-create") * 1000));
if (Conf.usePermissionHints) context.msg(TL.COMMAND_HINT_PERMISSION);
}
@Override

View File

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

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd;
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.zcore.util.TL;
@ -13,29 +13,29 @@ public class CmdDelFWarp extends FCommand {
this.aliases.add("dw");
this.aliases.add("deletewarp");
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
public void perform() {
String warp = argAsString(0);
if (myFaction.isWarp(warp)) {
if (!transact(fme)) {
public void perform(CommandContext context) {
String warp = context.argAsString(0);
if (context.faction.isWarp(warp)) {
if (!transact(context.fPlayer, context)) {
return;
}
myFaction.removeWarp(warp);
fme.msg(TL.COMMAND_DELFWARP_DELETED, warp);
context.faction.removeWarp(warp);
context.msg(TL.COMMAND_DELFWARP_DELETED, warp);
} else {
fme.msg(TL.COMMAND_DELFWARP_INVALID, warp);
context.msg(TL.COMMAND_DELFWARP_INVALID, warp);
}
}
private boolean transact(FPlayer player) {
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());
private boolean transact(FPlayer player, CommandContext context) {
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
@ -43,3 +43,4 @@ public class CmdDelFWarp extends FCommand {
return TL.COMMAND_DELFWARP_DESCRIPTION;
}
}

View File

@ -15,41 +15,35 @@ public class CmdDescription extends FCommand {
this.aliases.add("description");
this.requiredArgs.add("desc");
this.errorOnToManyArgs = false;
//this.optionalArgs
this.permission = Permission.DESCRIPTION.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.DESCRIPTION)
.playerOnly()
.memberOnly()
.noErrorOnManyArgs()
.build();
}
@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 (!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;
}
// 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.
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) {
fme.msg(TL.COMMAND_DESCRIPTION_CHANGED, myFaction.describeTo(fme));
fme.sendMessage(myFaction.getDescription());
context.msg(TL.COMMAND_DESCRIPTION_CHANGED, context.faction.describeTo(context.fPlayer));
context.sendMessage(context.faction.getDescription());
return;
}
// Broadcast the description to everyone
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
fplayer.msg(TL.COMMAND_DESCRIPTION_CHANGES, myFaction.describeTo(fplayer));
fplayer.sendMessage(myFaction.getDescription()); // players can inject "&" or "`" or "<i>" or whatever in their description; &k is particularly interesting looking
fplayer.msg(TL.COMMAND_DESCRIPTION_CHANGES, context.faction.describeTo(fplayer));
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.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import java.util.HashMap;
@ -23,87 +24,71 @@ public class CmdDisband extends FCommand {
super();
this.aliases.add("disband");
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.DISBAND.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.DISBAND)
.build();
}
@Override
public void perform() {
public void perform(CommandContext context) {
// The faction, default to your own.. but null if console sender.
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
if (faction == null) {
return;
}
Faction faction = context.argAsFaction(0, context.fPlayer == null ? null : context.faction);
if (faction == null) return;
boolean isMyFaction = context.fPlayer != null && faction == context.faction;
if (!fme.isCooldownEnded("disband")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("disband"));
return;
}
boolean isMyFaction = fme != null && faction == myFaction;
if (isMyFaction) {
if (!assertMinRole(Role.LEADER)) {
return;
}
} else {
if (!Permission.DISBAND_ANY.has(sender, true)) {
if (!isMyFaction) {
if (!Permission.DISBAND_ANY.has(context.sender, true)) {
return;
}
}
if (fme != null && !fme.isAdminBypassing()) {
Access access = faction.getAccess(fme, PermissableAction.DISBAND);
if (fme.getRole() != Role.LEADER && faction.getFPlayerLeader() != fme && access != Access.ALLOW) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag());
if (context.fPlayer != null && !context.fPlayer.isAdminBypassing()) {
Access access = faction.getAccess(context.fPlayer, PermissableAction.DISBAND);
if (context.fPlayer.getRole() != Role.LEADER && faction.getFPlayerLeader() != context.fPlayer && access != Access.ALLOW) {
context.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag());
return;
}
}
if (!faction.isNormal()) {
msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
context.msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
return;
}
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;
}
// check for tnt before disbanding.
if ((fme != null && !disbandMap.containsKey(me.getUniqueId().toString())) && faction.getTnt() > 0) {
msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));
disbandMap.put(me.getUniqueId().toString(), faction.getId());
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, () -> disbandMap.remove(me.getUniqueId().toString()), 200L);
} else if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) {
if (P.p.getConfig().getBoolean("faction-disband-broadcast", true)) {
if (!disbandMap.containsKey(context.player.getUniqueId().toString()) && faction.getTnt() > 0) {
context.msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));
disbandMap.put(context.player.getUniqueId().toString(), faction.getId());
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> disbandMap.remove(context.player.getUniqueId().toString()), 200L);
} else if (faction.getId().equals(disbandMap.get(context.player.getUniqueId().toString())) || faction.getTnt() == 0) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast", true)) {
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
String amountString = senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(follower);
UtilFly.checkFly(this.fme, Board.getInstance().getFactionAt(new FLocation(follower)));
String amountString = context.sender instanceof ConsoleCommandSender ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(follower);
UtilFly.checkFly(context.fPlayer, Board.getInstance().getFactionAt(new FLocation(follower)));
if (follower.getFaction() == faction) {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString);
fme.setCooldown("disband", System.currentTimeMillis() + (P.p.getConfig().getInt("fcooldowns.f-disband") * 1000));
} else {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower));
}
}
faction.disband(me, PlayerDisbandReason.COMMAND);
faction.disband(context.player, PlayerDisbandReason.COMMAND);
} else {
faction.disband(me, PlayerDisbandReason.COMMAND);
me.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER));
faction.disband(context.player, PlayerDisbandReason.COMMAND);
context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER));
}
}
}

View File

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

View File

@ -1,12 +1,10 @@
package com.massivecraft.factions.cmd;
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.Role;
import com.massivecraft.factions.util.FactionWarpsFrame;
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.util.TL;
import org.bukkit.Bukkit;
@ -23,59 +21,52 @@ public class CmdFWarp extends FCommand {
this.optionalArgs.put("warpname", "warpname");
this.optionalArgs.put("password", "password");
this.permission = Permission.WARP.node;
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
this.requirements = new CommandRequirements.Builder(Permission.WARP)
.playerOnly()
.memberOnly()
.withAction(PermissableAction.WARP)
.build();
}
@Override
public void perform() {
//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;
}
}
public void perform(CommandContext context) {
if (args.size() == 0) {
new FactionWarpsFrame(fme.getFaction()).buildGUI(fme);
} else if (args.size() > 2) {
fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
if (context.args.size() == 0) {
new FactionWarpsFrame(context.faction).buildGUI(context.fPlayer);
} else if (context.args.size() > 2) {
context.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
} else {
final String warpName = argAsString(0);
final String passwordAttempt = argAsString(1);
final String warpName = context.argAsString(0);
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
if (myFaction.hasWarpPassword(warpName) && !myFaction.isWarpPassword(warpName, passwordAttempt)) {
fme.msg(TL.COMMAND_FWARP_INVALID_PASSWORD);
if (context.faction.hasWarpPassword(warpName) && !context.faction.isWarpPassword(warpName, passwordAttempt)) {
context.faction.msg(TL.COMMAND_FWARP_INVALID_PASSWORD);
return;
}
// Check transaction AFTER password check.
if (!transact(fme)) return;
final FPlayer fPlayer = fme;
final UUID uuid = fme.getPlayer().getUniqueId();
this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
if (!transact(context.fPlayer, context)) return;
final FPlayer fPlayer = context.fPlayer;
final UUID uuid = context.player.getUniqueId();
context.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation());
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
}
}, this.p.getConfig().getLong("warmups.f-warp", 0));
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-warp", 0));
} else {
fme.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName);
context.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName);
}
}
}
private boolean transact(FPlayer player) {
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());
private boolean transact(FPlayer player, CommandContext context) {
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

View File

@ -4,14 +4,12 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.Particles.ParticleEffect;
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.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Particle;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -28,52 +26,27 @@ public class CmdFly extends FCommand {
public CmdFly() {
super();
this.aliases.add("fly");
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.FLY.node;
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
this.requirements = new CommandRequirements.Builder(Permission.FLY)
.playerOnly()
.memberOnly()
.build();
}
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()) {
Player player = Bukkit.getPlayer(name);
if (player == null) {
continue;
}
if (!player.isFlying()) {
continue;
}
if (!P.p.mc17) {
if (player.getGameMode() == GameMode.SPECTATOR) {
continue;
}
if (player == null) continue;
if (!player.isFlying()) continue;
if (!FactionsPlugin.getInstance().mc17) {
if (player.getGameMode() == GameMode.SPECTATOR) continue;
}
if (FPlayers.getInstance().getByPlayer(player).isVanished()) {
// Actually, vanished players (such as admins) should not display particles to prevent others from knowing their vanished assistance for moderation.
// 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);
}
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
fplayer.isVanished();
}
if (flyMap.keySet().size() == 0) {
@ -84,7 +57,7 @@ public class CmdFly extends FCommand {
}
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();
if (flyMap.keySet().size() != 0) {
for (String name : flyMap.keySet()) {
@ -95,7 +68,7 @@ public class CmdFly extends FCommand {
if (player == null
|| !player.isFlying()
|| player.getGameMode() == GameMode.CREATIVE
|| !P.p.mc17 && player.getGameMode() == GameMode.SPECTATOR) {
|| !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) {
continue;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
@ -105,7 +78,7 @@ public class CmdFly extends FCommand {
flyMap.remove(name);
continue;
}
if (fPlayer.checkIfNearbyEnemies()) {
if (player.hasPermission("factions.fly.bypassnearbyenemycheck") || fPlayer.checkIfNearbyEnemies()) {
continue;
}
FLocation myFloc = new FLocation(player.getLocation());
@ -174,57 +147,53 @@ public class CmdFly extends FCommand {
}
@Override
public void perform() {
public void perform(CommandContext context) {
// Disabled by default.
if (!P.p.getConfig().getBoolean("enable-faction-flight", false)) {
fme.msg(TL.COMMAND_FLY_DISABLED);
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) {
context.fPlayer.msg(TL.COMMAND_FLY_DISABLED);
return;
}
FLocation myfloc = new FLocation(me.getLocation());
FLocation myfloc = new FLocation(context.player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkBypassPerms(fme, me, toFac)) return;
List<Entity> entities = this.me.getNearbyEntities(16.0D, 256.0D, 16.0D);
if (!checkBypassPerms(context.fPlayer, context.player, toFac)) return;
List<Entity> entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D);
for (int i = 0; i <= entities.size() - 1; ++i) {
if (entities.get(i) instanceof Player) {
Player eplayer = (Player) entities.get(i);
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
if (efplayer.getRelationTo(this.fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
this.fme.msg(TL.COMMAND_FLY_CHECK_ENEMY);
if (efplayer.getRelationTo(context.fPlayer) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
context.msg(TL.COMMAND_FLY_CHECK_ENEMY);
return;
}
}
}
if (args.size() == 0) {
toggleFlight(fme.isFlying(), me);
} else if (args.size() == 1) {
toggleFlight(argAsBool(0), me);
if (context.args.size() == 0) {
toggleFlight(context.fPlayer.isFlying(), context.fPlayer, context);
} else if (context.args.size() == 1) {
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) {
fme.setFlying(false);
flyMap.remove(player.getName());
flyMap.remove(fme.getPlayer().getName());
return;
}
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);
flyMap.put(player.getName(), true);
if (id == -1) {
if (P.p.getConfig().getBoolean("ffly.Particles.Enabled")) {
startParticles();
}
}
flyMap.put(fme.getPlayer().getName(), true);
if (flyid == -1) {
startFlyCheck();
}
}, this.p.getConfig().getLong("warmups.f-fly", 0));
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
}
@Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,120 +12,96 @@ public class CmdJoin extends FCommand {
public CmdJoin() {
super();
this.aliases.add("join");
this.requiredArgs.add("faction name");
this.optionalArgs.put("player", "you");
this.permission = Permission.JOIN.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.JOIN)
.playerOnly()
.build();
}
@Override
public void perform() {
Faction faction = this.argAsFaction(0);
public void perform(CommandContext context) {
Faction faction = context.argAsFaction(0);
if (faction == null) {
return;
}
FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false);
boolean samePlayer = fplayer == fme;
FPlayer fplayer = context.argAsBestFPlayerMatch(1, context.fPlayer, false);
boolean samePlayer = fplayer == context.fPlayer;
if (!samePlayer && !Permission.JOIN_OTHERS.has(sender, false)) {
msg(TL.COMMAND_JOIN_CANNOTFORCE);
if (!samePlayer && !Permission.JOIN_OTHERS.has(context.sender, false)) {
context.msg(TL.COMMAND_JOIN_CANNOTFORCE);
return;
}
if (!faction.isNormal()) {
msg(TL.COMMAND_JOIN_SYSTEMFACTION);
context.msg(TL.COMMAND_JOIN_SYSTEMFACTION);
return;
}
if (faction == fplayer.getFaction()) {
//TODO:TL
msg(TL.COMMAND_JOIN_ALREADYMEMBER, fplayer.describeTo(fme, true), (samePlayer ? "are" : "is"), faction.getTag(fme));
context.msg(TL.COMMAND_JOIN_ALREADYMEMBER, fplayer.describeTo(context.fPlayer, true), (samePlayer ? "are" : "is"), faction.getTag(context.fPlayer));
return;
}
if (Conf.factionMemberLimit > 0 && faction.getFPlayers().size() >= Conf.factionMemberLimit) {
msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(fme), Conf.factionMemberLimit, fplayer.describeTo(fme, false));
if (Conf.factionMemberLimit > 0 && faction.getFPlayers().size() >= getFactionMemberLimit(faction)) {
context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), getFactionMemberLimit(faction), fplayer.describeTo(context.fPlayer, false));
return;
}
if (fplayer.hasFaction()) {
//TODO:TL
msg(TL.COMMAND_JOIN_INOTHERFACTION, fplayer.describeTo(fme, true), (samePlayer ? "your" : "their"));
context.msg(TL.COMMAND_JOIN_INOTHERFACTION, fplayer.describeTo(context.fPlayer, true), (samePlayer ? "your" : "their"));
return;
}
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;
}
if (!(faction.getOpen() || faction.isInvited(fplayer) || fme.isAdminBypassing() || Permission.JOIN_ANY.has(sender, false))) {
msg(TL.COMMAND_JOIN_REQUIRESINVITATION);
if (!(faction.getOpen() || faction.isInvited(fplayer) || context.fPlayer.isAdminBypassing() || Permission.JOIN_ANY.has(context.sender, false))) {
context.msg(TL.COMMAND_JOIN_REQUIRESINVITATION);
if (samePlayer) {
faction.msg(TL.COMMAND_JOIN_ATTEMPTEDJOIN, fplayer.describeTo(faction, true));
}
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;
if (altLimit > 0 && faction.getAltPlayers().size() >= altLimit && !faction.altInvited(fme)) {
msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(fme), altLimit, fplayer.describeTo(fme, false));
if (altLimit > 0 && faction.getAltPlayers().size() >= altLimit && !faction.altInvited(context.fPlayer)) {
context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), altLimit, fplayer.describeTo(context.fPlayer, false));
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 (samePlayer && !canAffordCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString())) {
if (samePlayer && !context.canAffordCommand(Conf.econCostJoin, TL.COMMAND_JOIN_TOJOIN.toString())) {
return;
}
// Check for ban
if (!fme.isAdminBypassing() && faction.isBanned(fme)) {
fme.msg(TL.COMMAND_JOIN_BANNED, faction.getTag(fme));
if (!context.fPlayer.isAdminBypassing() && faction.isBanned(context.fPlayer)) {
context.msg(TL.COMMAND_JOIN_BANNED, faction.getTag(context.fPlayer));
return;
}
// 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);
if (joinEvent.isCancelled()) {
return;
}
// 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;
}
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) {
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));
@ -140,18 +116,25 @@ public class CmdJoin extends FCommand {
}
faction.deinvite(fplayer);
fplayer.setRole(faction.getDefaultRole());
context.fPlayer.setRole(faction.getDefaultRole());
if (Conf.logFactionJoin) {
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 {
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
public TL getUsageTranslation() {
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.FPlayer;
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.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
public class CmdKick extends FCommand {
public CmdKick() {
super();
this.aliases.add("kick");
this.optionalArgs.put("player name", "player name");
//this.optionalArgs.put("", "");
this.permission = Permission.KICK.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.KICK)
.playerOnly()
.withAction(PermissableAction.KICK)
.memberOnly()
.build();
}
@Override
public void perform() {
FPlayer toKick = this.argIsSet(0) ? this.argAsBestFPlayerMatch(0) : null;
public void perform(CommandContext context) {
FPlayer toKick = context.argIsSet(0) ? context.argAsBestFPlayerMatch(0) : null;
if (toKick == null) {
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();
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 (FPlayer player : myFaction.getFPlayersWhereRole(Role.MODERATOR)) {
for (FPlayer player : context.faction.getFPlayersWhereRole(Role.MODERATOR)) {
String s = player.getName();
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.
for (FPlayer player : myFaction.getFPlayersWhereRole(Role.COLEADER)) {
for (FPlayer player : context.faction.getFPlayersWhereRole(Role.COLEADER)) {
String s = player.getName();
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;
}
if (fme == toKick) {
msg(TL.COMMAND_KICK_SELF);
msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdLeave.getUseageTemplate(false));
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>"));
if (context.fPlayer == toKick) {
context.msg(TL.COMMAND_KICK_SELF);
context.msg(TL.GENERIC_YOUMAYWANT.toString() + FactionsPlugin.getInstance().cmdBase.cmdLeave.getUseageTemplate(context));
return;
}
Faction toKickFaction = toKick.getFaction();
if (toKickFaction.isWilderness()) {
sender.sendMessage(TL.COMMAND_KICK_NONE.toString());
context.sender.sendMessage(TL.COMMAND_KICK_NONE.toString());
return;
}
@ -85,28 +74,23 @@ public class CmdKick extends FCommand {
// - Check for the kick permission.
// - Make sure the player is in the faction.
// - Make sure the kicked player has lower rank than the kicker.
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.KICK);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_NOPERMISSION, "kick");
if (!context.fPlayer.isAdminBypassing()) {
if (toKickFaction != context.faction) {
context.msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(context.fPlayer, true), context.faction.describeTo(context.fPlayer));
return;
}
if (toKickFaction != myFaction) {
msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(fme, true), myFaction.describeTo(fme));
return;
}
if (toKick.getRole().value >= fme.getRole().value) {
msg(TL.COMMAND_KICK_INSUFFICIENTRANK);
if (toKick.getRole().value >= context.fPlayer.getRole().value) {
context.msg(TL.COMMAND_KICK_INSUFFICIENTRANK);
return;
}
if (!Conf.canLeaveWithNegativePower && toKick.getPower() < 0) {
msg(TL.COMMAND_KICK_NEGATIVEPOWER);
context.msg(TL.COMMAND_KICK_NEGATIVEPOWER);
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 (!canAffordCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString())) {
if (!context.canAffordCommand(Conf.econCostKick, TL.COMMAND_KICK_TOKICK.toString())) {
return;
}
@ -118,18 +102,18 @@ public class CmdKick extends FCommand {
}
// 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;
}
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));
if (toKickFaction != myFaction) {
fme.msg(TL.COMMAND_KICK_KICKS, toKick.describeTo(fme), toKickFaction.describeTo(fme));
toKick.msg(TL.COMMAND_KICK_KICKED, context.fPlayer.describeTo(toKick, true), toKickFaction.describeTo(toKick));
if (toKickFaction != context.faction) {
context.fPlayer.msg(TL.COMMAND_KICK_KICKS, toKick.describeTo(context.fPlayer), toKickFaction.describeTo(context.fPlayer));
}
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) {
toKickFaction.promoteNewLeader();

View File

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

View File

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

View File

@ -3,13 +3,12 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -30,20 +29,15 @@ public class CmdList extends FCommand {
//this.requiredArgs.add("");
this.optionalArgs.put("page", "1");
this.permission = Permission.LIST.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.LIST)
.playerOnly()
.build();
}
@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 (!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;
ArrayList<Faction> factionList = Factions.getInstance().getAllFactions();
@ -52,14 +46,14 @@ public class CmdList extends FCommand {
factionList.remove(Factions.getInstance().getWarZone());
// remove exempt factions
if (fme != null && fme.getPlayer() != null && !fme.getPlayer().hasPermission("factions.show.bypassexempt")) {
List<String> exemptFactions = P.p.getConfig().getStringList("show-exempt");
if (context.fPlayer != null && context.fPlayer.getPlayer() != null && !context.fPlayer.getPlayer().hasPermission("factions.show.bypassexempt")) {
List<String> exemptFactions = FactionsPlugin.getInstance().getConfig().getStringList("show-exempt");
factionList.removeIf(next -> exemptFactions.contains(next.getTag()));
}
// Sort by total followers first
Collections.sort(factionList, (f1, f2) -> {
factionList.sort((f1, f2) -> {
int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) {
@ -87,7 +81,7 @@ public class CmdList extends FCommand {
factionList.add(0, Factions.getInstance().getWilderness());
final int pageheight = 9;
int pagenumber = this.argAsInt(0, 1);
int pagenumber = context.argAsInt(0, 1);
int pagecount = (factionList.size() / pageheight) + 1;
if (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));
lines.add(p.txt.parse(header));
lines.add(FactionsPlugin.getInstance().txt.parse(header));
for (Faction faction : factionList.subList(start, end)) {
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;
}
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

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@ -15,25 +16,17 @@ public class CmdLock extends FCommand {
public CmdLock() {
super();
this.aliases.add("lock");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.LOCK.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.LOCK)
.playerOnly()
.build();
}
@Override
public void perform() {
p.setLocked(this.argAsBool(0, !p.getLocked()));
msg(p.getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED);
public void perform(CommandContext context) {
FactionsPlugin.getInstance().setLocked(context.argAsBool(0, !FactionsPlugin.getInstance().getLocked()));
context.msg(FactionsPlugin.getInstance().getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED);
}
@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("logout");
this.aliases.add("logouts");
this.senderMustBePlayer = true;
this.senderMustBeMember = true;
this.permission = Permission.MONITOR_LOGINS.node;
this.requirements = new CommandRequirements.Builder(Permission.MONITOR_LOGINS)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
boolean monitor = fme.isMonitoringJoins();
fme.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor));
fme.setMonitorJoins(!monitor);
public void perform(CommandContext context) {
boolean monitor = context.fPlayer.isMonitoringJoins();
context.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor));
context.fPlayer.setMonitorJoins(!monitor);
}
@Override

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdLowPower extends FCommand {
@ -10,26 +11,21 @@ public class CmdLowPower extends FCommand {
super();
this.aliases.add("lowpower");
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.POWER_ANY)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
public void perform(CommandContext context) {
double maxPower = Conf.powerPlayerMax;
String format = TL.COMMAND_LOWPOWER_FORMAT.toString();
msg(TL.COMMAND_LOWPOWER_HEADER.toString().replace("{maxpower}", (int) maxPower + ""));
for (FPlayer fPlayer : fme.getFaction().getFPlayers()) {
context.msg(TL.COMMAND_LOWPOWER_HEADER.toString().replace("{maxpower}", (int) maxPower + ""));
for (FPlayer fPlayer : context.faction.getFPlayers()) {
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() {
super();
this.aliases.add("map");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "once");
this.permission = Permission.MAP.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.MAP)
.playerOnly()
.build();
}
@Override
public void perform() {
if (this.argIsSet(0)) {
if (this.argAsBool(0, !fme.isMapAutoUpdating())) {
public void perform(CommandContext context) {
if (context.argIsSet(0)) {
if (context.argAsBool(0, !context.fPlayer.isMapAutoUpdating())) {
// Turn on
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) {
if (!context.payForCommand(Conf.econCostMap, "to show the map", "for showing the map")) {
return;
}
fme.setMapAutoUpdating(true);
msg(TL.COMMAND_MAP_UPDATE_ENABLED);
context.fPlayer.setMapAutoUpdating(true);
context.msg(TL.COMMAND_MAP_UPDATE_ENABLED);
// And show the map once
showMap();
showMap(context);
} else {
// Turn off
fme.setMapAutoUpdating(false);
msg(TL.COMMAND_MAP_UPDATE_DISABLED);
context.fPlayer.setMapAutoUpdating(false);
context.msg(TL.COMMAND_MAP_UPDATE_DISABLED);
}
} else {
// 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;
}
showMap();
showMap(context);
}
}
public void showMap() {
sendFancyMessage(Board.getInstance().getMap(fme, new FLocation(fme), fme.getPlayer().getLocation().getYaw()));
public void showMap(CommandContext context) {
context.sendFancyMessage(Board.getInstance().getMap(context.fPlayer, new FLocation(context.fPlayer), context.player.getLocation().getYaw()));
}
@Override

View File

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

View File

@ -19,58 +19,46 @@ public class CmdMod extends FCommand {
this.aliases.add("setofficer");
this.optionalArgs.put("player name", "name");
//this.optionalArgs.put("", "");
this.permission = Permission.MOD.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.MOD)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0);
public void perform(CommandContext context) {
FPlayer you = context.argAsBestFPlayerMatch(0);
if (you == null) {
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();
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;
}
boolean permAny = Permission.MOD_ANY.has(sender, false);
boolean permAny = Permission.MOD_ANY.has(context.sender, false);
Faction targetFaction = you.getFaction();
if (you.isAlt()) {
msg(ChatColor.RED + "You can not promote alt accounts.");
if (targetFaction != context.faction && !permAny) {
context.msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(context.fPlayer, true));
return;
}
if (targetFaction != myFaction && !permAny) {
msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(fme, true));
if (context.fPlayer != null && context.fPlayer.getRole() != Role.LEADER && !permAny) {
context.msg(TL.COMMAND_MOD_NOTADMIN);
return;
}
if (fme != null && fme.getRole() != Role.LEADER && !permAny) {
msg(TL.COMMAND_MOD_NOTADMIN);
return;
}
if (you == fme && !permAny) {
msg(TL.COMMAND_MOD_SELF);
if (you == context.fPlayer && !permAny) {
context.msg(TL.COMMAND_MOD_SELF);
return;
}
if (you.getRole() == Role.LEADER) {
msg(TL.COMMAND_MOD_TARGETISADMIN);
context.msg(TL.COMMAND_MOD_TARGETISADMIN);
return;
}
@ -78,12 +66,12 @@ public class CmdMod extends FCommand {
// Revoke
you.setRole(Role.NORMAL);
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 {
// Give
you.setRole(Role.MODERATOR);
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("power");
this.permission = Permission.MODIFY_POWER.node; // admin only perm.
// 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;
this.requirements = new CommandRequirements.Builder(Permission.MODIFY_POWER)
.build();
}
@Override
public void perform() {
public void perform(CommandContext context) {
// /f modify <name> #
FPlayer player = argAsBestFPlayerMatch(0);
Double number = argAsDouble(1); // returns null if not a Double.
FPlayer player = context.argAsBestFPlayerMatch(0);
Double number = context.argAsDouble(1); // returns null if not a Double.
if (player == null || number == null) {
sender.sendMessage(getHelpShort());
context.sender.sendMessage(getHelpShort());
return;
}
player.alterPower(number);
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

View File

@ -2,7 +2,8 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
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 org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -10,37 +11,32 @@ import org.bukkit.entity.Player;
public class CmdNear extends FCommand {
public CmdNear() {
super();
this.aliases.add("near");
this.aliases.add("nearby");
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.NEAR)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("fnear.Enabled")) {
fme.msg(TL.COMMAND_NEAR_DISABLED_MSG);
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("fnear.Enabled")) {
context.msg(TL.COMMAND_NEAR_DISABLED_MSG);
return;
}
double range = P.p.getConfig().getInt("fnear.Radius");
double range = FactionsPlugin.getInstance().getConfig().getInt("fnear.Radius");
String format = TL.COMMAND_NEAR_FORMAT.toString();
fme.msg(TL.COMMAND_NEAR_USE_MSG);
for (Entity e : me.getNearbyEntities(range, 255, range)) {
context.msg(TL.COMMAND_NEAR_USE_MSG);
for (Entity e : context.player.getNearbyEntities(range, 255, range)) {
if (e instanceof Player) {
Player player = (((Player) e).getPlayer());
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
if (fme.getFaction() == fplayer.getFaction()) {
double distance = me.getLocation().distance(player.getLocation());
fme.sendMessage(format.replace("{playername}", player.getDisplayName()).replace("{distance}", (int) distance + ""));
if (context.faction == fplayer.getFaction()) {
double distance = context.player.getLocation().distance(player.getLocation());
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.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL;
public class CmdOpen extends FCommand {
@ -12,47 +12,34 @@ public class CmdOpen extends FCommand {
public CmdOpen() {
super();
this.aliases.add("open");
//this.requiredArgs.add("");
this.optionalArgs.put("yes/no", "flip");
this.permission = Permission.OPEN.node;
this.disableOnLock = false;
this.disableOnSpam = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.OPEN)
.withRole(Role.COLEADER)
.playerOnly()
.memberOnly()
.build();
}
@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 (!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;
}
if (!fme.isCooldownEnded("open")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("open"));
return;
}
context.faction.setOpen(context.argAsBool(0, !context.faction.getOpen()));
myFaction.setOpen(this.argAsBool(0, !myFaction.getOpen()));
String open = myFaction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString();
String open = context.faction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString();
// Inform
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(myFaction.getId())) {
fplayer.msg(TL.COMMAND_OPEN_CHANGES, fme.getName(), open);
if (fplayer.getFactionId().equals(context.faction.getId())) {
fplayer.msg(TL.COMMAND_OPEN_CHANGES, context.fPlayer.getName(), open);
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

View File

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

View File

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

View File

@ -1,57 +1,50 @@
package com.massivecraft.factions.cmd;
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.zcore.util.TL;
public class CmdPaypalSee extends FCommand {
public CmdPaypalSee() {
aliases.add("seepaypal");
aliases.add("paypal");
this.aliases.add("seepaypal");
this.aliases.add("paypal");
optionalArgs.put("faction", "yours");
permission = Permission.PAYPAL.node;
disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = true;
this.optionalArgs.put("faction", "yours");
this.requirements = new CommandRequirements.Builder(Permission.PAYPAL)
.memberOnly()
.build();
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("fpaypal.Enabled")) {
fme.msg(TL.GENERIC_DISABLED);
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) {
context.msg(TL.GENERIC_DISABLED);
return;
}
if (args.size() == 0) {
if (myFaction.getPaypal().isEmpty()) {
msg(TL.COMMAND_PAYPAL_NOTSET);
if (context.args.size() == 0) {
if (context.fPlayer.getFaction().getPaypal().isEmpty()) {
context.msg(TL.COMMAND_PAYPAL_NOTSET);
} else {
msg(TL.PAYPALSEE_PLAYER_PAYPAL, myFaction.getPaypal());
context.msg(TL.PAYPALSEE_PLAYER_PAYPAL, context.fPlayer.getFaction().getPaypal());
}
} else if (args.size() == 1) {
if (fme.isAdminBypassing()) {
Faction faction = argAsFaction(0);
} else if (context.args.size() == 1) {
if (context.fPlayer.isAdminBypassing()) {
Faction faction = context.argAsFaction(0);
if (faction != null) {
if (faction.getPaypal().isEmpty()) {
msg(TL.COMMAND_PAYPALSEE_FACTION_NOTSET, faction.getTag());
context.msg(TL.COMMAND_PAYPALSEE_FACTION_NOTSET, faction.getTag());
} 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 {
msg(TL.GENERIC_NOPERMISSION, "see another factions paypal.");
context.msg(TL.GENERIC_NOPERMISSION, "see another factions paypal.");
}
} 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;
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.zcore.util.TL;
@ -14,47 +14,43 @@ public class CmdPaypalSet extends FCommand {
this.requiredArgs.add("email");
this.permission = Permission.PAYPALSET.node;
this.disableOnLock = false;
this.senderMustBePlayer = true;
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
this.senderMustBeColeader = false;
this.senderMustBeAdmin = true;
this.requirements = new CommandRequirements.Builder(Permission.PAYPALSET)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("fpaypal.Enabled")) {
fme.msg(TL.GENERIC_DISABLED);
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) {
context.fPlayer.msg(TL.GENERIC_DISABLED);
return;
}
if (args.size() == 1) {
if (isEmail(argAsString(0))) {
myFaction.paypalSet(argAsString(0));
msg(TL.COMMAND_PAYPALSET_SUCCESSFUL, argAsString(0));
if (context.args.size() == 1) {
if (isEmail(context.argAsString(0))) {
context.fPlayer.getFaction().paypalSet(context.argAsString(0));
context.msg(TL.COMMAND_PAYPALSET_SUCCESSFUL, context.argAsString(0));
} else {
msg(TL.COMMAND_PAYPALSET_NOTEMAIL, argAsString(0));
context.msg(TL.COMMAND_PAYPALSET_NOTEMAIL, context.argAsString(0));
}
} else if (args.size() == 2) {
if (fme.isAdminBypassing()) {
Faction faction = argAsFaction(1);
} else if (context.args.size() == 2) {
if (context.fPlayer.isAdminBypassing()) {
Faction faction = context.argAsFaction(1);
if (faction != null) {
if (isEmail(argAsString(0))) {
myFaction.paypalSet(argAsString(0));
msg(TL.COMMAND_PAYPALSET_ADMIN_SUCCESSFUL, faction.getTag(), argAsString(0));
if (isEmail(context.argAsString(0))) {
context.fPlayer.getFaction().paypalSet(context.argAsString(0));
context.msg(TL.COMMAND_PAYPALSET_ADMIN_SUCCESSFUL, faction.getTag(), context.argAsString(0));
} else {
msg(TL.COMMAND_PAYPALSET_ADMIN_FAILED, argAsString(0));
context.msg(TL.COMMAND_PAYPALSET_ADMIN_FAILED, context.argAsString(0));
}
}
} else {
msg(TL.GENERIC_NOPERMISSION, "set another factions paypal!");
context.msg(TL.GENERIC_NOPERMISSION, "set another factions paypal!");
}
} 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() {
super();
this.aliases.add("peaceful");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.SET_PEACEFUL.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.SET_PEACEFUL)
.build();
}
@Override
public void perform() {
Faction faction = this.argAsFaction(0);
public void perform(CommandContext context) {
Faction faction = context.argAsFaction(0);
if (faction == null) {
return;
}
@ -44,7 +36,7 @@ public class CmdPeaceful extends FCommand {
// Inform all players
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) {
fplayer.msg(TL.COMMAND_PEACEFUL_YOURS, blame, change);
} else {

View File

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

View File

@ -3,7 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
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.zcore.util.TL;
@ -13,23 +13,15 @@ public class CmdPermanent extends FCommand {
public CmdPermanent() {
super();
this.aliases.add("permanent");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.SET_PERMANENT.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.SET_PERMANENT)
.build();
}
@Override
public void perform() {
Faction faction = this.argAsFaction(0);
public void perform(CommandContext context) {
Faction faction = context.argAsFaction(0);
if (faction == null) {
return;
}
@ -43,11 +35,11 @@ public class CmdPermanent extends FCommand {
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
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) {
fplayer.msg(TL.COMMAND_PERMANENT_YOURS, blame, change);
} else {
@ -61,3 +53,4 @@ public class CmdPermanent extends FCommand {
return TL.COMMAND_PERMANENT_DESCRIPTION;
}
}

View File

@ -9,28 +9,21 @@ public class CmdPermanentPower extends FCommand {
public CmdPermanentPower() {
super();
this.aliases.add("permanentpower");
this.requiredArgs.add("faction");
this.requiredArgs.add("power");
this.permission = Permission.SET_PERMANENTPOWER.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.SET_PERMANENTPOWER)
.build();
}
@Override
public void perform() {
Faction targetFaction = this.argAsFaction(0);
public void perform(CommandContext context) {
Faction targetFaction = context.argAsFaction(0);
if (targetFaction == null) {
return;
}
Integer targetPower = this.argAsInt(1);
Integer targetPower = context.argAsInt(1);
targetFaction.setPermanentPower(targetPower);
@ -40,14 +33,14 @@ public class CmdPermanentPower extends FCommand {
}
// 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
for (FPlayer fplayer : targetFaction.getFPlayersWhereOnline(true)) {
if (fplayer == fme) {
if (fplayer == context.fPlayer) {
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);
}
}

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
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.zcore.util.TL;
@ -15,69 +15,65 @@ public class CmdRules extends FCommand {
aliases.add("rules");
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
public void perform() {
if (!P.p.getConfig().getBoolean("frules.Enabled")) {
fme.msg(TL.COMMAND_RULES_DISABLED_MSG);
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("frules.Enabled")) {
context.msg(TL.COMMAND_RULES_DISABLED_MSG);
return;
}
if (this.args.size() == 0) {
HashMap<Integer, String> rules = fme.getFaction().getRulesMap();
if (context.args.size() == 0) {
HashMap<Integer, String> rules = context.faction.getRulesMap();
if (rules.size() == 0) {
List<String> ruleList = P.p.getConfig().getStringList("frules.default-rules");
fme.sendMessage(P.p.colorList(ruleList));
List<String> ruleList = FactionsPlugin.getInstance().getConfig().getStringList("frules.default-rules");
context.sendMessage(FactionsPlugin.getInstance().colorList(ruleList));
} else {
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 (args.get(0).equalsIgnoreCase("add")) {
fme.msg(TL.COMMAND_RULES_ADD_INVALIDARGS);
if (context.args.size() == 1) {
if (context.args.get(0).equalsIgnoreCase("add")) {
context.msg(TL.COMMAND_RULES_ADD_INVALIDARGS);
}
if (args.get(0).equalsIgnoreCase("set")) {
fme.msg(TL.COMMAND_RULES_SET_INVALIDARGS);
if (context.args.get(0).equalsIgnoreCase("set")) {
context.msg(TL.COMMAND_RULES_SET_INVALIDARGS);
}
if (args.get(0).equalsIgnoreCase("remove")) {
fme.msg(TL.COMMAND_RULES_REMOVE_INVALIDARGS);
if (context.args.get(0).equalsIgnoreCase("remove")) {
context.msg(TL.COMMAND_RULES_REMOVE_INVALIDARGS);
}
if (args.get(0).equalsIgnoreCase("clear")) {
fme.getFaction().clearRules();
fme.msg(TL.COMMAND_RULES_CLEAR_SUCCESS);
if (context.args.get(0).equalsIgnoreCase("clear")) {
context.faction.clearRules();
context.msg(TL.COMMAND_RULES_CLEAR_SUCCESS);
}
}
if (this.args.size() >= 2) {
if (args.get(0).equalsIgnoreCase("add")) {
if (context.args.size() >= 2) {
if (context.args.get(0).equalsIgnoreCase("add")) {
String message = "";
StringBuilder string = new StringBuilder(message);
for (int i = 1; i <= args.size() - 1; i++) {
string.append(" ").append(args.get(i));
for (int i = 1; i <= context.args.size() - 1; i++) {
string.append(" " + context.args.get(i));
}
fme.getFaction().addRule(string.toString());
fme.msg(TL.COMMAND_RULES_ADD_SUCCESS);
context.faction.addRule(string.toString());
context.msg(TL.COMMAND_RULES_ADD_SUCCESS);
}
if (this.args.size() == 2) {
if (args.get(0).equalsIgnoreCase("remove")) {
int index = argAsInt(1);
fme.getFaction().removeRule(index - 1);
fme.msg(TL.COMMAND_RULES_REMOVE_SUCCESS);
if (context.args.size() == 2) {
if (context.args.get(0).equalsIgnoreCase("remove")) {
int index = context.argAsInt(1);
context.faction.removeRule(index - 1);
context.msg(TL.COMMAND_RULES_REMOVE_SUCCESS);
}
}

View File

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

View File

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

View File

@ -2,7 +2,7 @@ package com.massivecraft.factions.cmd;
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.util.Particles.ParticleEffect;
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.
public static HashMap<String, Boolean> seeChunkMap = new HashMap<>();
Long interval;
private long interval;
private boolean useParticles;
private ParticleEffect effect;
private int taskID = -1;
@ -31,30 +31,26 @@ public class CmdSeeChunk extends FCommand {
aliases.add("seechunk");
aliases.add("sc");
permission = Permission.SEECHUNK.node;
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);
this.useParticles = FactionsPlugin.getInstance().getConfig().getBoolean("see-chunk.particles", true);
interval = FactionsPlugin.getInstance().getConfig().getLong("see-chunk.interval", 10L);
if (effect == null) {
effect = ParticleEffect.REDSTONE;
}
this.requirements = new CommandRequirements.Builder(Permission.SEECHUNK)
.playerOnly()
.build();
}
@Override
public void perform() {
if (seeChunkMap.containsKey(me.getName())) {
seeChunkMap.remove(me.getName());
msg(TL.COMMAND_SEECHUNK_DISABLED);
public void perform(CommandContext context) {
if (seeChunkMap.containsKey(context.player.getName())) {
seeChunkMap.remove(context.player.getName());
context.msg(TL.COMMAND_SEECHUNK_DISABLED);
} else {
seeChunkMap.put(me.getName(), true);
msg(TL.COMMAND_SEECHUNK_ENABLED);
seeChunkMap.put(context.player.getName(), true);
context.msg(TL.COMMAND_SEECHUNK_ENABLED);
manageTask();
}
}
@ -71,7 +67,7 @@ public class CmdSeeChunk extends FCommand {
}
private void startTask() {
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> {
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> {
for (Object nameObject : seeChunkMap.keySet()) {
String name = nameObject + "";
Player player = Bukkit.getPlayer(name);
@ -115,10 +111,10 @@ public class CmdSeeChunk extends FCommand {
continue;
}
if (useParticles) {
if (P.p.useNonPacketParticles) {
if (FactionsPlugin.getInstance().useNonPacketParticles) {
// Dust options only exists in the 1.13 API, so we use an
// 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));
} else {
player.getWorld().spawnParticle(Particle.REDSTONE, loc, 0, 255, 0, 0, 1);

View File

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

View File

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

View File

@ -1,12 +1,10 @@
package com.massivecraft.factions.cmd;
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.Relation;
import com.massivecraft.factions.struct.Role;
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.util.TL;
@ -17,63 +15,51 @@ public class CmdSetFWarp extends FCommand {
this.aliases.add("setwarp");
this.aliases.add("sw");
this.requiredArgs.add("warp name");
this.optionalArgs.put("password", "password");
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
this.senderMustBePlayer = true;
this.permission = Permission.SETWARP.node;
this.requirements = new CommandRequirements.Builder(Permission.SETWARP)
.playerOnly()
.memberOnly()
.withAction(PermissableAction.SETWARP)
.build();
}
@Override
public void perform() {
if (!(fme.getRelationToLocation() == Relation.MEMBER)) {
fme.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
public void perform(CommandContext context) {
if (!(context.fPlayer.getRelationToLocation() == Relation.MEMBER)) {
context.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
return;
}
// This statement allows us to check if they've specifically denied it, or default to
// 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);
String warp = context.argAsString(0);
// 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);
boolean tooManyWarps = maxWarps <= myFaction.getWarps().size();
int maxWarps = FactionsPlugin.getInstance().getConfig().getInt("max-warps", 5);
boolean tooManyWarps = maxWarps <= context.faction.getWarps().size();
if (tooManyWarps && !warpExists) {
fme.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
context.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
return;
}
if (!transact(fme)) {
if (!transact(context.fPlayer, context)) {
return;
}
String password = argAsString(1);
String password = context.argAsString(1);
LazyLocation loc = new LazyLocation(fme.getPlayer().getLocation());
myFaction.setWarp(warp, loc);
LazyLocation loc = new LazyLocation(context.player.getLocation());
context.faction.setWarp(warp, loc);
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) {
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());
private boolean transact(FPlayer player, CommandContext context) {
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
@ -81,3 +67,4 @@ public class CmdSetFWarp extends FCommand {
return TL.COMMAND_SETFWARP_DESCRIPTION;
}
}

View File

@ -10,37 +10,29 @@ public class CmdSetMaxVaults extends FCommand {
public CmdSetMaxVaults() {
this.aliases.add("setmaxvaults");
this.aliases.add("smv");
this.requiredArgs.add("faction");
this.requiredArgs.add("number");
this.permission = Permission.SETMAXVAULTS.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.SETMAXVAULTS)
.build();
}
@Override
public void perform() {
Faction targetFaction = argAsFaction(0);
int value = argAsInt(1, -1);
public void perform(CommandContext context) {
Faction targetFaction = context.argAsFaction(0);
int value = context.argAsInt(1, -1);
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;
}
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;
}
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

View File

@ -1,12 +1,7 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.*;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
@ -14,60 +9,46 @@ public class CmdSethome extends FCommand {
public CmdSethome() {
this.aliases.add("sethome");
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "mine");
this.permission = Permission.SETHOME.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.SETHOME)
.playerOnly()
.memberOnly()
.withAction(PermissableAction.SETHOME)
.build();
}
@Override
public void perform() {
public void perform(CommandContext context) {
if (!Conf.homesEnabled) {
fme.msg(TL.COMMAND_SETHOME_DISABLED);
context.msg(TL.COMMAND_SETHOME_DISABLED);
return;
}
Faction faction = this.argAsFaction(0, myFaction);
Faction faction = context.argAsFaction(0, context.faction);
if (faction == null) {
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?
if (!Permission.BYPASS.has(me) &&
if (!Permission.BYPASS.has(context.player) &&
Conf.homesMustBeInClaimedTerritory &&
Board.getInstance().getFactionAt(new FLocation(me)) != faction) {
fme.msg(TL.COMMAND_SETHOME_NOTCLAIMED);
Board.getInstance().getFactionAt(new FLocation(context.player)) != faction) {
context.msg(TL.COMMAND_SETHOME_NOTCLAIMED);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostSethome, TL.COMMAND_SETHOME_TOSET, TL.COMMAND_SETHOME_FORSET)) {
if (!context.payForCommand(Conf.econCostSethome, TL.COMMAND_SETHOME_TOSET, TL.COMMAND_SETHOME_FORSET)) {
return;
}
faction.setHome(me.getLocation());
faction.setHome(context.player.getLocation());
faction.msg(TL.COMMAND_SETHOME_SET, fme.describeTo(myFaction, true));
faction.sendMessage(p.cmdBase.cmdHome.getUseageTemplate());
if (faction != myFaction) {
fme.msg(TL.COMMAND_SETHOME_SETOTHER, faction.getTag(fme));
faction.msg(TL.COMMAND_SETHOME_SET, context.fPlayer.describeTo(context.faction, true));
faction.sendMessage(FactionsPlugin.getInstance().cmdBase.cmdHome.getUseageTemplate(context));
if (faction != context.faction) {
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.Faction;
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.TagReplacer;
@ -19,14 +19,12 @@ public class CmdShow extends FCommand {
public CmdShow() {
this.aliases.add("show");
this.aliases.add("who");
this.aliases.add("f");
// add defaults to /f show in case config doesnt have it
defaults.add("{header}");
defaults.add("<a>Description: <i>{description}");
defaults.add("<a>Joining: <i>{joining} {peaceful}");
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>This faction is permanent, remaining even with no members.");
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>Online: (<i>{online}<a>/<i>{members}<a>): {online-list}");
defaults.add("<a>Offline: (<i>{offline}<a>/<i>{members}<a>): {offline-list}");
defaults.add("<a>Alt List: <i>{alts}");
// this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.SHOW.node;
this.disableOnLock = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.SHOW).build();
}
@Override
public void perform() {
Faction faction = myFaction;
if (this.argIsSet(0))
faction = this.argAsFaction(0);
public void perform(CommandContext context) {
Faction faction = context.faction;
if (context.argIsSet(0))
faction = context.argAsFaction(0);
if (faction == null)
return;
if (fme != null && !fme.getPlayer().hasPermission("factions.show.bypassexempt")
&& P.p.getConfig().getStringList("show-exempt").contains(faction.getTag())) {
msg(TL.COMMAND_SHOW_EXEMPT);
if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt")
&& FactionsPlugin.getInstance().getConfig().getStringList("show-exempt").contains(faction.getTag())) {
context.msg(TL.COMMAND_SHOW_EXEMPT);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) {
if (!context.payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) {
return;
}
List<String> show = P.p.getConfig().getStringList("show");
List<String> show = FactionsPlugin.getInstance().getConfig().getStringList("show");
if (show == null || show.isEmpty())
show = defaults;
if (!faction.isNormal()) {
String tag = faction.getTag(fme);
String tag = faction.getTag(context.fPlayer);
// send header and that's all
String header = show.get(0);
if (TagReplacer.HEADER.contains(header)) {
msg(p.txt.titleize(tag));
context.msg(FactionsPlugin.getInstance().txt.titleize(tag));
} 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
}
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) {
continue; // Due to minimal f show.
}
if (fme != null) {
parsed = TagUtil.parsePlaceholders(fme.getPlayer(), parsed);
if (context.fPlayer != null) {
parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), 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)
sendFancyMessage(fancy);
context.sendFancyMessage(fancy);
continue;
}
@ -108,7 +100,7 @@ public class CmdShow extends FCommand {
if (parsed.contains("%")) {
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 CmdShowClaims() {
this.aliases.add("showclaims");
this.aliases.add("showclaim");
permission = Permission.SHOWCLAIMS.node;
this.senderMustBePlayer = true;
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
this.requirements = new CommandRequirements.Builder(Permission.SHOWCLAIMS)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}", fme.getFaction().describeTo(fme)));
public void perform(CommandContext context) {
context.sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}", context.faction.describeTo(context.fPlayer)));
ListMultimap<String, String> chunkMap = ArrayListMultimap.create();
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() + ""));
}
for (String world : chunkMap.keySet()) {
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:
sendMessage(message.replace("{chunks}", ""));
context.sendMessage(message.replace("{chunks}", ""));
StringBuilder chunks = new StringBuilder();
for (String chunkString : chunkMap.get(world)) {
chunks.append(chunkString).append(", ");
if (chunks.toString().length() >= 2000) {
sendMessage(chunks.toString());
context.sendMessage(chunks.toString());
chunks.setLength(0);
}
}
if (chunks.length() != 0) sendMessage(chunks.toString());
sendMessage("");
if (chunks.length() != 0) context.sendMessage(chunks.toString());
context.sendMessage("");
}
@ -54,3 +52,4 @@ public class CmdShowClaims extends FCommand {
}

View File

@ -13,23 +13,24 @@ public class CmdShowInvites extends FCommand {
public CmdShowInvites() {
super();
aliases.add("showinvites");
permission = Permission.SHOW_INVITES.node;
senderMustBePlayer = true;
senderMustBeMember = true;
this.requirements = new CommandRequirements.Builder(Permission.SHOW_INVITES)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
public void perform(CommandContext context) {
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);
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);
}
sendFancyMessage(msg);
context.sendFancyMessage(msg);
}
@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("s");
this.permission = Permission.STATUS.node;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.STATUS)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
public void perform(CommandContext context) {
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 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;
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

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@ -8,27 +7,19 @@ public class CmdStealth extends FCommand {
public CmdStealth() {
this.aliases.add("ninja");
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() {
Faction faction = fme.getFaction();
if (faction != null && !faction.getId().equalsIgnoreCase("0") && !faction.getId().equalsIgnoreCase("none") && !faction.getId().equalsIgnoreCase("safezone") && !faction.getId().equalsIgnoreCase("warzone")) {
fme.setStealth(!fme.isStealthEnabled());
fme.msg(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE);
@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")) {
context.fPlayer.setStealth(!context.fPlayer.isStealthEnabled());
context.msg(context.fPlayer.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE);
} 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.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class CmdStuck extends FCommand {
public CmdStuck() {
super();
this.aliases.add("stuck");
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
public void perform() {
final Player player = fme.getPlayer();
public void perform(CommandContext context) {
final Player player = context.player;
final Location sentAt = player.getLocation();
final FLocation chunk = fme.getLastStoodAt();
final long delay = P.p.getConfig().getLong("hcf.stuck.delay", 30);
final int radius = P.p.getConfig().getInt("hcf.stuck.radius", 10);
final FLocation chunk = context.fPlayer.getLastStoodAt();
final long delay = FactionsPlugin.getInstance().getConfig().getLong("hcf.stuck.delay", 30);
final int radius = FactionsPlugin.getInstance().getConfig().getInt("hcf.stuck.radius", 10);
if (P.p.getStuckMap().containsKey(player.getUniqueId())) {
long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
if (FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) {
long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
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 {
// 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;
}
final int id = Bukkit.getScheduler().runTaskLater(P.p, new BukkitRunnable() {
final int id = Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), new Runnable() {
@Override
public void run() {
if (!P.p.getStuckMap().containsKey(player.getUniqueId())) {
if (!FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) {
return;
}
// check for world difference or radius exceeding
final World world = chunk.getWorld();
if (world.getUID() != player.getWorld().getUID() || sentAt.distance(player.getLocation()) > radius) {
msg(TL.COMMAND_STUCK_OUTSIDE.format(radius));
P.p.getTimers().remove(player.getUniqueId());
P.p.getStuckMap().remove(player.getUniqueId());
context.msg(TL.COMMAND_STUCK_OUTSIDE.format(radius));
FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId());
FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId());
return;
}
final Board board = Board.getInstance();
// spiral task to find nearest wilderness chunk
new SpiralTask(new FLocation(me), radius * 2) {
final int buffer = P.p.getConfig().getInt("world-border.buffer", 0);
new SpiralTask(new FLocation(context.player), radius * 2) {
@Override
public boolean work() {
FLocation chunk = currentFLocation();
if (chunk.isOutsideWorldBorder(buffer)) {
return true;
}
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)) {
int cx = FLocation.chunkToBlock((int) chunk.getX());
int cz = FLocation.chunkToBlock((int) chunk.getZ());
int y = world.getHighestBlockYAt(cx, cz);
Location tp = new Location(world, cx, y, cz);
msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ());
P.p.getTimers().remove(player.getUniqueId());
P.p.getStuckMap().remove(player.getUniqueId());
context.msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ());
FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId());
FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId());
if (!Essentials.handleTeleport(player, 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();
return false;
@ -101,11 +89,11 @@ public class CmdStuck extends FCommand {
}
}, delay * 20).getTaskId();
P.p.getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000));
long wait = P.p.getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
FactionsPlugin.getInstance().getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000));
long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
msg(TL.COMMAND_STUCK_START, time);
P.p.getStuckMap().put(player.getUniqueId(), id);
context.msg(TL.COMMAND_STUCK_START, time);
FactionsPlugin.getInstance().getStuckMap().put(player.getUniqueId(), id);
}
}
@ -114,3 +102,4 @@ public class CmdStuck extends FCommand {
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.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
@ -17,77 +18,65 @@ public class CmdTag extends FCommand {
this.aliases.add("rename");
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
public void perform() {
String tag = this.argAsString(0);
if (!fme.isCooldownEnded("tag")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("tag"));
return;
}
public void perform(CommandContext context) {
String tag = context.argAsString(0);
// TODO does not first test cover selfcase?
if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) {
msg(TL.COMMAND_TAG_TAKEN);
if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(context.faction.getComparisonTag())) {
context.msg(TL.COMMAND_TAG_TAKEN);
return;
}
ArrayList<String> errors = MiscUtil.validateTag(tag);
if (errors.size() > 0) {
sendMessage(errors);
context.sendMessage(errors);
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 (!canAffordCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE.toString())) {
if (!context.canAffordCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE.toString())) {
return;
}
// trigger the faction rename event (cancellable)
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag);
FactionRenameEvent renameEvent = new FactionRenameEvent(context.fPlayer, tag);
Bukkit.getServer().getPluginManager().callEvent(renameEvent);
if (renameEvent.isCancelled()) {
return;
}
// 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;
}
String oldtag = myFaction.getTag();
myFaction.setTag(tag);
String oldtag = context.faction.getTag();
context.faction.setTag(tag);
// Inform
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(myFaction.getId())) {
fplayer.msg(TL.COMMAND_TAG_FACTION, fme.describeTo(myFaction, true), myFaction.getTag(myFaction));
if (fplayer.getFactionId().equals(context.faction.getId())) {
fplayer.msg(TL.COMMAND_TAG_FACTION, context.fPlayer.describeTo(context.faction, true), context.faction.getTag(context.faction));
continue;
}
// Broadcast the tag change (if applicable)
if (Conf.broadcastTagChanges) {
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

View File

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

View File

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

View File

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

View File

@ -1,39 +1,39 @@
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.FactionsPlayerListener;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.TL;
public class CmdTpBanner extends FCommand {
public CmdTpBanner() {
super();
this.aliases.add("tpbanner");
this.permission = Permission.TPBANNER.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.TPBANNER)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("fbanners.Enabled")) {
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Enabled")) {
return;
}
if (FactionsBlockListener.bannerLocations.containsKey(fme.getTag())) {
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));
final FactionsPlayerListener fpl = new FactionsPlayerListener();
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 {
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.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;
@ -12,44 +11,40 @@ public class CmdUnban extends FCommand {
public CmdUnban() {
super();
this.aliases.add("unban");
this.requiredArgs.add("target");
this.permission = Permission.BAN.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.BAN)
.playerOnly()
.memberOnly()
.withAction(PermissableAction.BAN)
.build();
}
@Override
public void perform() {
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;
}
}
public void perform(CommandContext context) {
// Good on permission checks. Now lets just ban the player.
FPlayer target = argAsFPlayer(0);
FPlayer target = context.argAsFPlayer(0);
if (target == null) {
return; // the above method sends a message if fails to find someone.
}
if (!myFaction.isBanned(target)) {
fme.msg(TL.COMMAND_UNBAN_NOTBANNED, target.getName());
if (target.getFaction() != context.fPlayer.getFaction()) {
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;
}
myFaction.unban(target);
context.faction.unban(target);
myFaction.msg(TL.COMMAND_UNBAN_UNBANNED, fme.getName(), target.getName());
target.msg(TL.COMMAND_UNBAN_TARGET, myFaction.getTag(target));
context.msg(TL.COMMAND_UNBAN_UNBANNED, context.fPlayer.getName(), target.getName());
target.msg(TL.COMMAND_UNBAN_TARGET, context.faction.getTag(target));
}
@Override

View File

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

View File

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

View File

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

View File

@ -1,40 +1,38 @@
package com.massivecraft.factions.cmd;
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.zcore.util.TL;
public class CmdViewChest extends FCommand {
public CmdViewChest() {
super();
this.aliases.add("viewchest");
this.aliases.add("viewpv");
this.requiredArgs.add("faction name");
this.permission = Permission.VIEWCHEST.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.requirements = new CommandRequirements.Builder(Permission.VIEWCHEST)
.playerOnly()
.build();
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("fchest.Enabled")) {
fme.msg(TL.GENERIC_DISABLED);
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("fchest.Enabled")) {
context.msg(TL.GENERIC_DISABLED);
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) {
return;
}
me.openInventory(faction.getChestInventory());
context.player.openInventory(context.faction.getChestInventory());
}
@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;
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.check.CmdCheck;
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.shop.CmdShop;
import com.massivecraft.factions.zcore.util.TL;
import me.lucko.commodore.CommodoreProvider;
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.logging.Level;
public class FCmdRoot extends FCommand {
public class FCmdRoot extends FCommand implements CommandExecutor {
public BrigadierManager brigadierManager;
public CmdAdmin cmdAdmin = new CmdAdmin();
public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim();
@ -124,43 +132,33 @@ public class FCmdRoot extends FCommand {
public CmdTntFill cmdTntFill = new CmdTntFill();
public CmdChest cmdChest = new CmdChest();
public CmdSetBanner cmdSetBanner = new CmdSetBanner();
public CmdStrike cmdStrike = new CmdStrike();
public CmdStrikeSet cmdStrikeSet = new CmdStrikeSet();
public CmdAlts cmdAlts = new CmdAlts();
public CmdSpam cmdSpam = new CmdSpam();
public CmdCorner cmdCorner = new CmdCorner();
public CmdInventorySee cmdInventorySee = new CmdInventorySee();
public CmdFGlobal cmdFGlobal = new CmdFGlobal();
public CmdViewChest cmdViewChest = new CmdViewChest();
public CmdPoints cmdPoints = new CmdPoints();
public CmdLogout cmdLogout = new CmdLogout();
public CmdNotifications cmdNotifications = new CmdNotifications();
public CmdShop cmdShop = new CmdShop();
public CmdMissions cmdMissions = new CmdMissions();
public CmdStrikes cmdStrikes = new CmdStrikes();
public CmdCheck cmdCheck = new CmdCheck();
public CmdWeeWoo cmdWeeWoo = new CmdWeeWoo();
public FCmdRoot() {
super();
if (CommodoreProvider.isSupported()) brigadierManager = new BrigadierManager();
this.aliases.addAll(Conf.baseCommandAliases);
this.aliases.removeAll(Collections.<String>singletonList(null)); // remove any nulls from extra commas
this.allowNoSlashAccess = Conf.allowNoSlashCommand;
//this.requiredArgs.add("");
//this.optionalArgs.put("","")
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.disableOnLock = false;
this.aliases.removeAll(Collections.<String>singletonList(null));
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.cmdAutoClaim);
@ -175,7 +173,6 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdDeinvite);
this.addSubCommand(this.cmdDescription);
this.addSubCommand(this.cmdDisband);
this.addSubCommand(this.cmdStrike);
this.addSubCommand(this.cmdHelp);
this.addSubCommand(this.cmdHome);
this.addSubCommand(this.cmdInvite);
@ -187,7 +184,6 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdMap);
this.addSubCommand(this.cmdMod);
this.addSubCommand(this.cmdMoney);
this.addSubCommand(this.cmdNotifications);
this.addSubCommand(this.cmdOpen);
this.addSubCommand(this.cmdOwner);
this.addSubCommand(this.cmdOwnerList);
@ -253,9 +249,8 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdTntFill);
this.addSubCommand(this.cmdChest);
this.addSubCommand(this.cmdSetBanner);
this.addSubCommand(this.cmdStrikeSet);
this.addSubCommand(this.cmdSpam);
this.addSubCommand(this.cmdCorner);
this.addSubCommand(this.cmdStrikes);
this.addSubCommand(this.cmdFGlobal);
this.addSubCommand(this.cmdViewChest);
@ -264,61 +259,77 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdWeeWoo);
}
if (P.p.getConfig().getBoolean("Missions-Enabled")) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("Missions-Enabled")) {
this.addSubCommand(this.cmdMissions);
}
if (P.p.getConfig().getBoolean("F-Shop.Enabled")) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled")) {
this.addSubCommand(this.cmdShop);
}
if (P.p.getConfig().getBoolean("f-inventory-see.Enabled")) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled")) {
this.addSubCommand(this.cmdInventorySee);
}
if (P.p.getConfig().getBoolean("f-points.Enabled")) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled")) {
this.addSubCommand(this.cmdPoints);
}
if (P.p.getConfig().getBoolean("f-alts.Enabled")) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("f-alts.Enabled")) {
this.addSubCommand(this.cmdAlts);
}
if (P.p.getConfig().getBoolean("f-grace.Enabled")) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) {
this.addSubCommand(this.cmdGrace);
}
if (Bukkit.getServer().getPluginManager().getPlugin("CoreProtect") != null) {
P.p.log("Found CoreProtect, enabling Inspect");
FactionsPlugin.getInstance().log("Found CoreProtect, enabling Inspect");
this.addSubCommand(this.cmdInspect);
} else {
P.p.log("CoreProtect not found, disabling Inspect");
FactionsPlugin.getInstance().log("CoreProtect not found, disabling Inspect");
}
if (P.p.getConfig().getBoolean("ffocus.Enabled")) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("ffocus.Enabled")) {
addSubCommand(this.cmdFocus);
}
if (P.p.getConfig().getBoolean("enable-faction-flight", false)) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) {
this.addSubCommand(this.cmdFly);
}
if (Bukkit.getServer().getPluginManager().getPlugin("FactionsTop") != null || Bukkit.getServer().getPluginManager().getPlugin("SavageFTOP") != null || Bukkit.getServer().getPluginManager().getPlugin("SaberFTOP") != null) {
P.p.log(Level.INFO, "Found FactionsTop plugin. Disabling our own /f top command.");
FactionsPlugin.getInstance().log(Level.INFO, "Found FactionsTop plugin. Disabling our own /f top command.");
} else {
P.p.log(Level.INFO, "Enabling FactionsTop command, this is a very basic /f top please get a dedicated /f top resource if you want land calculation etc.");
FactionsPlugin.getInstance().log(Level.INFO, "Enabling FactionsTop command, this is a very basic /f top please get a dedicated /f top resource if you want land calculation etc.");
this.addSubCommand(this.cmdTop);
}
if (P.p.getConfig().getBoolean("fpaypal.Enabled")) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("fpaypal.Enabled")) {
this.addSubCommand(this.cmdPaypalSet);
this.addSubCommand(this.cmdPaypalSee);
}
if (CommodoreProvider.isSupported()) brigadierManager.build();
}
@Override
public void perform() {
this.commandChain.add(this);
this.cmdHelp.execute(this.sender, this.args, this.commandChain);
public void perform(CommandContext context) {
context.commandChain.add(this);
this.cmdHelp.execute(context);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
this.execute(new CommandContext(sender, new ArrayList<>(Arrays.asList(args)), label));
return true;
}
@Override
public void addSubCommand(FCommand subCommand) {
super.addSubCommand(subCommand);
// People were getting NPE's as somehow CommodoreProvider#isSupported returned true on legacy versions.
if (CommodoreProvider.isSupported()) {
brigadierManager.addSubCommand(subCommand);
}
}
@Override

View File

@ -1,351 +1,248 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.MCommand;
import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.zcore.util.TextUtil;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;
public abstract class FCommand extends MCommand<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;
public boolean disableOnSpam;
// Command Aliases
public List<String> aliases;
public FPlayer fme;
public Faction myFaction;
public boolean senderMustBeMember;
public boolean senderMustBeModerator;
public boolean senderMustBeAdmin;
public boolean senderMustBeColeader;
// Information on the args
public List<String> requiredArgs;
public LinkedHashMap<String, String> optionalArgs;
public boolean isMoneyCommand;
// Requirements to execute this command
public CommandRequirements requirements;
/*
Subcommands
*/
public List<FCommand> subCommands;
/*
Help
*/
public List<String> helpLong;
public CommandVisibility visibility;
private String helpShort;
public FCommand() {
super(P.p);
// Due to safety reasons it defaults to disable on lock.
disableOnLock = true;
disableOnSpam = false;
requirements = new CommandRequirements.Builder(null).build();
// The money commands must be disabled if money should not be used.
isMoneyCommand = false;
this.subCommands = new ArrayList<>();
this.aliases = new ArrayList<>();
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
this.requiredArgs = new ArrayList<>();
this.optionalArgs = new LinkedHashMap<>();
this.helpShort = null;
this.helpLong = new ArrayList<>();
this.visibility = CommandVisibility.VISIBLE;
}
@Override
public void setCommandSender(CommandSender sender) {
super.setCommandSender(sender);
if (sender instanceof Player) {
this.fme = FPlayers.getInstance().getByPlayer((Player) sender);
this.myFaction = this.fme.getFaction();
public abstract void perform(CommandContext context);
public void execute(CommandContext context) {
// Is there a matching sub command?
if (context.args.size() > 0) {
for (FCommand subCommand : this.subCommands) {
if (subCommand.aliases.contains(context.args.get(0).toLowerCase())) {
context.args.remove(0);
context.commandChain.add(this);
subCommand.execute(context);
return;
}
}
}
if (!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 {
this.fme = null;
this.myFaction = null;
val = "=" + val;
}
args.add("[" + optionalArg.getKey() + val + "]");
}
@Override
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
setCommandSender(sender);
super.execute(sender, args, commandChain);
if (args.size() > 0) {
ret.append(FactionsPlugin.getInstance().txt.parseTags(" "));
ret.append(TextUtil.implode(args, " "));
}
@Override
public boolean isEnabled() {
if (p.getLocked() && this.disableOnLock) {
msg("<b>Factions was locked by an admin. Please try again later.");
return false;
if (addShortHelp) {
ret.append(FactionsPlugin.getInstance().txt.parseTags(" "));
ret.append(this.getHelpShort());
}
if (p.getSpam() && this.disableOnSpam) {
msg("<b>Anti-Spam is currently enabled! Please try again later.");
return false;
return ret.toString();
}
if (this.isMoneyCommand && !Conf.econEnabled) {
msg("<b>Faction economy features are disabled on this server.");
return false;
public String getUseageTemplate(CommandContext context) {
return getUseageTemplate(context, 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