From ebb24aefa1d7c825c180b46895c7988a2e53a7f8 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 25 Mar 2017 20:06:30 +0000 Subject: [PATCH] Fix parent set command also adding default --- .../api/delegates/PermissionHolderDelegate.java | 6 +++--- .../commands/impl/generic/parent/ParentClear.java | 6 +++--- .../commands/impl/generic/parent/ParentSet.java | 9 ++++----- .../common/core/model/PermissionHolder.java | 12 ++++++------ 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/PermissionHolderDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/PermissionHolderDelegate.java index 7493ddab..2e713740 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/PermissionHolderDelegate.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/PermissionHolderDelegate.java @@ -261,17 +261,17 @@ public class PermissionHolderDelegate implements PermissionHolder { @Override public void clearParents() { - master.clearParents(); + master.clearParents(true); } @Override public void clearParents(String server) { - master.clearParents(server); + master.clearParents(server, true); } @Override public void clearParents(String server, String world) { - master.clearParents(server, world); + master.clearParents(server, world, true); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClear.java index 6869da59..951696d0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClear.java @@ -58,13 +58,13 @@ public class ParentClear extends SharedSubCommand { switch (ContextHelper.determine(server, world)) { case NONE: - holder.clearParents(); + holder.clearParents(true); break; case SERVER: - holder.clearParents(server); + holder.clearParents(server, true); break; case SERVER_AND_WORLD: - holder.clearParents(server, world); + holder.clearParents(server, world, true); break; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java index 79d6abc7..dee26cf2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentSet.java @@ -75,7 +75,7 @@ public class ParentSet extends SharedSubCommand { switch (ContextHelper.determine(server, world)) { case NONE: - holder.clearParents(null, null); + holder.clearParents(null, null, false); try { holder.setInheritGroup(group); @@ -88,12 +88,11 @@ public class ParentSet extends SharedSubCommand { Message.SET_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName()); break; case SERVER: - holder.clearParents(server, null); + holder.clearParents(server, null, false); try { holder.setInheritGroup(group, server); - } catch (ObjectAlreadyHasException ignored) { - } + } catch (ObjectAlreadyHasException ignored) {} if (server.equalsIgnoreCase("global") && holder instanceof User) { ((User) holder).getPrimaryGroup().setStoredValue(group.getName()); @@ -102,7 +101,7 @@ public class ParentSet extends SharedSubCommand { Message.SET_PARENT_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server); break; case SERVER_AND_WORLD: - holder.clearParents(server, world); + holder.clearParents(server, world, false); try { holder.setInheritGroup(group, server, world); diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java index d2e8c0e8..d7159981 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java @@ -1130,7 +1130,7 @@ public abstract class PermissionHolder { plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after); } - public void clearParents() { + public void clearParents(boolean giveDefault) { ImmutableSet before = ImmutableSet.copyOf(getNodes().values()); synchronized (nodes) { @@ -1139,7 +1139,7 @@ public abstract class PermissionHolder { return; } } - if (this instanceof User) { + if (this instanceof User && giveDefault) { plugin.getUserManager().giveDefaultIfNeeded((User) this, false); } invalidateCache(); @@ -1147,7 +1147,7 @@ public abstract class PermissionHolder { plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after); } - public void clearParents(String server) { + public void clearParents(String server, boolean giveDefault) { String finalServer = Optional.ofNullable(server).orElse("global"); ImmutableSet before = ImmutableSet.copyOf(getNodes().values()); @@ -1159,7 +1159,7 @@ public abstract class PermissionHolder { return; } } - if (this instanceof User) { + if (this instanceof User && giveDefault) { plugin.getUserManager().giveDefaultIfNeeded((User) this, false); } invalidateCache(); @@ -1167,7 +1167,7 @@ public abstract class PermissionHolder { plugin.getApiProvider().getEventFactory().handleNodeClear(this, before, after); } - public void clearParents(String server, String world) { + public void clearParents(String server, String world, boolean giveDefault) { String finalServer = Optional.ofNullable(server).orElse("global"); String finalWorld = Optional.ofNullable(world).orElse("null"); @@ -1182,7 +1182,7 @@ public abstract class PermissionHolder { return; } } - if (this instanceof User) { + if (this instanceof User && giveDefault) { plugin.getUserManager().giveDefaultIfNeeded((User) this, false); } invalidateCache();