Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Addition of Command Usages #114

Open
wants to merge 12 commits into
base: v6
Choose a base branch
from
4 changes: 4 additions & 0 deletions AdvancedTeleport-Bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ tasks {
}
}

tasks.shadowJar {
from(tasks.slimJar.get().outputDirectory)
}

// Lead development use only.
modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.niestrat99.advancedteleport.config.CustomMessages;
import io.github.niestrat99.advancedteleport.managers.CommandManager;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -39,9 +40,15 @@ public boolean onCommand(
}
if (sender.hasPermission("at.member.core." + command)
|| sender.hasPermission("at.admin.core." + command)) {
CommandManager.subcommands
boolean correctUse = CommandManager.subcommands
.get(command)
.onCommand(sender, cmd, s, Arrays.copyOfRange(args, 1, args.length));

if (!correctUse) {
CustomMessages.sendMessage(sender, "Error.commandUse",
Placeholder.unparsed("usage", CustomMessages.asString("Usages.Subcommands." + command)));
}

} else {
CustomMessages.sendMessage(sender, "Error.noPermission");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean onCommand(
CoreClass.getInstance(), () -> RTPManager.loadWorldData(world));
CustomMessages.sendMessage(
sender, "Info.clearWorld", Placeholder.unparsed("world", args[0]));
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean onCommand(
// If there's no arguments contained, stop there
if (args.length == 0) {
CustomMessages.sendMessage(sender, "Error.noPluginSpecified");
return true;
return false;
}

// Attempt to get the plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean onCommand(
@NotNull final String[] args) {
if (args.length == 0) {
CustomMessages.sendMessage(sender, "Error.noPluginSpecified");
return true;
return false;
}

final var pluginHook = getImportExportPlugin(sender, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.github.niestrat99.advancedteleport.commands.SubATCommand;
import io.github.niestrat99.advancedteleport.commands.core.map.*;
import io.github.niestrat99.advancedteleport.config.CustomMessages;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -43,24 +45,30 @@ public boolean onCommand(
// If there's no arguments, stop there
if (args.length == 0) {
Bukkit.dispatchCommand(sender, "at help map");
return false;
return true;
}

// Get the subcommand in question
SubATCommand subATCommand = subMapCommands.get(args[0].toLowerCase());
if (subATCommand == null) {
Bukkit.dispatchCommand(sender, "at help map");
return false;
return true;
}

// Check permissions
if (!sender.hasPermission("at.member.core.map." + args[0].toLowerCase())) {
Bukkit.dispatchCommand(sender, "at help map");
return false;
return true;
}

// Execute
return subATCommand.onCommand(sender, command, s, Arrays.copyOfRange(args, 1, args.length));
boolean result = subATCommand.onCommand(sender, command, s, Arrays.copyOfRange(args, 1, args.length));

if (!result) {
CustomMessages.sendMessage(sender, "Error.commandUse",
Placeholder.unparsed("usage", CustomMessages.asString("Usages.Subcommands.map." + args[0].toLowerCase())));
}
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean onCommand(
if (data == null) data = "default";
String type = args[0];
if (!types.contains(type)) {
return false;
return true;
}
MainConfig.get().set("waiting-particles." + type, data);
CustomMessages.sendMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean onCommand(
CoreClass.sync);
}

return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public boolean onCommand(
@NotNull final Command command,
@NotNull final String s,
@NotNull final String[] args) {
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean onCommand(
// If not enough arguments are specified, let the player know
if (args.length < 3) {
CustomMessages.sendMessage(sender, "Error.notEnoughArgs");
return true;
return false;
}

// Squish together the input
Expand All @@ -66,7 +66,7 @@ public boolean onCommand(
case "home" -> {
if (args.length < 4) {
CustomMessages.sendMessage(sender, "Error.notEnoughArgs");
return true;
return false;
}

input = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public boolean onCommand(
&& atPlayer instanceof ATFloodgatePlayer atFloodgatePlayer
&& MainConfig.get().USE_FLOODGATE_FORMS.get()) {
atFloodgatePlayer.sendDeleteHomeForm();
} else CustomMessages.sendMessage(sender, "Error.noHomeInput");
} else {
CustomMessages.sendMessage(sender, "Error.noHomeInput");
return false;
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendMoveHomeForm();
} else {
CustomMessages.sendMessage(sender, "Error.noHomeInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendSetHomeForm();
} else {
CustomMessages.sendMessage(sender, "Error.noHomeInput");
return false;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendSetMainHomeForm();
} else {
CustomMessages.sendMessage(sender, "Error.noHomeInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public boolean onCommand(
// If no argument has been specified, stop there
if (args.length == 0) {
CustomMessages.sendMessage(sender, "Error.mirrorSpawnNoArguments");
return true;
return false;
}

// If just one spawn has been specified, then use the first argument as the spawn to mirror
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean onCommand(
removingSpawn = player.getWorld().getName();
} else {
CustomMessages.sendMessage(sender, "Error.removeSpawnNoArgs");
return true;
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendBlockForm();
} else {
CustomMessages.sendMessage(sender, "Error.noPlayerInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean onCommand(

if (args.length == 0) {
CustomMessages.sendMessage(sender, "Error.noPlayerInput");
return true;
return false;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public boolean onCommand(
if (!canProceed(sender)) return true;
if (args.length == 0) {
CustomMessages.sendMessage(sender, "Error.noPlayerInput");
return true;
return false;
}
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendUnblockForm();
} else {
CustomMessages.sendMessage(sender, "Error.noPlayerInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendTPAForm(false);
} else {
CustomMessages.sendMessage(sender, "Error.noPlayerInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendTPAForm(true);
} else {
CustomMessages.sendMessage(sender, "Error.noPlayerInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendTpoForm();
} else {
CustomMessages.sendMessage(sender, "Error.noPlayerInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendTpoHereForm();
} else {
CustomMessages.sendMessage(sender, "Error.noPlayerInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean onCommand(

// Otherwise, tell the player to enter a warp.
CustomMessages.sendMessage(sender, "Error.noWarpInput");
return true;
return false;
}

// Get the warp to be deleted.
Expand All @@ -58,6 +58,7 @@ public boolean onCommand(
Placeholder.unparsed("warp", args[0])));
} else {
CustomMessages.sendMessage(sender, "Error.noWarpInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendMoveWarpForm();
} else {
CustomMessages.sendMessage(sender, "Error.noWarpInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendSetWarpForm();
} else {
CustomMessages.sendMessage(sender, "Error.noWarpInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public boolean onCommand(
((ATFloodgatePlayer) atPlayer).sendWarpForm();
} else {
CustomMessages.sendMessage(sender, "Error.noWarpInput");
return false;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ If you prefer to use the Legacy Code format (i.e. &a, &b, etc.) then you can sti
"Error.randomLocFailed",
"<prefix> <gray>Sorry, we couldn't find a location to teleport you to :(");

addDefault("Error.commandUse", "<aqua>Usage: <gray><usage>");
addDefault("Error.rtpManagerNotUsed", "<prefix> <gray>The RTP-Cache is not being used on the server.");

makeSectionLenient("Info");
addDefault("Info.tpOff", "<prefix> <gray>Successfully disabled teleport requests!");
addDefault("Info.tpOn", "<prefix> <gray>Successfully enabled teleport requests!");
Expand Down Expand Up @@ -598,6 +601,9 @@ If you prefer to use the Legacy Code format (i.e. &a, &b, etc.) then you can sti
"Info.mirrorSpawnSame",
"<prefix> <gray>The spawns for <aqua><from></aqua> and <aqua><spawn></aqua> already to go the same place! Don't worry :)");

addDefault("Info.clearEverything", "<prefix> <gray>The RTP-Cache has been cleared.");
addDefault("Info.clearWorld", "<prefix> <gray>Cache for world <aqua><world></aqua> has been cleared.");

addDefault("Tooltip.homes", "<prefix> <gray>Teleports you to your home: <aqua><home>");
addDefault("Tooltip.warps", "<prefix> <gray>Teleports you to warp: <aqua><warp>");
addDefault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
import io.github.niestrat99.advancedteleport.commands.spawn.*;
import io.github.niestrat99.advancedteleport.commands.teleport.*;
import io.github.niestrat99.advancedteleport.commands.warp.*;
import io.github.niestrat99.advancedteleport.config.CustomMessages;
import io.github.niestrat99.advancedteleport.config.MainConfig;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.command.*;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -162,7 +161,15 @@ private static void register(String name, ATCommand atCommand) {
}

if (command.getExecutor() != atCommand) {
command.setExecutor(atCommand);
CommandExecutor usageExecutor = (sender, cmd, label, args) -> {
boolean result = atCommand.onCommand(sender, cmd, label, args);
if (!result) {
CustomMessages.sendMessage(sender, "Error.commandUse",
Placeholder.unparsed("usage", CustomMessages.asString("Usages." + name)));
}
return true;
};
command.setExecutor(usageExecutor);
command.setTabCompleter(atCommand);
}

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Advanced Teleport is a rapidly growing plugin that is not only increasing sharpl
## Installation/Cloning
As of currently, Advanced Teleport uses Gradle to manage its dependencies.

The Gradle command used to build the plugin is `gradle shadowJar` and is done under the AdvancedTeleport-Bukkit module.
The Gradle command used to build the plugin is `gradle slimJar` and is done under the AdvancedTeleport-Bukkit module.

> NOTE: Due to a bug with SlimJar you should try building twice when updating dependencies or building for the first time, or necessary files will not be installed.


Loading