Java Code Examples for org.spongepowered.api.event.command.SendCommandEvent#setCancelled()

The following examples show how to use org.spongepowered.api.event.command.SendCommandEvent#setCancelled() . 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: UCListener.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.POST)
public void onCommand(SendCommandEvent e, @First CommandSource p) {
    // Deny command if muted
    if (p instanceof Player && UChat.get().mutes.contains(p.getName()) &&
            UChat.get().getConfig().root().general.muted_deny_cmds.contains(e.getCommand())) {
        UChat.get().getLang().sendMessage(p, "player.muted.denycmd");
        e.setCancelled(true);
        return;
    }

    if (UChat.get().getUCJDA() != null) {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        Task.builder().async().execute(() -> UChat.get().getUCJDA().sendCommandsToDiscord(UChat.get().getLang().get("discord.command")
                .replace("{player}", p.getName())
                .replace("{cmd}", "/" + e.getCommand() + " " + e.getArguments())
                .replace("{time-now}", sdf.format(cal.getTime()))));
    }
}
 
Example 2
Source File: JailListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onCommand(SendCommandEvent event, @First Player p) {
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    JailData data = up.get(JailKeys.JAIL).orElse(null);
    if (data != null) {
        try {
            List<String> allowedcommands = Modules.JAIL.get().getConfig().get().get().getNode("allowed-commands").getList(TypeToken.of(String.class));
            if (!allowedcommands.contains(event.getCommand())) {
                event.setCancelled(true);
                Messages.send(p, "jail.event.command", "%time%", (data.getEndtime() == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.formatDateDiff(data.getEndtime())), "%reason%", data.getReason());
            }
        } catch (ObjectMappingException e) {
            ErrorLogger.log(e, "Failed to load allowed commands while jailed from config.");
        }
    }
}
 
Example 3
Source File: SendCommandListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener(order = Order.EARLY)
public void onCommandSend(final SendCommandEvent event, final @Root Player player)
{
    if (EagleFactionsPlugin.getPlugin().getPVPLogger().isActive() && EagleFactionsPlugin.getPlugin().getPVPLogger().shouldBlockCommand(player, event.getCommand() + " " + event.getArguments()))
    {
        player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_CANT_USE_COMMAND_WHILE_BEING_IN_A_FIGHT));
        player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, MessageLoader.parseMessage(Messages.TIME_LEFT_NUMBER_SECONDS, TextColors.RED, ImmutableMap.of(Placeholders.NUMBER, Text.of(TextColors.YELLOW, super.getPlugin().getPVPLogger().getPlayerBlockTime(player))))));
        event.setCancelled(true);
    }
}
 
Example 4
Source File: CommandListener.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Listener
public void onPlayerSendCommand(SendCommandEvent event, @Root Player player)
{
	if(EssentialCmds.jailedPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You may not execute commands while in jail!"));
		event.setCancelled(true);
	}
}
 
Example 5
Source File: PreventListener.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onCommand(SendCommandEvent commandEvent, @First Player player) {
    String command = commandEvent.getCommand();

    Optional<? extends CommandMapping> commandOpt = commandManager.get(command);
    if (commandOpt.isPresent()) {
        CommandMapping mapping = commandOpt.get();
        command = mapping.getPrimaryAlias();

        //do not blacklist our own commands
        if (commandManager.getOwner(mapping)
            .map(pc -> pc.getId().equals(PomData.ARTIFACT_ID))
            .orElse(false)) {
            return;
        }
    }

    commandEvent.setResult(CommandResult.empty());
    if (settings.getGeneral().isCommandOnlyProtection()) {
        List<String> protectedCommands = settings.getGeneral().getProtectedCommands();
        if (protectedCommands.contains(command) && !plugin.getDatabase().isLoggedIn(player)) {
            player.sendMessage(settings.getText().getProtectedCommand());
            commandEvent.setCancelled(true);
        }
    } else {
        checkLoginStatus(commandEvent, player);
    }
}
 
Example 6
Source File: ChatLoggerListener.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Listener
public void onCommand(SendCommandEvent commandEvent) {
    String command = commandEvent.getCommand();

    Optional<? extends CommandMapping> commandOpt = commandManager.get(command);
    if (isOurCommand(command)) {
        //fake the cancelled event
        commandEvent.setCancelled(true);
    }
}
 
Example 7
Source File: ChatLoggerListener.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(Tristate.TRUE)
public void onPostCommand(SendCommandEvent commandEvent) {
    String command = commandEvent.getCommand();
    if (isOurCommand(command)) {
        //re-enable it
        commandEvent.getContext();
        commandEvent.setCancelled(false);
    }
}
 
Example 8
Source File: UnknowncommandListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onCommand(SendCommandEvent event) {
    CommandSource p = event.getCause().first(CommandSource.class).orElse(null);
    if (p == null) return;
    CommandManager cm = Sponge.getCommandManager();
    if (cm.get(event.getCommand()).isPresent()) return;

    //Send message
    event.setCancelled(true);
    Messages.send(p, "unknowncommand.message");
}
 
Example 9
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerCommand(SendCommandEvent e, @First Player p) {

    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }

    String cmd = e.getCommand();

    if (RedProtect.get().config.configRoot().server_protection.deny_commands_on_worlds.getOrDefault(p.getWorld().getName(), new ArrayList<>()).contains(cmd) && !p.hasPermission("redprotect.bypass")) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.command-notallowed");
        e.setCancelled(true);
        return;
    }

    if (RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.containsKey(cmd) && !cmd.equals(".")) {
        double min = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmd).min_range;
        double max = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmd).max_range;
        String mesg = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmd).message;
        double py = p.getLocation().getY();
        if (py < min || py > max) {
            if (mesg != null && !mesg.equals("")) {
                RedProtect.get().lang.sendMessage(p, mesg);
            }
            e.setCancelled(true);
            return;
        }
    }

    if (cmd.startsWith("back") || cmd.startsWith("home")) {
        PlayerCmd.put(p, cmd);
    }

    Region r = RedProtect.get().rm.getTopRegion(p.getLocation(), this.getClass().getName());
    if (r != null) {

        if (!r.AllowCommands(p, cmd)) {
            if (cmd.startsWith("rp") || cmd.startsWith("redprotect")) {
                return;
            }
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantcommand");
            e.setCancelled(true);
            return;
        }

        if (!r.DenyCommands(p, cmd)) {
            if (cmd.startsWith("rp") || cmd.startsWith("redprotect")) {
                return;
            }
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantcommand");
            e.setCancelled(true);
            return;
        }

        if (cmd.startsWith("home") && !r.AllowHome(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.canthome");
            e.setCancelled(true);
        }
    }
}