From b3a6307052ac14b333d4b597cf6a443c8981126b Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sat, 22 Aug 2020 15:07:21 -0400 Subject: [PATCH] Fix miscellaneous command permission bugs (#3616) Fixes #3612, in which `/list`'s tab complete previously revealed the presence of vanished players in certain groups, and fixes #3613 in which `/time set` did not properly check whether the player had permission to change the time. --- .../src/com/earth2me/essentials/PlayerList.java | 2 +- .../essentials/commands/Commandlist.java | 2 +- .../essentials/commands/Commandtime.java | 4 ++++ .../essentials/commands/EssentialsCommand.java | 16 +++------------- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/PlayerList.java b/Essentials/src/com/earth2me/essentials/PlayerList.java index 9dd236010..9e4f90092 100644 --- a/Essentials/src/com/earth2me/essentials/PlayerList.java +++ b/Essentials/src/com/earth2me/essentials/PlayerList.java @@ -59,7 +59,7 @@ public class PlayerList { } // Build the basic player list, divided by groups. - public static Map> getPlayerLists(final IEssentials ess, final User sender, final boolean showHidden) { + public static Map> getPlayerLists(final IEssentials ess, final IUser sender, final boolean showHidden) { final Map> playerList = new HashMap<>(); for (User onlineUser : ess.getOnlineUsers()) { if ((sender == null && !showHidden && onlineUser.isHidden()) || (sender != null && !showHidden && !sender.getBase().canSee(onlineUser.getBase()))) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 620705ba8..1c79a088f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -120,7 +120,7 @@ public class Commandlist extends EssentialsCommand { @Override protected List getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) { if (args.length == 1) { - return getGroups(); + return new ArrayList<>(PlayerList.getPlayerLists(ess, sender.getUser(ess), true).keySet()); } else { return Collections.emptyList(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index 926745d72..6ad87415d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -64,6 +64,10 @@ public class Commandtime extends EssentialsCommand { // Start updating world times, we have what we need User user = ess.getUser(sender.getPlayer()); + if (!user.isAuthorized("essentials.time.set")) { + throw new Exception(tl("timeSetPermission")); + } + for (World world : worlds) { if (!canUpdateWorld(user, world)) { throw new Exception(tl("timeSetWorldPermission", user.getWorld().getName())); diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 4a1cd17a5..c2c950f96 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -1,10 +1,6 @@ package com.earth2me.essentials.commands; -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.PlayerList; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; @@ -14,8 +10,10 @@ import com.google.common.collect.Lists; import net.ess3.api.IEssentials; import org.bukkit.Server; import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; - +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.util.StringUtil; import java.util.ArrayList; @@ -282,14 +280,6 @@ public abstract class EssentialsCommand implements IEssentialsCommand { return players; } - /** - * Returns a list of all online groups. - */ - protected List getGroups() { - // TODO: A better way to do this - return new ArrayList<>(PlayerList.getPlayerLists(ess, null, true).keySet()); - } - /** * Gets a list of tab-completable items that start with the given name. * Due to the number of items, this may not return the entire list.