Verified Commit 142707c3 authored by Yannick Schinko's avatar Yannick Schinko
Browse files

Added console support

parent 98c43a88
package team.aura_dev.aurasudo.platform.bungeecord.player;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
public class ConsolePlayerDataBungeeCord extends ConsolePlayerDataCommon {
public static final ConsolePlayerDataBungeeCord INSTANCE = new ConsolePlayerDataBungeeCord();
protected ConsolePlayerDataBungeeCord() {
super();
}
}
......@@ -4,8 +4,10 @@ import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
......@@ -19,7 +21,9 @@ public class PlayerManagerBungeeCord extends PlayerManagerCommon {
@Nonnull
@Override
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataBungeeCord(basePlayerData.getUuid(), basePlayerData.getPlayerName());
return ConsolePlayerDataCommon.UUID.equals(basePlayerData.getUuid())
? ConsolePlayerDataBungeeCord.INSTANCE
: new PlayerDataBungeeCord(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
@Override
......@@ -40,14 +44,19 @@ public class PlayerManagerBungeeCord extends PlayerManagerCommon {
uuid = nativePlayer.getUniqueId();
playerName = nativePlayer.getName();
} else if (player instanceof CommandSender) {
// CommandSender but not a player means this is the console account
return BasePlayerData.CONSOLE;
} else {
throw new IllegalArgumentException(
"The passed player object ("
+ player
+ ") is not of type "
+ ProxiedPlayer.class.getName()
+ ", "
+ PendingConnection.class.getName()
+ " or "
+ PendingConnection.class.getName());
+ CommandSender.class.getName());
}
return new BasePlayerData(uuid, playerName);
......
package team.aura_dev.aurasudo.platform.common.player;
import java.util.UUID;
import team.aura_dev.aurasudo.platform.common.permission.Permission;
public abstract class ConsolePlayerDataCommon extends PlayerDataCommon {
public static final UUID UUID = new UUID(0, 0);
public static final String NAME = "Console";
public ConsolePlayerDataCommon() {
super(UUID, NAME);
}
@Override
public final boolean isConsole() {
return true;
}
@Override
public boolean hasPermission(Permission permission) {
return true;
}
@Deprecated
@Override
public final int getSudoLevel() throws UnsupportedOperationException {
throw new UnsupportedOperationException(
"Getting the sudo level for the console is unsupported");
}
@Deprecated
@Override
public final void setSudoLevel(int sudoLevel) throws UnsupportedOperationException {
throw new UnsupportedOperationException(
"Setting the sudo level for the console is unsupported");
}
}
......@@ -55,6 +55,10 @@ public class PlayerDataCommon implements PlayerData {
this.sudoLevel = sudoLevel;
}
public boolean isConsole() {
return false;
}
public boolean hasPermission(Permission permission) {
final User user = luckPerms.getUserManager().getUser(uuid);
......
......@@ -22,12 +22,6 @@ public abstract class PlayerManagerCommon implements PlayerManager {
.build(this::generatePlayerData);
}
protected abstract Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid);
@Nonnull
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")
......@@ -79,8 +73,17 @@ public abstract class PlayerManagerCommon implements PlayerManager {
protected abstract BasePlayerData nativePlayerToBasePlayerData(@Nonnull Object player)
throws IllegalArgumentException;
protected abstract Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid);
@Nonnull
protected abstract PlayerDataCommon generatePlayerData(
@Nonnull @NonNull BasePlayerData basePlayerData);
@Data
public static class BasePlayerData {
public static final BasePlayerData CONSOLE =
new BasePlayerData(ConsolePlayerDataCommon.UUID, ConsolePlayerDataCommon.NAME);
@NonNull private final UUID uuid;
@NonNull private final String playerName;
}
......
package team.aura_dev.aurasudo.platform.nukkit.player;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
public class ConsolePlayerDataNukkit extends ConsolePlayerDataCommon {
public static final ConsolePlayerDataNukkit INSTANCE = new ConsolePlayerDataNukkit();
protected ConsolePlayerDataNukkit() {
super();
}
}
package team.aura_dev.aurasudo.platform.nukkit.player;
import cn.nukkit.command.ConsoleCommandSender;
import cn.nukkit.player.Player;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
......@@ -18,7 +20,9 @@ public class PlayerManagerNukkit extends PlayerManagerCommon {
@Nonnull
@Override
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataNukkit(basePlayerData.getUuid(), basePlayerData.getPlayerName());
return ConsolePlayerDataCommon.UUID.equals(basePlayerData.getUuid())
? ConsolePlayerDataNukkit.INSTANCE
: new PlayerDataNukkit(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
@Override
......@@ -34,9 +38,16 @@ public class PlayerManagerNukkit extends PlayerManagerCommon {
uuid = nativePlayer.getServerId();
playerName = nativePlayer.getName();
} else if (player instanceof ConsoleCommandSender) {
return BasePlayerData.CONSOLE;
} else {
throw new IllegalArgumentException(
"The passed player object (" + player + ") is not of type " + Player.class.getName());
"The passed player object ("
+ player
+ ") is not of type "
+ Player.class.getName()
+ " or "
+ ConsoleCommandSender.class.getName());
}
return new BasePlayerData(uuid, playerName);
......
package team.aura_dev.aurasudo.platform.spigot.player;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
public class ConsolePlayerDataSpigot extends ConsolePlayerDataCommon {
public static final ConsolePlayerDataSpigot INSTANCE = new ConsolePlayerDataSpigot();
protected ConsolePlayerDataSpigot() {
super();
}
}
......@@ -4,7 +4,9 @@ import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
......@@ -18,7 +20,9 @@ public class PlayerManagerSpigot extends PlayerManagerCommon {
@Nonnull
@Override
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataSpigot(basePlayerData.getUuid(), basePlayerData.getPlayerName());
return ConsolePlayerDataCommon.UUID.equals(basePlayerData.getUuid())
? ConsolePlayerDataSpigot.INSTANCE
: new PlayerDataSpigot(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
@Override
......@@ -34,9 +38,16 @@ public class PlayerManagerSpigot extends PlayerManagerCommon {
uuid = nativePlayer.getUniqueId();
playerName = nativePlayer.getName();
} else if (player instanceof ConsoleCommandSender) {
return BasePlayerData.CONSOLE;
} else {
throw new IllegalArgumentException(
"The passed player object (" + player + ") is not of type " + Player.class.getName());
"The passed player object ("
+ player
+ ") is not of type "
+ Player.class.getName()
+ " or "
+ ConsoleCommandSender.class.getName());
}
return new BasePlayerData(uuid, playerName);
......
package team.aura_dev.aurasudo.platform.sponge.player;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
public class ConsolePlayerDataSponge extends ConsolePlayerDataCommon {
public static final ConsolePlayerDataSponge INSTANCE = new ConsolePlayerDataSponge();
protected ConsolePlayerDataSponge() {
super();
}
}
......@@ -4,8 +4,10 @@ import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import org.spongepowered.api.command.source.ConsoleSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.profile.GameProfile;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
......@@ -19,7 +21,9 @@ public class PlayerManagerSponge extends PlayerManagerCommon {
@Nonnull
@Override
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataSponge(basePlayerData.getUuid(), basePlayerData.getPlayerName());
return ConsolePlayerDataCommon.UUID.equals(basePlayerData.getUuid())
? ConsolePlayerDataSponge.INSTANCE
: new PlayerDataSponge(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
@Override
......@@ -40,14 +44,18 @@ public class PlayerManagerSponge extends PlayerManagerCommon {
uuid = nativePlayer.getUniqueId();
playerName = nativePlayer.getName().get();
} else if (player instanceof ConsoleSource) {
return BasePlayerData.CONSOLE;
} else {
throw new IllegalArgumentException(
"The passed player object ("
+ player
+ ") is not of type "
+ Player.class.getName()
+ ", "
+ GameProfile.class.getName()
+ " or "
+ GameProfile.class.getName());
+ ConsoleSource.class.getName());
}
return new BasePlayerData(uuid, playerName);
......
package team.aura_dev.aurasudo.platform.velocity.player;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
public class ConsolePlayerDataVelocity extends ConsolePlayerDataCommon {
public static final ConsolePlayerDataVelocity INSTANCE = new ConsolePlayerDataVelocity();
protected ConsolePlayerDataVelocity() {
super();
}
}
package team.aura_dev.aurasudo.platform.velocity.player;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.util.GameProfile;
......@@ -8,6 +9,7 @@ import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import team.aura_dev.aurasudo.platform.common.player.ConsolePlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
......@@ -23,7 +25,9 @@ public class PlayerManagerVelocity extends PlayerManagerCommon {
@Nonnull
@Override
protected PlayerDataCommon generatePlayerData(@Nonnull @NonNull BasePlayerData basePlayerData) {
return new PlayerDataCommon(basePlayerData.getUuid(), basePlayerData.getPlayerName());
return ConsolePlayerDataCommon.UUID.equals(basePlayerData.getUuid())
? ConsolePlayerDataVelocity.INSTANCE
: new PlayerDataCommon(basePlayerData.getUuid(), basePlayerData.getPlayerName());
}
@Override
......@@ -44,14 +48,18 @@ public class PlayerManagerVelocity extends PlayerManagerCommon {
uuid = nativePlayer.getId();
playerName = nativePlayer.getName();
} else if (player instanceof ConsoleCommandSource) {
return BasePlayerData.CONSOLE;
} else {
throw new IllegalArgumentException(
"The passed player object ("
+ player
+ ") is not of type "
+ Player.class.getName()
+ ", "
+ GameProfile.class.getName()
+ " or "
+ GameProfile.class.getName());
+ ConsoleCommandSource.class.getName());
}
return new BasePlayerData(uuid, playerName);
......
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