Java Code Examples for org.bukkit.event.player.PlayerCommandPreprocessEvent#isCancelled()

The following examples show how to use org.bukkit.event.player.PlayerCommandPreprocessEvent#isCancelled() . 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: 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 2
Source File: CommandInterceptor.java    From mcspring-boot with MIT License 5 votes vote down vote up
@EventHandler
void onPlayerCommand(PlayerCommandPreprocessEvent event) {
    if (event.isCancelled() || commandService.isRegistered()) return;
    val player = context.getPlayer();
    val result = commandExecutor.execute(event.getMessage().substring(1).split(" "));
    event.setCancelled(result.isExists());
    result.getOutput().forEach(player::sendMessage);
}
 
Example 3
Source File: BukkitChatListener.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Auto command listener
 */
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
	if (!event.isCancelled()) {
		String result = super.onPlayerCommandPreprocess(new BukkitUser(plugin, event.getPlayer()), event.getMessage());
		if (result != null) {
			event.setMessage(result);
		}
	}
}
 
Example 4
Source File: DefaultUIHandler.java    From SubServers-2 with Apache License 2.0 5 votes vote down vote up
/**
 * Input Listener
 *
 * @param event Event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void input(PlayerCommandPreprocessEvent event) {
    if (!event.isCancelled() && enabled && input.keySet().contains(event.getPlayer().getUniqueId())) {
        YAMLSection data = new YAMLSection();
        data.set("message", (event.getMessage().startsWith("/"))?event.getMessage().substring(1):event.getMessage());
        input.get(event.getPlayer().getUniqueId()).run(data);
        input.remove(event.getPlayer().getUniqueId());
        event.setCancelled(true);
    }
}
 
Example 5
Source File: DPlayerListener.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    Player player = event.getPlayer();
    if (isCitizensNPC(player)) {
        return;
    }

    if (DPermission.hasPermission(player, DPermission.BYPASS)) {
        return;
    }

    if (!(dPlayers.get(player) instanceof DInstancePlayer)) {
        return;
    }
    InstancePlayer dPlayer = dPlayers.getInstancePlayer(player);

    String command = event.getMessage().toLowerCase();
    ArrayList<String> commandWhitelist = new ArrayList<>();

    if (dPlayer instanceof DEditPlayer) {
        if (DPermission.hasPermission(player, DPermission.CMD_EDIT)) {
            return;

        } else {
            commandWhitelist.addAll(config.getEditCommandWhitelist());
        }

    } else {
        commandWhitelist.addAll(dPlayer.getGroup().getDungeon().getRules().getState(GameRule.GAME_COMMAND_WHITELIST));
    }

    commandWhitelist.add("dungeonsxl");
    commandWhitelist.add("dungeon");
    commandWhitelist.add("dxl");

    event.setCancelled(true);

    for (String whitelistEntry : commandWhitelist) {
        if (command.equals('/' + whitelistEntry.toLowerCase()) || command.startsWith('/' + whitelistEntry.toLowerCase() + ' ')) {
            event.setCancelled(false);
        }
    }

    if (event.isCancelled()) {
        MessageUtil.sendMessage(player, DMessage.ERROR_CMD.getMessage());
    }
}