mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-27 19:09:09 +00:00
API improvements
This commit is contained in:
@@ -229,6 +229,16 @@ public abstract class BukkitCustomCropsPlugin implements CustomCropsPlugin {
|
||||
return (RequirementManager<T>) instance.requirementManagers.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the config manager
|
||||
*
|
||||
* @return the config manager
|
||||
*/
|
||||
@Override
|
||||
public ConfigManager getConfigManager() {
|
||||
return configManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a debug message.
|
||||
*
|
||||
|
||||
@@ -91,6 +91,6 @@ public class BuiltInBlockMechanics {
|
||||
* @return the CustomCropsBlock
|
||||
*/
|
||||
public CustomCropsBlock mechanic() {
|
||||
return Objects.requireNonNull(Registries.BLOCK.get(key));
|
||||
return Objects.requireNonNull(InternalRegistries.BLOCK.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,6 @@ public class BuiltInItemMechanics {
|
||||
* @return the CustomCropsItem
|
||||
*/
|
||||
public CustomCropsItem mechanic() {
|
||||
return Registries.ITEM.get(key);
|
||||
return InternalRegistries.ITEM.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
|
||||
if (section.getBoolean("enable")) {
|
||||
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof Section innerSection) {
|
||||
FertilizerType type = Registries.FERTILIZER_TYPE.get(entry.getKey().replace("-", "_"));
|
||||
FertilizerType type = InternalRegistries.FERTILIZER_TYPE.get(entry.getKey().replace("-", "_"));
|
||||
if (type != null) {
|
||||
map.put(type, Pair.of(
|
||||
Preconditions.checkNotNull(innerSection.getString("dry"), entry.getKey() + ".dry should not be null"),
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.momirealms.customcrops.api.core;
|
||||
|
||||
import net.momirealms.customcrops.api.core.block.CustomCropsBlock;
|
||||
import net.momirealms.customcrops.api.core.item.CustomCropsItem;
|
||||
import net.momirealms.customcrops.api.core.mechanic.fertilizer.FertilizerType;
|
||||
import net.momirealms.customcrops.common.annotation.DoNotUse;
|
||||
import net.momirealms.customcrops.common.util.Key;
|
||||
|
||||
@DoNotUse(message = "Internal use only. Avoid using this class directly.")
|
||||
@Deprecated(since = "3.6", forRemoval = false)
|
||||
public class InternalRegistries {
|
||||
|
||||
public static final WriteableRegistry<Key, CustomCropsBlock> BLOCK = new MappedRegistry<>(Key.key("mechanic", "block"));
|
||||
public static final WriteableRegistry<Key, CustomCropsItem> ITEM = new MappedRegistry<>(Key.key("mechanic", "item"));
|
||||
public static final WriteableRegistry<String, FertilizerType> FERTILIZER_TYPE = new ClearableMappedRegistry<>(Key.key("mechanic", "fertilizer_type"));
|
||||
}
|
||||
@@ -21,11 +21,9 @@ import net.momirealms.customcrops.api.core.block.CustomCropsBlock;
|
||||
import net.momirealms.customcrops.api.core.item.CustomCropsItem;
|
||||
import net.momirealms.customcrops.api.core.mechanic.crop.CropConfig;
|
||||
import net.momirealms.customcrops.api.core.mechanic.fertilizer.FertilizerConfig;
|
||||
import net.momirealms.customcrops.api.core.mechanic.fertilizer.FertilizerType;
|
||||
import net.momirealms.customcrops.api.core.mechanic.pot.PotConfig;
|
||||
import net.momirealms.customcrops.api.core.mechanic.sprinkler.SprinklerConfig;
|
||||
import net.momirealms.customcrops.api.core.mechanic.wateringcan.WateringCanConfig;
|
||||
import net.momirealms.customcrops.common.annotation.DoNotUse;
|
||||
import net.momirealms.customcrops.common.util.Key;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@@ -34,15 +32,7 @@ import java.util.List;
|
||||
@ApiStatus.Internal
|
||||
public class Registries {
|
||||
|
||||
@DoNotUse
|
||||
public static final WriteableRegistry<Key, CustomCropsBlock> BLOCK = new MappedRegistry<>(Key.key("mechanic", "block"));
|
||||
@DoNotUse
|
||||
public static final WriteableRegistry<Key, CustomCropsItem> ITEM = new MappedRegistry<>(Key.key("mechanic", "item"));
|
||||
@DoNotUse
|
||||
public static final WriteableRegistry<String, FertilizerType> FERTILIZER_TYPE = new ClearableMappedRegistry<>(Key.key("mechanic", "fertilizer_type"));
|
||||
@DoNotUse
|
||||
public static final ClearableRegistry<String, CustomCropsBlock> BLOCKS = new ClearableMappedRegistry<>(Key.key("internal", "blocks"));
|
||||
@DoNotUse
|
||||
public static final ClearableRegistry<String, CustomCropsItem> ITEMS = new ClearableMappedRegistry<>(Key.key("internal", "items"));
|
||||
|
||||
public static final ClearableRegistry<String, SprinklerConfig> SPRINKLER = new ClearableMappedRegistry<>(Key.key("config", "sprinkler"));
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.customcrops.api.core.item.CustomCropsItem;
|
||||
import net.momirealms.customcrops.api.core.mechanic.fertilizer.FertilizerType;
|
||||
import net.momirealms.customcrops.common.util.Key;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SimpleRegistryAccess implements RegistryAccess {
|
||||
|
||||
private boolean frozen;
|
||||
@@ -45,33 +46,33 @@ public class SimpleRegistryAccess implements RegistryAccess {
|
||||
@Override
|
||||
public void registerBlockMechanic(CustomCropsBlock block) {
|
||||
if (frozen) throw new RuntimeException("Registries are frozen");
|
||||
Registries.BLOCK.register(block.type(), block);
|
||||
InternalRegistries.BLOCK.register(block.type(), block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerItemMechanic(CustomCropsItem item) {
|
||||
if (frozen) throw new RuntimeException("Registries are frozen");
|
||||
Registries.ITEM.register(item.type(), item);
|
||||
InternalRegistries.ITEM.register(item.type(), item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFertilizerType(FertilizerType type) {
|
||||
if (frozen) throw new RuntimeException("Registries are frozen");
|
||||
Registries.FERTILIZER_TYPE.register(type.id(), type);
|
||||
InternalRegistries.FERTILIZER_TYPE.register(type.id(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<Key, CustomCropsBlock> getBlockRegistry() {
|
||||
return Registries.BLOCK;
|
||||
return InternalRegistries.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<Key, CustomCropsItem> getItemRegistry() {
|
||||
return Registries.ITEM;
|
||||
return InternalRegistries.ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, FertilizerType> getFertilizerTypeRegistry() {
|
||||
return Registries.FERTILIZER_TYPE;
|
||||
return InternalRegistries.FERTILIZER_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
Reference in New Issue
Block a user