org.spongepowered.api.event.command.SendCommandEvent Java Examples
The following examples show how to use
org.spongepowered.api.event.command.SendCommandEvent.
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 |
@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: SpyListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onCommand(SendCommandEvent e) { Player t = e.getCause().first(Player.class).orElse(null); if (t == null) return; for (Player p : Sponge.getServer().getOnlinePlayers()) { if (!p.hasPermission(SpyPermissions.UC_SPY_COMMANDSPY_SEE.get())) { continue; } if (p == t) { continue; } if (!UltimateCore.get().getUserService().getUser(p).get(SpyKeys.COMMANDSPY_ENABLED).get()) { continue; } //Ignored commands List<String> ignored = Arrays.asList("personalmessage", "pm", "dm", "msg", "w", "whisper", "tell", "reply", "respond", "r"); if (ignored.contains(e.getCommand())) continue; Messages.send(p, "spy.format.commandspy", "%player%", VariableUtil.getNameEntity(t), "%message%", e.getCommand() + " " + e.getArguments()); } }
Example #3
Source File: JailListener.java From UltimateCore with MIT License | 6 votes |
@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 #4
Source File: CommandSentListener.java From EssentialCmds with MIT License | 6 votes |
@Listener public void onCommandSent(SendCommandEvent event, @Root CommandSource src) { if (src instanceof Player && Utils.isPlayerCommandLoggingEnabled()) { EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments()); } else if (src instanceof ConsoleSource && Utils.isConsoleCommandLoggingEnabled()) { EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments()); } else if (src instanceof CommandBlockSource && Utils.isCommandBlockCommandLoggingEnabled()) { EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments()); } else if (Utils.isOtherCommandLoggingEnabled()) { EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments()); } }
Example #5
Source File: CommandListener.java From EssentialCmds with MIT License | 5 votes |
@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 #6
Source File: EntityListener.java From Prism with MIT License | 5 votes |
/** * Saves event records when a player executes a command. * * @param event SendCommandEvent */ @Listener(order = Order.POST) public void onSendCommand(SendCommandEvent event, @Root Player player) { if (!Prism.getInstance().getConfig().getEventCategory().isCommandExecute()) { return; } PrismRecord.create() .source(event.getCause()) .event(PrismEvents.COMMAND_EXECUTE) .location(player.getLocation()) .target(event.getCommand()) .buildAndSave(); }
Example #7
Source File: UnknowncommandListener.java From UltimateCore with MIT License | 5 votes |
@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 #8
Source File: ChatLoggerListener.java From FlexibleLogin with MIT License | 5 votes |
@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 #9
Source File: ChatLoggerListener.java From FlexibleLogin with MIT License | 5 votes |
@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 #10
Source File: PreventListener.java From FlexibleLogin with MIT License | 5 votes |
@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 #11
Source File: SendCommandListener.java From EagleFactions with MIT License | 5 votes |
@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 #12
Source File: CachedCommandCall.java From Web-API with MIT License | 5 votes |
public CachedCommandCall(SendCommandEvent event, boolean censor) { super(null); this.timestamp = (new Date()).toInstant().toEpochMilli(); this.command = censor ? "[censored]" : event.getCommand(); this.args = censor ? "" : event.getArguments(); this.cause = new CachedCause(event.getCause()); this.cancelled = event.isCancelled(); this.result = new CachedCommandResult(event.getResult()); }
Example #13
Source File: CacheService.java From Web-API with MIT License | 5 votes |
@Listener(order = Order.POST) public void onCommand(SendCommandEvent event) { CachedCommandCall cache = new CachedCommandCall(event, censoredCommands.contains(event.getCommand())); commandCalls.add(cache); while (commandCalls.size() > numCommandCalls) { commandCalls.poll(); } }
Example #14
Source File: SpongePlatformListener.java From LuckPerms with MIT License | 5 votes |
@Listener public void onSendCommand(SendCommandEvent e) { CommandSource source = e.getCause().first(CommandSource.class).orElse(null); if (source == null) return; final String name = e.getCommand().toLowerCase(); if (((name.equals("op") || name.equals("minecraft:op")) && source.hasPermission("minecraft.command.op")) || ((name.equals("deop") || name.equals("minecraft:deop")) && source.hasPermission("minecraft.command.deop"))) { Message.OP_DISABLED_SPONGE.send(this.plugin.getSenderFactory().wrap(source)); } }
Example #15
Source File: SpongeAFKListener.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
@Listener(order = Order.POST) public void onPlayerCommand(SendCommandEvent event, @First Player player) { performedAction(player); boolean isAfkCommand = event.getCommand().toLowerCase().startsWith("afk"); if (isAfkCommand) { AFK_TRACKER.usedAfkCommand(player.getUniqueId(), System.currentTimeMillis()); } }
Example #16
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@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); } } }
Example #17
Source File: WebHookService.java From Web-API with MIT License | 4 votes |
@Listener(order = Order.POST) public void onCommand(SendCommandEvent event) { notifyHooks(WebHookService.WebHookType.COMMAND, event); }