Skip to content

Commit b091782

Browse files
authored
Merge pull request #218 from 1robie/developement
Fix
2 parents eebfc93 + 06d8f41 commit b091782

46 files changed

Lines changed: 745 additions & 90 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

API/src/main/java/fr/maxlego08/menu/ComponentsManager.java renamed to API/src/main/java/fr/maxlego08/menu/api/ComponentsManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package fr.maxlego08.menu;
1+
package fr.maxlego08.menu.api;
22

3-
import fr.maxlego08.menu.api.MenuPlugin;
43
import fr.maxlego08.menu.api.exceptions.ItemComponentAlreadyRegisterException;
54
import fr.maxlego08.menu.api.loader.ItemComponentLoader;
65
import org.jetbrains.annotations.NotNull;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import fr.maxlego08.menu.api.requirement.Action;
99
import fr.maxlego08.menu.api.requirement.ConditionalName;
1010
import fr.maxlego08.menu.api.requirement.Requirement;
11+
import fr.maxlego08.menu.api.utils.ClearInvType;
1112
import fr.maxlego08.menu.api.utils.OpenWithItem;
1213
import fr.maxlego08.menu.api.utils.Placeholders;
1314
import org.bukkit.entity.Player;
@@ -226,4 +227,6 @@ public interface Inventory {
226227
List<Action> getOpenActions();
227228

228229
List<Action> getCloseActions();
230+
231+
ClearInvType getClearInvType();
229232
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.maxlego08.menu.api;
22

33
import com.tcoded.folialib.impl.PlatformScheduler;
4-
import fr.maxlego08.menu.ComponentsManager;
54
import fr.maxlego08.menu.api.attribute.AttributApplier;
65
import fr.maxlego08.menu.api.command.CommandManager;
76
import fr.maxlego08.menu.api.dupe.DupeManager;
@@ -209,6 +208,12 @@ public interface MenuPlugin extends Plugin {
209208
*/
210209
boolean isPaper();
211210

211+
/**
212+
* Checks if the plugin is a Paper or Folia plugin.
213+
* @return true if the plugin is a Paper or Folia plugin, false otherwise
214+
*/
215+
boolean isPaperOrFolia();
216+
212217
/**
213218
* Checks if the plugin is a Spigot plugin.
214219
* @return true if the plugin is a Spigot plugin, false otherwise

API/src/main/java/fr/maxlego08/menu/api/configuration/Configuration.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ public class Configuration {
282282
)
283283
public static boolean enablePlayerCommandsAsOPAction = false;
284284

285+
@ConfigOption(
286+
key = "enablePacketEventClickLimiter",
287+
type = DialogInputType.BOOLEAN,
288+
trueText = "<green>Enabled",
289+
falseText = "<red>Disabled",
290+
label = "Enable packet event click limiter"
291+
)
292+
public static boolean enablePacketEventClickLimiter = false;
293+
294+
@ConfigOption(
295+
key = "packetEventClickLimiterMilliseconds",
296+
type = DialogInputType.NUMBER_RANGE,
297+
label = "Packet event click limiter milliseconds",
298+
endRange = 1000,
299+
stepRange = 10
300+
)
301+
public static long packetEventClickLimiterMilliseconds = 50L;
302+
285303
public static OpGrantMethod opGrantMethod = OpGrantMethod.ATTACHMENT;
286304

287305
@ConfigOption(
@@ -378,6 +396,9 @@ public void load(@NotNull FileConfiguration fileConfiguration) {
378396
opGrantMethod = OpGrantMethod.ATTACHMENT;
379397
}
380398
enableToast = fileConfiguration.getBoolean(ConfigPath.ENABLE_TOAST.getPath(), true);
399+
400+
enablePacketEventClickLimiter = fileConfiguration.getBoolean(ConfigPath.ENABLE_PACKET_EVENT_CLICK_LIMITER.getPath());
401+
packetEventClickLimiterMilliseconds = fileConfiguration.getLong(ConfigPath.PACKET_EVENT_CLICK_LIMITER_MILLISECONDS.getPath(), 50L);
381402
}
382403

383404
public void save(@NotNull FileConfiguration fileConfiguration,@NotNull File file) {
@@ -426,6 +447,8 @@ public void save(@NotNull FileConfiguration fileConfiguration,@NotNull File file
426447
fileConfiguration.set(ConfigPath.ENABLE_PLAYER_COMMANDS_AS_OP_ACTION.getPath(), enablePlayerCommandsAsOPAction);
427448
fileConfiguration.set(ConfigPath.OP_GRANT_METHOD.getPath(), opGrantMethod.name());
428449
fileConfiguration.set(ConfigPath.ENABLE_TOAST.getPath(), enableToast);
450+
fileConfiguration.set(ConfigPath.ENABLE_PACKET_EVENT_CLICK_LIMITER.getPath(), enablePacketEventClickLimiter);
451+
fileConfiguration.set(ConfigPath.PACKET_EVENT_CLICK_LIMITER_MILLISECONDS.getPath(), packetEventClickLimiterMilliseconds);
429452
updated = false;
430453
try {
431454
fileConfiguration.save(file);
@@ -475,8 +498,11 @@ private enum ConfigPath {
475498

476499
ENABLE_PLAYER_COMMANDS_AS_OP_ACTION("enable-player-commands-as-op-action"),
477500
OP_GRANT_METHOD("op-grant-method"),
478-
ENABLE_TOAST("enable-toast");
479-
501+
ENABLE_TOAST("enable-toast"),
502+
503+
ENABLE_PACKET_EVENT_CLICK_LIMITER("enable-packet-event-click-limiter"),
504+
PACKET_EVENT_CLICK_LIMITER_MILLISECONDS("packet-event-click-limiter-milliseconds");
505+
480506
private final String path;
481507

482508
ConfigPath(@NotNull String path) {

API/src/main/java/fr/maxlego08/menu/api/engine/BaseInventory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fr.maxlego08.menu.api.MenuPlugin;
44
import fr.maxlego08.menu.api.animation.PlayerTitleAnimation;
55
import fr.maxlego08.menu.api.animation.TitleAnimation;
6+
import fr.maxlego08.menu.api.utils.ClearInvType;
67
import org.bukkit.entity.Player;
78
import org.bukkit.inventory.Inventory;
89
import org.bukkit.inventory.InventoryHolder;
@@ -16,7 +17,7 @@
1617
public interface BaseInventory extends InventoryHolder {
1718

1819
@Contract(pure = true)
19-
@Nullable
20+
@NotNull
2021
MenuPlugin getPlugin();
2122

2223
@Contract(pure = true)
@@ -93,4 +94,7 @@ public interface BaseInventory extends InventoryHolder {
9394

9495
TitleAnimation getTitleAnimation();
9596

97+
void setClearInvType(ClearInvType clearInvType);
98+
99+
ClearInvType getClearInvType();
96100
}

API/src/main/java/fr/maxlego08/menu/api/engine/ItemButton.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ public class ItemButton {
1515
private final int slot;
1616
private final ItemStack displayItem;
1717
private final Map<ClickType, Consumer<InventoryClickEvent>> onClickType = new HashMap<>();
18+
private final boolean inPlayerInventory;
19+
private final BaseInventory baseInventory;
1820
private Consumer<InventoryClickEvent> onClick;
1921

20-
public ItemButton(@NotNull ItemStack displayItem, int slot) {
21-
super();
22+
public ItemButton(@NotNull ItemStack displayItem, int slot, boolean inPlayerInventory, @NotNull BaseInventory baseInventory) {
2223
this.displayItem = displayItem;
2324
this.slot = slot;
25+
this.inPlayerInventory = inPlayerInventory;
26+
this.baseInventory = baseInventory;
2427
}
2528

2629
@Contract(pure = true)
@@ -84,6 +87,17 @@ public ItemStack getDisplayItem() {
8487
return this.displayItem;
8588
}
8689

90+
@Contract(pure = true)
91+
public boolean isInPlayerInventory() {
92+
return this.inPlayerInventory;
93+
}
94+
95+
@Contract(pure = true)
96+
@NotNull
97+
public BaseInventory getBaseInventory() {
98+
return this.baseInventory;
99+
}
100+
87101
public void onClick(@NotNull InventoryClickEvent event) {
88102
if (this.onClick != null) {
89103
this.onClick.accept(event);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package fr.maxlego08.menu.api.interfaces;
2+
3+
@FunctionalInterface
4+
public interface TriConsumer<T, U, V> {
5+
void accept(T t, U u, V v);
6+
}

API/src/main/java/fr/maxlego08/menu/api/players/inventory/InventoriesPlayer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bukkit.event.Listener;
55
import org.bukkit.inventory.ItemStack;
66
import org.jetbrains.annotations.NotNull;
7+
import org.jspecify.annotations.NonNull;
78

89
import java.util.List;
910
import java.util.Optional;
@@ -21,6 +22,12 @@ public interface InventoriesPlayer extends Listener {
2122
*/
2223
void storeInventory(@NotNull Player player);
2324

25+
/**
26+
* Saves the player's inventory to be stored temporarily (cached only in memory)
27+
* @param player Player
28+
*/
29+
void storeInventoryTemporary(@NonNull Player player);
30+
2431
/**
2532
* Allows giving the inventory back to the player
2633
*

API/src/main/java/fr/maxlego08/menu/api/players/inventory/InventoryPlayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ public interface InventoryPlayer {
4242

4343
@NotNull
4444
Map<Integer, String> getItems();
45+
46+
boolean isPermanent();
4547
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package fr.maxlego08.menu.api.utils;
2+
3+
import fr.maxlego08.menu.api.interfaces.TriConsumer;
4+
import fr.maxlego08.menu.api.players.inventory.InventoriesPlayer;
5+
import org.bukkit.Material;
6+
import org.bukkit.entity.Player;
7+
import org.bukkit.inventory.ItemStack;
8+
import org.bukkit.inventory.PlayerInventory;
9+
10+
import java.util.function.BiConsumer;
11+
12+
public enum ClearInvType {
13+
DEFAULT(InventoriesPlayer::giveInventory,(player, slot) -> player.getInventory().setItem(slot, new ItemStack(Material.AIR)),(player, slot, playerInventory) -> playerInventory.clear(slot)),
14+
PACKET_EVENT("packetevents")
15+
;
16+
17+
private BiConsumer<InventoriesPlayer, Player> onInventoryClose;
18+
private BiConsumer<Player,Integer > onButtonClear;
19+
private TriConsumer<Player, Integer, PlayerInventory> removeItem;
20+
private final String requiredPlugin;
21+
22+
ClearInvType(String requiredPlugin) {
23+
this.requiredPlugin = requiredPlugin;
24+
this.onInventoryClose = (inventoriesPlayer, player) -> {
25+
// No action
26+
};
27+
this.onButtonClear = (slot, player) -> {
28+
// No action
29+
};
30+
this.removeItem = (player, slot, playerInventory) -> {
31+
// No action
32+
};
33+
}
34+
35+
ClearInvType(BiConsumer<InventoriesPlayer, Player> onInventoryClose, BiConsumer<Player, Integer> onButtonClear, TriConsumer<Player, Integer, PlayerInventory> removeItem) {
36+
this.onInventoryClose = onInventoryClose;
37+
this.onButtonClear = onButtonClear;
38+
this.removeItem = removeItem;
39+
this.requiredPlugin = null;
40+
}
41+
42+
public BiConsumer<InventoriesPlayer, Player> getOnInventoryClose() {
43+
return this.onInventoryClose;
44+
}
45+
46+
public void setOnInventoryClose(BiConsumer<InventoriesPlayer, Player> onInventoryClose) {
47+
this.onInventoryClose = onInventoryClose;
48+
}
49+
50+
public BiConsumer<Player, Integer> getOnButtonClear() {
51+
return this.onButtonClear;
52+
}
53+
54+
public void setOnButtonClear(BiConsumer<Player, Integer> onButtonClear) {
55+
this.onButtonClear = onButtonClear;
56+
}
57+
58+
public TriConsumer<Player, Integer, PlayerInventory> getRemoveItem() {
59+
return this.removeItem;
60+
}
61+
62+
public void setRemoveItem(TriConsumer<Player, Integer, PlayerInventory> removeItem) {
63+
this.removeItem = removeItem;
64+
}
65+
66+
public String getRequiredPlugin() {
67+
return this.requiredPlugin;
68+
}
69+
70+
public boolean hasRequiredPlugin() {
71+
return this.requiredPlugin != null && !this.requiredPlugin.isEmpty();
72+
}
73+
}

0 commit comments

Comments
 (0)