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; }
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; }
@Override protected void onCommand(CommandSender sender, String[] args) { BlockCommandSender bcs = (BlockCommandSender) sender; if (!Dungeons.isDungeon(bcs.getBlock().getWorld())) { sender.sendMessage(ChatColor.RED + "This command can only be run in a dungeon."); return; } Dungeon d = getDungeon(bcs); if (d.isEditMode()) { sender.sendMessage(ChatColor.RED + "This command cannot be run in edit-mode."); return; } super.onCommand(sender, args); if (deleteOnExecute() && !d.isEditMode()) bcs.getBlock().setType(Material.AIR); // Delete this command-block on execute, provided we aren't in edit-mode. }
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; }
/** * 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 ICommandListener getListener(CommandSender sender) { if (sender instanceof Player) { return ((CraftPlayer) sender).getHandle(); } if (sender instanceof BlockCommandSender) { return ((CraftBlockCommandSender) sender).getTileEntity(); } if (sender instanceof CommandMinecart) { return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock(); } if (sender instanceof RemoteConsoleCommandSender) { return RemoteControlCommandListener.instance; } if (sender instanceof ConsoleCommandSender) { return ((CraftServer) sender.getServer()).getServer(); } return null; }
@Override public boolean execute(org.bukkit.command.CommandSender sender, String label, String[] args) { if(!this.testPermission(sender)) { return true; } if((!this.command.player() && sender instanceof Player) || (!this.command.console() && sender instanceof ConsoleCommandSender) || (!this.command.commandblock() && sender instanceof BlockCommandSender)) { sendMessage(sender, "internal.cannot-use-command"); return true; } if(args.length < this.command.min() || (this.command.max() > 0 && args.length > this.command.max())) { sendUsage(sender, label, this.command.usage()); return true; } try { this.method.invoke(this.executor, sender, label, args); } catch(Throwable e) { sendMessage(sender, "internal.command-error"); ModuleManager.getLogger().log(Level.SEVERE, "Exception while executing Peacecraft command \"" + label + "\".", e); } return true; }
private ICommandListener getListener(CommandSender sender) { if (sender instanceof Player) { return ((CraftPlayer) sender).getHandle(); } if (sender instanceof BlockCommandSender) { return ((CraftBlockCommandSender) sender).getTileEntity(); } if (sender instanceof CommandMinecart) { return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock(); } if (sender instanceof RemoteConsoleCommandSender) { return RemoteControlCommandListener.getInstance(); } if (sender instanceof ConsoleCommandSender) { return ((CraftServer) sender.getServer()).getServer(); } if (sender instanceof ProxiedCommandSender) { return ((ProxiedNativeCommandSender) sender).getHandle(); } throw new IllegalArgumentException("Cannot make " + sender + " a vanilla command listener"); }
public static Object toNMSIComandSender(CommandSender s) { try { if (s instanceof Entity) { return getEntityByUUID(((Entity) s).getUniqueId()); } else if (s instanceof ConsoleCommandSender) { return getServer(); } else if (s instanceof RemoteConsoleCommandSender) { return getRemoteControlCommandListener(); } else if (s instanceof ProxiedCommandSender) { return getProxiedCommandSender((ProxiedCommandSender) s); } else if (s instanceof BlockCommandSender) { return getCommandBlockLogic(((BlockCommandSender) s).getBlock()); } else if (s instanceof CommandMinecart) { return getCommandBlockLogic((CommandMinecart) s); } return null; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public Locale localeForCommandSender(CommandSender sender) { if(sender instanceof BlockCommandSender) return commandBlockLocale; if(sender instanceof ConsoleCommandSender) return consoleLocale; if(sender instanceof RemoteConsoleCommandSender) return remoteConsoleLocale; if(sender instanceof Player) return LocaleUtils.toLocale(fetcher.getLocaleForPlayer((Player) sender)); return Locale.ENGLISH; }
protected final String getName(CommandSender sender) { if (sender instanceof BlockCommandSender) { BlockCommandSender commandBlock = (BlockCommandSender) sender; Location location = commandBlock.getBlock().getLocation(); return FormatUtil.format("CommandBlock ({0}, {1}, {2})", location.getBlockX(), location.getBlockY(), location.getBlockZ()); } else if (sender instanceof ConsoleCommandSender) { return "Console"; } else { return sender.getName(); } }
private MCCommandSender parseSender(CommandSender s, MCSubcommand mcsc){ if (mcsc.commandSender().equals(MCCommandSender.GENERIC) || mcsc.commandSender().equals(null)){ return MCCommandSender.GENERIC; } else if (s instanceof ConsoleCommandSender){ return MCCommandSender.CONSOLE; } else if (s instanceof Player){ return MCCommandSender.PLAYER; } else if (s instanceof RemoteConsoleCommandSender){ return MCCommandSender.REMOTE; } else if (s instanceof BlockCommandSender){ return MCCommandSender.COMMANDBLOCK; }else{ return MCCommandSender.GENERIC; } }
private ICommandListener getListener(CommandSender sender) { if (sender instanceof Player) { return ((CraftPlayer) sender).getHandle(); } if (sender instanceof BlockCommandSender) { return ((CraftBlockCommandSender) sender).getTileEntity(); } if (sender instanceof CommandMinecart) { return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock(); } if (sender instanceof RemoteConsoleCommandSender) { return ((DedicatedServer)MinecraftServer.getServer()).remoteControlCommandListener; } if (sender instanceof ConsoleCommandSender) { return ((CraftServer) sender.getServer()).getServer(); } if (sender instanceof ProxiedCommandSender) { return ((ProxiedNativeCommandSender) sender).getHandle(); } throw new IllegalArgumentException("Cannot make " + sender + " a vanilla command listener"); }
@Override public boolean canUse(CommandSender sender, boolean showMessage) { boolean passBlock = sender instanceof BlockCommandSender; if (!passBlock && showMessage) sender.sendMessage(ChatColor.RED + "This command can only be in a command block."); return passBlock; }
public static Location getLocation(CommandSender sender) { if (sender instanceof Entity) { return ((Entity)sender).getLocation(); } else if (sender instanceof BlockCommandSender) { return ((BlockCommandSender)sender).getBlock().getLocation().add(0.5f, 0.5f, 0.5f); } return null; }
private World getGameWorld(CommandSender sender) { if (sender instanceof HumanEntity) { World world = ((HumanEntity) sender).getWorld(); if (world != null) { return world; } } else if (sender instanceof BlockCommandSender) { return ((BlockCommandSender) sender).getBlock().getWorld(); } return Bukkit.getWorlds().get(0); }
public static void sendTo(CommandSender cs, char boxColor, String msg) { if (msg.substring(msg.length() - 1).equals("\n")) { msg = msg.substring(0, msg.length() - 1); } if (cs instanceof BlockCommandSender) { return; } String hLine; if (cs instanceof Player) { hLine = new StringBuilder() .append("§") .append(boxColor) .append("§m \n") .toString(); } else { hLine = new StringBuilder() .append("§") .append(boxColor) .append("--------------------------------------------------------------------------------\n") .toString(); } String[] lines = new StringBuilder() .append(hLine) .append(msg) .append('\n') .append(hLine) .toString().split("\n"); for (String line : lines) { cs.sendMessage(line); } }
@Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { if (!(sender instanceof BlockCommandSender)) { sender.sendMessage("§cError: This command can only be used from a command block. You can use add and remove, though it's not recommended."); return true; } if (args.length < 1) { return false; } StringBuilder sb1 = new StringBuilder(); for (int i1 = 1; i1 < args.length; i1++) { sb1.append(args[i1]); if (i1 != args.length - 1) sb1.append(" "); } String finalmessage1 = sb1.toString().replace('&', '§'); int index = Integer.parseInt(args[0]); if (index > 100) return false; while (PluginMain.AnnounceMessages.size() <= index) PluginMain.AnnounceMessages.add(""); PluginMain.AnnounceMessages.set(Integer.parseInt(args[0]), finalmessage1); sender.sendMessage("Announcement edited."); return true; }
public static String getDisplayName(CommandSender sender) { if(sender instanceof ConsoleCommandSender) { return ChatColor.GRAY + "CONSOLE" + ChatColor.WHITE; } else if(sender instanceof BlockCommandSender) { return ChatColor.GRAY + "@" + ChatColor.WHITE; } else if(sender instanceof Player) { return ((Player) sender).getDisplayName(); } else { return sender.getName(); } }
public static World getWorldByCommandSender(CommandSender sender) { if (sender instanceof Entity) { return ((Entity) sender).getWorld(); } else if (sender instanceof BlockCommandSender) { return ((BlockCommandSender) sender).getBlock().getWorld(); } else if (sender instanceof ProxiedCommandSender) { return getWorldByCommandSender(((ProxiedCommandSender) sender).getCaller()); } else { return null; } }
@Test public void test_sender_tester() { Command command = mock(Command.class); CommandSender commandSender = mock(CommandSender.class); Player player = mock(Player.class); BlockCommandSender bSender = mock(BlockCommandSender.class); String[] args = new String[0]; SenderTester tester = new SenderTester(); //test no senders specified - fail assertThat(tester.testCommand(command, commandSender, args)).isFalse(); //test with same class tester.add(CommandSender.class); assertThat(tester.testCommand(command, commandSender, args)).isTrue(); tester.clear(); tester.add(Player.class); assertThat(tester.testCommand(command, player, args)).isTrue(); //test with invalid class assertThat(tester.testCommand(command, bSender, args)).isFalse(); //test mutliclass tester.add(BlockCommandSender.class); assertThat(tester.testCommand(command, bSender, args)).isTrue(); assertThat(tester.testCommand(command, player, args)).isTrue(); //test inheritance tester.clear(); tester.add(CommandSender.class); assertThat(tester.testCommand(command, player, args)).isTrue(); assertThat(tester.testCommand(command, bSender, args)).isTrue(); }
@Override public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { String expression = strings[strings.length-1]; if (!expression.equals("id") && !expression.equals("id(")) return null; final Location location; if (commandSender instanceof Entity) { location = ((Entity) commandSender).getLocation(); } else if (commandSender instanceof BlockCommandSender) { location = ((BlockCommandSender) commandSender).getBlock().getLocation(); } else { location = null; } if (location != null) { List<String> result = new ArrayList<String>(); TreeSet<Entity> entities = new TreeSet<Entity>(new Comparator<Entity>() { @Override public int compare(Entity o1, Entity o2) { double d1 = o1.getLocation().distance(location); double d2 = o2.getLocation().distance(location); if (d1 < d2) return -1; else if (d1 > d2) return 1; return 0; } }); entities.addAll( location.getWorld().getEntities() ); for (Entity entity : entities) { if (entity == commandSender) continue; result.add("id("+entity.getEntityId()+"/*"+entity.getType()+"*/)"); } return result; } else { return null; } }
public static Object getSenderHashKey(CommandSender sender){ if (sender instanceof OfflinePlayer && usePlayerUniqueId) { return ((OfflinePlayer) sender).getUniqueId(); } else if (sender instanceof Entity && useEntityUniqueId) { return ((Entity) sender).getUniqueId(); } else if (sender instanceof BlockCommandSender) { return ((BlockCommandSender) sender).getBlock(); } return sender.getName(); }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof BlockCommandSender)) { plugin.sendPlayerError(sender, "This command may only be sent by command blocks."); return true; } if (args.length < 2) { plugin.getLogger().warning("Format: /grade @p 0.9"); return true; } Player player = getPlayer(args[0]); if (player == null) { plugin.getLogger().warning("Unrecognized player."); return true; } User user = User.byUuid(player.getUniqueId()); if (user == null) { plugin.getLogger().warning("Graded player not associated with an LTI user."); return true; } user.grade(args[1]); return true; }
public boolean isValidSender(CommandSender sender) { switch (this) { case PLAYER_ONLY: return (sender instanceof Player); case NO_PLAYER: return (sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender || sender instanceof BlockCommandSender); case CONSOLE_ONLY: return (sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender); case BLOCK_ONLY: return (sender instanceof BlockCommandSender); case DEFAULT: return true; } return false; }