. + improve build system
This commit is contained in:
parent
00eb51595d
commit
e09ae6cc18
10 changed files with 117 additions and 107 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package de.kentoj.kencommandapi;
|
||||
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.processing.ParsedArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.impl.AbstractKenCommandApi;
|
||||
|
|
@ -20,6 +21,12 @@ public class BukkitKenCommandApi extends AbstractKenCommandApi<CommandSender, Bu
|
|||
return new BukkitCommandContext(sender, parsedArguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendErrorMessage(CommandSender sender, CommandException ex) {
|
||||
var cause = (ex.getCause() != null) ? ": " + ex.getCause().getMessage() : "";
|
||||
sender.sendMessage("§c" + ex.getMessage() + cause);
|
||||
}
|
||||
|
||||
public void register(CommandNode<CommandSender, BukkitCommandContext> rootNode) {
|
||||
try {
|
||||
Field field = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.kencommandapi.type;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
||||
import lombok.AccessLevel;
|
||||
|
|
@ -22,15 +22,15 @@ public class OfflinePlayerArgumentType implements ArgumentType<CommandSender, Bu
|
|||
|
||||
@Override
|
||||
public OfflinePlayer parseInput(String string) {
|
||||
OfflinePlayer player = Bukkit.getPlayer(string);
|
||||
OfflinePlayer player = Bukkit.getPlayerExact(string);
|
||||
if (player == null) {
|
||||
try {
|
||||
player = Bukkit.getOfflinePlayer(UUID.fromString(string));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw new RuntimeException("Not a UUID or online player -- " + string);
|
||||
throw new CommandException("Not a UUID or online player -- " + string);
|
||||
}
|
||||
}
|
||||
if (!player.hasPlayedBefore()) throw new RuntimeException("Unknown player -- " + string);
|
||||
if (!player.hasPlayedBefore() && !player.isOnline()) throw new CommandException("Unknown player -- " + string);
|
||||
return player;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package de.kentoj.kencommandapi.type;
|
|||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.ArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.SuggestionProvider;
|
||||
import lombok.AccessLevel;
|
||||
|
|
@ -22,7 +23,7 @@ public class PlayerArgumentType implements ArgumentType<CommandSender, BukkitCom
|
|||
@Override
|
||||
public Player parseInput(String string) {
|
||||
var player = Bukkit.getPlayer(string);
|
||||
if (player == null) throw new RuntimeException("Player not online -- " + string);
|
||||
if (player == null) throw new CommandException("Player not online -- " + string);
|
||||
return player;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue