Skip to content

Commit

Permalink
feat: kyori Audience support
Browse files Browse the repository at this point in the history
Added kyori adventure support for unsupported platforms
  • Loading branch information
GeorgeV220 committed Feb 11, 2023
1 parent cae60d7 commit 642dec8
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 4 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ dependencies {
implementation "org.bstats:bstats-velocity:3.0.0"
implementation "org.bstats:bstats-sponge:3.0.0"

implementation "net.kyori:adventure-platform-bukkit:4.2.0"
implementation "net.kyori:adventure-platform-bungeecord:4.2.0"

implementation 'co.aikar:acf-paper:0.5.1-G-1.0-SNAPSHOT'
implementation 'co.aikar:acf-bungee:0.5.1-G-1.0-SNAPSHOT'
implementation 'co.aikar:acf-velocity:0.5.1-G-1.0-SNAPSHOT'
Expand Down
2 changes: 2 additions & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ dependencies {
compileOnly project(path: ':mc-1-18-2', configuration: 'reobf')
compileOnly project(path: ':mc-1-19', configuration: 'reobf')
compileOnly project(path: ':mc-1-19-3', configuration: 'reobf')

implementation "net.kyori:adventure-platform-bukkit:4.2.0"
}

defaultTasks 'build'
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
import com.georgev22.skinoverlay.utilities.interfaces.SkinOverlayImpl;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.georgev22.skinoverlay.utilities.player.PlayerObjectBukkit;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftVersion.*;
import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftVersion.V1_16_R3;
import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftVersion.getCurrentVersion;

@MavenLibrary(groupId = "org.mongodb", artifactId = "mongo-java-driver", version = "3.12.7")
@MavenLibrary(groupId = "mysql", artifactId = "mysql-connector-java", version = "8.0.22")
Expand All @@ -39,6 +42,14 @@ public class SkinOverlayBukkit extends JavaPlugin implements SkinOverlayImpl {

private int tick = 0;

private BukkitAudiences adventure;

private static SkinOverlayBukkit skinOverlayBukkit;

public static SkinOverlayBukkit getInstance() {
return skinOverlayBukkit == null ? SkinOverlayBukkit.getPlugin(SkinOverlayBukkit.class) : skinOverlayBukkit;
}

@Override
public void onLoad() {
try {
Expand All @@ -52,6 +63,7 @@ public void onLoad() {
}

public void onEnable() {
this.adventure = BukkitAudiences.create(this);
Bukkit.getScheduler().runTaskTimer(this, () -> {
tick++;
SchedulerManager.getScheduler().mainThreadHeartbeat(tick);
Expand All @@ -78,6 +90,10 @@ public void onEnable() {
public void onDisable() {
SkinOverlay.getInstance().onDisable();
Bukkit.getScheduler().cancelTasks(this);
if(this.adventure != null) {
this.adventure.close();
this.adventure = null;
}
}


Expand Down Expand Up @@ -136,4 +152,11 @@ public Object serverImpl() {
public String serverVersion() {
return Bukkit.getBukkitVersion();
}

public @NotNull BukkitAudiences adventure() {
if(this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}
return this.adventure;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import com.georgev22.library.maps.ObjectMap;
import com.georgev22.library.minecraft.BukkitMinecraftUtils;
import com.georgev22.skinoverlay.SkinOverlayBukkit;
import net.kyori.adventure.audience.Audience;
import org.bukkit.OfflinePlayer;

public class PlayerObjectBukkit extends PlayerObject {
Expand All @@ -20,6 +22,11 @@ public OfflinePlayer player() {
return this.offlinePlayer;
}

@Override
public Audience audience() {
return SkinOverlayBukkit.getInstance().adventure().player(player().getPlayer());
}

@Override
public UUID playerUUID() {
return this.offlinePlayer.getUniqueId();
Expand Down
2 changes: 2 additions & 0 deletions bungee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ dependencies {

compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-proxy:1.19-R0.1-SNAPSHOT'

implementation "net.kyori:adventure-platform-bungeecord:4.2.0"
}

defaultTasks 'build'
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.georgev22.skinoverlay.utilities.player.PlayerObjectBungee;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
Expand Down Expand Up @@ -48,8 +49,17 @@ public class SkinOverlayBungee extends Plugin implements SkinOverlayImpl {

private boolean enabled = false;

private BungeeAudiences adventure;

private static SkinOverlayBungee skinOverlayBungee;

public static SkinOverlayBungee getInstance() {
return skinOverlayBungee;
}

@Override
public void onLoad() {
skinOverlayBungee = this;
try {
new LibraryLoader(this.getClass(), this.getDataFolder()).loadAll(true);
} catch (InvalidDependencyException | UnknownDependencyException e) {
Expand All @@ -60,6 +70,7 @@ public void onLoad() {

@Override
public void onEnable() {
this.adventure = BungeeAudiences.create(this);
getProxy().getScheduler().schedule(this, () -> SchedulerManager.getScheduler().mainThreadHeartbeat(tick++), 0, 50L, TimeUnit.MILLISECONDS);
SkinOverlay.getInstance().setSkinHandler(new SkinHandler() {
@Override
Expand Down Expand Up @@ -106,6 +117,11 @@ protected <T> GameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
@Override
public void onDisable() {
SkinOverlay.getInstance().onDisable();
getProxy().getScheduler().cancel(this);
if (this.adventure != null) {
this.adventure.close();
this.adventure = null;
}
enabled = false;
}

Expand Down Expand Up @@ -177,4 +193,11 @@ public ProxyServer serverImpl() {
public String serverVersion() {
return getProxy().getVersion();
}

public @NotNull BungeeAudiences adventure() {
if (this.adventure == null) {
throw new IllegalStateException("Cannot retrieve audience provider while plugin is not enabled");
}
return this.adventure;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import com.georgev22.library.maps.ObjectMap;
import com.georgev22.library.minecraft.BungeeMinecraftUtils;
import com.georgev22.skinoverlay.SkinOverlayBungee;
import net.kyori.adventure.audience.Audience;
import net.md_5.bungee.api.connection.ProxiedPlayer;

public class PlayerObjectBungee extends PlayerObject {
Expand All @@ -19,6 +21,11 @@ public ProxiedPlayer player() {
return this.proxiedPlayer;
}

@Override
public Audience audience() {
return SkinOverlayBungee.getInstance().adventure().player(this.proxiedPlayer);
}

@Override
public UUID playerUUID() {
return this.proxiedPlayer.getUniqueId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.georgev22.skinoverlay.utilities.interfaces.SkinOverlayImpl;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import net.kyori.adventure.audience.Audience;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

Expand All @@ -29,6 +30,8 @@ public PlayerObject playerObject() {

public abstract Object player();

public abstract Audience audience();

public abstract UUID playerUUID();

public abstract String playerName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public GameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
Player player = (Player) playerObject.player();
final CraftPlayer craftPlayer = (CraftPlayer) player;
final ServerPlayer entityPlayer = craftPlayer.getHandle();
return entityPlayer.gameProfile;
return entityPlayer.getGameProfile();
}

private void sendPacket(@NotNull ServerPlayer player, Packet<?> packet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.georgev22.library.maps.ObjectMap;
import com.georgev22.library.minecraft.Sponge8MinecraftUtils;
import net.kyori.adventure.audience.Audience;
import org.spongepowered.api.entity.living.player.User;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;

Expand All @@ -25,6 +26,11 @@ public ServerPlayer player() {
return user.player().orElseThrow();
}

@Override
public Audience audience() {
return player();
}

@Override
public UUID playerUUID() {
return user.uniqueId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public Player player() {
return user.getPlayer().orElseThrow();
}

@Override
public Audience audience() {
return SkinOverlaySponge7.getInstance().adventure().player(player());
return SkinOverlaySponge7.getInstance().adventure().player(user.getPlayer().orElseThrow());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ModInfo;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -198,7 +199,12 @@ public PlayerObjectVelocity(final Player player) {
}

@Override
public Object player() {
public Player player() {
return player;
}

@Override
public Audience audience() {
return player;
}

Expand Down

0 comments on commit 642dec8

Please sign in to comment.