diff --git a/api/src/main/java/me/lucko/luckperms/api/context/AbstractContextSet.java b/api/src/main/java/me/lucko/luckperms/api/context/AbstractContextSet.java index 69e2b557a..8b8064e4a 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/AbstractContextSet.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/AbstractContextSet.java @@ -39,7 +39,6 @@ abstract class AbstractContextSet implements ContextSet { protected abstract Multimap backing(); - @Nonnull @Override public boolean containsKey(@Nonnull String key) { return backing().containsKey(sanitizeKey(key)); @@ -52,13 +51,11 @@ abstract class AbstractContextSet implements ContextSet { return values != null ? ImmutableSet.copyOf(values) : ImmutableSet.of(); } - @Nonnull @Override public boolean has(@Nonnull String key, @Nonnull String value) { return backing().containsEntry(sanitizeKey(key), sanitizeValue(value)); } - @Nonnull @Override public boolean hasIgnoreCase(@Nonnull String key, @Nonnull String value) { String v = sanitizeValue(value); @@ -90,6 +87,28 @@ abstract class AbstractContextSet implements ContextSet { return backing().size(); } + @Override + public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof ContextSet)) return false; + final ContextSet other = (ContextSet) o; + + final Multimap otherContexts; + + if (other instanceof MutableContextSet) { + otherContexts = ((MutableContextSet) other).backing(); + } else { + otherContexts = other.toMultimap(); + } + + return backing().equals(otherContexts); + } + + @Override + public int hashCode() { + return backing().hashCode(); + } + static String sanitizeKey(String key) { return checkNotNull(key, "key is null").toLowerCase().intern(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/context/ContextSet.java b/api/src/main/java/me/lucko/luckperms/api/context/ContextSet.java index 0435be75a..ee91da426 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/ContextSet.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/ContextSet.java @@ -277,7 +277,7 @@ public interface ContextSet { * @since 3.1 */ default boolean isSatisfiedBy(@Nonnull ContextSet other) { - return isSatisfiedBy(other, true); + return this == other || isSatisfiedBy(other, true); } /** @@ -289,6 +289,10 @@ public interface ContextSet { * @since 3.4 */ default boolean isSatisfiedBy(@Nonnull ContextSet other, boolean caseSensitive) { + if (this == other) { + return true; + } + Preconditions.checkNotNull(other, "other"); if (this.isEmpty()) { // this is empty, so is therefore always satisfied. diff --git a/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java b/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java index d6b4e10b0..a2d31387e 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java @@ -40,9 +40,6 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * An immutable implementation of {@link ContextSet}. * - *

On construction, all keys/values are {@link String#intern()}ed, in order to increase - * comparison speed.

- * * @since 2.16 */ public final class ImmutableContextSet extends AbstractContextSet implements ContextSet { @@ -164,9 +161,11 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con } private final ImmutableSetMultimap map; + private final int hashCode; ImmutableContextSet(ImmutableSetMultimap contexts) { this.map = contexts; + this.hashCode = map.hashCode(); } @Override @@ -216,26 +215,9 @@ public final class ImmutableContextSet extends AbstractContextSet implements Con return map; } - @Override - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof ContextSet)) return false; - final ContextSet other = (ContextSet) o; - - final Multimap otherContexts; - - if (other instanceof MutableContextSet) { - otherContexts = ((MutableContextSet) other).backing(); - } else { - otherContexts = other.toMultimap(); - } - - return this.map.equals(otherContexts); - } - @Override public int hashCode() { - return map.hashCode(); + return hashCode; } @Override diff --git a/api/src/main/java/me/lucko/luckperms/api/context/MutableContextSet.java b/api/src/main/java/me/lucko/luckperms/api/context/MutableContextSet.java index bccf6f247..4016124f3 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/MutableContextSet.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/MutableContextSet.java @@ -45,9 +45,6 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * A mutable implementation of {@link ContextSet}. * - *

On construction, all keys/values are {@link String#intern()}ed, in order to increase - * comparison speed.

- * * @since 2.16 */ public final class MutableContextSet extends AbstractContextSet implements ContextSet { @@ -338,28 +335,6 @@ public final class MutableContextSet extends AbstractContextSet implements Conte map.clear(); } - @Override - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof ContextSet)) return false; - final ContextSet other = (ContextSet) o; - - final Multimap otherContexts; - - if (other instanceof MutableContextSet) { - otherContexts = ((MutableContextSet) other).map; - } else { - otherContexts = other.toMultimap(); - } - - return this.map.equals(otherContexts); - } - - @Override - public int hashCode() { - return map.hashCode(); - } - @Override public String toString() { return "MutableContextSet(contexts=" + this.map + ")"; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index 24939556b..4440a2de1 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -51,8 +51,6 @@ import ru.tehkode.permissions.PermissionGroup; import ru.tehkode.permissions.PermissionManager; import ru.tehkode.permissions.bukkit.PermissionsEx; -import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; @@ -125,9 +123,9 @@ public class MigrationPermissionsEx extends SubCommand { // Get a list of all groups in a ladder List ladder = manager.getRankLadder(rankLadder).entrySet().stream() - .sorted(Comparator.>comparingInt(e -> e.getKey()).reversed()) - .map(e -> MigrationUtils.standardizeName(e.getValue().getName())) - .collect(Collectors.toList()); + .sorted(Comparator.>comparingInt(Map.Entry::getKey).reversed()) + .map(e -> MigrationUtils.standardizeName(e.getValue().getName())) + .collect(Collectors.toList()); track.setGroups(ladder); plugin.getStorage().saveTrack(track); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPSubscriptionMap.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPSubscriptionMap.java index 740253430..81049ad89 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPSubscriptionMap.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPSubscriptionMap.java @@ -74,7 +74,8 @@ public class LPSubscriptionMap extends HashMap this.plugin = plugin; } - /* The get method is the only one which is actually used by SimplePluginManager + /* + * The get method is the only one which is actually used by SimplePluginManager * we override it to always return a value - which means the null check in * subscribeToDefaultPerms always fails - soo, we don't have to worry too much * about implementing #put. diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/PermissibleInjector.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/PermissibleInjector.java index 9902c61a6..6c634e9c1 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/PermissibleInjector.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/PermissibleInjector.java @@ -47,7 +47,7 @@ public class PermissibleInjector { /** * All permission checks made on standard Bukkit objects are effectively proxied to a - * {@link PermissibleBase} object, held as a parameter on the object. + * {@link PermissibleBase} object, held as a variable on the object. * * This field is where the permissible is stored on a HumanEntity. */ diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java index 093e80d32..e23c612b2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java @@ -249,7 +249,7 @@ public class CommandManager { @SuppressWarnings("unchecked") String permission = (String) c.getPermission().map(p -> ((CommandPermission) p).getPermission()).orElse("None"); - TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), Constants.FORMAT_CHAR) + TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), Constants.AMPERSAND_CHAR) .toBuilder().applyDeep(comp -> { comp.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline( "&bCommand: &2" + c.getName(), @@ -258,7 +258,7 @@ public class CommandManager { "&bPermission: &2" + permission, " ", "&7Click to auto-complete." - ), Constants.FORMAT_CHAR))); + ), Constants.AMPERSAND_CHAR))); comp.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format(c.getUsage(), label))); }).build(); sender.sendMessage(component); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java index de4a3d642..5dae1d5d0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java @@ -84,7 +84,7 @@ public class MetaAddChatMeta extends SharedSubCommand { DataMutateResult result = holder.setPermission(NodeFactory.makeChatMetaNode(type, priority, meta).withExtraContext(context).build()); if (result.asBoolean()) { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), Constants.SECTION_CHAR).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( "¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta, '¥' diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java index 621774938..96e9417c6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java @@ -94,7 +94,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand { if (ret.getKey().asBoolean()) { duration = ret.getValue().getExpiryUnixTime(); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, DateUtil.formatDateDiff(duration), CommandUtils.contextSetToString(context)), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, DateUtil.formatDateDiff(duration), CommandUtils.contextSetToString(context)), Constants.SECTION_CHAR).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( "¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta, '¥' diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaInfo.java index 605c93fd3..eadbed8a5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaInfo.java @@ -125,11 +125,11 @@ public class MetaInfo extends SharedSubCommand { String location = processLocation(m, holder); if (m.hasSpecificContext()) { String context = CommandUtils.getAppendableNodeContextString(m); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location, context), Constants.SECTION_CHAR).toBuilder(); builder.applyDeep(makeFancy(holder, label, m)); sender.sendMessage(builder.build()); } else { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.META_ENTRY.asString(sender.getPlatform().getLocaleManager(), m.getMeta().getKey(), m.getMeta().getValue(), location), Constants.SECTION_CHAR).toBuilder(); builder.applyDeep(makeFancy(holder, label, m)); sender.sendMessage(builder.build()); } @@ -141,11 +141,11 @@ public class MetaInfo extends SharedSubCommand { String location = processLocation(e.getValue(), holder); if (e.getValue().hasSpecificContext()) { String context = CommandUtils.getAppendableNodeContextString(e.getValue()); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.CHAT_META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location, context), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.CHAT_META_ENTRY_WITH_CONTEXT.asString(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location, context), Constants.SECTION_CHAR).toBuilder(); builder.applyDeep(makeFancy(type, holder, label, e.getValue())); sender.sendMessage(builder.build()); } else { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.CHAT_META_ENTRY.asString(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.CHAT_META_ENTRY.asString(sender.getPlatform().getLocaleManager(), e.getKey(), type.getEntry(e.getValue()).getValue(), location), Constants.SECTION_CHAR).toBuilder(); builder.applyDeep(makeFancy(type, holder, label, e.getValue())); sender.sendMessage(builder.build()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java index 9ffbddbd5..4c842ac8a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java @@ -103,7 +103,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand { DataMutateResult result = holder.unsetPermission(NodeFactory.makeChatMetaNode(type, priority, meta).withExtraContext(context).build()); if (result.asBoolean()) { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), Constants.SECTION_CHAR).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( "¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta, '¥' diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java index 5b61086bb..85a36da2c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java @@ -103,7 +103,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand { DataMutateResult result = holder.unsetPermission(NodeFactory.makeChatMetaNode(type, priority, meta).setExpiry(10L).withExtraContext(context).build()); if (result.asBoolean()) { - TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), type.name().toLowerCase(), meta, priority, CommandUtils.contextSetToString(context)), Constants.SECTION_CHAR).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( "¥3Raw " + type.name().toLowerCase() + ": ¥r" + meta, '¥' diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java index 97fe54839..c166ce04e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java @@ -92,7 +92,7 @@ public class MetaSetTemp extends SharedSubCommand { holder.clearMetaKeys(key, context, true); duration = holder.setPermission(n, modifier).getValue().getExpiryUnixTime(); - TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_TEMP_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration), CommandUtils.contextSetToString(context)), Constants.COLOR_CHAR).toBuilder(); + TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_TEMP_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration), CommandUtils.contextSetToString(context)), Constants.SECTION_CHAR).toBuilder(); HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy( TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥' diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentInfo.java index 1924bda18..b23407ce3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentInfo.java @@ -118,7 +118,7 @@ public class ParentInfo extends SharedSubCommand { s += "\n&2 expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()); } - TextComponent message = TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build(); + TextComponent message = TextUtils.fromLegacy(s, Constants.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build(); sender.sendMessage(message); } @@ -140,7 +140,7 @@ public class ParentInfo extends SharedSubCommand { "&3> &f" + node.getGroupName(), " ", "&7Click to remove this parent from " + holder.getFriendlyName() - ), Constants.FORMAT_CHAR)); + ), Constants.AMPERSAND_CHAR)); String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false); ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionInfo.java index 7d813021a..6dcfad737 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionInfo.java @@ -123,7 +123,7 @@ public class PermissionInfo extends SharedSubCommand { s += "\n&2- expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()); } - TextComponent message = TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build(); + TextComponent message = TextUtils.fromLegacy(s, Constants.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(holder, label, node)).build(); sender.sendMessage(message); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupListMembers.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupListMembers.java index 91968490a..b3d9973c5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupListMembers.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupListMembers.java @@ -140,7 +140,7 @@ public class GroupListMembers extends SubCommand { for (Map.Entry> ent : mappedContent) { String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + CommandUtils.getAppendableNodeContextString(ent.getValue().asNode()); - TextComponent message = TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build(); + TextComponent message = TextUtils.fromLegacy(s, Constants.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build(); sender.sendMessage(message); } } @@ -158,7 +158,7 @@ public class GroupListMembers extends SubCommand { "&3> &b" + perm.asNode().getGroupName(), " ", "&7Click to remove this parent from " + holderName - ), Constants.FORMAT_CHAR)); + ), Constants.AMPERSAND_CHAR)); String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false); ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/ListGroups.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/ListGroups.java index 7ee25f799..c15ef7f35 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/ListGroups.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/ListGroups.java @@ -73,13 +73,13 @@ public class ListGroups extends SingleCommand { component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY.asString(plugin.getLocaleManager(), group.getFriendlyName(), group.getWeight().orElse(0) - ), Constants.COLOR_CHAR); + ), Constants.SECTION_CHAR); } else { component = TextUtils.fromLegacy(Message.GROUPS_LIST_ENTRY_WITH_TRACKS.asString(plugin.getLocaleManager(), group.getFriendlyName(), group.getWeight().orElse(0), CommandUtils.toCommaSep(tracks) - ), Constants.COLOR_CHAR); + ), Constants.SECTION_CHAR); } component = component.toBuilder().applyDeep(c -> { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/SearchCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/SearchCommand.java index b659037d5..cb3531ced 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/SearchCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/SearchCommand.java @@ -139,7 +139,7 @@ public class SearchCommand extends SingleCommand { for (Map.Entry> ent : mappedContent) { String s = "&3> &b" + ent.getKey() + " &7- " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + CommandUtils.getAppendableNodeContextString(ent.getValue().asNode()); - TextComponent message = TextUtils.fromLegacy(s, Constants.FORMAT_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build(); + TextComponent message = TextUtils.fromLegacy(s, Constants.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build(); sender.sendMessage(message); } } @@ -157,7 +157,7 @@ public class SearchCommand extends SingleCommand { "&3> " + (perm.asNode().getValuePrimitive() ? "&a" : "&c") + perm.asNode().getPermission(), " ", "&7Click to remove this node from " + holderName - ), Constants.FORMAT_CHAR)); + ), Constants.AMPERSAND_CHAR)); String command = "/" + label + " " + NodeFactory.nodeAsCommand(perm.asNode(), holderName, holderType, false); ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command); diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Constants.java b/common/src/main/java/me/lucko/luckperms/common/constants/Constants.java index 767db34d4..b5e741477 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Constants.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Constants.java @@ -41,7 +41,7 @@ public class Constants { public static final UUID IMPORT_UUID = UUID.fromString("11111111-1111-1111-1111-111111111111"); public static final String IMPORT_NAME = "Import"; - public static final char COLOR_CHAR = '\u00A7'; - public static final char FORMAT_CHAR = '&'; + public static final char SECTION_CHAR = '\u00A7'; // § + public static final char AMPERSAND_CHAR = '&'; } diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java b/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java index 63d5fc6d0..b516c4ea1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/DataConstraints.java @@ -46,98 +46,24 @@ public class DataConstraints { public static final int MAX_SERVER_LENGTH = 36; public static final int MAX_WORLD_LENGTH = 36; - public static final Predicate PERMISSION_TEST = s -> { - if (s.length() <= 0 || s.length() > MAX_PERMISSION_LENGTH) { - return false; - } + public static final Predicate PERMISSION_TEST = s -> s.length() > 0 && s.length() <= MAX_PERMISSION_LENGTH; - return true; - }; + public static final Predicate PLAYER_USERNAME_TEST = s -> s.length() > 0 && s.length() <= MAX_PLAYER_USERNAME_LENGTH && !PLAYER_USERNAME_INVALID_CHAR_MATCHER.matcher(s).find(); - public static final Predicate PLAYER_USERNAME_TEST = s -> { - if (s.length() <= 0 || s.length() > MAX_PLAYER_USERNAME_LENGTH) { - return false; - } + public static final Predicate PLAYER_USERNAME_TEST_LENIENT = s -> s.length() > 0 && s.length() <= MAX_PLAYER_USERNAME_LENGTH; - if (PLAYER_USERNAME_INVALID_CHAR_MATCHER.matcher(s).find()) { - return false; - } + public static final Predicate GROUP_NAME_TEST = s -> s.length() > 0 && s.length() <= MAX_GROUP_NAME_LENGTH && !s.contains(" "); - return true; - }; + public static final Predicate GROUP_NAME_TEST_ALLOW_SPACE = s -> s.length() > 0 && s.length() <= MAX_GROUP_NAME_LENGTH; - public static final Predicate PLAYER_USERNAME_TEST_LENIENT = s -> { - if (s.length() <= 0 || s.length() > MAX_PLAYER_USERNAME_LENGTH) { - return false; - } + public static final Predicate TRACK_NAME_TEST = s -> s.length() > 0 && s.length() <= MAX_TRACK_NAME_LENGTH && !s.contains(" "); - return true; - }; - - public static final Predicate GROUP_NAME_TEST = s -> { - if (s.length() <= 0 || s.length() > MAX_GROUP_NAME_LENGTH) { - return false; - } - - if (s.contains(" ")) { - return false; - } - - return true; - }; - - public static final Predicate GROUP_NAME_TEST_ALLOW_SPACE = s -> { - if (s.length() <= 0 || s.length() > MAX_GROUP_NAME_LENGTH) { - return false; - } - - return true; - }; - - public static final Predicate TRACK_NAME_TEST = s -> { - if (s.length() <= 0 || s.length() > MAX_TRACK_NAME_LENGTH) { - return false; - } - - if (s.contains(" ")) { - return false; - } - - return true; - }; - - public static final Predicate TRACK_NAME_TEST_ALLOW_SPACE = s -> { - if (s.length() <= 0 || s.length() > MAX_TRACK_NAME_LENGTH) { - return false; - } - - return true; - }; + public static final Predicate TRACK_NAME_TEST_ALLOW_SPACE = s -> s.length() > 0 && s.length() <= MAX_TRACK_NAME_LENGTH; public static final Predicate TIME_TEST = unixTime -> !DateUtil.shouldExpire(unixTime); - public static final Predicate SERVER_NAME_TEST = s -> { - if (s.length() <= 0 || s.length() > MAX_SERVER_LENGTH) { - return false; - } + public static final Predicate SERVER_NAME_TEST = s -> s.length() > 0 && s.length() <= MAX_SERVER_LENGTH && !s.contains(" "); - if (s.contains(" ")) { - return false; - } - - return true; - }; - - public static final Predicate WORLD_NAME_TEST = s -> { - if (s.length() <= 0 || s.length() > MAX_WORLD_LENGTH) { - return false; - } - - if (s.contains(" ")) { - return false; - } - - return true; - }; + public static final Predicate WORLD_NAME_TEST = s -> s.length() > 0 && s.length() <= MAX_WORLD_LENGTH && !s.contains(" "); } diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java index 1cd533a93..3da556ca8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java @@ -57,7 +57,7 @@ public abstract class AbstractContextManager implements ContextManager { protected final LuckPermsPlugin plugin; private final Class subjectClass; - private final List> calculators = new CopyOnWriteArrayList<>(); + private final List> calculators = new CopyOnWriteArrayList<>(); private final List staticCalculators = new CopyOnWriteArrayList<>(); // caches context lookups @@ -140,16 +140,14 @@ public abstract class AbstractContextManager implements ContextManager { } @Override - public void registerCalculator(ContextCalculator calculator) { + public void registerCalculator(ContextCalculator calculator) { // calculators registered first should have priority (and be checked last.) calculators.add(0, calculator); } @Override public void registerStaticCalculator(StaticContextCalculator calculator) { - //noinspection unchecked - registerCalculator((ContextCalculator) calculator); - + registerCalculator(calculator); staticCalculators.add(0, calculator); } @@ -168,7 +166,7 @@ public abstract class AbstractContextManager implements ContextManager { public Contexts load(T subject) { MutableContextSet accumulator = MutableContextSet.create(); - for (ContextCalculator calculator : calculators) { + for (ContextCalculator calculator : calculators) { try { MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator); //noinspection ConstantConditions diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java index 2d18dfdd9..614817b8c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java @@ -108,7 +108,7 @@ public interface ContextManager { * * @param calculator the calculator */ - void registerCalculator(ContextCalculator calculator); + void registerCalculator(ContextCalculator calculator); /** * Registers a static context calculator with the manager. diff --git a/common/src/main/java/me/lucko/luckperms/common/node/NodeModel.java b/common/src/main/java/me/lucko/luckperms/common/node/NodeModel.java index b5441bdc6..ac6983266 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/NodeModel.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/NodeModel.java @@ -134,6 +134,7 @@ public final class NodeModel { return of(permission, value, server, world, expiry, contexts); } + @Override public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof NodeModel)) return false; @@ -147,6 +148,7 @@ public final class NodeModel { this.getContexts().equals(other.getContexts()); } + @Override public int hashCode() { final int PRIME = 59; int result = 1; @@ -159,6 +161,7 @@ public final class NodeModel { return result; } + @Override public String toString() { return "NodeModel(" + "permission=" + this.getPermission() + ", " + diff --git a/common/src/main/java/me/lucko/luckperms/common/node/NodeWithContextComparator.java b/common/src/main/java/me/lucko/luckperms/common/node/NodeWithContextComparator.java index be4508b02..1e40ecafa 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/NodeWithContextComparator.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/NodeWithContextComparator.java @@ -95,5 +95,4 @@ public class NodeWithContextComparator implements Comparator { return CollationKeyCache.compareStrings(o1.getPermission(), o2.getPermission()) == 1 ? -1 : 1; } - } diff --git a/common/src/main/java/me/lucko/luckperms/common/node/ShorthandParser.java b/common/src/main/java/me/lucko/luckperms/common/node/ShorthandParser.java index c19dc692f..52768e42d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/ShorthandParser.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/ShorthandParser.java @@ -47,10 +47,6 @@ public class ShorthandParser { .build(); public static Set parseShorthand(String s) { - return parseShorthand(s, true); - } - - public static Set parseShorthand(String s, boolean removeSelf) { Set results = new HashSet<>(); results.add(s); @@ -75,9 +71,8 @@ public class ShorthandParser { break; } - if (removeSelf) { - results.remove(s); - } + // remove self + results.remove(s); return results; } diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java index 2621555f7..4db22b307 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java @@ -151,7 +151,7 @@ public class VerboseListener { } // send the message - HoverEvent e = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(hover.stream()), Constants.FORMAT_CHAR)); + HoverEvent e = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline(hover.stream()), Constants.AMPERSAND_CHAR)); TextComponent msg = textComponent.toBuilder().applyDeep(comp -> comp.hoverEvent(e)).build(); notifiedSender.sendMessage(msg); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/legacy/SubjectDataHolder.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/legacy/SubjectDataHolder.java index a04d80b79..b15c668d1 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/legacy/SubjectDataHolder.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/legacy/SubjectDataHolder.java @@ -40,6 +40,7 @@ import java.util.stream.Collectors; * @deprecated Because this format is no longer being used to store data. * @see SubjectStorageModel */ +@SuppressWarnings("DeprecatedIsStillUsed") @ToString @Deprecated public class SubjectDataHolder {