Skip to content

Commit

Permalink
[1.9.6-dev1]不再使用NBT存储物品,改用Bukkit的物品系统,兼容1.20.5/1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Jun 7, 2024
1 parent ae82a5a commit c223e0c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
8 changes: 6 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.9.5"
version = "1.9.6-dev1"

plugins {
`java-library`
Expand All @@ -24,6 +24,8 @@ repositories {
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
//EcoEnchants
maven("https://repo.auxilor.io/repository/maven-public/")
//NBT-API
maven("https://repo.codemc.io/repository/maven-public/")
mavenCentral()
}

Expand All @@ -43,7 +45,8 @@ dependencies {
compileOnly("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT")
compileOnly("net.Indyuce:MMOItems-API:6.9.5-SNAPSHOT")
compileOnly("com.willfp:EcoEnchants:12.5.1")
implementation("com.crypticlib:CrypticLib:0.17.10")
implementation("com.crypticlib:CrypticLib:0.18.0")
// implementation("de.tr7zw:item-nbt-api:2.12.4")
}

group = "com.github.yufiriamazenta"
Expand Down Expand Up @@ -77,5 +80,6 @@ tasks {
shadowJar {
archiveFileName.set("Craftorithm-$version.jar")
relocate("crypticlib", "com.github.yufiriamazenta.craftorithm.crypticlib")
relocate("de.tr7zw.changeme.nbtapi", "com.github.yufiriamazenta.craftorithm.nbtapi")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import com.github.yufiriamazenta.craftorithm.util.CollectionsUtil;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import crypticlib.config.ConfigWrapper;
import crypticlib.nms.item.ItemFactory;
import crypticlib.nms.item.NbtItem;
import crypticlib.util.FileUtil;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -97,22 +94,20 @@ private void loadItems() {
ConfigWrapper itemFile = itemConfigFileMap.get(namespace);
Set<String> itemKeySet = itemFile.config().getKeys(false);
for (String itemKey : itemKeySet) {
ConfigurationSection config = itemFile.config().getConfigurationSection(itemKey);
loadItem(namespace + ":" + itemKey, config);
try {
ItemStack item = itemFile.config().getItemStack(itemKey);
if (item == null) {
throw new NullPointerException("Item " + itemKey + " is null");
}
itemMap.put(itemKey, item);
} catch (Exception e) {
LangUtil.info(Languages.LOAD_ITEM_LOAD_EXCEPTION, CollectionsUtil.newStringHashMap("<item_name>", itemKey));
e.printStackTrace();
}
}
}
}

private void loadItem(String itemKey, ConfigurationSection config) {
try {
NbtItem item = ItemFactory.item(config);
ItemStack bukkitItem = item.saveNbtToItem();
itemMap.put(itemKey, bukkitItem);
} catch (Exception e) {
LangUtil.info(Languages.LOAD_ITEM_LOAD_EXCEPTION, CollectionsUtil.newStringHashMap("<item_name>", itemKey));
e.printStackTrace();
}
}

public String regCraftorithmItem(String namespace, String itemName, ItemStack item) {
ConfigWrapper itemConfigFile;
Expand All @@ -126,8 +121,7 @@ public String regCraftorithmItem(String namespace, String itemName, ItemStack it
} else {
itemConfigFile = itemConfigFileMap.get(namespace);
}
NbtItem nbtItem = ItemFactory.item(item);
itemConfigFile.set(itemName, nbtItem.toMap());
itemConfigFile.set(itemName, item);
itemConfigFile.saveConfig();
String key = namespace + ":" + itemName;
itemMap.put(key, item);
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/items/example_item.yml
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
example_item:
material: STONE_PICKAXE
amount: 10
nbt:
Damage: 78

0 comments on commit c223e0c

Please sign in to comment.