Skip to content

Commit

Permalink
Merge pull request #161 from SpaceServerUniverse/dev/m1sk9-impove-mai…
Browse files Browse the repository at this point in the history
…n-menu

feat: メインメニュー関連の改善
  • Loading branch information
OneWalkDev authored Oct 18, 2024
2 parents b3ed3f9 + 70c1770 commit 07a2350
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 51 deletions.
66 changes: 53 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 @@ -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;
}
}
}
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 @@ -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;
}
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

0 comments on commit 07a2350

Please sign in to comment.