Skip to content

Commit

Permalink
Introduce NULL-VALUE for MemoryPlayerDB (see #934)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlf committed Nov 26, 2016
1 parent 4d9c773 commit f55f3de
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public class MemoryPlayerDB implements PlayerDB {
private final LoadingCache<String, OfflinePlayer> nameCache;
private final LoadingCache<UUID, OfflinePlayer> uuidCache;
private static final OfflinePlayer NULL_PLAYER = NullPlayer.INSTANCE;

public MemoryPlayerDB(FileConfiguration config) {
nameCache = CacheBuilder
Expand All @@ -32,7 +33,7 @@ public OfflinePlayer load(String name) throws Exception {
uuidCache.put(offlinePlayer.getUniqueId(), offlinePlayer);
return offlinePlayer;
}
return null;
return NULL_PLAYER;
}
});
uuidCache = CacheBuilder
Expand All @@ -45,7 +46,7 @@ public OfflinePlayer load(UUID uuid) throws Exception {
nameCache.put(offlinePlayer.getName(), offlinePlayer);
return offlinePlayer;
}
return null;
return NULL_PLAYER;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package us.talabrek.ultimateskyblock.uuid;

import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.util.Map;
import java.util.UUID;

public class NullPlayer implements OfflinePlayer {
public static final NullPlayer INSTANCE = new NullPlayer();
private NullPlayer() {
}

@Override
public boolean isOnline() {
return false;
}

@Override
public String getName() {
return PlayerDB.UNKNOWN_PLAYER_NAME;
}

@Override
public UUID getUniqueId() {
return PlayerDB.UNKNOWN_PLAYER_UUID;
}

@Override
public boolean isBanned() {
return false;
}

@Override
public void setBanned(boolean b) {

}

@Override
public boolean isWhitelisted() {
return true;
}

@Override
public void setWhitelisted(boolean b) {

}

@Override
public Player getPlayer() {
return null;
}

@Override
public long getFirstPlayed() {
return 0;
}

@Override
public long getLastPlayed() {
return 0;
}

@Override
public boolean hasPlayedBefore() {
return false;
}

@Override
public Location getBedSpawnLocation() {
return null;
}

@Override
public Map<String, Object> serialize() {
return null;
}

@Override
public boolean isOp() {
return false;
}

@Override
public void setOp(boolean b) {

}
}

0 comments on commit f55f3de

Please sign in to comment.