From 6efc2f1fb1d05c051d260524c7a533a39ae5ab23 Mon Sep 17 00:00:00 2001 From: ErdbeerbaerLP Date: Thu, 12 Oct 2023 21:14:18 +0200 Subject: [PATCH] Backport 3.0.3 to 1.16.5 Signed-off-by: ErdbeerbaerLP --- build.gradle | 7 +- gradle.properties | 2 +- .../forge/DiscordIntegrationMod.java | 126 +++++++++--------- .../forge/command/DCCommandSender.java | 12 +- .../forge/command/McCommandDiscord.java | 18 ++- .../mixin/MixinNetHandlerPlayServer.java | 16 +-- .../forge/mixin/MixinPlayerLogin.java | 16 +-- .../forge/util/ForgeMessageUtils.java | 74 +++++----- .../forge/util/ForgeServerInterface.java | 44 +++--- src/main/resources/META-INF/mods.toml | 6 +- src/main/resources/mixins.dcintegration.json | 2 +- 11 files changed, 167 insertions(+), 156 deletions(-) diff --git a/build.gradle b/build.gradle index 5d05230d..aedd998a 100644 --- a/build.gradle +++ b/build.gradle @@ -34,7 +34,7 @@ version = "3.0.3" group = "de.erdbeerbaerlp.dcintegration" archivesBaseName = "dcintegration-forge" -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(8) //Gradle Repositories repositories { @@ -86,6 +86,7 @@ reobf { artifacts { archives tasks.shadowJar } + configurations.all { resolutionStrategy { cacheChangingModulesFor 1, 'minutes' @@ -94,12 +95,12 @@ configurations.all { //Dependencies dependencies { // ========= Common ===================== - embed('de.erdbeerbaerlp:dcintegration.common:3.0.3') { + embed('de.erdbeerbaerlp:dcintegration.common:3.0.3-j8') { changing = true } // ========= Minecraft Forge ============= - minecraft "net.minecraftforge:forge:${project.mcVersion}-40.2.10" + minecraft 'net.minecraftforge:forge:1.16.5-36.2.34' //Mixin annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' diff --git a/gradle.properties b/gradle.properties index 98c283cf..07d36591 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,4 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false changelog=Large discord integration rewrite adding new features and fixing long existing bugs\nOld configuration can be used as-is\n\nAdded custom status\nAdded tellraw\nAdded option to disable chat message editing for compatibility reasons\nFixed lots of bugs releaseType = BETA -mcVersion = 1.18.2 \ No newline at end of file +mcVersion = 1.16.5 \ No newline at end of file diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java index c7c7c40f..f85aeb8b 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/DiscordIntegrationMod.java @@ -27,12 +27,13 @@ import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.utils.messages.MessageCreateData; -import net.minecraft.ChatFormatting; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; +import net.minecraft.command.CommandSource; +import net.minecraft.command.arguments.ComponentArgument; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.CommandEvent; @@ -41,18 +42,19 @@ import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.player.AdvancementEvent; import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.event.server.ServerStartedEvent; -import net.minecraftforge.event.server.ServerStoppedEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.IExtensionPoint; +import net.minecraftforge.fml.ExtensionPoint; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent; +import net.minecraftforge.fml.event.server.FMLServerStartedEvent; +import net.minecraftforge.fml.event.server.FMLServerStoppedEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLEnvironment; -import net.minecraftforge.network.NetworkConstants; +import net.minecraftforge.fml.network.FMLNetworkConstants; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.tuple.Pair; import java.io.File; import java.io.IOException; @@ -77,7 +79,8 @@ public class DiscordIntegrationMod { private boolean stopped = false; public DiscordIntegrationMod() { - ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); + ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, + () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); try { //Create data directory if missing if (!discordDataDir.exists()) discordDataDir.mkdir(); @@ -118,7 +121,7 @@ public void serverSetup(FMLDedicatedServerSetupEvent ev) { if (DiscordIntegration.INSTANCE.getJDA() != null) { Thread.sleep(2000); //Wait for it to cache the channels CommandRegistry.registerDefaultCommands(); - if (!Localization.instance().serverStarting.isBlank()) + if (!Localization.instance().serverStarting.isEmpty()) if (DiscordIntegration.INSTANCE.getChannel() != null) { final MessageCreateData m; if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.startMessages.asEmbed) @@ -138,11 +141,11 @@ public void playerJoin(final PlayerEvent.PlayerLoggedInEvent ev) { if (LinkManager.isPlayerLinked(ev.getEntity().getUUID()) && LinkManager.getLink(null, ev.getEntity().getUUID()).settings.hideFromDiscord) return; LinkManager.checkGlobalAPI(ev.getEntity().getUUID()); - if (!Localization.instance().playerJoin.isBlank()) { - final Player p = ev.getPlayer(); + if (!Localization.instance().playerJoin.isEmpty()) { + final PlayerEntity p = ev.getPlayer(); if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.playerJoinMessage.asEmbed) { final String avatarURL = Configuration.instance().webhook.playerAvatarURL.replace("%uuid%", p.getUUID().toString()).replace("%uuid_dashless%", p.getUUID().toString().replace("-", "")).replace("%name%", p.getName().getString()).replace("%randomUUID%", UUID.randomUUID().toString()); - if (!Configuration.instance().embedMode.playerJoinMessage.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.playerJoinMessage.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.playerJoinMessage.toEmbedJson(Configuration.instance().embedMode.playerJoinMessage.customJSON .replace("%uuid%", p.getUUID().toString()) .replace("%uuid_dashless%", p.getUUID().toString().replace("-", "")) @@ -179,23 +182,23 @@ public void playerJoin(final PlayerEvent.PlayerLoggedInEvent ev) { @SubscribeEvent public void advancement(AdvancementEvent ev) { - if (Localization.instance().advancementMessage.isBlank()) return; + if (Localization.instance().advancementMessage.isEmpty()) return; if (LinkManager.isPlayerLinked(ev.getEntity().getUUID()) && LinkManager.getLink(null, ev.getEntity().getUUID()).settings.hideFromDiscord) return; - if (ev.getEntity().getServer().getPlayerList().getPlayerAdvancements((ServerPlayer) ev.getEntity()).getOrStartProgress(ev.getAdvancement()).isDone()) + if (ev.getEntity().getServer().getPlayerList().getPlayerAdvancements((ServerPlayerEntity) ev.getEntity()).getOrStartProgress(ev.getAdvancement()).isDone()) if (INSTANCE != null && ev.getAdvancement() != null && ev.getAdvancement().getDisplay() != null && ev.getAdvancement().getDisplay().shouldAnnounceChat()) - if (!Localization.instance().advancementMessage.isBlank()) { + if (!Localization.instance().advancementMessage.isEmpty()) { if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.advancementMessage.asEmbed) { final String avatarURL = Configuration.instance().webhook.playerAvatarURL.replace("%uuid%", ev.getEntity().getUUID().toString()).replace("%uuid_dashless%", ev.getEntity().getUUID().toString().replace("-", "")).replace("%name%", ev.getEntity().getName().getString()).replace("%randomUUID%", UUID.randomUUID().toString()); - if (!Configuration.instance().embedMode.advancementMessage.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.advancementMessage.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.advancementMessage.toEmbedJson(Configuration.instance().embedMode.advancementMessage.customJSON .replace("%uuid%", ev.getEntity().getUUID().toString()) .replace("%uuid_dashless%", ev.getEntity().getUUID().toString().replace("-", "")) .replace("%name%", ForgeMessageUtils.formatPlayerName(ev.getEntity())) .replace("%randomUUID%", UUID.randomUUID().toString()) .replace("%avatarURL%", avatarURL) - .replace("%advName%", ChatFormatting.stripFormatting(ev.getAdvancement().getDisplay().getTitle().getString())) - .replace("%advDesc%", ChatFormatting.stripFormatting(ev.getAdvancement().getDisplay().getDescription().getString())) + .replace("%advName%", TextFormatting.stripFormatting(ev.getAdvancement().getDisplay().getTitle().getString())) + .replace("%advDesc%", TextFormatting.stripFormatting(ev.getAdvancement().getDisplay().getDescription().getString())) .replace("%avatarURL%", avatarURL) .replace("%playerColor%", "" + TextColors.generateFromUUID(ev.getEntity().getUUID()).getRGB()) ); @@ -204,12 +207,12 @@ public void advancement(AdvancementEvent ev) { EmbedBuilder b = Configuration.instance().embedMode.advancementMessage.toEmbed(); b = b.setAuthor(ForgeMessageUtils.formatPlayerName(ev.getEntity()), null, avatarURL) .setDescription(Localization.instance().advancementMessage.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())).replace("%advName%", - ChatFormatting.stripFormatting(ev.getAdvancement() + TextFormatting.stripFormatting(ev.getAdvancement() .getDisplay() .getTitle() .getString())) .replace("%advDesc%", - ChatFormatting.stripFormatting(ev.getAdvancement() + TextFormatting.stripFormatting(ev.getAdvancement() .getDisplay() .getDescription() .getString())) @@ -217,14 +220,14 @@ public void advancement(AdvancementEvent ev) { INSTANCE.sendMessage(new DiscordMessage(b.build())); } } else INSTANCE.sendMessage(Localization.instance().advancementMessage.replace("%player%", - ChatFormatting.stripFormatting(ForgeMessageUtils.formatPlayerName(ev.getEntity()))) + TextFormatting.stripFormatting(ForgeMessageUtils.formatPlayerName(ev.getEntity()))) .replace("%advName%", - ChatFormatting.stripFormatting(ev.getAdvancement() + TextFormatting.stripFormatting(ev.getAdvancement() .getDisplay() .getTitle() .getString())) .replace("%advDesc%", - ChatFormatting.stripFormatting(ev.getAdvancement() + TextFormatting.stripFormatting(ev.getAdvancement() .getDisplay() .getDescription() .getString())) @@ -238,13 +241,13 @@ public void registerCommands(final RegisterCommandsEvent ev) { } @SubscribeEvent - public void serverStarted(final ServerStartedEvent ev) { + public void serverStarted(final FMLServerStartedEvent ev) { LOGGER.info("Started"); started = new Date().getTime(); if (INSTANCE != null) { if (DiscordIntegration.startingMsg != null) { if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.startMessages.asEmbed) { - if (!Configuration.instance().embedMode.startMessages.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.startMessages.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.startMessages.toEmbedJson(Configuration.instance().embedMode.startMessages.customJSON); DiscordIntegration.startingMsg.thenAccept((a) -> a.editMessageEmbeds(b.build()).queue()); } else @@ -253,7 +256,7 @@ public void serverStarted(final ServerStartedEvent ev) { DiscordIntegration.startingMsg.thenAccept((a) -> a.editMessage(Localization.instance().serverStarted).queue()); } else { if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.startMessages.asEmbed) { - if (!Configuration.instance().embedMode.startMessages.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.startMessages.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.startMessages.toEmbedJson(Configuration.instance().embedMode.startMessages.customJSON); DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build())); } else @@ -263,12 +266,11 @@ public void serverStarted(final ServerStartedEvent ev) { } INSTANCE.startThreads(); } - UpdateChecker.runUpdateCheck("https://raw.githubusercontent.com/ErdbeerbaerLP/Discord-Chat-Integration/1.18.2/update_checker.json"); + UpdateChecker.runUpdateCheck("https://raw.githubusercontent.com/ErdbeerbaerLP/Discord-Chat-Integration/1.16.5/update_checker.json"); if (ModList.get().getModContainerById("dynmap").isPresent()) { new DynmapListener().register(); } - if (!DownloadSourceChecker.checkDownloadSource(new File(DiscordIntegrationMod.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("%")[0]))) { LOGGER.warn("You likely got this mod from a third party website."); LOGGER.warn("Some of such websites are distributing malware or old versions."); @@ -288,7 +290,7 @@ public void command(CommandEvent ev) { .replace("%cmd-no-args%", command.split(" ")[0]), INSTANCE.getChannel(Configuration.instance().commandLog.channelID)); } if (INSTANCE != null) { - final CommandSourceStack source = ev.getParseResults().getContext().getSource(); + final CommandSource source = ev.getParseResults().getContext().getSource(); final Entity sourceEntity = source.getEntity(); boolean raw = false; @@ -303,7 +305,7 @@ public void command(CommandEvent ev) { INSTANCE.sendMessage(source.getTextName(), sourceEntity != null ? sourceEntity.getUUID().toString() : "0000000", new DiscordMessage(null, msg, !raw), INSTANCE.getChannel(Configuration.instance().advanced.chatOutputChannelID)); } - if(command.startsWith("tellraw ") && !Configuration.instance().messages.tellrawSelector.isBlank()){ + if(command.startsWith("tellraw ") && !Configuration.instance().messages.tellrawSelector.isEmpty()){ final String[] args = command.replace("tellraw ", "").replace("dc ", "").split(" "); if(args[0].equals(Configuration.instance().messages.tellrawSelector)){ INSTANCE.sendMessage(DiscordSerializer.INSTANCE.serialize(GsonComponentSerializer.gson().deserialize(command.replace("tellraw " + args[0], "")))); @@ -318,7 +320,7 @@ public void command(CommandEvent ev) { case CONSOLE_ONLY: try { source.getPlayerOrException(); - source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.consoleOnly)); + source.sendFailure(ITextComponent.nullToEmpty(Localization.instance().commands.consoleOnly)); } catch (CommandSyntaxException e) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, null)); try { @@ -329,7 +331,7 @@ public void command(CommandEvent ev) { break; case PLAYER_ONLY: try { - final ServerPlayer player = source.getPlayerOrException(); + final ServerPlayerEntity player = source.getPlayerOrException(); if (!mcSubCommand.needsOP()) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID())); @@ -345,17 +347,17 @@ public void command(CommandEvent ev) { } catch (CommandSyntaxException ignored) { } } else { - source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.noPermission)); + source.sendFailure(ITextComponent.nullToEmpty(Localization.instance().commands.noPermission)); } } catch (CommandSyntaxException e) { - source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.ingameOnly)); + source.sendFailure(ITextComponent.nullToEmpty(Localization.instance().commands.ingameOnly)); } break; case BOTH: try { - final ServerPlayer player = source.getPlayerOrException(); + final ServerPlayerEntity player = source.getPlayerOrException(); if (!mcSubCommand.needsOP()) { final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID())); @@ -372,7 +374,7 @@ public void command(CommandEvent ev) { } catch (CommandSyntaxException ignored) { } } else { - source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.noPermission)); + source.sendFailure(ITextComponent.nullToEmpty(Localization.instance().commands.noPermission)); } } catch (CommandSyntaxException e) { @@ -393,22 +395,22 @@ public void command(CommandEvent ev) { } @SubscribeEvent - public void serverStopping(ServerStoppedEvent ev) { + public void serverStopping(FMLServerStoppedEvent ev) { if (INSTANCE != null) { ev.getServer().executeBlocking(() -> { INSTANCE.stopThreads(); - if (!ev.getServer().isRunning() && !Localization.instance().serverStopped.isBlank()) + if (!ev.getServer().isRunning() && !Localization.instance().serverStopped.isEmpty()) if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.stopMessages.asEmbed) { - if (!Configuration.instance().embedMode.stopMessages.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.stopMessages.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.stopMessages.toEmbedJson(Configuration.instance().embedMode.stopMessages.customJSON); DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build())); } else DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(Configuration.instance().embedMode.stopMessages.toEmbed().setDescription(Localization.instance().serverStopped).build())); } else DiscordIntegration.INSTANCE.sendMessage(Localization.instance().serverStopped); - else if (ev.getServer().isRunning() && !Localization.instance().serverCrash.isBlank()) { + else if (ev.getServer().isRunning() && !Localization.instance().serverCrash.isEmpty()) { if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.stopMessages.asEmbed) { - if (!Configuration.instance().embedMode.stopMessages.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.stopMessages.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.stopMessages.toEmbedJson(Configuration.instance().embedMode.stopMessages.customJSON); DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build())); } else @@ -426,10 +428,10 @@ else if (ev.getServer().isRunning() && !Localization.instance().serverCrash.isBl @SubscribeEvent public void chat(ServerChatEvent ev) { - if (Localization.instance().discordChatMessage.isBlank()) return; + if (Localization.instance().discordChatMessage.isEmpty()) return; if (LinkManager.isPlayerLinked(ev.getPlayer().getUUID()) && LinkManager.getLink(null, ev.getPlayer().getUUID()).settings.hideFromDiscord) return; - final net.minecraft.network.chat.Component msg = ev.getComponent(); + final ITextComponent msg = ev.getComponent(); if (INSTANCE.callEvent((e) -> { if (e instanceof ForgeDiscordEventHandler) { return ((ForgeDiscordEventHandler) e).onMcChatMessage(ev); @@ -442,10 +444,10 @@ public void chat(ServerChatEvent ev) { if (INSTANCE != null) { GuildMessageChannel channel = INSTANCE.getChannel(Configuration.instance().advanced.chatOutputChannelID); if (channel == null) return; - if (!Localization.instance().discordChatMessage.isBlank()) + if (!Localization.instance().discordChatMessage.isEmpty()) if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.chatMessages.asEmbed) { final String avatarURL = Configuration.instance().webhook.playerAvatarURL.replace("%uuid%", ev.getPlayer().getUUID().toString()).replace("%uuid_dashless%", ev.getPlayer().getUUID().toString().replace("-", "")).replace("%name%", ev.getPlayer().getName().getString()).replace("%randomUUID%", UUID.randomUUID().toString()); - if (!Configuration.instance().embedMode.chatMessages.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.chatMessages.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.chatMessages.toEmbedJson(Configuration.instance().embedMode.chatMessages.customJSON .replace("%uuid%", ev.getPlayer().getUUID().toString()) .replace("%uuid_dashless%", ev.getPlayer().getUUID().toString().replace("-", "")) @@ -467,10 +469,10 @@ public void chat(ServerChatEvent ev) { } else INSTANCE.sendMessage(ForgeMessageUtils.formatPlayerName(ev.getPlayer()), ev.getPlayer().getUUID().toString(), new DiscordMessage(embed, text, true), channel); if(!Configuration.instance().compatibility.disableParsingMentionsIngame) { - final String json = net.minecraft.network.chat.Component.Serializer.toJson(msg); + final String json = ITextComponent.Serializer.toJson(msg); Component comp = GsonComponentSerializer.gson().deserialize(json); final String editedJson = GsonComponentSerializer.gson().serialize(MessageUtils.mentionsToNames(comp, channel.getGuild())); - ev.setComponent(net.minecraft.network.chat.Component.Serializer.fromJson(editedJson)); + ev.setComponent(ITextComponent.Serializer.fromJson(editedJson)); } } @@ -478,23 +480,23 @@ public void chat(ServerChatEvent ev) { @SubscribeEvent public void death(LivingDeathEvent ev) { - if (Localization.instance().playerDeath.isBlank()) return; - if (ev.getEntity() instanceof Player) { + if (Localization.instance().playerDeath.isEmpty()) return; + if (ev.getEntity() instanceof PlayerEntity) { if (LinkManager.isPlayerLinked(ev.getEntity().getUUID()) && LinkManager.getLink(null, ev.getEntity().getUUID()).settings.hideFromDiscord) return; if (INSTANCE != null) { - final net.minecraft.network.chat.Component deathMessage = ev.getSource().getLocalizedDeathMessage(ev.getEntityLiving()); + final ITextComponent deathMessage = ev.getSource().getLocalizedDeathMessage(ev.getEntityLiving()); final MessageEmbed embed = ForgeMessageUtils.genItemStackEmbedIfAvailable(deathMessage); if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.deathMessage.asEmbed) { final String avatarURL = Configuration.instance().webhook.playerAvatarURL.replace("%uuid%", ev.getEntity().getUUID().toString()).replace("%uuid_dashless%", ev.getEntity().getUUID().toString().replace("-", "")).replace("%name%", ev.getEntity().getName().getString()).replace("%randomUUID%", UUID.randomUUID().toString()); - if (!Configuration.instance().embedMode.playerJoinMessage.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.playerJoinMessage.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.playerJoinMessage.toEmbedJson(Configuration.instance().embedMode.playerJoinMessage.customJSON .replace("%uuid%", ev.getEntity().getUUID().toString()) .replace("%uuid_dashless%", ev.getEntity().getUUID().toString().replace("-", "")) .replace("%name%", ForgeMessageUtils.formatPlayerName(ev.getEntity())) .replace("%randomUUID%", UUID.randomUUID().toString()) .replace("%avatarURL%", avatarURL) - .replace("%deathMessage%", ChatFormatting.stripFormatting(deathMessage.getString()).replace(ForgeMessageUtils.formatPlayerName(ev.getEntity()) + " ", "")) + .replace("%deathMessage%", TextFormatting.stripFormatting(deathMessage.getString()).replace(ForgeMessageUtils.formatPlayerName(ev.getEntity()) + " ", "")) .replace("%playerColor%", "" + TextColors.generateFromUUID(ev.getEntity().getUUID()).getRGB()) ); if (embed != null) { @@ -504,7 +506,7 @@ public void death(LivingDeathEvent ev) { INSTANCE.sendMessage(new DiscordMessage(b.build())); } else { final EmbedBuilder b = Configuration.instance().embedMode.deathMessage.toEmbed(); - b.setDescription(":skull: " + Localization.instance().playerDeath.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())).replace("%msg%", ChatFormatting.stripFormatting(deathMessage.getString()).replace(ForgeMessageUtils.formatPlayerName(ev.getEntity()) + " ", ""))); + b.setDescription(":skull: " + Localization.instance().playerDeath.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())).replace("%msg%", TextFormatting.stripFormatting(deathMessage.getString()).replace(ForgeMessageUtils.formatPlayerName(ev.getEntity()) + " ", ""))); if (embed != null) { b.addBlankField(false); b.addField(embed.getTitle() + " *(" + embed.getFooter().getText() + ")*", embed.getDescription(), false); @@ -512,7 +514,7 @@ public void death(LivingDeathEvent ev) { INSTANCE.sendMessage(new DiscordMessage(b.build()), INSTANCE.getChannel(Configuration.instance().advanced.deathsChannelID)); } } else - INSTANCE.sendMessage(new DiscordMessage(embed, Localization.instance().playerDeath.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())).replace("%msg%", ChatFormatting.stripFormatting(deathMessage.getString()).replace(ForgeMessageUtils.formatPlayerName(ev.getEntity()) + " ", ""))), INSTANCE.getChannel(Configuration.instance().advanced.deathsChannelID)); + INSTANCE.sendMessage(new DiscordMessage(embed, Localization.instance().playerDeath.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())).replace("%msg%", TextFormatting.stripFormatting(deathMessage.getString()).replace(ForgeMessageUtils.formatPlayerName(ev.getEntity()) + " ", ""))), INSTANCE.getChannel(Configuration.instance().advanced.deathsChannelID)); } } } @@ -520,13 +522,13 @@ public void death(LivingDeathEvent ev) { @SubscribeEvent public void playerLeave(PlayerEvent.PlayerLoggedOutEvent ev) { if (stopped) return; //Try to fix player leave messages after stop! - if (Localization.instance().playerLeave.isBlank()) return; - final Player player = ev.getPlayer(); + if (Localization.instance().playerLeave.isEmpty()) return; + final PlayerEntity player = ev.getPlayer(); final String avatarURL = Configuration.instance().webhook.playerAvatarURL.replace("%uuid%", player.getUUID().toString()).replace("%uuid_dashless%", player.getUUID().toString().replace("-", "")).replace("%name%", player.getName().getString()).replace("%randomUUID%", UUID.randomUUID().toString()); if (DiscordIntegration.INSTANCE != null && !DiscordIntegrationMod.timeouts.contains(player.getUUID())) { - if (!Localization.instance().playerLeave.isBlank()) { + if (!Localization.instance().playerLeave.isEmpty()) { if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.playerLeaveMessages.asEmbed) { - if (!Configuration.instance().embedMode.playerLeaveMessages.customJSON.isBlank()) { + if (!Configuration.instance().embedMode.playerLeaveMessages.customJSON.isEmpty()) { final EmbedBuilder b = Configuration.instance().embedMode.playerLeaveMessages.toEmbedJson(Configuration.instance().embedMode.playerLeaveMessages.customJSON .replace("%uuid%", player.getUUID().toString()) .replace("%uuid_dashless%", player.getUUID().toString().replace("-", "")) @@ -546,7 +548,7 @@ public void playerLeave(PlayerEvent.PlayerLoggedOutEvent ev) { DiscordIntegration.INSTANCE.sendMessage(Localization.instance().playerLeave.replace("%player%", ForgeMessageUtils.formatPlayerName(player))); } } else if (DiscordIntegration.INSTANCE != null && DiscordIntegrationMod.timeouts.contains(player.getUUID())) { - if (!Localization.instance().playerTimeout.isBlank()) { + if (!Localization.instance().playerTimeout.isEmpty()) { if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.playerLeaveMessages.asEmbed) { EmbedBuilder b = Configuration.instance().embedMode.playerLeaveMessages.toEmbed(); b = b.setAuthor(ForgeMessageUtils.formatPlayerName(player), null, avatarURL) diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/DCCommandSender.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/DCCommandSender.java index 835336dc..981131fe 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/DCCommandSender.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/DCCommandSender.java @@ -6,11 +6,9 @@ import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.InteractionHook; -import net.minecraft.network.chat.ChatType; -import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.game.ServerboundChatPacket; +import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.minecraftforge.fml.server.ServerLifecycleHooks; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -29,13 +27,13 @@ public DCCommandSender(CompletableFuture cmdMsg, User user) { } - private static String textComponentToDiscordMessage(Component component) { + private static String textComponentToDiscordMessage(ITextComponent component) { if (component == null) return ""; return MessageUtils.convertMCToMarkdown(component.getString()); } @Override - public void sendMessage(Component p_215097_, UUID uuid) { + public void sendMessage(ITextComponent p_215097_, UUID uuid) { message.append(textComponentToDiscordMessage(p_215097_)).append("\n"); if (cmdMessage == null) cmdMsg.thenAccept((msg) -> { @@ -48,7 +46,7 @@ public void sendMessage(Component p_215097_, UUID uuid) { } @Override - public void displayClientMessage(Component chatComponent, boolean actionBar) { + public void displayClientMessage(ITextComponent chatComponent, boolean actionBar) { message.append(textComponentToDiscordMessage(chatComponent)).append("\n"); if (cmdMessage == null) cmdMsg.thenAccept((msg) -> { diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/McCommandDiscord.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/McCommandDiscord.java index 38723787..392f487a 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/McCommandDiscord.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/command/McCommandDiscord.java @@ -5,17 +5,21 @@ import de.erdbeerbaerlp.dcintegration.common.minecraftCommands.MCSubCommand; import de.erdbeerbaerlp.dcintegration.common.minecraftCommands.McCommandRegistry; import de.erdbeerbaerlp.dcintegration.common.storage.Configuration; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; -import net.minecraft.network.chat.*; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextComponentUtils; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.util.text.event.HoverEvent; public class McCommandDiscord { - public McCommandDiscord(CommandDispatcher dispatcher) { - final LiteralArgumentBuilder l = Commands.literal("discord"); + public McCommandDiscord(CommandDispatcher dispatcher) { + final LiteralArgumentBuilder l = Commands.literal("discord"); if (Configuration.instance().ingameCommand.enabled) l.executes((ctx) -> { - ctx.getSource().sendSuccess(ComponentUtils.mergeStyles(new TextComponent(Configuration.instance().ingameCommand.message), - Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent(Configuration.instance().ingameCommand.hoverMessage))) + ctx.getSource().sendSuccess(TextComponentUtils.mergeStyles(new StringTextComponent(Configuration.instance().ingameCommand.message), + Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent(Configuration.instance().ingameCommand.hoverMessage))) .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Configuration.instance().ingameCommand.inviteURL))), false); return 0; }); diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/mixin/MixinNetHandlerPlayServer.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/mixin/MixinNetHandlerPlayServer.java index e7bebb24..d5b2408b 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/mixin/MixinNetHandlerPlayServer.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/mixin/MixinNetHandlerPlayServer.java @@ -1,10 +1,10 @@ package de.erdbeerbaerlp.dcintegration.forge.mixin; import de.erdbeerbaerlp.dcintegration.forge.DiscordIntegrationMod; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.network.play.ServerPlayNetHandler; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -14,14 +14,14 @@ /** * Mixin used to detect player timeouts */ -@Mixin(value = ServerGamePacketListenerImpl.class, priority = 1001) +@Mixin(value = ServerPlayNetHandler.class, priority = 1001) public class MixinNetHandlerPlayServer { @Shadow - public ServerPlayer player; + public ServerPlayerEntity player; @Inject(method = "disconnect", at = @At("HEAD")) - private void onDisconnect(final Component textComponent, CallbackInfo ci) { - if (textComponent.equals(new TranslatableComponent("disconnect.timeout"))) + private void onDisconnect(final ITextComponent textComponent, CallbackInfo ci) { + if (textComponent.equals(new TranslationTextComponent("disconnect.timeout"))) DiscordIntegrationMod.timeouts.add(this.player.getUUID()); } } \ No newline at end of file diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/mixin/MixinPlayerLogin.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/mixin/MixinPlayerLogin.java index 30b46f3e..07d208f7 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/mixin/MixinPlayerLogin.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/mixin/MixinPlayerLogin.java @@ -5,10 +5,10 @@ import de.erdbeerbaerlp.dcintegration.common.storage.Configuration; import de.erdbeerbaerlp.dcintegration.common.storage.Localization; import de.erdbeerbaerlp.dcintegration.common.storage.linking.LinkManager; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.server.players.PlayerList; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.minecraft.server.management.PlayerList; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.fml.server.ServerLifecycleHooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -19,17 +19,17 @@ @Mixin(PlayerList.class) public class MixinPlayerLogin { @Inject(method = "canPlayerLogin", at = @At("HEAD"), cancellable = true) - private void canLogin(SocketAddress address, GameProfile profile, CallbackInfoReturnable cir) { + private void canLogin(SocketAddress address, GameProfile profile, CallbackInfoReturnable cir) { if (Configuration.instance().linking.whitelistMode && ServerLifecycleHooks.getCurrentServer().usesAuthentication()) { LinkManager.checkGlobalAPI(profile.getId()); try { if (!LinkManager.isPlayerLinked(profile.getId())) { - cir.setReturnValue(new TextComponent(Localization.instance().linking.notWhitelistedCode.replace("%code%",""+LinkManager.genLinkNumber(profile.getId())))); + cir.setReturnValue(new StringTextComponent(Localization.instance().linking.notWhitelistedCode.replace("%code%",""+LinkManager.genLinkNumber(profile.getId())))); }else if(!DiscordIntegration.INSTANCE.canPlayerJoin(profile.getId())){ - cir.setReturnValue(new TextComponent(Localization.instance().linking.notWhitelistedRole)); + cir.setReturnValue(new StringTextComponent(Localization.instance().linking.notWhitelistedRole)); } } catch (IllegalStateException e) { - cir.setReturnValue(new TextComponent("An error occured\nPlease check Server Log for more information\n\n" + e)); + cir.setReturnValue(new StringTextComponent("An error occured\nPlease check Server Log for more information\n\n" + e)); } } } diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeMessageUtils.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeMessageUtils.java index 8bbf2c5f..a449597c 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeMessageUtils.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeMessageUtils.java @@ -3,7 +3,6 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dcshadow.org.apache.commons.collections4.keyvalue.DefaultMapEntry; @@ -11,19 +10,19 @@ import de.erdbeerbaerlp.dcintegration.common.util.MessageUtils; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; -import net.minecraft.ChatFormatting; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.commands.arguments.NbtTagArgument; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.command.arguments.ComponentArgument; +import net.minecraft.command.arguments.NBTTagArgument; +import net.minecraft.entity.Entity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.nbt.StringNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.IForgeRegistry; @@ -33,6 +32,8 @@ public class ForgeMessageUtils extends MessageUtils { + private static final com.google.gson.JsonParser p = new com.google.gson.JsonParser(); + private static final IForgeRegistry itemreg = ForgeRegistries.ITEMS; public static String formatPlayerName(Map.Entry p) { @@ -40,22 +41,23 @@ public static String formatPlayerName(Map.Entry p) { } public static String formatPlayerName(Map.Entry p, boolean chatFormat) { - return ChatFormatting.stripFormatting(p.getValue()); + return TextFormatting.stripFormatting(p.getValue()); } /** - * Attempts to generate an {@link MessageEmbed} showing item info from an {@link Component} instance + * Attempts to generate an {@link MessageEmbed} showing item info from an {@link ITextComponent} instance * * @param component The TextComponent to scan for item info * @return an {@link MessageEmbed} when there was an Item info, or {@link null} if there was no item info OR the item info was disabled */ - public static MessageEmbed genItemStackEmbedIfAvailable(final Component component) { + public static MessageEmbed genItemStackEmbedIfAvailable(final ITextComponent component) { if (!Configuration.instance().forgeSpecific.sendItemInfo) return null; - final JsonObject json = JsonParser.parseString(Component.Serializer.toJson(component)).getAsJsonObject(); + final JsonObject json = p.parse(ITextComponent.Serializer.toJson(component)).getAsJsonObject(); if (json.has("with")) { final JsonArray args = json.getAsJsonArray("with"); for (JsonElement el : args) { - if (el instanceof JsonObject arg1) { + if (el instanceof JsonObject) { + JsonObject arg1 = (JsonObject) el; if (arg1.has("hoverEvent")) { final JsonObject hoverEvent = arg1.getAsJsonObject("hoverEvent"); if (hoverEvent.has("action") && hoverEvent.get("action").getAsString().equals("show_item") && hoverEvent.has("contents")) { @@ -64,12 +66,13 @@ public static MessageEmbed genItemStackEmbedIfAvailable(final Component componen try { final ItemStack is = new ItemStack(itemreg.getValue(new ResourceLocation(item.get("id").getAsString()))); if (item.has("tag")) { - final CompoundTag tag = (CompoundTag) NbtTagArgument.nbtTag().parse(new StringReader(item.get("tag").getAsString())); + + final CompoundNBT tag = (CompoundNBT) NBTTagArgument.nbtTag().parse(new StringReader(item.get("tag").getAsString())); is.setTag(tag); } - final CompoundTag itemTag = is.getOrCreateTag(); + final CompoundNBT itemTag = is.getOrCreateTag(); final EmbedBuilder b = new EmbedBuilder(); - String title = is.hasCustomHoverName() ? is.getDisplayName().getString() : new TranslatableComponent(is.getItem().getDescriptionId()).getString(); + String title = is.hasCustomHoverName() ? is.getDisplayName().getString() : new TranslationTextComponent(is.getItem().getDescriptionId()).getString(); if (title.isEmpty()) title = is.getItem().getDescriptionId(); else @@ -89,27 +92,28 @@ public static MessageEmbed genItemStackEmbedIfAvailable(final Component componen if (!flags[0]) { //Implementing this code myself because the original is broken for (int i = 0; i < is.getEnchantmentTags().size(); ++i) { - final CompoundTag compoundnbt = is.getEnchantmentTags().getCompound(i); - final Enchantment ench = Enchantment.byId(compoundnbt.getInt("id")); - if (compoundnbt.get("lvl") != null) { - final int level; - if (compoundnbt.get("lvl") instanceof StringTag) { - level = Integer.parseInt(compoundnbt.getString("lvl").replace("s", "")); - } else - level = compoundnbt.getInt("lvl") == 0 ? compoundnbt.getShort("lvl") : compoundnbt.getInt("lvl"); - tooltip.append(ChatFormatting.stripFormatting(ench.getFullname(level).getString())).append("\n"); - } + final CompoundNBT compoundnbt = is.getEnchantmentTags().getCompound(i); + Registry.ENCHANTMENT.getOptional(ResourceLocation.tryParse(compoundnbt.getString("id"))).ifPresent((ench) -> { + if (compoundnbt.get("lvl") != null) { + final int level; + if (compoundnbt.get("lvl") instanceof StringNBT) { + level = Integer.parseInt(compoundnbt.getString("lvl").replace("s", "")); + } else + level = compoundnbt.getInt("lvl") == 0 ? compoundnbt.getShort("lvl") : compoundnbt.getInt("lvl"); + tooltip.append(TextFormatting.stripFormatting(ench.getFullname(level).getString())).append("\n"); + } + }); }/* EnchantmentHelper.getEnchantments(is).forEach((ench, lvl) -> { tooltip.append(TextFormatting.getTextWithoutFormattingCodes(ench.getDisplayName(lvl).getUnformattedComponentText())).append("\n"); });*/ } //Add Lores - final ListTag list = itemTag.getCompound("display").getList("Lore", 8); + final ListNBT list = itemTag.getCompound("display").getList("Lore", 8); list.forEach((nbt) -> { try { - if (nbt instanceof StringTag) { - final Component comp = (Component) ComponentArgument.textComponent().parse(new StringReader(nbt.getAsString())); + if (nbt instanceof StringNBT) { + final ITextComponent comp = ComponentArgument.textComponent().parse(new StringReader(nbt.getAsString())); tooltip.append("_").append(comp.getString()).append("_\n"); } } catch (CommandSyntaxException e) { diff --git a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeServerInterface.java b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeServerInterface.java index 9da5481e..53f2d0d9 100644 --- a/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeServerInterface.java +++ b/src/main/java/de/erdbeerbaerlp/dcintegration/forge/util/ForgeServerInterface.java @@ -27,13 +27,15 @@ import net.dv8tion.jda.api.entities.emoji.EmojiUnion; import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.requests.RestAction; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.protocol.game.ClientboundSoundPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.sounds.SoundSource; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.minecraft.command.arguments.ComponentArgument; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.network.play.server.SPlaySoundPacket; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.fml.server.ServerLifecycleHooks; import java.util.HashMap; import java.util.List; @@ -55,24 +57,24 @@ public int getOnlinePlayers() { @Override public void sendIngameMessage(Component msg) { - final List l = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers(); + final List l = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers(); try { - for (final ServerPlayer p : l) { + for (final ServerPlayerEntity p : l) { if (!DiscordIntegration.INSTANCE.ignoringPlayers.contains(p.getUUID()) && !(LinkManager.isPlayerLinked(p.getUUID()) && LinkManager.getLink(null, p.getUUID()).settings.ignoreDiscordChatIngame)) { final Map.Entry ping = ComponentUtils.parsePing(msg, p.getUUID(), p.getName().getString()); final String jsonComp = GsonComponentSerializer.gson().serialize(ping.getValue()).replace("\\\\n", "\n"); - final net.minecraft.network.chat.Component comp = ComponentArgument.textComponent().parse(new StringReader(jsonComp)); + final ITextComponent comp = ComponentArgument.textComponent().parse(new StringReader(jsonComp)); p.sendMessage(comp, DiscordIntegration.dummyUUID); if (ping.getKey()) { if (LinkManager.isPlayerLinked(p.getUUID()) && LinkManager.getLink(null, p.getUUID()).settings.pingSound) { - p.connection.send(new ClientboundSoundPacket(SoundEvents.NOTE_BLOCK_PLING, SoundSource.MASTER, p.position().x,p.position().y,p.position().z, 1,1)); + p.connection.send(new SPlaySoundPacket(SoundEvents.NOTE_BLOCK_PLING.getLocation(), SoundCategory.MASTER, new Vector3d(p.position().x,p.position().y,p.position().z), 1,1)); } } } } //Send to server console too final String jsonComp = GsonComponentSerializer.gson().serialize(msg).replace("\\\\n", "\n"); - final net.minecraft.network.chat.Component comp = ComponentArgument.textComponent().parse(new StringReader(jsonComp)); + final ITextComponent comp = ComponentArgument.textComponent().parse(new StringReader(jsonComp)); ServerLifecycleHooks.getCurrentServer().sendMessage(comp, DiscordIntegration.dummyUUID); } catch (Exception e) { e.printStackTrace(); @@ -81,8 +83,8 @@ public void sendIngameMessage(Component msg) { @Override public void sendIngameReaction(Member member, RestAction retrieveMessage, UUID targetUUID, EmojiUnion reactionEmote) { - final List l = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers(); - for (final ServerPlayer p : l) { + final List l = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers(); + for (final ServerPlayerEntity p : l) { if (p.getUUID().equals(targetUUID) && !DiscordIntegration.INSTANCE.ignoringPlayers.contains(p.getUUID()) && (LinkManager.isPlayerLinked(p.getUUID()) && !LinkManager.getLink(null, p.getUUID()).settings.ignoreDiscordChatIngame && !LinkManager.getLink(null, p.getUUID()).settings.ignoreReactions)) { final String emote = reactionEmote.getType() == Emoji.Type.UNICODE ? EmojiParser.parseToAliases(reactionEmote.getName()) : ":" + reactionEmote.getName() + ":"; @@ -117,17 +119,17 @@ public void runMcCommand(String cmd, final CompletableFuture cm try { ServerLifecycleHooks.getCurrentServer().getCommands().getDispatcher().execute(cmd.trim(), s.createCommandSourceStack()); } catch (CommandSyntaxException e) { - s.sendMessage(new TextComponent(e.getMessage()), DiscordIntegration.dummyUUID); + s.sendMessage(new StringTextComponent(e.getMessage()), DiscordIntegration.dummyUUID); } } else - s.sendMessage(new TextComponent("Sorry, but the bot has no permissions...\nAdd this into the servers ops.json:\n```json\n {\n \"uuid\": \"" + Configuration.instance().commands.senderUUID + "\",\n \"name\": \"DiscordFakeUser\",\n \"level\": 4,\n \"bypassesPlayerLimit\": false\n }\n```"), DiscordIntegration.dummyUUID); + s.sendMessage(new StringTextComponent("Sorry, but the bot has no permissions...\nAdd this into the servers ops.json:\n```json\n {\n \"uuid\": \"" + Configuration.instance().commands.senderUUID + "\",\n \"name\": \"DiscordFakeUser\",\n \"level\": 4,\n \"bypassesPlayerLimit\": false\n }\n```"), DiscordIntegration.dummyUUID); } @Override public HashMap getPlayers() { final HashMap players = new HashMap<>(); - for (ServerPlayer p : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { + for (ServerPlayerEntity p : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { players.put(p.getUUID(), p.getDisplayName().getString().isEmpty() ? p.getName().getString() : p.getDisplayName().getString()); } return players; @@ -135,9 +137,9 @@ public HashMap getPlayers() { @Override public void sendIngameMessage(String msg, UUID player) { - final ServerPlayer p = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(player); + final ServerPlayerEntity p = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(player); if (p != null) - p.sendMessage(new TextComponent(msg), DiscordIntegration.dummyUUID); + p.sendMessage(new StringTextComponent(msg), DiscordIntegration.dummyUUID); } @@ -146,10 +148,10 @@ public boolean isOnlineMode() { return Configuration.instance().bungee.isBehindBungee || ServerLifecycleHooks.getCurrentServer().usesAuthentication(); } - private void sendReactionMCMessage(ServerPlayer target, Component msgComp) { + private void sendReactionMCMessage(ServerPlayerEntity target, Component msgComp) { final String jsonComp = GsonComponentSerializer.gson().serialize(msgComp).replace("\\\\n", "\n"); try { - final net.minecraft.network.chat.Component comp = ComponentArgument.textComponent().parse(new StringReader(jsonComp)); + final ITextComponent comp = ComponentArgument.textComponent().parse(new StringReader(jsonComp)); target.sendMessage(comp, DiscordIntegration.dummyUUID); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 02cf535b..0d8f4a25 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,6 +1,6 @@ modLoader = "javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion = "[40,)" #mandatory +loaderVersion = "[36,)" #mandatory license = "MIT License" # A URL to refer people to when problems occur with this mod issueTrackerURL = "https://github.com/ErdbeerbaerLP/Discord-Chat-Integration/issues" #optional @@ -23,12 +23,12 @@ This mod links your server chat with a channel on your discord server. [[dependencies.dcintegration]] modId = "minecraft" mandatory = true -versionRange = "[1.18,]" +versionRange = "[1.16.5]" ordering = "NONE" side = "SERVER" [[dependencies.dcintegration]] modId = "forge" mandatory = true -versionRange = "[40.2.0,)" +versionRange = "[36.2.34,)" ordering = "NONE" side = "BOTH" \ No newline at end of file diff --git a/src/main/resources/mixins.dcintegration.json b/src/main/resources/mixins.dcintegration.json index f0c8de4b..32c397db 100644 --- a/src/main/resources/mixins.dcintegration.json +++ b/src/main/resources/mixins.dcintegration.json @@ -2,7 +2,7 @@ "package": "de.erdbeerbaerlp.dcintegration.forge.mixin", "refmap": "mixins.dcintegration.refmap.json", "minVersion": "0.8", - "compatibilityLevel": "JAVA_11", + "compatibilityLevel": "JAVA_8", "server": [ "MixinNetHandlerPlayServer", "MixinPlayerLogin"