org.bukkit.event.player.PlayerCommandPreprocessEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerCommandPreprocessEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldCancelFastCommandEvent() {
    // given
    given(settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)).willReturn(false);
    given(settings.getProperty(RestrictionSettings.ALLOW_COMMANDS)).willReturn(newHashSet("/spawn", "/help"));
    Player player = playerWithMockedServer();
    PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
    given(quickCommandsProtectionManager.isAllowed(player.getName())).willReturn(false);

    // when
    listener.onPlayerCommandPreprocess(event);

    // then
    verify(event).setCancelled(true);
    verify(player).kickPlayer(messages.retrieveSingle(player, MessageKey.QUICK_COMMAND_PROTECTION_KICK));
}
 
Example #2
Source File: CommandUseEvent.java    From WildernessTp with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onCmd(PlayerCommandPreprocessEvent e) {
    String command = e.getMessage().toLowerCase();
    List<String> blockedCmds = wild.getConfig().getStringList("BlockCommands");
    if (TeleportTarget.cmdUsed.contains(e.getPlayer().getUniqueId())) {
        for (String cmd : blockedCmds) {
            if (command.contains(cmd)) {
                e.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', wild.getConfig().getString("Blocked_Command_Message")));
                e.setCancelled(true);
                break;
            }
        }
    }
    if (e.getMessage().equalsIgnoreCase("/wild") && wild.getConfig().getBoolean("FBasics") && (wild.usageMode != UsageMode.COMMAND_ONLY && wild.usageMode != UsageMode.BOTH)) {
        e.setCancelled(true);
        CheckPerms check = new CheckPerms(wild);
        Checks checks = new Checks(wild);
        Player p = e.getPlayer();
        if (!checks.world(p))
            p.sendMessage(ChatColor.translateAlternateColorCodes('&', wild.getConfig().getString("WorldMsg")));
        else
            check.check(p,p.getWorld().getName());
    }
}
 
Example #3
Source File: TellrawConvIO.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCommandAnswer(PlayerCommandPreprocessEvent event) {
    if (!event.getPlayer().equals(player))
        return;
    if (!event.getMessage().toLowerCase().startsWith("/betonquestanswer "))
        return;
    event.setCancelled(true);
    String[] parts = event.getMessage().split(" ");
    if (parts.length != 2)
        return;
    String hash = parts[1];
    for (int j = 1; j <= hashes.size(); j++) {
        if (hashes.get(j).equals(hash)) {
            conv.sendMessage(answerFormat + options.get(j));
            conv.passPlayerAnswer(j);
            return;
        }
    }
}
 
Example #4
Source File: CommandCatch.java    From Survival-Games with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
    String m = event.getMessage();

    if(!GameManager.getInstance().isPlayerActive(event.getPlayer()) && !GameManager.getInstance().isPlayerInactive(event.getPlayer()) && !GameManager.getInstance().isSpectator(event.getPlayer()))
        return;
    if(m.equalsIgnoreCase("/list")){
        event.getPlayer().sendMessage(
        		GameManager.getInstance().getStringList(
        				GameManager.getInstance().getPlayerGameId(event.getPlayer())));
        return;
    }
    if(!SettingsManager.getInstance().getConfig().getBoolean("disallow-commands"))
        return;
    if(event.getPlayer().isOp() || event.getPlayer().hasPermission("sg.staff.nocmdblock"))
        return;
    else if(m.startsWith("/sg") || m.startsWith("/survivalgames")|| m.startsWith("/hg")||m.startsWith("/hungergames")||m.startsWith("/msg")){
        return;
    }
    else if (SettingsManager.getInstance().getConfig().getStringList("cmdwhitelist").contains(m)) {
    	return;
    }
    event.setCancelled(true);
}
 
Example #5
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents teleporting when falling based on setting by stopping commands
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerCommandPreprocessEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getPlayer()) || Settings.allowTeleportWhenFalling || e.getPlayer().isOp()
            || !e.getPlayer().getGameMode().equals(GameMode.SURVIVAL)
            || plugin.getPlayers().isInTeleport(e.getPlayer().getUniqueId())) {
        return;
    }
    // Check commands
    // plugin.getLogger().info("DEBUG: falling command: '" +
    // e.getMessage().substring(1).toLowerCase() + "'");
    if (isFalling(e.getPlayer().getUniqueId()) && (Settings.fallingCommandBlockList.contains("*") || Settings.fallingCommandBlockList.contains(e.getMessage().substring(1).toLowerCase()))) {
        // Sorry you are going to die
        Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).errorNoPermission);
        Util.sendMessage(e.getPlayer(), plugin.myLocale(e.getPlayer().getUniqueId()).islandcannotTeleport);
        e.setCancelled(true);
    }
}
 
Example #6
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents visitors from using commands on islands, like /spawner
 * @param e - event
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onVisitorCommand(final PlayerCommandPreprocessEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("Visitor command " + e.getEventName() + ": " + e.getMessage());
    }
    if (!IslandGuard.inWorld(e.getPlayer()) || e.getPlayer().isOp()
            || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())) {
        //plugin.getLogger().info("player is not in world or op etc.");
        return;
    }
    // Check banned commands
    //plugin.getLogger().info(Settings.visitorCommandBlockList.toString());
    String[] args = e.getMessage().substring(1).toLowerCase().split(" ");
    if (Settings.visitorCommandBlockList.contains(args[0])) {
        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
        e.setCancelled(true);
    }
}
 
Example #7
Source File: ChunkEventHelper.java    From ClaimChunk with MIT License 6 votes vote down vote up
public static void handleCommandEvent(@Nonnull Player ply, @Nonnull Chunk chunk, @Nonnull PlayerCommandPreprocessEvent e) {
    if (e.isCancelled()) return;

    // If the user is an admin, they can run any command.
    if (Utils.hasAdmin(ply)) return;

    // If the user has permission to edit within this chunk, they can use
    // any command they have permissions to use.
    if (getCanEdit(chunk, ply.getUniqueId())) return;

    // Get the command from the message.
    final String[] cmdAndArgs = e.getMessage()
            .trim()
            .substring(1)
            .split(" ", 1);

    // Length should never be >1 but it could be 0.
    if (cmdAndArgs.length == 1) {
        // Cancel the event if the blocked commands list contains this
        // command.
        if (config.getList("protection", "blockedCmds").contains(cmdAndArgs[0])) e.setCancelled(true);
    }
}
 
Example #8
Source File: DeathListener.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
    Player player = event.getPlayer();
    Location location = player.getLocation();
    Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId());

    long jailTime = ConfigManager.getInstance().getJailTime();
    if (civilian.getLastJail() + jailTime < System.currentTimeMillis()) {
        return;
    }
    long timeRemaining = civilian.getLastJail() + jailTime - System.currentTimeMillis();

    Region region = RegionManager.getInstance().getRegionAt(location);
    if (region == null || !region.getEffects().containsKey("jail")) {
        return;
    }
    event.setCancelled(true);
    player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player,
            "no-commands-in-jail").replace("$1", (int) (timeRemaining / 1000) + "s"));
}
 
Example #9
Source File: CommandListener.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
  FileConfiguration spigot = YamlConfiguration.loadConfiguration(new File(Bukkit.getServer().getWorldContainer(), "spigot.yml"));
  if (event.getMessage().equalsIgnoreCase("/reload") && event.getPlayer().hasPermission("bukkit.command.reload")) {
    // Restarts server if server is set up for it.
    if (spigot.getBoolean("settings.restart-on-crash")) {
      Bukkit.getLogger().severe("[Carbon] Restarting server due to reload command!");
      Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "restart");
    } else {
      // Call to server shutdown on disable.
      // Won't hurt if server already disables itself, but will prevent plugin unload/reload.
      Bukkit.getLogger().severe("[Carbon] Stopping server due to reload command!");
      Bukkit.shutdown();
    }
  }
  }
 
Example #10
Source File: EssentialsHook.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCommand(final PlayerCommandPreprocessEvent e) {
    if (!CommandAction.VANISH_SELF.checkPermission(e.getPlayer(), superVanish)) return;
    if (superVanish.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) return;
    String command = e.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "")
            .toLowerCase(Locale.ENGLISH);
    if (command.split(":").length > 1) command = command.split(":")[1];
    if (command.equals("supervanish") || command.equals("sv")
            || command.equals("v") || command.equals("vanish")) {
        final User user = essentials.getUser(e.getPlayer());
        if (user == null || !user.isAfk()) return;
        user.setHidden(true);
        preVanishHiddenPlayers.add(e.getPlayer().getUniqueId());
        superVanish.getServer().getScheduler().runTaskLater(superVanish, new Runnable() {
            @Override
            public void run() {
                if (preVanishHiddenPlayers.remove(e.getPlayer().getUniqueId())) {
                    user.setHidden(false);
                }
            }
        }, 1);
    }
}
 
Example #11
Source File: CMListener.java    From ChatMenuAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onCommandPreprocess(PlayerCommandPreprocessEvent e)
{
	String cmd = e.getMessage().substring(1);
	if(cmd.length() <= 0) return;
	String[] unprocessedArgs = cmd.split(" ");
	
	String label = unprocessedArgs[0];
	String[] args = new String[unprocessedArgs.length - 1];
	System.arraycopy(unprocessedArgs, 1, args, 0, args.length);
	
	if(label.equalsIgnoreCase("cmapi"))
	{
		e.setCancelled(true);
		command.onCommand(e.getPlayer(), null, label, args);
	}
}
 
Example #12
Source File: CommandListener.java    From ChestCommands with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCommand(PlayerCommandPreprocessEvent event) {

	if (ChestCommands.getSettings().use_only_commands_without_args && event.getMessage().contains(" ")) {
		return;
	}

	// Very fast method compared to split & substring
	String command = StringUtils.getCleanCommand(event.getMessage());

	if (command.isEmpty()) {
		return;
	}

	ExtendedIconMenu menu = ChestCommands.getCommandToMenuMap().get(command);

	if (menu != null) {
		event.setCancelled(true);

		if (event.getPlayer().hasPermission(menu.getPermission())) {
			menu.open(event.getPlayer());
		} else {
			menu.sendNoPermissionMessage(event.getPlayer());
		}
	}
}
 
Example #13
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldCancelCommandEvent() {
    // given
    given(settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)).willReturn(false);
    given(settings.getProperty(RestrictionSettings.ALLOW_COMMANDS)).willReturn(newHashSet("/spawn", "/help"));
    Player player = playerWithMockedServer();
    PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
    given(listenerService.shouldCancelEvent(player)).willReturn(true);
    given(quickCommandsProtectionManager.isAllowed(player.getName())).willReturn(true);

    // when
    listener.onPlayerCommandPreprocess(event);

    // then
    verify(listenerService).shouldCancelEvent(player);
    verify(event).setCancelled(true);
    verify(messages).send(player, MessageKey.DENIED_COMMAND);
}
 
Example #14
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldNotCancelEventForAuthenticatedPlayer() {
    // given
    given(settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)).willReturn(false);
    given(settings.getProperty(RestrictionSettings.ALLOW_COMMANDS)).willReturn(Collections.emptySet());
    Player player = playerWithMockedServer();
    // PlayerCommandPreprocessEvent#getPlayer is final, so create a spy instead of a mock
    PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
    given(listenerService.shouldCancelEvent(player)).willReturn(false);
    given(quickCommandsProtectionManager.isAllowed(player.getName())).willReturn(true);

    // when
    listener.onPlayerCommandPreprocess(event);

    // then
    verify(event).getMessage();
    verifyNoMoreInteractions(event);
    verify(listenerService).shouldCancelEvent(player);
    verifyNoInteractions(messages);
}
 
Example #15
Source File: CommandEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCommandMonitor(PlayerCommandPreprocessEvent event) {
    String message = event.getMessage();
    String arguments = "";
    String command = "";
    if (!message.contains(" ")) {
        command = message.replace("/", "");
    } else {
        command = message.substring(0, message.indexOf(" ")).replace("/", "");
        arguments = message.substring(message.indexOf(" ") + 1, message.length());
    }
    if (command.equalsIgnoreCase("datapack") && (arguments.contains("enable") || arguments.contains("disable"))) {
        if (GriefDefenderPlugin.getInstance().getTagProvider() != null) {
            GriefDefenderPlugin.getInstance().getTagProvider().refresh();
        }
    }
}
 
Example #16
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String cmd = event.getMessage().split(" ")[0].toLowerCase();
    if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && "/motd".equals(cmd)) {
        return;
    }
    if (settings.getProperty(RestrictionSettings.ALLOW_COMMANDS).contains(cmd)) {
        return;
    }
    final Player player = event.getPlayer();
    if (!quickCommandsProtectionManager.isAllowed(player.getName())) {
        event.setCancelled(true);
        player.kickPlayer(messages.retrieveSingle(player, MessageKey.QUICK_COMMAND_PROTECTION_KICK));
        return;
    }
    if (listenerService.shouldCancelEvent(player)) {
        event.setCancelled(true);
        messages.send(player, MessageKey.DENIED_COMMAND);
    }
}
 
Example #17
Source File: InteractListener.java    From TradePlus with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInteract(PlayerInteractAtEntityEvent event) {
  if (event.getRightClicked() instanceof Player) {
    Long last = lastTrigger.get(event.getPlayer().getUniqueId());
    if (last != null && System.currentTimeMillis() < last + 5000L) return;
    Player player = event.getPlayer();
    Player interacted = (Player) event.getRightClicked();
    String action = pl.getConfig().getString("action", "").toLowerCase();
    if ((action.contains("sneak") || action.contains("crouch") || action.contains("shift"))
        && !player.isSneaking()) return;
    if (action.contains("right")) {
      event.setCancelled(true);
      Bukkit.getPluginManager()
          .callEvent(
              new PlayerCommandPreprocessEvent(
                  event.getPlayer(), "/trade " + interacted.getName()));
      lastTrigger.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
    }
  }
}
 
Example #18
Source File: InteractListener.java    From TradePlus with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onDamage(EntityDamageByEntityEvent event) {
  if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
    Long last = lastTrigger.get(event.getEntity().getUniqueId());
    if (last != null && System.currentTimeMillis() < last + 5000L) return;
    Player player = (Player) event.getDamager();
    Player interacted = (Player) event.getEntity();
    String action = pl.getConfig().getString("action", "").toLowerCase();
    if ((action.contains("sneak") || action.contains("crouch") || action.contains("shift"))
        && !player.isSneaking()) return;
    if (action.contains("left")) {
      event.setCancelled(true);
      Bukkit.getPluginManager()
          .callEvent(
              new PlayerCommandPreprocessEvent(
                  (Player) event.getDamager(), "/trade " + interacted.getName()));
      lastTrigger.put(event.getDamager().getUniqueId(), System.currentTimeMillis());
    }
  }
}
 
Example #19
Source File: CustomCommand.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void beforeCommand(PlayerCommandPreprocessEvent e) {
    Player player = e.getPlayer();
    String message = e.getMessage();
    String[] split = message.split(" ");

    String commandName = split[0];
    if(commandName.startsWith("/")) commandName = commandName.substring(1);
    if(commandName.equals(this.getName()) || this.getAliases().contains(commandName)) {
        e.setCancelled(true);

        String[] args = split.length > 1 ? Arrays.copyOfRange(split, 1, split.length) : new String[0];
        execute(player, commandName, args);
    }
}
 
Example #20
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onCommand(PlayerCommandPreprocessEvent pcpe) {
  Player player = pcpe.getPlayer();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() == GameState.STOPPED) {
    return;
  }

  String message = pcpe.getMessage();
  if (!message.startsWith("/bw")) {

    for (String allowed : BedwarsRel.getInstance().getAllowedCommands()) {
      if (!allowed.startsWith("/")) {
        allowed = "/" + allowed;
      }

      if (message.startsWith(allowed.trim())) {
        return;
      }
    }

    if (player.hasPermission("bw.cmd")) {
      return;
    }

    pcpe.setCancelled(true);
    return;
  }
}
 
Example #21
Source File: CommandInterceptorTest.java    From mcspring-boot with MIT License 5 votes vote down vote up
@Test
public void shouldDelegatePlayerCommandToExecutorWithContext() {
    PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, "/say hello", new HashSet<>());
    commandInterceptor.onPlayerCommand(event);

    assertTrue(event.isCancelled());
    verify(commandExecutor).execute("say", "hello");
    verify(player).sendMessage("message1");
    verify(player).sendMessage("message2");
}
 
Example #22
Source File: ListenerCommandBlocker.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
public void beforeCommand(PlayerCommandPreprocessEvent e) {
    Player player = e.getPlayer();
    ICombatManager combatManager = this.plugin.getCombatManager();
    if(!combatManager.isInCombat(player) && !isInCooldown(player)) return;

    String command = e.getMessage();
    String actualCommand = convertCommand(command);
    if(!isBlocked(actualCommand) || isAllowed(actualCommand)) return;

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.command-blocked").replace("{command}", actualCommand);
    this.plugin.sendMessage(player, message);
}
 
Example #23
Source File: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerCommand(final PlayerCommandPreprocessEvent event) {
    Player p = event.getPlayer();
    String cmd = event.getMessage().split(" ")[0].toLowerCase();
    while(cmd.length() > 0 && cmd.charAt(0) == '/') {
        cmd = cmd.substring(1);
    }
    if(cmd.length() > 0 && Config.deniedCommands.contains(cmd) && Utils.hasAnyTools(p)) {
        event.setCancelled(true);
        p.sendMessage(ChatColor.RED + Config.cmdNotAllowed);
    }
}
 
Example #24
Source File: CommandsPerformedListener.java    From Statz with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPerformCommand(final PlayerCommandPreprocessEvent event) {

	final PlayerStat stat = PlayerStat.COMMANDS_PERFORMED;

	// Get player
	final Player player = event.getPlayer();

	// Do general check
	if (!plugin.doGeneralCheck(player, stat))
		return;
	
	String message = event.getMessage();
	
	int subString = message.indexOf(" ");

	String command = "";
	String arguments = "";

	if (subString > 0) {
		command = message.substring(0, subString).trim();
		arguments = message.substring(subString).trim();

		// Cut off string so it's not too long
		if (arguments.length() > 100) {
			arguments = arguments.substring(0, 99);
		}
	} else {
		command = message.trim();
	}

	PlayerStatSpecification specification = new CommandsPerformedSpecification(player.getUniqueId(), 1,
			player.getWorld().getName(), command, arguments);

	// Update value to new stat.
	plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());

}
 
Example #25
Source File: PlayerCommand.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event) {
    Player player = event.getPlayer();
    if (player.hasPermission("funnyguilds.admin")) {
        return;
    }

    String[] splited = event.getMessage().split("\\s+");
    if (splited.length == 0) {
        return;
    }
    String command = splited[0];
    for (String s : FunnyGuilds.getInstance().getPluginConfiguration().regionCommands) {
        if (("/" + s).equalsIgnoreCase(command)) {
            command = null;
            break;
        }
    }
    if (command != null) {
        return;
    }

    Region region = RegionUtils.getAt(player.getLocation());
    if (region == null) {
        return;
    }

    Guild guild = region.getGuild();
    User user = User.get(player);
    if (guild.getMembers().contains(user)) {
        return;
    }

    event.setCancelled(true);
    player.sendMessage(FunnyGuilds.getInstance().getMessageConfiguration().regionCommand);
}
 
Example #26
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldNotStopAllowedCommand() {
    // given
    given(settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.ALLOW_COMMANDS)).willReturn(newHashSet("/plugins", "/mail", "/msg"));
    PlayerCommandPreprocessEvent event = mockCommandEvent("/Mail send test Test");

    // when
    listener.onPlayerCommandPreprocess(event);

    // then
    verify(event, only()).getMessage();
    verifyNoInteractions(listenerService, messages);
}
 
Example #27
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldAllowEssentialsMotd() {
    // given
    given(settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)).willReturn(true);
    PlayerCommandPreprocessEvent event = mockCommandEvent("/MOTD");

    // when
    listener.onPlayerCommandPreprocess(event);

    // then
    verify(event, only()).getMessage();
    verifyNoInteractions(listenerService, messages);
}
 
Example #28
Source File: ChatModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
    PermissionModule module = GameHandler.getGameHandler().getMatch().getModules().getModule(PermissionModule.class);
    if (!GameHandler.getGameHandler().getGlobalMute()) {
        if (module.isMuted(event.getPlayer()) && (event.getMessage().toLowerCase().startsWith("/me ") || event.getMessage().toLowerCase().startsWith("/minecraft:me "))) {
            event.getPlayer().sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.ERROR_NO_PERMISSION).getMessage(event.getPlayer().getLocale()));
            event.setCancelled(true);
        }
    } else {
        if (event.getMessage().toLowerCase().startsWith("/me ") || event.getMessage().toLowerCase().startsWith("/minecraft:me ")) {
            event.getPlayer().sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.ERROR_NO_PERMISSION).getMessage(event.getPlayer().getLocale()));
            event.setCancelled(true);
        }
    }
}
 
Example #29
Source File: WildCard.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    if (event.getPlayer().hasPermission("cardinal.wildcard")) {
        String command = event.getMessage() + " ";
        if (command.contains(" * ")) {
            event.setCancelled(true);
            for (Player player : Bukkit.getOnlinePlayers()) {
                Bukkit.dispatchCommand(event.getPlayer(), command.substring(1).replaceAll(" \\* ", " " + player.getName() + " ").trim());
            }
        }
    }
}
 
Example #30
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event) {
    if (event.getMessage().equalsIgnoreCase("/reload") || event.getMessage().equalsIgnoreCase("reload")) {
        event.setCancelled(true);
        event.getPlayer().sendMessage("PlotMe disabled /reload to prevent errors from occuring.");
    }
}