org.bukkit.event.player.AsyncPlayerChatEvent Java Examples

The following examples show how to use org.bukkit.event.player.AsyncPlayerChatEvent. 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: 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 onPlayerChat(AsyncPlayerChatEvent event) {
    if (settings.getProperty(RestrictionSettings.ALLOW_CHAT)) {
        return;
    }

    final Player player = event.getPlayer();
    final boolean mayPlayerSendChat = !listenerService.shouldCancelEvent(player)
        || permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_CHAT_BEFORE_LOGIN);
    if (mayPlayerSendChat) {
        removeUnauthorizedRecipients(event);
    } else {
        event.setCancelled(true);
        messages.send(player, MessageKey.DENIED_CHAT);
    }
}
 
Example #2
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldAllowChatForBypassPermission() {
    // given
    given(settings.getProperty(RestrictionSettings.ALLOW_CHAT)).willReturn(false);
    AsyncPlayerChatEvent event = newAsyncChatEvent();
    given(listenerService.shouldCancelEvent(event.getPlayer())).willReturn(true);
    given(permissionsManager.hasPermission(event.getPlayer(), PlayerStatePermission.ALLOW_CHAT_BEFORE_LOGIN)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.HIDE_CHAT)).willReturn(false);

    // when
    listener.onPlayerChat(event);

    // then
    assertThat(event.isCancelled(), equalTo(false));
    verify(listenerService).shouldCancelEvent(event.getPlayer());
    verify(permissionsManager).hasPermission(event.getPlayer(), PlayerStatePermission.ALLOW_CHAT_BEFORE_LOGIN);
    assertThat(event.getRecipients(), hasSize(3));
}
 
Example #3
Source File: CommandEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChatPost(AsyncPlayerChatEvent event) {
    final Player player = event.getPlayer();
    final Iterator<Player> iterator = event.getRecipients().iterator();

    while (iterator.hasNext()) {
        final Player receiver = iterator.next();
        if (receiver == player) {
            continue;
        }

        final GDPlayerData receiverData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(receiver.getWorld(), receiver.getUniqueId());
        if (receiverData.isRecordingChat()) {
            iterator.remove();
            final String s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
            final Component message = LegacyComponentSerializer.legacy().deserialize(s, '&');
            final Component component = TextComponent.builder()
                    .append(TextComponent.builder()
                            .append(message)
                            .hoverEvent(HoverEvent.showText(TextComponent.of(formatter.format(Instant.now()))))
                            .build())
                    .build();
            receiverData.chatLines.add(component);
        }
    }
}
 
Example #4
Source File: Catchers.java    From TabooLib with MIT License 6 votes vote down vote up
@EventHandler
public void chat(AsyncPlayerChatEvent e) {
    if (playerdata.containsKey(e.getPlayer().getName()) && contains(e.getPlayer())) {
        e.setCancelled(true);
        // 1.14 supported.
        TabooLib.getPlugin().runTask(() -> {
            Catcher catcher = playerdata.get(e.getPlayer().getName()).getFirst();
            // 退出
            if (e.getMessage().split(" ")[0].matches(catcher.quit())) {
                playerdata.get(e.getPlayer().getName()).removeFirst().cancel();
            }
            // 默认
            else {
                // 如果终止引导
                if (!catcher.after(e.getMessage())) {
                    playerdata.get(e.getPlayer().getName()).removeFirst();
                } else {
                    catcher.before();
                }
            }
        });
    }
}
 
Example #5
Source File: TestListener.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
	if(e.getMessage().contains(".meep")) {
		e.getPlayer().sendMessage("Meep!");
		for(Connection con : PocketCon.getPocketConnections()) {
			e.getPlayer().sendMessage("MEEEEEP!!");
			SimpleForm f = new SimpleForm("hoi", "hallo");
			f.clone();
			PocketCon.sendModal(con, 
				new SimpleForm("hoi", "hallo")
					.addButton(new ModalButton("Magbot").setImage(new ModalImage(ModalImageType.EXTERNAL_IMAGE, "http://magbot.nl/img/MagBot.png")))
					.addButton(new ModalButton("Awesome").setImage(new ModalImage(ModalImageType.EXTERNAL_IMAGE, "http://yumamom.com/wp-content/uploads/2015/05/LEGO.jpg"))), response -> {
						if (response.asSimpleFormResponse().getClickedButton() == 1) {
							response.getPlayer().sendMessage("You are awesome!");
						} else {
							response.getPlayer().sendMessage("You are not awesome! :(");
						}
					});
		}
	}
}
 
Example #6
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onTalk(AsyncPlayerChatEvent event){
	if(event.getPlayer().hasMetadata("recipeBuilder")){
		String step = event.getPlayer().getMetadata("recipeBuilder").get(0).asString();
		if(step.equalsIgnoreCase("choosePermission")){
			if(event.getMessage().equalsIgnoreCase("no")){
				event.setCancelled(true);
				openChoice(event.getPlayer());
				return;
			}
			event.getPlayer().setMetadata("recPermission", new FixedMetadataValue(ProRecipes.getPlugin(), ChatColor.stripColor(event.getMessage())));
			event.setCancelled(true);
			openChoice(event.getPlayer());
		}
	}
}
 
Example #7
Source File: ExprChatFormat.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) {
	if (delta == null){
		return;
	}
	String format = null;
	if (mode == Changer.ChangeMode.SET){
		String newFormat = (String) delta[0];
		if (newFormat == null){
			return;
		}
		format = convertToNormal(newFormat);
	}else if (mode == Changer.ChangeMode.RESET){
		format = "<%s> %s";
	}
	if (format == null){
		return;
	}
	((AsyncPlayerChatEvent) e).setFormat(format);
}
 
Example #8
Source File: NickNamerPlugin.java    From NickNamer with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void on(final AsyncPlayerChatEvent event) {
	if (ChatReplacementEvent.getHandlerList().getRegisteredListeners().length > 0) {
		final String message = event.getMessage();
		Set<String> nickedPlayerNames = NickNamerAPI.getNickedPlayerNames();
		String replacedMessage = NickNamerAPI.replaceNames(message, nickedPlayerNames, new NameReplacer() {
			@Override
			public String replace(String original) {
				Player player = Bukkit.getPlayer(original);
				if (player != null) {
					boolean async = !getServer().isPrimaryThread();
					NameReplacementEvent replacementEvent = new ChatReplacementEvent(player, event.getRecipients(), message, original, original, async);
					Bukkit.getPluginManager().callEvent(replacementEvent);
					if (replacementEvent.isCancelled()) { return original; }
					return replacementEvent.getReplacement();
				}
				return original;
			}
		}, true);
		event.setMessage(replacedMessage);
	}
}
 
Example #9
Source File: UCChannel.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Send a message from a channel as player.
 *
 * @param sender  {@code Player}
 * @param message {@code FancyMessage} - Message to send.
 * @param direct  {@code boolean} - Send message direct to players on channel.
 */
public void sendMessage(Player sender, UltimateFancy message, boolean direct) {
    if (direct) {
        for (Player p : Bukkit.getOnlinePlayers()) {
            UCChannel chp = UChat.get().getPlayerChannel(p);
            if (UCPerms.channelReadPerm(p, this) && !this.isIgnoring(p.getName()) && (!this.neeFocus() || chp.equals(this))) {
                UChat.get().getUCLogger().timings(timingType.START, "UCChannel#sendMessage()|Direct Message");
                message.send(p);
            }
        }
        message.send(sender);
    } else {
        Set<Player> pls = new HashSet<>(Bukkit.getOnlinePlayers());
        UChat.get().tempChannels.put(sender.getName(), this.getAlias());
        AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(true, sender, message.toOldFormat(), pls);
        Bukkit.getScheduler().runTaskAsynchronously(UChat.get(), () -> {
            UChat.get().getUCLogger().timings(timingType.START, "UCChannel#sendMessage()|Fire AsyncPlayerChatEvent");
            UChat.get().getServer().getPluginManager().callEvent(event);
        });
    }
}
 
Example #10
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 #11
Source File: MentionListener.java    From NyaaUtils with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void AsyncChatEvent(AsyncPlayerChatEvent e) {
    if (!plugin.cfg.mention_enable) return;
    Runnable r = () -> { // In case if we got an asynchronous event
        if (e.getMessage().contains("@")) {
            Player sender = e.getPlayer();
            String raw = e.getMessage();
            String rep = raw.replace("@ ", "@");
            Set<Player> playersNotified = Bukkit.getOnlinePlayers().parallelStream()
                                                .filter(p -> rep.contains("@" + p.getName()))
                                                .collect(Collectors.toSet());
            notify(sender, raw, playersNotified, plugin);
        }
    };
    if (e.isAsynchronous()) {
        Bukkit.getScheduler().runTask(plugin, r);
    } else {
        r.run();
    }
}
 
Example #12
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
{
	Player player = event.getPlayer();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	
	String prefix = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.CHAT_PREFIX);
	String suffix = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.CHAT_SUFFIX);

	if (prefix != null)
	{
		event.setFormat(prefix + event.getFormat());
	}
	
	if (suffix != null)
	{
		event.setFormat(event.getFormat() + suffix);
	}
}
 
Example #13
Source File: ChatModule.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
    event.setCancelled(true);
    switch (Settings.getSettingByName("ChatChannel").getValueByPlayer(event.getPlayer()).getValue()) {
        case "global":
            Bukkit.dispatchCommand(event.getPlayer(), "g " + event.getMessage());
            break;
        case "admin":
            Bukkit.dispatchCommand(event.getPlayer(), "a " + event.getMessage());
            break;
        case "team":
        default:
            Bukkit.dispatchCommand(event.getPlayer(), "t " + event.getMessage());
            break;
    }
}
 
Example #14
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldCancelChatForUnauthedPlayer() {
    // given
    given(settings.getProperty(RestrictionSettings.ALLOW_CHAT)).willReturn(false);
    AsyncPlayerChatEvent event = newAsyncChatEvent();
    given(listenerService.shouldCancelEvent(event.getPlayer())).willReturn(true);
    given(permissionsManager.hasPermission(event.getPlayer(), PlayerStatePermission.ALLOW_CHAT_BEFORE_LOGIN)).willReturn(false);

    // when
    listener.onPlayerChat(event);

    // then
    verify(listenerService).shouldCancelEvent(event.getPlayer());
    verify(permissionsManager).hasPermission(event.getPlayer(), PlayerStatePermission.ALLOW_CHAT_BEFORE_LOGIN);
    verify(event).setCancelled(true);
    verify(messages).send(event.getPlayer(), MessageKey.DENIED_CHAT);
}
 
Example #15
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 #16
Source File: VariableObjective.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent event) {
    String playerID = PlayerConverter.getID(event.getPlayer());
    if (!containsPlayer(playerID)) {
        return;
    }
    if (event.getMessage().matches("[a-zA-Z]*: .*")) {
        event.setCancelled(true);
        String message = event.getMessage();
        int index = message.indexOf(':');
        String key = message.substring(0, index).trim();
        String value = message.substring(index + 1).trim();
        ((VariableData) dataMap.get(playerID)).add(key, value);
        event.getPlayer().sendMessage("§2§l\u2713");
    }
}
 
Example #17
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldCancelChatEventForNoRemainingRecipients() {
    // given
    given(settings.getProperty(RestrictionSettings.ALLOW_CHAT)).willReturn(false);
    AsyncPlayerChatEvent event = newAsyncChatEvent();
    given(listenerService.shouldCancelEvent(any(Player.class))).willReturn(true);
    given(listenerService.shouldCancelEvent(event.getPlayer())).willReturn(false);
    given(settings.getProperty(RestrictionSettings.HIDE_CHAT)).willReturn(true);

    // when
    listener.onPlayerChat(event);

    // then
    verify(listenerService).shouldCancelEvent(event.getPlayer());
    // message sender + 3 recipients = 4
    verify(listenerService, times(4)).shouldCancelEvent(any(Player.class));
    verify(event).setCancelled(true);
    assertThat(event.getRecipients(), empty());
}
 
Example #18
Source File: ChatHealthPrependModule.java    From UHC with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void on(AsyncPlayerChatEvent event) {
    if (!isEnabled()) return;

    final double percent = event.getPlayer().getHealth() / event.getPlayer().getMaxHealth() * 100D;

    final StringBuilder format = new StringBuilder();

    if (useNumbers) {
        format.append(PERCENTAGE_COLOURS.ceilingEntry(percent).getValue())
                .append(FORMATTER.format(percent))
                .append("%%"); // double percent because it is a string.format string
    } else {
        format.append(BARS.ceilingEntry(percent).getValue());
    }

    format.append(ChatColor.RESET)
            .append(" ")
            .append(event.getFormat());

    event.setFormat(format.toString());
}
 
Example #19
Source File: BukkitImageListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerInteractEntity(AsyncPlayerChatEvent event) {
    Set<Player> recipients = event.getRecipients();
    Iterator<Player> iter = recipients.iterator();
    while (iter.hasNext()) {
        Player player = iter.next();
        if (player.equals(event.getPlayer())) continue;

        FawePlayer<Object> fp = FawePlayer.wrap(player);
        if (!fp.hasMeta()) continue;

        CFICommands.CFISettings settings = fp.getMeta("CFISettings");
        if (settings == null || !settings.hasGenerator()) continue;

        String name = player.getName().toLowerCase();
        if (!event.getMessage().toLowerCase().contains(name)) {
            ArrayDeque<String> buffered = fp.getMeta("CFIBufferedMessages");
            if (buffered == null) fp.setMeta("CFIBufferedMessaged", buffered = new ArrayDeque<String>());
            String full = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
            buffered.add(full);
            iter.remove();
        }
    }
}
 
Example #20
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldHideChatFromUnauthed() {
    // given
    given(settings.getProperty(RestrictionSettings.ALLOW_CHAT)).willReturn(false);
    AsyncPlayerChatEvent event = newAsyncChatEvent();
    given(listenerService.shouldCancelEvent(event.getPlayer())).willReturn(false);
    given(settings.getProperty(RestrictionSettings.HIDE_CHAT)).willReturn(true);
    List<Player> recipients = new ArrayList<>(event.getRecipients());
    given(listenerService.shouldCancelEvent(recipients.get(0))).willReturn(true);

    // when
    listener.onPlayerChat(event);

    // then
    verify(listenerService).shouldCancelEvent(event.getPlayer());
    // message sender + 3 recipients = 4
    verify(listenerService, times(4)).shouldCancelEvent(any(Player.class));
    verify(event, never()).setCancelled(anyBoolean());
    assertThat(event.getRecipients(), contains(recipients.get(1), recipients.get(2)));
}
 
Example #21
Source File: ChatEventsTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOnChatEvent_nullToggle() {
    final String TEST_MESSAGE = "This should be ignored";
    Player onlinePlayer = getFakePlayer(true);
    Set<Player> recipients = new HashSet<>();
    doReturn(null).when(fakeLogic).getToggle(onlinePlayer);

    AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(true, onlinePlayer, TEST_MESSAGE, recipients);
    listener.onChatEvent(event);
    verify(fakeScheduler, times(0)).runTask(any(Plugin.class), any(Runnable.class));
}
 
Example #22
Source File: ChatEventsTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOnChatEvent_partyToggle() {
    final String TEST_MESSAGE = "Party chat message via toggle";
    Player onlinePlayer = getFakePlayer(true);
    Set<Player> recipients = new HashSet<>();
    doReturn(Type.PARTY).when(fakeLogic).getToggle(onlinePlayer);

    AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(true, onlinePlayer, TEST_MESSAGE, recipients);
    listener.onChatEvent(event);
    verify(fakeScheduler).runTask(any(Plugin.class), any(Runnable.class));
}
 
Example #23
Source File: ChatEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onChatEvent(AsyncPlayerChatEvent e) {
    IslandChatEvent.Type toggle = logic.getToggle(e.getPlayer());
    if (toggle != null) {
        e.setCancelled(true);
        Server server = plugin.getServer();
        // Called via a sync task, because this listener might get called async.
        server.getScheduler().runTask(plugin, () ->
                server.getPluginManager().callEvent(
                        new IslandChatEvent(e.getPlayer(), toggle, e.getMessage())));
    }
}
 
Example #24
Source File: BukkitEventListener.java    From LunaChat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * プレイヤーがチャット発言したときに呼び出されるメソッド
 * @param event
 */
@EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true)
public void onAsyncPlayerChatNormal(AsyncPlayerChatEvent event) {
    if ( matchesEventPriority(EventPriority.NORMAL) ) {
        processChatEvent(event);
    }
}
 
Example #25
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 #26
Source File: DPlayerListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
    Player player = event.getPlayer();
    if (isCitizensNPC(player)) {
        return;
    }
    GlobalPlayer dPlayer = dPlayers.get(player);
    if (dPlayer == null) {
        return;
    }
    if (!dPlayer.isInGroupChat()) {
        return;
    }

    if (dPlayer instanceof DEditPlayer) {
        event.setCancelled(true);
        ((DInstancePlayer) dPlayer).chat(event.getMessage());
        return;
    }

    PlayerGroup group = plugin.getPlayerGroup(player);
    if (group == null) {
        return;
    }

    boolean game = event.getMessage().startsWith(ALL) && dPlayer instanceof DInstancePlayer;
    event.setCancelled(true);
    if (game) {
        ((DInstancePlayer) dPlayer).chat(event.getMessage().substring(ALL.length()));
    } else {
        group.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatGroup(), dPlayer) + event.getMessage());
    }
}
 
Example #27
Source File: ConfirmTransferCommandListener.java    From Statz with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onAsyncChat(final AsyncPlayerChatEvent event) {

	Player player = event.getPlayer();

	if (TransferCommand.confirmTransferSQLite.contains(player.getName())) {
		// Player did not type yes.
		if (!event.getMessage().trim().equalsIgnoreCase("yes")) {
			player.sendMessage(ChatColor.RED + "To confirm, type " + ChatColor.GOLD + "yes" + ChatColor.RED
					+ ". To deny, just wait 10 seconds.");
			event.setCancelled(true);
			return;
		}

		player.sendMessage(
				ChatColor.RED + "Confirmed " + ChatColor.GRAY + "/statz transfer" + ChatColor.RED + " command!");

		TransferCommand.confirmTransfer(player);

		// Cancel type of 'yes'
		event.setCancelled(true);
	} else if (TransferCommand.confirmTransferMySQL.contains(player.getName())) {
		// Player did not type yes.
		if (!event.getMessage().trim().equalsIgnoreCase("yes")) {
			player.sendMessage(ChatColor.RED + "To confirm, type " + ChatColor.GOLD + "yes" + ChatColor.RED
					+ ". To deny, just wait 10 seconds.");
			event.setCancelled(true);
			return;
		}

		player.sendMessage(
				ChatColor.RED + "Confirmed " + ChatColor.GRAY + "/statz transfer reverse" + ChatColor.RED + " command!");

		TransferCommand.confirmReverseTransfer(player);

		// Cancel type of 'yes'
		event.setCancelled(true);
	}

}
 
Example #28
Source File: DiscordSRV.java    From DiscordSRV with GNU General Public License v3.0 5 votes vote down vote up
public void reloadCancellationDetector() {
    if (cancellationDetector != null) {
        cancellationDetector.close();
        cancellationDetector = null;
    }

    if (config().getInt("DebugLevel") > 0) {
        cancellationDetector = new CancellationDetector<>(AsyncPlayerChatEvent.class);
        cancellationDetector.addListener((plugin, event) -> DiscordSRV.info("Plugin " + plugin.toString()
                + " cancelled AsyncPlayerChatEvent (author: " + event.getPlayer().getName()
                + " | message: " + event.getMessage() + ")"));
        DiscordSRV.info(LangUtil.InternalMessage.CHAT_CANCELLATION_DETECTOR_ENABLED);
    }
}
 
Example #29
Source File: ChatEvent.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event){
    Player player = event.getPlayer();
    if(StackTools.hasValidMetadata(player, GlobalValues.WAITING_FOR_INPUT)){
        if(!(player.getMetadata(GlobalValues.WAITING_FOR_INPUT).get(0).asBoolean())){
            return;
        }
        event.setCancelled(true);
        sm.getStickTools().updateStack(player, event.getMessage());
    }
}
 
Example #30
Source File: ChatListener.java    From CloudNet with Apache License 2.0 5 votes vote down vote up
@EventHandler
public void handle(AsyncPlayerChatEvent e) {
    PermissionGroup permissionGroup = permissionService ? CloudServer.getInstance()
                                                                     .getCachedPlayer(e.getPlayer().getUniqueId())
                                                                     .getPermissionEntity()
                                                                     .getHighestPermissionGroup(CloudAPI.getInstance()
                                                                                                        .getPermissionPool()) : null;

    if (permissionGroup == null) {
        return;
    }

    e.setFormat(ChatColor.translateAlternateColorCodes('&',
                                                       ChatPlugin.getPlugin(ChatPlugin.class)
                                                                 .getConfig()
                                                                 .getString("format")
                                                                 .replace("%display%",
                                                                          ChatColor.translateAlternateColorCodes('&',
                                                                                                                 permissionGroup.getDisplay()))
                                                                 .replace("%prefix%",
                                                                          ChatColor.translateAlternateColorCodes('&',
                                                                                                                 permissionGroup.getPrefix()))
                                                                 .replace("%suffix%",
                                                                          ChatColor.translateAlternateColorCodes('&',
                                                                                                                 permissionGroup.getSuffix()))
                                                                 .replace("%group%", permissionGroup.getName())
                                                                 .replace("%player%", e.getPlayer().getName())
                                                                 .replace("%message%",
                                                                          e.getPlayer().hasPermission("cloudnet.chat.color") ? ChatColor
                                                                              .translateAlternateColorCodes('&',
                                                                                                            e.getMessage()
                                                                                                             .replace("%",
                                                                                                                      "%%")) : ChatColor
                                                                              .stripColor(ChatColor.translateAlternateColorCodes('&',
                                                                                                                                 e.getMessage()
                                                                                                                                  .replace(
                                                                                                                                      "%",
                                                                                                                                      "%%"))))));
}