Skip to content

Commit

Permalink
Clickable welcome message (GTNewHorizons#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru authored Oct 11, 2024
1 parent e7a5826 commit af772e7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
49 changes: 36 additions & 13 deletions src/main/java/com/dreammaster/loginhandler/LoginHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,50 @@
import static com.dreammaster.config.CoreModConfig.ModPackVersion;
import static net.minecraft.util.EnumChatFormatting.*;

import java.util.Arrays;

import net.minecraft.event.ClickEvent;
import net.minecraft.event.HoverEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.StatCollector;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;

public class LoginHandler {

private static final String[] LOGIN_TEXT = {
GOLD.toString() + STRIKETHROUGH + "-----------------------------------------------------",
BOLD + "Welcome to Gregtech: New Horizons " + GREEN + ModPackVersion,
BLUE + "The Quest Book has a shortcut key, check your keybindings", BLUE + "to remove conflicts.",
DARK_GREEN + "GTNH WIKI link https://gtnh.miraheze.org/wiki/", GREEN + "Please report bugs here:",
GOLD + "https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/",
BLUE + "Visit our discord at https://discord.gg/gtnh",
GOLD.toString() + STRIKETHROUGH + "-----------------------------------------------------" };

@SuppressWarnings("unused")
// spotless:off
@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
Arrays.stream(LOGIN_TEXT).map(ChatComponentText::new).forEach(event.player::addChatMessage);
final String WIKI_LINK = "https://gtnh.miraheze.org/wiki/";
final String ISSUE_TRACKER_LINK = "https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues";
final String DISCORD_LINK = "https://discord.gg/gtnh";
final String WELCOME = StatCollector.translateToLocal("dreamcraft.welcome.welcome");
final String QUESTBOOK = StatCollector.translateToLocal("dreamcraft.welcome.questbook");
final String GTNH_WIKI = StatCollector.translateToLocal("dreamcraft.welcome.gtnh_wiki");
final String CLICK_WIKI = StatCollector.translateToLocal("dreamcraft.welcome.click_wiki");
final String REPORT_BUG = StatCollector.translateToLocal("dreamcraft.welcome.report_bug");
final String CLICK_GITHUB = StatCollector.translateToLocal("dreamcraft.welcome.click_github");
final String VISIT_DISCORD = StatCollector.translateToLocal("dreamcraft.welcome.visitdiscord");
final String CLICK_DISCORD = StatCollector.translateToLocal("dreamcraft.welcome.click_discord");
event.player.addChatMessage(new ChatComponentText(GOLD.toString() + STRIKETHROUGH + "-----------------------------------------------------"));
event.player.addChatMessage(new ChatComponentText(BOLD + WELCOME + " " + GREEN + ModPackVersion));
event.player.addChatMessage(new ChatComponentText(BLUE + QUESTBOOK));
event.player.addChatMessage(new ChatComponentText(DARK_GREEN + GTNH_WIKI + " ")
.appendSibling(new ChatComponentText(DARK_GREEN + WIKI_LINK)
.setChatStyle(new ChatStyle()
.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(YELLOW + CLICK_WIKI)))
.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, WIKI_LINK)))));
event.player.addChatMessage(new ChatComponentText(GREEN + REPORT_BUG));
event.player.addChatMessage(new ChatComponentText(GOLD + ISSUE_TRACKER_LINK)
.setChatStyle(new ChatStyle()
.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(YELLOW + CLICK_GITHUB)))
.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, ISSUE_TRACKER_LINK))));
event.player.addChatMessage(new ChatComponentText(BLUE + VISIT_DISCORD + " ")
.appendSibling(new ChatComponentText(BLUE + DISCORD_LINK)
.setChatStyle(new ChatStyle()
.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(YELLOW + CLICK_DISCORD)))
.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, DISCORD_LINK)))));
event.player.addChatMessage(new ChatComponentText(GOLD.toString() + STRIKETHROUGH + "-----------------------------------------------------"));
}
// spotless:on
}
9 changes: 9 additions & 0 deletions src/main/resources/assets/dreamcraft/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1740,3 +1740,12 @@ item.tconstruct.manual.weaponry.bolts=\n\nBolts:\nCrafting bolts is a delicate p

dreamcraft.mobsinfocompat.limitedropcount=Drops only %s times per person
dreamcraft.gui.quitmessage=Are you sure you want to exit the game ?

dreamcraft.welcome.welcome=Welcome to Gregtech: New Horizons
dreamcraft.welcome.questbook=The Quest Book has a shortcut key, check your keybindings.
dreamcraft.welcome.gtnh_wiki=GTNH WIKI link :
dreamcraft.welcome.click_wiki=Click to open the wiki!
dreamcraft.welcome.report_bug=Please report bugs on Github :
dreamcraft.welcome.click_github=Click to open the Github!
dreamcraft.welcome.visitdiscord=Visit our discord at
dreamcraft.welcome.click_discord=Click to open discord!

0 comments on commit af772e7

Please sign in to comment.