Skip to content

Commit

Permalink
1.19 paper chunk rewrite fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ds58 committed Oct 1, 2022
1 parent b3ee9b5 commit 26e2348
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.ruinscraft.panilla.craftbukkit.v1_19_R1;

import com.ruinscraft.panilla.api.IPanillaPlayer;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.WorldServer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public final class TempHacks {

public static EntityPlayer getEntityPlayerFromPanillaPlayer(IPanillaPlayer panillaPlayer) {
// PanillaPlayer->getHandle()->CraftPlayer->getHandle()->EntityPlayer
Object craftPlayerHandle = panillaPlayer.getHandle();

System.out.println(craftPlayerHandle.getClass().getCanonicalName());

try {
Method craftPlayerGetHandleMethod = craftPlayerHandle.getClass().getDeclaredMethod("getHandle");
Object o = craftPlayerGetHandleMethod.invoke(craftPlayerHandle);
System.out.println(o.getClass().getCanonicalName());
return (EntityPlayer) o;
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}

private static boolean paperChunkRewrite;

static {
try {
WorldServer.class.getField("P");
paperChunkRewrite = false;
} catch (NoSuchFieldException e) {
paperChunkRewrite = true;
}
}

public static boolean isPaperChunkRewrite() {
return paperChunkRewrite;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ruinscraft.panilla.api.io.IPacketInspector;
import com.ruinscraft.panilla.api.nbt.INbtTagCompound;
import com.ruinscraft.panilla.api.nbt.checks.NbtChecks;
import com.ruinscraft.panilla.craftbukkit.v1_19_R1.TempHacks;
import com.ruinscraft.panilla.craftbukkit.v1_19_R1.nbt.NbtTagCompound;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.chat.IChatBaseComponent;
Expand Down Expand Up @@ -114,6 +115,8 @@ public void checkPacketPlayOutWindowItems(Object _packet) throws NbtNotPermitted

@Override
public void checkPacketPlayOutSpawnEntity(Object _packet) throws EntityNbtNotPermittedException {
if (TempHacks.isPaperChunkRewrite()) return;

if (_packet instanceof PacketPlayOutSpawnEntity) {
PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet;

Expand Down Expand Up @@ -168,6 +171,8 @@ public void sendPacketPlayOutSetSlotAir(IPanillaPlayer player, int slot) {

@Override
public void stripNbtFromItemEntity(UUID entityId) {
if (TempHacks.isPaperChunkRewrite()) return;

Entity entity = null;

for (WorldServer worldServer : MinecraftServer.getServer().E()) {
Expand Down

0 comments on commit 26e2348

Please sign in to comment.