From 1ac3ad932e3ea4b202ab90c92e0722907441aad2 Mon Sep 17 00:00:00 2001 From: bloodshot Date: Tue, 31 Dec 2019 23:49:45 -0500 Subject: [PATCH] Fix getOptionValue without server context. * Disable weather change message. --- .../listener/CommonEntityEventHandler.java | 15 +++------------ .../griefdefender/provider/LuckPermsProvider.java | 14 +++++++++----- .../listener/CommonEntityEventHandler.java | 9 +++++---- .../griefdefender/provider/LuckPermsProvider.java | 14 +++++++++----- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bukkit/src/main/java/com/griefdefender/listener/CommonEntityEventHandler.java b/bukkit/src/main/java/com/griefdefender/listener/CommonEntityEventHandler.java index 4a561f6..cb21ca5 100644 --- a/bukkit/src/main/java/com/griefdefender/listener/CommonEntityEventHandler.java +++ b/bukkit/src/main/java/com/griefdefender/listener/CommonEntityEventHandler.java @@ -505,22 +505,13 @@ public void checkPlayerWeather(GDPermissionUser user, GDClaim fromClaim, GDClaim final org.bukkit.WeatherType currentWeather = player.getPlayerWeather(); player.setPlayerWeather(PlayerUtil.WEATHERTYPE_MAP.get(weatherType)); final org.bukkit.WeatherType newWeather = player.getPlayerWeather(); - if (currentWeather != newWeather) { + // TODO - improve so it doesn't spam + /*if (currentWeather != newWeather) { final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.OPTION_APPLY_PLAYER_WEATHER, ImmutableMap.of( "weather", weatherType.getName())); GriefDefenderPlugin.sendMessage(player, message); - } - } else { - final org.bukkit.WeatherType currentWeather = player.getPlayerWeather(); - player.resetPlayerWeather(); - final org.bukkit.WeatherType newWeather = player.getPlayerWeather(); - if (currentWeather != newWeather) { - final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.OPTION_APPLY_PLAYER_WEATHER, - ImmutableMap.of( - "weather", weatherType.getName())); - GriefDefenderPlugin.sendMessage(player, message); - } + }*/ } } diff --git a/bukkit/src/main/java/com/griefdefender/provider/LuckPermsProvider.java b/bukkit/src/main/java/com/griefdefender/provider/LuckPermsProvider.java index 4b29700..165ffcf 100644 --- a/bukkit/src/main/java/com/griefdefender/provider/LuckPermsProvider.java +++ b/bukkit/src/main/java/com/griefdefender/provider/LuckPermsProvider.java @@ -705,6 +705,8 @@ public Tristate getPermissionValue(GDPermissionHolder holder, String permission, // To set options, pass "meta.option". @Override public String getOptionValue(GDPermissionHolder holder, Option option, Set contexts) { + // If no server context exists, add global + this.checkServerContext(contexts); ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { @@ -718,6 +720,8 @@ public String getOptionValue(GDPermissionHolder holder, Option option, Set getOptionValueList(GDPermissionHolder holder, Option option, Set contexts) { + // If no server context exists, add global + this.checkServerContext(contexts); ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { @@ -737,7 +741,7 @@ public PermissionResult setOptionValue(GDPermissionHolder holder, String key, St DataMutateResult result = null; if (check) { // If no server context exists, add global - this.checkServerContext(contexts, value); + this.checkServerContext(contexts); } ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); @@ -776,7 +780,7 @@ public PermissionResult setPermissionValue(GDPermissionHolder holder, String per DataMutateResult result = null; if (check) { // If no server context exists, add global - this.checkServerContext(contexts, value.name()); + this.checkServerContext(contexts); } ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final Node node = this.luckPermsApi.getNodeBuilderRegistry().forPermission().permission(permission).value(value.asBoolean()).context(set).build(); @@ -812,7 +816,7 @@ public PermissionResult setPermissionValue(GDPermissionHolder holder, String per public void setTransientOption(GDPermissionHolder holder, String permission, String value, Set contexts) { // If no server context exists, add global - this.checkServerContext(contexts, value); + this.checkServerContext(contexts); MutableContextSet contextSet = this.getLPContexts(contexts); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { @@ -825,7 +829,7 @@ public void setTransientOption(GDPermissionHolder holder, String permission, Str public void setTransientPermission(GDPermissionHolder holder, String permission, Boolean value, Set contexts) { // If no server context exists, add global - this.checkServerContext(contexts, value.toString()); + this.checkServerContext(contexts); MutableContextSet contextSet = this.getLPContexts(contexts); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { @@ -898,7 +902,7 @@ private void clearMeta(PermissionHolder holder, String metaKey, ContextSet set) holder.data().clear(set, NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey))); } - private void checkServerContext(Set contexts, String value) { + private void checkServerContext(Set contexts) { for (Context context : contexts) { if (context.getKey().equalsIgnoreCase("server")) { return; diff --git a/sponge/src/main/java/com/griefdefender/listener/CommonEntityEventHandler.java b/sponge/src/main/java/com/griefdefender/listener/CommonEntityEventHandler.java index 3991eda..c7f1d78 100644 --- a/sponge/src/main/java/com/griefdefender/listener/CommonEntityEventHandler.java +++ b/sponge/src/main/java/com/griefdefender/listener/CommonEntityEventHandler.java @@ -549,20 +549,21 @@ public void checkPlayerWeather(GDPermissionUser user, GDClaim fromClaim, GDClaim if (weatherType != null) { final Weather currentWeather = player.getWorld().getWeather(); PlayerUtil.getInstance().setPlayerWeather(user, weatherType); - final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.OPTION_APPLY_PLAYER_WEATHER, + // TODO - improve so it doesn't spam + /*final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.OPTION_APPLY_PLAYER_WEATHER, ImmutableMap.of( "weather", weatherType == WeatherTypes.UNDEFINED ? currentWeather.getName().toUpperCase() : weatherType.getName().toUpperCase())); - GriefDefenderPlugin.sendMessage(player, message); + GriefDefenderPlugin.sendMessage(player, message);*/ } else { final WeatherType currentWeather = playerData.lastWeatherType; PlayerUtil.getInstance().resetPlayerWeather(user); final WeatherType newWeather = playerData.lastWeatherType; - if (currentWeather != newWeather) { + /*if (currentWeather != newWeather) { final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.OPTION_APPLY_PLAYER_WEATHER, ImmutableMap.of( "weather", newWeather.getName().toUpperCase())); GriefDefenderPlugin.sendMessage(player, message); - } + }*/ } } diff --git a/sponge/src/main/java/com/griefdefender/provider/LuckPermsProvider.java b/sponge/src/main/java/com/griefdefender/provider/LuckPermsProvider.java index 7b5f22a..cb18760 100644 --- a/sponge/src/main/java/com/griefdefender/provider/LuckPermsProvider.java +++ b/sponge/src/main/java/com/griefdefender/provider/LuckPermsProvider.java @@ -701,6 +701,8 @@ public Tristate getPermissionValue(GDPermissionHolder holder, String permission, // To set options, pass "meta.option". @Override public String getOptionValue(GDPermissionHolder holder, Option option, Set contexts) { + // If no server context exists, add global + this.checkServerContext(contexts); ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { @@ -714,6 +716,8 @@ public String getOptionValue(GDPermissionHolder holder, Option option, Set getOptionValueList(GDPermissionHolder holder, Option option, Set contexts) { + // If no server context exists, add global + this.checkServerContext(contexts); ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { @@ -733,7 +737,7 @@ public PermissionResult setOptionValue(GDPermissionHolder holder, String key, St DataMutateResult result = null; if (check) { // If no server context exists, add global - this.checkServerContext(contexts, value); + this.checkServerContext(contexts); } ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); @@ -772,7 +776,7 @@ public PermissionResult setPermissionValue(GDPermissionHolder holder, String per DataMutateResult result = null; if (check) { // If no server context exists, add global - this.checkServerContext(contexts, value.name()); + this.checkServerContext(contexts); } ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final Node node = this.luckPermsApi.getNodeBuilderRegistry().forPermission().permission(permission).value(value.asBoolean()).context(set).build(); @@ -808,7 +812,7 @@ public PermissionResult setPermissionValue(GDPermissionHolder holder, String per public void setTransientOption(GDPermissionHolder holder, String permission, String value, Set contexts) { // If no server context exists, add global - this.checkServerContext(contexts, value); + this.checkServerContext(contexts); MutableContextSet contextSet = this.getLPContexts(contexts); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { @@ -821,7 +825,7 @@ public void setTransientOption(GDPermissionHolder holder, String permission, Str public void setTransientPermission(GDPermissionHolder holder, String permission, Boolean value, Set contexts) { // If no server context exists, add global - this.checkServerContext(contexts, value.toString()); + this.checkServerContext(contexts); MutableContextSet contextSet = this.getLPContexts(contexts); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { @@ -894,7 +898,7 @@ private void clearMeta(PermissionHolder holder, String metaKey, ContextSet set) holder.data().clear(set, NodeType.META.predicate(node -> node.getMetaKey().equals(metaKey))); } - private void checkServerContext(Set contexts, String value) { + private void checkServerContext(Set contexts) { for (Context context : contexts) { if (context.getKey().equalsIgnoreCase("server")) { return;