diff --git a/src/main/java/space/yurisi/universecorev2/command/CommandManager.java b/src/main/java/space/yurisi/universecorev2/command/CommandManager.java index 78b0d345..08510262 100644 --- a/src/main/java/space/yurisi/universecorev2/command/CommandManager.java +++ b/src/main/java/space/yurisi/universecorev2/command/CommandManager.java @@ -12,6 +12,7 @@ public CommandManager(UniverseCoreV2 main){ } private void init(){ + main.getCommand("menu").setExecutor(new menuCommand()); main.getCommand("password").setExecutor(new passwordCommand()); main.getCommand("pplayer").setExecutor(new pplayerCommand()); main.getCommand("lobby").setExecutor(new lobbyCommand()); diff --git a/src/main/java/space/yurisi/universecorev2/command/menuCommand.java b/src/main/java/space/yurisi/universecorev2/command/menuCommand.java new file mode 100644 index 00000000..a892072b --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/command/menuCommand.java @@ -0,0 +1,37 @@ +package space.yurisi.universecorev2.command; + +import org.bukkit.Sound; +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.menu.MainMenu; +import space.yurisi.universecorev2.utils.Message; + +import java.util.Random; + +public class menuCommand implements CommandExecutor { + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + if (!(sender instanceof Player player)) { + return false; + } + + MainMenu mainMenu = new MainMenu(); + mainMenu.sendMenu(player); + + // 0.122%の確率でクリーパーの効果音を再生 + if (new Random().nextDouble() < 0.000122) { + player.playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 10, 1); + player.playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 10, 1); + Message.sendSuccessMessage(player, "[管理AI]", "§c§oメニューを開きました...ヮ! クリーパーが... (´・ω・`)"); + } else { + player.playSound(player.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_FALL, 10, 1); + Message.sendSuccessMessage(player, "[管理AI]", "メニューを開きました"); + } + + return true; + } +} diff --git a/src/main/java/space/yurisi/universecorev2/menu/MainMenu.java b/src/main/java/space/yurisi/universecorev2/menu/MainMenu.java new file mode 100644 index 00000000..444e2069 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/menu/MainMenu.java @@ -0,0 +1,176 @@ +package space.yurisi.universecorev2.menu; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; +import space.yurisi.universecorev2.UniverseCoreV2API; +import space.yurisi.universecorev2.database.DatabaseManager; +import space.yurisi.universecorev2.database.models.User; +import space.yurisi.universecorev2.database.repositories.CustomNameRepository; +import space.yurisi.universecorev2.database.repositories.UserRepository; +import space.yurisi.universecorev2.exception.CustomNameNotFoundException; +import space.yurisi.universecorev2.exception.MoneyNotFoundException; +import space.yurisi.universecorev2.exception.UserNotFoundException; +import space.yurisi.universecorev2.subplugins.universeeconomy.UniverseEconomyAPI; +import space.yurisi.universecorev2.utils.Message; +import space.yurisi.universecorev2.utils.TimeHelper; +import xyz.xenondevs.invui.gui.Gui; +import xyz.xenondevs.invui.item.Item; +import xyz.xenondevs.invui.item.builder.ItemBuilder; +import xyz.xenondevs.invui.item.impl.CommandItem; +import xyz.xenondevs.invui.item.impl.SimpleItem; +import xyz.xenondevs.invui.window.Window; + +import java.time.LocalTime; +import java.util.Arrays; +import java.util.List; + +public class MainMenu implements BaseMenu { + + public void sendMenu(Player player) { + Item border = new SimpleItem(new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE)); + Item inMenuBorder = new SimpleItem(new ItemBuilder(Material.LIGHT_BLUE_STAINED_GLASS_PANE)); + + Item executeMywarp = new CommandItem(new ItemBuilder(Material.COMPASS) + .setDisplayName("マイワープ") + .setLegacyLore(List.of("§6保存した場所にテレポートします")), + "/mywarp"); + Item executeMarket = new CommandItem(new ItemBuilder(Material.EMERALD) + .setDisplayName("マーケット") + .setLegacyLore(List.of("§6プレイヤー間のアイテム取引ができます")), + "/market"); + Item executeTpp = new CommandItem(new ItemBuilder(Material.ENDER_PEARL) + .setDisplayName("プレイヤー間テレポート") + .setLegacyLore(List.of("§6他のプレイヤーにテレポートできます")), + "/tpp"); + Item executeGacha = new CommandItem(new ItemBuilder(Material.NETHER_STAR) + .setDisplayName("ガチャ") + .setLegacyLore(List.of("§6ガチャを引くことができます")), + "/gacha"); + Item executeWiki = new CommandItem(new ItemBuilder(Material.MAP) + .setDisplayName("Wiki") + .setLegacyLore(List.of("§6公式WikiへのURLを表示します")), + "/wiki"); + Item executeWeb = new CommandItem(new ItemBuilder(Material.RECOVERY_COMPASS) + .setDisplayName("UniverseWeb") + .setLegacyLore(List.of("§6ランキングなどのオンラインサービスである UniverseWeb へのURLを表示します")), + "/web"); + // TODO: Add execute /money command + Item executeMoney = new SimpleItem(new ItemBuilder(Material.GOLD_INGOT) + .setDisplayName("銀行 (未実装)") + .setLegacyLore(List.of("§6お金を管理します"))); + Item executeTrash = new CommandItem(new ItemBuilder(Material.NETHER_STAR) + .setDisplayName("ゴミ箱") + .setLegacyLore(List.of("§6ゴミ箱を開きます。取り扱い注意!")), + "/trash"); + Item executeTag = new CommandItem(new ItemBuilder(Material.NAME_TAG) + .setDisplayName("称号設定") + .setLegacyLore(List.of("§6称号を設定します")), + "/tag"); + Item executeHead = new CommandItem(new ItemBuilder(Material.PLAYER_HEAD) + .setDisplayName("プレイヤーヘッド") + .setLegacyLore(List.of("§6他のプレイヤーのヘッドを購入します")), + "/head"); + + Gui gui = Gui.normal() + .setStructure( + "= # # # i # # # #", + "# + a m t g y + #", + "# + w u n s h + #", + "# # # # # # # # #" + ) + .addIngredient('#', border) + .addIngredient('+', inMenuBorder) + .addIngredient('=', createServerInfoItem()) + .addIngredient('i', createPlayerInfoHead(player)) + .addIngredient('a', executeGacha) + .addIngredient('m', executeMywarp) + .addIngredient('t', executeTpp) + .addIngredient('g', executeMoney) + .addIngredient('y', executeMarket) + .addIngredient('w', executeWiki) + .addIngredient('u', executeWeb) + .addIngredient('n', executeTag) + .addIngredient('s', executeTrash) + .addIngredient('h', executeHead) + .build(); + + xyz.xenondevs.invui.window.Window window = Window.single() + .setViewer(player) + .setGui(gui) + .setTitle("メインメニュー") + .build(); + + window.open(); + } + + private Item createPlayerInfoHead(Player player) { + ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1); + SkullMeta skullMeta = (SkullMeta) playerHead.getItemMeta(); + skullMeta.setOwningPlayer(player); + playerHead.setItemMeta(skullMeta); + + DatabaseManager dbManager = UniverseCoreV2API.getInstance().getDatabaseManager(); + UniverseEconomyAPI economyAPI = UniverseEconomyAPI.getInstance(); + UserRepository userRepo = dbManager.getUserRepository(); + CustomNameRepository customNameRepo = dbManager.getCustomNameRepository(); + + Long money = 0L; + String customName = "未設定"; + + try { + User user = userRepo.getUserFromUUID(player.getUniqueId()); + + money = economyAPI.getMoney(player); + if(customNameRepo.existsCustomNameFromUserId(user.getId())) { + customName = customNameRepo.getCustomNameFromUserId(user.getId()).getDisplay_custom_tag(); + } + } catch (UserNotFoundException e) { + money = 0L; + customName = "§c(取得できませんでした)"; + Message.sendErrorMessage(player,"[管理AI]", "ユーザーデータが見つかりませんでした。"); + } catch (MoneyNotFoundException e) { + money = 0L; + Message.sendErrorMessage(player,"[管理AI]", "所持金データが見つかりませんでした。"); + } catch (CustomNameNotFoundException e) { + customName = "§c(取得できませんでした)"; + Message.sendErrorMessage(player,"[管理AI]", "称号データが見つかりませんでした。"); + } + + String greetingWithName = switch (TimeHelper.checkTime()) { + case MORNING -> "§bおはようございます、 §r" + player.getName(); + case AFTERNOON -> "§6こんにちは、 §r" + player.getName(); + case EVENING -> "§9こんばんは、 §r" + player.getName(); + }; + + List playerinfo = List.of( + "§a名前: §r" + player.getName(), + "§a称号:§r" + customName, + "§a所持金: §r" + money + economyAPI.getUnit(), + "§a現在地: §r" + player.getWorld().getName(), + "§a座標: §r" + player.getLocation().getBlockX() + ", " + player.getLocation().getBlockY() + ", " + player.getLocation().getBlockZ(), + "§aPing値: §r" + player.getPing() + "ms" + ); + + return new SimpleItem(new ItemBuilder(playerHead) + .setDisplayName(greetingWithName) + .setLegacyLore(playerinfo)); + } + + private Item createServerInfoItem() { + Server server = Bukkit.getServer(); + List serverinfo = List.of( + "§aオンライン人数: §r" + server.getOnlinePlayers().size() + "/" + server.getMaxPlayers(), + "§aUniverseCoreV2のバージョン: §r" + server.getPluginManager().getPlugin("UniverseCoreV2").getDescription().getVersion(), + "§aTPS値: §r" + String.format("%.1f, %.1f, %.1f", server.getTPS()[0], server.getTPS()[1], server.getTPS()[2]), + "§aバージョン: §r" + server.getBukkitVersion() + " - " + server.getVersion() + ); + + return new SimpleItem(new ItemBuilder(Material.SOUL_LANTERN) + .setDisplayName("§bサーバー情報") + .setLegacyLore(serverinfo)); + } +} diff --git a/src/main/java/space/yurisi/universecorev2/utils/TimeHelper.java b/src/main/java/space/yurisi/universecorev2/utils/TimeHelper.java new file mode 100644 index 00000000..b7d561b7 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/utils/TimeHelper.java @@ -0,0 +1,25 @@ +package space.yurisi.universecorev2.utils; + +import space.yurisi.universecorev2.utils.time_type.TimeType; +import java.time.LocalTime; + +public class TimeHelper { + + /** + * 現在時刻をチェックし、その時間帯を返します。 + * + * @return TimeType 時間帯 -- MORNING: 朝, AFTERNOON: 昼, EVENING: 夜 + */ + public static TimeType checkTime() { + LocalTime now = LocalTime.now(); + + if (now.isBefore(LocalTime.NOON)) { + return TimeType.MORNING; + } else if (now.isBefore(LocalTime.of(18, 0))) { + return TimeType.AFTERNOON; + } else { + return TimeType.EVENING; + } + } + +} diff --git a/src/main/java/space/yurisi/universecorev2/utils/time_type/TimeType.java b/src/main/java/space/yurisi/universecorev2/utils/time_type/TimeType.java new file mode 100644 index 00000000..730d0c37 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/utils/time_type/TimeType.java @@ -0,0 +1,7 @@ +package space.yurisi.universecorev2.utils.time_type; + +public enum TimeType { + MORNING, + AFTERNOON, + EVENING +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 74de3f83..59dab578 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,6 +3,9 @@ version: '1.0' main: space.yurisi.universecorev2.UniverseCoreV2 api-version: '1.21' commands: + menu: + description: メニューを開きます + aliases: [ m ] password: description: パスワードを設定します pplayer: