Skip to content

Commit 8276406

Browse files
committed
Fix runCommands method
Note to future self, don't remove Util methods because someone might be using them!
1 parent 5eaf54e commit 8276406

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/main/java/world/bentobox/bentobox/util/Util.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ public static boolean isPassiveEntity(Entity entity) {
357357
// Most of passive mobs extends Animals
358358

359359
return entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman ||
360-
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
361-
entity instanceof Allay;
360+
entity instanceof WaterMob && !(entity instanceof PufferFish) || entity instanceof Bat ||
361+
entity instanceof Allay;
362362
}
363363

364364
/*
@@ -659,12 +659,23 @@ public static UUID getUUID(@NonNull String nameOrUUID) {
659659
return null;
660660
}
661661

662+
/**
663+
* Run a list of commands for a user
664+
* @param user - user affected by the commands
665+
* @param commands - a list of commands
666+
* @param commandType - the type of command being run - used in the console error message
667+
*/
668+
public static void runCommands(User user, @NonNull List<String> commands, String commandType) {
669+
runCommands(user, user.getName(), commands, commandType);
670+
}
671+
662672
/**
663673
* Run a list of commands for a user
664674
* @param user - user affected by the commands
665675
* @param ownerName - name of the island owner, or the user's name if it is the user's island
666676
* @param commands - a list of commands
667677
* @param commandType - the type of command being run - used in the console error message
678+
* @since 1.22.0
668679
*/
669680
public static void runCommands(User user, String ownerName, @NonNull List<String> commands, String commandType) {
670681
commands.forEach(command -> {
@@ -776,7 +787,7 @@ public static int broadcast(String localeKey, String... variables) {
776787
public static String sanitizeInput(String input)
777788
{
778789
return ChatColor.stripColor(
779-
Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
780-
toLowerCase();
790+
Util.translateColorCodes(input.replaceAll("[\\\\/:*?\"<>|\s]", "_"))).
791+
toLowerCase();
781792
}
782793
}

src/test/java/world/bentobox/bentobox/util/UtilTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public void testRunCommandsSudoUserOnlinePerformCommand() {
406406
when(user.getName()).thenReturn("tastybento");
407407
when(user.isOnline()).thenReturn(true);
408408
when(user.performCommand(anyString())).thenReturn(true);
409-
Util.runCommands(user, "tasty", Collections.singletonList("[SUDO]help"), "test");
409+
Util.runCommands(user, Collections.singletonList("[SUDO]help"), "test");
410410
verify(plugin, never()).logError(anyString());
411411
}
412412

@@ -418,7 +418,7 @@ public void testRunCommandsSudoUserOnlineFailCommand() {
418418
when(user.getName()).thenReturn("tastybento");
419419
when(user.isOnline()).thenReturn(true);
420420
when(user.performCommand(anyString())).thenReturn(false);
421-
Util.runCommands(user, "tasty", Collections.singletonList("[SUDO]help"), "test");
421+
Util.runCommands(user, Collections.singletonList("[SUDO]help"), "test");
422422
verify(plugin).logError(eq("Could not execute test command for tastybento: help"));
423423
}
424424

@@ -430,7 +430,7 @@ public void testRunCommandsSudoUserOfflineCommand() {
430430
when(user.getName()).thenReturn("tastybento");
431431
when(user.isOnline()).thenReturn(false);
432432
when(user.performCommand(anyString())).thenReturn(true);
433-
Util.runCommands(user, "tasty", Collections.singletonList("[SUDO]help"), "test");
433+
Util.runCommands(user, Collections.singletonList("[SUDO]help"), "test");
434434
verify(plugin).logError(eq("Could not execute test command for tastybento: help"));
435435
}
436436

@@ -441,13 +441,13 @@ public void testRunCommandsSudoUserOfflineCommand() {
441441
public void testRunCommandsConsoleCommand() {
442442
when(user.getName()).thenReturn("tastybento");
443443
when(Bukkit.dispatchCommand(eq(sender), anyString())).thenReturn(true);
444-
Util.runCommands(user, "tasty", List.of("replace [player]", "replace owner [owner]", "[owner] [player]"), "test");
444+
Util.runCommands(user, List.of("replace [player]", "replace owner [owner]", "[owner] [player]"), "test");
445445
PowerMockito.verifyStatic(Bukkit.class);
446446
Bukkit.dispatchCommand(sender, "replace tastybento");
447447
PowerMockito.verifyStatic(Bukkit.class);
448-
Bukkit.dispatchCommand(sender, "replace owner tasty");
448+
Bukkit.dispatchCommand(sender, "replace owner tastybento");
449449
PowerMockito.verifyStatic(Bukkit.class);
450-
Bukkit.dispatchCommand(sender, "tasty tastybento");
450+
Bukkit.dispatchCommand(sender, "tastybento tastybento");
451451
verify(plugin, never()).logError(anyString());
452452
}
453453

@@ -458,7 +458,7 @@ public void testRunCommandsConsoleCommand() {
458458
public void testRunCommandsConsoleCommandFail() {
459459
when(user.getName()).thenReturn("tastybento");
460460
when(Bukkit.dispatchCommand(eq(sender), anyString())).thenReturn(false);
461-
Util.runCommands(user, "", Collections.singletonList("replace [player]"), "test");
461+
Util.runCommands(user, Collections.singletonList("replace [player]"), "test");
462462
PowerMockito.verifyStatic(Bukkit.class);
463463
Bukkit.dispatchCommand(sender, "replace tastybento");
464464
verify(plugin).logError("Could not execute test command as console: replace tastybento");

0 commit comments

Comments
 (0)