Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions API/src/main/java/fr/maxlego08/menu/api/ItemManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fr.maxlego08.menu.api;

import fr.maxlego08.menu.api.mechanic.MechanicFactory;
import fr.maxlego08.menu.api.mechanic.MechanicListener;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;

import java.io.File;
import java.util.Optional;
import java.util.Set;

public interface ItemManager {

void loadAll();

void loadCustomItems();

void loadCustomItem(File file);

void reloadCustomItems();

boolean isCustomItem(String itemId);

boolean isCustomItem(ItemStack itemStack);

Optional<String> getItemId(ItemStack itemStack);

Set<String> getItemIds();

void registerListeners(Plugin plugin, String mechanicId, MechanicListener listener);

void unloadListeners();

void registerMechanicFactory(MechanicFactory factory);

void giveItem(Player player, String itemId);

void executeCheckInventoryItems(Player player);
}
2 changes: 2 additions & 0 deletions API/src/main/java/fr/maxlego08/menu/api/MenuPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,6 @@ public interface MenuPlugin extends Plugin {
ToastHelper getToastHelper();

DialogManager getDialogManager();

ItemManager getItemManager();
}
27 changes: 27 additions & 0 deletions API/src/main/java/fr/maxlego08/menu/api/mechanic/Mechanic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fr.maxlego08.menu.api.mechanic;

import org.bukkit.configuration.ConfigurationSection;

public abstract class Mechanic {
private final ConfigurationSection mechanicSection;
private final MechanicFactory mechanicFactory;
private final String itemId;

public Mechanic(final String itemId, final MechanicFactory mechanicFactory, final ConfigurationSection mechanicSection) {
this.mechanicFactory = mechanicFactory;
this.mechanicSection = mechanicSection;
this.itemId = itemId;
}

public ConfigurationSection getMechanicSection() {
return mechanicSection;
}

public MechanicFactory getMechanicFactory() {
return mechanicFactory;
}

public String getItemId() {
return itemId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package fr.maxlego08.menu.api.mechanic;

import fr.maxlego08.menu.api.ItemManager;
import fr.maxlego08.menu.api.MenuPlugin;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

public abstract class MechanicFactory {
private final MenuPlugin plugin;
private final ItemManager itemManager;
private final String mechanicId;
private final Map<String, Mechanic> mechanicByItemId = new HashMap<>();

public MechanicFactory(MenuPlugin plugin, String mechanicId) {
this.plugin = plugin;
this.mechanicId = mechanicId;
this.itemManager = plugin.getItemManager();
}

public abstract Mechanic parse(final MenuPlugin plugin, final String itemId, final ConfigurationSection mechanicSection, YamlConfiguration configurationFile, File file, String path);

public Mechanic getMechanic(String itemId){
return mechanicByItemId.get(itemId);
};

public void addToImplemented(Mechanic mechanic) {
mechanicByItemId.put(mechanic.getItemId(), mechanic);
}

public boolean isNotImplementedIn(ItemStack itemStack) {
Optional<String> itemId = itemManager.getItemId(itemStack);
return itemId.filter(string -> !mechanicByItemId.containsKey(string)).isPresent();
}

public boolean isNotImplementedIn(String itemID) {
return !mechanicByItemId.containsKey(itemID);
}

public String getMechanicId() {
return mechanicId;
}

public Set<Map.Entry<String, Mechanic>> getAllMechanics(){
return mechanicByItemId.entrySet();
}

public void clearMechanics() {
mechanicByItemId.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.maxlego08.menu.api.mechanic;

import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;

public abstract class MechanicListener implements Listener {

/*
* Called when an item with the mechanic is given to a player.
* Return true to cancel the item giving, false to allow it.
*/
public boolean onItemGive(Player player, ItemStack item, String itemId) {
return false;
}
}
7 changes: 6 additions & 1 deletion API/src/main/java/fr/maxlego08/menu/api/utils/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum Message implements IMessage {
COMMAND_NO_CONSOLE("&cOnly one player can execute this command."),
COMMAND_NO_ARG("&cImpossible to find the command with its arguments."),
COMMAND_SYNTAX_HELP("&f%syntax% &7» &7%description%"),
COMMAND_PLAYER_NOT_FOUND("&cUnable to find the player &f%player%&c."),
DOCUMENTATION_INFORMATION("&7Documentation&8: &fhttps://docs.zmenu.dev/"),
DOCUMENTATION_INFORMATION_LINK("&7Documentation&8: &f%link%"),
ADDONS_INFORMATION("&7Official addons :"),
Expand Down Expand Up @@ -97,6 +98,7 @@ public enum Message implements IMessage {
DESCRIPTION_ADDONS("List of official addons"),
DESCRIPTION_DUMPLOG("Generate a dumplog file for support"),
DESCRIPTION_CONTRIBUTORS("List of authors and contributors of the plugin"),
DESCRIPTION_GIVE_ITEM("Give a custom item to a player"),

RELOAD("&aYou have just reloaded the configuration files. &8(&7%inventories% inventories&8)"),
RELOAD_INVENTORY("&aYou have just reloaded the inventories files. &8(&7%inventories% inventories&8)"),
Expand All @@ -110,6 +112,10 @@ public enum Message implements IMessage {
DUMPLOG_SUCCESS("&aYou have just generated a dumplog file, please send this link to support: &f%url%"),
DUMPLOG_ERROR("&cAn error occurred while generating the dumplog file, %error%."),

GIVE_ITEM_NOT_FOUND("&cItem with ID &f%itemId%&c does not exist."),
GIVE_ITEM_SUCCESS_SELF("&aYou have received the item &f%itemId%&a."),
GIVE_ITEM_SUCCESS_OTHER("&aYou have given the item &f%itemId%&a to &3%player%&a."),

PLAYERS_DATA_CLEAR_ALL("&aYou have just deleted the datas of all the players."),
PLAYERS_DATA_CLEAR_PLAYER("&aYou have just deleted the player's data &f%player%&a."),

Expand Down Expand Up @@ -254,4 +260,3 @@ public void setItemStack(ItemStack itemStack) {
}

}
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing empty line should be removed from the end of the file for cleaner formatting.

Copilot uses AI. Check for mistakes.

Loading