Now with a fall distance check!

https://github.com/BentoBoxWorld/BentoBox/issues/863
This commit is contained in:
tastybento 2019-10-03 13:42:40 -07:00
parent 42ba6dcc50
commit 215c79d74d
2 changed files with 23 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.listeners;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -37,10 +38,12 @@ public class BannedCommands implements Listener {
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())) {
return;
}
World w = e.getPlayer().getWorld();
// Check banned commands
String[] args = e.getMessage().substring(1).toLowerCase(java.util.Locale.ENGLISH).split(" ");
if (plugin.getIWM().getVisitorBannedCommands(e.getPlayer().getWorld()).contains(args[0])
|| plugin.getIWM().getFallingBannedCommands(e.getPlayer().getWorld()).contains(args[0])) {
if (plugin.getIWM().getVisitorBannedCommands(w).contains(args[0])
|| (plugin.getIWM().getFallingBannedCommands(w).contains(args[0])
&& e.getPlayer().getFallDistance() > 0)) {
User user = User.getInstance(e.getPlayer());
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation("protection.command-is-banned"));
e.setCancelled(true);

View File

@ -246,6 +246,7 @@ public class BannedCommandsTest {
*/
@Test
public void testBannedCommandsWithBannedFallingCommand() {
when(player.getFallDistance()).thenReturn(10F);
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/banned_command");
BannedCommands bvc = new BannedCommands(plugin);
List<String> banned = new ArrayList<>();
@ -253,9 +254,25 @@ public class BannedCommandsTest {
banned.add("another_banned_command");
when(iwm.getFallingBannedCommands(any())).thenReturn(banned);
bvc.onCommand(e);
verify(iwm).getVisitorBannedCommands(any());
assertTrue(e.isCancelled());
}
/**
* Test for {@link BannedCommands#onCommand(PlayerCommandPreprocessEvent)}
*/
@Test
public void testBannedCommandsWithBannedFallingCommandNotFalling() {
when(player.getFallDistance()).thenReturn(0F);
PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent(player, "/banned_command");
BannedCommands bvc = new BannedCommands(plugin);
List<String> banned = new ArrayList<>();
banned.add("banned_command");
banned.add("another_banned_command");
when(iwm.getFallingBannedCommands(any())).thenReturn(banned);
bvc.onCommand(e);
assertFalse(e.isCancelled());
}
}