|
|
|
@ -1,19 +1,27 @@ |
|
|
|
package xyz.soukup.ecoCraftCore.objects; |
|
|
|
package xyz.soukup.ecoCraftCore.objects; |
|
|
|
import com.j256.ormlite.field.DatabaseField; |
|
|
|
import com.j256.ormlite.field.DatabaseField; |
|
|
|
import com.j256.ormlite.table.DatabaseTable; |
|
|
|
import com.j256.ormlite.table.DatabaseTable; |
|
|
|
|
|
|
|
import net.kyori.adventure.text.Component; |
|
|
|
|
|
|
|
import org.bukkit.block.Sign; |
|
|
|
|
|
|
|
import org.bukkit.block.TileState; |
|
|
|
|
|
|
|
import org.bukkit.block.sign.Side; |
|
|
|
|
|
|
|
import org.bukkit.block.sign.SignSide; |
|
|
|
import org.bukkit.entity.Player; |
|
|
|
import org.bukkit.entity.Player; |
|
|
|
import org.bukkit.inventory.ItemStack; |
|
|
|
import org.bukkit.inventory.ItemStack; |
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.DaoRegistry; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.DaoRegistry; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.JSONConverter; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.JSONConverter; |
|
|
|
|
|
|
|
import xyz.soukup.ecoCraftCore.utilities.PDC; |
|
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.Timestamp; |
|
|
|
import java.sql.Timestamp; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@DatabaseTable(tableName = "shops") |
|
|
|
@DatabaseTable(tableName = "shops") |
|
|
|
public class Shop { |
|
|
|
public class Shop { |
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(generatedId = true) |
|
|
|
@DatabaseField(generatedId = true) |
|
|
|
private long id; |
|
|
|
private int id; |
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
private String owner; |
|
|
|
private String owner; |
|
|
|
@ -40,6 +48,8 @@ public class Shop { |
|
|
|
@DatabaseField(canBeNull = false, defaultValue = "0") |
|
|
|
@DatabaseField(canBeNull = false, defaultValue = "0") |
|
|
|
private int stock; |
|
|
|
private int stock; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(canBeNull = false, defaultValue = "0", columnName = "free_space") |
|
|
|
|
|
|
|
private int freeSpace; |
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
private int virtualChestID; |
|
|
|
private int virtualChestID; |
|
|
|
@ -54,12 +64,13 @@ public class Shop { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Shop(Player player, ItemStack itemStack, int stock, int amount, float priceBuy, float priceSell, int virtualChestID) { |
|
|
|
public Shop(Player player, ItemStack itemStack, int stock, int freeSpace, int amount, float priceBuy, float priceSell, int virtualChestID) { |
|
|
|
this.ownerType = "player"; |
|
|
|
this.ownerType = "player"; |
|
|
|
this.owner = player.getName(); |
|
|
|
this.owner = player.getName(); |
|
|
|
this.itemStackJson = JSONConverter.itemStackToJson(itemStack); |
|
|
|
this.itemStackJson = JSONConverter.itemStackToJson(itemStack); |
|
|
|
this.itemName = itemStack.getType().toString(); |
|
|
|
this.itemName = itemStack.getType().toString(); |
|
|
|
this.stock = stock; |
|
|
|
this.stock = stock; |
|
|
|
|
|
|
|
this.freeSpace = freeSpace; |
|
|
|
this.amount = amount; |
|
|
|
this.amount = amount; |
|
|
|
this.priceBuy = priceBuy; |
|
|
|
this.priceBuy = priceBuy; |
|
|
|
this.priceSell = priceSell; |
|
|
|
this.priceSell = priceSell; |
|
|
|
@ -110,6 +121,35 @@ public class Shop { |
|
|
|
return JSONConverter.itemStackFromJson(this.itemStackJson); |
|
|
|
return JSONConverter.itemStackFromJson(this.itemStackJson); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void writeIntoSign(Sign sign){ |
|
|
|
|
|
|
|
PDC.set(sign, "shop", this.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Component prices; |
|
|
|
|
|
|
|
Component shopType; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.priceBuy != 0 && this.priceSell != 0){ |
|
|
|
|
|
|
|
shopType = Component.text("[ buy / sell ]"); |
|
|
|
|
|
|
|
prices = Component.text(String.format("%.2fŧ / %.2fŧ", this.priceBuy, this.priceSell)); |
|
|
|
|
|
|
|
} else if (this.priceBuy != 0) { |
|
|
|
|
|
|
|
shopType = Component.text("[ buy ]"); |
|
|
|
|
|
|
|
prices = Component.text(String.format("%.2fŧ", this.priceBuy)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
shopType = Component.text("[ sell ]"); |
|
|
|
|
|
|
|
prices = Component.text(String.format("%.2fŧ", this.priceSell)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NotNull SignSide side = sign.getSide(Side.FRONT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
side.line(0, Component.text(this.owner)); |
|
|
|
|
|
|
|
side.line(1, Component.text(this.itemName)); |
|
|
|
|
|
|
|
side.line(2, shopType); |
|
|
|
|
|
|
|
side.line(3, prices); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sign.update(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public long getId() { |
|
|
|
public long getId() { |
|
|
|
return id; |
|
|
|
return id; |
|
|
|
} |
|
|
|
} |
|
|
|
|