Skip to content

Commit

Permalink
feat: Implement the new changes of SkinHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeV220 committed Jun 11, 2023
1 parent 3912014 commit 43935d4
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.skinoverlay.handler.SGameProfile;
import com.georgev22.skinoverlay.handler.Skin;
import com.georgev22.skinoverlay.utilities.player.User;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing;
Expand All @@ -27,7 +26,8 @@

import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftReflection.getNMSClass;
import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftReflection.getOBCClass;
import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftVersion.*;
import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftVersion.V1_16_R1;
import static com.georgev22.library.minecraft.BukkitMinecraftUtils.MinecraftVersion.getCurrentVersion;
import static com.georgev22.library.utilities.Utils.Reflection.*;

@ApiStatus.Internal
Expand Down Expand Up @@ -288,13 +288,36 @@ public CompletableFuture<Boolean> updateSkin(@NotNull PlayerObject playerObject,
}

@Override
public GameProfile getGameProfile0(@NotNull PlayerObject playerObject) throws IOException, ExecutionException, InterruptedException {
public void applySkin(@NotNull PlayerObject playerObject, @NotNull Skin skin) {
SchedulerManager.getScheduler().runTaskLater(skinOverlay.getClass(), () -> {
Player player = (Player) playerObject.player();
player.hidePlayer(player);
player.showPlayer(player);
skinOverlay.getSkinHandler().updateSkin(playerObject, skin).handleAsync((aBoolean, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
return false;
}
return aBoolean;
}).thenAccept(aBoolean -> SchedulerManager.getScheduler().runTask(skinOverlay.getClass(), () -> {
if (aBoolean)
skinOverlay.onlinePlayers().stream().filter(playerObjects -> playerObjects != playerObject).forEach(playerObjects -> {
Player p = (Player) playerObjects.player();
p.hidePlayer(player);
p.showPlayer(player);
});
}));
}, 20L);
}

@Override
public GameProfile getInternalGameProfile(@NotNull PlayerObject playerObject) throws IOException, ExecutionException, InterruptedException {
try {
Class<?> craftPlayerClass = getOBCClass("entity.CraftPlayer");
org.bukkit.entity.Player player = (org.bukkit.entity.Player) playerObject.player();
return (GameProfile) fetchMethodAndInvoke(craftPlayerClass, "getProfile", player, new Object[]{}, new Class[]{});
} catch (Exception e) {
return super.getGameProfile0(playerObject);
return super.getInternalGameProfile(playerObject);
}
}

Expand All @@ -303,35 +326,10 @@ public SGameProfile getGameProfile(@NotNull PlayerObject playerObject) throws IO
if (sGameProfiles.containsKey(playerObject)) {
return sGameProfiles.get(playerObject);
}
return sGameProfiles.append(playerObject, wrapper(this.getGameProfile0(playerObject))).get(playerObject);
return sGameProfiles.append(playerObject, wrapper(this.getInternalGameProfile(playerObject))).get(playerObject);
}

private void sendPacket(Object playerConnection, Object packet) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
fetchMethodAndInvoke(playerConnection.getClass(), "sendPacket", playerConnection, new Object[]{packet}, new Class<?>[]{this.packet});
}

@Override
protected void updateSkin0(User user, PlayerObject playerObject, boolean forOthers) {
SchedulerManager.getScheduler().runTaskLater(skinOverlay.getClass(), () -> {
Player player = (Player) playerObject.player();
player.hidePlayer(player);
player.showPlayer(player);
skinOverlay.getSkinHandler().updateSkin(playerObject, user.skin()).handleAsync((aBoolean, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
return false;
}
return aBoolean;
}).thenAccept(aBoolean -> SchedulerManager.getScheduler().runTask(skinOverlay.getClass(), () -> {
if (aBoolean)
if (forOthers) {
skinOverlay.onlinePlayers().stream().filter(playerObjects -> playerObjects != playerObject).forEach(playerObjects -> {
Player p = (Player) playerObjects.player();
p.hidePlayer(player);
p.showPlayer(player);
});
}
}));
}, 20L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.georgev22.skinoverlay.handler.Skin;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.handler.profile.SGameProfileBungee;
import com.georgev22.skinoverlay.utilities.player.User;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.connection.InitialHandler;
Expand Down Expand Up @@ -42,7 +41,18 @@ public CompletableFuture<Boolean> updateSkin(@NotNull PlayerObject playerObject,
}

@Override
public SGameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
public void applySkin(@NotNull PlayerObject playerObject, @NotNull Skin skin) {
skinOverlay.getSkinHandler().updateSkin(playerObject, skin).handleAsync((aBoolean, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
return false;
}
return aBoolean;
});
}

@Override
public SGameProfile getInternalGameProfile(@NotNull PlayerObject playerObject) {
ObjectMap<String, SProperty> properties = new HashObjectMap<>();
for (Property property : ((InitialHandler) ((ProxiedPlayer) playerObject.player()).getPendingConnection()).getLoginProfile().getProperties()) {
properties.append(property.getName(), new SProperty(property.getName(), property.getValue(), property.getSignature()));
Expand All @@ -55,11 +65,6 @@ public SGameProfile getGameProfile(@NotNull PlayerObject playerObject) {
if (sGameProfiles.containsKey(playerObject)) {
return sGameProfiles.get(playerObject);
}
return sGameProfiles.append(playerObject, this.getGameProfile0(playerObject)).get(playerObject);
}

@Override
protected void updateSkin0(User user, PlayerObject playerObject, boolean forOthers) {
updateSkin1(user, playerObject, forOthers);
return sGameProfiles.append(playerObject, this.getInternalGameProfile(playerObject)).get(playerObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.georgev22.skinoverlay.handler.Skin;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.handler.profile.SGameProfileMojang;
import com.georgev22.skinoverlay.utilities.player.User;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
Expand All @@ -30,7 +29,18 @@ public CompletableFuture<Boolean> updateSkin(@NotNull PlayerObject playerObject,
}

@Override
public GameProfile getGameProfile0(@NotNull PlayerObject playerObject) throws IOException, ExecutionException, InterruptedException {
public void applySkin(@NotNull PlayerObject playerObject, @NotNull Skin skin) {
skinOverlay.getSkinHandler().updateSkin(playerObject, skin).handleAsync((aBoolean, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
return false;
}
return aBoolean;
});
}

@Override
public GameProfile getInternalGameProfile(@NotNull PlayerObject playerObject) throws IOException, ExecutionException, InterruptedException {
GameProfile gameProfile = new GameProfile(playerObject.playerUUID(), playerObject.playerName());
if (!gameProfile.getProperties().containsKey("textures")) {
SProperty property = getSkin(playerObject);
Expand All @@ -44,17 +54,12 @@ public SGameProfile getGameProfile(@NotNull PlayerObject playerObject) throws IO
if (sGameProfiles.containsKey(playerObject)) {
return sGameProfiles.get(playerObject);
}
return sGameProfiles.append(playerObject, wrapper(this.getGameProfile0(playerObject))).get(playerObject);
return sGameProfiles.append(playerObject, wrapper(this.getInternalGameProfile(playerObject))).get(playerObject);
}

public static @NotNull SGameProfile wrapper(@NotNull GameProfile gameProfile) {
ObjectMap<String, SProperty> propertyObjectMap = new HashObjectMap<>();
gameProfile.getProperties().forEach((s, property) -> propertyObjectMap.append(s, new SProperty(property.getName(), property.getValue(), property.getSignature())));
return new SGameProfileMojang(gameProfile.getName(), gameProfile.getId(), propertyObjectMap);
}

@Override
protected void updateSkin0(User user, PlayerObject playerObject, boolean forOthers) {
updateSkin1(user, playerObject, forOthers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.georgev22.skinoverlay.handler.SGameProfile;
import com.georgev22.skinoverlay.handler.Skin;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.utilities.player.User;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.google.common.collect.ImmutableList;
import com.mojang.authlib.GameProfile;
Expand Down Expand Up @@ -89,7 +88,7 @@ public CompletableFuture<Boolean> updateSkin(@NotNull PlayerObject playerObject,
}

@Override
public GameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
public @NotNull GameProfile getInternalGameProfile(@NotNull PlayerObject playerObject) {
Player player = (Player) playerObject.player();
final CraftPlayer craftPlayer = (CraftPlayer) player;
final ServerPlayer entityPlayer = craftPlayer.getHandle();
Expand All @@ -101,34 +100,32 @@ public SGameProfile getGameProfile(@NotNull PlayerObject playerObject) {
if (sGameProfiles.containsKey(playerObject)) {
return sGameProfiles.get(playerObject);
}
return sGameProfiles.append(playerObject, wrapper(this.getGameProfile0(playerObject))).get(playerObject);
return sGameProfiles.append(playerObject, wrapper(this.getInternalGameProfile(playerObject))).get(playerObject);
}

private void sendPacket(@NotNull ServerPlayer player, Packet<?> packet) {
player.connection.send(packet);
}

@Override
protected void updateSkin0(User user, PlayerObject playerObject, boolean forOthers) {
public void applySkin(@NotNull PlayerObject playerObject, @NotNull Skin skin) {
SchedulerManager.getScheduler().runTaskLater(skinOverlay.getClass(), () -> {
Player player = (Player) playerObject.player();
player.hidePlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
player.showPlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
skinOverlay.getSkinHandler().updateSkin(playerObject, user.skin()).handleAsync((aBoolean, throwable) -> {
skinOverlay.getSkinHandler().updateSkin(playerObject, skin).handleAsync((aBoolean, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
return false;
}
return aBoolean;
}).thenAccept(aBoolean -> SchedulerManager.getScheduler().runTask(skinOverlay.getClass(), () -> {
if (aBoolean)
if (forOthers) {
skinOverlay.onlinePlayers().stream().filter(playerObjects -> playerObjects != playerObject).forEach(playerObjects -> {
Player p = (Player) playerObjects.player();
p.hidePlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
p.showPlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
});
}
skinOverlay.onlinePlayers().stream().filter(playerObjects -> playerObjects != playerObject).forEach(playerObjects -> {
Player p = (Player) playerObjects.player();
p.hidePlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
p.showPlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
});
}));
}, 20L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.georgev22.skinoverlay.handler.SGameProfile;
import com.georgev22.skinoverlay.handler.Skin;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.utilities.player.User;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.google.common.collect.ImmutableList;
import com.mojang.authlib.GameProfile;
Expand Down Expand Up @@ -89,7 +88,30 @@ public CompletableFuture<Boolean> updateSkin(@NotNull PlayerObject playerObject,
}

@Override
public GameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
public void applySkin(@NotNull PlayerObject playerObject, @NotNull Skin skin) {
SchedulerManager.getScheduler().runTaskLater(skinOverlay.getClass(), () -> {
Player player = (Player) playerObject.player();
player.hidePlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
player.showPlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
skinOverlay.getSkinHandler().updateSkin(playerObject, skin).handleAsync((aBoolean, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
return false;
}
return aBoolean;
}).thenAccept(aBoolean -> SchedulerManager.getScheduler().runTask(skinOverlay.getClass(), () -> {
if (aBoolean)
skinOverlay.onlinePlayers().stream().filter(playerObjects -> playerObjects != playerObject).forEach(playerObjects -> {
Player p = (Player) playerObjects.player();
p.hidePlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
p.showPlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
});
}));
}, 20L);
}

@Override
public @NotNull GameProfile getInternalGameProfile(@NotNull PlayerObject playerObject) {
Player player = (Player) playerObject.player();
final CraftPlayer craftPlayer = (CraftPlayer) player;
final ServerPlayer entityPlayer = craftPlayer.getHandle();
Expand All @@ -101,36 +123,11 @@ public SGameProfile getGameProfile(@NotNull PlayerObject playerObject) {
if (sGameProfiles.containsKey(playerObject)) {
return sGameProfiles.get(playerObject);
}
return sGameProfiles.append(playerObject, wrapper(this.getGameProfile0(playerObject))).get(playerObject);
return sGameProfiles.append(playerObject, wrapper(this.getInternalGameProfile(playerObject))).get(playerObject);
}

private void sendPacket(@NotNull ServerPlayer player, Packet<?> packet) {
player.connection.send(packet);
}

@Override
protected void updateSkin0(User user, PlayerObject playerObject, boolean forOthers) {
SchedulerManager.getScheduler().runTaskLater(skinOverlay.getClass(), () -> {
Player player = (Player) playerObject.player();
player.hidePlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
player.showPlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
skinOverlay.getSkinHandler().updateSkin(playerObject, user.skin()).handleAsync((aBoolean, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
return false;
}
return aBoolean;
}).thenAccept(aBoolean -> SchedulerManager.getScheduler().runTask(skinOverlay.getClass(), () -> {
if (aBoolean)
if (forOthers) {
skinOverlay.onlinePlayers().stream().filter(playerObjects -> playerObjects != playerObject).forEach(playerObjects -> {
Player p = (Player) playerObjects.player();
p.hidePlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
p.showPlayer((Plugin) skinOverlay.getSkinOverlay().plugin(), player);
});
}
}));
}, 20L);
}
}

Loading

0 comments on commit 43935d4

Please sign in to comment.