Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fr.maxlego08.menu.api.configuration;

import fr.maxlego08.menu.api.configuration.annotation.ConfigDialog;
import fr.maxlego08.menu.api.configuration.annotation.ConfigOption;
import fr.maxlego08.menu.api.configuration.annotation.ConfigUpdate;
import fr.maxlego08.menu.api.enums.DialogInputType;
import fr.maxlego08.menu.api.utils.OpGrantMethod;
import fr.maxlego08.menu.zcore.logger.Logger;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.inventory.ClickType;
Expand Down Expand Up @@ -274,6 +275,18 @@ public class Config {
label = "Enable player open inventory logs"
)
public static boolean enablePlayerOpenInventoryLogs = true;

@ConfigOption(
key = "enablePlayerCommandsAsOPAction",
type = DialogInputType.BOOLEAN,
trueText = "<green>Enabled",
falseText = "<red>Disabled",
label = "Enable player commands as OP action (requires server restart)"
)
public static boolean enablePlayerCommandsAsOPAction = false;

public static OpGrantMethod opGrantMethod = OpGrantMethod.ATTACHMENT;

public static boolean enableToast = true;
@ConfigUpdate
public static boolean updated = false;
Expand Down Expand Up @@ -351,6 +364,14 @@ public void load(FileConfiguration configuration) {

enableDownloadCommand = configuration.getBoolean(ConfigPath.ENABLE_DOWNLOAD_COMMAND.getPath());
enablePlayerOpenInventoryLogs = configuration.getBoolean(ConfigPath.ENABLE_PLAYER_OPEN_INVENTORY_LOGS.getPath());

enablePlayerCommandsAsOPAction = configuration.getBoolean(ConfigPath.ENABLE_PLAYER_COMMANDS_AS_OP_ACTION.getPath());
try {
opGrantMethod = OpGrantMethod.valueOf(configuration.getString(ConfigPath.OP_GRANT_METHOD.getPath(), OpGrantMethod.ATTACHMENT.name()).toUpperCase());
} catch (IllegalArgumentException e) {
Logger.info("Invalid op grant method in config, defaulting to ATTACHMENT.");
opGrantMethod = OpGrantMethod.ATTACHMENT;
}
enableToast = configuration.getBoolean(ConfigPath.ENABLE_TOAST.getPath());
}

Expand Down Expand Up @@ -443,7 +464,11 @@ private enum ConfigPath {

ENABLE_DOWNLOAD_COMMAND("enable-download-command"),
ENABLE_PLAYER_OPEN_INVENTORY_LOGS("enable-player-open-inventory-logs"),

ENABLE_PLAYER_COMMANDS_AS_OP_ACTION("enable-player-commands-as-op-action"),
OP_GRANT_METHOD("op-grant-method"),
ENABLE_TOAST("enable-toast");

private final String path;

ConfigPath(String path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package fr.maxlego08.menu.api.configuration;

import fr.maxlego08.menu.api.configuration.dialog.ConfigDialogBuilder;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public interface ConfigManagerInt {
<T> void registerConfig(Class<T> configClass, Plugin plugin);
<T> void registerConfig(@NotNull ConfigDialogBuilder configDialogBuilder, @NotNull Class<T> configClass, @NotNull Plugin plugin);
List<String> getRegisteredConfigs();
void openConfig(String pluginName, Player player);
void openConfig(Plugin plugin, Player player);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package fr.maxlego08.menu.api.configuration.dialog;

public class ConfigDialogBuilder {
private final String name;
private final String externalTitle;
private String yesText = "<green>Confirm";
private String yesTooltip = "";
private int yesWidth = 150;
private String noText = "<red>Cancel";
private String noTooltip = "";
private int noWidth = 150;
private String booleanConfirmText = "<white>%key% :</white> %value% <gray>|</gray> %text%";
private String numberRangeConfirmText= "<white>%key% :</white> %value%";
private String textConfirmText="<white>%key% : <gray>%text%";

public ConfigDialogBuilder(String name, String externalTitle) {
this.name = name;
this.externalTitle = externalTitle;
}

public ConfigDialogBuilder yesText(String yesText) {
this.yesText = yesText;
return this;
}

public ConfigDialogBuilder yesTooltip(String yesTooltip) {
this.yesTooltip = yesTooltip;
return this;
}

public ConfigDialogBuilder yesWidth(int yesWidth) {
this.yesWidth = yesWidth;
return this;
}

public ConfigDialogBuilder noText(String noText) {
this.noText = noText;
return this;
}

public ConfigDialogBuilder noTooltip(String noTooltip) {
this.noTooltip = noTooltip;
return this;
}

public ConfigDialogBuilder noWidth(int noWidth) {
this.noWidth = noWidth;
return this;
}

public ConfigDialogBuilder booleanConfirmText(String booleanConfirmText) {
this.booleanConfirmText = booleanConfirmText;
return this;
}

public ConfigDialogBuilder numberRangeConfirmText(String numberRangeConfirmText) {
this.numberRangeConfirmText = numberRangeConfirmText;
return this;
}

public ConfigDialogBuilder textConfirmText(String textConfirmText) {
this.textConfirmText = textConfirmText;
return this;
}

public String getName() {
return name;
}

public String getExternalTitle() {
return externalTitle;
}

public String getYesText() {
return yesText;
}

public String getYesTooltip() {
return yesTooltip;
}

public int getYesWidth() {
return yesWidth;
}

public String getNoText() {
return noText;
}

public String getNoTooltip() {
return noTooltip;
}

public int getNoWidth() {
return noWidth;
}

public String getBooleanConfirmText() {
return booleanConfirmText;
}

public String getNumberRangeConfirmText() {
return numberRangeConfirmText;
}

public String getTextConfirmText() {
return textConfirmText;
}
}
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;
}
}
8 changes: 6 additions & 2 deletions 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 @@ -252,6 +258,4 @@ public ItemStack getItemStack() {
public void setItemStack(ItemStack itemStack) {
this.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
Loading