Java Code Examples for org.bukkit.OfflinePlayer#getName()

The following examples show how to use org.bukkit.OfflinePlayer#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: LuckPermsHandler.java    From AuthMeReloaded with GNU General Public License v3.0 8 votes vote down vote up
@Override
public boolean addToGroup(OfflinePlayer player, String group) {
    Group newGroup = luckPerms.getGroupManager().getGroup(group);
    if (newGroup == null) {
        return false;
    }

    String playerName = player.getName();
    if (playerName == null) {
        return false;
    }
    User user = luckPerms.getUserManager().getUser(playerName);
    if (user == null) {
        return false;
    }

    InheritanceNode node = InheritanceNode.builder(group).build();
    DataMutateResult result = user.data().add(node);
    if (result == DataMutateResult.FAIL) {
        return false;
    }

    luckPerms.getUserManager().saveUser(user);
    return true;
}
 
Example 2
Source File: PlayerProfile.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private PlayerProfile(OfflinePlayer p) {
    this.uuid = p.getUniqueId();
    this.name = p.getName();

    configFile = new Config(new File("data-storage/Slimefun/Players/" + uuid.toString() + ".yml"));
    waypointsFile = new Config("data-storage/Slimefun/waypoints/" + uuid.toString() + ".yml");

    for (Research research : SlimefunPlugin.getRegistry().getResearches()) {
        if (configFile.contains("researches." + research.getID())) {
            researches.add(research);
        }
    }

    for (String key : waypointsFile.getKeys()) {
        try {
            if (waypointsFile.contains(key + ".world") && Bukkit.getWorld(waypointsFile.getString(key + ".world")) != null) {
                String waypointName = waypointsFile.getString(key + ".name");
                Location loc = waypointsFile.getLocation(key);
                waypoints.add(new Waypoint(this, key, loc, waypointName));
            }
        }
        catch (Exception x) {
            Slimefun.getLogger().log(Level.WARNING, x, () -> "Could not load Waypoint \"" + key + "\" for Player \"" + p.getName() + '"');
        }
    }
}
 
Example 3
Source File: PlayerMenu.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean doActionAndCancel(Civilian civilian, String actionString, ItemStack clickedItem) {
    UUID uuid = ((UUID) MenuManager.getData(civilian.getUuid(), Constants.UUID));
    Player player = Bukkit.getPlayer(civilian.getUuid());
    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
    String name = offlinePlayer.getName();
    if (name == null) {
        name = "Unknown";
    }
    if ("add-friend".equals(actionString)) {
        civilian.getFriends().add(uuid);
        CivilianManager.getInstance().saveCivilian(civilian);
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player,
                "friend-added").replace("$1", name));
        return true;
    } else if ("remove-friend".equals(actionString)) {
        civilian.getFriends().remove(uuid);
        CivilianManager.getInstance().saveCivilian(civilian);
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player,
                "friend-removed").replace("$1", name));
        return true;
    }
    return super.doActionAndCancel(civilian, actionString, clickedItem);
}
 
Example 4
Source File: CachingReadWriteHandler.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@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 5
Source File: CommandClaimFlagPlayer.java    From GriefDefender with MIT License 6 votes vote down vote up
@CommandCompletion("@gdplayers @gdflags @gdmcids @gdtristates @gdcontexts @gddummy")
@CommandAlias("cfp")
@Description("Gets/Sets flag permission for a player in claim you are standing in.")
@Syntax("<player> <flag> <target> <value> [context[key=value]]")
@Subcommand("flag player")
public void execute(Player src, OfflinePlayer player, @Optional String[] args) throws InvalidCommandArgument {
    this.subject = PermissionHolderCache.getInstance().getOrCreateUser(player);
    this.friendlySubjectName = player.getName();

    if (src.hasPermission(GDPermissions.COMMAND_ADMIN_CLAIMS) && !src.hasPermission(GDPermissions.SET_ADMIN_FLAGS)) {
        GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().PERMISSION_PLAYER_ADMIN_FLAGS);
        return;
    }

    super.execute(src, args);
}
 
Example 6
Source File: TradeLog.java    From TradePlus with GNU General Public License v3.0 6 votes vote down vote up
public TradeLog(
    OfflinePlayer player1,
    OfflinePlayer player2,
    List<ItemFactory> player1Items,
    List<ItemFactory> player2Items,
    List<ExtraOffer> player1ExtraOffers,
    List<ExtraOffer> player2ExtraOffers) {
  this.player1 = new Trader(player1.getUniqueId(), player1.getName());
  this.player2 = new Trader(player2.getUniqueId(), player2.getName());
  player1Items.sort((o1, o2) -> Integer.compare(o2.getAmount(), o1.getAmount()));
  this.player1Items = player1Items;
  player2Items.sort((o1, o2) -> Integer.compare(o2.getAmount(), o1.getAmount()));
  this.player2Items = player2Items;
  this.player1ExtraOffers = player1ExtraOffers;
  this.player2ExtraOffers = player2ExtraOffers;
  this.time = new Date();
}
 
Example 7
Source File: NovaPlayerImpl.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addMoney(double money) {
	OfflinePlayer oPlayer = CompatibilityUtils.getOfflinePlayer(getUUID());

	if(!oPlayer.hasPlayedBefore() || oPlayer.getName() == null) {
		return;
	}

	NovaGuilds.getInstance().getDependencyManager().getEconomy().depositPlayer(oPlayer, money);
}
 
Example 8
Source File: PlayerVaults.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tries to get a name from a given String that we hope is a UUID.
 *
 * @param potentialUUID - potential UUID to try to get the name for.
 * @return the player's name if we can find it, otherwise return what got passed to us.
 */
public String getNameIfPlayer(String potentialUUID) {
    UUID uuid;
    try {
        uuid = UUID.fromString(potentialUUID);
    } catch (Exception e) {
        return potentialUUID;
    }

    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
    return offlinePlayer != null ? offlinePlayer.getName() : potentialUUID;
}
 
Example 9
Source File: SkullItem.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public SkullItem(OfflinePlayer player) {
	super(new ItemStack(MaterialHook.parse("PLAYER_HEAD", "SKULL_ITEM")));
	this.owner = player.getName();
	SkullMeta meta = (SkullMeta) getItemMeta();
	meta.setOwningPlayer(player);
	setItemMeta(meta);
}
 
Example 10
Source File: ChannelPlayerUUID.java    From LunaChat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * プレイヤー名を返す
 * @return プレイヤー名
 * @see com.github.ucchyocean.lc.channel.ChannelPlayer#getName()
 */
@Override
public String getName() {
    Player player = Bukkit.getPlayer(id);
    if ( player != null ) {
        return player.getName();
    }
    OfflinePlayer offlineplayer = Bukkit.getOfflinePlayer(id);
    if ( offlineplayer != null ) {
        String name = offlineplayer.getName();
        return name;
    }
    return id.toString();
}
 
Example 11
Source File: LuckPermsHandler.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setGroup(OfflinePlayer player, String group) {
    String playerName = player.getName();
    if (playerName == null) {
        return false;
    }
    User user = luckPerms.getUserManager().getUser(playerName);
    if (user == null) {
        logger.warning("LuckPermsHandler: tried to set group for offline user "
            + player.getName() + " but it isn't loaded!");
        return false;
    }
    InheritanceNode groupNode = InheritanceNode.builder(group).build();
    DataMutateResult result = user.data().add(groupNode);
    if (result == DataMutateResult.FAIL) {
        return false;
    }
    user.data().clear(node -> {
        if (!(node instanceof InheritanceNode)) {
            return false;
        }
        InheritanceNode inheritanceNode = (InheritanceNode) node;
        return !inheritanceNode.equals(groupNode);
    });

    luckPerms.getUserManager().saveUser(user);
    return true;
}
 
Example 12
Source File: UUIDRegistry.java    From Modern-LWC with MIT License 5 votes vote down vote up
/**
 * Get the name for the given UUID. If it is not already known, it will be retrieved from the account servers.
 *
 * @param uuid
 * @return
 */
public static String getName(UUID uuid) {
    if (uuid == null) {
        return null;
    }

    if (UUIDToNameCache.containsKey(uuid)) {
        return UUIDToNameCache.get(uuid).getName();
    }

    // First way: if they're on the server already
    Player player = Bukkit.getPlayer(uuid);

    if (player != null) {
        updateCache(uuid, player.getName());
        return player.getName();
    }

    // Second way: if they have been on the server before
    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);

    if (offlinePlayer != null && offlinePlayer.getName() != null) {
        updateCache(uuid, offlinePlayer.getName());
        return offlinePlayer.getName();
    }

    // Third way: use the web API
    try {
        Map<UUID, String> results = new NameFetcher(Arrays.asList(uuid)).call();

        if (results.containsKey(uuid)) {
            updateCache(uuid, results.get(uuid));
            return results.get(uuid);
        } else {
            return null;
        }
    } catch (Exception e) {
        return null;
    }
}
 
Example 13
Source File: AbstractEconomy.java    From VaultAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean has(OfflinePlayer player, double amount) {
	if (player.getName() == null) return false;
	return has(player.getName(), amount);
}
 
Example 14
Source File: MarriagePlayerData.java    From MarriageMaster with GNU General Public License v3.0 4 votes vote down vote up
public MarriagePlayerData(final @NotNull OfflinePlayer player)
{
	super(player.getUniqueId(), player.getName() != null ? player.getName() : "Unknown");
}
 
Example 15
Source File: SubCommand_SetOwner.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, "Only player can run this command");
        return;
    }

    if (cmdArg.length < 1) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.no-owner-given", sender));
        return;
    }

    final BlockIterator bIt = new BlockIterator((Player) sender, 10);

    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }

    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());

        if (shop == null) {
            continue;
        }

        @SuppressWarnings("deprecation") final OfflinePlayer newShopOwner = plugin.getServer().getOfflinePlayer(cmdArg[0]);
        if (newShopOwner.getName() == null) {
            MsgUtil.sendMessage(sender, MsgUtil.getMessage("unknown-player", null));
            return;
        }
        shop.setOwner(newShopOwner.getUniqueId());
        //shop.setSignText();
        //shop.update();
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.new-owner", sender, newShopOwner.getName()));
        return;
    }

    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 16
Source File: AbstractEconomy.java    From VaultAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean has(OfflinePlayer player, String worldName, double amount) {
	if (player.getName() == null) return false;
	return has(player.getName(), worldName, amount);
}
 
Example 17
Source File: RentRegion.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Unrent a region, reset to unrented.
 * @param giveMoneyBack true if money should be given back to the player, false otherwise
 * @param executor      The CommandSender that should get the cancelled message if there is any, or null
 * @return true if unrenting succeeded, othwerwise false
 */
@SuppressWarnings("deprecation")
public boolean unRent(boolean giveMoneyBack, CommandSender executor) {
	boolean own = executor instanceof Player && this.isRenter((Player) executor);
	if(executor != null) {
		if(!executor.hasPermission("areashop.unrent") && !own) {
			message(executor, "unrent-noPermissionOther");
			return false;
		}
		if(!executor.hasPermission("areashop.unrent") && !executor.hasPermission("areashop.unrentown") && own) {
			message(executor, "unrent-noPermission");
			return false;
		}
	}

	if(plugin.getEconomy() == null) {
		return false;
	}

	// Broadcast and check event
	UnrentingRegionEvent event = new UnrentingRegionEvent(this);
	Bukkit.getPluginManager().callEvent(event);
	if(event.isCancelled()) {
		message(executor, "general-cancelled", event.getReason());
		return false;
	}

	// Do a payback
	double moneyBack = getMoneyBackAmount();
	if(moneyBack > 0 && giveMoneyBack) {
		boolean noPayBack = false;
		OfflinePlayer landlordPlayer = null;
		if(getLandlord() != null) {
			landlordPlayer = Bukkit.getOfflinePlayer(getLandlord());
		}
		String landlordName = getLandlordName();
		EconomyResponse r;
		if(landlordName != null) {
			if(landlordPlayer != null && landlordPlayer.getName() != null) {
				r = plugin.getEconomy().withdrawPlayer(landlordPlayer, getWorldName(), moneyBack);
			} else {
				r = plugin.getEconomy().withdrawPlayer(landlordName, getWorldName(), moneyBack);
			}
			if(r == null || !r.transactionSuccess()) {
				noPayBack = true;
			}
		}

		// Give back the money
		OfflinePlayer player = Bukkit.getOfflinePlayer(getRenter());
		if(player != null && !noPayBack) {
			r = null;
			boolean error = false;
			try {
				if(player.getName() != null) {
					r = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack);
				} else if(getPlayerName() != null) {
					r = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
				}
			} catch(Exception e) {
				error = true;
			}
			if(error || r == null || !r.transactionSuccess()) {
				AreaShop.warn("Something went wrong with paying back to " + getPlayerName() + " money while unrenting region " + getName());
			}
		}
	}

	// Handle schematic save/restore (while %uuid% is still available)
	handleSchematicEvent(RegionEvent.UNRENTED);

	// Send message: before actual removal of the renter so that it is still available for variables
	message(executor, "unrent-unrented");

	// Remove friends, the owner and renteduntil values
	getFriendsFeature().clearFriends();
	UUID oldRenter = getRenter();
	setRenter(null);
	setRentedUntil(null);
	setTimesExtended(-1);
	removeLastActiveTime();

	// Notify about updates
	this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack)));
	return true;
}
 
Example 18
Source File: DefaultComparators.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Relation compare(final OfflinePlayer p, final String name) {
	String offlineName = p.getName();
	return offlineName == null ? Relation.NOT_EQUAL : Relation.get(offlineName.equalsIgnoreCase(name));
}
 
Example 19
Source File: TradeLog.java    From TradePlus with GNU General Public License v3.0 4 votes vote down vote up
void updateName() {
  OfflinePlayer op = Bukkit.getOfflinePlayer(uniqueId);
  if (op.getName() == null) lastKnownName = "unknown";
  else lastKnownName = op.getName();
}
 
Example 20
Source File: AbstractEconomy.java    From VaultAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean hasAccount(OfflinePlayer player, String worldName) {
	if (player.getName() == null) return false;
	return hasAccount(player.getName(), worldName);
}