Java Code Examples for cn.nukkit.Player#getUniqueId()

The following examples show how to use cn.nukkit.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: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event) {
    long time = System.currentTimeMillis();
    Player dead = event.getEntity();
    SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(Session::died);

    try {
        EntityDamageEvent entityDamageEvent = dead.getLastDamageCause();
        if (!(entityDamageEvent instanceof EntityDamageByEntityEvent)) {
            return;
        }

        EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent;
        Entity killerEntity = entityDamageByEntityEvent.getDamager();

        UUID uuid = dead.getUniqueId();
        handleKill(time, uuid, killerEntity);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, dead).build());
    }
}
 
Example 2
Source File: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Runnable handlePetKill(long time, UUID victimUUID, EntityTameable tameable) {
    if (!tameable.isTamed()) {
        return null;
    }

    Player owner = tameable.getOwner();

    String name;
    try {
        name = tameable.getName();
    } catch (NoSuchMethodError oldVersionNoTypesError) {
        // getType introduced in 1.9
        name = tameable.getClass().getSimpleName();
    }

    return victimUUID != null
            ? new PlayerKillProcessor(owner.getUniqueId(), time, victimUUID, new EntityNameFormatter().apply(name))
            : new MobKillProcessor(owner.getUniqueId());
}
 
Example 3
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void actOnQuitEvent(PlayerQuitEvent event) {
    long time = System.currentTimeMillis();
    Player player = event.getPlayer();
    String playerName = player.getName();
    UUID playerUUID = player.getUniqueId();
    if (playerUUID == null) return; // Can be null when player is not signed in to xbox live

    UUID serverUUID = serverInfo.getServerUUID();
    JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
    JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);

    NukkitAFKListener.AFK_TRACKER.loggedOut(playerUUID, time);

    nicknameCache.removeDisplayName(playerUUID);

    dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, player::isBanned));

    sessionCache.endSession(playerUUID, time)
            .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));

    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
 
Example 4
Source File: WorldChangeListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void actOnEvent(EntityLevelChangeEvent event) {
    long time = System.currentTimeMillis();

    // Checked earlier
    Player player = (Player) event.getEntity();
    UUID uuid = player.getUniqueId();

    String worldName = player.getLevel().getName();
    String gameMode = GMTimes.magicNumberToGMName(player.getGamemode());

    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 5
Source File: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Runnable handlePlayerKill(long time, UUID victimUUID, Player killer) {
    Item itemInHand = killer.getInventory().getItemInHand();

    String weaponName = new ItemNameFormatter().apply(itemInHand.getName());

    return victimUUID != null
            ? new PlayerKillProcessor(killer.getUniqueId(), time, victimUUID, weaponName)
            : new MobKillProcessor(killer.getUniqueId());
}
 
Example 6
Source File: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Runnable handleProjectileKill(long time, UUID victimUUID, EntityProjectile projectile) {
    Entity source = projectile.shootingEntity;
    if (!(source instanceof Player)) {
        return null;
    }

    Player player = (Player) source;
    String projectileName = new EntityNameFormatter().apply(projectile.getName());

    return victimUUID != null
            ? new PlayerKillProcessor(player.getUniqueId(), time, victimUUID, projectileName)
            : new MobKillProcessor(player.getUniqueId());
}
 
Example 7
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void beforePlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getName();
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_LEAVE));
}
 
Example 8
Source File: ChatListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void actOnChatEvent(PlayerChatEvent event) {
    long time = System.currentTimeMillis();
    Player player = event.getPlayer();
    UUID uuid = player.getUniqueId();
    String displayName = player.getDisplayName();

    dbSystem.getDatabase().executeTransaction(new NicknameStoreTransaction(
            uuid, new Nickname(displayName, time, serverInfo.getServerUUID()),
            (playerUUID, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)
    ));
}
 
Example 9
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 = GMTimes.magicNumberToGMName(event.getNewGamemode());
    String worldName = player.getLevel().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 10
Source File: NukkitPlaceholderRegistrar.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private PlayerContainer getPlayer(Player player) {
    UUID uuid = player.getUniqueId();

    PlayerContainer container = system.getDatabaseSystem().getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid));
    SessionCache.getCachedSession(uuid).ifPresent(session -> container.putRawData(PlayerKeys.ACTIVE_SESSION, session));

    return container;
}
 
Example 11
Source File: NukkitConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) {
    final Player player = e.getPlayer();

    // https://github.com/lucko/LuckPerms/issues/2269
    if (player.getUniqueId() == null) {
        return;
    }

    handleDisconnect(player.getUniqueId());

    // perform unhooking from nukkit objects 1 tick later.
    // this allows plugins listening after us on MONITOR to still have intact permissions data
    this.plugin.getBootstrap().getServer().getScheduler().scheduleDelayedTask(this.plugin.getBootstrap(), () -> {
        // Remove the custom permissible
        try {
            PermissibleInjector.uninject(player, true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // Handle auto op
        if (this.plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
            player.setOp(false);
        }

        // remove their contexts cache
        this.plugin.getContextManager().onPlayerQuit(player);
    }, 1, true);
}
 
Example 12
Source File: SynLibInterface.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Integer putPacket(Player player, DataPacket packet, boolean needACK, boolean immediate) {
    RedirectPacket pk = new RedirectPacket();
    pk.uuid = player.getUniqueId();
    pk.direct = immediate;
    pk.mcpeBuffer = packet instanceof BatchPacket ? Binary.appendBytes((byte) 0xfe, ((BatchPacket) packet).payload) : packet.getBuffer();

    this.synapseInterface.putPacket(pk);
    return 0;  //这个返回值在nk中并没有被用到
}
 
Example 13
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void actOnJoinEvent(PlayerJoinEvent event) {
    Player player = event.getPlayer();

    UUID playerUUID = player.getUniqueId();
    UUID serverUUID = serverInfo.getServerUUID();
    long time = System.currentTimeMillis();
    JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
    JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);

    NukkitAFKListener.AFK_TRACKER.performedAction(playerUUID, time);

    String world = player.getLevel().getName();
    String gm = GMTimes.magicNumberToGMName(player.getGamemode());

    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));

    String address = player.getAddress();

    String playerName = player.getName();
    String displayName = player.getDisplayName();

    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(
                new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
        );
    }

    long registerDate = TimeUnit.SECONDS.toMillis(player.getFirstPlayed());
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> registerDate, playerName, serverUUID));
    Session session = new Session(playerUUID, serverUUID, time, world, gm);
    session.putRawData(SessionKeys.NAME, playerName);
    session.putRawData(SessionKeys.SERVER_NAME, serverInfo.getServer().getIdentifiableName());
    sessionCache.cacheSession(playerUUID, session)
            .ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));

    database.executeTransaction(new NicknameStoreTransaction(
            playerUUID, new Nickname(displayName, time, serverUUID),
            (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)
    ));

    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
 
Example 14
Source File: NukkitContextManager.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public UUID getUniqueId(Player player) {
    return player.getUniqueId();
}