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

The following examples show how to use org.bukkit.event.player.AsyncPlayerChatEvent#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: SentinelEventHandler.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Called when players chat, to process event message targets.
 */
@EventHandler
public void onAsyncPlayerChat(final AsyncPlayerChatEvent event) {
    if (event.isCancelled()) {
        return;
    }
    Bukkit.getScheduler().scheduleSyncDelayedTask(SentinelPlugin.instance, new Runnable() {
        @Override
        public void run() {
            if (!event.getPlayer().isOnline()) {
                return;
            }
            for (SentinelTrait sentinel : cleanCurrentList()) {
                if (sentinel.allTargets.isEventTarget(sentinel, event)) {
                    sentinel.targetingHelper.addTarget(event.getPlayer().getUniqueId());
                }
                if (sentinel.allAvoids.isEventTarget(sentinel, event)) {
                    sentinel.targetingHelper.addAvoid(event.getPlayer().getUniqueId());
                }
            }
        }
    });
}
 
Example 2
Source File: IndicatorListener.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
    if (!event.isCancelled()) {
        final Player p = event.getPlayer();
        if (!HoloAPI.getVanishProvider().isVanished(p)) {
            final String msg = event.getMessage();
            if (event.isAsynchronous()) {
                HoloAPI.getCore().getServer().getScheduler().scheduleSyncDelayedTask(HoloAPI.getCore(), new BukkitRunnable() {
                    @Override
                    public void run() {
                        showChatHologram(p, msg);
                    }
                });
            } else {
                this.showChatHologram(p, msg);
            }
        }
    }
}
 
Example 3
Source File: ChatListener.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onChat(AsyncPlayerChatEvent e) {

    if (e.isCancelled() && plugin.getConfig().getBoolean("shop.ignore-cancel-chat-event")) {
        Util.debugLog("Ignored a chat event (Canceled by another plugin.)");
        return;
    }

    if (!plugin.getShopManager().getActions().containsKey(e.getPlayer().getUniqueId())) {
        return;
    }
    // Fix stupid chat plugin will add a weird space before or after the number we want.
    plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage().trim());
    e.setCancelled(true);
}
 
Example 4
Source File: SilentNightListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.HIGH)
public void onPlayerChat(AsyncPlayerChatEvent e){
    if (nightMode && !e.isCancelled()){
        e.setCancelled(true);
        e.getPlayer().sendMessage(Lang.SCENARIO_SILENTNIGHT_ERROR);
    }
}
 
Example 5
Source File: PlayerChatListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH)
public void onPlayerChat(AsyncPlayerChatEvent e){
	Player player = e.getPlayer();
	GameManager gm = GameManager.getGameManager();
	MainConfiguration cfg = gm.getConfiguration();

	if (e.isCancelled()){
	    return;
       }

	UhcPlayer uhcPlayer = gm.getPlayersManager().getUhcPlayer(player);

	// Spec chat
       if(!cfg.getCanSendMessagesAfterDeath() && uhcPlayer.getState() == PlayerState.DEAD){
       	// check if has override permissions
		if (player.hasPermission("uhc-core.chat.override")) return;

		// Send message in spec chat.
		String message = Lang.DISPLAY_SPECTATOR_CHAT
				.replace("%player%", player.getDisplayName())
				.replace("%message%", e.getMessage());

		gm.getPlayersManager().getOnlineSpectatingPlayers().forEach(p -> p.sendMessage(message));
           e.setCancelled(true);
           return;
       }

       // Team chat
	if (
			uhcPlayer.getState() == PlayerState.PLAYING && isTeamMessage(cfg, e, uhcPlayer)
	){
		e.setCancelled(true);
		uhcPlayer.getTeam().sendChatMessageToTeamMembers(uhcPlayer, e.getMessage());
       }

}
 
Example 6
Source File: ChatListener.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(@Nonnull AsyncPlayerChatEvent event) {
    if (event.isCancelled()) return;
    Optional<User> user = userHandler.getUser(event.getPlayer().getUniqueId());

    user.ifPresent(u -> u.getActiveChannel().sendMessage(u, event.getMessage()));

    event.setCancelled(true);
}
 
Example 7
Source File: ChatListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onChat(AsyncPlayerChatEvent event) {
    if (event.isCancelled()) {
        return;
    }

    try {
        actOnChatEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example 8
Source File: PlayerListener.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChat(AsyncPlayerChatEvent event) {
	if (event.isCancelled() && !DiscordBotCore.getInstance().getConfiguration().isForceChat()) {
		return;
	}
	
	Player player = event.getPlayer();
	String permission = DiscordBotCore.getInstance().getConfiguration().getChannels().get("Global").getPermission();
	boolean hasPermission = false;
	
	if (permission == null || permission.trim().equals("") || permission.trim().equals("null")) {
		hasPermission = false;
	} else if (permission.equals("*") || player.hasPermission(permission)) {
		hasPermission = true;
	}
	
	if (!DiscordBotCore.getInstance().getConfiguration().isPlayerChat() || !hasPermission || DiscordBotCore.getInstance().getDatabaseManager().checkDatabase(player.getUniqueId())) {
		return;
	}
	
	Message message = new Message()
			.setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get("Global").getChannel())
			.setFormat(DiscordBotCore.getInstance().getConfiguration().getChannelFormat().get("Global"))
			.setName(player.getName())
			.setNick(player.getDisplayName())
			.setServer("Unknown")
			.setMessage(event.getMessage())
			.setDiscord(true)
			.setMinecraft(false)
			.setConsole(false)
			.setRedis(false);
	
	if (player.getServer() != null && player.getServer().getName() != null) {
		message.setServer(player.getServer().getName());
	}
	
	DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
	return;
}
 
Example 9
Source File: Main.java    From TelegramChat with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
	if (!this.getConfig().getBoolean("enable-chatmessages"))
		return;
	if (e.isCancelled())
		return;
	if (telegramHook.connected) {
		ChatMessageToTelegram chat = new ChatMessageToTelegram();
		chat.parse_mode = "Markdown";
		chat.text = Utils
				.escape(Utils.formatMSG("general-message-to-telegram", e.getPlayer().getName(), e.getMessage())[0])
				.replaceAll("ยง.", "");
		telegramHook.sendAll(chat);
	}
}