mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Refactor the HolderType enum
This commit is contained in:
parent
12b861db3f
commit
8846932cb6
@ -37,6 +37,7 @@ import me.lucko.luckperms.common.cacheddata.type.PermissionCache;
|
|||||||
import me.lucko.luckperms.common.command.CommandManager;
|
import me.lucko.luckperms.common.command.CommandManager;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||||
@ -404,13 +405,13 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean holderSave(PermissionHolder holder) {
|
boolean holderSave(PermissionHolder holder) {
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
User u = (User) holder;
|
User u = (User) holder;
|
||||||
|
|
||||||
// we don't need to join this call - the save operation
|
// we don't need to join this call - the save operation
|
||||||
// can happen in the background.
|
// can happen in the background.
|
||||||
this.plugin.getStorage().saveUser(u);
|
this.plugin.getStorage().saveUser(u);
|
||||||
} else if (holder.getType().isGroup()) {
|
} else if (holder.getType() == HolderType.GROUP) {
|
||||||
Group g = (Group) holder;
|
Group g = (Group) holder;
|
||||||
|
|
||||||
// invalidate caches - they have potentially been affected by
|
// invalidate caches - they have potentially been affected by
|
||||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.api.Contexts;
|
|||||||
import me.lucko.luckperms.api.LogEntry;
|
import me.lucko.luckperms.api.LogEntry;
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.Track;
|
import me.lucko.luckperms.common.model.Track;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
@ -286,11 +287,11 @@ public class ExtendedLogEntry implements LogEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Builder acted(PermissionHolder acted) {
|
public Builder acted(PermissionHolder acted) {
|
||||||
if (acted.getType().isUser()) {
|
if (acted.getType() == HolderType.USER) {
|
||||||
actedName(((User) acted).getName().orElse("null"));
|
actedName(((User) acted).getName().orElse("null"));
|
||||||
acted(((User) acted).getUuid());
|
acted(((User) acted).getUuid());
|
||||||
type(Type.USER);
|
type(Type.USER);
|
||||||
} else if (acted.getType().isGroup()) {
|
} else if (acted.getType() == HolderType.GROUP) {
|
||||||
actedName(((Group) acted).getName());
|
actedName(((Group) acted).getName());
|
||||||
type(Type.GROUP);
|
type(Type.GROUP);
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ import me.lucko.luckperms.api.caching.CachedData;
|
|||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.NodeMapType;
|
import me.lucko.luckperms.common.model.NodeMapType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
@ -217,7 +218,7 @@ public class ApiPermissionHolder implements me.lucko.luckperms.api.PermissionHol
|
|||||||
Objects.requireNonNull(group, "group");
|
Objects.requireNonNull(group, "group");
|
||||||
|
|
||||||
Group g = ApiGroup.cast(group);
|
Group g = ApiGroup.cast(group);
|
||||||
if (this.handle.getType().isGroup() && g.getName().equals(this.handle.getObjectName())) {
|
if (this.handle.getType() == HolderType.GROUP && g.getName().equals(this.handle.getObjectName())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +231,7 @@ public class ApiPermissionHolder implements me.lucko.luckperms.api.PermissionHol
|
|||||||
Objects.requireNonNull(contextSet, "contextSet");
|
Objects.requireNonNull(contextSet, "contextSet");
|
||||||
|
|
||||||
Group g = ApiGroup.cast(group);
|
Group g = ApiGroup.cast(group);
|
||||||
if (this.handle.getType().isGroup() && g.getName().equals(this.handle.getObjectName())) {
|
if (this.handle.getType() == HolderType.GROUP && g.getName().equals(this.handle.getObjectName())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +280,7 @@ public class ApiPermissionHolder implements me.lucko.luckperms.api.PermissionHol
|
|||||||
public void clearMatching(@NonNull Predicate<Node> test) {
|
public void clearMatching(@NonNull Predicate<Node> test) {
|
||||||
Objects.requireNonNull(test, "test");
|
Objects.requireNonNull(test, "test");
|
||||||
this.handle.removeIf(test);
|
this.handle.removeIf(test);
|
||||||
if (this.handle.getType().isUser()) {
|
if (this.handle.getType() == HolderType.USER) {
|
||||||
this.handle.getPlugin().getUserManager().giveDefaultIfNeeded((User) this.handle, false);
|
this.handle.getPlugin().getUserManager().giveDefaultIfNeeded((User) this.handle, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.api.context.ContextSet;
|
|||||||
import me.lucko.luckperms.common.cacheddata.type.PermissionCache;
|
import me.lucko.luckperms.common.cacheddata.type.PermissionCache;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.Track;
|
import me.lucko.luckperms.common.model.Track;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
@ -271,7 +272,7 @@ public final class ArgumentPermissions {
|
|||||||
* @return true if the sender should NOT be allowed to act, true if they should
|
* @return true if the sender should NOT be allowed to act, true if they should
|
||||||
*/
|
*/
|
||||||
public static boolean checkGroup(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, ContextSet contextSet) {
|
public static boolean checkGroup(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, ContextSet contextSet) {
|
||||||
if (holder.getType().isGroup()) {
|
if (holder.getType() == HolderType.GROUP) {
|
||||||
return checkGroup(plugin, sender, ((Group) holder).getName(), contextSet);
|
return checkGroup(plugin, sender, ((Group) holder).getName(), contextSet);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.config.ConfigKeys;
|
|||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.Track;
|
import me.lucko.luckperms.common.model.Track;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
@ -166,10 +167,10 @@ public final class StorageAssistant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) {
|
public static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) {
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
User user = ((User) holder);
|
User user = ((User) holder);
|
||||||
save(user, sender, plugin);
|
save(user, sender, plugin);
|
||||||
} else if (holder.getType().isGroup()) {
|
} else if (holder.getType() == HolderType.GROUP) {
|
||||||
Group group = ((Group) holder);
|
Group group = ((Group) holder);
|
||||||
save(group, sender, plugin);
|
save(group, sender, plugin);
|
||||||
} else {
|
} else {
|
||||||
|
@ -38,6 +38,7 @@ import me.lucko.luckperms.common.locale.LocaleManager;
|
|||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
|
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
|
||||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||||
@ -166,7 +167,7 @@ public class MetaInfo extends SharedSubCommand {
|
|||||||
"¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFormattedDisplayName()
|
"¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFormattedDisplayName()
|
||||||
), '¥'));
|
), '¥'));
|
||||||
|
|
||||||
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
|
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
|
||||||
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
|
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
|
||||||
|
|
||||||
return component -> {
|
return component -> {
|
||||||
@ -190,7 +191,7 @@ public class MetaInfo extends SharedSubCommand {
|
|||||||
"¥7Click to remove this meta pair from " + holder.getFormattedDisplayName()
|
"¥7Click to remove this meta pair from " + holder.getFormattedDisplayName()
|
||||||
), '¥'));
|
), '¥'));
|
||||||
|
|
||||||
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
|
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
|
||||||
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
|
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
|
||||||
|
|
||||||
return component -> {
|
return component -> {
|
||||||
|
@ -37,6 +37,7 @@ import me.lucko.luckperms.common.locale.LocaleManager;
|
|||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.Track;
|
import me.lucko.luckperms.common.model.Track;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
@ -71,7 +72,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T>
|
|||||||
|
|
||||||
List<Map.Entry<Track, String>> lines = new ArrayList<>();
|
List<Map.Entry<Track, String>> lines = new ArrayList<>();
|
||||||
|
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
// if the holder is a user, we want to query parent groups for tracks
|
// if the holder is a user, we want to query parent groups for tracks
|
||||||
Set<Node> nodes = holder.enduringData().immutable().values().stream()
|
Set<Node> nodes = holder.enduringData().immutable().values().stream()
|
||||||
.filter(Node::isGroupNode)
|
.filter(Node::isGroupNode)
|
||||||
|
@ -40,6 +40,7 @@ import me.lucko.luckperms.common.command.utils.StorageAssistant;
|
|||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.Track;
|
import me.lucko.luckperms.common.model.Track;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
@ -95,7 +96,7 @@ public class ParentClearTrack extends SharedSubCommand {
|
|||||||
holder.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName()));
|
holder.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ import me.lucko.luckperms.common.command.utils.SortType;
|
|||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
|
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
|
||||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||||
@ -141,7 +142,7 @@ public class ParentInfo extends SharedSubCommand {
|
|||||||
"&7Click to remove this parent from " + holder.getFormattedDisplayName()
|
"&7Click to remove this parent from " + holder.getFormattedDisplayName()
|
||||||
), CommandManager.AMPERSAND_CHAR));
|
), CommandManager.AMPERSAND_CHAR));
|
||||||
|
|
||||||
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
|
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
|
||||||
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
|
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
|
||||||
|
|
||||||
return component -> {
|
return component -> {
|
||||||
|
@ -42,6 +42,7 @@ import me.lucko.luckperms.common.config.ConfigKeys;
|
|||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||||
@ -74,7 +75,7 @@ public class ParentRemove extends SharedSubCommand {
|
|||||||
return CommandResult.NO_PERMISSION;
|
return CommandResult.NO_PERMISSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
User user = (User) holder;
|
User user = (User) holder;
|
||||||
|
|
||||||
boolean shouldPrevent = plugin.getConfiguration().get(ConfigKeys.PREVENT_PRIMARY_GROUP_REMOVAL) &&
|
boolean shouldPrevent = plugin.getConfiguration().get(ConfigKeys.PREVENT_PRIMARY_GROUP_REMOVAL) &&
|
||||||
@ -96,7 +97,7 @@ public class ParentRemove extends SharedSubCommand {
|
|||||||
.action("parent", "remove", groupName, context)
|
.action("parent", "remove", groupName, context)
|
||||||
.build().submit(plugin, sender);
|
.build().submit(plugin, sender);
|
||||||
|
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ import me.lucko.luckperms.common.locale.LocaleManager;
|
|||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||||
@ -80,7 +81,7 @@ public class ParentSet extends SharedSubCommand {
|
|||||||
|
|
||||||
holder.clearParents(context, false);
|
holder.clearParents(context, false);
|
||||||
holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
|
holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
((User) holder).getPrimaryGroup().setStoredValue(group.getName());
|
((User) holder).getPrimaryGroup().setStoredValue(group.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ import me.lucko.luckperms.common.command.utils.SortType;
|
|||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
import me.lucko.luckperms.common.locale.command.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
|
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
|
||||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||||
@ -143,7 +144,7 @@ public class PermissionInfo extends SharedSubCommand {
|
|||||||
"¥7Click to remove this node from " + holder.getFormattedDisplayName()
|
"¥7Click to remove this node from " + holder.getFormattedDisplayName()
|
||||||
), '¥'));
|
), '¥'));
|
||||||
|
|
||||||
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
|
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType() == HolderType.GROUP ? holder.getObjectName() : holder.getFormattedDisplayName(), holder.getType(), false, !holder.getPlugin().getConfiguration().getContextsFile().getDefaultContexts().isEmpty());
|
||||||
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
|
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
|
||||||
|
|
||||||
return component -> {
|
return component -> {
|
||||||
|
@ -78,6 +78,7 @@ import me.lucko.luckperms.common.event.model.EntitySourceImpl;
|
|||||||
import me.lucko.luckperms.common.event.model.SenderEntity;
|
import me.lucko.luckperms.common.event.model.SenderEntity;
|
||||||
import me.lucko.luckperms.common.event.model.UnknownSource;
|
import me.lucko.luckperms.common.event.model.UnknownSource;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.Track;
|
import me.lucko.luckperms.common.model.Track;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
@ -267,7 +268,7 @@ public final class EventFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleDataRecalculate(PermissionHolder holder) {
|
public void handleDataRecalculate(PermissionHolder holder) {
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
User user = (User) holder;
|
User user = (User) holder;
|
||||||
post(UserDataRecalculateEvent.class, () -> generate(UserDataRecalculateEvent.class, user.getApiDelegate(), user.getCachedData()));
|
post(UserDataRecalculateEvent.class, () -> generate(UserDataRecalculateEvent.class, user.getApiDelegate(), user.getCachedData()));
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package me.lucko.luckperms.common.inheritance;
|
package me.lucko.luckperms.common.inheritance;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
import me.lucko.luckperms.common.node.factory.NodeFactory;
|
||||||
@ -39,7 +40,7 @@ public class InheritanceComparator implements Comparator<Group> {
|
|||||||
private static final Comparator<Group> NULL_ORIGIN = new InheritanceComparator(null);
|
private static final Comparator<Group> NULL_ORIGIN = new InheritanceComparator(null);
|
||||||
|
|
||||||
public static Comparator<Group> getFor(PermissionHolder origin) {
|
public static Comparator<Group> getFor(PermissionHolder origin) {
|
||||||
if (origin.getType().isUser()) {
|
if (origin.getType() == HolderType.USER) {
|
||||||
return new InheritanceComparator(((User) origin));
|
return new InheritanceComparator(((User) origin));
|
||||||
}
|
}
|
||||||
return NULL_ORIGIN;
|
return NULL_ORIGIN;
|
||||||
|
@ -26,32 +26,11 @@
|
|||||||
package me.lucko.luckperms.common.model;
|
package me.lucko.luckperms.common.model;
|
||||||
|
|
||||||
public enum HolderType {
|
public enum HolderType {
|
||||||
|
USER,
|
||||||
USER(true, false),
|
GROUP;
|
||||||
GROUP(false, true);
|
|
||||||
|
|
||||||
private final boolean user;
|
|
||||||
private final boolean group;
|
|
||||||
|
|
||||||
HolderType(boolean user, boolean group) {
|
|
||||||
this.user = user;
|
|
||||||
this.group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(PermissionHolder holder) {
|
|
||||||
return holder.getType() == this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name().toLowerCase();
|
return name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUser() {
|
|
||||||
return this.user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGroup() {
|
|
||||||
return this.group;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -506,7 +506,7 @@ public abstract class PermissionHolder {
|
|||||||
* @return a tristate, returns undefined if no match
|
* @return a tristate, returns undefined if no match
|
||||||
*/
|
*/
|
||||||
public Tristate hasPermission(NodeMapType type, Node node, NodeEqualityPredicate equalityPredicate) {
|
public Tristate hasPermission(NodeMapType type, Node node, NodeEqualityPredicate equalityPredicate) {
|
||||||
if (this.getType().isGroup() && node.isGroupNode() && node.getGroupName().equalsIgnoreCase(getObjectName())) {
|
if (this.getType() == HolderType.GROUP && node.isGroupNode() && node.getGroupName().equalsIgnoreCase(getObjectName())) {
|
||||||
return Tristate.TRUE;
|
return Tristate.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,7 +713,7 @@ public abstract class PermissionHolder {
|
|||||||
|
|
||||||
public boolean clearParents(boolean giveDefault) {
|
public boolean clearParents(boolean giveDefault) {
|
||||||
return removeIf(Node::isGroupNode, () -> {
|
return removeIf(Node::isGroupNode, () -> {
|
||||||
if (this.getType().isUser() && giveDefault) {
|
if (this.getType() == HolderType.USER && giveDefault) {
|
||||||
this.plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
|
this.plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -721,7 +721,7 @@ public abstract class PermissionHolder {
|
|||||||
|
|
||||||
public boolean clearParents(ContextSet contextSet, boolean giveDefault) {
|
public boolean clearParents(ContextSet contextSet, boolean giveDefault) {
|
||||||
return removeIf(contextSet, Node::isGroupNode, () -> {
|
return removeIf(contextSet, Node::isGroupNode, () -> {
|
||||||
if (this.getType().isUser() && giveDefault) {
|
if (this.getType() == HolderType.USER && giveDefault) {
|
||||||
this.plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
|
this.plugin.getUserManager().giveDefaultIfNeeded((User) this, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package me.lucko.luckperms.common.model.manager.user;
|
package me.lucko.luckperms.common.model.manager.user;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableCollection;
|
import com.google.common.collect.ImmutableCollection;
|
||||||
|
import com.google.common.collect.Streams;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.LocalizedNode;
|
import me.lucko.luckperms.api.LocalizedNode;
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
@ -42,6 +43,7 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public abstract class AbstractUserManager<T extends User> extends AbstractManager<UserIdentifier, User, T> implements UserManager<T> {
|
public abstract class AbstractUserManager<T extends User> extends AbstractManager<UserIdentifier, User, T> implements UserManager<T> {
|
||||||
|
|
||||||
@ -152,7 +154,12 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
|
|||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> updateAllUsers() {
|
public CompletableFuture<Void> updateAllUsers() {
|
||||||
return CompletableFuture.runAsync(
|
return CompletableFuture.runAsync(
|
||||||
() -> this.plugin.getBootstrap().getOnlinePlayers().forEach(u -> this.plugin.getStorage().loadUser(u, null).join()),
|
() -> {
|
||||||
|
Stream.concat(
|
||||||
|
getAll().keySet().stream().map(UserIdentifier::getUuid),
|
||||||
|
this.plugin.getBootstrap().getOnlinePlayers()
|
||||||
|
).forEach(u -> this.plugin.getStorage().loadUser(u, null).join());
|
||||||
|
},
|
||||||
this.plugin.getBootstrap().getScheduler().async()
|
this.plugin.getBootstrap().getScheduler().async()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,6 @@ public class SyncTask implements Runnable {
|
|||||||
this.plugin.getStorage().loadAllTracks().join();
|
this.plugin.getStorage().loadAllTracks().join();
|
||||||
|
|
||||||
// Refresh all online users.
|
// Refresh all online users.
|
||||||
this.plugin.getUserManager().invalidateAllUserCaches();
|
|
||||||
CompletableFuture<Void> userUpdateFut = this.plugin.getUserManager().updateAllUsers();
|
CompletableFuture<Void> userUpdateFut = this.plugin.getUserManager().updateAllUsers();
|
||||||
if (!this.initialUpdate) {
|
if (!this.initialUpdate) {
|
||||||
userUpdateFut.join();
|
userUpdateFut.join();
|
||||||
|
@ -34,6 +34,7 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
|
|||||||
import me.lucko.luckperms.common.context.ContextSetJsonSerializer;
|
import me.lucko.luckperms.common.context.ContextSetJsonSerializer;
|
||||||
import me.lucko.luckperms.common.locale.message.Message;
|
import me.lucko.luckperms.common.locale.message.Message;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.model.NodeDataContainer;
|
import me.lucko.luckperms.common.node.model.NodeDataContainer;
|
||||||
@ -74,7 +75,7 @@ public final class WebEditor {
|
|||||||
.add("id", getHolderIdentifier(holder))
|
.add("id", getHolderIdentifier(holder))
|
||||||
.add("friendly", holder.getPlainDisplayName())
|
.add("friendly", holder.getPlainDisplayName())
|
||||||
.consume(obj -> {
|
.consume(obj -> {
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
obj.add("uuid", ((User) holder).getUuid().toString());
|
obj.add("uuid", ((User) holder).getUuid().toString());
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
@ -111,7 +112,7 @@ public final class WebEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String getHolderIdentifier(PermissionHolder holder) {
|
private static String getHolderIdentifier(PermissionHolder holder) {
|
||||||
if (holder.getType().isUser()) {
|
if (holder.getType() == HolderType.USER) {
|
||||||
User user = ((User) holder);
|
User user = ((User) holder);
|
||||||
return USER_ID_PATTERN + user.getUuid().toString();
|
return USER_ID_PATTERN + user.getUuid().toString();
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,6 +36,7 @@ import me.lucko.luckperms.common.calculator.processor.PermissionProcessor;
|
|||||||
import me.lucko.luckperms.common.calculator.processor.RegexProcessor;
|
import me.lucko.luckperms.common.calculator.processor.RegexProcessor;
|
||||||
import me.lucko.luckperms.common.calculator.processor.WildcardProcessor;
|
import me.lucko.luckperms.common.calculator.processor.WildcardProcessor;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
|
|
||||||
public class SpongeCalculatorFactory implements CalculatorFactory {
|
public class SpongeCalculatorFactory implements CalculatorFactory {
|
||||||
@ -64,9 +65,9 @@ public class SpongeCalculatorFactory implements CalculatorFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_DEFAULT_SUBJECTS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_SPONGE_DEFAULT_SUBJECTS)) {
|
||||||
if (metadata.getHolderType().isUser()) {
|
if (metadata.getHolderType() == HolderType.USER) {
|
||||||
processors.add(new UserDefaultsProcessor(this.plugin.getService(), contexts.getContexts().makeImmutable()));
|
processors.add(new UserDefaultsProcessor(this.plugin.getService(), contexts.getContexts().makeImmutable()));
|
||||||
} else if (metadata.getHolderType().isGroup()) {
|
} else if (metadata.getHolderType() == HolderType.GROUP) {
|
||||||
processors.add(new GroupDefaultsProcessor(this.plugin.getService(), contexts.getContexts().makeImmutable()));
|
processors.add(new GroupDefaultsProcessor(this.plugin.getService(), contexts.getContexts().makeImmutable()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import me.lucko.luckperms.api.Tristate;
|
|||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator;
|
import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
|
import me.lucko.luckperms.common.model.HolderType;
|
||||||
import me.lucko.luckperms.common.model.NodeMapType;
|
import me.lucko.luckperms.common.model.NodeMapType;
|
||||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
@ -157,7 +158,7 @@ public class PermissionHolderSubjectData implements LPSubjectData {
|
|||||||
return CompletableFuture.completedFuture(false);
|
return CompletableFuture.completedFuture(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.holder.getType().isUser()) {
|
if (this.holder.getType() == HolderType.USER) {
|
||||||
this.service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) this.holder), false);
|
this.service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) this.holder), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +184,7 @@ public class PermissionHolderSubjectData implements LPSubjectData {
|
|||||||
return CompletableFuture.completedFuture(false);
|
return CompletableFuture.completedFuture(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.holder.getType().isUser()) {
|
if (this.holder.getType() == HolderType.USER) {
|
||||||
this.service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) this.holder), false);
|
this.service.getPlugin().getUserManager().giveDefaultIfNeeded(((User) this.holder), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,7 +472,7 @@ public class PermissionHolderSubjectData implements LPSubjectData {
|
|||||||
|
|
||||||
private CompletableFuture<Void> save(PermissionHolder t) {
|
private CompletableFuture<Void> save(PermissionHolder t) {
|
||||||
// if the holder is a group, invalidate caches.
|
// if the holder is a group, invalidate caches.
|
||||||
if (t.getType().isGroup()) {
|
if (t.getType() == HolderType.GROUP) {
|
||||||
this.service.getPlugin().getGroupManager().invalidateAllGroupCaches();
|
this.service.getPlugin().getGroupManager().invalidateAllGroupCaches();
|
||||||
this.service.getPlugin().getUserManager().invalidateAllUserCaches();
|
this.service.getPlugin().getUserManager().invalidateAllUserCaches();
|
||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
@ -482,7 +483,7 @@ public class PermissionHolderSubjectData implements LPSubjectData {
|
|||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.getType().isUser()) {
|
if (t.getType() == HolderType.USER) {
|
||||||
User user = ((User) t);
|
User user = ((User) t);
|
||||||
return this.service.getPlugin().getStorage().saveUser(user);
|
return this.service.getPlugin().getStorage().saveUser(user);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user