Misc cleanup

This commit is contained in:
Luck 2017-12-17 12:17:46 +00:00
parent ad5299d0cd
commit f86bdb7619
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
28 changed files with 79 additions and 178 deletions

View File

@ -39,7 +39,6 @@ abstract class AbstractContextSet implements ContextSet {
protected abstract Multimap<String, String> 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<String, String> 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();
}

View File

@ -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.

View File

@ -40,9 +40,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* An immutable implementation of {@link ContextSet}.
*
* <p>On construction, all keys/values are {@link String#intern()}ed, in order to increase
* comparison speed.</p>
*
* @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<String, String> map;
private final int hashCode;
ImmutableContextSet(ImmutableSetMultimap<String, String> 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<String, String> 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

View File

@ -45,9 +45,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* A mutable implementation of {@link ContextSet}.
*
* <p>On construction, all keys/values are {@link String#intern()}ed, in order to increase
* comparison speed.</p>
*
* @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<String, String> 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 + ")";

View File

@ -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<Object> {
// Get a list of all groups in a ladder
List<String> ladder = manager.getRankLadder(rankLadder).entrySet().stream()
.sorted(Comparator.<Map.Entry<Integer, PermissionGroup>>comparingInt(e -> e.getKey()).reversed())
.map(e -> MigrationUtils.standardizeName(e.getValue().getName()))
.collect(Collectors.toList());
.sorted(Comparator.<Map.Entry<Integer, PermissionGroup>>comparingInt(Map.Entry::getKey).reversed())
.map(e -> MigrationUtils.standardizeName(e.getValue().getName()))
.collect(Collectors.toList());
track.setGroups(ladder);
plugin.getStorage().saveTrack(track);

View File

@ -74,7 +74,8 @@ public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>
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.

View File

@ -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.
*/

View File

@ -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);

View File

@ -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,
'¥'

View File

@ -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,
'¥'

View File

@ -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());
}

View File

@ -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,
'¥'

View File

@ -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,
'¥'

View File

@ -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),
'¥'

View File

@ -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);

View File

@ -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);
}

View File

@ -140,7 +140,7 @@ public class GroupListMembers extends SubCommand<Group> {
for (Map.Entry<String, HeldPermission<T>> 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<Group> {
"&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);

View File

@ -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 -> {

View File

@ -139,7 +139,7 @@ public class SearchCommand extends SingleCommand {
for (Map.Entry<String, HeldPermission<T>> 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);

View File

@ -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 = '&';
}

View File

@ -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<String> PERMISSION_TEST = s -> {
if (s.length() <= 0 || s.length() > MAX_PERMISSION_LENGTH) {
return false;
}
public static final Predicate<String> PERMISSION_TEST = s -> s.length() > 0 && s.length() <= MAX_PERMISSION_LENGTH;
return true;
};
public static final Predicate<String> 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<String> PLAYER_USERNAME_TEST = s -> {
if (s.length() <= 0 || s.length() > MAX_PLAYER_USERNAME_LENGTH) {
return false;
}
public static final Predicate<String> 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<String> GROUP_NAME_TEST = s -> s.length() > 0 && s.length() <= MAX_GROUP_NAME_LENGTH && !s.contains(" ");
return true;
};
public static final Predicate<String> GROUP_NAME_TEST_ALLOW_SPACE = s -> s.length() > 0 && s.length() <= MAX_GROUP_NAME_LENGTH;
public static final Predicate<String> PLAYER_USERNAME_TEST_LENIENT = s -> {
if (s.length() <= 0 || s.length() > MAX_PLAYER_USERNAME_LENGTH) {
return false;
}
public static final Predicate<String> TRACK_NAME_TEST = s -> s.length() > 0 && s.length() <= MAX_TRACK_NAME_LENGTH && !s.contains(" ");
return true;
};
public static final Predicate<String> 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<String> GROUP_NAME_TEST_ALLOW_SPACE = s -> {
if (s.length() <= 0 || s.length() > MAX_GROUP_NAME_LENGTH) {
return false;
}
return true;
};
public static final Predicate<String> 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<String> TRACK_NAME_TEST_ALLOW_SPACE = s -> {
if (s.length() <= 0 || s.length() > MAX_TRACK_NAME_LENGTH) {
return false;
}
return true;
};
public static final Predicate<String> TRACK_NAME_TEST_ALLOW_SPACE = s -> s.length() > 0 && s.length() <= MAX_TRACK_NAME_LENGTH;
public static final Predicate<Long> TIME_TEST = unixTime -> !DateUtil.shouldExpire(unixTime);
public static final Predicate<String> SERVER_NAME_TEST = s -> {
if (s.length() <= 0 || s.length() > MAX_SERVER_LENGTH) {
return false;
}
public static final Predicate<String> 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<String> 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<String> WORLD_NAME_TEST = s -> s.length() > 0 && s.length() <= MAX_WORLD_LENGTH && !s.contains(" ");
}

View File

@ -57,7 +57,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
protected final LuckPermsPlugin plugin;
private final Class<T> subjectClass;
private final List<ContextCalculator<T>> calculators = new CopyOnWriteArrayList<>();
private final List<ContextCalculator<? super T>> calculators = new CopyOnWriteArrayList<>();
private final List<StaticContextCalculator> staticCalculators = new CopyOnWriteArrayList<>();
// caches context lookups
@ -140,16 +140,14 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
}
@Override
public void registerCalculator(ContextCalculator<T> calculator) {
public void registerCalculator(ContextCalculator<? super T> 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<T>) calculator);
registerCalculator(calculator);
staticCalculators.add(0, calculator);
}
@ -168,7 +166,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
public Contexts load(T subject) {
MutableContextSet accumulator = MutableContextSet.create();
for (ContextCalculator<T> calculator : calculators) {
for (ContextCalculator<? super T> calculator : calculators) {
try {
MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator);
//noinspection ConstantConditions

View File

@ -108,7 +108,7 @@ public interface ContextManager<T> {
*
* @param calculator the calculator
*/
void registerCalculator(ContextCalculator<T> calculator);
void registerCalculator(ContextCalculator<? super T> calculator);
/**
* Registers a static context calculator with the manager.

View File

@ -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() + ", " +

View File

@ -95,5 +95,4 @@ public class NodeWithContextComparator implements Comparator<LocalizedNode> {
return CollationKeyCache.compareStrings(o1.getPermission(), o2.getPermission()) == 1 ? -1 : 1;
}
}

View File

@ -47,10 +47,6 @@ public class ShorthandParser {
.build();
public static Set<String> parseShorthand(String s) {
return parseShorthand(s, true);
}
public static Set<String> parseShorthand(String s, boolean removeSelf) {
Set<String> 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;
}

View File

@ -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);
}

View File

@ -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 {