Fix runCommands method

Note to future self, don't remove Util methods because someone might be
using them!
This commit is contained in:
tastybento 2023-02-12 08:22:22 -08:00
parent 5eaf54e905
commit 8276406f9f
2 changed files with 22 additions and 11 deletions

View File

@ -357,8 +357,8 @@ public class Util {
// Most of passive mobs extends Animals
return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
entity instanceof Allay;
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
entity instanceof Allay;
}
/*
@ -659,12 +659,23 @@ public class Util {
return null;
}
/**
* Run a list of commands for a user
* @param user - user affected by the commands
* @param commands - a list of commands
* @param commandType - the type of command being run - used in the console error message
*/
public static void runCommands(User user, @NonNull List<String> commands, String commandType) {
runCommands(user, user.getName(), commands, commandType);
}
/**
* Run a list of commands for a user
* @param user - user affected by the commands
* @param ownerName - name of the island owner, or the user's name if it is the user's island
* @param commands - a list of commands
* @param commandType - the type of command being run - used in the console error message
* @since 1.22.0
*/
public static void runCommands(User user, String ownerName, @NonNull List<String> commands, String commandType) {
commands.forEach(command -> {
@ -776,7 +787,7 @@ public class Util {
public static String sanitizeInput(String input)
{
return ChatColor.stripColor(
Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
toLowerCase();
Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
toLowerCase();
}
}

View File

@ -406,7 +406,7 @@ public class UtilTest {
when(user.getName()).thenReturn("tastybento");
when(user.isOnline()).thenReturn(true);
when(user.performCommand(anyString())).thenReturn(true);
Util.runCommands(user, "tasty", Collections.singletonList("[SUDO]help"), "test");
Util.runCommands(user, Collections.singletonList("[SUDO]help"), "test");
verify(plugin, never()).logError(anyString());
}
@ -418,7 +418,7 @@ public class UtilTest {
when(user.getName()).thenReturn("tastybento");
when(user.isOnline()).thenReturn(true);
when(user.performCommand(anyString())).thenReturn(false);
Util.runCommands(user, "tasty", Collections.singletonList("[SUDO]help"), "test");
Util.runCommands(user, Collections.singletonList("[SUDO]help"), "test");
verify(plugin).logError(eq("Could not execute test command for tastybento: help"));
}
@ -430,7 +430,7 @@ public class UtilTest {
when(user.getName()).thenReturn("tastybento");
when(user.isOnline()).thenReturn(false);
when(user.performCommand(anyString())).thenReturn(true);
Util.runCommands(user, "tasty", Collections.singletonList("[SUDO]help"), "test");
Util.runCommands(user, Collections.singletonList("[SUDO]help"), "test");
verify(plugin).logError(eq("Could not execute test command for tastybento: help"));
}
@ -441,13 +441,13 @@ public class UtilTest {
public void testRunCommandsConsoleCommand() {
when(user.getName()).thenReturn("tastybento");
when(Bukkit.dispatchCommand(eq(sender), anyString())).thenReturn(true);
Util.runCommands(user, "tasty", List.of("replace [player]", "replace owner [owner]", "[owner] [player]"), "test");
Util.runCommands(user, List.of("replace [player]", "replace owner [owner]", "[owner] [player]"), "test");
PowerMockito.verifyStatic(Bukkit.class);
Bukkit.dispatchCommand(sender, "replace tastybento");
PowerMockito.verifyStatic(Bukkit.class);
Bukkit.dispatchCommand(sender, "replace owner tasty");
Bukkit.dispatchCommand(sender, "replace owner tastybento");
PowerMockito.verifyStatic(Bukkit.class);
Bukkit.dispatchCommand(sender, "tasty tastybento");
Bukkit.dispatchCommand(sender, "tastybento tastybento");
verify(plugin, never()).logError(anyString());
}
@ -458,7 +458,7 @@ public class UtilTest {
public void testRunCommandsConsoleCommandFail() {
when(user.getName()).thenReturn("tastybento");
when(Bukkit.dispatchCommand(eq(sender), anyString())).thenReturn(false);
Util.runCommands(user, "", Collections.singletonList("replace [player]"), "test");
Util.runCommands(user, Collections.singletonList("replace [player]"), "test");
PowerMockito.verifyStatic(Bukkit.class);
Bukkit.dispatchCommand(sender, "replace tastybento");
verify(plugin).logError("Could not execute test command as console: replace tastybento");