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

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