mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-12-04 02:23:22 +01:00
Add action structure
This commit is contained in:
parent
a96e3620d8
commit
1d136933a7
@ -33,12 +33,11 @@ public class ActionManager {
|
|||||||
* Get the current action of a {@link org.bukkit.entity.Player}
|
* Get the current action of a {@link org.bukkit.entity.Player}
|
||||||
*
|
*
|
||||||
* @param uuid {@link org.bukkit.entity.Player}'s {@link UUID}
|
* @param uuid {@link org.bukkit.entity.Player}'s {@link UUID}
|
||||||
* @return An {@link Optional} {@link PendingAction} which is :
|
* @return A {@link PendingAction} which the player should do when interacting
|
||||||
* - empty if there is no pending action for this player
|
|
||||||
* - filled by the current valid pending action if there is one
|
|
||||||
*/
|
*/
|
||||||
public Optional<PendingAction> getAction(UUID uuid) {
|
public PendingAction getAction(UUID uuid) {
|
||||||
return Optional.ofNullable(playerActions.computeIfPresent(uuid, (k, v) -> v.hasExpired() ? null : v));
|
final PendingAction action = playerActions.computeIfPresent(uuid, (k, v) -> v.hasExpired() ? null : v);
|
||||||
|
return action == null ? new InteractShopPendingAction(-1) : action;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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<Void> execute(Block block) {
|
||||||
|
// Create a shop
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -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<Void> execute(Block block) {
|
||||||
|
// Get the Shop
|
||||||
|
// - if special condition (e.g. info stick) -> apply condition
|
||||||
|
// - if owner -> open it
|
||||||
|
// - else start transaction
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -6,12 +6,10 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
|
|
||||||
public abstract class PendingAction {
|
public abstract class PendingAction {
|
||||||
|
|
||||||
protected final Block block;
|
|
||||||
protected final long endTime;
|
protected final long endTime;
|
||||||
|
|
||||||
public PendingAction(Block block, long duration) {
|
public PendingAction(long duration) {
|
||||||
this.block = block;
|
this.endTime = duration < 0 ? -1 : (System.currentTimeMillis() + duration);
|
||||||
this.endTime = System.currentTimeMillis() + duration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +26,7 @@ public abstract class PendingAction {
|
|||||||
* @return {@code true} if this action is valid, {@code false} otherwise
|
* @return {@code true} if this action is valid, {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
public boolean hasExpired() {
|
public boolean hasExpired() {
|
||||||
return System.currentTimeMillis() > endTime;
|
return endTime != -1 && System.currentTimeMillis() > endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user