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.
This commit is contained in:
Josh Roy 2020-08-22 15:07:21 -04:00 committed by GitHub
parent 3ca0181b79
commit b3a6307052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 15 deletions

View File

@ -59,7 +59,7 @@ public class PlayerList {
}
// Build the basic player list, divided by groups.
public static Map<String, List<User>> getPlayerLists(final IEssentials ess, final User sender, final boolean showHidden) {
public static Map<String, List<User>> getPlayerLists(final IEssentials ess, final IUser sender, final boolean showHidden) {
final Map<String, List<User>> playerList = new HashMap<>();
for (User onlineUser : ess.getOnlineUsers()) {
if ((sender == null && !showHidden && onlineUser.isHidden()) || (sender != null && !showHidden && !sender.getBase().canSee(onlineUser.getBase()))) {

View File

@ -120,7 +120,7 @@ public class Commandlist extends EssentialsCommand {
@Override
protected List<String> 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();
}

View File

@ -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()));

View File

@ -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<String> 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.