Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: メインメニュー関連の改善 #161

Merged
merged 6 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 55 additions & 13 deletions src/main/java/space/yurisi/universecorev2/command/menuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -18,20 +27,53 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (!(sender instanceof Player player)) {
return false;
}

switch (args.length) {
case 0:
MainMenu mainMenu = new MainMenu();
mainMenu.sendMenu(player);

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]", "メニューを開きました");
}
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メニューを開きました...ヮ! クリーパーが... (´・ω・`)");
return true;
}

player.playSound(player.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_FALL, 10, 1);
Message.sendSuccessMessage(player, "[管理AI]", "メニューを開きました");
m1sk9 marked this conversation as resolved.
Show resolved Hide resolved
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;
}

if (item == null) {
Message.sendErrorMessage(player, "[管理AI]", "不明なエラーが発生しました。運営に報告してください。通常通りのメニューは [/menu] で開けます。");
return false;
}

return true;
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -30,6 +30,19 @@ public void onInteract(PlayerInteractEvent event) {
break;
}

event.setCancelled(true);
}
case ANVIL -> {
if (!player.getWorld().getName().equals("lobby")) {
return;
}

if (LuckPermsWrapper.isUserInAdminOrDevGroup(player)) {
Message.sendSuccessMessage(player, "[管理AI]", "対象ブロック [金床] の利用制限をバイパスしました");
event.setCancelled(false);
break;
}

event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
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.*;
import space.yurisi.universecorev2.item.repair_cream.RepairCream;
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;
Expand Down Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};
}
}
14 changes: 12 additions & 2 deletions src/main/java/space/yurisi/universecorev2/menu/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();

Expand Down