Skip to content

Commit

Permalink
Updated Mod To 1.20.1 (#12)
Browse files Browse the repository at this point in the history
- Moved version numbers to gradle.properties
- Changed DiscriminatedName to Name as discord no longer has numbers
- Fixed AdvancementEvent to AdvancementEarnEvent
- Fixed the Name for AdvancementEarnEvent
- Added message to config to make sure 'Message Content Intent' is enabled for the bot

Co-authored-by: DinnerBeef <[email protected]>
  • Loading branch information
DinnerBeef and DinnerBeef authored Jul 9, 2023
1 parent abaaab3 commit 9042b7c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ minecraft {
//
// Use non-default mappings at your own risk. They may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'official', version: '1.19'
mappings channel: 'official', version: minecraft_version

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
Expand Down Expand Up @@ -118,7 +118,11 @@ configurations {
}
minecraft.runs.all {
lazyToken('minecraft_classpath') {
configurations.library.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator)
configurations.library.copyRecursive().resolve()
.collect { it.absolutePath }
.findAll { !it.contains("org.jetbrains\\annotations\\13.0") }
.findAll { !it.contains("org.jetbrains\\annotations\\23.0") }
.join(File.pathSeparator)
}
}

Expand All @@ -130,9 +134,9 @@ repositories {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.19-41.0.98'
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"

library('org.javacord:javacord:3.6.0')
library("org.javacord:javacord:${javacord_version}")
library('org.apache.logging.log4j:log4j-api:2.17.2')
}

Expand Down
9 changes: 8 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.daemon=false

minecraft_version=1.20.1
forge_version=47.1.0

javacord_version=3.8.0

mod_version=1.0.0
4 changes: 2 additions & 2 deletions src/main/java/org/jedi/DiscordMessageFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public Component format(Message message) {

private Component formatAuthorName(Message message) {
final TextColor color = this.getAuthorColor(message);
final MutableComponent discriminatedName = Component.literal(message.getAuthor().getDiscriminatedName());
final MutableComponent name = Component.literal(message.getAuthor().getName());

return Component.literal(message.getAuthor().getDisplayName())
.withStyle(Style.EMPTY
.withColor(color)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, discriminatedName))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, name))
);
}

Expand Down
27 changes: 12 additions & 15 deletions src/main/java/org/jedi/JustEnoughDiscordIntegrationMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import com.google.common.collect.Maps;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.advancements.Advancement;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.AdvancementEvent;
import net.minecraftforge.event.entity.player.AdvancementEvent.AdvancementEarnEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.event.server.ServerStoppedEvent;
Expand All @@ -31,6 +29,7 @@
import org.apache.logging.log4j.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.javacord.api.entity.intent.Intent;
import org.javacord.api.entity.message.Message;
import org.javacord.api.entity.message.WebhookMessageBuilder;
import org.javacord.api.entity.message.mention.AllowedMentions;
Expand Down Expand Up @@ -93,16 +92,14 @@ public JustEnoughDiscordIntegrationMod() {
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG);
MinecraftForge.EVENT_BUS.register(this);

ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> {
return new IExtensionPoint.DisplayTest(
() -> IGNORESERVERONLY,
(a, b) -> true
);
});
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(
() -> IGNORESERVERONLY,
(a, b) -> true
));
}

private static void setupConfig(ForgeConfigSpec.Builder builder) {
builder.comment(" Create a bot here: https://discord.com/developers/applications");
builder.comment(" Create a bot here: https://discord.com/developers/applications \"Make sure 'Message Content Intent' is enabled\"");
builder.push("Discord Values");

botTokenEntry = builder.comment(" The bot-specific token for your Discord bot")
Expand Down Expand Up @@ -154,6 +151,7 @@ public void onServerStarting(ServerStartingEvent event) {
final String token = botTokenEntry.get();
if (token.length() > 0) {
discordBuilder.setToken(token);
discordBuilder.addIntents(Intent.MESSAGE_CONTENT);
discordBuilder.login().thenAccept(dcObject -> {
discord = Optional.of(dcObject);
loadWebhooks();
Expand Down Expand Up @@ -195,28 +193,27 @@ public void playerLeave(PlayerEvent.PlayerLoggedOutEvent event) {

@SubscribeEvent
public void playerJoin(PlayerEvent.PlayerLoggedInEvent event) {
CACHE_BUSTS.put(event.getEntity().getUUID(), "" + System.currentTimeMillis());
CACHE_BUSTS.put(event.getEntity().getUUID(), String.valueOf(System.currentTimeMillis()));
sendMessage(String.format(joinedGameEntry.get(), getPlayerName(event)));
}

@SubscribeEvent
public void playerLeave(AdvancementEvent event) {
public void onAdvancementEarn(AdvancementEarnEvent event) {
final Advancement advancement = event.getAdvancement();
if (advancement.getDisplay() == null) {
return;
}
final String playerName = strip(event.getEntity().getDisplayName().getString());
final String advancementName = strip(advancement.getDisplay().getTitle().getString());
final String advancementDesc = strip(advancement.getDisplay().getDescription().getString());

sendMessage(String.format(advancementEntry.get(), playerName, advancementName, advancementDesc));
}

@SubscribeEvent
public void onServerChatEvent(ServerChatEvent event) {
try {
final String username = event.getUsername();
final String message = event.getMessage();
final String message = event.getMessage().getString();
final String uuid = event.getPlayer().getStringUUID();
final String cacheBust = CACHE_BUSTS.getOrDefault(event.getPlayer().getUUID(), username);

Expand All @@ -239,7 +236,7 @@ public void onMessageCreate(MessageCreateEvent event) {
if (!readChannels.get().contains(event.getChannel().getId())) return;

Component chatMessage = messageFormatter.format(message);
ServerLifecycleHooks.getCurrentServer().getPlayerList().broadcastSystemMessage(chatMessage, ChatType.SYSTEM);
ServerLifecycleHooks.getCurrentServer().getPlayerList().broadcastSystemMessage(chatMessage, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modLoader="javafml"
loaderVersion="[41,)"
loaderVersion="[47,)"
license="MPLv2"
issueTrackerURL="https://github.com/Cojomax99/JustEnoughDiscordIntegration/issues"

Expand Down

0 comments on commit 9042b7c

Please sign in to comment.