Fix command execution error output
This commit is contained in:
parent
791698adf9
commit
6c85283344
@ -48,7 +48,7 @@ public class MagnetCommandExecutor extends ConfigurableCommandExecutor<MagnetCon
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player))
|
||||
return false;
|
||||
return true;
|
||||
|
||||
final boolean isMagnetActive = toggleMagnet((Player) sender);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.w1zzrd.invtweaks.command;
|
||||
|
||||
import dev.w1zzrd.invtweaks.InvTweaksPlugin;
|
||||
import dev.w1zzrd.invtweaks.listener.TabCompletionListener;
|
||||
import dev.w1zzrd.invtweaks.serialization.SearchConfig;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.*;
|
||||
@ -17,6 +18,7 @@ import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static dev.w1zzrd.invtweaks.command.CommandUtils.assertTrue;
|
||||
import static dev.w1zzrd.invtweaks.listener.TabCompletionListener.*;
|
||||
|
||||
/**
|
||||
* Handler for executions of /search command
|
||||
@ -40,14 +42,11 @@ public class SearchCommandExecutor extends ConfigurableCommandExecutor<SearchCon
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
final NamespacedKey target;
|
||||
final Material targetMaterial;
|
||||
if (assertTrue(sender instanceof Player, ERR_NOT_PLAYER, sender) ||
|
||||
assertTrue(args.length == 1, ERR_NO_ARG, sender) ||
|
||||
assertTrue((target = NamespacedKey.fromString(args[0])) != null, String.format(ERR_UNKNOWN, args[0]), sender)
|
||||
) return false;
|
||||
|
||||
assert target != null;
|
||||
final Material targetMaterial = Arrays.stream(Material.values()).filter(it -> it.getKey().toString().equals(args[0])).findFirst().orElse(null);
|
||||
assertTrue((targetMaterial = getMaterialMatching(args[0])) != null, String.format(ERR_UNKNOWN, args[0]), sender)
|
||||
) return true;
|
||||
|
||||
assert targetMaterial != null;
|
||||
assert sender instanceof Player;
|
||||
@ -64,7 +63,7 @@ public class SearchCommandExecutor extends ConfigurableCommandExecutor<SearchCon
|
||||
|
||||
// Ensure we found inventory-holding blocks
|
||||
if (assertTrue(matches.size() != 0, ERR_NO_INVENTORIES, sender))
|
||||
return false;
|
||||
return true;
|
||||
|
||||
final InventoryHolder result;
|
||||
|
||||
@ -97,7 +96,7 @@ public class SearchCommandExecutor extends ConfigurableCommandExecutor<SearchCon
|
||||
}
|
||||
}
|
||||
assertTrue(false, "Could not find inventory with target item/block", sender);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (result instanceof DoubleChest) {
|
||||
@ -175,4 +174,9 @@ public class SearchCommandExecutor extends ConfigurableCommandExecutor<SearchCon
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
private static Material materialFromKey(final NamespacedKey key) {
|
||||
final String stringKey = key.toString();
|
||||
return Arrays.stream(Material.values()).filter(it -> it.getKey().toString().equals(stringKey)).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import static dev.w1zzrd.invtweaks.InvTweaksPlugin.LOG_PLUGIN_NAME;
|
||||
import static org.bukkit.Material.*;
|
||||
import static dev.w1zzrd.invtweaks.command.CommandUtils.*;
|
||||
|
||||
/**
|
||||
* Handler for executions of /sort command
|
||||
@ -32,12 +33,10 @@ public class SortCommandExecutor implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
// Since we rely on targeting an inventory either by what we're looking at or by whom it was called,
|
||||
// there is an implicit dependency on that the command is called by (at the very least) an entity
|
||||
if (!(sender instanceof Player)) {
|
||||
logger.info(LOG_PLUGIN_NAME + " Sort command triggered by non-player");
|
||||
sender.sendMessage("Command must be run by a player");
|
||||
return false;
|
||||
}
|
||||
if (assertTrue(sender instanceof Player, "Command must be run by a player", sender))
|
||||
return true;
|
||||
|
||||
assert sender instanceof Player;
|
||||
final Player player = (Player) sender;
|
||||
|
||||
logger.fine(LOG_PLUGIN_NAME + " Sort triggered by player " + player.getName());
|
||||
|
Loading…
x
Reference in New Issue
Block a user