org.bukkit.event.server.ServerCommandEvent Java Examples

The following examples show how to use org.bukkit.event.server.ServerCommandEvent. 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: CommandListener.java    From Carbon with GNU Lesser General Public License v3.0 8 votes vote down vote up
@EventHandler
public void onServerCommand(ServerCommandEvent event) {
  FileConfiguration spigot = YamlConfiguration.loadConfiguration(new File(Bukkit.getServer().getWorldContainer(), "spigot.yml"));

  if (event.getCommand().equalsIgnoreCase("reload")) {
    // Restarts server if server is set up for it.
    if (spigot.getBoolean("settings.restart-on-crash")) {
      Bukkit.getLogger().severe("Restarting server due to reload command!");
      event.setCommand("restart");
    } else {
      // Call to server shutdown on disable.
      // Won't hurt if server already disables itself, but will prevent plugin unload/reload.
      Bukkit.getLogger().severe("Stopping server due to reload command!");
      Bukkit.shutdown();
    }
  }
}
 
Example #2
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 #3
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");
	}
}
 
Example #4
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onCommand(ServerCommandEvent event) {
    if (event.getCommand().equalsIgnoreCase("/reload") || event.getCommand().equalsIgnoreCase("reload")) {
        event.setCommand("");
        event.getSender().sendMessage("PlotMe disabled /reload to prevent errors from occuring.");
    }
}
 
Example #5
Source File: ServerCommandPlaceholder.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onCmd(ServerCommandEvent e) {
    String cmd = e.getCommand();
    String replacement = PlaceholderHandler.replacePlaceholders(e.getSender() instanceof Player ? (Player) e.getSender() : null, cmd);
    if (replacement != null && !cmd.equals(replacement)) {
        e.setCommand(cmd);
    }
}
 
Example #6
Source File: TpsPingCmdWarpper.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onServerCommandPreProcess(ServerCommandEvent e) {
    String cmd = e.getCommand();
    if (plugin.cfg.tps_enable && plugin.cfg.tps_override && (cmd.startsWith("tps ") || cmd.equals("tps"))) {
        e.setCommand(cmd.replaceAll("^tps", "nu tps"));
    }

    if (plugin.cfg.ping_enable && plugin.cfg.ping_override && (cmd.startsWith("ping ") || cmd.equals("ping"))) {
        e.setCommand(cmd.replaceAll("^ping", "nu ping"));
    }

    if (plugin.cfg.ping_enable && plugin.cfg.ping_override && (cmd.startsWith("pingtop ") || cmd.equals("pingtop"))) {
        e.setCommand(cmd.replaceAll("^pingtop", "nu pingtop"));
    }
}
 
Example #7
Source File: BukkitCommandExecutor.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onConsoleCommand(ServerCommandEvent e) {
    if (!(e.getSender() instanceof ConsoleCommandSender)) {
        return;
    }

    String buffer = e.getCommand();
    if (buffer.isEmpty() || buffer.charAt(0) != '/') {
        return;
    }

    buffer = buffer.substring(1);

    String commandLabel;
    int firstSpace = buffer.indexOf(' ');
    if (firstSpace == -1) {
        commandLabel = buffer;
    } else {
        commandLabel = buffer.substring(0, firstSpace);
    }

    Command command = CommandMapUtil.getCommandMap(this.plugin.getBootstrap().getServer()).getCommand(commandLabel);
    if (command != this.command) {
        return;
    }

    e.setCommand(buffer);
}
 
Example #8
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 #9
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 #10
Source File: EvtCommand.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public boolean check(final Event e) {
	if (command == null)
		return true;
	final String message;
	if (e instanceof PlayerCommandPreprocessEvent) {
		assert ((PlayerCommandPreprocessEvent) e).getMessage().startsWith("/");
		message = ((PlayerCommandPreprocessEvent) e).getMessage().substring(1);
	} else {
		message = ((ServerCommandEvent) e).getCommand();
	}
	return StringUtils.startsWithIgnoreCase(message, command)
			&& (command.contains(" ") || message.length() == command.length() || Character.isWhitespace(message.charAt(command.length()))); // if only the command is given, match that command only
}
 
Example #11
Source File: ExprCommand.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	what = matchedPattern;
	if (!ScriptLoader.isCurrentEvent(PlayerCommandPreprocessEvent.class, ServerCommandEvent.class)) {
		if (what != ARGS) // ExprArgument has the same syntax
			Skript.error("The 'command' expression can only be used in a command event");
		return false;
	}
	return true;
}
 
Example #12
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 #13
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 #14
Source File: CommandInterceptorTest.java    From mcspring-boot with MIT License 5 votes vote down vote up
@Test
public void shouldNotDelegateServerCommandIfAlreadyRegistered() {
    when(commandService.isRegistered()).thenReturn(true);

    ServerCommandEvent event = new ServerCommandEvent(player, "say hello");
    commandInterceptor.onServerCommand(event);

    verify(commandExecutor, never()).execute(any());
}
 
Example #15
Source File: CommandInterceptorTest.java    From mcspring-boot with MIT License 5 votes vote down vote up
@Test
public void shouldDelegateServerCommandToExecutorWithContext() {
    ServerCommandEvent event = new ServerCommandEvent(player, "say hello");
    commandInterceptor.onServerCommand(event);

    assertTrue(event.isCancelled());
    verify(commandExecutor).execute("say", "hello");
    verify(player).sendMessage("message1");
    verify(player).sendMessage("message2");
}
 
Example #16
Source File: EventUtil.java    From mcspring-boot with MIT License 5 votes vote down vote up
public static CommandSender getSender(Event event) {
    if (event instanceof PlayerEvent) {
        return ((PlayerEvent) event).getPlayer();
    } else if (event instanceof ServerCommandEvent) {
        return ((ServerCommandEvent) event).getSender();
    } else if (event instanceof EntityEvent) {
        val entityEvent = (EntityEvent) event;
        return entityEvent.getEntity() instanceof Player ? entityEvent.getEntity() : null;
    }
    return getInferredSender(event);
}
 
Example #17
Source File: CommandListener.java    From factions-top with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCommand(ServerCommandEvent event) {
    event.setCommand(attemptRebind(event.getCommand()));
}
 
Example #18
Source File: BukkitPlatformListener.java    From LuckPerms with MIT License 4 votes vote down vote up
@EventHandler
public void onServerCommand(ServerCommandEvent e) {
    handleCommand(e.getSender(), e.getCommand().toLowerCase(), e);
}
 
Example #19
Source File: GroupSynchronizationManager.java    From DiscordSRV with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onServerCommand(ServerCommandEvent event) {
    checkCommand(event.getCommand());
}
 
Example #20
Source File: CommandHandler.java    From TradePlus with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onServerCommand(ServerCommandEvent event) {
  String[] cmd = event.getCommand().split("\\s+");
  testAndRun(event, event.getSender(), cmd);
}
 
Example #21
Source File: CommandEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onServerCommand(ServerCommandEvent event) {
    //CauseTracker.getInstance().getCauseStack().add(event.getSender());
}
 
Example #22
Source File: EssentialsBridge.java    From BungeePerms with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onEssReloadCommandConsole(ServerCommandEvent e)
{
    handleEssReload(e.getCommand());
}