Verified Commit 55606fad authored by Yannick Schinko's avatar Yannick Schinko
Browse files

Added sudo command

Also improved some internal impelementations
parent e97b4ace
......@@ -14,7 +14,7 @@ public interface PlayerManager {
* @return the data of the player associated with the passed UUID wrapped in an {@link Optional}.
* Or an empty Optional if the player does not exist.
*/
public Optional<PlayerData> getPlayerData(@Nonnull UUID uuid);
public Optional<? extends PlayerData> getPlayerData(@Nonnull UUID uuid);
/**
* Does the same as {@link #getPlayerData(UUID)} but returns the {@link PlayerData} object
......
......@@ -5,9 +5,10 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
import team.aura_dev.aurasudo.api.player.PlayerManager;
import team.aura_dev.aurasudo.platform.common.command.BaseCommand;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class CommandWrapperBungeeCord extends Command {
protected final PlayerManager playerManager;
protected final PlayerManagerCommon playerManager;
protected final BaseCommand command;
/**
......@@ -17,7 +18,7 @@ public class CommandWrapperBungeeCord extends Command {
* objects
* @param command The underlying {@link BaseCommand}
*/
public CommandWrapperBungeeCord(PlayerManager playerManager, BaseCommand command) {
public CommandWrapperBungeeCord(PlayerManagerCommon playerManager, BaseCommand command) {
super(command.getBaseCommand(), command.COMMAND.getPermission(), command.getAliasesAsArray());
this.playerManager = playerManager;
......
......@@ -6,18 +6,18 @@ import javax.annotation.Nonnull;
import lombok.NonNull;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import team.aura_dev.aurasudo.api.player.PlayerData;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerManagerBungeeCord extends PlayerManagerCommon {
@Override
protected Optional<PlayerData> generatePlayerData(@Nonnull @NonNull UUID uuid) {
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataBungeeCord(uuid));
}
@Nonnull
@Override
protected PlayerData generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataBungeeCord(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
......
......@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import team.aura_dev.aurasudo.api.AuraSudoApi;
import team.aura_dev.aurasudo.platform.common.command.BaseCommand;
import team.aura_dev.aurasudo.platform.common.command.SudoCommand;
import team.aura_dev.aurasudo.platform.common.config.ConfigLoader;
import team.aura_dev.aurasudo.platform.common.context.SudoContextCalculator;
import team.aura_dev.aurasudo.platform.common.dependency.RuntimeDependencies;
......@@ -150,6 +151,9 @@ public abstract class AuraSudoBase implements AuraSudoApi, AuraSudoBaseBootstrap
.getContextManager()
.registerCalculator(new SudoContextCalculator(playerManager, getMaxSudoLevel()));
logger.info("Registering Context with LuckPerms");
registerCommand(new SudoCommand());
// TODO
}
......
......@@ -6,8 +6,8 @@ import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import lombok.Getter;
import team.aura_dev.aurasudo.api.player.PlayerData;
import team.aura_dev.aurasudo.platform.common.permission.Permission;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
public abstract class BaseCommand {
public final Permission BASE;
......@@ -40,6 +40,6 @@ public abstract class BaseCommand {
return aliases.toArray(new String[] {});
}
public abstract void execute(PlayerData player, String alias, Collection<String> arguments)
public abstract void execute(PlayerDataCommon player, String alias, List<String> arguments)
throws CommandExecutionException;
}
package team.aura_dev.aurasudo.platform.common.command;
import java.util.List;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
public class SudoCommand extends BaseCommand {
public SudoCommand() {
super("sudo");
}
@Override
public void execute(PlayerDataCommon player, String alias, List<String> arguments)
throws CommandExecutionException {
if (!player.hasPermission(COMMAND)) throw new PermissionException(COMMAND);
// Toggle
player.setSudoLevel((player.getSudoLevel() + 1) % 2);
}
}
......@@ -13,7 +13,7 @@ import team.aura_dev.aurasudo.api.player.PlayerData;
import team.aura_dev.aurasudo.api.player.PlayerManager;
public abstract class PlayerManagerCommon implements PlayerManager {
protected final LoadingCache<UUID, Optional<PlayerData>> playerCache;
protected final LoadingCache<UUID, Optional<PlayerDataCommon>> playerCache;
protected PlayerManagerCommon() {
playerCache =
......@@ -22,25 +22,26 @@ public abstract class PlayerManagerCommon implements PlayerManager {
.build(this::generatePlayerData);
}
protected abstract Optional<PlayerData> generatePlayerData(@Nonnull @NonNull UUID uuid);
protected abstract Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid);
@Nonnull
protected abstract PlayerData generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData);
protected abstract PlayerDataCommon generatePlayerData(
@Nonnull @NonNull BasePlayerData basePlayerData);
@SuppressFBWarnings(
value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE",
justification = "SpotBugs is incorrect in this case")
@Override
public Optional<PlayerData> getPlayerData(@Nonnull @NonNull UUID uuid) {
public Optional<PlayerDataCommon> getPlayerData(@Nonnull @NonNull UUID uuid) {
return playerCache.get(uuid);
}
@Override
public PlayerData fromNativePlayer(@Nonnull @NonNull Object player)
public PlayerDataCommon fromNativePlayer(@Nonnull @NonNull Object player)
throws IllegalArgumentException {
final BasePlayerData playerData = nativePlayerToBasePlayerData(player);
final UUID uuid = playerData.getUuid();
Optional<PlayerData> data = playerCache.getIfPresent(uuid);
Optional<PlayerDataCommon> data = playerCache.getIfPresent(uuid);
if ((data != null) && data.isPresent()) return data.get();
......
......@@ -6,9 +6,10 @@ import cn.nukkit.command.data.CommandData;
import java.util.Arrays;
import team.aura_dev.aurasudo.api.player.PlayerManager;
import team.aura_dev.aurasudo.platform.common.command.BaseCommand;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class CommandWrapperNukkit extends Command {
protected final PlayerManager playerManager;
protected final PlayerManagerCommon playerManager;
protected final BaseCommand command;
/**
......@@ -18,7 +19,7 @@ public class CommandWrapperNukkit extends Command {
* objects
* @param command The underlying {@link BaseCommand}
*/
public CommandWrapperNukkit(PlayerManager playerManager, BaseCommand command) {
public CommandWrapperNukkit(PlayerManagerCommon playerManager, BaseCommand command) {
super(
CommandData.builder(command.getBaseCommand())
.addPermission(command.COMMAND.getPermission())
......
......@@ -5,18 +5,18 @@ import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import team.aura_dev.aurasudo.api.player.PlayerData;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerManagerNukkit extends PlayerManagerCommon {
@Override
protected Optional<PlayerData> generatePlayerData(@Nonnull @NonNull UUID uuid) {
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataNukkit(uuid));
}
@Nonnull
@Override
protected PlayerData generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataNukkit(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
......
......@@ -5,9 +5,10 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import team.aura_dev.aurasudo.api.player.PlayerManager;
import team.aura_dev.aurasudo.platform.common.command.BaseCommand;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class CommandWrapperSpigot extends Command {
protected final PlayerManager playerManager;
protected final PlayerManagerCommon playerManager;
protected final BaseCommand command;
/**
......@@ -17,7 +18,7 @@ public class CommandWrapperSpigot extends Command {
* objects
* @param command The underlying {@link BaseCommand}
*/
public CommandWrapperSpigot(PlayerManager playerManager, BaseCommand command) {
public CommandWrapperSpigot(PlayerManagerCommon playerManager, BaseCommand command) {
super(command.getBaseCommand(), "", "", command.getAliasesAsList());
setPermission(command.COMMAND.getPermission());
......
......@@ -5,18 +5,18 @@ import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import org.bukkit.entity.Player;
import team.aura_dev.aurasudo.api.player.PlayerData;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerManagerSpigot extends PlayerManagerCommon {
@Override
protected Optional<PlayerData> generatePlayerData(@Nonnull @NonNull UUID uuid) {
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataSpigot(uuid));
}
@Nonnull
@Override
protected PlayerData generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataSpigot(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
......
package team.aura_dev.aurasudo.platform.sponge.command;
import java.util.ArrayList;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
......@@ -8,11 +9,12 @@ import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.text.Text;
import team.aura_dev.aurasudo.api.player.PlayerManager;
import team.aura_dev.aurasudo.platform.common.command.BaseCommand;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class CommandExecutorSponge implements CommandExecutor {
public static final Text ARGS = Text.of("args");
protected final PlayerManager playerManager;
protected final PlayerManagerCommon playerManager;
protected final BaseCommand command;
/**
......@@ -22,7 +24,7 @@ public class CommandExecutorSponge implements CommandExecutor {
* objects
* @param command The underlying {@link BaseCommand}
*/
public CommandExecutorSponge(PlayerManager playerManager, BaseCommand command) {
public CommandExecutorSponge(PlayerManagerCommon playerManager, BaseCommand command) {
this.playerManager = playerManager;
this.command = command;
}
......@@ -31,7 +33,9 @@ public class CommandExecutorSponge implements CommandExecutor {
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
// Sadly we don't know the alias being used, so we need to pass the base command
command.execute(
playerManager.fromNativePlayer(src), command.getBaseCommand(), args.getAll(ARGS));
playerManager.fromNativePlayer(src),
command.getBaseCommand(),
new ArrayList(args.getAll(ARGS)));
return CommandResult.success();
}
......
......@@ -6,18 +6,18 @@ import javax.annotation.Nonnull;
import lombok.NonNull;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.profile.GameProfile;
import team.aura_dev.aurasudo.api.player.PlayerData;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerManagerSponge extends PlayerManagerCommon {
@Override
protected Optional<PlayerData> generatePlayerData(@Nonnull @NonNull UUID uuid) {
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataSponge(uuid));
}
@Nonnull
@Override
protected PlayerData generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataSponge(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
......
......@@ -5,9 +5,10 @@ import com.velocitypowered.api.command.CommandSource;
import java.util.Arrays;
import team.aura_dev.aurasudo.api.player.PlayerManager;
import team.aura_dev.aurasudo.platform.common.command.BaseCommand;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class CommandWrapperVelocity implements Command {
protected final PlayerManager playerManager;
protected final PlayerManagerCommon playerManager;
protected final BaseCommand command;
/**
......@@ -17,7 +18,7 @@ public class CommandWrapperVelocity implements Command {
* objects
* @param command The underlying {@link BaseCommand}
*/
public CommandWrapperVelocity(PlayerManager playerManager, BaseCommand command) {
public CommandWrapperVelocity(PlayerManagerCommon playerManager, BaseCommand command) {
this.playerManager = playerManager;
this.command = command;
}
......
......@@ -8,7 +8,6 @@ import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import team.aura_dev.aurasudo.api.player.PlayerData;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
......@@ -17,13 +16,13 @@ public class PlayerManagerVelocity extends PlayerManagerCommon {
private final ProxyServer server;
@Override
protected Optional<PlayerData> generatePlayerData(@Nonnull @NonNull UUID uuid) {
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataCommon(uuid, server.getPlayer(uuid).get().getUsername()));
}
@Nonnull
@Override
protected PlayerData generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataCommon(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment