-
Notifications
You must be signed in to change notification settings - Fork 31
Custom Item Management System #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
84e23d5
feat: add support to create custom items + command
1robie ed3e542
feat: move messages in GiveItemCommand to Message.java and add a defa…
1robie e5080eb
feat: fix owner + space after implement
1robie 8434b5d
refactor: remove unnecessary newline
1robie 851a2e0
chore: update version
1robie 3ef1e32
fix: resolve false positive detection caused by annotation
1robie 5f9565c
Merge branch 'Maxlego08:main' into developement
1robie 31b6e5c
chore: update Paper and Spigot API dependencies to 1.21.10
1robie c99453c
Merge branch 'develop' into developement
1robie 7e29cd3
feat: add player commands as OP action and BreweryX support
1robie cdf5b34
feat: add BOTH method for op-granting in config and OpGrantMethod
1robie eefe5d5
Merge branch 'develop' into developement
Maxlego08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
API/src/main/java/fr/maxlego08/menu/api/configuration/ConfigManagerInt.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
API/src/main/java/fr/maxlego08/menu/api/configuration/annotation/ConfigDialog.java
This file was deleted.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
API/src/main/java/fr/maxlego08/menu/api/configuration/dialog/ConfigDialogBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
27
API/src/main/java/fr/maxlego08/menu/api/mechanic/Mechanic.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
API/src/main/java/fr/maxlego08/menu/api/mechanic/MechanicFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
API/src/main/java/fr/maxlego08/menu/api/mechanic/MechanicListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.