Update flag API

This commit is contained in:
Eric 2019-08-17 14:05:45 +02:00
parent 24e0f0d064
commit 70f9ff3914
8 changed files with 208 additions and 2 deletions

View File

@ -0,0 +1,59 @@
package de.epiceric.shopchest.api.flag;
import de.epiceric.shopchest.api.ShopChest;
import de.epiceric.shopchest.api.shop.ShopProduct;
/**
* Represents the flag a player has after entering the create command
*/
public class CreateFlag extends TimedFlag {
private ShopProduct product;
private double buyPrice;
private double sellPrice;
private boolean admin;
public CreateFlag(ShopChest plugin, ShopProduct product, double buyPrice, double sellPrice, boolean admin) {
super(plugin, 15);
this.product = product;
this.buyPrice = buyPrice;
this.sellPrice = sellPrice;
this.admin = admin;
}
/**
* Gets the product the player wants to create a shop with
*
* @return the product
*/
public ShopProduct getProduct() {
return product;
}
/**
* Gets the price the player wants others to buy the product for
*
* @return the buy price
*/
public double getBuyPrice() {
return buyPrice;
}
/**
* Gets the price the player wants others to sell the product for
*
* @return the sell price
*/
public double getSellPrice() {
return sellPrice;
}
/**
* Gets whether the player wants to create an admin shop
*
* @return whether the players wants to create an admin shop
*/
public boolean isAdminShop() {
return admin;
}
}

View File

@ -1,9 +1,29 @@
package de.epiceric.shopchest.api.flag;
import de.epiceric.shopchest.api.player.ShopPlayer;
/**
* Represents a flag a player can have
*
* @since 1.13
* @since 1.13
*/
public interface Flag {
/**
* Called when this flag is assigned to a player
*
* @param player the player
* @since 1.13
*/
default void onAssign(ShopPlayer player) {};
/**
* Called when this flag will be removed from a player
* <p>
* The flag will be removed after this method is called.
*
* @param player the player
* @since 1.13
*/
default void onRemove(ShopPlayer player) {};
}

View File

@ -0,0 +1,12 @@
package de.epiceric.shopchest.api.flag;
import de.epiceric.shopchest.api.ShopChest;
/**
* Represents the flag a player has after entering the info command
*/
public class InfoFlag extends TimedFlag {
public InfoFlag(ShopChest plugin) {
super(plugin, 15);
}
}

View File

@ -0,0 +1,12 @@
package de.epiceric.shopchest.api.flag;
import de.epiceric.shopchest.api.ShopChest;
/**
* Represents the flag a player has after entering the open command
*/
public class OpenFlag extends TimedFlag {
public OpenFlag(ShopChest plugin) {
super(plugin, 15);
}
}

View File

@ -0,0 +1,12 @@
package de.epiceric.shopchest.api.flag;
import de.epiceric.shopchest.api.ShopChest;
/**
* Represents the flag a player has after entering the remove command
*/
public class RemoveFlag extends TimedFlag {
public RemoveFlag(ShopChest plugin) {
super(plugin, 15);
}
}

View File

@ -0,0 +1,34 @@
package de.epiceric.shopchest.api.flag;
import org.bukkit.GameMode;
import de.epiceric.shopchest.api.player.ShopPlayer;
/**
* Represents the flag a player has after entering the create command
*/
public class SelectFlag implements Flag {
private GameMode gameMode;
public SelectFlag(GameMode gameMode) {
this.gameMode = gameMode;
}
/**
* Gets the game mode the player had before entering the command
* <p>
* This is used for resetting the game mode when the player has selected the
* product from the creative inventory.
*
* @return the game mode
*/
public GameMode getGameMode() {
return gameMode;
}
@Override
public void onRemove(ShopPlayer player) {
player.getPlayer().setGameMode(getGameMode());;
}
}

View File

@ -0,0 +1,46 @@
package de.epiceric.shopchest.api.flag;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask;
import de.epiceric.shopchest.api.ShopChest;
import de.epiceric.shopchest.api.player.ShopPlayer;
/**
* Represents a flag that is removed after a given time
*/
public abstract class TimedFlag implements Flag {
private ShopChest plugin;
private int seconds;
private BukkitTask task;
public TimedFlag(ShopChest plugin, int seconds) {
this.plugin = plugin;
this.seconds = seconds;
}
/**
* {@inheritDoc}
* <p>
* To use the functionality of this flag, a call to {@code super.onAssign(player)} is mandatory.
*/
@Override
public void onAssign(ShopPlayer player) {
task = Bukkit.getScheduler().runTaskLater(plugin, () -> {
if (this.equals(player.getFlag())) {
player.removeFlag();
}
}, seconds * 20);
}
/**
* {@inheritDoc}
* <p>
* To use the functionality of this flag, a call to {@code super.onAssign(player)} is mandatory.
*/
@Override
public void onRemove(ShopPlayer player) {
task.cancel();
}
}

View File

@ -45,7 +45,18 @@ public interface ShopPlayer {
* @return whether this player has a flag
* @since 1.13
*/
boolean hasFlag();
default boolean hasFlag() {
return getFlag() != null;
}
/**
* Removes this player's flag
*
* @since 1.13
*/
default void removeFlag() {
setFlag(null);
}
/**
* Gets the amount of shops the given player is allowed to have