Java Code Examples for org.bukkit.OfflinePlayer#getUniqueId()
The following examples show how to use
org.bukkit.OfflinePlayer#getUniqueId() .
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: CachingReadWriteHandler.java From HeavySpleef with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @Override public Statistic getStatistic(String playerName) throws Exception { GameProfile profile; try { profile = uuidManager.getProfile(playerName); } catch (ExecutionException e) { logger.log(Level.SEVERE, "Could not retrieve player uuid from mojang api, using OfflinePlayer#getUniqueId()", e); OfflinePlayer player = Bukkit.getOfflinePlayer(playerName); profile = new GameProfile(player.getUniqueId(), player.getName()); } Statistic statistic = getStatistic(profile.getUniqueIdentifier()); statistic.setLastName(playerName); return statistic; }
Example 2
Source File: GeneralRegion.java From AreaShop with GNU General Public License v3.0 | 6 votes |
/** * Get the landlord of this region (the player that receives any revenue from this region). * @return The UUID of the landlord of this region */ public UUID getLandlord() { String landlord = getStringSetting("general.landlord"); if(landlord != null && !landlord.isEmpty()) { try { return UUID.fromString(landlord); } catch(IllegalArgumentException e) { // Incorrect UUID } } String landlordName = getStringSetting("general.landlordName"); if(landlordName != null && !landlordName.isEmpty()) { @SuppressWarnings("deprecation") OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(landlordName); if(offlinePlayer != null) { return offlinePlayer.getUniqueId(); } } return null; }
Example 3
Source File: ClickType.java From ShopChest with MIT License | 6 votes |
/** * Sets the click type of a player and removes it after 15 seconds * * @param player Player whose click type should be set * @param clickType Click type to set */ public static void setPlayerClickType(OfflinePlayer player, ClickType clickType) { UUID uuid = player.getUniqueId(); if (playerClickType.get(uuid) instanceof SelectClickType && player instanceof Player) { // Reset gamemode player has select click type ((Player) player).setGameMode(((SelectClickType) playerClickType.get(uuid)).gameMode); } playerClickType.put(uuid, clickType); // If a timer is already running, cancel it Optional.ofNullable(playerTimers.get(uuid)).ifPresent(task -> task.cancel()); if (clickType.getClickType() != EnumClickType.SELECT_ITEM) { // Remove ClickType after 15 seconds if player has not clicked a chest playerTimers.put(uuid, new BukkitRunnable() { @Override public void run() { playerClickType.remove(uuid); } }.runTaskLater(ShopChest.getInstance(), 300)); } }
Example 4
Source File: PlaceholderReplacerImpl.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@Override public String replace(OfflinePlayer offlinePlayer, Player player, String placeholder) { if (placeholder == null || !placeholder.startsWith("usb_")) { return null; } UUID uuid = player != null ? player.getUniqueId() : null; if (uuid == null && offlinePlayer != null) { uuid = offlinePlayer.getUniqueId(); } if (uuid == null) { return null; } CacheEntry cacheKey = new CacheEntry(uuid, placeholder); try { return cache.get(cacheKey); } catch (ExecutionException e) { return null; } }
Example 5
Source File: VaultHook.java From SaneEconomy with GNU General Public License v3.0 | 5 votes |
public boolean hasPermission(OfflinePlayer offlinePlayer, String permNode) { RegisteredServiceProvider<Permission> rsp = this.plugin.getServer().getServicesManager().getRegistration(Permission.class); if ((offlinePlayer == null) || (offlinePlayer.getUniqueId() == null) || Strings.isNullOrEmpty(offlinePlayer.getName())) { return false; } return (rsp != null) && rsp.getProvider().playerHas(null, offlinePlayer, permNode); }
Example 6
Source File: FilePlayerDB.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Override public UUID getUUIDFromName(String name, boolean lookup) { if (name2uuidCache.containsKey(name)) { return name2uuidCache.get(name); } UUID result = null; if (lookup) { //noinspection deprecation OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); updatePlayer(offlinePlayer.getUniqueId(), offlinePlayer.getName(), offlinePlayer.getName()); result = offlinePlayer.getUniqueId(); } name2uuidCache.put(name, result); return result; }
Example 7
Source File: ChannelPlayerUUID.java From LunaChat with GNU Lesser General Public License v3.0 | 5 votes |
/** * プレイヤー名からUUIDを取得してChannelPlayerUUIDを作成して返す * @param name プレイヤー名 * @return ChannelPlayerUUID */ public static ChannelPlayerUUID getChannelPlayerUUIDFromName(String name) { Player player = Bukkit.getPlayerExact(name); if ( player != null ) { return new ChannelPlayerUUID(player.getUniqueId()); } OfflinePlayer offline = Bukkit.getOfflinePlayer(name); if ( offline != null && offline.getUniqueId() != null ) { return new ChannelPlayerUUID(offline.getUniqueId()); } return null; }
Example 8
Source File: UUIDMigration.java From SonarPet with GNU General Public License v3.0 | 5 votes |
/** * Returns the identification for a given player * * @param player player to fetch a UUID for * @param enableFetching if set to true, the UUID will be fetched from Mojang if {@code player} is offline * @return identification for the given player */ public static Object getIdentificationFor(OfflinePlayer player, boolean enableFetching) { if (player instanceof Player) { if (supportsUuid()) { return player.getUniqueId(); } return player.getName(); } else { if (enableFetching) { return getIdentificationFor(player.getName()); } return null; } }
Example 9
Source File: InviteHandler.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public synchronized boolean uninvite(IslandInfo islandInfo, String playerName) { if (Bukkit.isPrimaryThread()) { throw new UnsupportedOperationException("This method cannot be called in the primary thread!"); } OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(playerName); if (offlinePlayer != null) { UUID uuid = offlinePlayer.getUniqueId(); return uninvite(islandInfo, uuid); } return false; }
Example 10
Source File: PurgeExecutor.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Removes the Essentials userdata file of each given player. * * @param cleared list of players to clear */ synchronized void purgeEssentials(Collection<OfflinePlayer> cleared) { if (!settings.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES)) { return; } File essentialsDataFolder = pluginHookService.getEssentialsDataFolder(); if (essentialsDataFolder == null) { logger.info("Cannot purge Essentials: plugin is not loaded"); return; } final File userDataFolder = new File(essentialsDataFolder, "userdata"); if (!userDataFolder.exists() || !userDataFolder.isDirectory()) { return; } int deletedFiles = 0; for (OfflinePlayer offlinePlayer : cleared) { File playerFile = new File(userDataFolder, offlinePlayer.getUniqueId() + ".yml"); if (playerFile.exists() && playerFile.delete()) { deletedFiles++; } } logger.info("AutoPurge: Removed " + deletedFiles + " EssentialsFiles"); }
Example 11
Source File: RegionAccessSet.java From AreaShop with GNU General Public License v3.0 | 5 votes |
/** * Get this access set as a list of player UUIDs. * @return List of player UUIDs, first players already added by UUID, then players added by name, groups are not in the list */ public List<UUID> asUniqueIdList() { List<UUID> result = new ArrayList<>(); result.addAll(playerUniqueIds); for(String playerName : playerNames) { OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName); if(offlinePlayer != null && offlinePlayer.getUniqueId() != null) { result.add(offlinePlayer.getUniqueId()); } } return result; }
Example 12
Source File: MsgUtil.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
/** * Empties the queue of messages a player has and sends them to the player. * * @param p The player to message * @return True if success, False if the player is offline or null */ public static boolean flush(@NotNull OfflinePlayer p) { Player player = p.getPlayer(); if (player != null) { UUID pName = p.getUniqueId(); LinkedList<String> msgs = player_messages.get(pName); if (msgs != null) { for (String msg : msgs) { if (p.getPlayer() != null) { Util.debugLog("Accepted the msg for player " + p.getName() + " : " + msg); String[] msgData = msg.split("##########"); try { ItemStack data = Util.deserialize(msgData[1]); if (data == null) { throw new InvalidConfigurationException(); } sendItemholochat(player, msgData[0], data, msgData[2]); } catch (InvalidConfigurationException e) { MsgUtil.sendMessage(p.getPlayer(), msgData[0] + msgData[1] + msgData[2]); } catch (ArrayIndexOutOfBoundsException e2) { MsgUtil.sendMessage(p.getPlayer(), msg); } } } plugin.getDatabaseHelper().cleanMessageForPlayer(pName); msgs.clear(); return true; } } return false; }
Example 13
Source File: UUIDRegistry.java From Modern-LWC with MIT License | 4 votes |
/** * Get the UUID for the given name. If it is not already known, it will be retrieved from the account servers. * * @param name * @return * @throws Exception */ @SuppressWarnings("deprecation") public static UUID getUUID(String name) { String nameLower = name.toLowerCase(); try { if (nameToUUIDCache.containsKey(nameLower)) { return nameToUUIDCache.get(nameLower).getUUID(); } if (isValidUUID(name)) { return UUID.fromString(name); } if (Bukkit.getOnlineMode()) { Map<String, UUID> results = new UUIDFetcher(Arrays.asList(nameLower)).call(); // The returned name is the exact casing; so we need to look for it // in the case-insensitive version for (String key : results.keySet()) { if (key.equalsIgnoreCase(name)) { UUID uuid = results.get(key); updateCache(uuid, key); return uuid; } } } else { OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); if (offlinePlayer != null && offlinePlayer.getUniqueId() != null) { if (offlinePlayer.getName() != null) { name = offlinePlayer.getName(); } updateCache(offlinePlayer.getUniqueId(), name); return offlinePlayer.getUniqueId(); } } nameToUUIDCache.put(nameLower, null); return null; } catch (Exception e) { nameToUUIDCache.put(nameLower, null); return null; } }
Example 14
Source File: MysteryCrate.java From CratesPlus with GNU General Public License v3.0 | 4 votes |
public boolean give(OfflinePlayer offlinePlayer, Integer amount) { CratesPlus cratesPlus = getCratesPlus(); UUID uuid = offlinePlayer.getUniqueId(); cratesPlus.getStorageHandler().incPlayerData(uuid, "Crates-" + getName(false), amount); return true; }
Example 15
Source File: CraftMetaSkull.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public boolean setOwningPlayer(OfflinePlayer owner) { profile = (owner == null) ? null : new GameProfile(owner.getUniqueId(), owner.getName()); return true; }
Example 16
Source File: PlayerStatistic.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
public PlayerStatistic(OfflinePlayer player) { this.uuid = player.getUniqueId(); this.name = player.getName(); }
Example 17
Source File: BackpackConverter.java From PlayerVaults with GNU General Public License v3.0 | 4 votes |
private int convert(File worldFolder, int intoVaultNum) { PlayerVaults plugin = PlayerVaults.getInstance(); VaultManager vaults = VaultManager.getInstance(); int converted = 0; long lastUpdate = 0; File[] files = worldFolder.listFiles(); for (File file : files != null ? files : new File[0]) { if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) { try { OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().substring(0, file.getName().lastIndexOf('.'))); if (player == null || player.getUniqueId() == null) { plugin.getLogger().warning("Unable to convert Backpack for player: " + (player != null ? player.getName() : file.getName())); } else { UUID uuid = player.getUniqueId(); FileConfiguration yaml = YamlConfiguration.loadConfiguration(file); ConfigurationSection section = yaml.getConfigurationSection("backpack"); if (section.getKeys(false).size() <= 0) { continue; // No slots } Inventory vault = vaults.getVault(uuid.toString(), intoVaultNum); if (vault == null) { vault = plugin.getServer().createInventory(null, section.getKeys(false).size()); } for (String key : section.getKeys(false)) { ConfigurationSection slotSection = section.getConfigurationSection(key); ItemStack item = slotSection.getItemStack("ItemStack"); if (item == null) { continue; } // Overwrite vault.setItem(Integer.parseInt(key.split(" ")[1]), item); } vaults.saveVault(vault, uuid.toString(), intoVaultNum); converted++; if (System.currentTimeMillis() - lastUpdate >= 1500) { plugin.getLogger().info(converted + " backpacks have been converted in " + worldFolder.getAbsolutePath()); lastUpdate = System.currentTimeMillis(); } } } catch (Exception e) { plugin.getLogger().warning("Error converting " + file.getAbsolutePath()); e.printStackTrace(); } } } return converted; }
Example 18
Source File: PlayerStatistic.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
public PlayerStatistic(OfflinePlayer player) { this.uuid = player.getUniqueId(); this.name = player.getName(); }
Example 19
Source File: NPCManager.java From CombatLogX with GNU General Public License v3.0 | 4 votes |
public NPC getNPC(OfflinePlayer player) { if(player == null) return null; UUID uuid = player.getUniqueId(); return getNPC(uuid); }
Example 20
Source File: MemoryPlayerDB.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
@Override public UUID getUUIDFromName(String name, boolean lookup) { OfflinePlayer offlinePlayer = getOfflinePlayer(name, lookup); return offlinePlayer != null ? offlinePlayer.getUniqueId() : null; }