Skip to content

Commit

Permalink
Update to support Minecraft 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ste3et committed Dec 22, 2023
1 parent cfde4db commit a72fc52
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 17 deletions.
Binary file modified .gradle/7.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/checksums/sha1-checksums.bin
Binary file not shown.
8 changes: 4 additions & 4 deletions FurnitureLib-Core/build.gradle
Expand Up @@ -30,10 +30,10 @@ dependencies {

implementation "com.zaxxer:HikariCP:4.0.3"
implementation "org.slf4j:slf4j-simple:1.7.5"
implementation "net.kyori:adventure-text-minimessage:4.13.0"
implementation "net.kyori:adventure-platform-bukkit:4.3.0"
implementation "net.kyori:adventure-text-serializer-legacy:4.13.0"
implementation "net.kyori:adventure-text-serializer-plain:4.13.0"
implementation "net.kyori:adventure-text-minimessage:4.14.0"
implementation "net.kyori:adventure-platform-bukkit:4.3.1"
implementation "net.kyori:adventure-text-serializer-legacy:4.14.0"
implementation "net.kyori:adventure-text-serializer-plain:4.14.0"

compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
compileOnly 'com.gitlab.Ste3et_C0st.protectionlib:Core:v1.4'
Expand Down
Expand Up @@ -3,18 +3,23 @@
import de.Ste3et_C0st.FurnitureLib.NBT.ItemStackReader.ItemStackReader;
import de.Ste3et_C0st.FurnitureLib.NBT.ItemStackReader.ItemStackV111_112;
import de.Ste3et_C0st.FurnitureLib.NBT.ItemStackReader.ItemStackV113;
import de.Ste3et_C0st.FurnitureLib.NBT.ItemStackReader.ItemStackV120_1;
import de.Ste3et_C0st.FurnitureLib.main.FurnitureLib;

import org.bukkit.inventory.ItemStack;

import com.comphenix.protocol.utility.MinecraftVersion;

import java.util.Objects;

public class CraftItemStack {

private final static ItemStackReader reader;

static {
if(FurnitureLib.getVersionInt() < 13) {
if(FurnitureLib.getVersion(new MinecraftVersion("1.20.3"))) {
reader = new ItemStackV120_1();
}else if(FurnitureLib.getVersionInt() < 13) {
reader = new ItemStackV111_112();
}else {
reader = new ItemStackV113();
Expand Down
@@ -1,7 +1,6 @@
package de.Ste3et_C0st.FurnitureLib.NBT.ItemStackReader;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import org.bukkit.inventory.ItemStack;
Expand All @@ -15,19 +14,16 @@ public abstract class ItemStackReader {

protected static Class<?> clazz_obc_CraftItemStack, clazz_nms_nbt, clazz_nbttools, clazz_nms_item;
private static Method asNMSCopy, method_save;
protected static Method clazz_nbttools_method_a_output, clazz_nbttools_method_a_input;
public static Method clazz_nbttools_method_a_output, clazz_nbttools_method_a_input;

static {
try {
String nbtFolder = FurnitureLib.getVersionInt() > 16 ? "net.minecraft.nbt" : "net.minecraft.server." + FurnitureLib.getBukkitVersion();
String itemStack = FurnitureLib.getVersionInt() > 16 ? "net.minecraft.world.item.ItemStack" : "net.minecraft.server." + FurnitureLib.getBukkitVersion() + ".ItemStack";
clazz_obc_CraftItemStack = Class.forName("org.bukkit.craftbukkit." + FurnitureLib.getBukkitVersion() + ".inventory.CraftItemStack");
clazz_nms_nbt = Class.forName(nbtFolder + ".NBTTagCompound");
clazz_nbttools = Class.forName(nbtFolder + ".NBTCompressedStreamTools");
clazz_nms_nbt = Class.forName(getNbtFolder() + ".NBTTagCompound");
clazz_nbttools = Class.forName(getNbtFolder() + ".NBTCompressedStreamTools");
asNMSCopy = clazz_obc_CraftItemStack.getMethod("asNMSCopy", org.bukkit.inventory.ItemStack.class);
clazz_nms_item = Class.forName(itemStack);
clazz_nms_item = Class.forName(getItemStackClass());
method_save = clazz_nms_item.getMethod(FurnitureLib.getVersionInt() > 17 ? "b" : "save", clazz_nms_nbt);
clazz_nbttools_method_a_input = clazz_nbttools.getMethod("a", InputStream.class);
clazz_nbttools_method_a_output = clazz_nbttools.getMethod("a", clazz_nms_nbt, OutputStream.class);
}catch(Exception ex) {
ex.printStackTrace();
Expand All @@ -51,4 +47,12 @@ public NBTTagCompound getNBTTag(ItemStack is) throws Exception {
}
}

static String getNbtFolder() {
return FurnitureLib.getVersionInt() > 16 ? "net.minecraft.nbt" : "net.minecraft.server." + FurnitureLib.getBukkitVersion();
}

static String getItemStackClass() {
return FurnitureLib.getVersionInt() > 16 ? "net.minecraft.world.item.ItemStack" : "net.minecraft.server." + FurnitureLib.getBukkitVersion() + ".ItemStack";
}

}
@@ -1,6 +1,7 @@
package de.Ste3et_C0st.FurnitureLib.NBT.ItemStackReader;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

Expand All @@ -17,6 +18,7 @@ public class ItemStackV111_112 extends ItemStackReader{
static {
try {
constructor_nms_item = clazz_nms_item.getConstructor(clazz_nms_nbt);
clazz_nbttools_method_a_input = clazz_nbttools.getMethod("a", InputStream.class);
asBukkitCopy = clazz_obc_CraftItemStack.getMethod("asBukkitCopy", clazz_nms_item);
}catch(Exception ex) {
ex.printStackTrace();
Expand Down
@@ -1,6 +1,7 @@
package de.Ste3et_C0st.FurnitureLib.NBT.ItemStackReader;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;

import org.bukkit.inventory.ItemStack;
Expand All @@ -15,6 +16,7 @@ public class ItemStackV113 extends ItemStackReader{
static {
try {
a = clazz_nms_item.getMethod("a", clazz_nms_nbt);
clazz_nbttools_method_a_input = clazz_nbttools.getMethod("a", InputStream.class);
asBukkitCopy = clazz_obc_CraftItemStack.getMethod("asBukkitCopy", clazz_nms_item);
}catch(Exception ex) {
ex.printStackTrace();
Expand Down
@@ -0,0 +1,41 @@
package de.Ste3et_C0st.FurnitureLib.NBT.ItemStackReader;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;

import org.bukkit.inventory.ItemStack;

import de.Ste3et_C0st.FurnitureLib.NBT.NBTCompressedStreamTools;
import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound;

public class ItemStackV120_1 extends ItemStackReader{

private static Class<?> nmsNBTReadLimiter;
private static Method a, asBukkitCopy;


static {
try {
nmsNBTReadLimiter = Class.forName(getNbtFolder() + ".NBTReadLimiter");
a = clazz_nms_item.getMethod("a", clazz_nms_nbt);
asBukkitCopy = clazz_obc_CraftItemStack.getMethod("asBukkitCopy", clazz_nms_item);
clazz_nbttools_method_a_input = clazz_nbttools.getMethod("a", InputStream.class, nmsNBTReadLimiter);
}catch(Exception ex) {
ex.printStackTrace();
}
}

public ItemStack getItemStack(NBTTagCompound nbt) {
try {
byte[] data = NBTCompressedStreamTools.toByte(nbt);
Object nbtTag = clazz_nbttools_method_a_input.invoke(null, new ByteArrayInputStream(data), nmsNBTReadLimiter.getMethod("a").invoke(null));
Object nms_item = a.invoke(null, nbtTag);
return (ItemStack) asBukkitCopy.invoke(null, nms_item);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

}
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.Bukkit;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import com.google.gson.Gson;
Expand Down Expand Up @@ -208,7 +209,12 @@ private void sendToHost(JsonObject dump, CommandSender sender) {
sender.sendMessage("§cThe dump can't be handeld");
}else {
sender.sendMessage("§7FurnitureLib dump file upload §2§lSuccess");
LanguageManager.sendChatMessage(sender, MiniMessage.miniMessage().deserialize("<gray>You can find it here: <click:open_url:" + response.toString().replace("#URL:", "") +"><yellow>Click</click>"));
if(sender instanceof Player) {
LanguageManager.sendChatMessage(sender, MiniMessage.miniMessage().deserialize("<gray>You can find it here: <yellow><click:open_url:'" + response.toString().replace("#URL:", "") +"'>Click</click>"));
}else {
response.toString().replace("#URL:", "");
}

}
}
}
Expand Down
Expand Up @@ -69,7 +69,7 @@ public ItemDisplayTransform getItemDisplay() {

public fItem_display setItemStack(final ItemStack stack) {
this.stack.setValue(stack);
getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 22, Registry.getItemStackSerializer(false)), getStack());
getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 22, Registry.getItemStackSerializer(false)), stack);
return this;
}

Expand Down
Expand Up @@ -101,7 +101,7 @@ public fText_display setText(final String text) {
final String workString = LanguageConverter.serializeLegacyColors(text);
final Component textComponent = MiniMessage.miniMessage().deserialize(workString);
final Object wrappedChat = WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(textComponent)).getHandle();
getWatcher().setObject(new WrappedDataWatcherObject(22, Registry.getChatComponentSerializer(false)), wrappedChat);
getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 22, Registry.getChatComponentSerializer(false)), wrappedChat);
return this;
}

Expand Down
Binary file modified buildSrc/.gradle/7.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified buildSrc/.gradle/7.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified buildSrc/build/libs/buildSrc.jar
Binary file not shown.
Expand Up @@ -82,7 +82,7 @@ tasks {

allprojects {
group = 'de.Ste3et_C0st.furniture'
version = '3.1.2'
version = '3.1.4'
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand Down

0 comments on commit a72fc52

Please sign in to comment.