Skip to content

Commit

Permalink
[2.0.0-dev21]将插件默认物品提供源分离,并调整其运行优先级
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Feb 7, 2024
1 parent 61ad31b commit 56d32de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "2.0.0-dev20"
version = "2.0.0-dev21"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum CraftorithmAPI {
INSTANCE;

public ItemStack getCraftorithmItem(String itemName) {
return CraftorithmItemProvider.INSTANCE.getItem(itemName);
return ItemManager.INSTANCE.defaultItemProvider.getItem(itemName);
}

public void regItemProvider(ItemProvider itemProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum ItemManager {

private final Map<String, ItemProvider> itemProviderMap;
private final Map<String, Integer> customCookingFuelMap;
public final ItemProvider defaultItemProvider = CraftorithmItemProvider.INSTANCE;
private final ConfigWrapper customFuelConfig = new ConfigWrapper(Craftorithm.instance(), "custom_fuels.yml");
private final String BURN_TIME_KEY = "burn_time";

Expand All @@ -35,14 +36,9 @@ public enum ItemManager {
}

public void loadItemManager() {
regDefaultProviders();
reloadCustomCookingFuel();
}

public void regDefaultProviders() {
regItemProvider(CraftorithmItemProvider.INSTANCE);
}

public void regItemProvider(ItemProvider itemProvider) {
Preconditions.checkArgument(
!itemProvider.namespace().equalsIgnoreCase(NamespacedKey.MINECRAFT),
Expand Down Expand Up @@ -73,7 +69,13 @@ public void regItemProvider(ItemProvider itemProvider) {
String namespace = itemKey.substring(0, index);
String name = itemKey.substring(index + 1);

ItemProvider provider = itemProviderMap.get(namespace);
ItemProvider provider;
if (namespace.equalsIgnoreCase("items")) {
provider = defaultItemProvider;
} else {
provider = itemProviderMap.get(namespace);
}

if (provider == null) {
return matchVanillaItem(itemKey, amountScale);
}
Expand Down Expand Up @@ -103,7 +105,7 @@ public String matchItemName(ItemStack item, boolean ignoreAmount) {
}
}

return null;
return defaultItemProvider.getItemName(item, ignoreAmount);
}

/**
Expand Down

0 comments on commit 56d32de

Please sign in to comment.