Verified Commit 04a28dd5 authored by Yannick Schinko's avatar Yannick Schinko
Browse files

Added BungeeCord code

parent 5e86232e
package team.aura_dev.aurasudo.platform.bungeecord;
import java.nio.file.Path;
import net.md_5.bungee.api.ProxyServer;
import team.aura_dev.aurasudo.api.AuraSudo;
import team.aura_dev.aurasudo.platform.bungeecord.listener.PlayerEventListenerBungeeCord;
import team.aura_dev.aurasudo.platform.bungeecord.player.PlayerManagerBungeeCord;
import team.aura_dev.aurasudo.platform.common.AuraSudoBase;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
import team.aura_dev.lib.multiplatformcore.DependencyClassLoader;
public class AuraSudoBungeeCord extends AuraSudoBase {
private final AuraSudoBungeeCordBootstrap plugin;
private final ProxyServer server;
public AuraSudoBungeeCord(
DependencyClassLoader classLoader,
AuraSudoBungeeCordBootstrap plugin,
ProxyServer server,
Path configDir) {
super(classLoader, configDir);
this.plugin = plugin;
this.server = server;
// Instance is initialized
AuraSudo.setApi(this);
}
@Override
public String getBasePlatform() {
return "BungeeCord";
}
@Override
public String getPlatformVariant() {
return server.getName();
}
@Override
protected PlayerManagerCommon generatePlayerManager() {
return new PlayerManagerBungeeCord();
}
@Override
protected void registerEventListeners() {
server.getPluginManager().registerListener(plugin, new PlayerEventListenerBungeeCord(this));
}
}
package team.aura_dev.aurasudo.platform.bungeecord;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import team.aura_dev.aurasudo.platform.common.AuraSudoBaseBootstrap;
import team.aura_dev.aurasudo.platform.common.AuraSudoBootstrapper;
public class AuraSudoBungeeCordBootstrap extends Plugin {
private AuraSudoBaseBootstrap bootstrappedPlugin;
@Override
public void onLoad() {
final AuraSudoBootstrapper bootstrapper = new AuraSudoBootstrapper();
bootstrapper.checkAndLoadSLF4JPlugin(getDataFolder().toPath().resolve("libs"), "bungeecord");
bootstrapper.initializePlugin(this, ProxyServer.getInstance(), getDataFolder().toPath());
bootstrappedPlugin = bootstrapper.getPlugin();
}
@Override
public void onEnable() {
bootstrappedPlugin.preInitPlugin();
bootstrappedPlugin.initPlugin();
}
}
package team.aura_dev.aurasudo.platform.bungeecord.listener;
import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
import team.aura_dev.aurasudo.platform.common.AuraSudoBase;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerEventListenerBungeeCord implements Listener {
private final PlayerManagerCommon playerManager;
public PlayerEventListenerBungeeCord(AuraSudoBase plugin) {
this.playerManager = plugin.getPlayerManager();
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoinAsync(LoginEvent event) {
playerManager.fromNativePlayer(event.getConnection());
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLeave(PlayerDisconnectEvent event) {
playerManager.unloadPlayer(event.getPlayer().getUniqueId());
}
}
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
package team.aura_dev.aurasudo.platform.bungeecord.player;
import java.util.UUID;
import javax.annotation.Nonnull;
import lombok.NonNull;
import net.md_5.bungee.api.ProxyServer;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
public class PlayerDataBungeeCord extends PlayerDataCommon {
public PlayerDataBungeeCord(@NonNull UUID uuid) {
super(uuid, ProxyServer.getInstance().getPlayer(uuid).getName());
}
@Nonnull
@Override
public String getDisplayName() {
return ProxyServer.getInstance().getPlayer(uuid).getDisplayName();
}
}
package team.aura_dev.aurasudo.platform.bungeecord.player;
import java.util.Optional;
import java.util.UUID;
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.PlayerManagerCommon;
public class PlayerManagerBungeeCord extends PlayerManagerCommon {
@Override
protected Optional<PlayerData> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataBungeeCord(uuid));
}
@Override
protected BasePlayerData nativePlayerToBasePlayerData(Object player)
throws IllegalArgumentException {
UUID uuid;
String playerName;
if (player instanceof BasePlayerData) {
return (BasePlayerData) player;
} else if (player instanceof ProxiedPlayer) {
final ProxiedPlayer nativePlayer = (ProxiedPlayer) player;
uuid = nativePlayer.getUniqueId();
playerName = nativePlayer.getName();
} else if (player instanceof PendingConnection) {
final PendingConnection nativePlayer = (PendingConnection) player;
uuid = nativePlayer.getUniqueId();
playerName = nativePlayer.getName();
} else {
throw new IllegalArgumentException(
"The passed player object ("
+ player
+ ") is not of type "
+ ProxiedPlayer.class.getName()
+ " or "
+ PendingConnection.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