Skip to content

Commit

Permalink
Added .item:serializer module to automatically load and save item o…
Browse files Browse the repository at this point in the history
…bjects.

Added parsers:
- [EnchantmentParser](item/serializer/src/main/java/it/angrybear/serializers/EnchantmentParser.java);
- [ItemParser](item/serializer/src/main/java/it/angrybear/serializers/ItemParser.java);
- [ShapeParser](item/serializer/src/main/java/it/angrybear/serializers/ShapeParser.java);
- [ShapedRecipeParser](item/serializer/src/main/java/it/angrybear/serializers/ShapedRecipeParser.java);
- [ShapelessRecipeParser](item/serializer/src/main/java/it/angrybear/serializers/ShapelessRecipeParser.java);
- [FurnaceRecipeParser](item/serializer/src/main/java/it/angrybear/serializers/FurnaceRecipeParser.java).
Added [YAGLParser](item/serializer/src/main/java/it/angrybear/serializers/YAGLParser.java) to automatically load parsers.
Moved everything to package `it.angrybear.yagl`.
Reworked `Item#copy()` method: it will try to get a default empty constructor from the current class. If it fails, it defaults to `ItemImpl`.
Fixed `Item#copy(Class)` with automatic resolution of interfaces: passing `Item` or `BukkitItem` will convert them into `ItemImpl` and `BukkitItemImpl`.
Fixed `Item#copy(Class)` not checking if current item has field of receiving class.
Fixed various bugs in **ShapedRecipe**.
Fixed recipes not copying items in their most default state (Item).
Fixed invalid casts to `BukkitItem` in `ItemUtils`.
Fixed `ItemUtils`: now it will apply model data only for values higher than 0.
Fixed visibility issues in `PersistentListener`: every event method is now protected.
Fixed PersistentListener not checking for main hand upon interacting.
Updated FulmiCollection to version 1.4.1.
  • Loading branch information
fulminazzo committed Mar 5, 2024
1 parent d4c1430 commit 325c3ad
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.function.Consumer;

/**
* A listener for {@link PersistentItem}s.
*/
public class PersistentListener implements Listener {
private static boolean INITIALIZED = false;
/**
* Timeout, in milliseconds, to check before calling {@link #on(PlayerInteractEvent)}.
* This is used to prevent double calls.
*/
private static long INTERACT_TIMEOUT = 10;
private final Map<UUID, Long> lastUsed;

/**
* Instantiates a new Persistent listener.
*/
public PersistentListener() {
public PersistentListener(Map<UUID, Long> lastUsed) {
this.lastUsed = lastUsed;
INITIALIZED = true;
}

Expand Down Expand Up @@ -67,6 +72,10 @@ protected void on(PlayerDeathEvent event) {
protected void on(PlayerInteractEvent event) {
if (event.getHand() != EquipmentSlot.HAND) return;
Player player = event.getPlayer();
long lastUsed = this.lastUsed.getOrDefault(player.getUniqueId(), 0L);
long now = new Date().getTime();
if (now < lastUsed + INTERACT_TIMEOUT) return;
this.lastUsed.put(player.getUniqueId(), now);
interactPersistentItem(event.getItem(), player, event.getAction(), cancelled(event));
}

Expand Down

0 comments on commit 325c3ad

Please sign in to comment.