-
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.
feat: Add support for Minecraft version 1.20.2
- Loading branch information
1 parent
147314e
commit b5c7f92
Showing
3 changed files
with
142 additions
and
0 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
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" | ||
} |
124 changes: 124 additions & 0 deletions
124
...c-1-20-2/src/main/java/com/georgev22/skinoverlay/handler/handlers/SkinHandler_1_20_2.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,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); | ||
} | ||
} | ||
|
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