Skip to content

Commit

Permalink
Update code to 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonLucid committed Dec 28, 2023
1 parent 7f560c1 commit 92733f4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sourceSets.main.resources { srcDir 'src/generated/resources' }

configurations {
shade
implementation.extendsFrom shade
minecraftLibrary.extendsFrom shade
}

dependencies {
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/aeonlucid/discordsync/DiscordSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.dv8tion.jda.api.utils.MarkdownSanitizer;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.DisplayInfo;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -77,14 +77,14 @@ public void onServerStopped(ServerStoppedEvent event) {
@SubscribeEvent
public void playerJoin(final PlayerEvent.PlayerLoggedInEvent e) {
if (discordClient != null) {
discordClient.sendServerMessage(String.format("**%s joined the server**", PlayerUtils.getName(e.getPlayer())));
discordClient.sendServerMessage(String.format("**%s joined the server**", PlayerUtils.getName(e.getEntity())));
}
}

@SubscribeEvent
public void playerLeft(final PlayerEvent.PlayerLoggedOutEvent e) {
if (discordClient != null) {
discordClient.sendServerMessage(String.format("**%s left the server**", PlayerUtils.getName(e.getPlayer())));
discordClient.sendServerMessage(String.format("**%s left the server**", PlayerUtils.getName(e.getEntity())));
}
}

Expand All @@ -93,12 +93,12 @@ public void playerLeft(final PlayerEvent.PlayerLoggedOutEvent e) {
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void playerChat(final ServerChatEvent e) {
if (discordClient != null) {
String replacement = discordClient.sendPlayerMessage(MarkdownSanitizer.sanitize(e.getMessage()),
String replacement = discordClient.sendPlayerMessage(MarkdownSanitizer.sanitize(e.getMessage().getString()),
PlayerUtils.getName(e.getPlayer()),
PlayerUtils.getAvatar(e.getPlayer()));

if (replacement != null && e.getComponent() instanceof final TranslatableComponent component) {
component.getArgs()[1] = new TextComponent(replacement);
if (replacement != null && e.getMessage().getContents() instanceof final TranslatableContents component) {
component.getArgs()[1] = Component.literal(replacement);
}
}
}
Expand All @@ -111,7 +111,7 @@ public void playerDeath(final LivingDeathEvent e) {
return;
}

final String deathMessage = e.getSource().getLocalizedDeathMessage(e.getEntityLiving()).getString();
final String deathMessage = e.getSource().getLocalizedDeathMessage(e.getEntity()).getString();

if (discordClient != null) {
discordClient.sendServerMessage(String.format("**%s**", MarkdownSanitizer.sanitize(deathMessage)));
Expand All @@ -120,13 +120,13 @@ public void playerDeath(final LivingDeathEvent e) {

@SubscribeEvent
public void playerAdvancement(final AdvancementEvent e) {
final MinecraftServer server = e.getPlayer().getServer();
final MinecraftServer server = e.getEntity().getServer();

if (server == null) {
return;
}

final PlayerAdvancements advancements = server.getPlayerList().getPlayerAdvancements((ServerPlayer) e.getPlayer());
final PlayerAdvancements advancements = server.getPlayerList().getPlayerAdvancements((ServerPlayer) e.getEntity());
final Advancement advancement = e.getAdvancement();

if (!advancements.getOrStartProgress(advancement).isDone()) {
Expand All @@ -141,7 +141,7 @@ public void playerAdvancement(final AdvancementEvent e) {

if (discordClient != null) {
discordClient.sendServerMessage(String.format("%s has made the advancement **[%s]**",
PlayerUtils.getName(e.getPlayer()),
PlayerUtils.getName(e.getEntity()),
MarkdownSanitizer.sanitize(titleDisplay.getTitle().getString())));
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/aeonlucid/discordsync/bot/DiscordEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.session.*;
import net.dv8tion.jda.api.events.session.ReadyEvent;
import net.dv8tion.jda.api.events.session.SessionDisconnectEvent;
import net.dv8tion.jda.api.events.session.SessionRecreateEvent;
import net.dv8tion.jda.api.events.session.SessionResumeEvent;
import net.dv8tion.jda.api.events.session.ShutdownEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.players.PlayerList;
import net.minecraftforge.server.ServerLifecycleHooks;
Expand Down Expand Up @@ -101,13 +102,13 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
final String sender = member.getEffectiveName();
final String message = event.getMessage().getContentStripped();

final Component textComponent = new TextComponent("")
.append(new TextComponent("[Discord @").withStyle(ChatFormatting.AQUA))
.append(new TextComponent(sender).withStyle(ChatFormatting.GREEN))
.append(new TextComponent("] ").withStyle(ChatFormatting.AQUA))
final Component textComponent = Component.literal("")
.append(Component.literal("[Discord @").withStyle(ChatFormatting.AQUA))
.append(Component.literal(sender).withStyle(ChatFormatting.GREEN))
.append(Component.literal("] ").withStyle(ChatFormatting.AQUA))
.append(message);

// Send to all players.
playerList.broadcastMessage(textComponent, ChatType.SYSTEM, Util.NIL_UUID);
playerList.broadcastSystemMessage(textComponent, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
public class PlayerUtils {

public static String getName(Player player) {
String name = player.getDisplayName().getContents();
String name = player.getDisplayName().getString();

if (name.isEmpty()) {
name = player.getName().getContents();
name = player.getName().getString();
}

return name;
Expand Down

0 comments on commit 92733f4

Please sign in to comment.