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); }
protected void setCommandSender(CommandSender sender) { if (sender != null) { this.commandSenderRef = new WeakReference<>(sender); if (sender instanceof BlockCommandSender) { BlockCommandSender commandBlock = (BlockCommandSender) sender; playerName = commandBlock.getName(); Location location = getLocation(); if (location == null) { location = commandBlock.getBlock().getLocation(); } else { Location blockLocation = commandBlock.getBlock().getLocation(); location.setX(blockLocation.getX()); location.setY(blockLocation.getY()); location.setZ(blockLocation.getZ()); } setLocation(location, false); } else { setLocation(null); } } else { this.commandSenderRef.clear(); setLocation(null); } }
public String fromCommandSender(CommandSender commandSender) { Preconditions.checkArgument( !(commandSender instanceof Player), "fromCommandSender does not accept a player argument: %s", commandSender); if (commandSender instanceof ConsoleCommandSender) { return "CONSOLE"; } else if (commandSender instanceof BlockCommandSender) { BlockCommandSender commandBlock = (BlockCommandSender) commandSender; String commandName = commandBlock.getName(); if (commandName != null && commandName.length() > 0) { return "COMMAND-" + commandBlock.getName(); } } return "COMMAND"; } }
/** * Gets the location that is "~ ~ ~" for a command sender. * * @param sender a command sender * @return the sender's location if the sender is a block or entity, or the default world's * coordinate origin otherwise. */ public static Location getLocation(CommandSender sender) { if (sender instanceof Entity) { return ((Entity) sender).getLocation(); } else if (sender instanceof BlockCommandSender) { return ((BlockCommandSender) sender).getBlock().getLocation(); } return new Location(getDefaultWorld(), 0, 0, 0); }
/** * Returns the world that the given command sender is referring to when not specifying one. * * @param sender a command sender * @return the command sender's world if the sender is a block or entity, or the default world * otherwise */ public static GlowWorld getWorld(CommandSender sender) { if (sender instanceof ConsoleCommandSender) { return getDefaultWorld(); } else if (sender instanceof Entity) { return (GlowWorld) ((Entity) sender).getWorld(); } else if (sender instanceof BlockCommandSender) { return (GlowWorld) ((BlockCommandSender) sender).getBlock().getWorld(); } return getDefaultWorld(); }
&& CommandUtils.isPhysical(sender)) { final Location location = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); final Entity[] entities = new CommandTarget(sender, args[1]).getMatched(location); targets = new ArrayList<>();
BlockCommandSender blockCommandSender = (BlockCommandSender) source; if (blockCommandSender.getBlock().getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) { Bukkit.getConsoleSender().sendMessage(result); return;
: ((BlockCommandSender) sender).getBlock().getLocation(); final Entity[] entities = new CommandTarget(sender, args[0]).getMatched(location); targets = new ArrayList<>(); } else { currentLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); if (CommandUtils.isPhysical(sender)) { spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); } else { sender.sendMessage(ChatColor.RED
if (name.startsWith("@") && name.length() >= 2 && CommandUtils.isPhysical(sender)) { Location location = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); CommandTarget target = new CommandTarget(sender, name); Entity[] matched = target.getMatched(location);
if (CommandUtils.isPhysical(sender)) { spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); } else { sender.sendMessage(ChatColor.RED } else { senderLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation();
if (name.startsWith("@") && name.length() >= 2 && CommandUtils.isPhysical(sender)) { Location location = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); CommandTarget target = new CommandTarget(sender, name); Entity[] matched = target.getMatched(location);
@Override public MCBlock getBlock() { return new BukkitMCBlock(bcs.getBlock()); }
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); }
/** * If the sender has a location (it is a player or a command block), this * method returns their location. If not, this method returns null. * * @param sender * The sender. * @return The location, or null if not found. */ protected Location getLocation(CommandSender sender) { if (sender instanceof Player) { return ((Player) sender).getLocation(); } if (sender instanceof BlockCommandSender) { return ((BlockCommandSender) sender).getBlock().getLocation(); } return null; }
public Location getSenderTargetBlockLocation() { if (sender == null) return location; if (sender instanceof Player) location = ((Player) sender).getTargetBlock((java.util.Set<org.bukkit.Material>) null, 50).getLocation(); else if (sender instanceof BlockCommandSender) location = ((BlockCommandSender) sender).getBlock().getLocation(); return location; }
/** * Try to extract the world of a command sender. * * @param sender command sender * @return world or null */ public static World extractWorld(CommandSender sender) { if (sender instanceof Player) { return ((Player) sender).getWorld(); } else if (sender instanceof BlockCommandSender) { return ((BlockCommandSender) sender).getBlock().getWorld(); } else { return BasePlugin.server().getWorlds().get(0); } }
private Collection<Entity> getNearbyEntities(CommandSender sender, int radius) { Location center; if (sender instanceof Player) { center = ((Player) sender).getLocation(); } else { center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); } return center.getWorld().getNearbyEntities(center, radius, radius, radius); }
public Location getSenderLocation() throws CommandException { if (location != null || sender == null) return location; if (sender instanceof Player) location = ((Player) sender).getLocation(); else if (sender instanceof BlockCommandSender) location = ((BlockCommandSender) sender).getBlock().getLocation(); if (hasValueFlag("location")) { location = parseLocation(location, getFlag("location")); } return location; }
BlockCommandSender blockCommandSender = (BlockCommandSender) source; if (blockCommandSender.getBlock().getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) { Bukkit.getConsoleSender().sendMessage(result); return;
targetLocation = player.getLocation(); } else if (commandBlock != null) { targetLocation = commandBlock.getBlock().getLocation(); } else { sender.sendMessage(ChatColor.RED + "Invalid world: " + args[2]); targetLocation = player.getLocation(); } else if (commandBlock != null) { targetLocation = commandBlock.getBlock().getLocation();