Java Code Examples for org.bukkit.event.server.ServerCommandEvent#setCancelled()

The following examples show how to use org.bukkit.event.server.ServerCommandEvent#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: CommandInterceptor.java    From mcspring-boot with MIT License 5 votes vote down vote up
@EventHandler
void onServerCommand(ServerCommandEvent event) {
    if (event.isCancelled() || commandService.isRegistered()) return;
    val sender = context.getSender();
    val result = commandExecutor.execute(event.getCommand().split(" "));
    event.setCancelled(result.isExists());
    result.getOutput().forEach(sender::sendMessage);
}
 
Example 2
Source File: ListenerTabooLibUpdateCommand.java    From TrMenu with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onCommand(ServerCommandEvent e) {
    if ("tlibupdate".equalsIgnoreCase(e.getCommand())) {
        e.setCancelled(true);
        e.getSender().sendMessage("§8[§fTabooLib§8] §cWARNING §7| §4Update TabooLib will force to restart your server. Please confirm this action by type §c/tlibupdateConfirm");
    } else if ("tlibupdateConfirm".equalsIgnoreCase(e.getCommand()) || "tlibupdate confirm".equalsIgnoreCase(e.getCommand())) {
        e.setCommand("tlibupdatebbb");
        update(e.getSender());
    }
}
 
Example 3
Source File: ListenerCommand.java    From TabooLib with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void cmd(ServerCommandEvent e) {
    if (e.getCommand().equalsIgnoreCase("saveFiles")) {
        Local.saveFiles();
        LocalPlayer.saveFiles();
        TLogger.getGlobalLogger().info("Successfully.");
    } else if (e.getCommand().equalsIgnoreCase("tDebug")) {
        if (TabooLibAPI.isDebug()) {
            TabooLibAPI.debug(false);
            TLogger.getGlobalLogger().info("&cDisabled.");
        } else {
            TabooLibAPI.debug(true);
            TLogger.getGlobalLogger().info("&aEnabled.");
        }
    } else if (e.getCommand().equalsIgnoreCase("libUpdate")) {
        e.setCancelled(true);
        e.getSender().sendMessage("§8[§fTabooLib§8] §cWARNING §7| §4Update TabooLib will force to restart your server. Please confirm this action by type §c/libupdateconfirm");
    } else if (e.getCommand().equalsIgnoreCase("libUpdateConfirm") || e.getCommand().equalsIgnoreCase("libUpdate confirm")) {
        e.getSender().sendMessage("§8[§fTabooLib§8] §7Downloading TabooLib file...");
        Files.downloadFile("https://skymc.oss-cn-shanghai.aliyuncs.com/plugins/TabooLib.jar", new File("libs/TabooLib.jar"));
        e.getSender().sendMessage("§8[§fTabooLib§8] §2Download completed, the server will restart in 3 secs");
        try {
            Thread.sleep(3000L);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
        Bukkit.shutdown();
    }
}
 
Example 4
Source File: Commands.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerCommand(final ServerCommandEvent e) {
	if (e.getCommand() == null || e.getCommand().isEmpty())
		return;
	if (SkriptConfig.enableEffectCommands.value() && e.getCommand().startsWith(SkriptConfig.effectCommandToken.value())) {
		if (handleEffectCommand(e.getSender(), e.getCommand())) {
			e.setCancelled(true);
		}
		return;
	}
}
 
Example 5
Source File: UCListener.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onServerCmd(ServerCommandEvent e) {
    String[] args = e.getCommand().replace("/", "").split(" ");
    final String[] msg = {null};
    if (e.getCommand().length() > args[0].length() + 1) {
        msg[0] = e.getCommand().substring(args[0].length() + 1);
    }

    if (msg[0] != null && UChat.get().getUCConfig().getTellAliases().contains(args[0])) {
        if (args.length >= 3) {

            Bukkit.getScheduler().runTaskAsynchronously(UChat.get(), () -> {
                Player p = UChat.get().getServer().getPlayer(args[1]);

                if (p == null || !p.isOnline()) {
                    UChat.get().getLang().sendMessage(e.getSender(), "listener.invalidplayer");
                    return;
                }

                msg[0] = msg[0].substring(args[1].length() + 1);

                UChat.get().tempTellPlayers.put("CONSOLE", p.getName());
                UChat.get().command.add("CONSOLE");
                sendPreTell(UChat.get().getServer().getConsoleSender(), p, msg[0]);
            });

            e.setCancelled(true);
        }
    }
}
 
Example 6
Source File: ReloadCommandBlocker.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onConsoleCommand(ServerCommandEvent event) {
	String command = event.getCommand().toLowerCase();
	if (command.startsWith("/")) {
		command = command.substring(1);
	}
	if (blacklist.contains(command)) {
		event.setCancelled(true);
		event.getSender().sendMessage(ChatColor.DARK_RED + "The reload command has been disabled by ProtocolSupport");
	}
}