Verified Commit 75af408d authored by Yannick Schinko's avatar Yannick Schinko
Browse files

Added Velocity code

parent ba2a60ae
package team.aura_dev.aurasudo.platform.velocity;
import com.velocitypowered.api.proxy.ProxyServer;
import java.nio.file.Path;
import team.aura_dev.aurasudo.api.AuraSudo;
import team.aura_dev.aurasudo.platform.common.AuraSudoBase;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
import team.aura_dev.aurasudo.platform.velocity.listener.PlayerEventListenerVelocity;
import team.aura_dev.aurasudo.platform.velocity.player.PlayerManagerVelocity;
import team.aura_dev.lib.multiplatformcore.DependencyClassLoader;
public class AuraSudoVelocity extends AuraSudoBase {
private final AuraSudoVelocityBootstrap plugin;
private final ProxyServer server;
public AuraSudoVelocity(
DependencyClassLoader classLoader,
AuraSudoVelocityBootstrap 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 "Velocity";
}
@Override
public String getPlatformVariant() {
return server.getVersion().getName();
}
@Override
protected PlayerManagerCommon generatePlayerManager() {
return new PlayerManagerVelocity(server);
}
@Override
protected void registerEventListeners() {
server.getEventManager().register(plugin, new PlayerEventListenerVelocity(this));
}
}
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.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import java.nio.file.Path;
import team.aura_dev.aurasudo.platform.common.AuraSudoBaseBootstrap;
import team.aura_dev.aurasudo.platform.common.AuraSudoBootstrapper;
@Plugin(
id = AuraSudoBootstrapper.ID,
name = AuraSudoBootstrapper.NAME,
version = AuraSudoBootstrapper.VERSION,
description = AuraSudoBootstrapper.DESCRIPTION,
url = AuraSudoBootstrapper.URL,
authors = {AuraSudoBootstrapper.AUTHOR})
public class AuraSudoVelocityBootstrap {
private final AuraSudoBaseBootstrap bootstrappedPlugin;
@Inject
public AuraSudoVelocityBootstrap(ProxyServer server, @DataDirectory Path dataDir) {
final AuraSudoBootstrapper bootstrapper = new AuraSudoBootstrapper();
bootstrapper.initializePlugin(this, server, dataDir);
bootstrappedPlugin = bootstrapper.getPlugin();
}
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
bootstrappedPlugin.preInitPlugin();
bootstrappedPlugin.initPlugin();
}
}
package team.aura_dev.aurasudo.platform.velocity.listener;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.LoginEvent;
import team.aura_dev.aurasudo.platform.common.AuraSudoBase;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerEventListenerVelocity {
private final PlayerManagerCommon playerManager;
public PlayerEventListenerVelocity(AuraSudoBase plugin) {
this.playerManager = plugin.getPlayerManager();
}
@Subscribe(order = PostOrder.EARLY)
public void onPlayerJoinAsync(LoginEvent event) {
playerManager.fromNativePlayer(event.getPlayer());
}
@Subscribe(order = PostOrder.LAST)
public void onPlayerLeave(DisconnectEvent event) {
playerManager.unloadPlayer(event.getPlayer().getUniqueId());
}
}
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
package team.aura_dev.aurasudo.platform.velocity.player;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.util.GameProfile;
import java.util.Optional;
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;
@RequiredArgsConstructor
public class PlayerManagerVelocity extends PlayerManagerCommon {
private final ProxyServer server;
@Override
protected Optional<PlayerData> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataCommon(uuid, server.getPlayer(uuid).get().getUsername()));
}
@Override
protected BasePlayerData nativePlayerToBasePlayerData(Object player)
throws IllegalArgumentException {
UUID uuid;
String playerName;
if (player instanceof BasePlayerData) {
return (BasePlayerData) player;
} else if (player instanceof Player) {
final Player nativePlayer = (Player) player;
uuid = nativePlayer.getUniqueId();
playerName = nativePlayer.getUsername();
} else if (player instanceof GameProfile) {
final GameProfile nativePlayer = (GameProfile) player;
uuid = nativePlayer.getId();
playerName = nativePlayer.getName();
} else {
throw new IllegalArgumentException(
"The passed player object ("
+ player
+ ") is not of type "
+ Player.class.getName()
+ " or "
+ GameProfile.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