Fix list command permissions checking

This commit is contained in:
Ben Woo 2023-09-03 23:38:22 +08:00
parent f524c5bdde
commit 6f673066a8
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8

View File

@ -8,6 +8,7 @@ import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax; import co.aikar.commands.annotation.Syntax;
import com.onarandombox.MultiverseCore.commandtools.MVCommandIssuer;
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand; import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagGroup; import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagGroup;
@ -19,6 +20,7 @@ import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter;
import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter; import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter;
import com.onarandombox.MultiverseCore.display.handlers.PagedSendHandler; import com.onarandombox.MultiverseCore.display.handlers.PagedSendHandler;
import com.onarandombox.MultiverseCore.display.parsers.ListContentProvider; import com.onarandombox.MultiverseCore.display.parsers.ListContentProvider;
import com.onarandombox.MultiverseCore.worldnew.entrycheck.WorldEntryChecker;
import com.onarandombox.MultiverseCore.worldnew.entrycheck.WorldEntryCheckerProvider; import com.onarandombox.MultiverseCore.worldnew.entrycheck.WorldEntryCheckerProvider;
import com.onarandombox.MultiverseCore.worldnew.MVWorld; import com.onarandombox.MultiverseCore.worldnew.MVWorld;
import com.onarandombox.MultiverseCore.worldnew.WorldManager; import com.onarandombox.MultiverseCore.worldnew.WorldManager;
@ -78,7 +80,7 @@ public class ListCommand extends MultiverseCommand {
@CommandCompletion("@flags:groupName=mvlist") @CommandCompletion("@flags:groupName=mvlist")
@Syntax("--filter [filter] --page [page]") @Syntax("--filter [filter] --page [page]")
@Description("Displays a listing of all worlds that you can enter.") @Description("Displays a listing of all worlds that you can enter.")
public void onListCommand(BukkitCommandIssuer issuer, public void onListCommand(MVCommandIssuer issuer,
@Syntax("--filter [filter] --page [page]") @Syntax("--filter [filter] --page [page]")
@Description("Filters the list of worlds by the given regex and displays the given page.") @Description("Filters the list of worlds by the given regex and displays the given page.")
@ -94,19 +96,19 @@ public class ListCommand extends MultiverseCommand {
.send(issuer); .send(issuer);
} }
private List<String> getListContents(BukkitCommandIssuer issuer) { private List<String> getListContents(MVCommandIssuer issuer) {
Player player = issuer.isPlayer() ? issuer.getPlayer() : null;
List<String> worldList = new ArrayList<>(); List<String> worldList = new ArrayList<>();
WorldEntryChecker worldEntryChecker = worldEntryCheckerProvider.forSender(issuer.getIssuer());
worldManager.getMVWorlds().stream() worldManager.getMVWorlds().stream()
.filter(world -> player == null) // TODO: || worldEntryCheckerProvider.forSender(player).canAccessWorld(world).isSuccess()) .filter(world -> worldEntryChecker.canAccessWorld(world).isSuccess())
.filter(world -> canSeeWorld(player, world)) .filter(world -> canSeeWorld(issuer, world))
.map(world -> hiddenText(world) + world.getAlias() + " - " + parseColouredEnvironment(world.getEnvironment())) .map(world -> hiddenText(world) + world.getAlias() + " - " + parseColouredEnvironment(world.getEnvironment()))
.sorted() .sorted()
.forEach(worldList::add); .forEach(worldList::add);
worldManager.getOfflineOnlyWorlds().stream() worldManager.getOfflineOnlyWorlds().stream()
.filter(world -> issuer.hasPermission("multiverse.access." + world.getName())) // TODO: Refactor stray permission check .filter(world -> worldEntryChecker.canAccessWorld(world).isSuccess())
.map(world -> ChatColor.GRAY + world.getAlias() + " - UNLOADED") .map(world -> ChatColor.GRAY + world.getAlias() + " - UNLOADED")
.sorted() .sorted()
.forEach(worldList::add); .forEach(worldList::add);
@ -114,10 +116,9 @@ public class ListCommand extends MultiverseCommand {
return worldList; return worldList;
} }
private boolean canSeeWorld(Player player, MVWorld world) { private boolean canSeeWorld(MVCommandIssuer issuer, MVWorld world) {
return !world.isHidden() return !world.isHidden()
|| player == null || issuer.hasPermission("multiverse.core.modify"); // TODO: Refactor stray permission check
|| player.hasPermission("multiverse.core.modify"); // TODO: Refactor stray permission check
} }
private String hiddenText(MVWorld world) { private String hiddenText(MVWorld world) {