Skip to content

Commit e426a40

Browse files
committed
🚧 Add toast action
1 parent 0708507 commit e426a40

File tree

14 files changed

+983
-4
lines changed

14 files changed

+983
-4
lines changed

API/src/main/java/fr/maxlego08/menu/api/MenuPlugin.java

Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import fr.maxlego08.menu.api.players.inventory.InventoriesPlayer;
1212
import fr.maxlego08.menu.api.storage.StorageManager;
1313
import fr.maxlego08.menu.api.utils.MetaUpdater;
14+
import fr.maxlego08.menu.api.utils.toast.ToastHelper;
1415
import org.bukkit.OfflinePlayer;
1516
import org.bukkit.configuration.file.YamlConfiguration;
1617
import org.bukkit.entity.Player;
@@ -22,44 +23,194 @@
2223

2324
public interface MenuPlugin extends Plugin {
2425

26+
/**
27+
* Retrieves the scheduler associated with this plugin.
28+
* This scheduler is responsible for running tasks asynchronously.
29+
*
30+
* @return the scheduler.
31+
*/
2532
PlatformScheduler getScheduler();
2633

34+
/**
35+
* Retrieves the manager responsible for handling inventory-related operations.
36+
* This manager provides methods for creating, managing and retrieving inventories.
37+
*
38+
* @return the inventory manager.
39+
*/
2740
InventoryManager getInventoryManager();
2841

42+
/**
43+
* Retrieves the manager responsible for handling button-related operations.
44+
* This manager provides methods for managing button states and interactions.
45+
*
46+
* @return the button manager.
47+
*/
2948
ButtonManager getButtonManager();
3049

50+
/**
51+
* Returns the instance of the pattern manager.
52+
*
53+
* @return the pattern manager.
54+
*/
3155
PatternManager getPatternManager();
3256

33-
<T> T getProvider(Class<T> headManagerClass);
57+
/**
58+
* Retrieves a service provider of the specified class type.
59+
*
60+
* @param classPath the class type of the provider to retrieve.
61+
* @param <T> the type of the service provider.
62+
*/
63+
<T> T getProvider(Class<T> classPath);
3464

65+
/**
66+
* Replaces placeholders in the given string with actual values for the given player.
67+
* Placeholders are specified in the format %placeholder% and are replaced with actual values.
68+
* If the placeholder does not exist, the placeholder is kept as is.
69+
*
70+
* @param player the player to substitute placeholders for.
71+
* @param string the string to replace placeholders in.
72+
* @return a string with placeholders replaced.
73+
*/
3574
String parse(Player player, String string);
3675

76+
/**
77+
* Replaces placeholders in the given string with actual values for the given offline player.
78+
* Placeholders are specified in the format %placeholder% and are replaced with actual values.
79+
* If the placeholder does not exist, the placeholder is kept as is.
80+
*
81+
* @param offlinePlayer the offline player to substitute placeholders for.
82+
* @param string the string to replace placeholders in.
83+
* @return a string with placeholders replaced.
84+
*/
3785
String parse(OfflinePlayer offlinePlayer, String string);
3886

87+
/**
88+
* Replaces placeholders in a list of strings with actual values for the given player.
89+
* Placeholders are specified in the format %placeholder% and are replaced with actual values.
90+
* If the placeholder does not exist, the placeholder is kept as is.
91+
*
92+
* @param player the player to substitute placeholders for.
93+
* @param strings the list of strings to replace placeholders in.
94+
* @return a list of strings with placeholders replaced.
95+
*/
3996
List<String> parse(Player player, List<String> strings);
4097

98+
/**
99+
* Replaces placeholders in a list of strings with actual values for the given offline player.
100+
* Placeholders are specified in the format %placeholder% and are replaced with actual values.
101+
* If the placeholder does not exist, the placeholder is kept as is.
102+
*
103+
* @param offlinePlayer the player to substitute placeholders for.
104+
* @param strings the list of strings to replace placeholders in.
105+
* @return a list of strings with placeholders replaced.
106+
*/
41107
List<String> parse(OfflinePlayer offlinePlayer, List<String> strings);
42108

109+
/**
110+
* Retrieves the manager responsible for player inventory related operations.
111+
* This manager provides methods for managing player inventory state,
112+
* such as saving, loading, and clearing inventories.
113+
*
114+
* @return The manager responsible for player inventory related operations.
115+
*/
43116
InventoriesPlayer getInventoriesPlayer();
44117

118+
/**
119+
* Retrieves a map of global placeholders.
120+
* This method returns a map where the keys are placeholder strings
121+
* and the values are the corresponding objects.
122+
* These placeholders are used for dynamic content replacement
123+
* throughout the plugin.
124+
*
125+
* @return A map containing global placeholders and their values.
126+
*/
45127
Map<String, Object> getGlobalPlaceholders();
46128

129+
/**
130+
* Retrieves the font image utility for managing custom fonts.
131+
*
132+
* @return An instance of {@link FontImage} for handling font images.
133+
*/
47134
FontImage getFontImage();
48135

136+
/**
137+
* Returns the data manager.
138+
* This method returns the data manager, which is used for managing data related to players.
139+
* The data manager is used for managing data related to players.
140+
*
141+
* @return the data manager
142+
*/
49143
DataManager getDataManager();
50144

145+
/**
146+
* Returns the dupe manager.
147+
* This method returns the dupe manager, which is responsible for managing
148+
* the duplication detection and protection logic within the plugin.
149+
* The dupe manager can be used to check if items are duplicated and to
150+
* apply protection against duplication exploits.
151+
*
152+
* @return the dupe manager
153+
*/
51154
DupeManager getDupeManager();
52155

156+
/**
157+
* Returns the enchantments manager.
158+
* This method returns the enchantments manager, which is used for managing custom enchantments.
159+
* The enchantments manager is used for managing custom enchantments.
160+
*
161+
* @return the enchantments manager
162+
*/
53163
Enchantments getEnchantments();
54164

165+
/**
166+
* Returns the meta updater.
167+
* This method returns the meta updater, which is used for updating the item meta.
168+
* The meta updater is used for updating the item meta.
169+
*
170+
* @return the meta updater
171+
*/
55172
MetaUpdater getMetaUpdater();
56173

174+
/**
175+
* Returns the command manager.
176+
* This method returns the command manager, which is used for registering and
177+
* executing commands.
178+
* The command manager is used for registering and executing commands.
179+
*
180+
* @return the command manager
181+
*/
57182
CommandManager getCommandManager();
58183

184+
/**
185+
* Returns the storage manager.
186+
* This method returns the storage manager, which is used for storing and retrieving data.
187+
* The storage manager is used for storing and retrieving data from the database or other
188+
* storage systems.
189+
*
190+
* @return the storage manager
191+
*/
59192
StorageManager getStorageManager();
60193

194+
/**
195+
* Checks if the plugin is a Folia plugin.
196+
* This method returns a boolean indicating whether the plugin is a Folia plugin.
197+
* This method is useful for checking if the plugin is a Folia plugin before using any
198+
* methods that require a Folia plugin.
199+
*
200+
* @return true if the plugin is a Folia plugin, false otherwise
201+
*/
61202
boolean isFolia();
62203

204+
/**
205+
* Registers a placeholder that can be used globally in the plugin.
206+
* This method allows you to register a placeholder that can be used in any menu item stack.
207+
* The placeholder is specified by the given startWith string, and the biConsumer parameter
208+
* is a function that takes an OfflinePlayer and returns a string. The return value of this
209+
* function is the replacement string for the given placeholder.
210+
*
211+
* @param startWith the startWith string for the placeholder.
212+
* @param biConsumer the function that provides the replacement string for the placeholder.
213+
*/
63214
void registerPlaceholder(String startWith, ReturnBiConsumer<OfflinePlayer, String, String> biConsumer);
64215

65216
/**
@@ -73,4 +224,12 @@ public interface MenuPlugin extends Plugin {
73224
* @return the loaded menu item stack.
74225
*/
75226
MenuItemStack loadItemStack(YamlConfiguration configuration, String path, File file);
227+
228+
/**
229+
* Returns the ToastHelper object for this plugin.
230+
* The ToastHelper allows you to create and send toasts to players.
231+
*
232+
* @return the ToastHelper object.
233+
*/
234+
ToastHelper getToastHelper();
76235
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package fr.maxlego08.menu.api.utils.toast;
2+
3+
import org.bukkit.entity.Player;
4+
5+
import java.util.Collection;
6+
7+
public interface ToastHelper {
8+
9+
/**
10+
* Shows a toast to all the given players.
11+
*
12+
* @param players the players to show the toast to
13+
* @param icon the icon
14+
* @param message the message
15+
* @param style the style
16+
* @param modelData the model data
17+
* @param glowing whether the icon is glowing
18+
*/
19+
void showToast(Collection<? extends Player> players, String icon, String message, ToastType style, Object modelData, boolean glowing);
20+
21+
/**
22+
* Shows a toast to a varargs of players.
23+
*
24+
* @param icon the icon
25+
* @param message the message
26+
* @param style the style
27+
* @param modelData the model data
28+
* @param glowing whether the icon is glowing
29+
* @param players the players to show the toast to
30+
*/
31+
void showToast(String icon, String message, ToastType style, Object modelData, boolean glowing, Player... players);
32+
33+
/**
34+
* Shows a toast to all online players.
35+
*
36+
* @param icon the icon
37+
* @param message the message
38+
* @param style the style
39+
* @param modelData the model data
40+
* @param glowing whether the icon is glowing
41+
*/
42+
void showToastToAll(String icon, String message, ToastType style, Object modelData, boolean glowing);
43+
44+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package fr.maxlego08.menu.api.utils.toast;
2+
3+
public enum ToastType {
4+
TASK,
5+
GOAL,
6+
CHALLENGE;
7+
8+
@Override
9+
public String toString() {
10+
return super.toString().toLowerCase();
11+
}
12+
}

src/main/java/fr/maxlego08/menu/ZInventoryManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ public void loadButtons() {
327327
if (this.plugin.isEnable(Plugins.LUCKPERMS)) {
328328
buttonManager.registerAction(new LuckPermissionSetLoader());
329329
}
330+
buttonManager.registerAction(new ToastLoader(this.plugin));
330331

331332
// Loading ButtonLoader
332333
// The first step will be to load the buttons in the plugin, so each

src/main/java/fr/maxlego08/menu/ZMenuPlugin.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import fr.maxlego08.menu.api.players.inventory.InventoriesPlayer;
1818
import fr.maxlego08.menu.api.storage.StorageManager;
1919
import fr.maxlego08.menu.api.utils.MetaUpdater;
20+
import fr.maxlego08.menu.api.utils.toast.ToastHelper;
2021
import fr.maxlego08.menu.api.website.WebsiteManager;
2122
import fr.maxlego08.menu.command.VCommandManager;
2223
import fr.maxlego08.menu.command.commands.CommandMenu;
@@ -56,6 +57,7 @@
5657
import fr.maxlego08.menu.zcore.utils.plugins.Metrics;
5758
import fr.maxlego08.menu.zcore.utils.plugins.Plugins;
5859
import fr.maxlego08.menu.zcore.utils.plugins.VersionChecker;
60+
import fr.maxlego08.menu.zcore.utils.toast.ToastManager;
5961
import org.bukkit.Bukkit;
6062
import org.bukkit.OfflinePlayer;
6163
import org.bukkit.configuration.file.YamlConfiguration;
@@ -93,6 +95,7 @@ public class ZMenuPlugin extends ZPlugin implements MenuPlugin {
9395
private final PatternManager patternManager = new ZPatternManager(this);
9496
private final Enchantments enchantments = new ZEnchantments();
9597
private final Map<String, Object> globalPlaceholders = new HashMap<>();
98+
private final ToastHelper toastHelper = new ToastManager(this);
9699
private CommandMenu commandMenu;
97100
private PlatformScheduler scheduler;
98101
private DupeManager dupeManager;
@@ -439,10 +442,10 @@ public void loadGlobalPlaceholders() {
439442
}
440443

441444
@Override
442-
public <T> T getProvider(Class<T> classz) {
443-
RegisteredServiceProvider<T> provider = getServer().getServicesManager().getRegistration(classz);
445+
public <T> T getProvider(Class<T> classPath) {
446+
RegisteredServiceProvider<T> provider = getServer().getServicesManager().getRegistration(classPath);
444447
if (provider == null) {
445-
getLogger().info("Unable to retrieve the provider " + classz);
448+
getLogger().info("Unable to retrieve the provider " + classPath);
446449
return null;
447450
}
448451
return provider.getProvider();
@@ -483,4 +486,9 @@ private void loadMeta() {
483486
}
484487
}
485488
}
489+
490+
@Override
491+
public ToastHelper getToastHelper() {
492+
return this.toastHelper;
493+
}
486494
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fr.maxlego08.menu.loader.actions;
2+
3+
import fr.maxlego08.menu.api.MenuPlugin;
4+
import fr.maxlego08.menu.api.loader.ActionLoader;
5+
import fr.maxlego08.menu.api.requirement.Action;
6+
import fr.maxlego08.menu.api.utils.TypedMapAccessor;
7+
import fr.maxlego08.menu.api.utils.toast.ToastType;
8+
import fr.maxlego08.menu.requirement.actions.ToastAction;
9+
10+
import java.io.File;
11+
12+
public class ToastLoader extends ActionLoader {
13+
14+
private final MenuPlugin plugin;
15+
16+
public ToastLoader(MenuPlugin plugin) {
17+
super("toast", "send toast");
18+
this.plugin = plugin;
19+
}
20+
21+
@Override
22+
public Action load(String path, TypedMapAccessor accessor, File file) {
23+
24+
String message = accessor.getString("message", "Default message");
25+
String material = accessor.getString("material", "PAPER");
26+
String modelId = accessor.getString("model-id", "0");
27+
ToastType toastType = ToastType.valueOf(accessor.getString("toast-type", ToastType.CHALLENGE.toString()).toUpperCase());
28+
boolean glowing = accessor.getBoolean("glowing", false);
29+
30+
return new ToastAction(this.plugin, material, message, toastType, modelId, glowing);
31+
}
32+
}

0 commit comments

Comments
 (0)