diff --git a/src/main/java/space/yurisi/universecorev2/database/DatabaseConnector.java b/src/main/java/space/yurisi/universecorev2/database/DatabaseConnector.java index 1b2ff602..8e8ac116 100644 --- a/src/main/java/space/yurisi/universecorev2/database/DatabaseConnector.java +++ b/src/main/java/space/yurisi/universecorev2/database/DatabaseConnector.java @@ -68,7 +68,8 @@ private Configuration registerAnnotatedClasses(Configuration configuration) { .addAnnotatedClass(CustomName.class) .addAnnotatedClass(Market.class) .addAnnotatedClass(ChestShop.class) - .addAnnotatedClass(Ammo.class); + .addAnnotatedClass(Ammo.class) + .addAnnotatedClass(ReceiveBox.class); } private Configuration registerProperties(Configuration configuration) { diff --git a/src/main/java/space/yurisi/universecorev2/database/DatabaseManager.java b/src/main/java/space/yurisi/universecorev2/database/DatabaseManager.java index 807a9876..b8a57497 100644 --- a/src/main/java/space/yurisi/universecorev2/database/DatabaseManager.java +++ b/src/main/java/space/yurisi/universecorev2/database/DatabaseManager.java @@ -28,6 +28,7 @@ public class DatabaseManager { private final PlayerCountRepository playerCountRepository; private final CustomNameRepository customNameRepository; private final MarketRepository marketRepository; + private final ReceiveBoxRepository receiveBoxRepository; public DatabaseManager(SessionFactory sessionFactory) { this.userRepository = new UserRepository(sessionFactory); @@ -51,6 +52,7 @@ public DatabaseManager(SessionFactory sessionFactory) { this.marketRepository = new MarketRepository(sessionFactory); this.chestShopRepository = new ChestShopRepository(sessionFactory); this.ammoRepository = new AmmoRepository(sessionFactory); + this.receiveBoxRepository = new ReceiveBoxRepository(sessionFactory); } /** @@ -239,4 +241,12 @@ public ChestShopRepository getChestShopRepository() { public AmmoRepository getAmmoRepository() { return ammoRepository; } + + /** + * 受取ボックスリポジトリーを取得 + * @return ReceiveBoxRepository 受取ボックスのリポジトリ + */ + public ReceiveBoxRepository getReceiveBoxRepository(){ + return receiveBoxRepository; + } } diff --git a/src/main/java/space/yurisi/universecorev2/database/models/ReceiveBox.java b/src/main/java/space/yurisi/universecorev2/database/models/ReceiveBox.java new file mode 100644 index 00000000..bd9d71b7 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/database/models/ReceiveBox.java @@ -0,0 +1,175 @@ +package space.yurisi.universecorev2.database.models; + +import jakarta.persistence.*; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import java.util.Date; + +@Entity +@Table(name = "receive_boxes") +public class ReceiveBox { + @Id + @Column(name = "id", columnDefinition = "BIGINT UNSIGNED") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "uuid", columnDefinition = "VARCHAR(255) NOT NULL") + private String uuid; + + @Column(name = "item_name", nullable = false) + private String itemName; + + @Column(name = "display_name") + private String displayName; + + @Column(name = "description") + private String description; + + @Column(name = "serialized_item", nullable = false) + private byte[] serializedItem; + + @Column(name = "serialized_item_stack_json", nullable = false) + private String serializedItemStackJson; + + @Column(name = "serialized_item_meta_json", nullable = false) + private String serializedItemStackMetaJson; + + @Column(name = "is_received") + private boolean is_received; + + @Column(name = "expired_at", nullable = false) + private Date expired_at; + + @CreationTimestamp + @Column(name = "created_at", nullable = false) + private Date created_at; + + @UpdateTimestamp + @Column(name = "updated_at", nullable = false) + private Date updated_at; + + public ReceiveBox( + Long id, + String uuid, + String itemName, + String displayName, + String description, + byte[] serializedItem, + String serializedItemStackJson, + String serializedItemStackMetaJson, + int is_received, + Date expired_at + ) { + this.id = id; + this.uuid = uuid; + this.itemName = itemName; + this.displayName = displayName; + this.description = description; + this.serializedItem = serializedItem; + this.serializedItemStackJson = serializedItemStackJson; + this.serializedItemStackMetaJson = serializedItemStackMetaJson; + this.is_received = (is_received != 0); + this.expired_at = expired_at; + } + + public ReceiveBox() { + + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getDescription(){ + return description; + } + + public void setDescription(String description){ + this.description = description; + } + + public byte[] getSerializedItem() { + return serializedItem; + } + + public void setSerializedItem(byte[] serializedItem) { + this.serializedItem = serializedItem; + } + + public String getSerializedItemStackJson() { + return serializedItemStackJson; + } + + public void setSerializedItemStackJson(String serializedItemStackJson) { + this.serializedItemStackJson = serializedItemStackJson; + } + + public String getSerializedItemStackMetaJson() { + return serializedItemStackMetaJson; + } + + public void setSerializedItemStackMetaJson(String serializedItemStackMetaJson) { + this.serializedItemStackMetaJson = serializedItemStackMetaJson; + } + + public boolean isReceived() { + return is_received; + } + + public void setReceived(boolean is_received) { + this.is_received = is_received; + } + + public Date getExpired_at() { + return expired_at; + } + + public void setExpired_at(Date expired_at) { + this.expired_at = expired_at; + } + + public Date getCreated_at() { + return created_at; + } + + public void setCreated_at(Date created_at) { + this.created_at = created_at; + } + + public Date getUpdated_at() { + return updated_at; + } + + public void setUpdated_at(Date updated_at) { + this.updated_at = updated_at; + } +} diff --git a/src/main/java/space/yurisi/universecorev2/database/repositories/ReceiveBoxRepository.java b/src/main/java/space/yurisi/universecorev2/database/repositories/ReceiveBoxRepository.java new file mode 100644 index 00000000..9e7dfeba --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/database/repositories/ReceiveBoxRepository.java @@ -0,0 +1,126 @@ +package space.yurisi.universecorev2.database.repositories; + +import org.bukkit.entity.Player; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import space.yurisi.universecorev2.database.models.Market; +import space.yurisi.universecorev2.database.models.Mywarp; +import space.yurisi.universecorev2.database.models.ReceiveBox; +import space.yurisi.universecorev2.exception.MywarpNotFoundException; +import space.yurisi.universecorev2.exception.ReceiveBoxNotFoundException; + +import java.util.Date; +import java.util.List; +import java.util.UUID; + +public class ReceiveBoxRepository { + + private final SessionFactory sessionFactory; + + public ReceiveBoxRepository(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + /** + * 受取アイテムを作ります + * + * @return ReceiveBox + */ + public ReceiveBox createReceiveBox(ReceiveBox receiveBox) { + Session session = this.sessionFactory.getCurrentSession(); + try { + session.beginTransaction(); + session.persist(receiveBox); + session.getTransaction().commit(); + + } finally { + session.close(); + } + return receiveBox; + } + + /** + * 受取アイテムをプライマリーキーから検索します + * @param id + * @return ReceiveBox + * @throws ReceiveBoxNotFoundException + */ + public ReceiveBox getItemFromId(Long id) throws ReceiveBoxNotFoundException { + Session session = this.sessionFactory.getCurrentSession(); + try { + session.beginTransaction(); + ReceiveBox data = session.createSelectionQuery("from ReceiveBox where is_received = 0 and id = :id", ReceiveBox.class) + .setParameter("id", id) + .getSingleResult(); + session.getTransaction().commit(); + if (data == null) { + throw new ReceiveBoxNotFoundException("受取ボックスにアイテムが存在しませんでした。id: " + id); + } + return data; + } finally { + session.close(); + } + } + + + /** + * 受取アイテムを全て取得します + * + * @return Market + */ + public List getReceiveBoxes() { + Session session = this.sessionFactory.getCurrentSession(); + try { + session.beginTransaction(); + List receiveBoxes = session.createSelectionQuery("from ReceiveBox where is_received != :is_received", ReceiveBox.class) + .setParameter("is_received", true) + .getResultList(); + session.getTransaction().commit(); + return receiveBoxes; + } finally { + session.close(); + } + } + + /** + * 受取アイテムをプレイヤーから検索します + * @param player + * @return List + */ + public List getReceiveBoxesFromPlayer(Player player) { + Session session = this.sessionFactory.getCurrentSession(); + UUID uuid = player.getUniqueId(); + Date now = new Date(); + try { + session.beginTransaction(); + List receiveBoxes = session.createQuery( + "from ReceiveBox where uuid = :uuid and is_received = 0 and expired_at > :now", ReceiveBox.class) + .setParameter("uuid", uuid.toString()) + .setParameter("now", now) + .getResultList(); + session.getTransaction().commit(); + return receiveBoxes; + } finally { + session.close(); + } + } + + + /** + * 受取アイテムを更新します + * + * @return ReceiveBox + */ + public ReceiveBox updateReceiveBox(ReceiveBox receiveBox){ + Session session = this.sessionFactory.getCurrentSession(); + try { + session.beginTransaction(); + session.merge(receiveBox); + session.getTransaction().commit(); + return receiveBox; + } finally { + session.close(); + } + } + +} diff --git a/src/main/java/space/yurisi/universecorev2/exception/ReceiveBoxNotFoundException.java b/src/main/java/space/yurisi/universecorev2/exception/ReceiveBoxNotFoundException.java new file mode 100644 index 00000000..2e1edf42 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/exception/ReceiveBoxNotFoundException.java @@ -0,0 +1,7 @@ +package space.yurisi.universecorev2.exception; + +public class ReceiveBoxNotFoundException extends Exception{ + public ReceiveBoxNotFoundException(String message){ + super(message); + } +} diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/SubPluginInitializer.java b/src/main/java/space/yurisi/universecorev2/subplugins/SubPluginInitializer.java index b2058882..05d8d0f6 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/SubPluginInitializer.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/SubPluginInitializer.java @@ -19,6 +19,7 @@ import space.yurisi.universecorev2.subplugins.playerhead.PlayerHead; import space.yurisi.universecorev2.subplugins.playerinfoscoreboard.PlayerInfoScoreBoard; import space.yurisi.universecorev2.subplugins.rankcounter.RankCounter; +import space.yurisi.universecorev2.subplugins.receivebox.ReceiveBox; import space.yurisi.universecorev2.subplugins.repaircream.RepairCream; import space.yurisi.universecorev2.subplugins.snowsafeframe.SnowSafeFrame; import space.yurisi.universecorev2.subplugins.tickfreezer.TickFreezer; @@ -79,6 +80,7 @@ private void registerPlugin() { this.subPlugins.add(new TickFreezer()); this.subPlugins.add(new UniverseGuns()); this.subPlugins.add(new SnowSafeFrame()); + this.subPlugins.add(new ReceiveBox()); this.subPlugins.add(new Elevator()); } diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/freemarket/command/marketCommand.java b/src/main/java/space/yurisi/universecorev2/subplugins/freemarket/command/marketCommand.java index b52000f2..05548169 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/freemarket/command/marketCommand.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/freemarket/command/marketCommand.java @@ -14,17 +14,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import space.yurisi.universecorev2.UniverseCoreV2API; -import space.yurisi.universecorev2.database.models.Market; -import space.yurisi.universecorev2.database.models.Money; import space.yurisi.universecorev2.exception.MarketItemNotFoundException; import space.yurisi.universecorev2.exception.MoneyNotFoundException; import space.yurisi.universecorev2.exception.UserNotFoundException; import space.yurisi.universecorev2.subplugins.freemarket.data.Config; -import space.yurisi.universecorev2.subplugins.freemarket.data.JsonConverter; +import space.yurisi.universecorev2.utils.JsonConverter; import space.yurisi.universecorev2.subplugins.freemarket.menu.MarketMenu; import space.yurisi.universecorev2.subplugins.freemarket.menu.PurchasedItemMenu; import space.yurisi.universecorev2.subplugins.freemarket.menu.RemoveMenu; -import space.yurisi.universecorev2.subplugins.universeeconomy.UniverseEconomyAPI; import space.yurisi.universecorev2.subplugins.universeeconomy.exception.CanNotAddMoneyException; import space.yurisi.universecorev2.subplugins.universeeconomy.exception.CanNotReduceMoneyException; import space.yurisi.universecorev2.subplugins.universeeconomy.exception.ParameterException; diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/ReceiveBox.java b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/ReceiveBox.java new file mode 100644 index 00000000..e77bbdc1 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/ReceiveBox.java @@ -0,0 +1,30 @@ +package space.yurisi.universecorev2.subplugins.receivebox; + +import space.yurisi.universecorev2.UniverseCoreV2; +import space.yurisi.universecorev2.subplugins.SubPlugin; +import space.yurisi.universecorev2.subplugins.receivebox.command.addreceiveCommand; +import space.yurisi.universecorev2.subplugins.receivebox.command.receiveCommand; +import space.yurisi.universecorev2.subplugins.repaircream.command.repairCommand; + +public class ReceiveBox implements SubPlugin { + @Override + public void onEnable(UniverseCoreV2 core) { + core.getCommand("receive").setExecutor(new receiveCommand()); + core.getCommand("addreceive").setExecutor(new addreceiveCommand()); + } + + @Override + public void onDisable() { + + } + + @Override + public String getName() { + return "ReceiveBox"; + } + + @Override + public String getVersion() { + return "1.0.0"; + } +} \ No newline at end of file diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/ReceiveBoxAPI.java b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/ReceiveBoxAPI.java new file mode 100644 index 00000000..f4513267 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/ReceiveBoxAPI.java @@ -0,0 +1,38 @@ +package space.yurisi.universecorev2.subplugins.receivebox; + +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import space.yurisi.universecorev2.UniverseCoreV2API; +import space.yurisi.universecorev2.database.models.ReceiveBox; +import space.yurisi.universecorev2.utils.JsonConverter; +import space.yurisi.universecorev2.utils.Message; + +import java.util.Date; +import java.util.UUID; + +public class ReceiveBoxAPI { + + public static void AddReceiveItem(ItemStack itemStack, UUID uuid, Date expire_date, String description){ + String displayName = null; + if(itemStack.getItemMeta() != null){ + displayName = itemStack.getItemMeta().hasDisplayName() ? PlainTextComponentSerializer.plainText().serialize(itemStack.getItemMeta().displayName()) : null; + } + ReceiveBox receiveBox = new ReceiveBox( + null, + uuid.toString(), + itemStack.getType().toString(), + displayName, + description, + itemStack.serializeAsBytes(), + JsonConverter.ItemStackSerializer(itemStack), + JsonConverter.ItemMetaSerializer(itemStack), + 0, + expire_date + ); + UniverseCoreV2API.getInstance().getDatabaseManager().getReceiveBoxRepository().createReceiveBox(receiveBox); + } + + +} diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/command/addreceiveCommand.java b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/command/addreceiveCommand.java new file mode 100644 index 00000000..fe093802 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/command/addreceiveCommand.java @@ -0,0 +1,58 @@ +package space.yurisi.universecorev2.subplugins.receivebox.command; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import space.yurisi.universecorev2.database.models.ReceiveBox; +import space.yurisi.universecorev2.subplugins.receivebox.ReceiveBoxAPI; +import space.yurisi.universecorev2.utils.Message; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class addreceiveCommand implements CommandExecutor { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!(sender instanceof Player player)) { + return false; + } + + if(args.length < 3){ + Message.sendErrorMessage(player, "[管理AI]", "/addreceive player description expire_datetime([YYYY-mm-dd][HH:ii:ss])"); + return false; + } + + ItemStack item = player.getInventory().getItemInMainHand(); + if(item.getType() == Material.AIR){ + Message.sendErrorMessage(player, "[管理AI]", "渡したいアイテムを手に持って下さい。"); + return false; + } + + OfflinePlayer target = Bukkit.getOfflinePlayerIfCached(args[0]); + if(target == null){ + Message.sendErrorMessage(player, "[管理AI]", "プレイヤーが存在しません。"); + return false; + } + + // 日付フォーマットを指定 + SimpleDateFormat formatter = new SimpleDateFormat("[yyyy-MM-dd][HH:mm:ss]"); + + try { + Date date = formatter.parse(args[2]); + + + ReceiveBoxAPI.AddReceiveItem(item, target.getUniqueId(), date ,args[1]); + Message.sendSuccessMessage(player, "[管理AI]", "追加しました!"); + } catch (ParseException e) { + Message.sendErrorMessage(player, "[管理AI]", "日時のフォーマットが違います。"); + } + + return true; + } +} diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/command/receiveCommand.java b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/command/receiveCommand.java new file mode 100644 index 00000000..c4c12ea5 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/command/receiveCommand.java @@ -0,0 +1,20 @@ +package space.yurisi.universecorev2.subplugins.receivebox.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import space.yurisi.universecorev2.subplugins.receivebox.menu.ReceiveBoxMenu; + +public class receiveCommand implements CommandExecutor { + + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!(sender instanceof Player player)) { + return false; + } + + new ReceiveBoxMenu().sendMenu(player); + return true; + } +} diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/menu/ReceiveBoxMenu.java b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/menu/ReceiveBoxMenu.java new file mode 100644 index 00000000..79d7cde9 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/menu/ReceiveBoxMenu.java @@ -0,0 +1,50 @@ +package space.yurisi.universecorev2.subplugins.receivebox.menu; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import space.yurisi.universecorev2.UniverseCoreV2API; +import space.yurisi.universecorev2.menu.BaseMenu; +import space.yurisi.universecorev2.menu.menu_item.BackItem; +import space.yurisi.universecorev2.menu.menu_item.ForwardItem; +import space.yurisi.universecorev2.subplugins.receivebox.menu.menu_item.ReceiveBoxItem; +import xyz.xenondevs.invui.gui.PagedGui; +import xyz.xenondevs.invui.gui.structure.Markers; +import xyz.xenondevs.invui.item.Item; +import xyz.xenondevs.invui.item.builder.ItemBuilder; +import xyz.xenondevs.invui.item.impl.SimpleItem; +import xyz.xenondevs.invui.window.Window; + +import java.util.List; +import java.util.stream.Collectors; + +public class ReceiveBoxMenu implements BaseMenu { + + @Override + public void sendMenu(Player player) { + List items = UniverseCoreV2API.getInstance().getDatabaseManager().getReceiveBoxRepository().getReceiveBoxesFromPlayer(player).stream() + .map(ReceiveBoxItem::new) + .collect(Collectors.toList()); + + Item border = new SimpleItem(new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE)); + PagedGui gui = PagedGui.items() + .setStructure( + "x x x x x x x x #", + "x x x x x x x x u", + "x x x x x x x x d", + "x x x x x x x x #") + .addIngredient('#', border) + .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) + .addIngredient('u', new BackItem()) + .addIngredient('d', new ForwardItem()) + .setContent(items) + .build(); + + Window window = Window.single() + .setViewer(player) + .setGui(gui) + .setTitle("報酬受け取りボックス") + .build(); + + window.open(); + } +} diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/menu/menu_item/ReceiveBoxItem.java b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/menu/menu_item/ReceiveBoxItem.java new file mode 100644 index 00000000..be051a3e --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/subplugins/receivebox/menu/menu_item/ReceiveBoxItem.java @@ -0,0 +1,56 @@ +package space.yurisi.universecorev2.subplugins.receivebox.menu.menu_item; + +import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import space.yurisi.universecorev2.UniverseCoreV2API; +import space.yurisi.universecorev2.database.models.ReceiveBox; +import space.yurisi.universecorev2.subplugins.receivebox.menu.ReceiveBoxMenu; +import space.yurisi.universecorev2.utils.Message; +import space.yurisi.universecorev2.utils.Sound; +import xyz.xenondevs.invui.item.ItemProvider; +import xyz.xenondevs.invui.item.builder.ItemBuilder; +import xyz.xenondevs.invui.item.impl.AbstractItem; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class ReceiveBoxItem extends AbstractItem { + ReceiveBox receiveBox; + + public ReceiveBoxItem(ReceiveBox receiveBox) { + this.receiveBox = receiveBox; + } + + @Override + public ItemProvider getItemProvider() { + ItemStack itemStack = ItemStack.deserializeBytes(receiveBox.getSerializedItem()); + Date date = this.receiveBox.getExpired_at(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH時mm分"); + String formattedDate = sdf.format(date); + + return new ItemBuilder(itemStack) + .addLoreLines( + this.receiveBox.getDescription(), + "期限: §c" + formattedDate) + .setAmount(itemStack.getAmount()); + } + + @Override + public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { + if (player.getInventory().firstEmpty() != -1) { + this.receiveBox.setReceived(true); + UniverseCoreV2API.getInstance().getDatabaseManager().getReceiveBoxRepository().updateReceiveBox(this.receiveBox); + Sound.sendSuccessSound(player); + Message.sendSuccessMessage(player, "[管理AI]", "アイテムを受け取りました!"); + player.getInventory().addItem(ItemStack.deserializeBytes(this.receiveBox.getSerializedItem())); + }else{ + Message.sendErrorMessage(player, "[管理AI]", "アイテムがいっぱいです!"); + } + + new ReceiveBoxMenu().sendMenu(player); + } +} diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/freemarket/data/JsonConverter.java b/src/main/java/space/yurisi/universecorev2/utils/JsonConverter.java similarity index 90% rename from src/main/java/space/yurisi/universecorev2/subplugins/freemarket/data/JsonConverter.java rename to src/main/java/space/yurisi/universecorev2/utils/JsonConverter.java index 2b3ebbd7..d57571ca 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/freemarket/data/JsonConverter.java +++ b/src/main/java/space/yurisi/universecorev2/utils/JsonConverter.java @@ -1,4 +1,4 @@ -package space.yurisi.universecorev2.subplugins.freemarket.data; +package space.yurisi.universecorev2.utils; import com.google.gson.Gson; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/space/yurisi/universecorev2/utils/Sound.java b/src/main/java/space/yurisi/universecorev2/utils/Sound.java new file mode 100644 index 00000000..28bea240 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/utils/Sound.java @@ -0,0 +1,18 @@ +package space.yurisi.universecorev2.utils; + +import org.bukkit.entity.Player; + +public class Sound { + + public static void sendSuccessSound(Player player){ + player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_BLOCK_PLING, 1, 1); + } + + public static void sendErrorSound(Player player){ + //TODO + } + + public static void sendTeleportSound(Player player){ + player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_ENDERMAN_TELEPORT, 1, 1); + } +} diff --git a/src/main/resources/db/migration/V2024.10.13.01__create_receive_box_table.sql b/src/main/resources/db/migration/V2024.10.13.01__create_receive_box_table.sql new file mode 100644 index 00000000..d78214b5 --- /dev/null +++ b/src/main/resources/db/migration/V2024.10.13.01__create_receive_box_table.sql @@ -0,0 +1,16 @@ +use SpaceServerUniverse; + +CREATE TABLE IF NOT EXISTS receive_boxes ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + uuid VARCHAR(255) NOT NULL, + item_name VARCHAR(255) NOT NULL, + display_name VARCHAR(255), + description VARCHAR(255) NOT NULL, + serialized_item BLOB NOT NULL, + serialized_item_stack_json TEXT NOT NULL, + serialized_item_meta_json TEXT NOT NULL, + is_received INTEGER(1) NOT NULL DEFAULT 0, + expired_at DATETIME NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fdb6a45c..5be3de4a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -120,6 +120,12 @@ commands: item: description: メインハンドに持ったアイテムの名前を表示します + # ReceiveBox + receive: + description: アイテム受取ボックスを表示します + addreceive: + description: アイテム受取ボックスに追加します + permissions: # UniverseCoreV2 space.yurisi.universecorev2.interactevent.enchanttable: