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

The following examples show how to use org.bukkit.entity.Player#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: VoteManager.java    From ZombieEscape with GNU General Public License v2.0 7 votes vote down vote up
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;
}
 
Example 2
Source File: UserHandler.java    From VoxelGamesLibv2 with MIT License 6 votes vote down vote up
/**
 * 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() + ")");
}
 
Example 3
Source File: DamageTakenListener.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
@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());

}
 
Example 4
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 6 votes vote down vote up
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);
}
 
Example 5
Source File: SbManager.java    From ScoreboardStats with MIT License 6 votes vote down vote up
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);
}
 
Example 6
Source File: CooldownHandler.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
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));
}
 
Example 7
Source File: HealthListeners.java    From ActionHealth with MIT License 5 votes vote down vote up
@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());
        }
    }
}
 
Example 8
Source File: PWIPlayer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: BukkitPlayerService.java    From SquirrelID with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example 10
Source File: GameModeChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
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));
}
 
Example 11
Source File: PlayerManager.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: ScoreBoardManager.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: ReviveHandler.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: ItemsCaughtListener.java    From Statz with GNU General Public License v3.0 5 votes vote down vote up
@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());

}
 
Example 15
Source File: GDPermissionUser.java    From GriefDefender with MIT License 5 votes vote down vote up
public GDPermissionUser(Player player) {
    super(player.getUniqueId().toString());
    this.uniqueId = player.getUniqueId();
    this.worldUniqueId = player.getWorld().getUID();
    this.offlinePlayer = player;
    this.userName = player.getName();
}
 
Example 16
Source File: RealmListener.java    From NyaaUtils with MIT License 4 votes vote down vote up
@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;
}
 
Example 17
Source File: LuckPermsVaultPermission.java    From LuckPerms with MIT License 4 votes vote down vote up
@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;
}
 
Example 18
Source File: Strafe.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void removeData(Player p) {
    UUID uuid = p.getUniqueId();
    lastIdleTick.remove(uuid);
    bouncedSet.remove(uuid);
}
 
Example 19
Source File: TimesShornListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@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());

}
 
Example 20
Source File: ItemsCraftedListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@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());

}