perf(hamster-core-bukkit): 优化代码
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
plugins {
|
||||
id 'com.github.johnrengelman.shadow' version '7.1.2'
|
||||
}
|
||||
setArchivesBaseName("HamsterCore-Bukkit")
|
||||
|
||||
evaluationDependsOn(':hamster-core-common')
|
||||
@@ -10,20 +13,17 @@ dependencies {
|
||||
api project(":hamster-core-common") transitive false
|
||||
shade project(":hamster-core-common") transitive false
|
||||
|
||||
implementation "de.tr7zw:item-nbt-api:2.11.2"
|
||||
|
||||
//noinspection VulnerableLibrariesLocal
|
||||
compileOnly 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT' exclude group: "com.google.code.gson"
|
||||
|
||||
compileOnly 'net.milkbowl.vault:VaultAPI:1.7' transitive false
|
||||
compileOnly 'org.black_ixx:playerpoints:2.1.3' transitive false
|
||||
compileOnly "com.comphenix.protocol:ProtocolLib-API:4.4.0" transitive false
|
||||
|
||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||
//noinspection GradlePackageUpdate
|
||||
//noinspection VulnerableLibrariesLocal
|
||||
compileOnly 'com.google.code.gson:gson:2.8.0'
|
||||
|
||||
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-bukkit
|
||||
api "net.kyori:adventure-platform-bukkit:${adventure_version}"
|
||||
//noinspection VulnerableLibrariesLocal
|
||||
oldJar "net.kyori:adventure-platform-bukkit:${adventure_version}"
|
||||
// https://mvnrepository.com/artifact/net.kyori/adventure-text-minimessage
|
||||
api "net.kyori:adventure-text-minimessage:${adventure_serializer_version}"
|
||||
@@ -52,18 +52,17 @@ processResources {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
tasks.compileJava.dependsOn(":hamster-core-common:build")
|
||||
tasks.register("shadowJar", Jar) {
|
||||
dependsOn("jar")
|
||||
from([
|
||||
tasks.jar.outputs.files.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
},
|
||||
configurations.shade.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
shadowJar {
|
||||
//noinspection GrDeprecatedAPIUsage
|
||||
classifier = ""
|
||||
dependencies {
|
||||
exclude(dependency {
|
||||
it.moduleGroup != 'cn.hamster3.mc.plugin.core' && it.moduleGroup != 'de.tr7zw'
|
||||
})
|
||||
}
|
||||
])
|
||||
relocate 'de.tr7zw.changeme.nbtapi', 'cn.hamster3.mc.plugin.core.bukkit.nbtapi'
|
||||
relocate 'de.tr7zw.annotations', 'cn.hamster3.mc.plugin.core.bukkit.nbtapi.annotations'
|
||||
destinationDir(getRootProject().buildDir)
|
||||
}
|
||||
tasks.build.dependsOn(shadowJar)
|
||||
|
@@ -2,8 +2,9 @@ package cn.hamster3.mc.plugin.core.bukkit.util;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bukkit.listener.CallbackListener;
|
||||
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||
import com.comphenix.protocol.utility.StreamSerializer;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.tr7zw.changeme.nbtapi.NBTContainer;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -236,36 +237,20 @@ public final class CoreBukkitUtils {
|
||||
|
||||
@NotNull
|
||||
public static String serializeItemStack(@NotNull ItemStack stack) {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
throw new RuntimeException("ProtocolLib 前置插件未启用, 无法序列化物品!");
|
||||
}
|
||||
try {
|
||||
return StreamSerializer.getDefault().serializeItemStack(stack);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("序列化物品时出现了一个异常!", e);
|
||||
}
|
||||
NBTContainer container = NBTItem.convertItemtoNBT(stack);
|
||||
return container.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ItemStack deserializeItemStack(@NotNull String s) {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
throw new RuntimeException("ProtocolLib 前置插件未启用, 无法反序列化物品!");
|
||||
}
|
||||
try {
|
||||
return StreamSerializer.getDefault().deserializeItemStack(s);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("反序列化物品时出现了一个异常!", e);
|
||||
}
|
||||
return NBTItem.convertNBTtoItem(new NBTContainer(s));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ItemStack deserializeItemStack(@NotNull String s, @NotNull ItemStack defaultValue) {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return StreamSerializer.getDefault().deserializeItemStack(s);
|
||||
} catch (IOException e) {
|
||||
return NBTItem.convertNBTtoItem(new NBTContainer(s));
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ load: STARTUP
|
||||
softdepend:
|
||||
- Vault
|
||||
- PlayerPoints
|
||||
- ProtocolLib
|
||||
- NBTAPI
|
||||
|
||||
loadbefore:
|
||||
- HamsterAPI
|
||||
|
Reference in New Issue
Block a user