Skip to content

Commit

Permalink
Gotta make sure special formatting is kept for Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
phit committed Dec 22, 2024
1 parent e6f68cf commit e6ea905
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,27 @@ public void playerLoggedOut(ServerPlayer e) {
// }
// }

public void serverChat(ServerPlayer player, ChatEvent.ChatComponent component) {
public void formatServerChat(ServerPlayer player, ChatEvent.ChatComponent component) {
Component chatComponent = component.get().copy();
String content = SIBUtil.getRawText(chatComponent);
component.set(SimpleIRCBridgeCommon.newChatWithLinks(content, false));
if (player != null) {
String playername = player.getName().getString();
}

public EventResult livingDeath(LivingEntity livingEntity, DamageSource damageSource) {
if (livingEntity instanceof ServerPlayer) {
toIrc(String.format(FORMAT1_MC_DEATH, damageSource.getLocalizedDeathMessage(livingEntity).getString().replace(livingEntity.getName().toString(), SIBUtil.mangle(livingEntity.getName().toString())) ));
}
return EventResult.pass();
}

private void toIrc(String s) {
this.bridge.sendToIrc(s);
}

public EventResult serverChat(ServerPlayer serverPlayer, Component component) {
String content = SIBUtil.getRawText(component);
if (serverPlayer != null) {
String playername = SIBUtil.mangle(serverPlayer.getName().getString());
if (Config.ircFormatting) {
content = IRCMinecraftConverter.convMinecraftToIRC(content);
}
Expand All @@ -71,16 +86,7 @@ public void serverChat(ServerPlayer player, ChatEvent.ChatComponent component) {
}
toIrc(String.format(FORMAT2_MC_CHAT, "Server", content));
}
}

public EventResult livingDeath(LivingEntity livingEntity, DamageSource damageSource) {
if (livingEntity instanceof ServerPlayer) {
toIrc(String.format(FORMAT1_MC_DEATH, damageSource.getLocalizedDeathMessage(livingEntity).getString().replace(livingEntity.getName().toString(), SIBUtil.mangle(livingEntity.getName().toString())) ));
}
return EventResult.pass();
}

private void toIrc(String s) {
this.bridge.sendToIrc(s);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SIBConstants {
public static final String FORMAT1_MC_LOGIN = "> %s joined the game";
public static final String FORMAT1_MC_LOGOUT = "< %s left the game";
public static final String FORMAT1_MC_DEATH = "%s";
public static final String FORMAT1_MC_LOGOUT_STOP = ">>>%s was still online when time came to a halt<<<";
public static final String FORMAT1_MC_LOGOUT_STOP = "< %s left the game when time came to a halt";

/* == MC FORMATS, 2 PARAMETERS == */
public static final String FORMAT2_MC_EMOTE = "* %s %s";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public SimpleIRCBridgeCommon() {
PlayerEvent.PLAYER_QUIT.register((Playerquit) -> eventHandler.playerLoggedOut(Playerquit));
EntityEvent.LIVING_DEATH.register(eventHandler::livingDeath);

ChatEvent.DECORATE.register(eventHandler::serverChat);
ChatEvent.DECORATE.register(eventHandler::formatServerChat);
ChatEvent.RECEIVED.register(eventHandler::serverChat);

LifecycleEvent.SERVER_STARTING.register(Config::serverStarting);
LifecycleEvent.SERVER_STOPPING.register(Config::serverStopping);
Expand All @@ -55,7 +56,7 @@ public void serverStopping(MinecraftServer instance) {
if (this.mcServer != null && Config.timestop) {
this.mcServer.getPlayerList()
.getPlayers()
.forEach(player -> sendToIrc(MircColors.BOLD + MircColors.LIGHT_RED + String.format(FORMAT1_MC_LOGOUT_STOP, SIBUtil.mangle(player.getName().getString()))));
.forEach(player -> sendToIrc(String.format(FORMAT1_MC_LOGOUT_STOP, SIBUtil.mangle(player.getName().getString()))));
}
if (this.bot != null) {
this.bot.disconnect();
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true

# Mod properties
mod_version = 1.1.1
mod_version = 1.1.3
maven_group = net.stonebound.simpleircbridge
archives_name = simpleircbridge
enabled_platforms = fabric,neoforge
Expand Down

0 comments on commit e6ea905

Please sign in to comment.