-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
486 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
allprojects { | ||
group = 'com.ruinscraft' | ||
version = '1.7.6-booktest' | ||
version = '1.7.7' | ||
} | ||
|
||
subprojects { | ||
|
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
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
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,4 @@ | ||
dependencies { | ||
compileOnly project(':panilla-api') | ||
compileOnly 'org.spigotmc:spigot:1.19-R0.1-SNAPSHOT' | ||
} |
54 changes: 54 additions & 0 deletions
54
...-v1_19_R1/src/main/java/com/ruinscraft/panilla/craftbukkit/v1_19_R1/InventoryCleaner.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,54 @@ | ||
package com.ruinscraft.panilla.craftbukkit.v1_19_R1; | ||
|
||
import com.ruinscraft.panilla.api.IInventoryCleaner; | ||
import com.ruinscraft.panilla.api.IPanilla; | ||
import com.ruinscraft.panilla.api.IPanillaPlayer; | ||
import com.ruinscraft.panilla.api.exception.FailedNbt; | ||
import com.ruinscraft.panilla.api.nbt.INbtTagCompound; | ||
import com.ruinscraft.panilla.api.nbt.checks.NbtChecks; | ||
import com.ruinscraft.panilla.craftbukkit.v1_19_R1.nbt.NbtTagCompound; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.world.inventory.Container; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; | ||
|
||
public class InventoryCleaner implements IInventoryCleaner { | ||
|
||
private final IPanilla panilla; | ||
|
||
public InventoryCleaner(IPanilla panilla) { | ||
this.panilla = panilla; | ||
} | ||
|
||
@Override | ||
public void clean(IPanillaPlayer player) { | ||
CraftPlayer craftPlayer = (CraftPlayer) player.getHandle(); | ||
Container container = craftPlayer.getHandle().bT; | ||
|
||
for (int slot = 0; slot < container.i.size(); slot++) { | ||
ItemStack itemStack = container.b(slot).e(); | ||
|
||
if (itemStack == null || !itemStack.t()) { | ||
continue; | ||
} | ||
|
||
NBTTagCompound nmsTag = itemStack.v(); | ||
INbtTagCompound tag = new NbtTagCompound(nmsTag); | ||
String itemName = itemStack.c().a(); | ||
|
||
if (nmsTag == null || itemName == null) { | ||
continue; | ||
} | ||
|
||
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla); | ||
|
||
if (FailedNbt.failsThreshold(failedNbt)) { | ||
container.b(slot).e().c((NBTTagCompound) null); | ||
} else if (FailedNbt.fails(failedNbt)) { | ||
nmsTag.r(failedNbt.key); | ||
container.b(slot).e().c(nmsTag); | ||
} | ||
} | ||
} | ||
|
||
} |
204 changes: 204 additions & 0 deletions
204
...1_19_R1/src/main/java/com/ruinscraft/panilla/craftbukkit/v1_19_R1/io/PacketInspector.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,204 @@ | ||
package com.ruinscraft.panilla.craftbukkit.v1_19_R1.io; | ||
|
||
import com.ruinscraft.panilla.api.IPanilla; | ||
import com.ruinscraft.panilla.api.IPanillaPlayer; | ||
import com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException; | ||
import com.ruinscraft.panilla.api.exception.FailedNbt; | ||
import com.ruinscraft.panilla.api.exception.NbtNotPermittedException; | ||
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.nbt.NbtTagCompound; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.network.chat.IChatBaseComponent; | ||
import net.minecraft.network.protocol.Packet; | ||
import net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot; | ||
import net.minecraft.network.protocol.game.PacketPlayOutSetSlot; | ||
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; | ||
import net.minecraft.network.protocol.game.PacketPlayOutWindowItems; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.EntityPlayer; | ||
import net.minecraft.server.level.WorldServer; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.item.EntityItem; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.Blocks; | ||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class PacketInspector implements IPacketInspector { | ||
|
||
private final IPanilla panilla; | ||
|
||
public PacketInspector(IPanilla panilla) { | ||
this.panilla = panilla; | ||
} | ||
|
||
@Override | ||
public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException { | ||
if (_packet instanceof PacketPlayInSetCreativeSlot) { | ||
PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet; | ||
|
||
int slot = packet.b(); | ||
ItemStack itemStack = packet.c(); | ||
|
||
if (itemStack == null || !itemStack.t()) return; | ||
|
||
NbtTagCompound tag = new NbtTagCompound(itemStack.v()); | ||
String itemClass = itemStack.c().getClass().getSimpleName(); | ||
String packetClass = packet.getClass().getSimpleName(); | ||
|
||
NbtChecks.checkPacketPlayIn(slot, tag, itemClass, packetClass, panilla); | ||
} | ||
} | ||
|
||
@Override | ||
public void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException { | ||
if (_packet instanceof PacketPlayOutSetSlot) { | ||
PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) _packet; | ||
|
||
int windowId = packet.b(); | ||
|
||
// check if window is not player inventory and we are ignoring non-player inventories | ||
if (windowId != 0 && panilla.getPConfig().ignoreNonPlayerInventories) { | ||
return; | ||
} | ||
|
||
int slot = packet.c(); | ||
|
||
ItemStack itemStack = packet.d(); | ||
|
||
if (itemStack == null || !itemStack.t()) { | ||
return; | ||
} | ||
|
||
NbtTagCompound tag = new NbtTagCompound(itemStack.v()); | ||
String itemClass = itemStack.getClass().getSimpleName(); | ||
String packetClass = packet.getClass().getSimpleName(); | ||
|
||
NbtChecks.checkPacketPlayOut(slot, tag, itemClass, packetClass, panilla); | ||
} | ||
} | ||
|
||
@Override | ||
public void checkPacketPlayOutWindowItems(Object _packet) throws NbtNotPermittedException { | ||
if (_packet instanceof PacketPlayOutWindowItems) { | ||
PacketPlayOutWindowItems packet = (PacketPlayOutWindowItems) _packet; | ||
|
||
int windowId = packet.b(); | ||
|
||
// check if window is not player inventory | ||
if (windowId != 0) { | ||
return; | ||
} | ||
|
||
List<ItemStack> itemStacks = packet.c(); | ||
|
||
for (ItemStack itemStack : itemStacks) { | ||
if (itemStack == null || !itemStack.t()) { | ||
continue; | ||
} | ||
|
||
NbtTagCompound tag = new NbtTagCompound(itemStack.v()); | ||
String itemClass = itemStack.getClass().getSimpleName(); | ||
String packetClass = packet.getClass().getSimpleName(); | ||
|
||
NbtChecks.checkPacketPlayOut(0, tag, itemClass, packetClass, panilla); // TODO: set slot? | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void checkPacketPlayOutSpawnEntity(Object _packet) throws EntityNbtNotPermittedException { | ||
if (_packet instanceof PacketPlayOutSpawnEntity) { | ||
PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet; | ||
|
||
UUID entityId = packet.c(); | ||
Entity entity = null; | ||
|
||
for (WorldServer worldServer : MinecraftServer.getServer().E()) { | ||
entity = worldServer.P.d().a(entityId); | ||
if (entity != null) break; | ||
} | ||
|
||
if (entity != null) { | ||
if (entity instanceof EntityItem) { | ||
EntityItem item = (EntityItem) entity; | ||
|
||
if (item.h() == null) { | ||
return; | ||
} | ||
|
||
if (!item.h().t()) { | ||
return; | ||
} | ||
|
||
INbtTagCompound tag = new NbtTagCompound(item.h().v()); | ||
String itemName = item.h().c().a(); | ||
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla); | ||
|
||
if (FailedNbt.fails(failedNbt)) { | ||
throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, entity.W().getWorld().getName()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void sendPacketPlayOutSetSlotAir(IPanillaPlayer player, int slot) { | ||
CraftPlayer craftPlayer = (CraftPlayer) player.getHandle(); | ||
EntityPlayer entityPlayer = craftPlayer.getHandle(); | ||
|
||
try { | ||
Class<?> packetPlayOutSetSlotClass = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutSetSlot"); | ||
Class<?>[] type = { int.class, int.class, int.class, ItemStack.class }; | ||
Constructor<?> constructor = packetPlayOutSetSlotClass.getConstructor(type); | ||
Object[] params = { 0, 0, slot, new ItemStack(Blocks.a) }; | ||
Object packetPlayOutSetSlotInstance = constructor.newInstance(params); | ||
entityPlayer.b.a((Packet<?>) packetPlayOutSetSlotInstance); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (InstantiationException e) { | ||
e.printStackTrace(); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void stripNbtFromItemEntity(UUID entityId) { | ||
Entity entity = null; | ||
|
||
for (WorldServer worldServer : MinecraftServer.getServer().E()) { | ||
entity = worldServer.P.d().a(entityId); | ||
if (entity != null) break; | ||
} | ||
|
||
if (entity instanceof EntityItem) { | ||
EntityItem item = (EntityItem) entity; | ||
if (item.h() == null) return; | ||
if (!item.h().t()) return; | ||
item.h().c((NBTTagCompound) null); | ||
} | ||
} | ||
|
||
@Override | ||
public void stripNbtFromItemEntityLegacy(int entityId) { | ||
throw new RuntimeException("cannot use #stripNbtFromItemEntityLegacy on 1.19"); | ||
} | ||
|
||
@Override | ||
public void validateBaseComponentParse(String string) throws Exception { | ||
IChatBaseComponent.ChatSerializer.a(string); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...v1_19_R1/src/main/java/com/ruinscraft/panilla/craftbukkit/v1_19_R1/io/PlayerInjector.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,55 @@ | ||
package com.ruinscraft.panilla.craftbukkit.v1_19_R1.io; | ||
|
||
import com.ruinscraft.panilla.api.IPanillaPlayer; | ||
import com.ruinscraft.panilla.api.io.IPlayerInjector; | ||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.ByteToMessageDecoder; | ||
import net.minecraft.network.PacketDecoder; | ||
import net.minecraft.network.protocol.EnumProtocolDirection; | ||
import net.minecraft.server.level.EntityPlayer; | ||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; | ||
|
||
import java.util.List; | ||
|
||
public class PlayerInjector implements IPlayerInjector { | ||
|
||
@Override | ||
public Channel getPlayerChannel(IPanillaPlayer player) throws IllegalArgumentException { | ||
CraftPlayer craftPlayer = (CraftPlayer) player.getHandle(); | ||
EntityPlayer entityPlayer = craftPlayer.getHandle(); | ||
return entityPlayer.b.b.m; | ||
} | ||
|
||
@Override | ||
public int getCompressionLevel() { | ||
return 256; | ||
} | ||
|
||
@Override | ||
public ByteToMessageDecoder getDecompressor() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ByteToMessageDecoder getDecoder() { | ||
return new PanillaPacketDecoder(EnumProtocolDirection.a); | ||
} | ||
|
||
private class PanillaPacketDecoder extends PacketDecoder { | ||
public PanillaPacketDecoder(EnumProtocolDirection enumProtocolDirection) { | ||
super(enumProtocolDirection); | ||
} | ||
|
||
@Override | ||
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) { | ||
try { | ||
super.decode(channelHandlerContext, byteBuf, list); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...1/src/main/java/com/ruinscraft/panilla/craftbukkit/v1_19_R1/io/dplx/PacketSerializer.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,35 @@ | ||
package com.ruinscraft.panilla.craftbukkit.v1_19_R1.io.dplx; | ||
|
||
import com.ruinscraft.panilla.api.io.IPacketSerializer; | ||
import io.netty.buffer.ByteBuf; | ||
import net.minecraft.network.PacketDataSerializer; | ||
|
||
public class PacketSerializer implements IPacketSerializer { | ||
|
||
private final PacketDataSerializer handle; | ||
|
||
public PacketSerializer(ByteBuf byteBuf) { | ||
this.handle = new PacketDataSerializer(byteBuf); | ||
} | ||
|
||
@Override | ||
public int readableBytes() { | ||
return handle.readableBytes(); | ||
} | ||
|
||
@Override | ||
public int readVarInt() { | ||
return handle.k(); | ||
} | ||
|
||
@Override | ||
public ByteBuf readBytes(int i) { | ||
return handle.readBytes(i); | ||
} | ||
|
||
@Override | ||
public ByteBuf readBytes(byte[] buffer) { | ||
return handle.readBytes(buffer); | ||
} | ||
|
||
} |
Oops, something went wrong.