@Listener public void onCommand(SendCommandEvent commandEvent, @First Player player) { String command = commandEvent.getCommand(); // do not blacklist our own commands if ("register".equals(command) || "login".equals(command) || "forgotpassword".equals(command)) { return; } if (plugin.getConfigManager().getConfig().isCommandOnlyProtection()) { List<String> protectedCommands = plugin.getConfigManager().getConfig().getProtectedCommands(); if ((protectedCommands.isEmpty() || protectedCommands.contains(command))) { if (!plugin.getDatabase().isLoggedin(player)) { player.sendMessage( plugin.getConfigManager().getConfig().getTextConfig().getProtectedCommand()); commandEvent.setCancelled(true); } } } else { checkLoginStatus(commandEvent, player); } }
@Listener public void onSendCommandEvent(SendCommandEvent event, @First CommandSource src) { String command = event.getCommand(); if (!command.equalsIgnoreCase("say")) { return; } if (Sponge.getPluginManager().isLoaded("simplechat")) { return; } String message = event.getArguments(); if (message == null || message.equals("")) { return; } MutableMessageChannel channel = MessageChannel.TO_ALL.asMutable(); if (message.startsWith("@")) { channel = MessageChannel.TO_NONE.asMutable(); String selector = message.substring(0, message.indexOf(" ")); for (Entity entity : Selector.parse(selector).resolve(src)) { if (entity instanceof Player) { channel.addMember((MessageReceiver) entity); } } if (channel.getMembers().size() == 0) { src.sendMessage(Text.of(TextColors.RED, "Selector returned no players")); return; } channel.addMember(Sponge.getServer().getConsole()); message = message.replace(selector, ""); } Text text = TextSerializers.FORMATTING_CODE.deserialize(message); if (src instanceof Player) { Player player = (Player) src; Optional<PlayerTag> optionalPlayerTag = PlayerTag.get(player); if (optionalPlayerTag.isPresent()) { text = Text.join(optionalPlayerTag.get().getTag(), Text.of(" "), text); } else { text = Text.join(PlayerTag.getDefault(player), Text.of(" "), text); } } else { Optional<SingleTag> optionalTag = SingleTag.get("simpletags", "console"); if (optionalTag.isPresent()) { text = Text.join(optionalTag.get().getTag(), Text.of(" "), text); } } channel.send(text); event.setCancelled(true); }