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

@@ -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