Skip to content

Commit

Permalink
feat: A lot of internal changes
Browse files Browse the repository at this point in the history
Added SGameProfile and SProperty to represent the different classes that each implementation use (Mojang GameProfile, Velocity GameProfile, etc).
Moved SkinHandler_ to SkinHandler_Unsupported
Updated Velocity to 3.2.0
Added PlayerObject#internalGameProfile
Changed SkinHandler#getGameProfile0 from private to public abstract
  • Loading branch information
GeorgeV220 committed Apr 2, 2023
1 parent 3a68882 commit 06d9a67
Show file tree
Hide file tree
Showing 24 changed files with 662 additions and 155 deletions.
Expand Up @@ -7,7 +7,6 @@
import com.georgev22.api.libraryloader.exceptions.UnknownDependencyException;
import com.georgev22.library.minecraft.BukkitMinecraftUtils;
import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.skinoverlay.handler.SkinHandler.SkinHandler_;
import com.georgev22.skinoverlay.handler.handlers.*;
import com.georgev22.skinoverlay.hook.hooks.SkinsRestorerHook;
import com.georgev22.skinoverlay.listeners.bukkit.DeveloperInformListener;
Expand Down Expand Up @@ -77,7 +76,7 @@ public void onEnable() {
case V1_19_R1 -> SkinOverlay.getInstance().setSkinHandler(new SkinHandler_1_19());
case V1_19_R2 -> SkinOverlay.getInstance().setSkinHandler(new SkinHandler_1_19_R2());
case V1_19_R3 -> SkinOverlay.getInstance().setSkinHandler(new SkinHandler_1_19_R3());
case UNKNOWN -> SkinOverlay.getInstance().setSkinHandler(new SkinHandler_());
case UNKNOWN -> SkinOverlay.getInstance().setSkinHandler(new SkinHandler_Unsupported());
default -> SkinOverlay.getInstance().setSkinHandler(new SkinHandler_Legacy());
}
switch (OptionsUtil.SKIN_HOOK.getStringValue()) {
Expand Down
Expand Up @@ -4,13 +4,13 @@
import com.georgev22.library.minecraft.BukkitMinecraftUtils;
import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.library.utilities.Utils;
import com.georgev22.skinoverlay.handler.SkinHandler.SkinHandler_;
import com.georgev22.skinoverlay.handler.SGameProfile;
import com.georgev22.skinoverlay.handler.SProperty;
import com.georgev22.skinoverlay.utilities.SkinOptions;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -29,7 +29,7 @@
import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftReflection.getOBCClass;
import static com.georgev22.library.utilities.Utils.Reflection.*;

public class SkinHandler_Legacy extends SkinHandler_ {
public class SkinHandler_Legacy extends SkinHandler_Unsupported {
private final Class<?> playOutRespawn;
private final Class<?> playOutPlayerInfo;
private final Class<?> playOutPosition;
Expand Down Expand Up @@ -282,12 +282,12 @@ public void updateSkin(@NotNull PlayerObject playerObject, @NotNull SkinOptions
}

@Override
public void updateSkin(@NotNull PlayerObject playerObject, @NotNull SkinOptions skinOptions, Property property, Utils.@NotNull Callback<Boolean> callback) {
public void updateSkin(@NotNull PlayerObject playerObject, @NotNull SkinOptions skinOptions, SProperty property, Utils.@NotNull Callback<Boolean> callback) {
updateSkin(playerObject, skinOptions, callback);
}

@Override
protected <T> GameProfile getGameProfile0(@NotNull PlayerObject playerObject) throws IOException, ExecutionException, InterruptedException {
public GameProfile getGameProfile0(@NotNull PlayerObject playerObject) throws IOException, ExecutionException, InterruptedException {
try {
Class<?> craftPlayerClass = getOBCClass("entity.CraftPlayer");
org.bukkit.entity.Player player = (org.bukkit.entity.Player) playerObject.player();
Expand All @@ -297,6 +297,14 @@ protected <T> GameProfile getGameProfile0(@NotNull PlayerObject playerObject) th
}
}

@Override
public SGameProfile getGameProfile(@NotNull PlayerObject playerObject) throws IOException, ExecutionException, InterruptedException {
if (sGameProfiles.containsKey(playerObject)) {
return sGameProfiles.get(playerObject);
}
return sGameProfiles.append(playerObject, wrapper(this.getGameProfile0(playerObject))).get(playerObject);
}

private void sendPacket(Object playerConnection, Object packet) throws ReflectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
fetchMethodAndInvoke(playerConnection.getClass(), "sendPacket", playerConnection, new Object[]{packet}, new Class<?>[]{this.packet});
}
Expand Down
Expand Up @@ -8,7 +8,10 @@
import com.georgev22.library.minecraft.BungeeMinecraftUtils;
import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.library.utilities.Utils;
import com.georgev22.skinoverlay.handler.SGameProfile;
import com.georgev22.skinoverlay.handler.SProperty;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.handler.profile.SGameProfileBungee;
import com.georgev22.skinoverlay.hook.hooks.SkinsRestorerHook;
import com.georgev22.skinoverlay.listeners.bungee.DeveloperInformListener;
import com.georgev22.skinoverlay.listeners.bungee.PlayerListeners;
Expand All @@ -19,13 +22,12 @@
import com.georgev22.skinoverlay.utilities.interfaces.SkinOverlayImpl;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
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;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.protocol.Property;
import org.bstats.bungeecord.Metrics;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -91,12 +93,12 @@ public void updateSkin(@NotNull PlayerObject playerObject, @NotNull SkinOptions
}

@Override
public void updateSkin(@NotNull PlayerObject playerObject, @NotNull SkinOptions skinOptions, Property property, Utils.@NotNull Callback<Boolean> callback) {
public void updateSkin(@NotNull PlayerObject playerObject, @NotNull SkinOptions skinOptions, SProperty property, Utils.@NotNull Callback<Boolean> callback) {
try {
if (skinOptions.getSkinName().equalsIgnoreCase("default")) {
new BungeeCordPluginMessageUtils().sendDataTooAllServers("resetWithProperties", playerObject.playerUUID().toString(), Utilities.skinOptionsToBytes(skinOptions), property.getName(), property.getValue(), property.getSignature());
new BungeeCordPluginMessageUtils().sendDataTooAllServers("resetWithProperties", playerObject.playerUUID().toString(), Utilities.skinOptionsToBytes(skinOptions), property.name(), property.value(), property.signature());
} else {
new BungeeCordPluginMessageUtils().sendDataTooAllServers("changeWithProperties", playerObject.playerUUID().toString(), Utilities.skinOptionsToBytes(skinOptions), property.getName(), property.getValue(), property.getSignature());
new BungeeCordPluginMessageUtils().sendDataTooAllServers("changeWithProperties", playerObject.playerUUID().toString(), Utilities.skinOptionsToBytes(skinOptions), property.name(), property.value(), property.signature());
}
callback.onSuccess();
} catch (Exception exception) {
Expand All @@ -105,15 +107,23 @@ public void updateSkin(@NotNull PlayerObject playerObject, @NotNull SkinOptions
}

@Override
protected <T> GameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
GameProfile gameProfile = new GameProfile(playerObject.playerUUID(), playerObject.playerName());
public SGameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
SGameProfile gameProfile = new SGameProfileBungee(playerObject.playerName(), playerObject.playerUUID());
if (!gameProfile.getProperties().containsKey("textures")) {
for (net.md_5.bungee.protocol.Property property : ((InitialHandler) ((ProxiedPlayer) playerObject.player()).getPendingConnection()).getLoginProfile().getProperties()) {
gameProfile.getProperties().put(property.getName(), new Property(property.getName(), property.getValue(), property.getSignature()));
for (Property property : ((InitialHandler) ((ProxiedPlayer) playerObject.player()).getPendingConnection()).getLoginProfile().getProperties()) {
gameProfile.addProperty(property.getName(), new SProperty(property.getName(), property.getValue(), property.getSignature()));
}
}
return gameProfile;
}

@Override
public SGameProfile getGameProfile(@NotNull PlayerObject playerObject) {
if (sGameProfiles.containsKey(playerObject)) {
return sGameProfiles.get(playerObject);
}
return sGameProfiles.append(playerObject, this.getGameProfile0(playerObject)).get(playerObject);
}
});
switch (OptionsUtil.SKIN_HOOK.getStringValue()) {
case "SkinsRestorer" -> {
Expand Down
@@ -0,0 +1,47 @@
package com.georgev22.skinoverlay.handler.profile;

import com.georgev22.library.maps.HashObjectMap;
import com.georgev22.library.maps.ObjectMap;
import com.georgev22.skinoverlay.SkinOverlay;
import com.georgev22.skinoverlay.handler.SGameProfile;
import com.georgev22.skinoverlay.handler.SProperty;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.connection.LoginResult;
import net.md_5.bungee.protocol.Property;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class SGameProfileBungee extends SGameProfile {

private final String name;
private final UUID uuid;
private final ObjectMap<String, SProperty> properties;
private final SkinOverlay skinOverlay = SkinOverlay.getInstance();

public SGameProfileBungee(String name, UUID uuid) {
super(name, uuid);
this.name = name;
this.uuid = uuid;
this.properties = new HashObjectMap<>();
}

public SGameProfileBungee(String name, UUID uuid, ObjectMap<String, SProperty> properties) {
super(name, uuid, properties);
this.name = name;
this.uuid = uuid;
this.properties = properties;
}

@Override
public void apply() {
PlayerObject playerObject = skinOverlay.getPlayer(uuid).orElseThrow();
LoginResult initialHandler = ((InitialHandler) ((ProxiedPlayer) playerObject.player()).getPendingConnection()).getLoginProfile();
List<Property> bungeeProperties = new ArrayList<>();
this.properties.forEach((s, sProperty) -> bungeeProperties.add(new Property(sProperty.name(), sProperty.value(), sProperty.value())));
initialHandler.setProperties(bungeeProperties.toArray(Property[]::new));
}
}
119 changes: 119 additions & 0 deletions core/src/main/java/com/georgev22/skinoverlay/handler/SGameProfile.java
@@ -0,0 +1,119 @@
package com.georgev22.skinoverlay.handler;

import com.georgev22.library.maps.HashObjectMap;
import com.georgev22.library.maps.ObjectMap;
import com.georgev22.library.maps.UnmodifiableObjectMap;
import org.jetbrains.annotations.UnmodifiableView;

import java.util.UUID;

/**
* The SGameProfile class represents a simplified version of a GameProfile, containing a player's name, UUID, and properties.
*/
public abstract class SGameProfile {

/**
* The player's name.
*/
private final String name;

/**
* The player's UUID.
*/
private final UUID uuid;

/**
* The player's properties.
*/
private final ObjectMap<String, SProperty> properties;

/**
* Constructs an {@link SGameProfile} object with the specified name and UUID, and an empty properties map.
*
* @param name the player's name
* @param uuid the player's UUID
*/
public SGameProfile(String name, UUID uuid) {
this.name = name;
this.uuid = uuid;
this.properties = new HashObjectMap<>();
}

/**
* Constructs an {@link SGameProfile} object with the specified name, UUID, and properties map.
*
* @param name the player's name
* @param uuid the player's UUID
* @param properties the player's properties map
*/
public SGameProfile(String name, UUID uuid, ObjectMap<String, SProperty> properties) {
this.name = name;
this.uuid = uuid;
this.properties = properties;
}

/**
* Returns the player's name.
*
* @return the player's name
*/
public String getName() {
return name;
}

/**
* Returns the player's UUID.
*
* @return the player's UUID
*/
public UUID getUUID() {
return uuid;
}

/**
* Returns an unmodifiable view of the player's properties map.
*
* @return an unmodifiable view of the player's properties map
*/
@UnmodifiableView
public UnmodifiableObjectMap<String, SProperty> getProperties() {
return new UnmodifiableObjectMap<>(properties);
}

/**
* Adds a property to the player's properties map.
*
* @param propertyName the name of the property to add
* @param sProperty the {@link SProperty} object representing the property to add
* @return this {@link SGameProfile} object
*/
public SGameProfile addProperty(String propertyName, SProperty sProperty) {
this.properties.append(propertyName, sProperty);
this.apply();
return this;
}

/**
* Removes a property from the player's properties map.
*
* @param propertyName the name of the property to remove
* @return this {@link SGameProfile} object
*/
public SGameProfile removeProperty(String propertyName) {
this.properties.remove(propertyName);
this.apply();
return this;
}

/**
* Returns the {@link SProperty} associated with the specified property name.
*
* @param propertyName the name of the property to retrieve
* @return the {@code SProperty} object associated with the given property name
*/
public SProperty getProperty(String propertyName) {
return this.properties.get(propertyName);
}

public abstract void apply();
}
@@ -0,0 +1,5 @@
package com.georgev22.skinoverlay.handler;

public record SProperty(String name, String value, String signature) {

}

0 comments on commit 06d9a67

Please sign in to comment.