From 3871ce9330c6a36ab87f77401a459fead6cd284b Mon Sep 17 00:00:00 2001 From: unldenis Date: Mon, 7 Feb 2022 21:11:34 +0100 Subject: [PATCH] 1.0.3 Update: - SpawnCorpseCommand fixed to spawn an online player - Skin now rendered (1.8-1.12) - Other minor fixes --- pom.xml | 10 +--------- .../java/com/github/unldenis/corpse/api/CorpseAPI.java | 4 +++- .../unldenis/corpse/command/SpawnCorpseCommand.java | 7 ++++++- .../java/com/github/unldenis/corpse/logic/Corpse.java | 4 +--- .../com/github/unldenis/corpse/logic/PacketLoader.java | 8 -------- .../corpse/logic/packet/WrapperEntityMetadata.java | 2 -- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 6a94c32..b0f4253 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.unldenis.corpse Corpse - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT 8 @@ -46,14 +46,6 @@ 20.1.0 provided - - diff --git a/src/main/java/com/github/unldenis/corpse/api/CorpseAPI.java b/src/main/java/com/github/unldenis/corpse/api/CorpseAPI.java index 428a89a..c28ea3d 100644 --- a/src/main/java/com/github/unldenis/corpse/api/CorpseAPI.java +++ b/src/main/java/com/github/unldenis/corpse/api/CorpseAPI.java @@ -35,6 +35,8 @@ public CorpseAPI() { throw new IllegalArgumentException(); } + private CorpseAPI(Object dummy) { } + /** * Method that creates a corpse in the player's position and with its skin and inventory * @param player The player to copy @@ -133,7 +135,7 @@ public void removeCorpse(@NotNull Corpse corpse) { @NotNull public static synchronized CorpseAPI getInstance() { if(instance == null) { - instance = new CorpseAPI(); + instance = new CorpseAPI(null); } return instance; } diff --git a/src/main/java/com/github/unldenis/corpse/command/SpawnCorpseCommand.java b/src/main/java/com/github/unldenis/corpse/command/SpawnCorpseCommand.java index 0c279ca..b579976 100644 --- a/src/main/java/com/github/unldenis/corpse/command/SpawnCorpseCommand.java +++ b/src/main/java/com/github/unldenis/corpse/command/SpawnCorpseCommand.java @@ -19,6 +19,7 @@ package com.github.unldenis.corpse.command; +import com.github.unldenis.corpse.api.*; import com.github.unldenis.corpse.logic.*; import org.bukkit.*; import org.bukkit.command.*; @@ -38,7 +39,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N return true; }else if(args.length==1) { OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); - new Corpse(player.getLocation(), target, null); + if(target.isOnline()) { + CorpseAPI.getInstance().spawnCorpse((Player) target, player.getLocation()); + } else { + new Corpse(player.getLocation(), target, null); + } player.sendMessage(ChatColor.GREEN+"Corpse created"); return true; } diff --git a/src/main/java/com/github/unldenis/corpse/logic/Corpse.java b/src/main/java/com/github/unldenis/corpse/logic/Corpse.java index cf5dad2..b95b05e 100644 --- a/src/main/java/com/github/unldenis/corpse/logic/Corpse.java +++ b/src/main/java/com/github/unldenis/corpse/logic/Corpse.java @@ -120,8 +120,7 @@ public void show(@NotNull Player player) { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); } } - - Bukkit.getScheduler().runTaskLater(CorpseP.getInstance(), ()->{ + Bukkit.getScheduler().runTaskLaterAsynchronously(CorpseP.getInstance(), ()->{ try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, this.packetLoader.getWrapperPlayerInfoRemove().get()); } catch (InvocationTargetException e) { @@ -147,7 +146,6 @@ public void hide(@NotNull Player player) { this.seeingPlayers.remove(player); } - public boolean isShownFor(@NotNull Player player) { return this.seeingPlayers.contains(player); } diff --git a/src/main/java/com/github/unldenis/corpse/logic/PacketLoader.java b/src/main/java/com/github/unldenis/corpse/logic/PacketLoader.java index 865b283..07075f7 100644 --- a/src/main/java/com/github/unldenis/corpse/logic/PacketLoader.java +++ b/src/main/java/com/github/unldenis/corpse/logic/PacketLoader.java @@ -27,11 +27,7 @@ public class PacketLoader { - private final Corpse corpse; - - private final Collection packets = new CopyOnWriteArraySet<>(); - private final WrapperEntityDestroy wrapperEntityDestroy; private final WrapperEntityEquipment wrapperEntityEquipment; private final WrapperEntityMetadata wrapperEntityMetadata; @@ -40,8 +36,6 @@ public class PacketLoader { private final WrapperPlayerInfo wrapperPlayerInfoRemove; public PacketLoader(@NotNull Corpse corpse) { - this.corpse = corpse; - //init packets this.wrapperEntityDestroy = new WrapperEntityDestroy(corpse.id); this.wrapperEntityEquipment = new WrapperEntityEquipment(corpse.id, corpse.armorContents); @@ -59,11 +53,9 @@ public void load() { packets.add(wrapperNamedEntitySpawn); packets.add(wrapperPlayerInfoAdd); packets.add(wrapperPlayerInfoRemove); - this.packets.forEach(IPacket::load); } - public WrapperEntityDestroy getWrapperEntityDestroy() { return wrapperEntityDestroy; } diff --git a/src/main/java/com/github/unldenis/corpse/logic/packet/WrapperEntityMetadata.java b/src/main/java/com/github/unldenis/corpse/logic/packet/WrapperEntityMetadata.java index ef47bd9..75c88d5 100644 --- a/src/main/java/com/github/unldenis/corpse/logic/packet/WrapperEntityMetadata.java +++ b/src/main/java/com/github/unldenis/corpse/logic/packet/WrapperEntityMetadata.java @@ -43,13 +43,11 @@ public void load() { if(VersionUtil.isAbove(VersionUtil.VersionEnum.V1_13)) { WrappedDataWatcher.WrappedDataWatcherObject visible = new WrappedDataWatcher.WrappedDataWatcherObject(6, WrappedDataWatcher.Registry.get(EnumWrappers.getEntityPoseClass())); watcher.setObject(visible, EnumWrappers.EntityPose.SLEEPING.toNms()); - /* //Works and set location a little higher WrappedDataWatcher.WrappedDataWatcherObject bed = new WrappedDataWatcher.WrappedDataWatcherObject(14, WrappedDataWatcher.Registry.getBlockPositionSerializer(true)); watcher.setObject(bed, Optional.of(BlockPosition.getConverter().getGeneric(new BlockPosition(corpse.location.toVector())))); */ - int indexSkinLayer = VersionUtil.isAbove(VersionUtil.VersionEnum.V1_17) ? 17 : 16; WrappedDataWatcher.WrappedDataWatcherObject skinLayers = new WrappedDataWatcher.WrappedDataWatcherObject(indexSkinLayer, WrappedDataWatcher.Registry.get(Byte.class)); watcher.setObject(skinLayers, (byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40 | 0x80));