Skip to content

Commit

Permalink
Port 3.0.0 to 1.19
Browse files Browse the repository at this point in the history
Signed-off-by: ErdbeerbaerLP <[email protected]>
  • Loading branch information
ErdbeerbaerLP committed Aug 5, 2023
1 parent c78ffff commit 0d0ac28
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 72 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ configurations {
task release{

}

shadowJar {
archiveClassifier = "${project.mcVersion}"
configurations = [project.configurations.embed]
Expand Down Expand Up @@ -101,7 +102,7 @@ dependencies {
}

// ========= Minecraft Forge =============
minecraft "net.minecraftforge:forge:${project.mcVersion}-47.1.43"
minecraft "net.minecraftforge:forge:${project.mcVersion}-45.1.0"

//Mixin
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
releaseType = ALPHA
mcVersion = 1.20.1
mcVersion = 1.19.4
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,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 @@ -207,18 +207,18 @@ public void advancement(AdvancementEvent.AdvancementEarnEvent ev) {
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("%name%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getTitle()
.getString()))
.replace("%desc%",
ChatFormatting.stripFormatting(ev.getAdvancement()
.getDisplay()
.getDescription()
.getString()))
.replace("\\n", "\n"));
}
}

Expand Down Expand Up @@ -304,13 +304,10 @@ public void command(CommandEvent ev) {
source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.consoleOnly));
} catch (CommandSyntaxException e) {
final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, null));
source.sendSuccess(() -> {
try {
return ComponentArgument.textComponent().parse(new StringReader(txt));
} catch (CommandSyntaxException ignored) {
return null;
}
}, false);
try {
source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false);
} catch (CommandSyntaxException ignored) {
}
}
break;
case PLAYER_ONLY:
Expand All @@ -319,24 +316,17 @@ public void command(CommandEvent ev) {
if (!mcSubCommand.needsOP()) {
final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID()));

source.sendSuccess(() -> {
try {
return ComponentArgument.textComponent().parse(new StringReader(txt));
} catch (CommandSyntaxException ignored) {
return null;
}
}, false);

try {
source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false);
} catch (CommandSyntaxException ignored) {
}
} else if (source.hasPermission(4)) {
final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID()));
source.sendSuccess(() -> {
try {
return ComponentArgument.textComponent().parse(new StringReader(txt));
} catch (CommandSyntaxException ignored) {
return null;
}
}, false);

try {
source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false);
} catch (CommandSyntaxException ignored) {
}
} else {
source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.noPermission));
}
Expand All @@ -351,38 +341,30 @@ public void command(CommandEvent ev) {
final ServerPlayer player = source.getPlayerOrException();
if (!mcSubCommand.needsOP()) {
final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID()));
source.sendSuccess(() -> {
try {
return ComponentArgument.textComponent().parse(new StringReader(txt));
} catch (CommandSyntaxException ignored) {
return null;
}
}, false);

try {
source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false);
} catch (CommandSyntaxException ignored) {
}
} else if (source.hasPermission(4)) {
final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, player.getUUID()));

source.sendSuccess(() -> {
try {
return ComponentArgument.textComponent().parse(new StringReader(txt));
} catch (CommandSyntaxException ignored) {
return null;
}
}, false);

try {
source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false);
} catch (CommandSyntaxException ignored) {
}
} else {
source.sendFailure(net.minecraft.network.chat.Component.nullToEmpty(Localization.instance().commands.noPermission));
}

} catch (CommandSyntaxException e) {
final String txt = GsonComponentSerializer.gson().serialize(mcSubCommand.execute(cmdArgs, null));
source.sendSuccess(() -> {
try {
return ComponentArgument.textComponent().parse(new StringReader(txt));
} catch (CommandSyntaxException ignored) {
return null;
}
}, false);

try {
source.sendSuccess(ComponentArgument.textComponent().parse(new StringReader(txt)), false);
} catch (CommandSyntaxException ignored) {
}
}
break;
}
Expand Down Expand Up @@ -520,7 +502,8 @@ 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 (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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class McCommandDiscord {
public McCommandDiscord(CommandDispatcher<CommandSourceStack> dispatcher) {
final LiteralArgumentBuilder<CommandSourceStack> l = Commands.literal("discord");
if (Configuration.instance().ingameCommand.enabled) l.executes((ctx) -> {
ctx.getSource().sendSuccess(()->ComponentUtils.mergeStyles(Component.literal(Configuration.instance().ingameCommand.message),
ctx.getSource().sendSuccess(ComponentUtils.mergeStyles(Component.literal(Configuration.instance().ingameCommand.message),
Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(Configuration.instance().ingameCommand.hoverMessage)))
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Configuration.instance().ingameCommand.inviteURL))), false);
return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -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 = "[41,)" #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
Expand All @@ -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.20,]"
versionRange = "[1.19,]"
ordering = "NONE"
side = "SERVER"
[[dependencies.dcintegration]]
modId = "forge"
mandatory = true
versionRange = "[47.0.0,)"
versionRange = "[41.1.0,)"
ordering = "NONE"
side = "BOTH"

0 comments on commit 0d0ac28

Please sign in to comment.