Fixes for offline mode servers

This commit is contained in:
Luck 2016-09-16 21:24:25 +01:00
parent f2e06b56e7
commit be74b50762
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
7 changed files with 42 additions and 30 deletions

View File

@ -80,7 +80,7 @@ public class LuckPermsPlaceholderExpansion extends PlaceholderExpansion {
return "";
}
Optional<User> u = api.getUserSafe(player.getUniqueId());
Optional<User> u = api.getUserSafe(api.getUuidCache().getUUID(player.getUniqueId()));
if (!u.isPresent()) {
return "";
}

View File

@ -33,6 +33,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.*;
import java.util.UUID;
class BukkitListener extends AbstractListener implements Listener {
private final LPBukkitPlugin plugin;
@ -80,20 +82,22 @@ class BukkitListener extends AbstractListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
// Refresh permissions again
plugin.getUserManager().getWorldCache().put(e.getPlayer().getUniqueId(), e.getPlayer().getWorld().getName());
plugin.doAsync(() -> refreshPlayer(e.getPlayer().getUniqueId()));
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
plugin.getUserManager().getWorldCache().put(internal, e.getPlayer().getWorld().getName());
plugin.doAsync(() -> refreshPlayer(internal));
}
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent e) {
plugin.getUserManager().getWorldCache().put(e.getPlayer().getUniqueId(), e.getPlayer().getWorld().getName());
plugin.doAsync(() -> refreshPlayer(e.getPlayer().getUniqueId()));
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
plugin.getUserManager().getWorldCache().put(internal, e.getPlayer().getWorld().getName());
plugin.doAsync(() -> refreshPlayer(internal));
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
plugin.getUserManager().getWorldCache().remove(e.getPlayer().getUniqueId());
plugin.getUserManager().getWorldCache().remove(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
onLeave(e.getPlayer().getUniqueId());
}

View File

@ -55,7 +55,7 @@ public class BungeeListener extends AbstractListener implements Listener {
final ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
BungeePlayerCache playerCache = plugin.getPlayerCache().get(player.getUniqueId());
BungeePlayerCache playerCache = plugin.getPlayerCache().get(plugin.getUuidCache().getUUID(player.getUniqueId()));
if (playerCache == null) {
return;
}

View File

@ -69,11 +69,11 @@ public class AbstractListener {
protected void onLeave(UUID uuid) {
final UuidCache cache = plugin.getUuidCache();
// Unload the user from memory when they disconnect;
cache.clearCache(uuid);
final User user = plugin.getUserManager().get(cache.getUUID(uuid));
plugin.getUserManager().unload(user);
// Unload the user from memory when they disconnect;
cache.clearCache(uuid);
}
protected void refreshPlayer(UUID uuid) {

View File

@ -35,9 +35,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.users.User;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.service.permission.SubjectCollection;
@ -86,15 +84,6 @@ public class LuckPermsSubject implements Subject {
@Override
public Optional<CommandSource> getCommandSource() {
if (holder instanceof User) {
final UUID uuid = ((User) holder).getUuid();
Optional<Player> p = Sponge.getServer().getPlayer(uuid);
if (p.isPresent()) {
return Optional.of(p.get());
}
}
return Optional.empty();
}

View File

@ -26,12 +26,13 @@ import com.google.common.base.Splitter;
import lombok.Getter;
import lombok.NonNull;
import me.lucko.luckperms.users.User;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.util.Tristate;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class LuckPermsUserSubject extends LuckPermsSubject {
@ -109,4 +110,21 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
return service.getDefaults().getPermissionValue(contexts, permission);
}
@Override
public String getIdentifier() {
return service.getPlugin().getUuidCache().getExternalUUID(user.getUuid()).toString();
}
@Override
public Optional<CommandSource> getCommandSource() {
final UUID uuid = service.getPlugin().getUuidCache().getExternalUUID(user.getUuid());
Optional<Player> p = Sponge.getServer().getPlayer(uuid);
if (p.isPresent()) {
return Optional.of(p.get());
}
return Optional.empty();
}
}

View File

@ -61,22 +61,23 @@ public class UserCollection implements SubjectCollection {
}
private void load(UUID uuid) {
if (!manager.isLoaded(uuid)) {
UUID internal = service.getPlugin().getUuidCache().getUUID(uuid);
if (!manager.isLoaded(internal)) {
return;
}
User user = manager.get(uuid);
users.put(uuid, LuckPermsUserSubject.wrapUser(user, service));
User user = manager.get(internal);
users.put(internal, LuckPermsUserSubject.wrapUser(user, service));
}
public void unload(UUID uuid) {
users.remove(uuid);
users.remove(service.getPlugin().getUuidCache().getUUID(uuid));
}
@Override
public synchronized Subject get(@NonNull String id) {
try {
UUID u = UUID.fromString(id);
UUID u = service.getPlugin().getUuidCache().getUUID(UUID.fromString(id));
if (users.containsKey(u)) {
return users.get(u);
}
@ -105,7 +106,7 @@ public class UserCollection implements SubjectCollection {
public boolean hasRegistered(@NonNull String id) {
try {
UUID u = UUID.fromString(id);
return manager.isLoaded(u);
return manager.isLoaded(service.getPlugin().getUuidCache().getUUID(u));
} catch (IllegalArgumentException e) {
User user = manager.get(id);
return user != null;