Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
/g で引数に大文字を指定できない問題を修正 (#891)
Browse files Browse the repository at this point in the history
* fix: Gamemode Lowercase

* refactor: Send Message

* fix: Typo Advanture -> Adventure
  • Loading branch information
yuuahp authored Jul 31, 2022
1 parent a82c12b commit fa8a7fd
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions src/main/java/com/jaoafa/mymaid4/command/Cmd_G.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ public MyMaidCommand.Cmd register(Command.Builder<CommandSender> builder) {
);
}

void sendChangeNotify(Player player, String before, String after) {
SendMessage(player, details(), Component.text().append(
Component.text("ゲームモードを切り替えました: ", NamedTextColor.GREEN),
Component.text(before, NamedTextColor.GREEN)
.hoverEvent(HoverEvent.showText(Component.text(MessageFormat.format("{0} にゲームモードを変更します", before))))
.clickEvent(ClickEvent.runCommand(String.format("/g %s", before))),
Component.text(" -> ", NamedTextColor.GREEN),
Component.text(after, NamedTextColor.GREEN, TextDecoration.BOLD)
).build());
}

void autoChangeGamemode(CommandContext<CommandSender> context) {
Player player = (Player) context.getSender();
GameMode beforeGamemode = player.getGameMode();
Expand All @@ -89,25 +100,11 @@ void autoChangeGamemode(CommandContext<CommandSender> context) {
}

player.setGameMode(GameMode.SPECTATOR);
SendMessage(player, details(), Component.text().append(
Component.text("ゲームモードを切り替えました: ", NamedTextColor.GREEN),
Component.text(beforeGamemode.name(), NamedTextColor.GREEN)
.hoverEvent(HoverEvent.showText(Component.text(MessageFormat.format("{0} にゲームモードを変更します", beforeGamemode.name()))))
.clickEvent(ClickEvent.runCommand(String.format("/g %s", beforeGamemode.name()))),
Component.text(" -> ", NamedTextColor.GREEN),
Component.text("SPECTATOR", NamedTextColor.GREEN, TextDecoration.BOLD)
).build());
} else {
player.setGameMode(GameMode.CREATIVE);
SendMessage(player, details(), Component.text().append(
Component.text("ゲームモードを切り替えました: ", NamedTextColor.GREEN),
Component.text(beforeGamemode.name(), NamedTextColor.GREEN)
.hoverEvent(HoverEvent.showText(Component.text(MessageFormat.format("{0} にゲームモードを変更します", beforeGamemode.name()))))
.clickEvent(ClickEvent.runCommand(String.format("/g %s", beforeGamemode.name()))),
Component.text(" -> ", NamedTextColor.GREEN),
Component.text(player.getGameMode().name(), NamedTextColor.GREEN, TextDecoration.BOLD)
).build());
}

sendChangeNotify(player, beforeGamemode.name(), player.getGameMode().name());
}

void changeGamemode(CommandContext<CommandSender> context) {
Expand All @@ -134,14 +131,8 @@ void changeGamemode(CommandContext<CommandSender> context) {
}

player.setGameMode(gamemode);
SendMessage(player, details(), Component.text().append(
Component.text("ゲームモードを切り替えました: ", NamedTextColor.GREEN),
Component.text(beforeGamemode.name(), NamedTextColor.GREEN)
.hoverEvent(HoverEvent.showText(Component.text(MessageFormat.format("{0} にゲームモードを変更します", beforeGamemode.name()))))
.clickEvent(ClickEvent.runCommand(String.format("/g %s", beforeGamemode.name()))),
Component.text(" -> ", NamedTextColor.GREEN),
Component.text(player.getGameMode().name(), NamedTextColor.GREEN, TextDecoration.BOLD)
).build());

sendChangeNotify(player, beforeGamemode.name(), player.getGameMode().name());
}

void changePlayerGamemode(CommandContext<CommandSender> context) {
Expand Down Expand Up @@ -207,7 +198,7 @@ void gamemodeNotFound(Player player) {
Component.text("Creative -> c / 1 / creative", NamedTextColor.WHITE)
.clickEvent(ClickEvent.runCommand("/g c")),
Component.newline(),
Component.text("Advanture -> a / 2 / advanture", NamedTextColor.RED)
Component.text("Adventure -> a / 2 / adventure", NamedTextColor.RED)
.clickEvent(ClickEvent.runCommand("/g a")),
Component.newline(),
Component.text("Spectator -> sp / 3 / spectator", NamedTextColor.YELLOW)
Expand All @@ -231,7 +222,7 @@ GameMode getGameModeStartWith(String str) {
return GameMode.SPECTATOR;
}
for (GameMode mode : GameMode.values()) {
if (mode.name().toLowerCase().startsWith(str)) {
if (mode.name().toLowerCase().startsWith(str.toLowerCase())) {
return mode;
}
}
Expand Down

0 comments on commit fa8a7fd

Please sign in to comment.