Other Block System

In addition to the oraxen and ItemsAdder compatibility provided by the plugin, you can also adapt customcrops to your own server, especially for some large servers with independent development capabilities.

To adapt your own plugin to customcrops you only need to implement two classes: AbstractCustomEventListener & CustomItemProvider

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 ...;
    }
}

At last, register them on plugin enable

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);
    }
}

Last updated