Skip to content

Commit

Permalink
Command cleanup (#2351)
Browse files Browse the repository at this point in the history
* update version command tagline

replace links with variables for readability

* move guide link into a constant

* formatting and wording fixes

* formatting fixes in NPCCommandHandler

* formatting mostly in fishing command

I have no idea what the flag "percent" does so I just made something up, should probably be changed.

* more npc formatting fixes

also shorten an if statement

* acikek suggestions

fix passive voice
use screaming snake case

* fix my own typo (oops)

* review fixes

* more review changes
  • Loading branch information
funkychicken493 committed Aug 2, 2022
1 parent 3ccbd98 commit a2cd344
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
Expand Up @@ -137,23 +137,23 @@ public void debug(CommandContext args, CommandSender sender) throws CommandExcep
}
Debug.showStackTraces = !Debug.showStackTraces;
Messaging.sendInfo(sender, (Debug.showStackTraces ? "Denizen debugger is now showing caught " +
"exception stack traces." : "Denizen debugger is now hiding caught stacktraces."));
"exception stack traces." : "Denizen debugger is no longer showing caught stack traces."));
}
if (args.hasFlag('c')) {
if (!Debug.showDebug) {
Debug.toggle();
}
Debug.showColor = !Debug.showColor;
Messaging.sendInfo(sender, (Debug.showColor ? "Denizen debugger is now showing color."
: "Denizen debugger color has been disabled."));
Messaging.sendInfo(sender, (Debug.showColor ? "Denizen debugger will now show color."
: "Denizen debugger will no longer show color."));
}
if (args.hasFlag('o')) {
if (!Debug.showDebug) {
Debug.toggle();
}
CoreConfiguration.debugOverride = !CoreConfiguration.debugOverride;
Messaging.sendInfo(sender, (CoreConfiguration.debugOverride ? "Denizen debugger is now overriding 'debug: false'."
: "Denizen debugger override has been disabled."));
: "Denizen debugger will no longer override 'debug: false'."));
}
if (args.hasFlag('b')) {
if (!Debug.showDebug) {
Expand All @@ -178,23 +178,23 @@ public void debug(CommandContext args, CommandSender sender) throws CommandExcep
}
CoreConfiguration.debugExtraInfo = !CoreConfiguration.debugExtraInfo;
Messaging.sendInfo(sender, (CoreConfiguration.debugExtraInfo ? "Denizen debugger is now showing extra internal information." :
"Denizen debugger extra-info disabled."));
"Denizen debugger is no longer showing extra internal information."));
}
if (args.hasFlag('v')) {
if (!Debug.showDebug) {
Debug.toggle();
}
CoreConfiguration.debugVerbose = !CoreConfiguration.debugVerbose;
Messaging.sendInfo(sender, (CoreConfiguration.debugVerbose ? "Denizen debugger is now verbose." :
"Denizen debugger verbosity disabled."));
"Denizen debugger is no longer verbose."));
}
if (args.hasFlag('f')) {
if (!Debug.showDebug) {
Debug.toggle();
}
CoreConfiguration.futureWarningsEnabled = !CoreConfiguration.futureWarningsEnabled;
Messaging.sendInfo(sender, (CoreConfiguration.futureWarningsEnabled ? "Denizen debugger is now showing future warnings." :
"Denizen debugger future-warnings disabled."));
"Denizen debugger will no longer show future warnings."));
}
if (args.hasFlag('n')) {
if (!Debug.showDebug) {
Expand Down Expand Up @@ -242,7 +242,7 @@ public void debug(CommandContext args, CommandSender sender) throws CommandExcep
}
if (args.getFlags().isEmpty()) {
Debug.toggle();
Messaging.sendInfo(sender, "Denizen debugger is now: " + (Debug.showDebug ? "<a>ENABLED" : "<c>DISABLED"));
Messaging.sendInfo(sender, "Denizen debugger is now: " + (Debug.showDebug ? "<a>ENABLED" : "<c>DISABLED") + "<f>.");
}

}
Expand All @@ -252,7 +252,7 @@ public void debug(CommandContext args, CommandSender sender) throws CommandExcep
*/
@Command(
aliases = {"denizen"}, usage = "do_nothing",
desc = "Does nothing, for better server command handling", modifiers = {"do_nothing"},
desc = "Does nothing, for better server command handling.", modifiers = {"do_nothing"},
min = 1, max = 3, permission = "denizen.basic")
public void do_nothing(CommandContext args, CommandSender sender) throws CommandException {
// Do nothing
Expand All @@ -266,11 +266,11 @@ public void do_nothing(CommandContext args, CommandSender sender) throws Command
desc = "Shows the currently loaded version of Denizen.", modifiers = {"version"},
min = 1, max = 3, permission = "denizen.basic")
public void version(CommandContext args, CommandSender sender) throws CommandException {
Messaging.sendInfo(sender, "<2>DENIZEN<7>: scriptable Minecraft!"); // TODO: "It's Scriptable!"?
Messaging.sendInfo(sender, "<2>DENIZEN<7>: A high-power scripting engine for Spigot!");
Messaging.send(sender, "");
Messaging.send(sender, "<7>by: <f>the DenizenScript team, with help from many skilled contributors!");
Messaging.send(sender, "<7>chat with us at: <f> https://discord.gg/Q6pZGSR");
Messaging.send(sender, "<7>or learn more at: <f> https://denizenscript.com");
Messaging.send(sender, "<7>chat with us at: <f>https://discord.gg/Q6pZGSR");
Messaging.send(sender, "<7>or learn more at: <f>https://denizenscript.com");
Messaging.send(sender, "<7>version: <f>" + Denizen.versionTag + "<7>, core version: <f>" + DenizenCore.VERSION);
}

Expand All @@ -284,7 +284,7 @@ public void version(CommandContext args, CommandSender sender) throws CommandExc
public void save(CommandContext args, CommandSender sender) throws CommandException {
DenizenCore.saveAll();
Denizen.getInstance().saveSaves(false);
Messaging.send(sender, "Denizen save data saved to disk from memory.");
Messaging.send(sender, "Denizen save data saved to file from memory.");
}

/*
Expand Down Expand Up @@ -337,7 +337,7 @@ else if (args.getString(1).equalsIgnoreCase("scripts")) {
Messaging.send(sender, "<f>Specify which parts to reload. Valid options are: SAVES, NOTES, CONFIG, SCRIPTS");
Messaging.send(sender, "<b>Example: /denizen reload saves");
Messaging.send(sender, "<f>Use '-a' to reload all parts at once.");
Messaging.send(sender, "<f>Note that you shouldn't use this command generally, instead use '/ex reload' - see also the Beginner's Guide @ https://guide.denizenscript.com/");
Messaging.send(sender, "<f>Note that you shouldn't use this command generally, instead use '/ex reload' - see also the Beginner's Guide at https://guide.denizenscript.com/");
Messaging.send(sender, "");
}

Expand All @@ -346,7 +346,7 @@ else if (args.getString(1).equalsIgnoreCase("scripts")) {
*/
@Command(
aliases = {"denizen"}, usage = "scripts (--type assignment|task|...) (--filter string)",
desc = "Lists currently loaded dScripts.", modifiers = {"scripts"},
desc = "Lists the currently loaded scripts.", modifiers = {"scripts"},
min = 1, max = 4, permission = "denizen.basic")
public void scripts(CommandContext args, CommandSender sender) throws CommandException {
String type = null;
Expand Down Expand Up @@ -384,7 +384,7 @@ else if (filter != null) {
}
}
if (!paginator.sendPage(sender, args.getInteger(1, 1))) {
throw new CommandException("The page " + args.getInteger(1, 1) + " does not exist.");
throw new CommandException("The page " + args.getInteger(1, 1) + " does not exist!");
}
}
}
Expand Up @@ -82,12 +82,11 @@ else if (args.hasValueFlag("delay") && !args.hasFlag('t')) {
trait.setReturnable(true);
Messaging.sendInfo(sender, npc.getName() + " will return after '" + args.getFlag("delay") + "' seconds"
+ (trait.isPushable() ? "." : ", but is currently not pushable."));
return;
}
else {
Messaging.sendError(sender, "Delay must be a valid number of seconds!");
return;
}
return;
}
else if (args.hasFlag('t') && !args.hasValueFlag("delay") && !args.hasFlag('r')) {
trait.toggle();
Expand All @@ -110,7 +109,7 @@ else if (args.hasFlag('t')) {
else if (args.length() > 2) {
Messaging.send(sender, "");
Messaging.send(sender, "<f>Use '-t' to toggle pushable state. <b>Example: /npc pushable -t");
Messaging.send(sender, "<f>To have the NPC return when pushed, use '-r'.");
Messaging.send(sender, "<f>To have the NPC return to their position when pushed, use '-r'.");
Messaging.send(sender, "<f>Change the return delay with '--delay #'.");
Messaging.send(sender, "");
}
Expand Down Expand Up @@ -161,7 +160,7 @@ public void constants(CommandContext args, CommandSender sender, NPC npc) throws
}
else if (args.hasValueFlag("remove")) {
trait.removeConstant(args.getFlag("remove"));
Messaging.sendInfo(sender, npc.getName() + " has removed constant '" + args.getFlag("remove") + "'.");
Messaging.sendInfo(sender, "Removed constant '" + args.getFlag("remove") + "' from " + npc.getName() + "<f>.");
return;
}
Messaging.send(sender, "");
Expand Down Expand Up @@ -243,7 +242,7 @@ else if (args.hasValueFlag("remove")) {
}
}
else {
Messaging.sendError(sender, "That NPC was already not assigned that script.");
Messaging.sendError(sender, npc.getName() + "<f> was already not assigned to " + script + ".");
}
return;
}
Expand Down Expand Up @@ -277,7 +276,7 @@ public void trigger(CommandContext args, CommandSender sender, NPC npc) throws C
Messaging.sendError(sender, "'" + triggerName.toUpperCase() + "' trigger does not exist.");
Messaging.send(sender, "<f>Usage: /npc trigger [trigger_name] [(--cooldown #)|(--radius #)|(-t)]");
Messaging.send(sender, "");
Messaging.send(sender, "<f>Use '--name trigger_name' to specify a specific trigger, and '-t' to toggle.");
Messaging.send(sender, "<f>Use '--name trigger_name' to specify the trigger, and '-t' to toggle it.");
Messaging.send(sender, "<b>Example: /npc trigger --name damage -t");
Messaging.send(sender, "<f>You may also use '--cooldown #' to specify a new cooldown time, and '--radius #' to specify a specific radius, when applicable.");
Messaging.send(sender, "");
Expand All @@ -294,7 +293,7 @@ public void trigger(CommandContext args, CommandSender sender, NPC npc) throws C
// If specifying radius
if (args.hasValueFlag("radius")) {
trait.setLocalRadius(triggerName, args.getFlagInteger("radius"));
Messaging.sendInfo(sender, triggerName.toUpperCase() + " trigger radius now " + args.getFlag("radius") + ".");
Messaging.sendInfo(sender, triggerName.toUpperCase() + " trigger radius is now " + args.getFlag("radius") + ".");
}
// Show current status of the trigger
Messaging.sendInfo(sender, triggerName.toUpperCase() + " trigger " + (trait.isEnabled(triggerName) ? "is" : "is not") + " currently enabled" +
Expand All @@ -318,7 +317,7 @@ public void nickname(CommandContext args, CommandSender sender, NPC npc) throws
NicknameTrait trait = npc.getOrAddTrait(NicknameTrait.class);
if (args.hasValueFlag("set")) {
trait.setNickname(args.getFlag("set"));
Messaging.send(sender, "Nickname set.");
Messaging.send(sender, "Nickname set to '" + args.getFlag("set") + "'.");
return;
}
else if (args.hasFlag('r')) {
Expand Down Expand Up @@ -367,7 +366,7 @@ else if (args.hasValueFlag("anchor")) {
return;
}
}
Messaging.sendError(sender, "The NPC does not have the specified anchor!");
Messaging.sendError(sender, "NPC " + npc.getName() + "<f> does not have the anchor '" + args.getFlag("anchor") + "'!");
return;
}
Location targetLocation;
Expand Down Expand Up @@ -483,7 +482,7 @@ else if (args.hasValueFlag("anchor")) {
return;
}
}
Messaging.sendError(sender, "The NPC does not have the specified anchor!");
Messaging.sendError(sender, "NPC " + npc.getName() + "<f> does not have the anchor '" + args.getFlag("anchor") + "'!");
return;
}
else {
Expand Down Expand Up @@ -525,11 +524,12 @@ public void startFishing(CommandContext args, CommandSender sender, NPC npc) thr
}
if (args.hasValueFlag("percent")) {
trait.setCatchPercent(args.getFlagInteger("percent"));
Messaging.send(sender, npc.getName() + " will now catch " + args.getFlagInteger("percent") + "% of the fish.");
}
if (args.hasValueFlag("reel_time")) {
DurationTag duration = DurationTag.valueOf(args.getFlag("reel_time"), CoreUtilities.basicContext);
if (duration == null) {
Messaging.sendError(sender, "Invalid reel duration.");
Messaging.sendError(sender, "Invalid reel duration!");
return;
}
trait.reelTickRate = duration.getTicksAsInt();
Expand All @@ -538,14 +538,16 @@ public void startFishing(CommandContext args, CommandSender sender, NPC npc) thr
if (args.hasValueFlag("cast_time")) {
DurationTag duration = DurationTag.valueOf(args.getFlag("cast_time"), CoreUtilities.basicContext);
if (duration == null) {
Messaging.sendError(sender, "Invalid cast duration.");
Messaging.sendError(sender, "Invalid cast duration!");
return;
}
trait.reelTickRate = duration.getTicksAsInt();
Messaging.send(sender, "Set cast rate to " + duration.formatted(true));
Messaging.send(sender, "Set cast rate to " + duration.formatted(true) + ".");
}
if (args.hasFlag('c')) {
trait.startFishing(args.getSenderTargetBlockLocation());
Messaging.send(sender, npc.getName() + " is now fishing at your cursor.");
return;
}
else if (args.hasValueFlag("location")) {
String[] argsArray = args.getFlag("location").split(",");
Expand All @@ -560,9 +562,14 @@ else if (args.hasValueFlag("anchor")) {
Anchors anchors = npc.getOrAddTrait(Anchors.class);
if (anchors.getAnchor(args.getFlag("anchor")) != null) {
trait.startFishing(anchors.getAnchor(args.getFlag("anchor")).getLocation());
} else {
Messaging.sendError(sender, "Anchor '" + args.getFlag("anchor") + "' is invalid! Did you make a typo?");
return;
}
} else {
Messaging.sendError(sender, "NPC " + npc.getName() + "<f> does not have the anchor '" + args.getFlag("anchor") + "'!");
return;
}
Messaging.sendError(sender, "The NPC does not have the specified anchor!");
}
else {
trait.startFishing();
Expand All @@ -579,7 +586,7 @@ public void stopFishing(CommandContext args, CommandSender sender, NPC npc) thro
FishingTrait trait = npc.getOrAddTrait(FishingTrait.class);
if (!trait.isFishing()) {
npc.removeTrait(FishingTrait.class);
Messaging.sendError(sender, npc.getName() + " isn't fishing!");
Messaging.sendError(sender, npc.getName() + " isn't currently fishing!");
return;
}
trait.stopFishing();
Expand Down

0 comments on commit a2cd344

Please sign in to comment.