Remove API module

This commit is contained in:
Len
2022-08-07 17:28:38 +02:00
parent aeb6d79495
commit 5ccd5b6f0c
34 changed files with 88 additions and 263 deletions
@@ -0,0 +1,105 @@
package com.alttd.playershops.shop;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.data.Directional;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public abstract class AbstractShop {
@Getter
private int id;
private String ownerName;
@Getter
private UUID ownerUUID;
@Getter @Setter
private ShopType type;
@Getter
private Location signLocation;
@Getter
private Location containerLocation;
@Getter
private String server;
@Getter @Setter
private double price;
@Getter @Setter
private int amount;
@Getter @Setter
private double balance;
@Getter @Setter
private ItemStack itemStack;
@Getter @Setter
private ItemStack secondaryItem;
@Getter @Setter
private long lastTransaction;
protected boolean initialized;
AbstractShop(Location signLocation, UUID uuid, double price, int amount) {
this.signLocation = signLocation;
if (signLocation != null) {
Directional sign = (Directional) signLocation.getBlock().getState().getBlockData();
this.containerLocation = signLocation.getBlock().getRelative(sign.getFacing().getOppositeFace()).getLocation();
}
this.ownerUUID = uuid;
ownerName = getOwnerName();
this.price = price;
this.amount = amount;
this.server = Bukkit.getServerName();
}
AbstractShop(int id, String ownerName, UUID ownerUUID, String server,
Location containerLocation, Location signLocation, double price, int amount,
double balance, ItemStack itemOne, ItemStack itemTwo, long lastTransaction) {
this.id = id;
this.ownerName = ownerName;
this.ownerUUID = ownerUUID;
this.server = server;
this.containerLocation = containerLocation;
this.signLocation = signLocation;
this.price = price;
this.amount = amount;
this.balance = balance;
this.itemStack = itemOne;
this.secondaryItem = itemTwo;
this.lastTransaction = lastTransaction;
}
public static AbstractShop create(Location signLocation, UUID player, double price, int amount, ShopType shopType) {
return switch (shopType) {
case SELL -> new SellShop(signLocation, player, price, amount);
case BUY -> new BuyShop(signLocation, player, price, amount);
case GAMBLE -> new GambleShop(signLocation, player, price, amount);
case BARTER -> new BarterShop(signLocation, player, price, amount);
};
}
public static AbstractShop create(int id, String ownerName, UUID ownerUUID, ShopType shopType, String server,
Location containerLocation, Location signLocation, double price, int amount,
double balance, ItemStack itemOne, ItemStack itemTwo, long lastTransaction) {
return switch (shopType) {
case SELL -> new SellShop(id, ownerName, ownerUUID, server, containerLocation, signLocation, price, amount, balance, itemOne, itemTwo, lastTransaction);
case BUY -> new BuyShop(id, ownerName, ownerUUID, server, containerLocation, signLocation, price, amount, balance, itemOne, itemTwo, lastTransaction);
case GAMBLE -> new GambleShop(id, ownerName, ownerUUID, server, containerLocation, signLocation, price, amount, balance, itemOne, itemTwo, lastTransaction);
case BARTER -> new BarterShop(id, ownerName, ownerUUID, server, containerLocation, signLocation, price, amount, balance, itemOne, itemTwo, lastTransaction);
};
}
public String getOwnerName() {
if(this.ownerName != null) return ownerName;
if (this.getOwnerUUID() != null) {
ownerName = Bukkit.getOfflinePlayer(this.getOwnerUUID()).getName();
return ownerName;
}
return ChatColor.RED + "[CLOSED]";
}
public boolean isInitialized() {
return initialized;
}
}
@@ -0,0 +1,24 @@
package com.alttd.playershops.shop;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class BarterShop extends AbstractShop {
public BarterShop(Location location, UUID player, double price, int amount) {
super(location, player, price, amount);
this.setType(ShopType.BARTER);
}
public BarterShop(int id, String ownerName, UUID ownerUUID, String server,
Location containerLocation, Location signLocation, double price, int amount,
double balance, ItemStack itemOne, ItemStack itemTwo, long lastTransaction) {
super(id, ownerName, ownerUUID, server, containerLocation, signLocation, price, amount,
balance, itemOne, itemTwo, lastTransaction);
this.setType(ShopType.BARTER);
}
}
@@ -0,0 +1,23 @@
package com.alttd.playershops.shop;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class BuyShop extends AbstractShop {
public BuyShop(Location location, UUID player, double price, int amount) {
super(location, player, price, amount);
this.setType(ShopType.BUY);
}
public BuyShop(int id, String ownerName, UUID ownerUUID, String server,
Location containerLocation, Location signLocation, double price, int amount,
double balance, ItemStack itemOne, ItemStack itemTwo, long lastTransaction) {
super(id, ownerName, ownerUUID, server, containerLocation, signLocation, price, amount,
balance, itemOne, itemTwo, lastTransaction);
this.setType(ShopType.BUY);
}
}
@@ -0,0 +1,27 @@
package com.alttd.playershops.shop;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class GambleShop extends AbstractShop {
private ItemStack gambleItem;
public GambleShop(Location location, UUID player, double price, int amount) {
super(location, player, price, amount);
this.setType(ShopType.GAMBLE);
this.gambleItem = this.getItemStack();
}
public GambleShop(int id, String ownerName, UUID ownerUUID, String server,
Location containerLocation, Location signLocation, double price, int amount,
double balance, ItemStack itemOne, ItemStack itemTwo, long lastTransaction) {
super(id, ownerName, ownerUUID, server, containerLocation, signLocation, price, amount,
balance, itemOne, itemTwo, lastTransaction);
this.setType(ShopType.GAMBLE);
}
}
@@ -0,0 +1,24 @@
package com.alttd.playershops.shop;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class SellShop extends AbstractShop {
public SellShop(Location location, UUID player, double price, int amount) {
super(location, player, price, amount);
this.setType(ShopType.SELL);
}
public SellShop(int id, String ownerName, UUID ownerUUID, String server,
Location containerLocation, Location signLocation, double price, int amount,
double balance, ItemStack itemOne, ItemStack itemTwo, long lastTransaction) {
super(id, ownerName, ownerUUID, server, containerLocation, signLocation, price, amount,
balance, itemOne, itemTwo, lastTransaction);
this.setType(ShopType.SELL);
}
}
@@ -0,0 +1,13 @@
package com.alttd.playershops.shop;
public class ShopTransaction {
public enum ShopTransactionError {
CANCELLED,
INSUFFICIENT_FUNDS_SHOP,
INSUFFICIENT_FUNDS_PLAYER,
INVENTORY_FULL_SHOP,
INVENTORY_FULL_PLAYER,
NONE;
}
}
@@ -0,0 +1,10 @@
package com.alttd.playershops.shop;
public enum ShopTransactionError {
CANCELLED,
INSUFFICIENT_FUNDS_SHOP,
INSUFFICIENT_FUNDS_PLAYER,
INVENTORY_FULL_SHOP,
INVENTORY_FULL_PLAYER,
NONE;
}
@@ -0,0 +1,13 @@
package com.alttd.playershops.shop;
public enum ShopType {
SELL,
BUY,
GAMBLE,
BARTER;
@Override
public String toString() {
return name().toLowerCase();
}
}