下面列出了org.bukkit.entity.Player#getUniqueId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public boolean vote(Player player, String map) {
UUID uuid = player.getUniqueId();
if (VOTED.contains(uuid)) {
Messages.VOTED_ALREADY.send(player);
return false;
}
VOTED.add(uuid);
// TODO: Remove override
if (player.getName().equals("sgtcazeyt")) {
VOTES.put(map, VOTES.get(map) + 100);
}
VOTES.put(map, VOTES.get(map) + 1);
Messages.VOTED.send(player, map);
return true;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(final EntityDamageEvent event) {
final PlayerStat stat = PlayerStat.DAMAGE_TAKEN;
if (!(event.getEntity() instanceof Player)) {
// It was not a player that got damage
return;
}
// Get player
final Player player = (Player) event.getEntity();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
PlayerStatSpecification specification = new DamageTakenSpecification(player.getUniqueId(), event.getDamage(),
player.getWorld().getName(), event.getCause().toString());
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());
}
protected void scheduleShowTask(Player player, boolean action) {
if (!Settings.isTempScoreboard()) {
return;
}
int interval = Settings.getTempDisappear();
if (action) {
interval = Settings.getTempAppear();
}
UUID uuid = player.getUniqueId();
Bukkit.getScheduler().runTaskLater(plugin, () -> {
Player localPlayer = Bukkit.getPlayer(uuid);
if (localPlayer == null) {
return;
}
if (action) {
createTopListScoreboard(player);
} else {
createScoreboard(player);
}
}, interval * 20L);
}
public void resetCooldown(final Player player, final String cmd, int cooldownSecs) {
UUID uuid = player.getUniqueId();
if (!cooldowns.containsKey(uuid)) {
Map<String, Long> cdMap = new ConcurrentHashMap<>();
cooldowns.put(uuid, cdMap);
}
if (cooldownSecs == 0) {
cooldowns.get(uuid).remove(cmd);
return;
}
cooldowns.get(uuid).put(cmd, System.currentTimeMillis() + TimeUtil.secondsAsMillis(cooldownSecs));
plugin.async(new Runnable() {
@Override
public void run() {
Map<String, Long> cmdMap = cooldowns.get(player.getUniqueId());
if (cmdMap != null) {
cmdMap.remove(cmd);
}
}
}, TimeUtil.secondsAsMillis(cooldownSecs));
}
public static void hideDurabilityBossBar(Player player, EquipmentSlot slot) {
UUID uuid = player.getUniqueId();
BossBar bar;
HashMap<UUID, BossBar> playersBars;
if (slot.equals(EquipmentSlot.HAND)) {
playersBars = playersBarsMain;
} else if (slot.equals(EquipmentSlot.OFF_HAND)) {
playersBars = playersBarsOff;
} else {
return;
}
if (!playersBars.containsKey(uuid)) {
return;
} else {
bar = playersBars.get(uuid);
}
bar.setVisible(false);
bar.setProgress(1.0D);
bar.setColor(BarColor.GREEN);
}
/**
* Creates the user object for a new user
*
* @param player the player that joined
* @throws UserException when the player was not logged in
*/
public void join(@Nonnull Player player) {
if (!hasLoggedIn(player.getUniqueId())) {
throw new UserException("User " + player.getName() + "(" + player.getUniqueId()
+ ") tried to join without being logged in!");
}
User user = tempData.remove(player.getUniqueId());
user.setPlayer(player);
user.refreshDisplayName();
// todo load persisted data
user.addListeningChannel(chatHandler.defaultChannel.getIdentifier());
user.setActiveChannel(chatHandler.defaultChannel.getIdentifier());
user.applyRolePrefix();
user.applyRoleSuffix();
users.put(user.getUuid(), user);
log.info("Applied data for user " + user.getUuid() + " (" + user.getRole().getName() + " " + user.getRawDisplayName() + ")");
}
public GDPermissionUser(Player player) {
super(player.getUniqueId().toString());
this.uniqueId = player.getUniqueId();
this.worldUniqueId = player.getWorld().getUID();
this.offlinePlayer = player;
this.userName = player.getName();
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onFishCaught(final PlayerFishEvent event) {
final PlayerStat stat = PlayerStat.ITEMS_CAUGHT;
// Get player
final Player player = event.getPlayer();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
Entity entity;
ItemStack item;
String materialName = null;
if (event.getCaught() != null) {
entity = event.getCaught();
if (!(entity instanceof Item)) {
return; // Did not catch an item
}
item = ((Item) entity).getItemStack();
materialName = item.getType().name();
} else {
// Did not catch anything.
return;
}
PlayerStatSpecification specification = new ItemsCaughtSpecification(player.getUniqueId(), item.getAmount(),
player.getWorld().getName(), item.getType());
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());
}
public void restoreInventory(Player player)
{
UUID uuid = player.getUniqueId();
ModeDataVault modeDataVault = savedInventories.get(uuid);
JavaUtils.clearInventory(player);
player.getInventory().setContents(modeDataVault.getItems());
player.getInventory().setArmorContents(modeDataVault.getArmor());
message.send(player, messages.revivedUser, messages.prefixGeneral);
savedInventories.remove(uuid);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (plugin.configStore.rememberToggle) {
FileHandler fileHandler = new FileHandler("plugins/ActionHealth/players/" + player.getUniqueId() + ".yml");
if (fileHandler.getBoolean("toggle")) {
plugin.toggle.add(player.getUniqueId());
}
}
}
public void toggleScoreboard(Player player) {
if(player == null) return;
UUID uuid = player.getUniqueId();
if(this.disabledList.contains(uuid)) {
this.disabledList.remove(uuid);
return;
}
removeScoreboard(player);
this.disabledList.add(uuid);
}
/**
* Adds a player
*
* @param player player instance
*/
private void add(Player player) {
Validate.notNull(player);
NovaPlayer nPlayer = new NovaPlayerImpl(player.getUniqueId());
nPlayer.setName(player.getName());
nPlayer.setPoints(Config.KILLING_STARTPOINTS.getInt());
players.put(nPlayer.getName(), nPlayer);
}
private void actOnEvent(PlayerGameModeChangeEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
long time = System.currentTimeMillis();
String gameMode = event.getNewGameMode().name();
String worldName = player.getWorld().getName();
dbSystem.getDatabase().executeTransaction(new WorldNameStoreTransaction(serverInfo.getServerUUID(), worldName));
worldAliasSettings.addWorld(worldName);
Optional<Session> cachedSession = SessionCache.getCachedSession(uuid);
cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
}
@Nullable
@Override
public Profile findByName(String name) throws IOException, InterruptedException {
Player player = Bukkit.getServer().getPlayerExact(name);
if (player != null) {
return new Profile(player.getUniqueId(), player.getName());
} else {
return null;
}
}
PWIPlayer(Player player, Group group, double bankBalance, double balance, boolean useAttributes) {
this.uuid = player.getUniqueId();
this.name = player.getName();
this.location = player.getLocation();
this.group = group;
this.saved = false;
this.armor = player.getInventory().getArmorContents();
this.enderChest = player.getEnderChest().getContents();
this.inventory = player.getInventory().getContents();
this.canFly = player.getAllowFlight();
this.displayName = player.getDisplayName();
this.exhaustion = player.getExhaustion();
this.experience = player.getExp();
this.isFlying = player.isFlying();
this.foodLevel = player.getFoodLevel();
if (useAttributes) {
this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
} else {
this.maxHealth = player.getMaxHealth();
}
this.health = player.getHealth();
this.gamemode = player.getGameMode();
this.level = player.getLevel();
this.saturationLevel = player.getSaturation();
this.potionEffects = player.getActivePotionEffects();
this.fallDistance = player.getFallDistance();
this.fireTicks = player.getFireTicks();
this.maxAir = player.getMaximumAir();
this.remainingAir = player.getRemainingAir();
this.bankBalance = bankBalance;
this.balance = balance;
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
UUID id = player.getUniqueId();
if(muteList.contains(id)){
return;
}
String currentRealmName = currentRealm.getOrDefault(id, "");
Realm realm = getRealm(player.getLocation());
if (realm == null) {
return;
}
if (currentRealmName.equals(realm.getName()) && realm.inArea(player.getLocation())) {
return;
}
if (!currentRealmName.equals(realm.getName()) && !Realm.__DEFAULT__.equals(realm.getName())) {
currentRealm.put(id, realm.getName());
if(plugin.cfg.realm_notification_type == MessageType.TITLE){
String title, subtitle;
if (realm.getType().equals(RealmType.PUBLIC)) {
title = I18n.format("user.realm.notification.public_title", realm.getName());
subtitle = I18n.format("user.realm.notification.public_subtitle");
} else {
title = I18n.format("user.realm.notification.private_title", realm.getName());
subtitle = I18n.format("user.realm.notification.private_subtitle", realm.getOwner().getName());
}
Message.sendTitle(player,
new Message(title).inner,
new Message(subtitle).inner,
plugin.cfg.realm_notification_title_fadein_tick,
plugin.cfg.realm_notification_title_stay_tick,
plugin.cfg.realm_notification_title_fadeout_tick
);
}else{
if (realm.getType().equals(RealmType.PUBLIC)) {
new Message(I18n.format("user.realm.notification.public", realm.getName())).
send(player, plugin.cfg.realm_notification_type);
} else {
new Message(I18n.format("user.realm.notification.private", realm.getName(),
realm.getOwner().getName())).send(player, plugin.cfg.realm_notification_type);
}
}
return;
} else if (!currentRealm.containsKey(id) || !Realm.__DEFAULT__.equals(currentRealmName)) {
currentRealm.put(id, Realm.__DEFAULT__);
new Message(ChatColor.translateAlternateColorCodes('&', plugin.cfg.realm_default_name))
.send(player, plugin.cfg.realm_notification_type);
}
return;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCraft(final CraftItemEvent event) {
final PlayerStat stat = PlayerStat.ITEMS_CRAFTED;
// Get player
final Player player = (Player) event.getWhoClicked();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
final ItemStack itemCrafted = event.getCurrentItem();
PlayerStatSpecification specification = new ItemsCraftedSpecification(player.getUniqueId(),
itemCrafted.getAmount(), player.getWorld().getName(),
itemCrafted.getType());
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());
}
@Override
public UUID lookupUuid(String player) {
Objects.requireNonNull(player, "player");
// are they online?
Player onlinePlayer = this.plugin.getBootstrap().getServer().getPlayerExact(player);
if (onlinePlayer != null) {
return onlinePlayer.getUniqueId();
}
// account for plugins that for some reason think it's valid to pass the uuid as a string.
UUID uuid = Uuids.parse(player);
if (uuid != null) {
return uuid;
}
// are we on the main thread?
if (!this.plugin.getBootstrap().isServerStarting() && this.plugin.getBootstrap().getServer().isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
throw new RuntimeException(
"The operation to lookup a UUID for '" + player + "' was cancelled by LuckPerms. This is NOT a bug. \n" +
"The lookup request was made on the main server thread. It is not safe to execute a request to \n" +
"load username data from the database in this context. \n" +
"If you are a plugin author, please either make your request asynchronously, \n" +
"or provide an 'OfflinePlayer' object with the UUID already populated. \n" +
"Alternatively, server admins can disable this catch by setting 'vault-unsafe-lookups' to true \n" +
"in the LP config, but should consider the consequences (lag) before doing so."
);
}
// lookup a username from the database
uuid = this.plugin.getStorage().getPlayerUniqueId(player.toLowerCase()).join();
if (uuid == null) {
uuid = this.plugin.getBootstrap().lookupUniqueId(player).orElse(null);
}
// unable to find a user, throw an exception
if (uuid == null) {
throw new IllegalArgumentException("Unable to find a UUID for player '" + player + "'.");
}
return uuid;
}
@Override
public void removeData(Player p) {
UUID uuid = p.getUniqueId();
lastIdleTick.remove(uuid);
bouncedSet.remove(uuid);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onShear(final PlayerShearEntityEvent event) {
final PlayerStat stat = PlayerStat.TIMES_SHORN;
// Get player
final Player player = event.getPlayer();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
PlayerStatSpecification specification = new TimesShornSpecification(player.getUniqueId(), 1,
player.getWorld().getName());
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());
}