public boolean canSee(CommandSender sender) { if (amendedPermission == null) { if (sender instanceof ConsoleCommandSender) { return true; } for (Command command : alias.getCommands()) { if (!command.testPermissionSilent(sender)) { return false; } } return true; } else { return sender.hasPermission(amendedPermission); } }
@Override public boolean dispatchCommand(CommandSender sender, String commandLine) { Validate.notNull(sender, "Sender cannot be null"); Validate.notNull(commandLine, "CommandLine cannot be null"); if (commandMap.dispatch(sender, commandLine)) { return true; } // Cauldron start - handle vanilla commands called from plugins if(sender instanceof ConsoleCommandSender) { craftCommandMap.setVanillaConsoleSender(this.console); } return this.dispatchVanillaCommand(sender, commandLine); // Cauldron end }
private net.minecraft.command.ICommandSender getListener(CommandSender sender) { if (sender instanceof Player) { return ((CraftPlayer) sender).getHandle(); } if (sender instanceof BlockCommandSender) { return ((CraftBlockCommandSender) sender).getTileEntity(); } if (sender instanceof CommandMinecart) { return ((net.minecraft.entity.EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).func_145822_e(); } if (sender instanceof RemoteConsoleCommandSender) { return net.minecraft.network.rcon.RConConsoleSource.instance; } if (sender instanceof ConsoleCommandSender) { return ((CraftServer) sender.getServer()).getServer(); } return null; }
@Inject BroadcastScheduler(Loggers loggers, @Named("configuration") Path configPath, Scheduler scheduler, ConsoleCommandSender console, OnlinePlayers onlinePlayers, LocalizedMessageMap.Factory messageMapFactory, DocumentWatcher.Factory<List<BroadcastSchedule>> documentWatcherFactory, Server localServer, BroadcastFormatter formatter, ComponentRenderContext renderer, BroadcastSettings settings) { this.logger = loggers.get(getClass()); this.configPath = configPath; this.configFile = configPath.resolve(CONFIG_FILE); this.scheduler = scheduler; this.console = console; this.onlinePlayers = onlinePlayers; this.messageMapFactory = messageMapFactory; this.documentWatcherFactory = documentWatcherFactory; this.localServer = localServer; this.formatter = formatter; this.renderer = renderer; this.settings = settings; }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { Bukkit.getPluginManager().disablePlugin(Survival.instance); Bukkit.getPluginManager().enablePlugin(Survival.instance); Survival.instance.reloadConfig(); if(sender instanceof Player) { sender.sendMessage(ChatColor.AQUA + "[SurvivalPlus] " + ChatColor.GREEN + "Reload complete."); sender.getServer().getConsoleSender().sendMessage("[SurvivalPlus] " + ChatColor.GREEN + "Reload complete."); } else if(sender instanceof ConsoleCommandSender) { sender.sendMessage("[SurvivalPlus] " + ChatColor.GREEN + "Reload complete."); } return true; }
private static Sender getSender(CommandSender sender) { if (sender instanceof LivingEntity) { LivingEntity livingEntity = (LivingEntity) sender; Sender s; if (cachedSenders.containsKey(livingEntity.getUniqueId())) { s = cachedSenders.get(livingEntity.getUniqueId()); s.refresh(livingEntity); } else { cachedSenders.put(livingEntity.getUniqueId(), s = new Sender(livingEntity)); } return s; } if (sender instanceof ConsoleCommandSender) return consoleSender == null ? consoleSender = new Sender(sender) : consoleSender; if (sender instanceof BlockCommandSender) return new Sender(sender); return null; }
@EventHandler // Handles command-specific tab-completes. public void onArgsComplete(TabCompleteEvent evt) { String input = evt.getBuffer(); String label = input.split(" ")[0]; boolean console = evt.getSender() instanceof ConsoleCommandSender; Command cmd = getUsable(evt.getSender()).stream() .filter(c -> !c.getCommandPrefix().contains(" ") && label.length() >= c.getCommandPrefix().length()) // Don't count /trigger .filter(c -> c.getAlias().contains(console ? label : label.substring(c.getCommandPrefix().length()))) .findAny().orElse(null); // Get the command for the input supplied. if (!input.contains(" ") || cmd == null) return; // No command was found. String[] args = Utils.shift(input.split(" ")); String lastArg = (args.length > 0 ? args[args.length - 1] : "").toLowerCase(); boolean space = input.endsWith(" "); List<String> possible = cmd.getCompletions(evt.getSender(), args, args.length + (space ? 1 : 0) - 1); evt.setCompletions(possible.stream().filter(ac -> ac.toLowerCase().startsWith(lastArg) || space).collect(Collectors.toList())); }
public void handle(String msg, CommandSender sender, Cancellable event) { if (Config.get().hiddenMode && !sender.hasPermission("camerastudio.use") && !sender.isOp()) return; if (msg.startsWith("/cam") || msg.startsWith("/camerastudio")) { event.setCancelled(true); List<String> args = Lists.newArrayList(msg.split(" ")); if (args.size() > 1) { args.remove(0); } Traveller traveller = null; if (sender instanceof ConsoleCommandSender) { traveller = new BukkitTraveller(null); } else { Player player = (Player) sender; traveller = Travellers.impl().get(player.getUniqueId()); } CmdCam.get().preExec(traveller, args); } }
public static Server createMockServer() { ConsoleCommandSender commandSender = (ConsoleCommandSender) createCommandSender(); Server server = mock(Server.class); when(server.getLogger()).thenReturn(Logger.getGlobal()); when(server.getPluginManager()).thenReturn( new SimplePluginManager(server, new SimpleCommandMap(server))); when(server.getItemFactory()).thenReturn(new MockItemFactory()); doAnswer(invocation -> new MockInventory(InventoryType.CHEST, invocation.getArgument(1), invocation.getArgument(2))) .when(server).createInventory(any(), anyInt(), anyString()); when(server.getBukkitVersion()).thenReturn("1.0"); when(server.getConsoleSender()).thenReturn(commandSender); doAnswer(invocation -> createMockWorld()) .when(server).getWorld(anyString()); return server; }
public static CommandSender createCommandSender() { CommandSender sender = mock( CommandSender.class, withSettings().extraInterfaces(Player.class, ConsoleCommandSender.class) ); when(sender.getServer()).thenReturn(Bukkit.getServer()); doAnswer(invocation -> { String fixed = StringUtils.join((String[]) invocation.getArguments()[0], '\n'); System.out.println(ChatColor.stripColor(fixed)); return null; }).when(sender).sendMessage(any(String[].class)); doAnswer(invocation -> { sender.sendMessage(new String[]{(String) invocation.getArguments()[0]}); return null; }).when(sender).sendMessage(anyString()); return sender; }
public boolean execute(CommandSender sender, String label, String[] args) { VPSender vpSender; if(sender instanceof Player) vpSender = VanillaPlusCore.getPlayerManager().getPlayer(((Player)sender).getUniqueId()); else if(sender instanceof BlockCommandSender) vpSender = new VPCommandBlock((BlockCommandSender) sender); else if(sender instanceof ConsoleCommandSender) vpSender = VanillaPlusCore.getVPConsole(); else return false; if(label.equalsIgnoreCase(PlaceH.HELP.get())){ showTopHelp(vpSender, label, args.length > 0 ? Utils.parseInt(args[0], 1, false) : 1); return true; } for(CommandPlus command : getLoaded()) if(command.is(label.toLowerCase())){ if(command.hasRequirement(vpSender)) command.onExecute(vpSender, label, new LinkedList<String>(Arrays.asList(args))); return true; } return false; }
@Override protected boolean onCommand(CommandSender sender, String label, String[] arguments) { if (!(sender instanceof ConsoleCommandSender) && !sender.isOp()) return true; if (arguments.length != 2) return true; String cheat = arguments[0]; String player = arguments[1]; String server = SamaGamesAPI.get().getServerName(); new JsonModMessage("AntiCheat", ModChannel.REPORT, ChatColor.DARK_RED, player + "#####" + server + "#####Possible usage de la triche : " + cheat).send(); return true; }
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { if (args.length > 0 && args[0].equalsIgnoreCase("reload")){ if (sender instanceof ConsoleCommandSender || sender.hasPermission("sddls.reload")) { plugin.reloadConfig(); plugin.loadConfig(); sender.sendMessage(ChatColor.translateAlternateColorCodes('&',"&6[Sddls] &rReloaded!")); return true; } } sender.sendMessage(ChatColor.translateAlternateColorCodes('&',"&6[Sddls] &rv"+plugin.getDescription().getVersion())); sender.sendMessage(ChatColor.translateAlternateColorCodes('&',"&r"+plugin.getDescription().getDescription())); sender.sendMessage(ChatColor.translateAlternateColorCodes('&',"&7"+plugin.getDescription().getWebsite())); if (sender instanceof ConsoleCommandSender || sender.hasPermission("sddls.reload")) sender.sendMessage(ChatColor.translateAlternateColorCodes('&',"&6/sddls reload &r- reloads config")); return true; }
/** Send a message from a channel as console. * @param sender {@code ConsoleCommandSender} - Console sender. * @param message {@code FancyMessage} - Message to send. * @param direct {@code boolean} - Send message direct to players on channel. */ public void sendMessage(ConsoleCommandSender sender, UltimateFancy message, boolean direct){ if (direct){ for (Player p:Bukkit.getOnlinePlayers()){ UCChannel chp = UChat.get().getPlayerChannel(p); if (UCPerms.channelReadPerm(p, this) && !this.isIgnoring(p.getName()) && (!this.neeFocus() || chp.equals(this))){ UChat.get().getUCLogger().timings(timingType.START, "UCChannel#sendMessage()|Direct Message"); message.send(p); } } message.send(sender); } else { UChat.get().getUCLogger().timings(timingType.START, "UCChannel#sendMessage()|Fire MessageChannelEvent"); UCMessages.sendFancyMessage(new String[0], message.toOldFormat(), this, sender, null); } }
/** Send a message from a channel as console. * @param sender {@code ConsoleCommandSender} - Console sender. * @param message {@code FancyMessage} - Message to send. */ @Deprecated public void sendMessage(ConsoleCommandSender sender, String message){ if (UChat.get().getUCConfig().getBoolean("api.format-console-messages")){ UCMessages.sendFancyMessage(new String[0], message, this, sender, null); } else { UltimateFancy fmsg = new UltimateFancy(message); for (Player p:Bukkit.getOnlinePlayers()){ UCChannel chp = UChat.get().getPlayerChannel(p); if (UCPerms.channelReadPerm(p, this) && !this.isIgnoring(p.getName()) && (!this.neeFocus() || chp.equals(this))){ UChat.get().getUCLogger().timings(timingType.START, "UCChannel#sendMessage()|Fire AsyncPlayerChatEvent"); fmsg.send(p); } } fmsg.send(sender); } }
private void injectConsole() throws Exception { ConsoleCommandSender consoleSender = this.plugin.getServer().getConsoleSender(); // get the ServerCommandSender class Class<?> serverCommandSenderClass = ReflectionUtil.obcClass("command.ServerCommandSender"); // get the perm field Field permField = serverCommandSenderClass.getDeclaredField("perm"); permField.setAccessible(true); // get the PermissibleBase instance PermissibleBase permBase = (PermissibleBase) permField.get(consoleSender); // create a monitored instance which delegates to the previous PermissibleBase MonitoredPermissibleBase newPermBase = wrap(permBase, "internal/console"); // inject the monitored instance permField.set(consoleSender, newPermBase); }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(sender instanceof ConsoleCommandSender) { if(label.equalsIgnoreCase("vpngpurge")) { sender.sendMessage(PluginMessages.CONSOLE_COMMAND_PURGE); plugin.file.purgeCache(); sender.sendMessage(PluginMessages.CONSOLE_COMMAND_PURGE_COMPLETED); } return true; } else { sender.sendMessage(PluginMessages.PREFIX + "You must have console access to run this command."); } return false; }
public boolean canSee(CommandSender sender) { if (!command.isRegistered() && !(command instanceof VanillaCommand)) { // Unregistered commands should not show up in the help (ignore VanillaCommands) return false; } if (sender instanceof ConsoleCommandSender) { return true; } if (amendedPermission != null) { return sender.hasPermission(amendedPermission); } else { return command.testPermissionSilent(sender); } }
private void updateConfigFiles() { final int verConfig = 210; final int verLang = 211; final int verFish = 212; String msg = locale.getString("old-file"); ConsoleCommandSender console = getServer().getConsoleSender(); if (getConfig().getInt("version") != verConfig) { // Update console.sendMessage(String.format(msg, "config.yml")); } if (locale.getLangVersion() != verLang) { // Update console.sendMessage(String.format(msg, locale.getLangPath())); } if (locale.getFishVersion() != verFish) { // Update console.sendMessage(String.format(msg, locale.getFishPath())); } }
@Override public void onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (sender instanceof ConsoleCommandSender) { for (Player player : Bukkit.getOnlinePlayers()) { String rankName = KitManager.getKit("kitpvp",args[1]).guiItem.getItemMeta().getDisplayName(); if (player.getName().equalsIgnoreCase(args[0])) { player.sendMessage(Util.parseColors("&5Thank you for purchasing a " + rankName + " &5rank! We truly appreciate your support!")); } else { String name = args[0]; for(int i = 0; i < ranks.length; i++){ String s = ranks[i]; if(s.equals(args[1])){ name = "&" + colors[i] + name; } } player.sendMessage(Util.parseColors(name + " &5just purchased a " + rankName + " &5rank!")); } } } else { sender.sendMessage(ChatColor.RED + "This command can only be executed "); } }
/** * CommandSenderから、MailSenderを作成して返す * @param sender * @return MailSender */ public static MailSender getMailSender(CommandSender sender) { if ( sender == null ) { return null; } else if ( sender instanceof BlockCommandSender ) { return new MailSenderBlock((BlockCommandSender)sender); } else if ( sender instanceof ConsoleCommandSender ) { return new MailSenderConsole((ConsoleCommandSender)sender); } else if ( sender instanceof OfflinePlayer ) { OfflinePlayer player = (OfflinePlayer)sender; if ( Utility.isCB178orLater() ) { return new MailSenderPlayer("$" + player.getUniqueId().toString()); } else { return new MailSenderPlayer(player.getName()); } } return null; }
private void convertConfigV5(ConsoleCommandSender console, String oldConfig) { console.sendMessage(pluginPrefix + ChatColor.GREEN + "Converting config to version 5..."); for (String name : getConfig().getConfigurationSection("Crates").getKeys(false)) { getConfig().set("Crates." + name + ".Key.Item", getConfig().getString("Crate Keys.Item")); getConfig().set("Crates." + name + ".Key.Name", getConfig().getString("Crate Keys.Name")); getConfig().set("Crates." + name + ".Key.Enchanted", getConfig().getBoolean("Crate Keys.Enchanted")); } getConfig().set("Crate Keys", null); // Set config version getConfig().set("Config Version", 5); // Save config saveConfig(); console.sendMessage(pluginPrefix + ChatColor.GREEN + "Conversion of config has completed."); if (oldConfig != null && !oldConfig.equalsIgnoreCase("")) { configBackup = oldConfig; console.sendMessage(pluginPrefix + ChatColor.GREEN + "Your old config was backed up to " + oldConfig); } }
private void convertConfigV6(ConsoleCommandSender console, String oldConfig) { console.sendMessage(pluginPrefix + ChatColor.GREEN + "Converting config to version 6..."); if (getConfig().isSet("Hologram Text")) { List<String> oldHologramList = getConfig().getStringList("Hologram Text"); getConfig().set("Default Hologram Text", oldHologramList); getConfig().set("Hologram Text", null); } // Set config version getConfig().set("Config Version", 6); // Save config saveConfig(); console.sendMessage(pluginPrefix + ChatColor.GREEN + "Conversion of config has completed."); if (oldConfig != null && !oldConfig.equalsIgnoreCase("")) { configBackup = oldConfig; console.sendMessage(pluginPrefix + ChatColor.GREEN + "Your old config was backed up to " + oldConfig); } }
@Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { Channel channel; if (sender instanceof Player && ((Player) sender).isOnline()) channel = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel; else if (sender instanceof ConsoleCommandSender) channel = PlayerListener.ConsoleChannel; else channel = Channel.GlobalChat; final String message; if (args.length == 0) message = "wait what"; else message = "wait " + Arrays.stream(args).collect(Collectors.joining(" ")) + " what"; TBMCChatAPI.SendChatMessage(channel, sender, message); return true; }