diff --git a/src/main/java/com/alttd/playershops/PlayerShops.java b/src/main/java/com/alttd/playershops/PlayerShops.java index 02f8c7d..2798b6a 100644 --- a/src/main/java/com/alttd/playershops/PlayerShops.java +++ b/src/main/java/com/alttd/playershops/PlayerShops.java @@ -2,6 +2,8 @@ package com.alttd.playershops; import com.alttd.playershops.config.Config; import com.alttd.playershops.handler.ShopHandler; +import com.alttd.playershops.listener.PlayerListener; +import com.alttd.playershops.listener.ShopListener; import lombok.Getter; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; @@ -17,6 +19,9 @@ public class PlayerShops extends JavaPlugin { @Getter private ShopHandler shopHandler; + private ShopListener shopListener; + private PlayerListener playerListener; + public void onEnable() { instance = this; if(!setupEconomy()) { @@ -51,7 +56,15 @@ public class PlayerShops extends JavaPlugin { } private void registerListeners() { + shopListener = new ShopListener(); + shopListener.register(this); + playerListener = new PlayerListener(); + playerListener.register(this); + } + private void UnregisterListeners() { + shopListener.unregister(); + playerListener.unregister(); } private void registerCommands() { diff --git a/src/main/java/com/alttd/playershops/listener/EventListener.java b/src/main/java/com/alttd/playershops/listener/EventListener.java index b9be021..54aa0fb 100644 --- a/src/main/java/com/alttd/playershops/listener/EventListener.java +++ b/src/main/java/com/alttd/playershops/listener/EventListener.java @@ -8,12 +8,12 @@ import org.bukkit.plugin.java.JavaPlugin; public class EventListener implements Listener { protected boolean isRegistered = false; - protected void register(JavaPlugin instance) { + public void register(JavaPlugin instance) { Bukkit.getServer().getPluginManager().registerEvents(this, instance); isRegistered = true; } - protected void unregister() { + public void unregister() { HandlerList.unregisterAll(this); isRegistered = false; } diff --git a/src/main/java/com/alttd/playershops/listener/PlayerListener.java b/src/main/java/com/alttd/playershops/listener/PlayerListener.java new file mode 100644 index 0000000..fcf5964 --- /dev/null +++ b/src/main/java/com/alttd/playershops/listener/PlayerListener.java @@ -0,0 +1,4 @@ +package com.alttd.playershops.listener; + +public class PlayerListener extends EventListener { +} diff --git a/src/main/java/com/alttd/playershops/listener/ShopListener.java b/src/main/java/com/alttd/playershops/listener/ShopListener.java new file mode 100644 index 0000000..d527a95 --- /dev/null +++ b/src/main/java/com/alttd/playershops/listener/ShopListener.java @@ -0,0 +1,4 @@ +package com.alttd.playershops.listener; + +public class ShopListener extends EventListener { +} diff --git a/src/main/java/com/alttd/playershops/shop/AbstractShop.java b/src/main/java/com/alttd/playershops/shop/AbstractShop.java index 211d7d9..7c19986 100644 --- a/src/main/java/com/alttd/playershops/shop/AbstractShop.java +++ b/src/main/java/com/alttd/playershops/shop/AbstractShop.java @@ -1,5 +1,70 @@ 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; + + 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; + } + + 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 String getOwnerName() { + if(this.ownerName != null) return ownerName; + if (this.getOwnerUUID() != null) { + ownerName = Bukkit.getOfflinePlayer(this.getOwnerUUID()).getName(); + return ownerName; + } + return ChatColor.RED + "[CLOSED]"; + } } diff --git a/src/main/java/com/alttd/playershops/shop/BarterShop.java b/src/main/java/com/alttd/playershops/shop/BarterShop.java new file mode 100644 index 0000000..64f2964 --- /dev/null +++ b/src/main/java/com/alttd/playershops/shop/BarterShop.java @@ -0,0 +1,15 @@ +package com.alttd.playershops.shop; + +import org.bukkit.Location; + +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); + } + +} diff --git a/src/main/java/com/alttd/playershops/shop/BuyShop.java b/src/main/java/com/alttd/playershops/shop/BuyShop.java new file mode 100644 index 0000000..03da9dd --- /dev/null +++ b/src/main/java/com/alttd/playershops/shop/BuyShop.java @@ -0,0 +1,15 @@ +package com.alttd.playershops.shop; + +import org.bukkit.Location; + +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); + } + +} diff --git a/src/main/java/com/alttd/playershops/shop/GambleShop.java b/src/main/java/com/alttd/playershops/shop/GambleShop.java new file mode 100644 index 0000000..cbe3698 --- /dev/null +++ b/src/main/java/com/alttd/playershops/shop/GambleShop.java @@ -0,0 +1,19 @@ +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(); + } + +} diff --git a/src/main/java/com/alttd/playershops/shop/SellShop.java b/src/main/java/com/alttd/playershops/shop/SellShop.java new file mode 100644 index 0000000..a39cc16 --- /dev/null +++ b/src/main/java/com/alttd/playershops/shop/SellShop.java @@ -0,0 +1,15 @@ +package com.alttd.playershops.shop; + +import org.bukkit.Location; + +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); + } + +} diff --git a/src/main/java/com/alttd/playershops/shop/ShopTransaction.java b/src/main/java/com/alttd/playershops/shop/ShopTransaction.java new file mode 100755 index 0000000..cfa5ab9 --- /dev/null +++ b/src/main/java/com/alttd/playershops/shop/ShopTransaction.java @@ -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; + } +} diff --git a/src/main/java/com/alttd/playershops/shop/ShopTransactionError.java b/src/main/java/com/alttd/playershops/shop/ShopTransactionError.java new file mode 100755 index 0000000..5affe5a --- /dev/null +++ b/src/main/java/com/alttd/playershops/shop/ShopTransactionError.java @@ -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; +}