From b0643bc4175241b6f9932114f342478747db844f Mon Sep 17 00:00:00 2001 From: Thutmose Date: Thu, 7 May 2020 16:03:54 -0400 Subject: [PATCH] Fixes some issues with applying perms this means it no longer requires relogs to update players' commands lists also should address #43 --- .../java/thut/perms/commands/EditGroup.java | 11 ++++++++++ .../java/thut/perms/commands/EditPlayer.java | 4 ++++ src/main/java/thut/perms/commands/Reload.java | 8 +++++++- .../java/thut/perms/management/Group.java | 16 ++++++++++++--- .../perms/management/PermissionsHolder.java | 20 +++++++++++++------ .../java/thut/perms/management/Player.java | 16 +++++++++++---- .../assets/thutperms/lang/en_us.json | 4 ++-- .../assets/thutperms/lang/zh_cn.json | 2 +- 8 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/main/java/thut/perms/commands/EditGroup.java b/src/main/java/thut/perms/commands/EditGroup.java index 381288f..f1c8d93 100644 --- a/src/main/java/thut/perms/commands/EditGroup.java +++ b/src/main/java/thut/perms/commands/EditGroup.java @@ -15,6 +15,7 @@ import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; import net.minecraft.command.arguments.GameProfileArgument; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraftforge.server.permission.DefaultPermissionLevel; import net.minecraftforge.server.permission.PermissionAPI; import thut.perms.Perms; @@ -129,6 +130,9 @@ private static int executeAddGroup(final CommandSource source, final String grou { Perms.savePerms(); Perms.config.sendFeedback(source, "thutperms.group.added", true, name, groupName); + final ServerPlayerEntity player = source.getServer().getPlayerList().getPlayerByUUID(profile + .getId()); + if (player != null) source.getServer().getCommandManager().send(player); } else Perms.config.sendFeedback(source, "thutperms.group.already_in", true, name, groupName); } @@ -157,6 +161,9 @@ private static int executeRemoveGroup(final CommandSource source, final String g { Perms.savePerms(); Perms.config.sendFeedback(source, "thutperms.group.removed", true, name, groupName); + final ServerPlayerEntity player = source.getServer().getPlayerList().getPlayerByUUID(profile + .getId()); + if (player != null) source.getServer().getCommandManager().send(player); } else Perms.config.sendFeedback(source, "thutperms.group.not_in", true, name, groupName); } @@ -178,6 +185,7 @@ private static int executeAddPerm(final CommandSource source, final String perm, if (!EditGroup.valid(perm)) Perms.config.sendError(source, "thutperms.perm.unknownperm", perm); g.allowedCommands.add(perm); + g.onUpdated(source.getServer()); Perms.savePerms(); Perms.config.sendFeedback(source, "thutperms.perm.added", true, groupName, perm); return 0; @@ -194,6 +202,7 @@ private static int executeRemovePerm(final CommandSource source, final String pe if (!EditGroup.valid(perm)) Perms.config.sendError(source, "thutperms.perm.unknownperm", perm); g.allowedCommands.remove(perm); + g.onUpdated(source.getServer()); Perms.savePerms(); Perms.config.sendFeedback(source, "thutperms.perm.removed", true, groupName, perm); return 0; @@ -210,6 +219,7 @@ private static int executeDenyPerm(final CommandSource source, final String perm if (!EditGroup.valid(perm)) Perms.config.sendError(source, "thutperms.perm.unknownperm", perm); g.bannedCommands.add(perm); + g.onUpdated(source.getServer()); Perms.savePerms(); Perms.config.sendFeedback(source, "thutperms.perm.denied", true, groupName, perm); return 0; @@ -226,6 +236,7 @@ private static int executeUnDenyPerm(final CommandSource source, final String pe if (!EditGroup.valid(perm)) Perms.config.sendError(source, "thutperms.perm.unknownperm", perm); g.bannedCommands.remove(perm); + g.onUpdated(source.getServer()); Perms.savePerms(); Perms.config.sendFeedback(source, "thutperms.perm.undenied", true, groupName, perm); return 0; diff --git a/src/main/java/thut/perms/commands/EditPlayer.java b/src/main/java/thut/perms/commands/EditPlayer.java index 1bfd430..584b662 100644 --- a/src/main/java/thut/perms/commands/EditPlayer.java +++ b/src/main/java/thut/perms/commands/EditPlayer.java @@ -167,6 +167,7 @@ private static int executeAddPerm(final CommandSource source, final String perm, { final Player p = GroupManager.get_instance()._manager.getPlayer(profile.getId()); p.allowedCommands.add(perm); + p.onUpdated(source.getServer()); Perms.config.sendFeedback(source, "thutperms.perm.added", true, profile.getName(), perm); } return 0; @@ -180,6 +181,7 @@ private static int executeRemovePerm(final CommandSource source, final String pe { final Player p = GroupManager.get_instance()._manager.getPlayer(profile.getId()); p.allowedCommands.remove(perm); + p.onUpdated(source.getServer()); Perms.config.sendFeedback(source, "thutperms.perm.removed", true, profile.getName(), perm); } return 0; @@ -193,6 +195,7 @@ private static int executeDenyPerm(final CommandSource source, final String perm { final Player p = GroupManager.get_instance()._manager.getPlayer(profile.getId()); p.bannedCommands.add(perm); + p.onUpdated(source.getServer()); Perms.config.sendFeedback(source, "thutperms.perm.denied", true, profile.getName(), perm); } return 0; @@ -206,6 +209,7 @@ private static int executeUnDenyPerm(final CommandSource source, final String pe { final Player p = GroupManager.get_instance()._manager.getPlayer(profile.getId()); p.bannedCommands.remove(perm); + p.onUpdated(source.getServer()); Perms.config.sendFeedback(source, "thutperms.perm.undenied", true, profile.getName(), perm); } return 0; diff --git a/src/main/java/thut/perms/commands/Reload.java b/src/main/java/thut/perms/commands/Reload.java index 03682e9..5482796 100644 --- a/src/main/java/thut/perms/commands/Reload.java +++ b/src/main/java/thut/perms/commands/Reload.java @@ -39,9 +39,15 @@ private static int execute(final CommandSource source) throws CommandSyntaxExcep final MinecraftServer server = source.getServer(); Perms.loadPerms(); GroupManager.get_instance()._server = server; - // Reload player names, to apply the tags if they exist + + // Refresh things for the players for (final ServerPlayerEntity player : server.getPlayerList().getPlayers()) + { + // Reload player names, to apply the tags if they exist GroupManager.get_instance().updateName(player); + // Update their command lists + server.getCommandManager().send(player); + } return 0; } } \ No newline at end of file diff --git a/src/main/java/thut/perms/management/Group.java b/src/main/java/thut/perms/management/Group.java index 8483c4d..8958bff 100644 --- a/src/main/java/thut/perms/management/Group.java +++ b/src/main/java/thut/perms/management/Group.java @@ -5,15 +5,25 @@ import com.google.common.collect.Sets; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.server.MinecraftServer; + public class Group extends PermissionsHolder { - public String name; - public String prefix = ""; - public String suffix = ""; public Set members = Sets.newHashSet(); public Group(final String name) { this.name = name; } + + @Override + public void onUpdated(final MinecraftServer server) + { + for (final UUID id : this.members) + { + final ServerPlayerEntity player = server.getPlayerList().getPlayerByUUID(id); + if (player != null) server.getCommandManager().send(player); + } + } } diff --git a/src/main/java/thut/perms/management/PermissionsHolder.java b/src/main/java/thut/perms/management/PermissionsHolder.java index c94ad03..59d96ae 100644 --- a/src/main/java/thut/perms/management/PermissionsHolder.java +++ b/src/main/java/thut/perms/management/PermissionsHolder.java @@ -4,20 +4,26 @@ import com.google.common.collect.Lists; +import net.minecraft.server.MinecraftServer; import net.minecraftforge.server.permission.DefaultPermissionLevel; import thut.perms.Perms; public abstract class PermissionsHolder { - public boolean all = false; - public boolean all_non_op = true; - public List allowedCommands = Lists.newArrayList(); - public List bannedCommands = Lists.newArrayList(); - public String parentName = null; + public String name = ""; + public String prefix = ""; + public String suffix = ""; + public boolean all = false; + public boolean all_non_op = true; + public String parentName = null; + + public List allowedCommands = Lists.newArrayList(); + public List bannedCommands = Lists.newArrayList(); + public PermissionsHolder _parent; protected List _whiteWildCards; protected List _blackWildCards; - public boolean _init = false; + public boolean _init = false; private void init() { @@ -34,6 +40,8 @@ private void init() else if (s.startsWith("*")) this._blackWildCards.add(s.substring(1)); } + public abstract void onUpdated(MinecraftServer server); + public List getAllowedCommands() { if (this.allowedCommands == null) this.allowedCommands = Lists.newArrayList(); diff --git a/src/main/java/thut/perms/management/Player.java b/src/main/java/thut/perms/management/Player.java index 27f5fd0..aa7e9a5 100644 --- a/src/main/java/thut/perms/management/Player.java +++ b/src/main/java/thut/perms/management/Player.java @@ -5,12 +5,13 @@ import com.google.common.collect.Lists; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.server.MinecraftServer; + public class Player extends PermissionsHolder { - public UUID id; - public String name = ""; - public String prefix = ""; - public String suffix = ""; + public UUID id; + public List groups = Lists.newArrayList(); public List _groups = Lists.newArrayList(); @@ -55,4 +56,11 @@ public boolean isAll_non_op() { return false; } + + @Override + public void onUpdated(final MinecraftServer server) + { + final ServerPlayerEntity player = server.getPlayerList().getPlayerByUUID(this.id); + if (player != null) server.getCommandManager().send(player); + } } diff --git a/src/main/resources/assets/thutperms/lang/en_us.json b/src/main/resources/assets/thutperms/lang/en_us.json index 32aa8ba..919cf8f 100644 --- a/src/main/resources/assets/thutperms/lang/en_us.json +++ b/src/main/resources/assets/thutperms/lang/en_us.json @@ -12,7 +12,7 @@ "thutperms.group.removed": "§aRemoved §6%1$s§a from group §6%2$s", "thutperms.suffix.set": "§6%1$s§a was given the suffix §6%2$s", - "thutperms.prefix.set": "§6%1$s§a was given the prefix §6%2$s" + "thutperms.prefix.set": "§6%1$s§a was given the prefix §6%2$s", "_comment": "error messages", @@ -36,6 +36,6 @@ "thutperms.reloaded": "§aReloaded permissions from file", - "thutperms.perms.logged": "§aA Table of all known permissions was saved to thutperms.log", + "thutperms.perms.logged": "§aA Table of all known permissions was saved to thutperms.log" } \ No newline at end of file diff --git a/src/main/resources/assets/thutperms/lang/zh_cn.json b/src/main/resources/assets/thutperms/lang/zh_cn.json index 76f5d7c..e30fac7 100644 --- a/src/main/resources/assets/thutperms/lang/zh_cn.json +++ b/src/main/resources/assets/thutperms/lang/zh_cn.json @@ -36,6 +36,6 @@ "thutperms.reloaded": "§a重载权限", - "thutperms.perms.logged": "§a所有权限节点已被存储至 thutperms.log", + "thutperms.perms.logged": "§a所有权限节点已被存储至 thutperms.log" } \ No newline at end of file