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"; } }
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); } }