Skip to content

Commit

Permalink
feat: Added SkinOverlayImpl#getServerImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeV220 committed Jan 7, 2023
1 parent f72d5d4 commit b143b2e
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ allprojects {
compileOnly 'co.aikar:acf-paper:0.5.1-SNAPSHOT'
compileOnly 'co.aikar:acf-bungee:0.5.1-SNAPSHOT'
compileOnly 'co.aikar:acf-velocity:0.5.1-SNAPSHOT'
compileOnly 'com.georgev22:martexlibrary:8.5.1'
compileOnly 'com.georgev22:martexlibrary:8.6.0'
compileOnly 'com.georgev22.api:libraryloader:1.3.0'
compileOnly 'org.jetbrains:annotations:23.1.0'
compileOnly 'commons-codec:commons-codec:1.15'
Expand Down Expand Up @@ -105,7 +105,7 @@ dependencies {
implementation 'co.aikar:acf-paper:0.5.1-SNAPSHOT'
implementation 'co.aikar:acf-bungee:0.5.1-SNAPSHOT'
implementation 'co.aikar:acf-velocity:0.5.1-SNAPSHOT'
implementation 'com.georgev22:martexlibrary:8.5.1'
implementation 'com.georgev22:martexlibrary:8.6.0'
implementation 'com.georgev22.api:libraryloader:1.3.0'
implementation project(path: ':core')
implementation project(path: ':bukkit')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ public List<PlayerObject> onlinePlayers() {
public Object getPlugin() {
return this;
}

@Override
public Object getServerImpl() {
return getServer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla
String skinName = in.readUTF();
PlayerObject playerObject = new PlayerObject.PlayerObjectWrapper(UUID.fromString(Objects.requireNonNull(uuid)), skinOverlay.type()).getPlayerObject();
if (subChannel.equalsIgnoreCase("change")) {
Utilities.setSkin(() -> ImageIO.read(new File(skinOverlay.getSkinsDataFolder(), skinName + ".png")), skinName, playerObject);
Utilities.setSkin(() -> ImageIO.read(new File(skinOverlay.getSkinsDataFolder(), skinName + ".png")), skinName, playerObject, null);
} else if (subChannel.equalsIgnoreCase("reset")) {
Utilities.setSkin(() -> null, skinName, playerObject);
Utilities.setSkin(() -> null, skinName, playerObject, null);
} else if (subChannel.equalsIgnoreCase("changeWithProperties")) {
String name = in.readUTF();
String value = in.readUTF();
Expand Down
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.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.connection.InitialHandler;
Expand Down Expand Up @@ -149,4 +150,9 @@ public List<PlayerObject> onlinePlayers() {
public Object getPlugin() {
return this;
}

@Override
public ProxyServer getServerImpl() {
return getProxy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void overlay(@NotNull CommandIssuer issuer, String @NotNull [] args) {
}
target = Optional.of(new PlayerObject.PlayerObjectWrapper(issuer.getUniqueId(), skinOverlay.type()).getPlayerObject());
}
Utilities.setSkin(() -> ImageIO.read(new File(skinOverlay.getSkinsDataFolder(), overlay + ".png")), overlay, new PlayerObject.PlayerObjectWrapper(target.get().playerUUID(), skinOverlay.type()).getPlayerObject());
Utilities.setSkin(() -> ImageIO.read(new File(skinOverlay.getSkinsDataFolder(), overlay + ".png")), overlay, new PlayerObject.PlayerObjectWrapper(target.get().playerUUID(), skinOverlay.type()).getPlayerObject(), issuer);
}

@Subcommand("clear")
Expand All @@ -151,7 +151,7 @@ public void clear(@NotNull CommandIssuer issuer, String[] args) {
return;
}
if (args.length == 0) {
Utilities.setSkin(() -> null, "default", new PlayerObject.PlayerObjectWrapper(issuer.getUniqueId(), skinOverlay.type()).getPlayerObject());
Utilities.setSkin(() -> null, "default", new PlayerObject.PlayerObjectWrapper(issuer.getUniqueId(), skinOverlay.type()).getPlayerObject(), issuer);
} else {
clear0(issuer, args[0]);
}
Expand All @@ -164,6 +164,6 @@ private void clear0(@NotNull CommandIssuer issuer, String target) {
MessagesUtil.OFFLINE_PLAYER.msg(issuer, new HashObjectMap<String, String>().append("%player%", target), true);
return;
}
Utilities.setSkin(() -> null, "default", new PlayerObject.PlayerObjectWrapper(optionalPlayerObject.get().playerUUID(), skinOverlay.type()).getPlayerObject());
Utilities.setSkin(() -> null, "default", new PlayerObject.PlayerObjectWrapper(optionalPlayerObject.get().playerUUID(), skinOverlay.type()).getPlayerObject(), issuer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import co.aikar.commands.CommandIssuer;
import com.georgev22.library.maps.HashObjectMap;
import com.georgev22.library.minecraft.BukkitMinecraftUtils;
import com.georgev22.library.minecraft.BungeeMinecraftUtils;
import com.georgev22.library.minecraft.VelocityMinecraftUtils;
import com.georgev22.library.utilities.Utils;
import com.georgev22.library.yaml.configmanager.CFG;
import com.georgev22.skinoverlay.SkinOverlay;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
Expand All @@ -18,6 +23,7 @@ public enum MessagesUtil {
ONLY_PLAYER_COMMAND("Messages.Only Player Command", "&c&l(!)&c Only players can run this command!"),
OFFLINE_PLAYER("Messages.Offline Player", "&c&l(!)&c Player %player% is offline!"),
DONE("Messages.Overlay Applied", "&a&l(!)&a Overlay %url% applied!"),
RESET("Messages.Overlay Reset", "&a&l(!)&a Default skin applied(%player%)!!"),
INSUFFICIENT_ARGUMENTS("Messages.Insufficient arguments", "&c&l(!)&c Insufficient arguments (%command%)");
private String[] messages;
private final String path;
Expand Down Expand Up @@ -93,6 +99,30 @@ public void msg(CommandIssuer issuer, Map<String, String> map, boolean ignoreCas
}
}

public void msgConsole() {
msgConsole(new HashMap<>(), false);
}

public void msgConsole(Map<String, String> map, boolean ignoreCase) {
if (this.isMultiLined()) {
switch (SkinOverlay.getInstance().type()) {
case PAPER ->
BukkitMinecraftUtils.printMsg(Utils.placeHolder(Arrays.stream(this.getMessages()).toList(), map, ignoreCase));
case BUNGEE ->
BungeeMinecraftUtils.printMsg(Utils.placeHolder(Arrays.stream(this.getMessages()).toList(), map, ignoreCase));
case VELOCITY ->
VelocityMinecraftUtils.printMsg((com.velocitypowered.api.proxy.ProxyServer) SkinOverlay.getInstance().getSkinOverlay().getServerImpl(), Utils.placeHolder(Arrays.stream(this.getMessages()).toList(), map, ignoreCase));
}
} else {
switch (SkinOverlay.getInstance().type()) {
case PAPER -> BukkitMinecraftUtils.printMsg(Utils.placeHolder(this.getMessages()[0], map, ignoreCase));
case BUNGEE -> BungeeMinecraftUtils.printMsg(Utils.placeHolder(this.getMessages()[0], map, ignoreCase));
case VELOCITY ->
VelocityMinecraftUtils.printMsg((com.velocitypowered.api.proxy.ProxyServer) SkinOverlay.getInstance().getSkinOverlay().getServerImpl(), Utils.placeHolder(this.getMessages()[0], map, ignoreCase));
}
}
}

public void msgAll() {
if (this.isMultiLined()) {
SkinOverlay.getInstance().getSkinOverlay().onlinePlayers().forEach(playerObject -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.georgev22.skinoverlay.utilities;

import co.aikar.commands.CommandIssuer;
import com.georgev22.library.maps.HashObjectMap;
import com.georgev22.library.maps.ObjectMap;
import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.library.utilities.Utils;
import com.georgev22.skinoverlay.SkinOverlay;
import com.georgev22.skinoverlay.handler.SkinHandler.Request;
import com.georgev22.skinoverlay.utilities.interfaces.ImageSupplier;
Expand All @@ -19,6 +19,7 @@
import com.mojang.authlib.properties.PropertyMap;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.imageio.ImageIO;
import java.awt.*;
Expand All @@ -43,7 +44,7 @@ public static void setSkin(String skinName, @NotNull PlayerObject playerObject,
updateSkin(playerObject, true, false);
}

public static void setSkin(ImageSupplier imageSupplier, String skinName, PlayerObject playerObject) {
public static void setSkin(ImageSupplier imageSupplier, String skinName, PlayerObject playerObject, @Nullable CommandIssuer commandIssuer) {
SchedulerManager.getScheduler().runTaskAsynchronously(skinOverlay.getClass(), () -> {
Image overlay;
try {
Expand All @@ -68,6 +69,11 @@ public static void setSkin(ImageSupplier imageSupplier, String skinName, PlayerO
userData.setSkinName(skinName);
userData.setProperty(new Property("textures", object.getAsJsonObject().get("value").getAsString(), object.getAsJsonObject().get("signature").getAsString()));
Utilities.updateSkin(playerObject, true, true);
if (commandIssuer == null) {
MessagesUtil.RESET.msgConsole(new HashObjectMap<String, String>().append("%player%", playerObject.playerName()), true);
} else {
MessagesUtil.RESET.msg(commandIssuer, new HashObjectMap<String, String>().append("%player%", playerObject.playerName()), true);
}
break;
}
String base64 = object.getAsJsonObject().get("value").getAsString();
Expand Down Expand Up @@ -96,7 +102,12 @@ public static void setSkin(ImageSupplier imageSupplier, String skinName, PlayerO
userData.setSkinName(skinName);
userData.setProperty(new Property("textures", texturesValue, texturesSignature));
Utilities.updateSkin(playerObject, true, false);
skinOverlay.getLogger().log(Level.INFO, Utils.placeHolder(MessagesUtil.DONE.getMessages()[0], new HashObjectMap<String, String>().append("%url%", texture.get("url").getAsString()), true));
if (commandIssuer == null) {
MessagesUtil.DONE.msgConsole(new HashObjectMap<String, String>().append("%player%", playerObject.playerName()).append("%url%", texture.get("url").getAsString()), true);
} else {
MessagesUtil.DONE.msg(commandIssuer, new HashObjectMap<String, String>().append("%player%", playerObject.playerName()).append("%url%", texture.get("url").getAsString()), true);
}

}
default ->
skinOverlay.getLogger().log(Level.SEVERE, "Unknown error code: " + request.getHttpCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface SkinOverlayImpl {

Object getPlugin();

Object getServerImpl();

record Description(String name, String version, String main, List<String> authors) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.georgev22.skinoverlay.SkinOverlay;
import com.georgev22.skinoverlay.utilities.interfaces.SkinOverlayImpl;
import com.velocitypowered.api.proxy.ProxyServer;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -43,11 +41,7 @@ public PlayerObject getPlayerObject() {
return new PlayerObjectBukkit(org.bukkit.Bukkit.getOfflinePlayer(this.uuid));
}
case VELOCITY -> {
try {
return new PlayerObjectVelocity(((ProxyServer) SkinOverlay.getInstance().getSkinOverlay().getPlugin().getClass().getMethod("getProxy").invoke(SkinOverlay.getInstance().getSkinOverlay().getPlugin())).getPlayer(this.uuid).get());
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
return new PlayerObjectVelocity(((com.velocitypowered.api.proxy.ProxyServer) SkinOverlay.getInstance().getSkinOverlay().getServerImpl()).getPlayer(this.uuid).get());
}
default -> {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,9 @@ public ProxyServer getProxy() {
public Object getPlugin() {
return this;
}

@Override
public ProxyServer getServerImpl() {
return server;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.georgev22.skinoverlay.SkinOverlayVelocity;
import com.georgev22.skinoverlay.utilities.Utilities;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.georgev22.skinoverlay.utilities.player.PlayerObjectVelocity;
import com.georgev22.skinoverlay.utilities.player.UserData;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
Expand Down Expand Up @@ -61,7 +62,8 @@ public Boolean onSuccess() {

@Subscribe
public void onQuit(DisconnectEvent playerDisconnectEvent) {
PlayerObject playerObject = new PlayerObject.PlayerObjectWrapper(playerDisconnectEvent.getPlayer().getUniqueId(), this.skinOverlay.type()).getPlayerObject();
//Wrapper won't work here
PlayerObject playerObject = new PlayerObjectVelocity(playerDisconnectEvent.getPlayer());
final UserData userData = UserData.getUser(playerObject);
userData.save(true, new Utils.Callback<>() {

Expand Down

0 comments on commit b143b2e

Please sign in to comment.