mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-30 15:47:33 +02:00
parent
999ca242d7
commit
1b81e74f4c
@ -36,19 +36,42 @@ public class BannedCommands implements Listener {
|
|||||||
public void onVisitorCommand(PlayerCommandPreprocessEvent e) {
|
public void onVisitorCommand(PlayerCommandPreprocessEvent e) {
|
||||||
if (!plugin.getIWM().inWorld(e.getPlayer().getLocation()) || e.getPlayer().isOp()
|
if (!plugin.getIWM().inWorld(e.getPlayer().getLocation()) || e.getPlayer().isOp()
|
||||||
|| e.getPlayer().hasPermission(plugin.getIWM().getPermissionPrefix(e.getPlayer().getWorld()) + "mod.bypassprotect")
|
|| e.getPlayer().hasPermission(plugin.getIWM().getPermissionPrefix(e.getPlayer().getWorld()) + "mod.bypassprotect")
|
||||||
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())) {
|
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())
|
||||||
|
|| e.getMessage().isEmpty()
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
World w = e.getPlayer().getWorld();
|
World w = e.getPlayer().getWorld();
|
||||||
// Check banned commands
|
// Check banned commands
|
||||||
|
// Split up the entry
|
||||||
String[] args = e.getMessage().substring(1).toLowerCase(java.util.Locale.ENGLISH).split(" ");
|
String[] args = e.getMessage().substring(1).toLowerCase(java.util.Locale.ENGLISH).split(" ");
|
||||||
if (plugin.getIWM().getVisitorBannedCommands(w).contains(args[0])) {
|
// Loop through each of the banned commands
|
||||||
User user = User.getInstance(e.getPlayer());
|
for (String cmd : plugin.getIWM().getVisitorBannedCommands(w)) {
|
||||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation("protection.command-is-banned"));
|
if (checkCmd(cmd, args)) {
|
||||||
e.setCancelled(true);
|
User user = User.getInstance(e.getPlayer());
|
||||||
|
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation("protection.command-is-banned"));
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
for (int i = 0; i < bannedSplit.length; i++) {
|
||||||
|
if (!bannedSplit[i].equals(args[i])) {
|
||||||
|
banned = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return banned;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevents falling players from using commands, like /warp
|
* Prevents falling players from using commands, like /warp
|
||||||
* @param e - event
|
* @param e - event
|
||||||
|
@ -245,6 +245,35 @@ public class BannedCommandsTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testBannedCommandsWithBannedCommandWithExtraBannedStuff() {
|
||||||
|
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/banned_command with extra stuff");
|
||||||
|
BannedCommands bvc = new BannedCommands(plugin);
|
||||||
|
List<String> banned = new ArrayList<>();
|
||||||
|
banned.add("banned_command with extra stuff");
|
||||||
|
banned.add("another_banned_command");
|
||||||
|
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 testBannedCommandsWithNothing() {
|
||||||
|
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "");
|
||||||
|
BannedCommands bvc = new BannedCommands(plugin);
|
||||||
|
bvc.onVisitorCommand(e);
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user