mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
checkpoint - 34
This commit is contained in:
@@ -267,6 +267,13 @@ public enum Dependency {
|
|||||||
"slf4j-api",
|
"slf4j-api",
|
||||||
"maven",
|
"maven",
|
||||||
"slf4j"
|
"slf4j"
|
||||||
|
),
|
||||||
|
LZ4(
|
||||||
|
"org{}lz4",
|
||||||
|
"lz4-java",
|
||||||
|
"maven",
|
||||||
|
"lz4-java",
|
||||||
|
Relocation.of("jpountz", "net{}jpountz")
|
||||||
);
|
);
|
||||||
|
|
||||||
private final List<Relocation> relocations;
|
private final List<Relocation> relocations;
|
||||||
|
|||||||
@@ -24,3 +24,4 @@ caffeine=${caffeine_version}
|
|||||||
jedis=${jedis_version}
|
jedis=${jedis_version}
|
||||||
exp4j=${exp4j_version}
|
exp4j=${exp4j_version}
|
||||||
slf4j=${slf4j_version}
|
slf4j=${slf4j_version}
|
||||||
|
lz4-java=${lz4_version}
|
||||||
@@ -55,6 +55,8 @@ dependencies {
|
|||||||
compileOnly("net.objecthunter:exp4j:${rootProject.properties["exp4j_version"]}")
|
compileOnly("net.objecthunter:exp4j:${rootProject.properties["exp4j_version"]}")
|
||||||
// placeholder api
|
// placeholder api
|
||||||
compileOnly("me.clip:placeholderapi:${rootProject.properties["placeholder_api_version"]}")
|
compileOnly("me.clip:placeholderapi:${rootProject.properties["placeholder_api_version"]}")
|
||||||
|
// lz4
|
||||||
|
compileOnly("org.lz4:lz4-java:${rootProject.properties["lz4_version"]}")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@@ -76,6 +78,7 @@ tasks {
|
|||||||
relocate ("com.saicone.rtag", "net.momirealms.customfishing.libraries.rtag")
|
relocate ("com.saicone.rtag", "net.momirealms.customfishing.libraries.rtag")
|
||||||
relocate ("xyz.xenondevs", "net.momirealms.customfishing.libraries")
|
relocate ("xyz.xenondevs", "net.momirealms.customfishing.libraries")
|
||||||
relocate ("net.objecthunter.exp4j", "net.momirealms.customfishing.libraries.exp4j")
|
relocate ("net.objecthunter.exp4j", "net.momirealms.customfishing.libraries.exp4j")
|
||||||
|
relocate ("net.jpountz", "net.momirealms.customfishing.libraries.jpountz") //lz4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin {
|
|||||||
Dependency.SQLITE_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE,
|
Dependency.SQLITE_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE,
|
||||||
Dependency.H2_DRIVER,
|
Dependency.H2_DRIVER,
|
||||||
Dependency.MONGODB_DRIVER_CORE, Dependency.MONGODB_DRIVER_SYNC, Dependency.MONGODB_DRIVER_BSON,
|
Dependency.MONGODB_DRIVER_CORE, Dependency.MONGODB_DRIVER_SYNC, Dependency.MONGODB_DRIVER_BSON,
|
||||||
Dependency.HIKARI_CP
|
Dependency.HIKARI_CP,
|
||||||
|
Dependency.LZ4
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@
|
|||||||
package net.momirealms.customfishing.bukkit.hook;
|
package net.momirealms.customfishing.bukkit.hook;
|
||||||
|
|
||||||
import com.saicone.rtag.item.ItemTagStream;
|
import com.saicone.rtag.item.ItemTagStream;
|
||||||
|
import net.jpountz.lz4.LZ4Compressor;
|
||||||
|
import net.jpountz.lz4.LZ4Factory;
|
||||||
|
import net.jpountz.lz4.LZ4FastDecompressor;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ScoreComponent;
|
import net.kyori.adventure.text.ScoreComponent;
|
||||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||||
@@ -45,6 +48,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -54,9 +58,11 @@ public class BukkitHookManager implements HookManager, Listener {
|
|||||||
|
|
||||||
private final BukkitCustomFishingPlugin plugin;
|
private final BukkitCustomFishingPlugin plugin;
|
||||||
private final HashMap<String, HookConfig> hooks = new HashMap<>();
|
private final HashMap<String, HookConfig> hooks = new HashMap<>();
|
||||||
|
private LZ4Factory factory;
|
||||||
|
|
||||||
public BukkitHookManager(BukkitCustomFishingPlugin plugin) {
|
public BukkitHookManager(BukkitCustomFishingPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.factory = LZ4Factory.fastestInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -119,7 +125,7 @@ public class BukkitHookManager implements HookManager, Listener {
|
|||||||
int damage = (int) wrapped.getTag("CustomFishing", "hook_damage").orElse(0);
|
int damage = (int) wrapped.getTag("CustomFishing", "hook_damage").orElse(0);
|
||||||
ItemStack itemStack;
|
ItemStack itemStack;
|
||||||
if (hookItemBase64 != null) {
|
if (hookItemBase64 != null) {
|
||||||
itemStack = ItemTagStream.INSTANCE.fromBytes(hookItemBase64);
|
itemStack = bytesToHook(hookItemBase64);
|
||||||
} else {
|
} else {
|
||||||
itemStack = plugin.getItemManager().buildInternal(Context.player(player), id);
|
itemStack = plugin.getItemManager().buildInternal(Context.player(player), id);
|
||||||
}
|
}
|
||||||
@@ -174,7 +180,7 @@ public class BukkitHookManager implements HookManager, Listener {
|
|||||||
ItemStack previousItemStack;
|
ItemStack previousItemStack;
|
||||||
byte[] stackBytes = (byte[]) wrapped.getTag("CustomFishing", "hook_stack").orElse(null);
|
byte[] stackBytes = (byte[]) wrapped.getTag("CustomFishing", "hook_stack").orElse(null);
|
||||||
if (stackBytes != null) {
|
if (stackBytes != null) {
|
||||||
previousItemStack = ItemTagStream.INSTANCE.fromBytes(stackBytes);
|
previousItemStack = bytesToHook(stackBytes);
|
||||||
} else {
|
} else {
|
||||||
previousItemStack = plugin.getItemManager().buildInternal(Context.player(player), previousHookID);
|
previousItemStack = plugin.getItemManager().buildInternal(Context.player(player), previousHookID);
|
||||||
}
|
}
|
||||||
@@ -197,7 +203,7 @@ public class BukkitHookManager implements HookManager, Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wrapped.setTag(hookID, "CustomFishing", "hook_id");
|
wrapped.setTag(hookID, "CustomFishing", "hook_id");
|
||||||
wrapped.setTag(ItemTagStream.INSTANCE.toBytes(clonedHook), "CustomFishing", "hook_stack");
|
wrapped.setTag(hookToBytes(clonedHook), "CustomFishing", "hook_stack");
|
||||||
wrapped.setTag(durabilityItem.damage(), "CustomFishing", "hook_damage");
|
wrapped.setTag(durabilityItem.damage(), "CustomFishing", "hook_damage");
|
||||||
wrapped.setTag(durabilityItem.maxDamage(), "CustomFishing", "hook_max_damage");
|
wrapped.setTag(durabilityItem.maxDamage(), "CustomFishing", "hook_max_damage");
|
||||||
|
|
||||||
@@ -225,4 +231,42 @@ public class BukkitHookManager implements HookManager, Listener {
|
|||||||
wrapped.lore(newLore);
|
wrapped.lore(newLore);
|
||||||
wrapped.load();
|
wrapped.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private byte[] hookToBytes(ItemStack hook) {
|
||||||
|
try {
|
||||||
|
byte[] data = ItemTagStream.INSTANCE.toBytes(hook);
|
||||||
|
int decompressedLength = data.length;
|
||||||
|
LZ4Compressor compressor = factory.fastCompressor();
|
||||||
|
int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);
|
||||||
|
byte[] compressed = new byte[maxCompressedLength];
|
||||||
|
int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength);
|
||||||
|
|
||||||
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream);
|
||||||
|
outputStream.writeInt(decompressedLength);
|
||||||
|
outputStream.write(compressed, 0, compressedLength);
|
||||||
|
outputStream.close();
|
||||||
|
|
||||||
|
return byteArrayOutputStream.toByteArray();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack bytesToHook(byte[] bytes) {
|
||||||
|
try {
|
||||||
|
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(bytes));
|
||||||
|
int decompressedLength = inputStream.readInt();
|
||||||
|
byte[] compressed = new byte[inputStream.available()];
|
||||||
|
inputStream.readFully(compressed);
|
||||||
|
|
||||||
|
LZ4FastDecompressor decompressor = factory.fastDecompressor();
|
||||||
|
byte[] restored = new byte[decompressedLength];
|
||||||
|
decompressor.decompress(compressed, 0, restored, 0, decompressedLength);
|
||||||
|
|
||||||
|
return ItemTagStream.INSTANCE.fromBytes(restored);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ placeholder_api_version=2.11.6
|
|||||||
invui_version=1.32
|
invui_version=1.32
|
||||||
vault_version=1.7
|
vault_version=1.7
|
||||||
guava_version=33.2.0-jre
|
guava_version=33.2.0-jre
|
||||||
|
lz4_version=1.8.0
|
||||||
|
|
||||||
# Proxy settings
|
# Proxy settings
|
||||||
systemProp.socks.proxyHost=127.0.0.1
|
systemProp.socks.proxyHost=127.0.0.1
|
||||||
|
|||||||
Reference in New Issue
Block a user