-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: improve performance of looking up platform players and users by …
…uuid or name
- Loading branch information
1 parent
a7ee154
commit d496d56
Showing
6 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
common/src/main/java/com/gufli/kingdomcraft/common/ebean/PlayerStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.gufli.kingdomcraft.common.ebean; | ||
|
||
import com.gufli.kingdomcraft.api.domain.User; | ||
import com.gufli.kingdomcraft.api.entity.PlatformPlayer; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class PlayerStore { | ||
|
||
private final Map<UUID, User> usersByUuid = new ConcurrentHashMap<>(); | ||
private final Map<String, User> usersByName = new ConcurrentHashMap<>(); | ||
|
||
private final Map<UUID, PlatformPlayer> playersByUuid = new ConcurrentHashMap<>(); | ||
private final Map<String, PlatformPlayer> playersByName = new ConcurrentHashMap<>(); | ||
|
||
public final User getUser(UUID uuid) { | ||
return usersByUuid.get(uuid); | ||
} | ||
|
||
public final User getUser(String name) { | ||
return usersByName.get(name); | ||
} | ||
|
||
public final User getUser(PlatformPlayer player) { | ||
return usersByUuid.get(player.getUniqueId()); | ||
} | ||
|
||
public final PlatformPlayer getPlayer(UUID uuid) { | ||
return playersByUuid.get(uuid); | ||
} | ||
|
||
public final PlatformPlayer getPlayer(String name) { | ||
return playersByName.get(name); | ||
} | ||
|
||
public final PlatformPlayer getPlayer(User user) { | ||
return playersByUuid.get(user.getUniqueId()); | ||
} | ||
|
||
public final Collection<PlatformPlayer> getPlayers() { | ||
return playersByUuid.values(); | ||
} | ||
|
||
public final Collection<User> getUsers() { | ||
return usersByUuid.values(); | ||
} | ||
|
||
public final void remove(UUID uuid) { | ||
User user = usersByUuid.remove(uuid); | ||
if ( user != null ) { | ||
usersByName.remove(user.getName()); | ||
} | ||
|
||
PlatformPlayer player = playersByUuid.remove(uuid); | ||
if ( player != null ) { | ||
playersByName.remove(player.getName()); | ||
} | ||
} | ||
|
||
public final void add(User user, PlatformPlayer player) { | ||
usersByUuid.put(user.getUniqueId(), user); | ||
usersByName.put(user.getName(), user); | ||
|
||
playersByUuid.put(user.getUniqueId(), player); | ||
playersByName.put(user.getName(), player); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters