mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-10 12:59:45 +01:00
Fixes the logic and adds a bunch of tests to prove the logic works.
This commit is contained in:
parent
d6d86d39d2
commit
bcb4ed28b8
@ -57,20 +57,19 @@ public class BannedCommands implements Listener {
|
||||
}
|
||||
|
||||
private boolean checkCmd(String cmd, String[] args) {
|
||||
// Commands are guilty until proven innocent :-)
|
||||
boolean banned = true;
|
||||
// Get the elements of the banned command by splitting it
|
||||
String[] bannedSplit = cmd.toLowerCase(java.util.Locale.ENGLISH).split(" ");
|
||||
// If the banned command has the same number of elements or less than the entered command then it may be banned
|
||||
if (bannedSplit.length <= args.length) {
|
||||
if (bannedSplit.length <= args.length) {
|
||||
for (int i = 0; i < bannedSplit.length; i++) {
|
||||
if (!bannedSplit[i].equals(args[i])) {
|
||||
banned = false;
|
||||
break;
|
||||
if (!bannedSplit[i].equalsIgnoreCase(args[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return banned;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,6 +262,106 @@ public class BannedCommandsTest {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||
*/
|
||||
@Test
|
||||
public void testBannedCommandsWithBannedCommand2() {
|
||||
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/spawn");
|
||||
BannedCommands bvc = new BannedCommands(plugin);
|
||||
List<String> banned = new ArrayList<>();
|
||||
banned.add("cmi sethome");
|
||||
when(iwm.getVisitorBannedCommands(any())).thenReturn(banned);
|
||||
bvc.onVisitorCommand(e);
|
||||
verify(iwm).getVisitorBannedCommands(any());
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||
*/
|
||||
@Test
|
||||
public void testBannedCommandsWithBannedCommand3() {
|
||||
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/cmi sethome");
|
||||
BannedCommands bvc = new BannedCommands(plugin);
|
||||
List<String> banned = new ArrayList<>();
|
||||
banned.add("cmi sethome");
|
||||
when(iwm.getVisitorBannedCommands(any())).thenReturn(banned);
|
||||
bvc.onVisitorCommand(e);
|
||||
verify(iwm).getVisitorBannedCommands(any());
|
||||
assertTrue(e.isCancelled());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||
*/
|
||||
@Test
|
||||
public void testBannedCommandsWithBannedComman4() {
|
||||
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/cmi");
|
||||
BannedCommands bvc = new BannedCommands(plugin);
|
||||
List<String> banned = new ArrayList<>();
|
||||
banned.add("cmi sethome");
|
||||
when(iwm.getVisitorBannedCommands(any())).thenReturn(banned);
|
||||
bvc.onVisitorCommand(e);
|
||||
verify(iwm).getVisitorBannedCommands(any());
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||
*/
|
||||
@Test
|
||||
public void testBannedCommandsWithBannedCommand5() {
|
||||
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/cmi homey");
|
||||
BannedCommands bvc = new BannedCommands(plugin);
|
||||
List<String> banned = new ArrayList<>();
|
||||
banned.add("cmi sethome");
|
||||
when(iwm.getVisitorBannedCommands(any())).thenReturn(banned);
|
||||
bvc.onVisitorCommand(e);
|
||||
verify(iwm).getVisitorBannedCommands(any());
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||
*/
|
||||
@Test
|
||||
public void testBannedCommandsWithBannedCommand6() {
|
||||
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/spawn");
|
||||
BannedCommands bvc = new BannedCommands(plugin);
|
||||
List<String> banned = new ArrayList<>();
|
||||
banned.add("cmi sethome");
|
||||
banned.add("spawn sethome now");
|
||||
when(iwm.getVisitorBannedCommands(any())).thenReturn(banned);
|
||||
bvc.onVisitorCommand(e);
|
||||
verify(iwm).getVisitorBannedCommands(any());
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||
*/
|
||||
@Test
|
||||
public void testBannedCommandsWithBannedCommand7() {
|
||||
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/spawn");
|
||||
BannedCommands bvc = new BannedCommands(plugin);
|
||||
List<String> banned = new ArrayList<>();
|
||||
banned.add("cmi sethome");
|
||||
banned.add("spawn sethome now");
|
||||
banned.add("cmi multi now");
|
||||
when(iwm.getVisitorBannedCommands(any())).thenReturn(banned);
|
||||
bvc.onVisitorCommand(e);
|
||||
verify(iwm).getVisitorBannedCommands(any());
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user