Skip to content

Commit

Permalink
feat: Add support for Minecraft version 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeV220 committed Nov 3, 2023
1 parent 147314e commit b5c7f92
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
16 changes: 16 additions & 0 deletions multiver/mc-1-20-2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id "io.papermc.paperweight.userdev" version "1.5.5"
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.20.2-R0.1-SNAPSHOT")

implementation project(path: ':core')

compileOnly "io.papermc:paperlib:1.0.8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

package com.georgev22.skinoverlay.handler.handlers;

import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.skinoverlay.handler.SGameProfile;
import com.georgev22.skinoverlay.storage.data.Skin;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.*;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.world.level.biome.BiomeManager;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;

import static com.georgev22.skinoverlay.handler.handlers.SkinHandler_Unsupported.wrapper;

public final class SkinHandler_1_20_2 extends SkinHandler {

@Override
public CompletableFuture<Boolean> updateSkin(@NotNull PlayerObject playerObject, @NotNull Skin skin) {
return CompletableFuture.supplyAsync(() -> {
try {
Player player = (Player) playerObject.player();
final CraftPlayer craftPlayer = (CraftPlayer) player;
final ServerPlayer entityPlayer = craftPlayer.getHandle();

ClientboundPlayerInfoRemovePacket removePlayer = new ClientboundPlayerInfoRemovePacket(List.of(entityPlayer.getUUID()));
ClientboundPlayerInfoUpdatePacket addPlayer = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityPlayer));
ServerLevel world = entityPlayer.serverLevel();
ServerPlayerGameMode gamemode = entityPlayer.gameMode;

ClientboundRespawnPacket respawn = new ClientboundRespawnPacket(
new CommonPlayerSpawnInfo(
world.dimensionTypeId(),
world.dimension(),
BiomeManager.obfuscateSeed(world.getSeed()),
gamemode.getGameModeForPlayer(),
gamemode.getPreviousGameModeForPlayer(),
world.isDebug(),
world.isFlat(),
entityPlayer.getLastDeathLocation(),
entityPlayer.getPortalCooldown()
),
(byte) 3
);
Location l = player.getLocation();
ClientboundPlayerPositionPacket pos = new ClientboundPlayerPositionPacket(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch(), new HashSet<>(), 0);
ClientboundSetCarriedItemPacket slot = new ClientboundSetCarriedItemPacket(player.getInventory().getHeldItemSlot());

sendPacket(entityPlayer, removePlayer);
sendPacket(entityPlayer, addPlayer);

sendPacket(entityPlayer, respawn);

entityPlayer.onUpdateAbilities();

sendPacket(entityPlayer, pos);
sendPacket(entityPlayer, slot);
craftPlayer.updateScaledHealth();
player.updateInventory();
entityPlayer.resetSentInfo();
return true;
} catch (Exception exception) {
throw new RuntimeException(exception);
}
});
}

@Override
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) {
skinOverlay.getLogger().log(Level.SEVERE, "Error updating skin", throwable);
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 GameProfile getInternalGameProfile(@NotNull PlayerObject playerObject) {
Player player = (Player) playerObject.player();
final CraftPlayer craftPlayer = (CraftPlayer) player;
final ServerPlayer entityPlayer = craftPlayer.getHandle();
return entityPlayer.getGameProfile();
}

@Override
public SGameProfile getGameProfile(@NotNull PlayerObject playerObject) {
if (sGameProfiles.containsKey(playerObject)) {
return sGameProfiles.get(playerObject);
}
return sGameProfiles.append(playerObject, wrapper(this.getInternalGameProfile(playerObject))).get(playerObject);
}

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

2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ include ':multiver:mc-1-19'
include ':multiver:mc-1-19-3'
include ':multiver:mc-1-19-4'
include 'multiver:mc-1-20'
include 'multiver:mc-1-20-2'
findProject(':multiver:mc-1-17')?.name = 'mc-1-17'
findProject(':multiver:mc-1-18')?.name = 'mc-1-18'
findProject(':multiver:mc-1-18-2')?.name = 'mc-1-18-2'
findProject(':multiver:mc-1-19')?.name = 'mc-1-19'
findProject(':multiver:mc-1-19-3')?.name = 'mc-1-19-3'
findProject(':multiver:mc-1-19-4')?.name = 'mc-1-19-4'
findProject(':multiver:mc-1-20')?.name = 'mc-1-20'
findProject(':multiver:mc-1-20-2')?.name = 'mc-1-20-2'

0 comments on commit b5c7f92

Please sign in to comment.