Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
narumii committed May 9, 2021
1 parent 6c2e444 commit 5421746
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public final class ReflectionHelper {
try {
BUKKIT = Bukkit.getServer().getClass().getName().replace(".CraftServer", "");
NMS = BUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server");
VERSION = (BUKKIT.split("\\.")[BUKKIT.split("\\.").length - 1]).substring(1).replace("_", "."); //Yes i know boiler plate
VERSION = (BUKKIT.split("\\.")[BUKKIT.split("\\.").length - 1]).substring(1)
.replace("_", "."); //Yes i know boiler plate

Class<?> craftPlayerClass = Class.forName(BUKKIT + ".entity.CraftPlayer");
Class<?> entityPlayerClass = Class.forName(NMS + ".EntityPlayer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import uwu.narumi.nbt.NbtTag;
import uwu.narumi.nbt.NbtType;
import uwu.narumi.nbt.exception.NBTException;

public class NbtStreamHelper {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private String getTagsString() {
.append("name=")
.append(name)
.append(", ")
.append(tag.toString())
.append(tag)
.append((atomicInteger.get() >= tags.size() ? "" : ", "));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import java.io.IOException;
import net.minecraft.server.v1_8_R3.NBTBase;
import uwu.narumi.itemstack.ItemStack;
import uwu.narumi.nbt.NbtTag;
import uwu.narumi.nbt.helper.NbtStreamHelper;
Expand All @@ -20,10 +19,11 @@ public static void writeItemStack(ItemStack itemStack, ByteBuf buf) throws IOExc
buf.writeByte(itemStack.amount());
buf.writeShort(itemStack.data());

if (itemStack.getCompoundTag() != null)
if (itemStack.getCompoundTag() != null) {
NbtStreamHelper.writeTag(itemStack.getCompoundTag(), new ByteBufOutputStream(buf));
else
} else {
buf.writeByte(0);
}
}
}

Expand All @@ -34,7 +34,8 @@ public static ItemStack readItemStack(ByteBuf buf) throws IOException {
byte amount = buf.readByte();
short data = buf.readShort();
NbtTag compoundTag = NbtStreamHelper.readTag(new ByteBufInputStream(buf));
itemStack = new ItemStack(id, amount, data, compoundTag instanceof CompoundTag ? (CompoundTag) compoundTag : null);
itemStack = new ItemStack(id, amount, data,
compoundTag instanceof CompoundTag ? (CompoundTag) compoundTag : null);
}

return itemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class ItemStackExample {

public static void main(String... args) throws Exception {
public static void main(String... args) {
CompoundTag compoundTag = new CompoundTag();
compoundTag.with("pages",
new StringTag("page 1"),
Expand All @@ -25,6 +25,6 @@ public static void main(String... args) throws Exception {
itemStack.lore("lore1", "lore2");
itemStack.enchant(5, 1);

System.out.println(itemStack.toString());
System.out.println(itemStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void main(String... args) throws Exception {

try (DataInputStream in = new DataInputStream(new FileInputStream("test.nbt"))) {
CompoundTag tag = (CompoundTag) NbtStreamHelper.readTag(in);
System.out.println(tag.toString());
System.out.println(tag);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uwu.narumi.example.packetlib;

import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand All @@ -12,7 +13,6 @@
import uwu.narumi.itemstack.ItemStack;
import uwu.narumi.itemstack.helper.ItemStackStreamHelper;
import uwu.narumi.nbt.impl.CompoundTag;
import uwu.narumi.packetlib.api.helper.BufHelper;
import uwu.narumi.packetlib.api.helper.ReflectionHelper;
import uwu.narumi.packetlib.api.packet.PacketHandler;
import uwu.narumi.packetlib.api.packet.PacketInterceptor;
Expand Down Expand Up @@ -80,7 +80,7 @@ public PacketInterceptorExample(Session session) {
}

@Override
public PacketState receive(int packetId, ByteBuf data, ByteBuf newData) throws Exception {
public PacketState receive(int packetId, ByteBuf data, ByteBuf newData) throws IOException {
if (packetId == 0x10 && canReWrite) {
newData.writeShort(data.readShort()); //Slot id

Expand All @@ -89,7 +89,7 @@ public PacketState receive(int packetId, ByteBuf data, ByteBuf newData) throws E
itemStack.setCompoundTag(new CompoundTag()); //setting new item nbt
itemStack.name("Noice");
itemStack.lore("B", "U", "S", "T", "A", "R", "D");
itemStack.enchant(1,1);
itemStack.enchant(1, 1);
}

ItemStackStreamHelper.writeItemStack(itemStack, newData); //writing new data
Expand Down

0 comments on commit 5421746

Please sign in to comment.