Java Code Examples for org.bukkit.entity.Player#getName()

The following examples show how to use org.bukkit.entity.Player#getName() . 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: CommandCombatLogX.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
private boolean tagPlayerCommand(CommandSender sender, String[] args) {
    if(checkNoPermission(sender, "combatlogx.command.combatlogx.tag")) return true;
    if(args.length < 1) return false;

    String targetName = args[0];
    Player target = getTarget(sender, targetName);
    if(target == null) return true;
    targetName = target.getName();

    ICombatManager combatManager = this.plugin.getCombatManager();
    boolean isTagged = combatManager.tag(target, null, PlayerPreTagEvent.TagType.UNKNOWN, PlayerPreTagEvent.TagReason.UNKNOWN);

    String messagePath = "commands.combatlogx." + (isTagged ? "tag-player" : "tag-player-fail");
    String message = this.plugin.getLanguageMessageColoredWithPrefix(messagePath).replace("{target}", targetName);

    this.plugin.sendMessage(sender, message);
    return true;
}
 
Example 2
Source File: Scoreboards.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Puts a player into a team of their own and sets the team suffix to be the level
 * @param playerUUID - the player's UUID
 */
public void setLevel(UUID playerUUID) {
    Player player = plugin.getServer().getPlayer(playerUUID);
    if (player == null) {
        // Player is offline...
        return;
    }
    // The default team name is their own name
    String teamName = player.getName();
    String level = String.valueOf(plugin.getPlayers().getIslandLevel(playerUUID));
    Team team = board.getTeam(teamName);
    if (team == null) {
        //Team does not exist
        team = board.registerNewTeam(teamName);
    }
    // Add the suffix
    team.setSuffix(Settings.teamSuffix.replace("[level]",String.valueOf(level)));
    //Adding player to team
    team.addPlayer(player);
    // Assign scoreboard to player
    player.setScoreboard(board);
}
 
Example 3
Source File: TabPlayer.java    From TAB with Apache License 2.0 6 votes vote down vote up
public TabPlayer(Player p) throws Exception {
	player = p;
	world = p.getWorld().getName();
	channel = (Channel) MethodAPI.getInstance().getChannel(player);
	tablistId = p.getUniqueId();
	uniqueId = p.getUniqueId();
	name = p.getName();
	int version;
	if (PluginHooks.protocolsupport){
		version = PluginHooks.ProtocolSupportAPI_getProtocolVersionId(this);
		if (version > 0) this.version = ProtocolVersion.fromNumber(version);
	} else if (PluginHooks.viaversion){
		version = PluginHooks.ViaVersion_getPlayerVersion(this);
		if (version > 0) this.version = ProtocolVersion.fromNumber(version);
	}
	init();
}
 
Example 4
Source File: CraftServer.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Deprecated
public List<Player> matchPlayer(String partialName) {
    Validate.notNull(partialName, "PartialName cannot be null");

    List<Player> matchedPlayers = new ArrayList<Player>();

    for (Player iterPlayer : this.getOnlinePlayers()) {
        String iterPlayerName = iterPlayer.getName();

        if (partialName.equalsIgnoreCase(iterPlayerName)) {
            // Exact match
            matchedPlayers.clear();
            matchedPlayers.add(iterPlayer);
            break;
        }
        if (iterPlayerName.toLowerCase().contains(partialName.toLowerCase())) {
            // Partial match
            matchedPlayers.add(iterPlayer);
        }
    }

    return matchedPlayers;
}
 
Example 5
Source File: PlayerComponent.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Get the player's prefix as a {@link Component}
 *
 * @param player The player
 * @return a component with a player's prefix
 */
static TextComponent.Builder getPrefixComponent(Player player) {
  String realName = player.getName();
  String displayName = player.getDisplayName();
  String prefix = displayName.substring(0, displayName.indexOf(realName) - 2);

  TextComponent.Builder prefixComponent = TextComponent.builder();
  boolean isColor = false;
  TextColor color = null;
  for (int i = 0; i < prefix.length(); i++) {
    if (prefix.charAt(i) == ChatColor.COLOR_CHAR) {
      isColor = true;
      continue;
    }

    if (isColor) {
      color = TextFormatter.convert(ChatColor.getByChar(prefix.charAt(i)));
      isColor = false;
    } else {
      prefixComponent.append(
          String.valueOf(prefix.charAt(i)), color != null ? color : TextColor.WHITE);
    }
  }

  return prefixComponent;
}
 
Example 6
Source File: WorldResourcepacks.java    From ResourcepacksPlugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ResourcepacksPlayer getPlayer(UUID playerId) {
    Player player = getServer().getPlayer(playerId);
    if(player != null) {
        return new ResourcepacksPlayer(player.getName(), player.getUniqueId());
    }
    return null;
}
 
Example 7
Source File: PlayerChat.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
private void spy(Player player, String message) {
    String spyMessage = ChatColor.GOLD + "[Spy] " + ChatColor.GRAY + player.getName() + ": " + ChatColor.WHITE + message;

    for (Player looped : Bukkit.getOnlinePlayers()) {
        if (User.get(looped).getCache().isSpy()) {
            looped.sendMessage(spyMessage);
        }
    }
}
 
Example 8
Source File: PluginHooks.java    From TAB with Apache License 2.0 5 votes vote down vote up
public static String PlaceholderAPI_setPlaceholders(Player player, String placeholder) {
	if (!placeholderAPI) return placeholder;
	try {
		return PlaceholderAPI.setPlaceholders(player, placeholder);
	} catch (Throwable t) {
		String playername = (player == null ? "null" : player.getName());
		Plugin papi = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
		if (papi != null) {
			Shared.errorManager.printError("PlaceholderAPI v" + papi.getDescription().getVersion() + " generated an error when setting placeholder " + placeholder + " for player " + playername, t, false, Configs.papiErrorFile);
		} else {
			placeholderAPI = false;
		}
		return "ERROR";
	}
}
 
Example 9
Source File: PetManager.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
private static String noPrimaryPetErrorMessage(UUID playerId, Set<IPet> secondaryPets) {
    Player player = Bukkit.getPlayer(playerId);
    String playerStr = player != null ? player.getName() : playerId.toString();
    return playerStr +
            " has no primary pet, but has secondary pets: " +
            secondaryPets.stream()
                    .map(IPet::toString)
                    .collect(Collectors.joining(",", "{", "}"));
}
 
Example 10
Source File: ExploitPlayerManager.java    From ExploitFixer with GNU General Public License v3.0 5 votes vote down vote up
public ExploitPlayer get(final Player player) {
	final UUID uuid = player.getUniqueId();
	final ExploitPlayer exploitPlayer;

	if (exploitPlayers.containsKey(uuid)) {
		exploitPlayer = exploitPlayers.get(uuid);
	} else {
		exploitPlayer = new ExploitPlayer(this.plugin, player.getName(), moduleManager);
		exploitPlayers.put(uuid, exploitPlayer);
	}

	return exploitPlayer;
}
 
Example 11
Source File: RandomTeleport.java    From RandomTeleport with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Run a preset
 * @param sender The sender that executed the preset
 * @param preset The preset ID to run
 * @param target The player targeted by the teleporter
 * @param center The center for the search
 * @return The RandomSearcher instance that is searching
 */
public RandomSearcher runPreset(CommandSender sender, String preset, Player target, Location center) {
    String cmd = getConfig().getString("presets." + preset) + " -p " + target.getName();
    if (!cmd.contains("-id")) {
        cmd += " -id " + preset;
    }
    if (cmd.startsWith("/")) {
        cmd = cmd.substring(1);
    }
    if (cmd.startsWith("rtp ")) {
        cmd = cmd.substring(4);
    }
    return parseAndRun(sender, center, cmd.split(" "));
}
 
Example 12
Source File: CommandBase.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public Resident getResident() throws CivException {
	Player player = getPlayer();
	Resident res = CivGlobal.getResident(player);
	if (res == null) {
		throw new CivException("Resident "+player.getName()+" could not be found.");
	}
	return res;
}
 
Example 13
Source File: ShopkeepersPlugin.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
void onPlayerQuit(Player player) {
	String playerName = player.getName();
	shopTypesManager.clearSelection(player);
	shopObjectTypesManager.clearSelection(player);
	uiManager.onInventoryClose(player);

	selectedChest.remove(playerName);
	recentlyPlacedChests.remove(playerName);
	naming.remove(playerName);
	this.endConfirmation(player);
}
 
Example 14
Source File: InventoryHolderStorage.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public InventoryHolderStorage(InventoryHolder holder, Location holderLocation) {
	if (holder instanceof Player) {
		Player player = (Player)holder;
		playerName = player.getName();
		blockLocation = null;
	} else {
		blockLocation = holderLocation;
	}
}
 
Example 15
Source File: ExhibitionFrame.java    From NyaaUtils with MIT License 5 votes vote down vote up
public void set(Player owner) {
    if (isSet()) return;
    baseItem = frame.getItem().clone();
    ownerUUID = owner.getUniqueId().toString();
    ownerName = owner.getName();
    descriptions = new ArrayList<>();
    itemSet = true;
    encodeItem();
}
 
Example 16
Source File: TimebombListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.HIGHEST)
public void onPlayerDeath(PlayerDeathEvent e) {
    Player p = e.getEntity().getPlayer();
    List<ItemStack> drops = new ArrayList<>(e.getDrops());
    e.getDrops().removeAll(e.getDrops());

    TimebombThread timebombThread = new TimebombThread(drops, p.getLocation().getBlock().getLocation(), p.getName(), delay);
    Bukkit.getScheduler().scheduleSyncDelayedTask(UhcCore.getPlugin(), timebombThread,1L);
}
 
Example 17
Source File: CommandManager.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s,
						 @NotNull String[] args) {
	if (!(sender.hasPermission("minetinker.commands.main"))) {
		sendError(sender, LanguageManager.getString("Commands.Failure.Cause.NoPermission"));
		return true;
	}

	if (args.length <= 0) {
		sendError(sender, LanguageManager.getString("Commands.Failure.Cause.InvalidArguments"));
		sendHelp(sender, null);
		return true;
	}

	if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
		sendHelp(sender, args.length >= 2 ? map.get(args[1].toLowerCase()) : null);
		return true;
	}

	SubCommand sub = map.get(args[0].toLowerCase());
	if (sub == null) {
		sendError(sender, LanguageManager.getString("Commands.Failure.Cause.UnknownCommand"));
		sendHelp(sender, null);
		return true;
	}

	parseArguments(sender, sub, args);

	//@all / @allworld
	{
		int index = -1;
		boolean worldOnly = false;
		for (int i = 0; i < args.length; i++) {
			List<ArgumentType> types = sub.getArgumentsToParse().get(i);
			if (types != null && types.contains(ArgumentType.PLAYER)) {
				if (args[i].startsWith("@aw")) {
					index = i;
					worldOnly = true;
					break;
				} else if (args[i].startsWith("@a")) {
					index = i;
					break;
				}
			}
		}
		if (index != -1) {
			Collection<? extends Player> players;
			if (worldOnly) {
				World world = null;
				if (sender instanceof BlockCommandSender) {
					world = ((BlockCommandSender) sender).getBlock().getWorld();
				} else if (sender instanceof Entity) {
					world = ((Entity) sender).getWorld();
				}

				if (world == null) return true;
				players = world.getPlayers();
			} else {
				players = Bukkit.getOnlinePlayers();
			}

			boolean ret = true;
			for (Player player : players) {
				String[] arg = args.clone();
				arg[index] = player.getName();
				ret = ret && onCommand(sender, command, s, arg);
			}
		}
	}

	if (!sender.hasPermission(sub.getPermission())) {
		sendError(sender, LanguageManager.getString("Commands.Failure.Cause.NoPermission"));
		return true;
	}

	return sub.onCommand(sender, args);
}
 
Example 18
Source File: Blacksmith.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public String getkey(Player player, Structure struct, String tag) {
	return player.getName()+"_"+struct.getConfigId()+"_"+struct.getCorner().toString()+"_"+tag; 
}
 
Example 19
Source File: VanishOther.java    From SuperVanish with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void execute(Command cmd, CommandSender sender, String[] args, String label) {
    if (canDo(sender, CommandAction.VANISH_OTHER, true)) {
        boolean hide = false, offline = false, silent = false;
        Player target;
        String name;
        UUID uuid;
        if (specifiedPlayer == null) {
            if (args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("enable")
                    || args[0].equalsIgnoreCase("vanish"))
                hide = true;
            target = Bukkit.getPlayer(args[1]);
            name = target == null ? args[1] : target.getName();
        } else {
            target = specifiedPlayer;
            name = specifiedPlayer.getName();
            hide = !isVanished(target.getUniqueId());
        }
        if (target == null) {
            offline = true;
            uuid = plugin.getVanishStateMgr().getVanishedUUIDFromNameOnFile(name);
            if (uuid == null) {
                plugin.sendMessage(sender, "PlayerNonExistent", sender, name);
                return;
            }
        } else {
            name = target.getName();
            uuid = target.getUniqueId();
        }
        if (!offline && sender instanceof Player && sender != target
                && target.hasPermission("sv.notoggle")) {
            plugin.sendMessage(sender, "CannotHideOtherPlayer", sender, name);
            return;
        }
        if (plugin.getSettings().getBoolean(
                "IndicationFeatures.LayeredPermissions.HideInvisibleInCommands", false) && target != null
                && sender instanceof Player && !plugin.hasPermissionToSee((Player) sender, target)) {
            plugin.sendMessage(sender, "PlayerNonExistent", sender, name);
            return;
        }
        if (hide && (offline ? isVanished(uuid) : isVanished(uuid))) {
            plugin.sendMessage(sender, "AlreadyInvisibleMessage", sender, name);
            return;
        } else if (!hide && !(offline ? isVanished(uuid) : isVanished(uuid))) {
            plugin.sendMessage(sender, "AlreadyVisibleMessage", sender, name);
            return;
        }
        if (args.length == 3)
            silent = args[2].equalsIgnoreCase("-s");
        else if (args.length == 2)
            silent = args[1].equalsIgnoreCase("-s");
        if (!offline) {
            if (hide) {
                plugin.getVisibilityChanger().hidePlayer(target, sender.getName(), silent);
                plugin.sendMessage(sender, "HideOtherMessage", sender, name);
            } else {
                plugin.getVisibilityChanger().showPlayer(target, sender.getName());
                plugin.sendMessage(sender, "ShowOtherMessage", sender, name, silent);
            }
        } else {
            if (hide) {
                plugin.getVanishStateMgr().setVanishedState(uuid, name, true, sender.getName());
                plugin.sendMessage(sender, "HideOtherMessage", sender, name);
            } else {
                plugin.getVanishStateMgr().setVanishedState(uuid, name, false, sender.getName());
                plugin.sendMessage(sender, "ShowOtherMessage", sender, name);
            }
        }
    }
}
 
Example 20
Source File: Util.java    From EnchantmentsEnhance with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets a player's username as a string.
 *
 * @param player
 * @return
 */
public static String getPlayerUsername(Player player) {
    return player.getName();
}