From 0f4c0573952e0a380685e3da4950afcf9fe9771e Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 15 Oct 2017 15:13:23 +0100 Subject: [PATCH] Add highest_inherited and lowest_inherited meta stack elements --- bukkit/src/main/resources/config.yml | 2 + bungee/src/main/resources/config.yml | 2 + .../metastacking/StandardStackElements.java | 48 +++++++++++++++++-- sponge/src/main/resources/luckperms.conf | 2 + 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index 5f60c2d88..522eae378 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -176,6 +176,8 @@ group-weight: # - lowest # - highest_own # - lowest_own +# - highest_inherited +# - lowest_inherited # - highest_on_track_ # - lowest_on_track_ # - highest_not_on_track_ diff --git a/bungee/src/main/resources/config.yml b/bungee/src/main/resources/config.yml index 60f56543d..432c2d7b7 100644 --- a/bungee/src/main/resources/config.yml +++ b/bungee/src/main/resources/config.yml @@ -165,6 +165,8 @@ group-weight: # - lowest # - highest_own # - lowest_own +# - highest_inherited +# - lowest_inherited # - highest_on_track_ # - lowest_on_track_ # - highest_not_on_track_ diff --git a/common/src/main/java/me/lucko/luckperms/common/metastacking/StandardStackElements.java b/common/src/main/java/me/lucko/luckperms/common/metastacking/StandardStackElements.java index e090f9d71..7b2853710 100644 --- a/common/src/main/java/me/lucko/luckperms/common/metastacking/StandardStackElements.java +++ b/common/src/main/java/me/lucko/luckperms/common/metastacking/StandardStackElements.java @@ -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 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 current) { + if (type.shouldIgnore(node)) { + return false; + } + + if (!checkOwnElement(node)) { + return false; + } + + Map.Entry 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 current) { + if (type.shouldIgnore(node)) { + return false; + } + + if (!checkOwnElement(node)) { + return false; + } + + Map.Entry newEntry = type.getEntry(node); + return !compareEntriesLowest(current, newEntry); + } + } + @ToString(of = "trackName") @RequiredArgsConstructor @EqualsAndHashCode(of = "trackName") diff --git a/sponge/src/main/resources/luckperms.conf b/sponge/src/main/resources/luckperms.conf index ec8cd8c51..5a23e3898 100644 --- a/sponge/src/main/resources/luckperms.conf +++ b/sponge/src/main/resources/luckperms.conf @@ -175,6 +175,8 @@ group-weight { # - lowest # - highest_own # - lowest_own +# - highest_inherited +# - lowest_inherited # - highest_on_track_ # - lowest_on_track_ # - highest_not_on_track_