mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-05 23:08:23 +00:00
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:
parent
3ca0181b79
commit
b3a6307052
4 changed files with 9 additions and 15 deletions
|
@ -59,7 +59,7 @@ public class PlayerList {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the basic player list, divided by groups.
|
// 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<>();
|
final Map<String, List<User>> playerList = new HashMap<>();
|
||||||
for (User onlineUser : ess.getOnlineUsers()) {
|
for (User onlineUser : ess.getOnlineUsers()) {
|
||||||
if ((sender == null && !showHidden && onlineUser.isHidden()) || (sender != null && !showHidden && !sender.getBase().canSee(onlineUser.getBase()))) {
|
if ((sender == null && !showHidden && onlineUser.isHidden()) || (sender != null && !showHidden && !sender.getBase().canSee(onlineUser.getBase()))) {
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class Commandlist extends EssentialsCommand {
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return getGroups();
|
return new ArrayList<>(PlayerList.getPlayerLists(ess, sender.getUser(ess), true).keySet());
|
||||||
} else {
|
} else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,10 @@ public class Commandtime extends EssentialsCommand {
|
||||||
|
|
||||||
// Start updating world times, we have what we need
|
// Start updating world times, we have what we need
|
||||||
User user = ess.getUser(sender.getPlayer());
|
User user = ess.getUser(sender.getPlayer());
|
||||||
|
if (!user.isAuthorized("essentials.time.set")) {
|
||||||
|
throw new Exception(tl("timeSetPermission"));
|
||||||
|
}
|
||||||
|
|
||||||
for (World world : worlds) {
|
for (World world : worlds) {
|
||||||
if (!canUpdateWorld(user, world)) {
|
if (!canUpdateWorld(user, world)) {
|
||||||
throw new Exception(tl("timeSetWorldPermission", user.getWorld().getName()));
|
throw new Exception(tl("timeSetWorldPermission", user.getWorld().getName()));
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package com.earth2me.essentials.commands;
|
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.CommandSource;
|
||||||
import com.earth2me.essentials.PlayerList;
|
|
||||||
import com.earth2me.essentials.IEssentialsModule;
|
import com.earth2me.essentials.IEssentialsModule;
|
||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
@ -14,8 +10,10 @@ import com.google.common.collect.Lists;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -282,14 +280,6 @@ public abstract class EssentialsCommand implements IEssentialsCommand {
|
||||||
return players;
|
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.
|
* 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.
|
* Due to the number of items, this may not return the entire list.
|
||||||
|
|
Loading…
Reference in a new issue