From 4aca0c5f432d1c0eb1201f0b149dffaa5168d87c Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Fri, 25 Oct 2024 15:36:09 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E3=83=81=E3=83=A3=E3=83=B3=E3=83=8D?= =?UTF-8?q?=E3=83=AB=E3=81=8C=E3=83=86=E3=82=AD=E3=82=B9=E3=83=88=E3=83=81?= =?UTF-8?q?=E3=83=A3=E3=83=B3=E3=83=8D=E3=83=AB=E3=81=A7=E3=81=AF=E3=81=AA?= =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=9F=E9=9A=9B=E3=81=AB=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=81=A7=E7=B5=82=E4=BA=86=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subplugins/universediscord/UniverseDiscord.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscord.java b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscord.java index 261bab07..39ee7ff8 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscord.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscord.java @@ -3,6 +3,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.requests.GatewayIntent; import org.bukkit.Bukkit; @@ -39,17 +40,21 @@ public void onEnable(UniverseCoreV2 core) { try { jda.awaitReady(); } catch (InterruptedException e) { - throw new DiscordJDANotReadyException("JDA is not ready!"); + throw new DiscordJDANotReadyException("JDA の初期化に失敗しました。詳しくは JDA のスタックトレースを確認してください"); } Guild guild = jda.getGuildById(config.getDiscordGuildId()); if (guild == null) { - throw new DiscordGuildNotFoundException("Guild not found with ID: " + config.getDiscordGuildId()); + throw new DiscordGuildNotFoundException("指定されたギルドIDは無効です: " + config.getDiscordGuildId()); } TextChannel channel = guild.getTextChannelById(config.getDiscordChannelId()); if (channel == null) { - throw new DiscordChannelNotFoundException("Channel not found with ID: " + config.getDiscordChannelId()); + throw new DiscordChannelNotFoundException("指定されたチャンネルIDは無効です: " + config.getDiscordChannelId()); + } + + if (channel.getType() != ChannelType.TEXT) { + throw new DiscordChannelNotFoundException("指定されたチャンネルIDはテキストチャンネルではありません: " + config.getDiscordChannelId()); } new EventManager(core, channel); From 360fe5878a327f3efd6dbda6b9b736ee57994339 Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Fri, 25 Oct 2024 15:37:17 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix!:=20=E3=83=81=E3=83=A3=E3=83=B3?= =?UTF-8?q?=E3=83=8D=E3=83=AB=E3=83=88=E3=83=94=E3=83=83=E3=82=AF=E3=82=92?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD=E3=81=AE?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../universediscord/UniverseDiscordChannel.java | 12 ------------ .../universediscord/event/PlayerEvent.java | 3 --- 2 files changed, 15 deletions(-) delete mode 100644 src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordChannel.java diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordChannel.java b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordChannel.java deleted file mode 100644 index efff74c5..00000000 --- a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordChannel.java +++ /dev/null @@ -1,12 +0,0 @@ -package space.yurisi.universecorev2.subplugins.universediscord; - -import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import org.bukkit.Bukkit; - -public class UniverseDiscordChannel { - - public static void updateDiscordChannelTopic(TextChannel channel, int playerCount) { - channel.getManager().setTopic(playerCount + "人が接続中").queue(); - } - -} diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/event/PlayerEvent.java b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/event/PlayerEvent.java index b8b98d48..c075334e 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/event/PlayerEvent.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/event/PlayerEvent.java @@ -13,7 +13,6 @@ import org.bukkit.event.player.PlayerAdvancementDoneEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import space.yurisi.universecorev2.subplugins.universediscord.UniverseDiscordChannel; import space.yurisi.universecorev2.subplugins.universediscord.UniverseDiscordMessage; import space.yurisi.universecorev2.utils.Message; @@ -28,13 +27,11 @@ public PlayerEvent(TextChannel discordChannel) { @EventHandler(priority = EventPriority.HIGHEST) public void onJoin(PlayerJoinEvent event) { UniverseDiscordMessage.sendJoinMessageToDiscord(event.getPlayer(), discordChannel); - UniverseDiscordChannel.updateDiscordChannelTopic(discordChannel, event.getPlayer().getServer().getOnlinePlayers().size()); } @EventHandler(priority = EventPriority.HIGHEST) public void onQuit(PlayerQuitEvent event) { UniverseDiscordMessage.sendQuitMessageToDiscord(event.getPlayer(), discordChannel); - UniverseDiscordChannel.updateDiscordChannelTopic(discordChannel, event.getPlayer().getServer().getOnlinePlayers().size()); } @EventHandler(priority = EventPriority.HIGHEST) From b6b05a1b9e1ec79dc5fd20f0275e1923e7715610 Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Fri, 25 Oct 2024 17:55:36 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20`!playerlist`=20=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniverseDiscordMessage.java | 19 +++++++++++++++++++ .../universediscord/event/DiscordEvent.java | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordMessage.java b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordMessage.java index f8950db8..c7ce35c1 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordMessage.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordMessage.java @@ -9,6 +9,8 @@ import org.bukkit.entity.Player; import space.yurisi.universecorev2.utils.Message; +import java.util.stream.Collectors; + public class UniverseDiscordMessage { /** Minecraft へのメッセージ */ @@ -67,4 +69,21 @@ public static void sendQuitMessageToDiscord(Player player, TextChannel discordCh discordChannel.sendMessageEmbeds(embed.build()).queue(); } + public static void sendStatusMessageToMinecraft(TextChannel discordChannel) { + String players = Bukkit.getOnlinePlayers().stream() + .map(Player::getName) + .collect(Collectors.joining(", ")); + int online_players = Bukkit.getOnlinePlayers().size(); + int max_players = Bukkit.getMaxPlayers(); + + EmbedBuilder embed = new EmbedBuilder(); + embed.setTitle("サーバー情報"); + embed.setDescription("```\n" + players + "\n```"); + embed.setFooter("現在のプレイヤー数: " + online_players + " / " + max_players); + embed.setColor(0xFFA74B); + + discordChannel.sendMessageEmbeds(embed.build()).queue(); + + } + } diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/event/DiscordEvent.java b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/event/DiscordEvent.java index a6305fed..7b4729c5 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/event/DiscordEvent.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/event/DiscordEvent.java @@ -32,6 +32,12 @@ public void onMessageReceived(MessageReceivedEvent event) { return; } + if (content.equals("!playerlist")) { + // すでに環境変数で指定されたチャンネルであることは確認済みなので, 暗黙的キャストでテキストチャンネル *として* 扱う + UniverseDiscordMessage.sendStatusMessageToMinecraft(event.getChannel().asTextChannel()); + return; + } + UniverseDiscordMessage.sendMessageToMinecraft(member, content); } From c84569bef36d094f287a39251e11533bb19efb1a Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Fri, 25 Oct 2024 19:50:43 +0900 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=E3=83=A1=E3=83=83=E3=82=BB?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=81=AE=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../universediscord/UniverseDiscordMessage.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordMessage.java b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordMessage.java index c7ce35c1..cb51485d 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordMessage.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/universediscord/UniverseDiscordMessage.java @@ -28,7 +28,7 @@ public static void sendMessageToMinecraft(Member discordMember, String discordMe name_format = discordMember.getUser().getName() + " (" + discordMember.getNickname() + ")"; } - Bukkit.broadcast(Component.text("§a[Discord#" + name_format + "] " + "§f" + discordMessage)); + Bukkit.broadcast(Component.text("§a[Discord] §r<" + name_format + "> " + discordMessage)); } @@ -38,7 +38,7 @@ public static void sendMessageToDiscord(Player player, TextChannel discordChanne Location location = player.getLocation(); String world_name = location.getWorld().getName(); - discordChannel.sendMessage("[" + player.getName() + " | " + world_name + "]" + " " + message).queue(); + discordChannel.sendMessage("[" + player.getName() + "@" + world_name + "]" + " " + message).queue(); } public static void sendEventMessageToDiscord(TextChannel discordChannel, String message, int color) { @@ -53,7 +53,7 @@ public static void sendJoinMessageToDiscord(Player player, TextChannel discordCh EmbedBuilder embed = new EmbedBuilder(); embed.setTitle("入室"); embed.setDescription(player.getName() + " がログインしました"); - embed.setThumbnail("https://mc-heads.net/avatar/" + player.getUniqueId() + "/100/nohelm.png"); + embed.setThumbnail("https://mc-heads.net/head/" + player.getUniqueId()); embed.setColor(0x2AFF5C); discordChannel.sendMessageEmbeds(embed.build()).queue(); @@ -63,7 +63,7 @@ public static void sendQuitMessageToDiscord(Player player, TextChannel discordCh EmbedBuilder embed = new EmbedBuilder(); embed.setTitle("退出"); embed.setDescription(player.getName() + " がログアウトしました"); - embed.setThumbnail("https://mc-heads.net/avatar/" + player.getUniqueId() + "/100/nohelm.png"); + embed.setThumbnail("https://mc-heads.net/head/" + player.getUniqueId()); embed.setColor(0x687EFF); discordChannel.sendMessageEmbeds(embed.build()).queue();