diff --git a/src/main/java/space/yurisi/universecorev2/command/menuCommand.java b/src/main/java/space/yurisi/universecorev2/command/menuCommand.java index a892072b..5ad0fbfa 100644 --- a/src/main/java/space/yurisi/universecorev2/command/menuCommand.java +++ b/src/main/java/space/yurisi/universecorev2/command/menuCommand.java @@ -4,11 +4,20 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import space.yurisi.universecorev2.item.CustomItem; +import space.yurisi.universecorev2.item.UniverseItem; +import space.yurisi.universecorev2.item.book.MainMenuBook; import space.yurisi.universecorev2.menu.MainMenu; import space.yurisi.universecorev2.utils.Message; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Random; public class menuCommand implements CommandExecutor { @@ -19,19 +28,50 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command 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]", "メニューを開きました"); - } + switch (args.length) { + case 0: + MainMenu mainMenu = new MainMenu(); + mainMenu.sendMenu(player); + + 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); + return true; + } + + player.playSound(player.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_FALL, 10, 1); + return true; + case 1: + if (!args[0].equals("book")) { + Message.sendWarningMessage(player, "[管理AI]", "メインメニュー用のアイテムを入手するには [/menu book] と入力してください。"); + return false; + } + + CustomItem item = UniverseItem.getItem(MainMenuBook.id); + Inventory inv = player.getInventory(); + if (inv.firstEmpty() == -1) { + Message.sendErrorMessage(player, "[管理AI]", "インベントリがいっぱいです。"); + return false; + } - return true; + if (item == null) { + Message.sendErrorMessage(player, "[管理AI]", "不明なエラーが発生しました。運営に報告してください。通常通りのメニューは [/menu] で開けます。"); + return false; + } + + ItemStack itemStack = item.getItem(); + if (inv.contains(item.getItem())) { + Message.sendErrorMessage(player, "[管理AI]", "既にメインメニュー用のアイテムを持っています。"); + return false; + } + + inv.addItem(itemStack); + + Message.sendSuccessMessage(player, "[管理AI]", "メインメニュー用のアイテムをインベントリに追加しました"); + return true; + default: + Message.sendNormalMessage(player, "[管理AI]", "[/menu] でメインメニューを開くか、[/menu book] でメインメニュー用のアイテムを入手できます。"); + return true; + } } } diff --git a/src/main/java/space/yurisi/universecorev2/event/EventManager.java b/src/main/java/space/yurisi/universecorev2/event/EventManager.java index fa81214e..b69f9052 100644 --- a/src/main/java/space/yurisi/universecorev2/event/EventManager.java +++ b/src/main/java/space/yurisi/universecorev2/event/EventManager.java @@ -7,10 +7,7 @@ import space.yurisi.universecorev2.event.block.PlaceEvent; import space.yurisi.universecorev2.event.entity.EExplodeEvent; import space.yurisi.universecorev2.event.entity.EntityHangingBreakEvent; -import space.yurisi.universecorev2.event.player.InteractEvent; -import space.yurisi.universecorev2.event.player.LoginEvent; -import space.yurisi.universecorev2.event.player.TouchEvent; -import space.yurisi.universecorev2.event.player.TeleportEvent; +import space.yurisi.universecorev2.event.player.*; public class EventManager { public EventManager(UniverseCoreV2 main){ @@ -22,10 +19,10 @@ private void init(UniverseCoreV2 main) { Bukkit.getPluginManager().registerEvents(new TeleportEvent(main), main); Bukkit.getPluginManager().registerEvents(new BreakEvent(), main); Bukkit.getPluginManager().registerEvents(new PlaceEvent(), main); - Bukkit.getPluginManager().registerEvents(new TouchEvent(), main); + Bukkit.getPluginManager().registerEvents(new OpenMainMenuEvent(), main); Bukkit.getPluginManager().registerEvents(new BExplodeEvent(),main); Bukkit.getPluginManager().registerEvents(new EExplodeEvent(),main); - Bukkit.getPluginManager().registerEvents(new InteractEvent(), main); + Bukkit.getPluginManager().registerEvents(new BlockProtectEvent(), main); Bukkit.getPluginManager().registerEvents(new EntityHangingBreakEvent(),main); } } diff --git a/src/main/java/space/yurisi/universecorev2/event/player/InteractEvent.java b/src/main/java/space/yurisi/universecorev2/event/player/BlockProtectEvent.java similarity index 73% rename from src/main/java/space/yurisi/universecorev2/event/player/InteractEvent.java rename to src/main/java/space/yurisi/universecorev2/event/player/BlockProtectEvent.java index 7d1a3a88..64ecbf0e 100644 --- a/src/main/java/space/yurisi/universecorev2/event/player/InteractEvent.java +++ b/src/main/java/space/yurisi/universecorev2/event/player/BlockProtectEvent.java @@ -9,7 +9,7 @@ import space.yurisi.universecorev2.api.LuckPermsWrapper; import space.yurisi.universecorev2.utils.Message; -public class InteractEvent implements Listener { +public class BlockProtectEvent implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onInteract(PlayerInteractEvent event) { @@ -25,7 +25,18 @@ public void onInteract(PlayerInteractEvent event) { switch (targetBlock.getType()) { case ENCHANTING_TABLE -> { if (LuckPermsWrapper.isUserInAdminOrDevGroup(player)) { - Message.sendSuccessMessage(player, "[管理AI]", "対象ブロック [エンチャントテーブル] の利用制限をバイパスしました"); + event.setCancelled(false); + break; + } + + event.setCancelled(true); + } + case ANVIL -> { + if (!player.getWorld().getName().equals("lobby")) { + return; + } + + if (LuckPermsWrapper.isUserInAdminOrDevGroup(player)) { event.setCancelled(false); break; } diff --git a/src/main/java/space/yurisi/universecorev2/event/player/OpenMainMenuEvent.java b/src/main/java/space/yurisi/universecorev2/event/player/OpenMainMenuEvent.java new file mode 100644 index 00000000..96d70db3 --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/event/player/OpenMainMenuEvent.java @@ -0,0 +1,33 @@ +package space.yurisi.universecorev2.event.player; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import space.yurisi.universecorev2.item.UniverseItem; +import space.yurisi.universecorev2.item.book.MainMenuBook; + +public class OpenMainMenuEvent implements Listener { + + @EventHandler(priority = EventPriority.HIGH) + public void onInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + + ItemStack targetItem = event.getItem(); + + switch (targetItem.getType()) { + case KNOWLEDGE_BOOK -> { + ItemStack item = UniverseItem.getItem(MainMenuBook.id).getItem(); + if (targetItem.isSimilar(item)) { + Bukkit.dispatchCommand(player, "menu"); + } + event.setCancelled(true); + } + } + + } + +} diff --git a/src/main/java/space/yurisi/universecorev2/event/player/TouchEvent.java b/src/main/java/space/yurisi/universecorev2/event/player/TouchEvent.java deleted file mode 100644 index 79995bf8..00000000 --- a/src/main/java/space/yurisi/universecorev2/event/player/TouchEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package space.yurisi.universecorev2.event.player; - -import org.bukkit.Material; -import org.bukkit.block.ShulkerBox; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.block.Block; -import org.bukkit.event.player.PlayerInteractEvent; - -public class TouchEvent implements Listener { - - @EventHandler - public void onTouch(PlayerInteractEvent event) { - Player player = event.getPlayer(); - Block targetBlock = event.getClickedBlock(); - if(targetBlock == null){ - return; - } - if(targetBlock.getType() != Material.ANVIL && !(targetBlock.getState() instanceof ShulkerBox)){ - return; - } - if(player.getWorld().getName().equals("lobby") && !player.isOp()){ - event.setCancelled(true); - } - } -} diff --git a/src/main/java/space/yurisi/universecorev2/item/UniverseItem.java b/src/main/java/space/yurisi/universecorev2/item/UniverseItem.java index 430f57ac..850b5434 100644 --- a/src/main/java/space/yurisi/universecorev2/item/UniverseItem.java +++ b/src/main/java/space/yurisi/universecorev2/item/UniverseItem.java @@ -9,6 +9,7 @@ import org.bukkit.persistence.PersistentDataType; import space.yurisi.universecorev2.UniverseCoreV2; import space.yurisi.universecorev2.constants.UniverseItemKeyString; +import space.yurisi.universecorev2.item.book.MainMenuBook; import space.yurisi.universecorev2.item.fishingrod.FishingRod; import space.yurisi.universecorev2.item.pickaxe.FishingPickaxe; import space.yurisi.universecorev2.item.gun.*; @@ -16,6 +17,7 @@ import space.yurisi.universecorev2.item.solar_system.*; import space.yurisi.universecorev2.item.stick.BlockCopyStick; import space.yurisi.universecorev2.item.ticket.GachaTicket; +import space.yurisi.universecorev2.menu.MainMenu; import java.util.HashMap; import java.util.Objects; @@ -48,6 +50,7 @@ public void register(){ items.put(F2.id, new F2()); items.put(M870.id, new M870()); items.put(MagazineBag.id, new MagazineBag()); + items.put(MainMenuBook.id, new MainMenuBook()); } public static CustomItem getItem(String id){ diff --git a/src/main/java/space/yurisi/universecorev2/item/book/MainMenuBook.java b/src/main/java/space/yurisi/universecorev2/item/book/MainMenuBook.java new file mode 100644 index 00000000..f6f6a9af --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/item/book/MainMenuBook.java @@ -0,0 +1,36 @@ +package space.yurisi.universecorev2.item.book; + +import net.kyori.adventure.text.Component; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import space.yurisi.universecorev2.item.CustomItem; + +public class MainMenuBook extends CustomItem { + + public static final String id = "main_menu_book"; + + public MainMenuBook() { + super( + id, + "§eメインメニュー", + // 本来の用途はレシピの限定解放だが, あくまでミニゲーム用で生活鯖運用ではただの緑の本 + // https://ja.minecraft.wiki/w/%E7%9F%A5%E6%81%B5%E3%81%AE%E6%9C%AC + ItemStack.of(Material.KNOWLEDGE_BOOK) + ); + } + + @Override + protected void registerItemFunction() { + default_setting = (item) -> { + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.addEnchant(Enchantment.VANISHING_CURSE, 1, true); + meta.setUnbreakable(true); + item.setItemMeta(meta); + } + return item; + }; + } +} diff --git a/src/main/java/space/yurisi/universecorev2/menu/MainMenu.java b/src/main/java/space/yurisi/universecorev2/menu/MainMenu.java index 8e545237..43e0208c 100644 --- a/src/main/java/space/yurisi/universecorev2/menu/MainMenu.java +++ b/src/main/java/space/yurisi/universecorev2/menu/MainMenu.java @@ -69,13 +69,21 @@ public void sendMenu(Player player) { .setDisplayName("報酬受け取り") .setLegacyLore(List.of("§6報酬受け取りメニューを開きます")), "/receive"); + Item executeBirthday = new CommandItem(new ItemBuilder(Material.CAKE) + .setDisplayName("誕生日カードメニュー") + .setLegacyLore(List.of("§6誕生日カードメニューを開きます")), + "/birthday"); + Item executeMenuBook = new CommandItem(new ItemBuilder(Material.KNOWLEDGE_BOOK) + .setDisplayName("メインメニューの本を召喚する") + .setLegacyLore(List.of("§6右クリックでメニューが開ける本を召喚します")), + "/menu book"); Gui gui = Gui.normal() .setStructure( "# # # i # = # # #", "# + a m t o y + #", - "# + + n s h p + #", - "# # # # l # # # #" + "# + k n s h p + #", + "b # # # l # # # #" ) .addIngredient('#', border) .addIngredient('+', inMenuBorder) @@ -85,11 +93,13 @@ public void sendMenu(Player player) { .addIngredient('m', executeMywarp) .addIngredient('t', executeTpp) .addIngredient('y', executeMarket) + .addIngredient('k', executeBirthday) .addIngredient('n', executeTag) .addIngredient('s', executeTrash) .addIngredient('h', executeHead) .addIngredient('o', executeAmmo) .addIngredient('p', executeReceive) + .addIngredient('b', executeMenuBook) .addIngredient('l', new LaunchNavigationItem()) .build();