Skip to content

Commit

Permalink
Update to 3.0.3, fix bugs
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 f95126f commit 4563e37
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 466 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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 @@ -96,7 +96,7 @@ configurations.all {
//Dependencies
dependencies {
// ========= Common =====================
embed('de.erdbeerbaerlp:dcintegration.common:3.0.2-SNAPSHOT') {
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\nOld configuration can be used as-is\n\nFixed linking not being saved\nOptimized code
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.20.1
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 @@ -202,17 +203,27 @@ 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%",
.replace("%advName%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getTitle()
.getString()))
.replace("%desc%",
.replace("%advDesc%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getDescription()
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 @@ -466,10 +484,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 @@ -519,12 +539,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
Loading

0 comments on commit 4563e37

Please sign in to comment.