Skip to content

Commit

Permalink
use registry event, hide item group,
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Mar 21, 2024
1 parent b682812 commit 0a3608b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package dev.j3fftw.worldeditslimefun;

import dev.j3fftw.worldeditslimefun.commands.WorldEditSlimefunCommands;
import dev.j3fftw.worldeditslimefun.listeners.RegistryListener;
import dev.j3fftw.worldeditslimefun.slimefun.Items;
import dev.j3fftw.worldeditslimefun.slimefun.WandListener;
import dev.j3fftw.worldeditslimefun.listeners.WandListener;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.libraries.dough.updater.BlobBuildUpdater;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import javax.annotation.Nonnull;
Expand All @@ -32,7 +34,10 @@ public void onEnable() {

Items.init(this);
WorldEditSlimefunCommands.init(this);
Bukkit.getPluginManager().registerEvents(new WandListener(), this);

PluginManager manager = Bukkit.getPluginManager();
manager.registerEvents(new WandListener(), this);
manager.registerEvents(new RegistryListener(), this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.j3fftw.worldeditslimefun.listeners;

import dev.j3fftw.worldeditslimefun.utils.Utils;
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemRegistryFinalizedEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;

public class RegistryListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onRegistryInitialized(SlimefunItemRegistryFinalizedEvent event) {
Utils.init();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.j3fftw.worldeditslimefun.slimefun;
package dev.j3fftw.worldeditslimefun.listeners;

import dev.j3fftw.worldeditslimefun.utils.PositionManager;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/dev/j3fftw/worldeditslimefun/slimefun/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;

public class Items {
public static void init(WorldEditSlimefun plugin) {
ItemGroup WESF_GROUP = new ItemGroup(
new NamespacedKey(plugin, "world_edit_slimefun"),
new CustomItemStack(Material.STONE_AXE, "&fWorld Edit Slimefun (Dummy Group)")
);
new CustomItemStack(Material.STONE_AXE, "&fWorld Edit Slimefun")
) {
@Override
public boolean isVisible(@Nonnull Player ignored) {
return false;
}
};

new SlimefunItem(
WESF_GROUP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Utils {
public static final List<String> SLIMEFUN_ITEMS = new ArrayList<>();
public static final Map<String, Material> MATERIALS = new HashMap<>();

static {
public static void init() {
for (SlimefunItem item : Slimefun.getRegistry().getEnabledSlimefunItems()) {
if (!(item instanceof UnplaceableBlock) && item.getItem().getType().isBlock()) {
SLIMEFUN_BLOCKS.add(item.getId());
Expand Down

0 comments on commit 0a3608b

Please sign in to comment.