Skip to content

Commit

Permalink
Merge pull request #151 from SpaceServerUniverse/dev/in-ammo-menu
Browse files Browse the repository at this point in the history
feat: 弾薬メニューをメニューから開けるように
  • Loading branch information
OneWalkDev authored Oct 12, 2024
2 parents ee8313d + d66ea88 commit 66bd458
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 29 deletions.
39 changes: 17 additions & 22 deletions src/main/java/space/yurisi/universecorev2/menu/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import space.yurisi.universecorev2.exception.CustomNameNotFoundException;
import space.yurisi.universecorev2.exception.MoneyNotFoundException;
import space.yurisi.universecorev2.exception.UserNotFoundException;
import space.yurisi.universecorev2.menu.menu_item.main_menu.LaunchNavigationItem;
import space.yurisi.universecorev2.subplugins.universeeconomy.UniverseEconomyAPI;
import space.yurisi.universecorev2.utils.Message;
import space.yurisi.universecorev2.utils.TimeHelper;
Expand Down Expand Up @@ -50,18 +51,6 @@ public void sendMenu(Player player) {
.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.LAVA_BUCKET)
.setDisplayName("ゴミ箱")
.setLegacyLore(List.of("§6ゴミ箱を開きます。取り扱い注意!")),
Expand All @@ -74,13 +63,17 @@ public void sendMenu(Player player) {
.setDisplayName("プレイヤーヘッド")
.setLegacyLore(List.of("§6他のプレイヤーのヘッドを購入します")),
"/head");
Item executeAmmo = new CommandItem(new ItemBuilder(Material.IRON_NUGGET)
.setDisplayName("弾薬")
.setLegacyLore(List.of("§6弾薬を購入・クラフトします")),
"/ammo");

Gui gui = Gui.normal()
.setStructure(
"= # # # i # # # #",
"# + a m t g y + #",
"# + w u n s h + #",
"# # # # # # # # #"
"# # # i # = # # #",
"# + a m t o y + #",
"# + + n s h + + #",
"# # # # l # # # #"
)
.addIngredient('#', border)
.addIngredient('+', inMenuBorder)
Expand All @@ -89,16 +82,15 @@ public void sendMenu(Player 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)
.addIngredient('o', executeAmmo)
.addIngredient('l', new LaunchNavigationItem())
.build();

xyz.xenondevs.invui.window.Window window = Window.single()
Window window = Window.single()
.setViewer(player)
.setGui(gui)
.setTitle("メインメニュー")
Expand Down Expand Up @@ -141,9 +133,12 @@ private Item createPlayerInfoHead(Player player) {
}

String greetingWithName = switch (TimeHelper.checkTime()) {
case LATE_NIGHT -> "§e遅くまでお疲れ様です、 §r" + player.getName();
case EARLY_MORNING -> "§f朝早くからお疲れ様です、 §r" + player.getName();
case MORNING -> "§bおはようございます、 §r" + player.getName();
case AFTERNOON -> "§6こんにちは、 §r" + player.getName();
case EVENING -> "§9こんばんは、 §r" + player.getName();
case AFTERNOON -> "§aこんにちは、 §r" + player.getName();
case EVENING -> "§6夜ご飯は何を食べるんですか? §r" + player.getName();
case NIGHT -> "§9こんばんは、 §r" + player.getName();
};

List<String> playerinfo = List.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package space.yurisi.universecorev2.menu.menu_item.main_menu;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import space.yurisi.universecorev2.menu.MainMenu;
import xyz.xenondevs.invui.item.ItemProvider;
import xyz.xenondevs.invui.item.builder.ItemBuilder;
import xyz.xenondevs.invui.item.impl.AbstractItem;

import java.util.List;

public class LaunchNavigationItem extends AbstractItem {

@Override
public ItemProvider getItemProvider() {
return new ItemBuilder(Material.MAP)
.setDisplayName("関連リンク")
.setLegacyLore(List.of("§6関連リンクを表示します"));
}

@Override
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent inventoryClickEvent) {
Bukkit.getServer().dispatchCommand(player, "web");
Bukkit.getServer().dispatchCommand(player, "wiki");
Bukkit.getServer().dispatchCommand(player, "discord");
// メニューを閉じる
player.closeInventory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import space.yurisi.universecorev2.UniverseCoreV2API;
import space.yurisi.universecorev2.database.DatabaseManager;
import space.yurisi.universecorev2.subplugins.SubPlugin;
import space.yurisi.universecorev2.subplugins.universeguns.core.GunCommand;
import space.yurisi.universecorev2.subplugins.universeguns.event.GunEvent;
import space.yurisi.universecorev2.subplugins.universeguns.connector.UniverseCoreAPIConnector;

Expand All @@ -16,6 +17,7 @@ public void onEnable(UniverseCoreV2 core) {
DatabaseManager manager = UniverseCoreV2API.getInstance().getDatabaseManager();
this.connector = new UniverseCoreAPIConnector(manager);
core.getServer().getPluginManager().registerEvents(new GunEvent(core, connector), core);
core.getCommand("ammo").setExecutor(new GunCommand(connector));
}

public void onDisable() {
Expand All @@ -31,4 +33,4 @@ public String getName() {
public String getVersion() {
return "1.0.1";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package space.yurisi.universecorev2.subplugins.universeguns.core;

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.universeguns.connector.UniverseCoreAPIConnector;
import space.yurisi.universecorev2.subplugins.universeguns.menu.AmmoManagerInventoryMenu;
import space.yurisi.universecorev2.utils.Message;

public class GunCommand implements CommandExecutor {

private final UniverseCoreAPIConnector connector;

public GunCommand(UniverseCoreAPIConnector connector) {
this.connector = connector;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (!(sender instanceof Player player)) {
return false;
}

AmmoManagerInventoryMenu ammoManagerInventoryMenu = new AmmoManagerInventoryMenu(connector);
ammoManagerInventoryMenu.sendMenu(player);

Message.sendSuccessMessage(player, "[武器AI]", "弾薬管理メニューを開きました");
return true;
}
}
16 changes: 11 additions & 5 deletions src/main/java/space/yurisi/universecorev2/utils/TimeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@
public class TimeHelper {

/**
* 現在時刻をチェックし、その時間帯を返します
* 現在時間をチェックし、その時間帯を表すTimeType列挙型を返します
*
* @return TimeType 時間帯 -- MORNING: 朝, AFTERNOON: 昼, EVENING: 夜
* @return TimeType 時間帯
*/
public static TimeType checkTime() {
LocalTime now = LocalTime.now();

if (now.isBefore(LocalTime.NOON)) {
if (now.isBefore(LocalTime.of(5, 0))) {
return TimeType.LATE_NIGHT;
} else if (now.isBefore(LocalTime.of(8, 0))) {
return TimeType.EARLY_MORNING;
} else if (now.isBefore(LocalTime.of(10, 0))) {
return TimeType.MORNING;
} else if (now.isBefore(LocalTime.of(18, 0))) {
} else if (now.isBefore(LocalTime.of(16, 0))) {
return TimeType.AFTERNOON;
} else {
} else if (now.isBefore(LocalTime.of(20, 0))) {
return TimeType.EVENING;
} else {
return TimeType.NIGHT;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package space.yurisi.universecorev2.utils.time_type;

public enum TimeType {
LATE_NIGHT,
EARLY_MORNING,
MORNING,
AFTERNOON,
EVENING
EVENING,
NIGHT
}
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ commands:
unlock:
description: コンテナ等の保護を解除します

## UniverseGuns
ammo:
description: 弾薬管理メニューを開く

## PlayerHead
head:
description: プレイヤーヘッドを購入します(WIP)
Expand Down

0 comments on commit 66bd458

Please sign in to comment.