Refactor meta stack element creation, add 'from_group' & 'not_from_group' elements

This commit is contained in:
Luck 2018-05-16 18:46:25 +01:00
parent 18f09f9862
commit 20f992110d
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 290 additions and 305 deletions

View File

@ -51,7 +51,7 @@ public class ApiMetaStackFactory implements MetaStackFactory {
@Override @Override
public Optional<MetaStackElement> fromString(@Nonnull String definition) { public Optional<MetaStackElement> fromString(@Nonnull String definition) {
Objects.requireNonNull(definition, "definition"); Objects.requireNonNull(definition, "definition");
return StandardStackElements.parseFromString(this.plugin, definition); return Optional.ofNullable(StandardStackElements.parseFromString(this.plugin, definition));
} }
@Nonnull @Nonnull

View File

@ -0,0 +1,112 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.metastacking;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.api.ChatMetaType;
import me.lucko.luckperms.api.LocalizedNode;
import me.lucko.luckperms.api.metastacking.MetaStackElement;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class FluentMetaStackElement implements MetaStackElement {
public static Builder builder(String name) {
return new Builder(name);
}
private final List<MetaStackElement> subElements;
private final String toString;
private FluentMetaStackElement(String name, Map<String, String> params, List<MetaStackElement> subElements) {
this.subElements = ImmutableList.copyOf(subElements);
this.toString = formToString(name, params);
}
@Override
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, @Nullable Map.Entry<Integer, String> current) {
for (MetaStackElement element : this.subElements) {
if (!element.shouldAccumulate(node, type, current)) {
return false;
}
}
return true;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FluentMetaStackElement that = (FluentMetaStackElement) o;
return this.subElements.equals(that.subElements);
}
@Override
public int hashCode() {
return this.subElements.hashCode();
}
@Override
public String toString() {
return this.toString;
}
private static String formToString(String name, Map<String, String> params) {
return name + "(" + params.entrySet().stream().map(p -> p.getKey() + "=" + p.getValue()).collect(Collectors.joining(", ")) + ")";
}
public static final class Builder {
private final String name;
private final ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
private final ImmutableList.Builder<MetaStackElement> elements = ImmutableList.builder();
Builder(String name) {
this.name = name;
}
public Builder with(MetaStackElement check) {
this.elements.add(check);
return this;
}
public Builder param(String name, String value) {
this.params.put(name, value);
return this;
}
public MetaStackElement build() {
return new FluentMetaStackElement(this.name, this.params.build(), this.elements.build());
}
}
}

View File

@ -31,416 +31,289 @@ import me.lucko.luckperms.api.metastacking.MetaStackElement;
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;
import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.common.utils.Uuids;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Objects;
import java.util.UUID;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/** /**
* Contains the standard {@link MetaStackElement}s provided by LuckPerms. * Contains the standard {@link MetaStackElement}s provided by LuckPerms.
*/ */
public final class StandardStackElements { public final class StandardStackElements {
public static final HighestPriority HIGHEST_PRIORITY = new HighestPriority();
public static final LowestPriority LOWEST_PRIORITY = new LowestPriority();
public static final HighestPriorityOwn HIGHEST_PRIORITY_OWN = new HighestPriorityOwn();
public static final LowestPriorityOwn LOWEST_PRIORITY_OWN = new LowestPriorityOwn();
public static final HighestPriorityInherited HIGHEST_PRIORITY_INHERITED = new HighestPriorityInherited();
public static final LowestPriorityInherited LOWEST_PRIORITY_INHERITED = new LowestPriorityInherited();
public static Optional<MetaStackElement> parseFromString(LuckPermsPlugin plugin, String s) { public static MetaStackElement parseFromString(LuckPermsPlugin plugin, String s) {
s = s.toLowerCase(); s = s.toLowerCase();
if (s.equals("highest")) { // static
return Optional.of(HIGHEST_PRIORITY); if (s.equals("highest")) return HIGHEST;
} if (s.equals("lowest")) return LOWEST;
if (s.equals("highest_own")) return HIGHEST_OWN;
if (s.equals("lowest_own")) return LOWEST_OWN;
if (s.equals("highest_inherited")) return HIGHEST_INHERITED;
if (s.equals("lowest_inherited")) return LOWEST_INHERITED;
if (s.equals("lowest")) { // dynamic
return Optional.of(LOWEST_PRIORITY); String p;
} if ((p = parseParam(s, "highest_on_track_")) != null) return highestFromGroupOnTrack(plugin, p);
if ((p = parseParam(s, "lowest_on_track_")) != null) return lowestFromGroupOnTrack(plugin, p);
if ((p = parseParam(s, "highest_not_on_track_")) != null) return highestNotFromGroupOnTrack(plugin, p);
if ((p = parseParam(s, "lowest_not_on_track_")) != null) return lowestNotFromGroupOnTrack(plugin, p);
if ((p = parseParam(s, "highest_from_group_")) != null) return highestFromGroup(p);
if ((p = parseParam(s, "lowest_from_group_")) != null) return lowestFromGroup(p);
if ((p = parseParam(s, "highest_not_from_group_")) != null) return highestNotFromGroup(p);
if ((p = parseParam(s, "lowest_not_from_group_")) != null) return lowestNotFromGroup(p);
if (s.equals("highest_own")) { return null;
return Optional.of(HIGHEST_PRIORITY_OWN); }
}
if (s.equals("lowest_own")) { private static String parseParam(String s, String prefix) {
return Optional.of(LOWEST_PRIORITY_OWN); if (s.startsWith(prefix) && s.length() > prefix.length()) {
return s.substring(prefix.length());
} }
return null;
if (s.equals("highest_inherited")) {
return Optional.of(HIGHEST_PRIORITY_INHERITED);
}
if (s.equals("lowest_inherited")) {
return Optional.of(LOWEST_PRIORITY_INHERITED);
}
if (s.startsWith("highest_on_track_") && s.length() > "highest_on_track_".length()) {
String track = s.substring("highest_on_track_".length());
return Optional.of(new HighestPriorityTrack(plugin, track));
}
if (s.startsWith("lowest_on_track_") && s.length() > "lowest_on_track_".length()) {
String track = s.substring("lowest_on_track_".length());
return Optional.of(new LowestPriorityTrack(plugin, track));
}
if (s.startsWith("highest_not_on_track_") && s.length() > "highest_not_on_track_".length()) {
String track = s.substring("highest_not_on_track_".length());
return Optional.of(new HighestPriorityNotOnTrack(plugin, track));
}
if (s.startsWith("lowest_not_on_track_") && s.length() > "lowest_not_on_track_".length()) {
String track = s.substring("lowest_not_on_track_".length());
return Optional.of(new LowestPriorityNotOnTrack(plugin, track));
}
new IllegalArgumentException("Cannot parse MetaStackElement: " + s).printStackTrace();
return Optional.empty();
} }
public static List<MetaStackElement> parseList(LuckPermsPlugin plugin, List<String> strings) { public static List<MetaStackElement> parseList(LuckPermsPlugin plugin, List<String> strings) {
return strings.stream() return strings.stream()
.map(s -> parseFromString(plugin, s)) .map(s -> {
.filter(Optional::isPresent) MetaStackElement parsed = parseFromString(plugin, s);
.map(Optional::get) if (parsed == null) {
new IllegalArgumentException("Unable to parse from: " + s).printStackTrace();
}
return parsed;
})
.filter(Objects::nonNull)
.collect(ImmutableCollectors.toList()); .collect(ImmutableCollectors.toList());
} }
/** // utility functions, used in combination with FluentMetaStackElement for form full MetaStackElements
* Returns true if the current node has the greater priority
* @param current the current entry private static final MetaStackElement TYPE_CHECK = (node, type, current) -> type.matches(node);
* @param newEntry the new entry private static final MetaStackElement HIGHEST_CHECK = (node, type, current) -> current == null || type.getEntry(node).getKey() > current.getKey();
* @return true if the accumulation should return private static final MetaStackElement LOWEST_CHECK = (node, type, current) -> current == null || type.getEntry(node).getKey() < current.getKey();
*/ private static final MetaStackElement OWN_CHECK = (node, type, current) -> Uuids.fromString(node.getLocation()) != null;
private static boolean compareEntriesHighest(Map.Entry<Integer, String> current, Map.Entry<Integer, String> newEntry) { private static final MetaStackElement INHERITED_CHECK = (node, type, current) -> Uuids.fromString(node.getLocation()) == null;
return current != null && current.getKey() >= newEntry.getKey();
// implementations
private static final MetaStackElement HIGHEST = FluentMetaStackElement.builder("HighestPriority")
.with(TYPE_CHECK)
.with(HIGHEST_CHECK)
.build();
private static final MetaStackElement HIGHEST_OWN = FluentMetaStackElement.builder("HighestPriorityOwn")
.with(TYPE_CHECK)
.with(OWN_CHECK)
.with(HIGHEST_CHECK)
.build();
private static final MetaStackElement HIGHEST_INHERITED = FluentMetaStackElement.builder("HighestPriorityInherited")
.with(TYPE_CHECK)
.with(INHERITED_CHECK)
.with(HIGHEST_CHECK)
.build();
private static MetaStackElement highestFromGroupOnTrack(LuckPermsPlugin plugin, String trackName) {
return FluentMetaStackElement.builder("HighestPriorityOnTrack")
.param("trackName", trackName)
.with(TYPE_CHECK)
.with(HIGHEST_CHECK)
.with(new FromGroupOnTrackCheck(plugin, trackName))
.build();
} }
/** private static MetaStackElement highestNotFromGroupOnTrack(LuckPermsPlugin plugin, String trackName) {
* Returns true if the current node has the lesser priority return FluentMetaStackElement.builder("HighestPriorityNotOnTrack")
* @param current the current entry .param("trackName", trackName)
* @param newEntry the new entry .with(TYPE_CHECK)
* @return true if the accumulation should return .with(HIGHEST_CHECK)
*/ .with(new NotFromGroupOnTrackCheck(plugin, trackName))
private static boolean compareEntriesLowest(Map.Entry<Integer, String> current, Map.Entry<Integer, String> newEntry) { .build();
return current != null && current.getKey() <= newEntry.getKey(); }
private static MetaStackElement highestFromGroup(String groupName) {
return FluentMetaStackElement.builder("HighestPriorityFromGroup")
.param("groupName", groupName)
.with(TYPE_CHECK)
.with(HIGHEST_CHECK)
.with(new FromGroupCheck(groupName))
.build();
} }
/** private static MetaStackElement highestNotFromGroup(String groupName) {
* Returns true if the node is not held by a user return FluentMetaStackElement.builder("HighestPriorityNotFromGroup")
* @param node the node to check .param("groupName", groupName)
* @return true if the accumulation should return .with(TYPE_CHECK)
*/ .with(HIGHEST_CHECK)
private static boolean checkOwnElement(LocalizedNode node) { .with(new NotFromGroupCheck(groupName))
try { .build();
UUID.fromString(node.getLocation());
return false;
} catch (IllegalArgumentException e) {
return true;
}
} }
/** private static final MetaStackElement LOWEST = FluentMetaStackElement.builder("LowestPriority")
* Returns true if the node is not held by a group on the track .with(TYPE_CHECK)
* @param node the node to check .with(LOWEST_CHECK)
* @param track the track .build();
* @return true if the accumulation should return
*/
private static boolean checkTrackElement(LuckPermsPlugin plugin, LocalizedNode node, String track) {
if (node.getLocation() == null || node.getLocation().equals("")) {
return true;
}
Track t = plugin.getTrackManager().getIfLoaded(track); private static final MetaStackElement LOWEST_OWN = FluentMetaStackElement.builder("LowestPriorityOwn")
return t == null || !t.containsGroup(node.getLocation()); .with(TYPE_CHECK)
.with(OWN_CHECK)
.with(LOWEST_CHECK)
.build();
private static final MetaStackElement LOWEST_INHERITED = FluentMetaStackElement.builder("LowestPriorityInherited")
.with(TYPE_CHECK)
.with(INHERITED_CHECK)
.with(LOWEST_CHECK)
.build();
private static MetaStackElement lowestFromGroupOnTrack(LuckPermsPlugin plugin, String trackName) {
return FluentMetaStackElement.builder("LowestPriorityOnTrack")
.param("trackName", trackName)
.with(TYPE_CHECK)
.with(LOWEST_CHECK)
.with(new FromGroupOnTrackCheck(plugin, trackName))
.build();
} }
/** private static MetaStackElement lowestNotFromGroupOnTrack(LuckPermsPlugin plugin, String trackName) {
* Returns true if the node is held by a group on the track return FluentMetaStackElement.builder("LowestPriorityNotOnTrack")
* @param node the node to check .param("trackName", trackName)
* @param track the track .with(TYPE_CHECK)
* @return true if the accumulation should return .with(LOWEST_CHECK)
*/ .with(new NotFromGroupOnTrackCheck(plugin, trackName))
private static boolean checkNotTrackElement(LuckPermsPlugin plugin, LocalizedNode node, String track) { .build();
// it's not come from a group on this track (from the user directly)
if (node.getLocation() == null || node.getLocation().equals("")) {
return false;
}
Track t = plugin.getTrackManager().getIfLoaded(track);
return t == null || t.containsGroup(node.getLocation());
} }
private static final class HighestPriority implements MetaStackElement { private static MetaStackElement lowestFromGroup(String groupName) {
@Override return FluentMetaStackElement.builder("LowestPriorityFromGroup")
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) { .param("groupName", groupName)
if (type.shouldIgnore(node)) { .with(TYPE_CHECK)
return false; .with(LOWEST_CHECK)
} .with(new FromGroupCheck(groupName))
.build();
Map.Entry<Integer, String> newEntry = type.getEntry(node);
return !compareEntriesHighest(current, newEntry);
}
@Override
public String toString() {
return "StandardStackElements.HighestPriority()";
}
} }
private static final class HighestPriorityOwn implements MetaStackElement { private static MetaStackElement lowestNotFromGroup(String groupName) {
@Override return FluentMetaStackElement.builder("LowestPriorityNotFromGroup")
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) { .param("groupName", groupName)
if (type.shouldIgnore(node)) { .with(TYPE_CHECK)
return false; .with(LOWEST_CHECK)
} .with(new NotFromGroupCheck(groupName))
.build();
if (checkOwnElement(node)) {
return false;
}
Map.Entry<Integer, String> newEntry = type.getEntry(node);
return !compareEntriesHighest(current, newEntry);
}
@Override
public String toString() {
return "StandardStackElements.HighestPriorityOwn()";
}
} }
private static final class HighestPriorityInherited implements MetaStackElement { private static final class FromGroupOnTrackCheck implements MetaStackElement {
@Override
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) {
if (type.shouldIgnore(node)) {
return false;
}
if (!checkOwnElement(node)) {
return false;
}
Map.Entry<Integer, String> newEntry = type.getEntry(node);
return !compareEntriesHighest(current, newEntry);
}
@Override
public String toString() {
return "StandardStackElements.HighestPriorityInherited()";
}
}
private static final class HighestPriorityTrack implements MetaStackElement {
private final LuckPermsPlugin plugin; private final LuckPermsPlugin plugin;
private final String trackName; private final String trackName;
public HighestPriorityTrack(LuckPermsPlugin plugin, String trackName) { FromGroupOnTrackCheck(LuckPermsPlugin plugin, String trackName) {
this.plugin = plugin; this.plugin = plugin;
this.trackName = trackName; this.trackName = trackName;
} }
@Override @Override
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) { public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, @Nullable Map.Entry<Integer, String> current) {
if (type.shouldIgnore(node)) { Track t = this.plugin.getTrackManager().getIfLoaded(this.trackName);
return false; return t != null && t.containsGroup(node.getLocation());
}
Map.Entry<Integer, String> newEntry = type.getEntry(node);
return !compareEntriesHighest(current, newEntry) && !checkTrackElement(this.plugin, node, this.trackName);
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == this) return true; if (this == o) return true;
if (!(o instanceof HighestPriorityTrack)) return false; if (o == null || getClass() != o.getClass()) return false;
final HighestPriorityTrack other = (HighestPriorityTrack) o; FromGroupOnTrackCheck that = (FromGroupOnTrackCheck) o;
return this.trackName.equals(other.trackName); return this.trackName.equals(that.trackName);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return this.trackName.hashCode(); return this.trackName.hashCode();
} }
@Override
public String toString() {
return "StandardStackElements.HighestPriorityTrack(trackName=" + this.trackName + ")";
}
} }
private static final class HighestPriorityNotOnTrack implements MetaStackElement { private static final class NotFromGroupOnTrackCheck implements MetaStackElement {
private final LuckPermsPlugin plugin; private final LuckPermsPlugin plugin;
private final String trackName; private final String trackName;
public HighestPriorityNotOnTrack(LuckPermsPlugin plugin, String trackName) { NotFromGroupOnTrackCheck(LuckPermsPlugin plugin, String trackName) {
this.plugin = plugin; this.plugin = plugin;
this.trackName = trackName; this.trackName = trackName;
} }
@Override @Override
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) { public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, @Nullable Map.Entry<Integer, String> current) {
if (type.shouldIgnore(node)) { Track t = this.plugin.getTrackManager().getIfLoaded(this.trackName);
return false; return t != null && !t.containsGroup(node.getLocation());
}
Map.Entry<Integer, String> newEntry = type.getEntry(node);
return !compareEntriesHighest(current, newEntry) && !checkNotTrackElement(this.plugin, node, this.trackName);
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == this) return true; if (this == o) return true;
if (!(o instanceof HighestPriorityNotOnTrack)) return false; if (o == null || getClass() != o.getClass()) return false;
final HighestPriorityNotOnTrack other = (HighestPriorityNotOnTrack) o; NotFromGroupOnTrackCheck that = (NotFromGroupOnTrackCheck) o;
return this.trackName.equals(other.trackName); return this.trackName.equals(that.trackName);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return this.trackName.hashCode(); return this.trackName.hashCode();
} }
@Override
public String toString() {
return "StandardStackElements.HighestPriorityNotOnTrack(trackName=" + this.trackName + ")";
}
} }
private static final class LowestPriority implements MetaStackElement { private static final class FromGroupCheck implements MetaStackElement {
@Override private final String groupName;
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) {
if (type.shouldIgnore(node)) {
return false;
}
Map.Entry<Integer, String> newEntry = type.getEntry(node); FromGroupCheck(String groupName) {
return !compareEntriesLowest(current, newEntry); this.groupName = groupName;
} }
@Override @Override
public String toString() { public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, @Nullable Map.Entry<Integer, String> current) {
return "StandardStackElements.LowestPriority()"; return this.groupName.equals(node.getLocation());
}
}
private static final class LowestPriorityOwn implements MetaStackElement {
@Override
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) {
if (type.shouldIgnore(node)) {
return false;
}
if (checkOwnElement(node)) {
return false;
}
Map.Entry<Integer, String> newEntry = type.getEntry(node);
return !compareEntriesLowest(current, newEntry);
}
@Override
public String toString() {
return "StandardStackElements.LowestPriorityOwn()";
}
}
private static final class LowestPriorityInherited implements MetaStackElement {
@Override
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) {
if (type.shouldIgnore(node)) {
return false;
}
if (!checkOwnElement(node)) {
return false;
}
Map.Entry<Integer, String> newEntry = type.getEntry(node);
return !compareEntriesLowest(current, newEntry);
}
@Override
public String toString() {
return "StandardStackElements.LowestPriorityInherited()";
}
}
private static final class LowestPriorityTrack implements MetaStackElement {
private final LuckPermsPlugin plugin;
private final String trackName;
public LowestPriorityTrack(LuckPermsPlugin plugin, String trackName) {
this.plugin = plugin;
this.trackName = trackName;
}
@Override
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) {
if (type.shouldIgnore(node)) {
return false;
}
Map.Entry<Integer, String> entry = type.getEntry(node);
return !compareEntriesLowest(current, entry) && !checkTrackElement(this.plugin, node, this.trackName);
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == this) return true; if (this == o) return true;
if (!(o instanceof LowestPriorityTrack)) return false; if (o == null || getClass() != o.getClass()) return false;
final LowestPriorityTrack other = (LowestPriorityTrack) o; FromGroupCheck that = (FromGroupCheck) o;
return this.trackName.equals(other.trackName); return this.groupName.equals(that.groupName);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return this.trackName.hashCode(); return this.groupName.hashCode();
}
@Override
public String toString() {
return "StandardStackElements.LowestPriorityTrack(trackName=" + this.trackName + ")";
} }
} }
private static final class LowestPriorityNotOnTrack implements MetaStackElement { private static final class NotFromGroupCheck implements MetaStackElement {
private final LuckPermsPlugin plugin; private final String groupName;
private final String trackName;
public LowestPriorityNotOnTrack(LuckPermsPlugin plugin, String trackName) { NotFromGroupCheck(String groupName) {
this.plugin = plugin; this.groupName = groupName;
this.trackName = trackName;
} }
@Override @Override
public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, Map.Entry<Integer, String> current) { public boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, @Nullable Map.Entry<Integer, String> current) {
if (type.shouldIgnore(node)) { return !this.groupName.equals(node.getLocation());
return false;
}
Map.Entry<Integer, String> newEntry = type.getEntry(node);
return !compareEntriesLowest(current, newEntry) && !checkNotTrackElement(this.plugin, node, this.trackName);
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o == this) return true; if (this == o) return true;
if (!(o instanceof LowestPriorityNotOnTrack)) return false; if (o == null || getClass() != o.getClass()) return false;
final LowestPriorityNotOnTrack other = (LowestPriorityNotOnTrack) o; NotFromGroupCheck that = (NotFromGroupCheck) o;
return this.trackName.equals(other.trackName); return this.groupName.equals(that.groupName);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return this.trackName.hashCode(); return this.groupName.hashCode();
}
@Override
public String toString() {
return "StandardStackElements.LowestPriorityNotOnTrack(trackName=" + this.trackName + ")";
} }
} }