Skip to content

Commit

Permalink
Update to 3.0.3
Browse files Browse the repository at this point in the history
Signed-off-by: ErdbeerbaerLP <[email protected]>
  • Loading branch information
ErdbeerbaerLP committed Sep 30, 2023
1 parent 36d8e67 commit fc48928
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 43 deletions.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ buildscript {
url = 'https://repo.spongepowered.org/maven'
}
maven {
url "https://plugins.gradle.org/m2/"

url "https://plugins.gradle.org/m2/"
}
}
dependencies {
Expand All @@ -31,7 +30,7 @@ apply plugin: 'org.spongepowered.mixin'


//Build variables
version = "3.0.2"
version = "3.0.3"
group = "de.erdbeerbaerlp.dcintegration"
archivesBaseName = "dcintegration-forge"

Expand Down Expand Up @@ -95,7 +94,7 @@ configurations.all {
//Dependencies
dependencies {
// ========= Common =====================
embed('de.erdbeerbaerlp:dcintegration.common:3.0.2') {
embed('de.erdbeerbaerlp:dcintegration.common:3.0.3') {
changing = true
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
changelog=Large discord integration rewrite adding new features and fixing long existing bugs Old configuration can be used as-is\n\nFixed linking not being saved\nOptimized code\n\nNOTE: This version may contain lots of console spam
releaseType = ALPHA
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.19.2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dcshadow.dev.vankka.mcdiscordreserializer.discord.DiscordSerializer;
import dcshadow.net.kyori.adventure.text.Component;
import dcshadow.net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import de.erdbeerbaerlp.dcintegration.common.DiscordIntegration;
Expand Down Expand Up @@ -117,16 +118,16 @@ 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 (DiscordIntegration.INSTANCE.getChannel() != null) {
final MessageCreateData m;
if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.startMessages.asEmbed)
m = new MessageCreateBuilder().setEmbeds(Configuration.instance().embedMode.startMessages.toEmbed().setDescription(Localization.instance().serverStarting).build()).build();
else
m = new MessageCreateBuilder().addContent(Localization.instance().serverStarting).build();
DiscordIntegration.startingMsg = DiscordIntegration.INSTANCE.sendMessageReturns(m, DiscordIntegration.INSTANCE.getChannel(Configuration.instance().advanced.serverChannelID));
}
}
if (!Localization.instance().serverStarting.isBlank())
if (DiscordIntegration.INSTANCE.getChannel() != null) {
final MessageCreateData m;
if (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.startMessages.asEmbed)
m = new MessageCreateBuilder().setEmbeds(Configuration.instance().embedMode.startMessages.toEmbed().setDescription(Localization.instance().serverStarting).build()).build();
else
m = new MessageCreateBuilder().addContent(Localization.instance().serverStarting).build();
DiscordIntegration.startingMsg = DiscordIntegration.INSTANCE.sendMessageReturns(m, DiscordIntegration.INSTANCE.getChannel(Configuration.instance().advanced.serverChannelID));
}
}
} catch (InterruptedException | NullPointerException ignored) {
}
}
Expand Down Expand Up @@ -202,22 +203,32 @@ public void advancement(AdvancementEvent.AdvancementEarnEvent ev) {
} else {
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())));
.setDescription(Localization.instance().advancementMessage.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())).replace("%advName%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getTitle()
.getString()))
.replace("%advDesc%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getDescription()
.getString()))
.replace("\\n", "\n"));
INSTANCE.sendMessage(new DiscordMessage(b.build()));
}
} else INSTANCE.sendMessage(Localization.instance().advancementMessage.replace("%player%",
ChatFormatting.stripFormatting(ForgeMessageUtils.formatPlayerName(ev.getEntity())))
.replace("%name%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getTitle()
.getString()))
.replace("%desc%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getDescription()
.getString()))
.replace("\\n", "\n"));
ChatFormatting.stripFormatting(ForgeMessageUtils.formatPlayerName(ev.getEntity())))
.replace("%advName%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getTitle()
.getString()))
.replace("%advDesc%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getDescription()
.getString()))
.replace("\\n", "\n"));
}
}

Expand Down Expand Up @@ -252,7 +263,7 @@ public void serverStarted(final ServerStartedEvent ev) {
}
INSTANCE.startThreads();
}
UpdateChecker.runUpdateCheck("https://raw.githubusercontent.com/ErdbeerbaerLP/Discord-Chat-Integration/1.20.1/update_checker.json");
UpdateChecker.runUpdateCheck("https://raw.githubusercontent.com/ErdbeerbaerLP/Discord-Chat-Integration/1.19.2/update_checker.json");
if (ModList.get().getModContainerById("dynmap").isPresent()) {
new DynmapListener().register();
}
Expand Down Expand Up @@ -291,6 +302,13 @@ 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()){
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], ""))));
}
}
if (command.startsWith("discord ") || command.startsWith("dc ")) {
final String[] args = command.replace("discord ", "").replace("dc ", "").split(" ");
for (MCSubCommand mcSubCommand : McCommandRegistry.getCommands()) {
Expand Down Expand Up @@ -448,10 +466,12 @@ public void chat(ServerChatEvent ev) {
}
} else
INSTANCE.sendMessage(ForgeMessageUtils.formatPlayerName(ev.getPlayer()), ev.getPlayer().getUUID().toString(), new DiscordMessage(embed, text, true), channel);
final String json = net.minecraft.network.chat.Component.Serializer.toJson(msg);
Component comp = GsonComponentSerializer.gson().deserialize(json);
final String editedJson = GsonComponentSerializer.gson().serialize(MessageUtils.mentionsToNames(comp, channel.getGuild()));
ev.setMessage(net.minecraft.network.chat.Component.Serializer.fromJson(editedJson));
if(!Configuration.instance().compatibility.disableParsingMentionsIngame) {
final String json = net.minecraft.network.chat.Component.Serializer.toJson(msg);
Component comp = GsonComponentSerializer.gson().deserialize(json);
final String editedJson = GsonComponentSerializer.gson().serialize(MessageUtils.mentionsToNames(comp, channel.getGuild()));
ev.setMessage(net.minecraft.network.chat.Component.Serializer.fromJson(editedJson));
}
}

}
Expand Down Expand Up @@ -501,13 +521,41 @@ public void death(LivingDeathEvent ev) {
public void playerLeave(PlayerEvent.PlayerLoggedOutEvent ev) {
if (stopped) return; //Try to fix player leave messages after stop!
if (Localization.instance().playerLeave.isBlank()) return;
if (LinkManager.isPlayerLinked(ev.getEntity().getUUID()) && LinkManager.getLink(null, ev.getEntity().getUUID()).settings.hideFromDiscord)
return;
if (INSTANCE != null && !timeouts.contains(ev.getEntity().getUUID()))
INSTANCE.sendMessage(Localization.instance().playerLeave.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())));
else if (INSTANCE != null && timeouts.contains(ev.getEntity().getUUID())) {
INSTANCE.sendMessage(Localization.instance().playerTimeout.replace("%player%", ForgeMessageUtils.formatPlayerName(ev.getEntity())));
timeouts.remove(ev.getEntity().getUUID());
final Player player = ev.getEntity();
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 (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.playerLeaveMessages.asEmbed) {
if (!Configuration.instance().embedMode.playerLeaveMessages.customJSON.isBlank()) {
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("-", ""))
.replace("%name%", ForgeMessageUtils.formatPlayerName(player))
.replace("%randomUUID%", UUID.randomUUID().toString())
.replace("%avatarURL%", avatarURL)
.replace("%playerColor%", "" + TextColors.generateFromUUID(player.getUUID()).getRGB())
);
DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build()));
} else {
EmbedBuilder b = Configuration.instance().embedMode.playerLeaveMessages.toEmbed();
b = b.setAuthor(ForgeMessageUtils.formatPlayerName(player), null, avatarURL)
.setDescription(Localization.instance().playerLeave.replace("%player%", ForgeMessageUtils.formatPlayerName(player)));
DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build()));
}
} else
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 (Configuration.instance().embedMode.enabled && Configuration.instance().embedMode.playerLeaveMessages.asEmbed) {
EmbedBuilder b = Configuration.instance().embedMode.playerLeaveMessages.toEmbed();
b = b.setAuthor(ForgeMessageUtils.formatPlayerName(player), null, avatarURL)
.setDescription(Localization.instance().playerTimeout.replace("%player%", ForgeMessageUtils.formatPlayerName(player)));
DiscordIntegration.INSTANCE.sendMessage(new DiscordMessage(b.build()));
} else
DiscordIntegration.INSTANCE.sendMessage(Localization.instance().playerTimeout.replace("%player%", ForgeMessageUtils.formatPlayerName(player)));
}
DiscordIntegrationMod.timeouts.remove(player.getUUID());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public static MessageEmbed genItemStackEmbedIfAvailable(final Component componen
if (json.has("with")) {
final JsonArray args = json.getAsJsonArray("with");
for (JsonElement el : args) {
if (el instanceof JsonObject) {
JsonObject arg1 = (JsonObject) el;
if (el instanceof JsonObject arg1) {
if (arg1.has("hoverEvent")) {
final JsonObject hoverEvent = arg1.getAsJsonObject("hoverEvent");
if (hoverEvent.has("action") && hoverEvent.get("action").getAsString().equals("show_item") && hoverEvent.has("contents")) {
Expand Down
5 changes: 5 additions & 0 deletions update_checker.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"version": "3.0.3",
"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",
"type": "beta"
},
{
"version": "3.0.2",
"changelog": "Fixed linking not being saved\nOptimized code",
Expand Down

0 comments on commit fc48928

Please sign in to comment.