Add highest_inherited and lowest_inherited meta stack elements

This commit is contained in:
Luck 2017-10-15 15:13:23 +01:00
parent 2fd74f3b7e
commit 0f4c057395
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 50 additions and 4 deletions

View File

@ -176,6 +176,8 @@ group-weight:
# - lowest
# - highest_own
# - lowest_own
# - highest_inherited
# - lowest_inherited
# - highest_on_track_<track>
# - lowest_on_track_<track>
# - highest_not_on_track_<track>

View File

@ -165,6 +165,8 @@ group-weight:
# - lowest
# - highest_own
# - lowest_own
# - highest_inherited
# - lowest_inherited
# - highest_on_track_<track>
# - lowest_on_track_<track>
# - highest_not_on_track_<track>

View File

@ -51,6 +51,8 @@ public class StandardStackElements {
private static final LowestPriority LOWEST_PRIORITY = new LowestPriority();
private static final HighestPriorityOwn HIGHEST_PRIORITY_OWN = new HighestPriorityOwn();
private static final LowestPriorityOwn LOWEST_PRIORITY_OWN = new LowestPriorityOwn();
private static final HighestPriorityInherited HIGHEST_PRIORITY_INHERITED = new HighestPriorityInherited();
private static final LowestPriorityInherited LOWEST_PRIORITY_INHERITED = new LowestPriorityInherited();
public static Optional<MetaStackElement> parseFromString(LuckPermsPlugin plugin, String s) {
s = s.toLowerCase();
@ -71,6 +73,14 @@ public class StandardStackElements {
return Optional.of(LOWEST_PRIORITY_OWN);
}
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));
@ -129,10 +139,6 @@ public class StandardStackElements {
* @return true if the accumulation should return
*/
private static boolean checkOwnElement(LocalizedNode node) {
if (node.getLocation() == null || node.getLocation().equals("")) {
return true;
}
try {
UUID.fromString(node.getLocation());
return false;
@ -202,6 +208,23 @@ public class StandardStackElements {
}
}
@ToString
private static final class HighestPriorityInherited implements MetaStackElement {
@Override
public boolean shouldAccumulate(LocalizedNode node, 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);
}
}
@ToString(of = "trackName")
@RequiredArgsConstructor
@EqualsAndHashCode(of = "trackName")
@ -268,6 +291,23 @@ public class StandardStackElements {
}
}
@ToString
private static final class LowestPriorityInherited implements MetaStackElement {
@Override
public boolean shouldAccumulate(LocalizedNode node, 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);
}
}
@ToString(of = "trackName")
@RequiredArgsConstructor
@EqualsAndHashCode(of = "trackName")

View File

@ -175,6 +175,8 @@ group-weight {
# - lowest
# - highest_own
# - lowest_own
# - highest_inherited
# - lowest_inherited
# - highest_on_track_<track>
# - lowest_on_track_<track>
# - highest_not_on_track_<track>