其他方块系统

除了插件提供的oraxen和ItemsAdder兼容性之外,你还可以将customcrops适配到自己的服务器上,特别是对于一些具有独立开发能力的大型服务器。

要使您自己的插件适应自定义作物,您只需要实现两个类: AbstractCustomEventListenerCustomItemProvider

package net.momirealms.customcrops.api.example;

import net.momirealms.customcrops.api.core.AbstractCustomEventListener;
import net.momirealms.customcrops.api.core.AbstractItemManager;
import org.bukkit.event.EventHandler;

public class MyCustomListener extends AbstractCustomEventListener {

    public MyCustomListener(AbstractItemManager itemManager) {
        super(itemManager);
    }

    @EventHandler(ignoreCancelled = true)
    public void onInteractFurniture(FurnitureInteractEvent event) {
        itemManager.handlePlayerInteractFurniture(...);
    }

    @EventHandler(ignoreCancelled = true)
    public void onInteractCustomBlock(CustomBlockInteractEvent event) {
        itemManager.handlePlayerInteractBlock(...);
    }

    @EventHandler(ignoreCancelled = true)
    public void onBreakFurniture(FurnitureBreakEvent event) {
        itemManager.handlePlayerBreak(...);
    }

    @EventHandler(ignoreCancelled = true)
    public void onBreakCustomBlock(CustomBlockBreakEvent event) {
        itemManager.handlePlayerBreak(..);
    }
    
    @EventHandler(ignoreCancelled = true)
    public void onPlaceFurniture(FurniturePlaceEvent event) {
        itemManager.handlePlayerPlace(...);
    }
    
    @EventHandler(ignoreCancelled = true)
    public void onPlaceCustomBlock(CustomBlockPlaceEvent event) {
        itemManager.handlePlayerPlace(...);
    }
}
package net.momirealms.customcrops.api.example;

import net.momirealms.customcrops.api.core.CustomItemProvider;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;

public class MyCustomItemProvider implements CustomItemProvider {

    @Override
    public boolean removeCustomBlock(Location location) {
        return ...;
    }

    @Override
    public boolean placeCustomBlock(Location location, String id) {
        return ...;
    }

    @Override
    public @Nullable Entity placeFurniture(Location location, String id) {
        return ...;
    }

    @Override
    public boolean removeFurniture(Entity entity) {
        return ...;
    }

    @Override
    public @Nullable String blockID(Block block) {
        return ...;
    }

    @Override
    public @Nullable String itemID(ItemStack itemStack) {
        return ...;
    }

    @Override
    public @Nullable ItemStack itemStack(Player player, String id) {
        return ...;
    }

    @Override
    public @Nullable String furnitureID(Entity entity) {
        return ...;
    }

    @Override
    public boolean isFurniture(Entity entity) {
        return ...;
    }
}

最后,在插件启用上注册它们

package net.momirealms.customcrops.api.example;

import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
import net.momirealms.customcrops.api.core.AbstractItemManager;
import org.bukkit.plugin.java.JavaPlugin;

public class MyPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        register();
    }

    public void register() {
        AbstractItemManager itemManager = BukkitCustomCropsPlugin.getInstance().getItemManager();
        MyCustomListener listener = new MyCustomListener(itemManager);
        MyCustomItemProvider provider = new MyCustomItemProvider();
        itemManager.setCustomEventListener(listener);
        itemManager.setCustomItemProvider(provider);
    }
}

最后更新于