-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
505 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
core/src/main/java/com/georgev22/skinoverlay/utilities/VelocityPluginMessageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.georgev22.skinoverlay.utilities; | ||
|
||
import com.google.common.io.ByteArrayDataOutput; | ||
import com.google.common.io.ByteStreams; | ||
import com.velocitypowered.api.proxy.Player; | ||
import com.velocitypowered.api.proxy.ProxyServer; | ||
import com.velocitypowered.api.proxy.server.RegisteredServer; | ||
import com.velocitypowered.api.proxy.server.ServerInfo; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class VelocityPluginMessageUtils { | ||
|
||
public void sendDataToServer(@NotNull ProxyServer proxyServer, @NotNull ServerInfo serverInfo, @NotNull String channel, String... dataArray) { | ||
if (proxyServer.getServer(serverInfo.getName()).isPresent()) { | ||
proxyServer.getServer(serverInfo.getName()).get().sendPluginMessage(() -> "skinoverlay:bungee", this.toByteArray(channel, dataArray)); | ||
} | ||
} | ||
|
||
public void sendDataTooAllServers(@NotNull ProxyServer proxyServer, @NotNull String channel, String... dataArray) { | ||
proxyServer.getAllServers().forEach(registeredServer -> this.sendDataToServer(proxyServer, registeredServer.getServerInfo(), channel, dataArray)); | ||
} | ||
|
||
public void sendDataToPlayer(@NotNull String channel, @NotNull Player player, String... dataArray) { | ||
player.sendPluginMessage(() -> "skinoverlay:bungee", this.toByteArray(channel, dataArray)); | ||
} | ||
|
||
public void sendDataToAllPlayers(ProxyServer proxyServer, @NotNull String channel, String... dataArray) { | ||
proxyServer.getAllPlayers().forEach(player -> this.sendDataToPlayer(channel, player, dataArray)); | ||
} | ||
|
||
@NotNull | ||
public ByteArrayDataOutput byteArrayDataOutput(@NotNull String channel, String @NotNull ... dataArray) { | ||
ByteArrayDataOutput out = ByteStreams.newDataOutput(); | ||
out.writeUTF(channel); | ||
for (String data : dataArray) { | ||
out.writeUTF(data); | ||
} | ||
return out; | ||
} | ||
|
||
public byte @NotNull [] toByteArray(@NotNull String channel, String... dataArray) { | ||
return this.byteArrayDataOutput(channel, dataArray).toByteArray(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
core/src/main/java/com/georgev22/skinoverlay/utilities/player/PlayerObjectVelocity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.georgev22.skinoverlay.utilities.player; | ||
|
||
import com.georgev22.library.minecraft.VelocityMinecraftUtils; | ||
import com.velocitypowered.api.proxy.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class PlayerObjectVelocity implements PlayerObject { | ||
|
||
private final Player player; | ||
|
||
public PlayerObjectVelocity(final Player player) { | ||
this.player = player; | ||
} | ||
|
||
@Override | ||
public Object getPlayer() { | ||
return player; | ||
} | ||
|
||
@Override | ||
public UUID playerUUID() { | ||
return player.getUniqueId(); | ||
} | ||
|
||
@Override | ||
public String playerName() { | ||
return player.getUsername(); | ||
} | ||
|
||
@Override | ||
public void sendMessage(String input) { | ||
VelocityMinecraftUtils.msg(player, input); | ||
} | ||
|
||
@Override | ||
public void sendMessage(@NotNull List<String> input) { | ||
VelocityMinecraftUtils.msg(player, input); | ||
} | ||
|
||
@Override | ||
public void sendMessage(String @NotNull ... input) { | ||
VelocityMinecraftUtils.msg(player, input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ include 'mc-1-19' | |
include 'mc-1-19-3' | ||
include 'mc-1-17' | ||
include 'bungee' | ||
include 'velocity' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
dependencies { | ||
compileOnly project(path: ':core') | ||
|
||
annotationProcessor 'com.velocitypowered:velocity-api:3.1.1' | ||
} | ||
|
||
blossom { | ||
var constants = "src/main/java/com/georgev22/skinoverlay/SkinOverlayVelocity.java" | ||
replaceToken('${version}', this.version, constants) | ||
replaceToken('${pluginName}', this.pluginName, constants) | ||
replaceToken('${author}', this.author, constants) | ||
} |
211 changes: 211 additions & 0 deletions
211
velocity/src/main/java/com/georgev22/skinoverlay/SkinOverlayVelocity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
package com.georgev22.skinoverlay; | ||
|
||
import co.aikar.commands.VelocityCommandManager; | ||
import com.georgev22.api.libraryloader.LibraryLoader; | ||
import com.georgev22.api.libraryloader.annotations.MavenLibrary; | ||
import com.georgev22.api.libraryloader.exceptions.InvalidDependencyException; | ||
import com.georgev22.api.libraryloader.exceptions.UnknownDependencyException; | ||
import com.georgev22.library.scheduler.SchedulerManager; | ||
import com.georgev22.library.utilities.Utils; | ||
import com.georgev22.library.yaml.file.FileConfiguration; | ||
import com.georgev22.skinoverlay.handler.SkinHandler; | ||
import com.georgev22.skinoverlay.listeners.velocity.DeveloperInformListener; | ||
import com.georgev22.skinoverlay.listeners.velocity.PlayerListeners; | ||
import com.georgev22.skinoverlay.utilities.VelocityPluginMessageUtils; | ||
import com.georgev22.skinoverlay.utilities.interfaces.SkinOverlayImpl; | ||
import com.georgev22.skinoverlay.utilities.player.PlayerObject; | ||
import com.georgev22.skinoverlay.utilities.player.PlayerObjectVelocity; | ||
import com.google.common.collect.Lists; | ||
import com.google.inject.Inject; | ||
import com.mojang.authlib.GameProfile; | ||
import com.mojang.authlib.properties.Property; | ||
import com.velocitypowered.api.event.Subscribe; | ||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; | ||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; | ||
import com.velocitypowered.api.plugin.Plugin; | ||
import com.velocitypowered.api.plugin.annotation.DataDirectory; | ||
import com.velocitypowered.api.proxy.Player; | ||
import com.velocitypowered.api.proxy.ProxyServer; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.time.Duration; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.logging.Logger; | ||
|
||
@MavenLibrary(groupId = "org.mongodb", artifactId = "mongo-java-driver", version = "3.12.7") | ||
@MavenLibrary(groupId = "mysql", artifactId = "mysql-connector-java", version = "8.0.22") | ||
@MavenLibrary(groupId = "org.xerial", artifactId = "sqlite-jdbc", version = "3.34.0") | ||
@MavenLibrary(groupId = "com.google.guava", artifactId = "guava", version = "30.1.1-jre") | ||
@MavenLibrary(groupId = "org.postgresql", artifactId = "postgresql", version = "42.2.18") | ||
@MavenLibrary(groupId = "commons-io", artifactId = "commons-io", version = "2.11.0") | ||
@MavenLibrary(groupId = "commons-codec", artifactId = "commons-codec", version = "1.15") | ||
@MavenLibrary(groupId = "commons-lang", artifactId = "commons-lang", version = "2.6") | ||
@MavenLibrary("com.mojang:authlib:3.11.50:https://nexus.velocitypowered.com/repository/maven-public/") | ||
@Plugin(id = "skinoverlay", name = "${pluginName}", version = "${version}", description = "SkinOverlay", authors = {"${author}"}) | ||
public class SkinOverlayVelocity implements SkinOverlayImpl { | ||
|
||
private final ProxyServer server; | ||
private final Logger logger; | ||
|
||
private final Path dataDirectory; | ||
|
||
private final File dataFolder; | ||
|
||
private final Plugin pluginAnnotation; | ||
private int tick = 0; | ||
|
||
private boolean enabled = false; | ||
|
||
private static SkinOverlayVelocity instance; | ||
|
||
public static SkinOverlayVelocity getInstance() { | ||
return instance; | ||
} | ||
|
||
@Contract(pure = true) | ||
@Inject | ||
public SkinOverlayVelocity(@NotNull ProxyServer server, @NotNull Logger logger, @DataDirectory @NotNull Path dataDirectory) { | ||
instance = this; | ||
this.server = server; | ||
this.logger = logger; | ||
this.dataDirectory = dataDirectory; | ||
this.dataFolder = dataDirectory.toFile(); | ||
this.pluginAnnotation = this.getClass().getAnnotation(Plugin.class); | ||
} | ||
|
||
@Subscribe | ||
public void onProxyInitialization(ProxyInitializeEvent event) { | ||
onLoad(); | ||
} | ||
|
||
@Subscribe | ||
public void onProxyShutdown(ProxyShutdownEvent event) { | ||
onDisable(); | ||
} | ||
|
||
public void onLoad() { | ||
try { | ||
new LibraryLoader(this.getClass(), this.getDataFolder()).loadAll(); | ||
} catch (InvalidDependencyException | UnknownDependencyException e) { | ||
throw new RuntimeException(e); | ||
} | ||
SkinOverlay.getInstance().onLoad(this); | ||
onEnable(); | ||
} | ||
|
||
public void onEnable() { | ||
getProxy().getScheduler().buildTask(this, () -> SchedulerManager.getScheduler().mainThreadHeartbeat(tick++)).repeat(Duration.ofMillis(50L)).schedule(); | ||
SkinOverlay.getInstance().setCommandManager(new VelocityCommandManager(getProxy(), this)); | ||
SkinOverlay.getInstance().setSkinHandler(new SkinHandler() { | ||
@Override | ||
public void updateSkin(@NotNull FileConfiguration fileConfiguration, @NotNull PlayerObject playerObject, boolean reset, @NotNull String skinName) { | ||
if (reset) { | ||
new VelocityPluginMessageUtils().sendDataTooAllServers(getProxy(), "reset", playerObject.playerUUID().toString(), "default"); | ||
} else { | ||
new VelocityPluginMessageUtils().sendDataTooAllServers(getProxy(), "change", playerObject.playerUUID().toString(), skinName); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateSkin(@NotNull FileConfiguration fileConfiguration, @NotNull PlayerObject playerObject, boolean reset, @NotNull String skinName, Property property) { | ||
if (reset) { | ||
new VelocityPluginMessageUtils().sendDataTooAllServers(getProxy(), "resetWithProperties", playerObject.playerUUID().toString(), "default", property.getName(), property.getValue(), property.getSignature()); | ||
} else { | ||
new VelocityPluginMessageUtils().sendDataTooAllServers(getProxy(), "changeWithProperties", playerObject.playerUUID().toString(), skinName, property.getName(), property.getValue(), property.getSignature()); | ||
} | ||
} | ||
|
||
@Override | ||
protected <T> GameProfile getGameProfile0(@NotNull PlayerObject playerObject) { | ||
GameProfile gameProfile = new GameProfile(playerObject.playerUUID(), playerObject.playerName()); | ||
for (com.velocitypowered.api.util.GameProfile.Property property : ((Player) playerObject.getPlayer()).getGameProfile().getProperties()) { | ||
gameProfile.getProperties().put(property.getName(), new Property(property.getName(), property.getValue(), property.getSignature())); | ||
} | ||
return gameProfile; | ||
} | ||
}); | ||
SkinOverlay.getInstance().onEnable(); | ||
//BungeeMinecraftUtils.registerListeners(this, new PlayerListeners(), new DeveloperInformListener()); | ||
getProxy().getEventManager().register(this, new DeveloperInformListener()); | ||
getProxy().getEventManager().register(this, new PlayerListeners()); | ||
enabled = true; | ||
} | ||
|
||
public void onDisable() { | ||
SkinOverlay.getInstance().onDisable(); | ||
enabled = false; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.VELOCITY; | ||
} | ||
|
||
public File getDataFolder() { | ||
return dataFolder; | ||
} | ||
|
||
public Logger getLogger() { | ||
return logger; | ||
} | ||
|
||
@Override | ||
public Description description() { | ||
return new Description(pluginAnnotation.name(), pluginAnnotation.version(), this.getClass().getCanonicalName(), Arrays.stream(pluginAnnotation.authors()).toList()); | ||
} | ||
|
||
@Override | ||
public boolean setEnable(boolean enable) { | ||
if (enable) { | ||
onEnable(); | ||
} else { | ||
onDisable(); | ||
} | ||
return isEnabled(); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public void saveResource(@NotNull String resource, boolean replace) { | ||
try { | ||
Utils.saveResource(resource, replace, getDataFolder(), this.getClass()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isOnlineMode() { | ||
return server.getConfiguration().isOnlineMode(); | ||
} | ||
|
||
@Override | ||
public List<PlayerObject> onlinePlayers() { | ||
List<PlayerObject> playerObjects = Lists.newArrayList(); | ||
for (Player player : server.getAllPlayers()) { | ||
playerObjects.add(new PlayerObjectVelocity(player)); | ||
} | ||
return playerObjects; | ||
} | ||
|
||
public Path getDataDirectory() { | ||
return dataDirectory; | ||
} | ||
|
||
public ProxyServer getProxy() { | ||
return server; | ||
} | ||
|
||
@Override | ||
public Object getPlugin() { | ||
return this; | ||
} | ||
} |
Oops, something went wrong.