Update the cache on login.
This commit is contained in:
parent
d73d453994
commit
666e4d0dff
@ -24,6 +24,7 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import com.massivecraft.mcore.MCore;
|
import com.massivecraft.mcore.MCore;
|
||||||
@ -151,6 +152,8 @@ public class PlayerUtil implements Listener
|
|||||||
// PLAYER ID <---> PLAYER NAME
|
// PLAYER ID <---> PLAYER NAME
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// getPlayerName
|
||||||
|
|
||||||
public static String getPlayerName(final UUID playerId, final boolean usingCache, final boolean usingMojangApi)
|
public static String getPlayerName(final UUID playerId, final boolean usingCache, final boolean usingMojangApi)
|
||||||
{
|
{
|
||||||
List<UUID> playerIds = Collections.singletonList(playerId);
|
List<UUID> playerIds = Collections.singletonList(playerId);
|
||||||
@ -166,6 +169,8 @@ public class PlayerUtil implements Listener
|
|||||||
return getPlayerName(playerId, true);
|
return getPlayerName(playerId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getPlayerId
|
||||||
|
|
||||||
public static UUID getPlayerId(final String playerName, final boolean usingCache, final boolean usingMojangApi)
|
public static UUID getPlayerId(final String playerName, final boolean usingCache, final boolean usingMojangApi)
|
||||||
{
|
{
|
||||||
List<String> playerNames = Collections.singletonList(playerName);
|
List<String> playerNames = Collections.singletonList(playerName);
|
||||||
@ -181,6 +186,19 @@ public class PlayerUtil implements Listener
|
|||||||
return getPlayerId(playerName, true);
|
return getPlayerId(playerName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update Cache on Login
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void playerIdPlayerName(PlayerLoginEvent event)
|
||||||
|
{
|
||||||
|
final String playerName = event.getPlayer().getName();
|
||||||
|
final UUID playerId = event.getPlayer().getUniqueId();
|
||||||
|
MCoreMPlayer mplayer = MCoreMPlayer.get(playerId, true);
|
||||||
|
mplayer.setName(playerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Core Methods
|
||||||
|
|
||||||
// I suggest using ...
|
// I suggest using ...
|
||||||
// final Map<String, UUID> ret = new TreeMap<String, UUID>(String.CASE_INSENSITIVE_ORDER);
|
// final Map<String, UUID> ret = new TreeMap<String, UUID>(String.CASE_INSENSITIVE_ORDER);
|
||||||
// ... since you achieve case insensitivity that way.
|
// ... since you achieve case insensitivity that way.
|
||||||
|
Loading…
Reference in New Issue
Block a user