Fix getAllNodes cache not working properly, remove pre-process contexts on Bungee & cleanup some unused methods

This commit is contained in:
Luck 2017-03-11 17:55:50 +00:00
parent a35fd80763
commit bce7fa871d
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
11 changed files with 65 additions and 57 deletions

View File

@ -192,9 +192,7 @@ public class Contexts {
if (o == this) return true;
if (!(o instanceof Contexts)) return false;
final Contexts other = (Contexts) o;
final Object this$context = this.getContexts();
final Object other$context = other.getContexts();
return (this$context == null ? other$context == null : this$context.equals(other$context)) &&
return (this.getContexts() == null ? other.getContexts() == null : this.getContexts().equals(other.getContexts())) &&
this.isOp() == other.isOp() &&
this.isIncludeGlobal() == other.isIncludeGlobal() &&
this.isIncludeGlobalWorld() == other.isIncludeGlobalWorld() &&
@ -212,8 +210,8 @@ public class Contexts {
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $context = this.getContexts();
result = result * PRIME + ($context == null ? 43 : $context.hashCode());
final Object contexts = this.getContexts();
result = result * PRIME + (contexts == null ? 43 : contexts.hashCode());
result = result * PRIME + (this.isOp() ? 79 : 97);
result = result * PRIME + (this.isIncludeGlobal() ? 79 : 97);
result = result * PRIME + (this.isIncludeGlobalWorld() ? 79 : 97);

View File

@ -591,16 +591,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
return map;
}
@SuppressWarnings("deprecation")
@Override
public UUID getUuidFromUsername(String playerName) {
try {
return getServer().getOfflinePlayer(playerName).getUniqueId();
} catch (Exception e) {
return null;
}
}
private void registerPermissions(PermissionDefault def) {
PluginManager pm = getServer().getPluginManager();

View File

@ -41,6 +41,8 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
import org.bukkit.Bukkit;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collections;
@ -130,11 +132,16 @@ public class MigrationBPermissions extends SubCommand<Object> {
AtomicInteger userCount = new AtomicInteger(0);
for (Calculable user : world.getAll(CalculableType.USER)) {
// There is no mention of UUIDs in the API. I assume that name = uuid. idk?
UUID uuid;
UUID uuid = null;
try {
uuid = UUID.fromString(user.getName());
} catch (IllegalArgumentException e) {
uuid = plugin.getUuidFromUsername(user.getName());
try {
//noinspection deprecation
uuid = Bukkit.getOfflinePlayer(user.getName()).getUniqueId();
} catch (Exception ex) {
e.printStackTrace();
}
}
if (uuid == null) {

View File

@ -195,7 +195,11 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
} catch (IllegalArgumentException e) {
u = ni.nameToUUID(user.getIdentifier());
if (u == null) {
u = plugin.getUuidFromUsername(user.getIdentifier());
try {
u = Bukkit.getOfflinePlayer(user.getIdentifier()).getUniqueId();
} catch (Exception ex) {
e.printStackTrace();
}
}
}

View File

@ -23,6 +23,8 @@
package me.lucko.luckperms.bungee;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.caching.UserData;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.core.UuidCache;
@ -37,6 +39,7 @@ import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.api.event.PermissionCheckEvent;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
@ -68,7 +71,8 @@ public class BungeeListener extends AbstractListener implements Listener {
return;
}
if (user.getUserData() == null) {
UserData userData = user.getUserData();
if (userData == null) {
plugin.getLog().warn("Player " + player.getName() + " does not have any user data setup.");
return;
}
@ -83,7 +87,7 @@ public class BungeeListener extends AbstractListener implements Listener {
false
);
e.setHasPermission(user.getUserData().getPermissionData(contexts).getPermissionValue(e.getPermission()).asBoolean());
e.setHasPermission(userData.getPermissionData(contexts).getPermissionValue(e.getPermission()).asBoolean());
}
@EventHandler(priority = EventPriority.LOWEST)
@ -163,4 +167,38 @@ public class BungeeListener extends AbstractListener implements Listener {
public void onPlayerQuit(PlayerDisconnectEvent e) {
onLeave(e.getPlayer().getUniqueId());
}
// We don't preprocess all servers, so we may have to do it here.
@EventHandler(priority = EventPriority.LOWEST)
public void onServerSwitch(ServerConnectEvent e) {
String serverName = e.getTarget().getName();
UUID uuid = e.getPlayer().getUniqueId();
plugin.doAsync(() -> {
MutableContextSet set = MutableContextSet.create();
set.add("server", plugin.getConfiguration().get(ConfigKeys.SERVER));
set.add("world", serverName);
User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(uuid));
if (user == null) {
return;
}
UserData userData = user.getUserData();
if (userData == null) {
return;
}
Contexts contexts = new Contexts(
set.makeImmutable(),
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
true,
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
false
);
userData.preCalculate(contexts);
});
}
}

View File

@ -28,7 +28,6 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Logger;
import me.lucko.luckperms.api.PlatformType;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.bungee.messaging.BungeeMessagingService;
import me.lucko.luckperms.common.api.ApiHandler;
import me.lucko.luckperms.common.api.ApiProvider;
@ -67,7 +66,6 @@ import me.lucko.luckperms.common.treeview.PermissionVault;
import me.lucko.luckperms.common.utils.BufferedRequest;
import me.lucko.luckperms.common.utils.LoggerImpl;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
@ -329,17 +327,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
Set<ContextSet> c = new HashSet<>();
c.add(ContextSet.empty());
c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.SERVER)));
c.addAll(getProxy().getServers().values().stream()
.map(ServerInfo::getName)
.map(s -> {
MutableContextSet set = MutableContextSet.create();
set.add("server", getConfiguration().get(ConfigKeys.SERVER));
set.add("world", s);
return set.makeImmutable();
})
.collect(Collectors.toList())
);
return c.stream()
.map(set -> new Contexts(
set,
@ -352,9 +339,4 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
))
.collect(Collectors.toSet());
}
@Override
public UUID getUuidFromUsername(String playerName) {
return null; // Not needed on Bungee
}
}

View File

@ -27,7 +27,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.common.utils.ExtractedContexts;
@ -37,7 +37,7 @@ import me.lucko.luckperms.common.utils.ExtractedContexts;
@AllArgsConstructor(staticName = "of")
public class GetAllNodesRequest {
private final ImmutableList<String> excludedGroups;
private final ImmutableSet<String> excludedGroups;
private final ExtractedContexts contexts;
}

View File

@ -29,7 +29,6 @@ import lombok.RequiredArgsConstructor;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
@ -61,6 +60,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -257,7 +257,7 @@ public abstract class PermissionHolder {
private SortedSet<LocalizedNode> getAllNodesCacheApply(GetAllNodesRequest getAllNodesHolder) {
// Expand the holder.
List<String> excludedGroups = new ArrayList<>(getAllNodesHolder.getExcludedGroups());
Set<String> excludedGroups = new HashSet<>(getAllNodesHolder.getExcludedGroups());
ExtractedContexts contexts = getAllNodesHolder.getContexts();
// Don't register users, as they cannot be inherited.
@ -436,8 +436,8 @@ public abstract class PermissionHolder {
* @param contexts context to decide if groups should be applied
* @return a set of nodes
*/
public SortedSet<LocalizedNode> getAllNodes(List<String> excludedGroups, ExtractedContexts contexts) {
return getAllNodesCache.getUnchecked(GetAllNodesRequest.of(excludedGroups == null ? ImmutableList.of() : ImmutableList.copyOf(excludedGroups), contexts));
public SortedSet<LocalizedNode> getAllNodes(Collection<String> excludedGroups, ExtractedContexts contexts) {
return getAllNodesCache.getUnchecked(GetAllNodesRequest.of(excludedGroups == null ? ImmutableSet.of() : ImmutableSet.copyOf(excludedGroups), contexts));
}
/**

View File

@ -345,14 +345,6 @@ public interface LuckPermsPlugin {
*/
Set<UUID> getIgnoringLogs();
/**
* Gets the UUID of a player. Used as a backup for migration
*
* @param playerName the players name
* @return a uuid if found, or null if not
*/
UUID getUuidFromUsername(String playerName);
/**
* Gets the update task buffer of the platform, used for scheduling and running update tasks.
*

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.utils;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@ -31,6 +32,7 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.api.context.MutableContextSet;
@Getter
@EqualsAndHashCode
@ToString
public class ExtractedContexts {
public static ExtractedContexts generate(Contexts contexts) {

View File

@ -442,11 +442,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
return Collections.emptySet();
}
@Override
public UUID getUuidFromUsername(String playerName) {
return game.getServer().getPlayer(playerName).map(Player::getUniqueId).orElse(null);
}
@Override
public List<BaseCommand> getExtraCommands() {
return Collections.singletonList(new SpongeMainCommand(this));