mirror of https://github.com/GeyserMC/Geyser.git
Fix GeyserSession#hasPermission, remove WorldManager#hasPermission, docs
This commit is contained in:
parent
e3532fa4f9
commit
5b3226b0bf
|
@ -31,5 +31,6 @@ import org.geysermc.geyser.api.util.TriState;
|
|||
|
||||
public interface PermissionChecker {
|
||||
|
||||
@NonNull
|
||||
TriState hasPermission(@NonNull CommandSource source, @NonNull String permission);
|
||||
}
|
||||
|
|
|
@ -147,12 +147,6 @@ public class GeyserFabricWorldManager extends GeyserWorldManager {
|
|||
BlockEntityUtils.updateBlockEntity(session, blockEntityTag, Vector3i.from(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(GeyserSession session, String permission) {
|
||||
ServerPlayer player = getPlayer(session);
|
||||
return Permissions.check(player, permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<com.github.steveice10.opennbt.tag.builtin.CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) {
|
||||
|
|
|
@ -171,11 +171,6 @@ public class GeyserSpigotWorldManager extends WorldManager {
|
|||
return gameRule.getDefaultIntValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(GeyserSession session, String permission) {
|
||||
return Bukkit.getPlayer(session.getPlayerEntity().getUsername()).hasPermission(permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) {
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionCheckersE
|
|||
import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent;
|
||||
import org.geysermc.geyser.api.permission.PermissionChecker;
|
||||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.command.GeyserCommandManager;
|
||||
import org.geysermc.geyser.command.GeyserCommandSource;
|
||||
import org.geysermc.geyser.util.FileUtils;
|
||||
|
||||
|
@ -70,6 +71,10 @@ public class GeyserStandaloneCommandManager extends CommandManager<GeyserCommand
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a {@link GeyserRegisterPermissionsEvent} to determine any additions or removals to the base list of
|
||||
* permissions. This should be called after any event listeners have been registered, such as that of {@link GeyserCommandManager}.
|
||||
*/
|
||||
public void gatherPermissions() {
|
||||
geyser.getEventBus().fire((GeyserRegisterPermissionsEvent) (permission, def) -> {
|
||||
if (def == TriState.TRUE) {
|
||||
|
@ -82,6 +87,15 @@ public class GeyserStandaloneCommandManager extends CommandManager<GeyserCommand
|
|||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull GeyserCommandSource sender, @NonNull String permission) {
|
||||
// Note: the two GeyserCommandSources on Geyser-Standalone are GeyserLogger and GeyserSession
|
||||
// GeyserLogger#hasPermission always returns true
|
||||
// GeyserSession#hasPermission delegates to this method,
|
||||
// which is why this method doesn't just call GeyserCommandSource#hasPermission
|
||||
|
||||
if (sender.isConsole()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (PermissionChecker checker : permissionCheckers) {
|
||||
Boolean result = checker.hasPermission(sender, permission).toBoolean();
|
||||
if (result != null) {
|
||||
|
|
|
@ -29,6 +29,14 @@ import java.util.UUID;
|
|||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Converts {@link GeyserCommandSource}s to the server's command sender type in a lenient manner.
|
||||
*
|
||||
* @param senderType class of the server command sender type
|
||||
* @param playerLookup function for looking up a player command sender by UUID
|
||||
* @param consoleProvider supplier of the console command sender
|
||||
* @param <S> server command sender type
|
||||
*/
|
||||
public record CommandSourceConverter<S>(Class<S> senderType,
|
||||
Function<UUID, S> playerLookup,
|
||||
Supplier<S> consoleProvider) {
|
||||
|
@ -49,6 +57,18 @@ public record CommandSourceConverter<S>(Class<S> senderType,
|
|||
.orElseThrow(() -> new IllegalArgumentException("failed to find sender for name=%s, uuid=%s".formatted(source.name(), source.playerUuid())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CommandSourceConverter for a server platform
|
||||
* in which the player type is not the command sender type, and must be mapped.
|
||||
*
|
||||
* @param senderType class of the command sender type
|
||||
* @param playerLookup function for looking up a player by UUID
|
||||
* @param senderLookup function for converting a player to a command sender
|
||||
* @param consoleProvider supplier of the console command sender
|
||||
* @return a new CommandSourceConverter
|
||||
* @param <P> server player type
|
||||
* @param <S> server command sender type
|
||||
*/
|
||||
public static <P, S> CommandSourceConverter<S> layered(Class<S> senderType,
|
||||
Function<UUID, P> playerLookup,
|
||||
Function<P, S> senderLookup,
|
||||
|
|
|
@ -165,7 +165,7 @@ public class GeyserCommandManager {
|
|||
* @return Command description
|
||||
*/
|
||||
public String description(String command) {
|
||||
return "";
|
||||
return ""; // todo: reimplement
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
|
|
|
@ -160,11 +160,6 @@ public class GeyserWorldManager extends WorldManager {
|
|||
return gameRule.getDefaultIntValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(GeyserSession session, String permission) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) {
|
||||
|
|
|
@ -180,15 +180,6 @@ public abstract class WorldManager {
|
|||
session.sendCommand("difficulty " + difficulty.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given session's player has a permission
|
||||
*
|
||||
* @param session The session of the player to check the permission of
|
||||
* @param permission The permission node to check
|
||||
* @return True if the player has the requested permission, false if not
|
||||
*/
|
||||
public abstract boolean hasPermission(GeyserSession session, String permission);
|
||||
|
||||
/**
|
||||
* Returns a list of biome identifiers available on the server.
|
||||
*/
|
||||
|
|
|
@ -1693,7 +1693,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return geyser.getWorldManager().hasPermission(this, permission);
|
||||
// let the cloud implementation handle permission checking
|
||||
return geyser.commandManager().cloud().hasPermission(this, permission);
|
||||
}
|
||||
|
||||
private static final Ability[] USED_ABILITIES = Ability.values();
|
||||
|
|
Loading…
Reference in New Issue