diff --git a/plugin/src/main/java/de/epiceric/shopchest/action/ActionManager.java b/plugin/src/main/java/de/epiceric/shopchest/action/ActionManager.java index a2d0589..eb9cc27 100644 --- a/plugin/src/main/java/de/epiceric/shopchest/action/ActionManager.java +++ b/plugin/src/main/java/de/epiceric/shopchest/action/ActionManager.java @@ -33,12 +33,11 @@ public class ActionManager { * Get the current action of a {@link org.bukkit.entity.Player} * * @param uuid {@link org.bukkit.entity.Player}'s {@link UUID} - * @return An {@link Optional} {@link PendingAction} which is : - * - empty if there is no pending action for this player - * - filled by the current valid pending action if there is one + * @return A {@link PendingAction} which the player should do when interacting */ - public Optional getAction(UUID uuid) { - return Optional.ofNullable(playerActions.computeIfPresent(uuid, (k, v) -> v.hasExpired() ? null : v)); + public PendingAction getAction(UUID uuid) { + final PendingAction action = playerActions.computeIfPresent(uuid, (k, v) -> v.hasExpired() ? null : v); + return action == null ? new InteractShopPendingAction(-1) : action; } } diff --git a/plugin/src/main/java/de/epiceric/shopchest/action/CreatePendingAction.java b/plugin/src/main/java/de/epiceric/shopchest/action/CreatePendingAction.java new file mode 100644 index 0000000..75f639f --- /dev/null +++ b/plugin/src/main/java/de/epiceric/shopchest/action/CreatePendingAction.java @@ -0,0 +1,18 @@ +package de.epiceric.shopchest.action; + +import org.bukkit.block.Block; + +import java.util.concurrent.CompletableFuture; + +public class CreatePendingAction extends ShopCheckerPendingAction { + + public CreatePendingAction(long duration) { + super(duration, false); + } + + @Override + public CompletableFuture execute(Block block) { + // Create a shop + return null; + } +} diff --git a/plugin/src/main/java/de/epiceric/shopchest/action/InteractShopPendingAction.java b/plugin/src/main/java/de/epiceric/shopchest/action/InteractShopPendingAction.java new file mode 100644 index 0000000..aeb8403 --- /dev/null +++ b/plugin/src/main/java/de/epiceric/shopchest/action/InteractShopPendingAction.java @@ -0,0 +1,21 @@ +package de.epiceric.shopchest.action; + +import org.bukkit.block.Block; + +import java.util.concurrent.CompletableFuture; + +public class InteractShopPendingAction extends ShopCheckerPendingAction { + + public InteractShopPendingAction(long duration) { + super(duration, true); + } + + @Override + public CompletableFuture execute(Block block) { + // Get the Shop + // - if special condition (e.g. info stick) -> apply condition + // - if owner -> open it + // - else start transaction + return null; + } +} diff --git a/plugin/src/main/java/de/epiceric/shopchest/action/PendingAction.java b/plugin/src/main/java/de/epiceric/shopchest/action/PendingAction.java index 8fe5118..c6dce3f 100644 --- a/plugin/src/main/java/de/epiceric/shopchest/action/PendingAction.java +++ b/plugin/src/main/java/de/epiceric/shopchest/action/PendingAction.java @@ -6,12 +6,10 @@ import java.util.concurrent.CompletableFuture; public abstract class PendingAction { - protected final Block block; protected final long endTime; - public PendingAction(Block block, long duration) { - this.block = block; - this.endTime = System.currentTimeMillis() + duration; + public PendingAction(long duration) { + this.endTime = duration < 0 ? -1 : (System.currentTimeMillis() + duration); } /** @@ -28,7 +26,7 @@ public abstract class PendingAction { * @return {@code true} if this action is valid, {@code false} otherwise */ public boolean hasExpired() { - return System.currentTimeMillis() > endTime; + return endTime != -1 && System.currentTimeMillis() > endTime; } /** diff --git a/plugin/src/main/java/de/epiceric/shopchest/action/ShopCheckerPendingAction.java b/plugin/src/main/java/de/epiceric/shopchest/action/ShopCheckerPendingAction.java new file mode 100644 index 0000000..8292810 --- /dev/null +++ b/plugin/src/main/java/de/epiceric/shopchest/action/ShopCheckerPendingAction.java @@ -0,0 +1,25 @@ +package de.epiceric.shopchest.action; + +import org.bukkit.block.Block; + +public abstract class ShopCheckerPendingAction extends ShopMaterialPendingAction { + + private final boolean shouldBeShop; + + public ShopCheckerPendingAction(long duration, boolean shouldBeShop) { + super(duration); + this.shouldBeShop = shouldBeShop; + } + + @Override + public boolean canApply(Block block) { + if(!super.canApply(block)) { + return false; + } + + // Check if it's a shop (Shop access should be kept somewhere in cache) + final boolean isShop = false; + + return shouldBeShop == isShop; + } +} diff --git a/plugin/src/main/java/de/epiceric/shopchest/action/ShopMaterialPendingAction.java b/plugin/src/main/java/de/epiceric/shopchest/action/ShopMaterialPendingAction.java new file mode 100644 index 0000000..b1ccd68 --- /dev/null +++ b/plugin/src/main/java/de/epiceric/shopchest/action/ShopMaterialPendingAction.java @@ -0,0 +1,17 @@ +package de.epiceric.shopchest.action; + +import org.bukkit.block.Block; + +public abstract class ShopMaterialPendingAction extends PendingAction { + + public ShopMaterialPendingAction(long duration) { + super(duration); + } + + @Override + public boolean canApply(Block block) { + // Check if the block can be a shop + return false; + } + +}