Add in shop objects
This commit is contained in:
parent
10ea384164
commit
ca279dc1ed
|
|
@ -2,6 +2,8 @@ package com.alttd.playershops;
|
||||||
|
|
||||||
import com.alttd.playershops.config.Config;
|
import com.alttd.playershops.config.Config;
|
||||||
import com.alttd.playershops.handler.ShopHandler;
|
import com.alttd.playershops.handler.ShopHandler;
|
||||||
|
import com.alttd.playershops.listener.PlayerListener;
|
||||||
|
import com.alttd.playershops.listener.ShopListener;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -17,6 +19,9 @@ public class PlayerShops extends JavaPlugin {
|
||||||
@Getter
|
@Getter
|
||||||
private ShopHandler shopHandler;
|
private ShopHandler shopHandler;
|
||||||
|
|
||||||
|
private ShopListener shopListener;
|
||||||
|
private PlayerListener playerListener;
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
if(!setupEconomy()) {
|
if(!setupEconomy()) {
|
||||||
|
|
@ -51,7 +56,15 @@ public class PlayerShops extends JavaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListeners() {
|
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() {
|
private void registerCommands() {
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
public class EventListener implements Listener {
|
public class EventListener implements Listener {
|
||||||
protected boolean isRegistered = false;
|
protected boolean isRegistered = false;
|
||||||
|
|
||||||
protected void register(JavaPlugin instance) {
|
public void register(JavaPlugin instance) {
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(this, instance);
|
Bukkit.getServer().getPluginManager().registerEvents(this, instance);
|
||||||
isRegistered = true;
|
isRegistered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unregister() {
|
public void unregister() {
|
||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
isRegistered = false;
|
isRegistered = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.alttd.playershops.listener;
|
||||||
|
|
||||||
|
public class PlayerListener extends EventListener {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.alttd.playershops.listener;
|
||||||
|
|
||||||
|
public class ShopListener extends EventListener {
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,70 @@
|
||||||
package com.alttd.playershops.shop;
|
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 {
|
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]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
src/main/java/com/alttd/playershops/shop/BarterShop.java
Normal file
15
src/main/java/com/alttd/playershops/shop/BarterShop.java
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
src/main/java/com/alttd/playershops/shop/BuyShop.java
Normal file
15
src/main/java/com/alttd/playershops/shop/BuyShop.java
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
src/main/java/com/alttd/playershops/shop/GambleShop.java
Normal file
19
src/main/java/com/alttd/playershops/shop/GambleShop.java
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
src/main/java/com/alttd/playershops/shop/SellShop.java
Normal file
15
src/main/java/com/alttd/playershops/shop/SellShop.java
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
13
src/main/java/com/alttd/playershops/shop/ShopTransaction.java
Executable file
13
src/main/java/com/alttd/playershops/shop/ShopTransaction.java
Executable file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/main/java/com/alttd/playershops/shop/ShopTransactionError.java
Executable file
10
src/main/java/com/alttd/playershops/shop/ShopTransactionError.java
Executable file
|
|
@ -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;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user