Verified Commit 628563cf authored by Yannick Schinko's avatar Yannick Schinko
Browse files

Added sudo context for LuckPerms

parent 247b7c1c
......@@ -11,4 +11,6 @@ public interface AuraSudoApi {
public static final String AUTHOR = "The_BrainStone";
public PlayerManager getPlayerManager();
public int getMaxSudoLevel();
}
......@@ -18,7 +18,7 @@ public interface PlayerData {
@Nonnull
public String getDisplayName();
public boolean getSudoActive();
public int getSudoLevel();
public void setSudoActive(boolean active);
public void setSudoLevel(int level);
}
......@@ -5,3 +5,5 @@ version: ${version}
author: BrainStone
description: ${description}
url: https://github.com/AuraDevelopmentTeam/AuraSudo
depends:
- LuckPerms
......@@ -26,6 +26,7 @@ dependencies {
api "org.slf4j:slf4j-api:${slf4j_version}"
api "com.github.ben-manes.caffeine:caffeine:${caffeine_version}"
api "org.spongepowered:configurate-hocon:${configurate_version}"
api "net.luckperms:api:${luckPerms_version}"
// Shadow dependencies
shadow("team.aura_dev.lib.multiplatformcore:MultiPlatformCore:${multiPlatformCore_version}") {
......
......@@ -12,6 +12,7 @@ useRootValues=true
caffeine_version=2.8.0
configurate_version=3.6.1
luckPerms_version=5.2
multiPlatformCore_version=1.2.1.+
slf4j_version=1.7.25
......
......@@ -6,10 +6,12 @@ import java.util.Arrays;
import java.util.List;
import lombok.Getter;
import lombok.SneakyThrows;
import net.luckperms.api.LuckPermsProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import team.aura_dev.aurasudo.api.AuraSudoApi;
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;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
import team.aura_dev.lib.multiplatformcore.DependencyClassLoader;
......@@ -121,9 +123,20 @@ public abstract class AuraSudoBase implements AuraSudoApi, AuraSudoBaseBootstrap
logger.info("Registering Event Listeners");
registerEventListeners();
logger.info("Registering Context with LuckPerms");
LuckPermsProvider.get()
.getContextManager()
.registerCalculator(new SudoContextCalculator(playerManager, getMaxSudoLevel()));
// TODO
}
@Override
public int getMaxSudoLevel() {
// TODO: Read from config
return 2;
}
// Private helper methods
// Generated with http://www.patorjk.com/software/taag/#p=display&f=Straight&t=AuraSudo
private List<String> generateAsciiBanner() {
......
package team.aura_dev.aurasudo.platform.common.context;
import lombok.RequiredArgsConstructor;
import net.luckperms.api.context.ContextCalculator;
import net.luckperms.api.context.ContextConsumer;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.ImmutableContextSet;
import org.checkerframework.checker.nullness.qual.NonNull;
import team.aura_dev.aurasudo.api.player.PlayerData;
import team.aura_dev.aurasudo.api.player.PlayerManager;
@RequiredArgsConstructor
public class SudoContextCalculator implements ContextCalculator<Object> {
public static final String CONTEXT_SUDO = "sudo";
protected final PlayerManager playerManager;
protected final int maxSudoLevel;
@Override
public void calculate(@NonNull Object target, @NonNull ContextConsumer consumer) {
final PlayerData data = playerManager.fromNativePlayer(target);
if (data == null) return;
consumer.accept(CONTEXT_SUDO, Integer.toString(data.getSudoLevel()));
}
@Override
public ContextSet estimatePotentialContexts() {
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
for (int i = 0; i <= maxSudoLevel; i++) builder.add(CONTEXT_SUDO, Integer.toString(i));
return builder.build();
}
}
......@@ -7,6 +7,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import team.aura_dev.aurasudo.api.AuraSudo;
import team.aura_dev.aurasudo.api.player.PlayerData;
/**
......@@ -24,7 +25,7 @@ import team.aura_dev.aurasudo.api.player.PlayerData;
public class PlayerDataCommon implements PlayerData {
@NonNull protected final UUID uuid;
@NonNull protected final String playerName;
protected boolean sudoActive = false;
protected int sudoLevel = 0;
/**
* A nice name for the player.<br>
......@@ -38,12 +39,13 @@ public class PlayerDataCommon implements PlayerData {
return playerName;
}
@Override
public boolean getSudoActive() {
return sudoActive;
}
public void setSudoLevel(int sudoLevel) {
final int maxSudoLevel = AuraSudo.getApi().getMaxSudoLevel();
if ((sudoLevel < 0) || (sudoLevel > maxSudoLevel))
throw new IllegalArgumentException(
"sudoLevel was " + sudoLevel + ". But must be between 0 and " + maxSudoLevel);
public void setSudoActive(boolean active) {
sudoActive = active;
this.sudoLevel = sudoLevel;
}
}
......@@ -5,3 +5,5 @@ version: ${version}
author: BrainStone
description: ${description}
url: https://github.com/AuraDevelopmentTeam/AuraSudo
depends:
- LuckPerms
......@@ -5,3 +5,5 @@ version: ${version}
author: BrainStone
description: ${description}
url: https://github.com/AuraDevelopmentTeam/AuraSudo
depends:
- LuckPerms
......@@ -6,6 +6,7 @@ import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
import team.aura_dev.aurasudo.platform.common.AuraSudoBaseBootstrap;
import team.aura_dev.aurasudo.platform.common.AuraSudoBootstrapper;
......@@ -16,7 +17,8 @@ import team.aura_dev.aurasudo.platform.common.AuraSudoBootstrapper;
version = AuraSudoBootstrapper.VERSION,
description = AuraSudoBootstrapper.DESCRIPTION,
url = AuraSudoBootstrapper.URL,
authors = {AuraSudoBootstrapper.AUTHOR})
authors = {AuraSudoBootstrapper.AUTHOR},
dependencies = @Dependency(id = "luckperms"))
public class AuraSudoSpongeBootstrap {
private final AuraSudoBaseBootstrap bootstrappedPlugin;
......
......@@ -3,6 +3,7 @@ package team.aura_dev.aurasudo.platform.velocity;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
......@@ -16,7 +17,8 @@ import team.aura_dev.aurasudo.platform.common.AuraSudoBootstrapper;
version = AuraSudoBootstrapper.VERSION,
description = AuraSudoBootstrapper.DESCRIPTION,
url = AuraSudoBootstrapper.URL,
authors = {AuraSudoBootstrapper.AUTHOR})
authors = {AuraSudoBootstrapper.AUTHOR},
dependencies = @Dependency(id = "luckperms"))
public class AuraSudoVelocityBootstrap {
private final AuraSudoBaseBootstrap bootstrappedPlugin;
......
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