mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 17:39:30 +00:00
添加api方法
This commit is contained in:
@@ -27,10 +27,28 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class CraftEngineBlocks {
|
||||
|
||||
private CraftEngineBlocks() {}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns an unmodifiable map of all currently loaded custom blocks.
|
||||
* The map keys represent unique identifiers, and the values are the corresponding CustomBlock instances.
|
||||
*
|
||||
* <p><strong>Important:</strong> Do not attempt to access this method during the onEnable phase
|
||||
* as it will be empty. Instead, listen for the {@code CraftEngineReloadEvent} and use this method
|
||||
* after the event is fired to obtain the complete block list.
|
||||
*
|
||||
* @return a non-null map containing all loaded custom blocks
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<Key, CustomBlock> loadedBlocks() {
|
||||
return BukkitBlockManager.instance().loadedBlocks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a custom block by ID
|
||||
*
|
||||
|
||||
@@ -27,11 +27,27 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CraftEngineFurniture {
|
||||
|
||||
private CraftEngineFurniture() {}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable map of all currently loaded custom furniture.
|
||||
* The map keys represent unique identifiers, and the values are the corresponding CustomFurniture instances.
|
||||
*
|
||||
* <p><strong>Important:</strong> Do not attempt to access this method during the onEnable phase
|
||||
* as it will be empty. Instead, listen for the {@code CraftEngineReloadEvent} and use this method
|
||||
* after the event is fired to obtain the complete furniture list.
|
||||
*
|
||||
* @return a non-null map containing all loaded custom furniture
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<Key, CustomFurniture> loadedFurniture() {
|
||||
return BukkitFurnitureManager.instance().loadedFurniture();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets custom furniture by ID
|
||||
*
|
||||
|
||||
@@ -8,10 +8,28 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class CraftEngineItems {
|
||||
|
||||
private CraftEngineItems() {}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable map of all currently loaded custom items.
|
||||
* The map keys represent unique identifiers, and the values are the corresponding CustomItem instances.
|
||||
*
|
||||
* <p><strong>Important:</strong> Do not attempt to access this method during the onEnable phase
|
||||
* as it will be empty. Instead, listen for the {@code CraftEngineReloadEvent} and use this method
|
||||
* after the event is fired to obtain the complete item list.
|
||||
*
|
||||
* @return a non-null map containing all loaded custom items
|
||||
* @throws IllegalStateException if the BukkitItemManager instance is not available
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<Key, CustomItem<ItemStack>> loadedItems() {
|
||||
return BukkitItemManager.instance().loadedItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a custom item by ID
|
||||
*
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Key, CustomBlock> blocks() {
|
||||
public Map<Key, CustomBlock> loadedBlocks() {
|
||||
return Collections.unmodifiableMap(this.byId);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,12 @@ public interface BlockManager extends Manageable, ModelGenerator {
|
||||
|
||||
Map<Key, JsonElement> modBlockStates();
|
||||
|
||||
Map<Key, CustomBlock> blocks();
|
||||
Map<Key, CustomBlock> loadedBlocks();
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
default Map<Key, CustomBlock> blocks() {
|
||||
return loadedBlocks();
|
||||
}
|
||||
|
||||
Optional<CustomBlock> blockById(Key key);
|
||||
|
||||
|
||||
@@ -58,6 +58,11 @@ public abstract class AbstractFurnitureManager implements FurnitureManager {
|
||||
return Optional.ofNullable(this.byId.get(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Key, CustomFurniture> loadedFurniture() {
|
||||
return Collections.unmodifiableMap(this.byId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.byId.clear();
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface FurnitureManager extends Manageable {
|
||||
@@ -30,6 +31,8 @@ public interface FurnitureManager extends Manageable {
|
||||
|
||||
Optional<CustomFurniture> furnitureById(Key id);
|
||||
|
||||
Map<Key, CustomFurniture> loadedFurniture();
|
||||
|
||||
boolean isFurnitureRealEntity(int entityId);
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -229,8 +229,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Key> items() {
|
||||
return Collections.unmodifiableCollection(this.customItemsById.keySet());
|
||||
public Map<Key, CustomItem<I>> loadedItems() {
|
||||
return Collections.unmodifiableMap(this.customItemsById);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,10 @@ import java.util.Optional;
|
||||
|
||||
public interface CustomItem<I> extends BuildableItem<I> {
|
||||
|
||||
/**
|
||||
* Since CraftEngine allows users to add certain functionalities to vanilla items, this custom item might actually be a vanilla item.
|
||||
* This will be refactored before the 1.0 release, but no changes will be made for now to ensure compatibility.
|
||||
*/
|
||||
boolean isVanillaItem();
|
||||
|
||||
Key id();
|
||||
|
||||
@@ -54,7 +54,12 @@ public interface ItemManager<T> extends Manageable, ModelGenerator {
|
||||
|
||||
Item<T> fromByteArray(byte[] bytes);
|
||||
|
||||
Collection<Key> items();
|
||||
Map<Key, CustomItem<T>> loadedItems();
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
default Collection<Key> items() {
|
||||
return loadedItems().keySet();
|
||||
}
|
||||
|
||||
ExternalItemSource<T> getExternalItemSource(String name);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.core.world;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.collection.MultiThreadedQueue;
|
||||
import ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable;
|
||||
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
|
||||
Reference in New Issue
Block a user