use of net.minecraft.util.text.event.ClickEvent in project SpongeVanilla by SpongePowered.
the class ChatFormatter method format.
@Nullable
public static ITextComponent format(String s) {
Matcher matcher = URL_PATTERN.matcher(s);
if (!matcher.find()) {
return null;
}
ITextComponent result = null;
int pos = 0;
do {
int start = matcher.start();
int end = matcher.end();
String displayUrl = s.substring(start, end);
String url = displayUrl;
try {
if (new URI(url).getScheme() == null) {
url = DEFAULT_SCHEME + url;
}
} catch (URISyntaxException e) {
// Invalid URL so just ignore it
continue;
}
if (pos < start) {
if (result == null) {
result = new TextComponentString(s.substring(pos, start));
} else {
result.appendText(s.substring(pos, start));
}
}
pos = end;
ITextComponent link = new TextComponentString(displayUrl);
link.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
if (result == null) {
result = new TextComponentString("");
}
result.appendSibling(link);
} while (matcher.find());
// If there is something left, append the rest
if (pos < s.length()) {
if (result == null) {
result = new TextComponentString(s.substring(pos));
} else {
result.appendText(s.substring(pos));
}
}
return result;
}
use of net.minecraft.util.text.event.ClickEvent in project Cavern2 by kegare.
the class ClientEventHooks method onConnected.
@SubscribeEvent
public void onConnected(ClientConnectedToServerEvent event) {
Minecraft mc = FMLClientHandler.instance().getClient();
if (GeneralConfig.versionNotify) {
ITextComponent message;
ITextComponent name = new TextComponentString(Cavern.metadata.name);
name.getStyle().setColor(TextFormatting.AQUA);
if (Version.isOutdated()) {
ITextComponent latest = new TextComponentString(Version.getLatest().toString());
latest.getStyle().setColor(TextFormatting.YELLOW);
message = new TextComponentTranslation("cavern.version.message", name);
message.appendText(" : ").appendSibling(latest);
message.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Cavern.metadata.url));
mc.ingameGUI.getChatGUI().printChatMessage(message);
}
message = null;
if (Version.DEV_DEBUG) {
message = new TextComponentTranslation("cavern.version.message.dev", name);
} else if (Version.isBeta()) {
message = new TextComponentTranslation("cavern.version.message.beta", name);
} else if (Version.isAlpha()) {
message = new TextComponentTranslation("cavern.version.message.alpha", name);
}
if (message != null) {
mc.ingameGUI.getChatGUI().printChatMessage(message);
}
}
}
use of net.minecraft.util.text.event.ClickEvent in project HorsePower by GoryMoon.
the class Utils method sendSavedErrors.
public static void sendSavedErrors() {
if (FMLCommonHandler.instance().getSide().isClient() && FMLClientHandler.instance().getClientPlayerEntity() != null && HPRecipes.ERRORS.size() > 0) {
FMLClientHandler.instance().getClientPlayerEntity().sendMessage(new TextComponentString(TextFormatting.RED + "" + TextFormatting.BOLD + "HorsePower config errors"));
FMLClientHandler.instance().getClientPlayerEntity().sendMessage(new TextComponentString(TextFormatting.RED + "" + TextFormatting.BOLD + "-----------------------------------------"));
HPRecipes.ERRORS.forEach(s -> FMLClientHandler.instance().getClientPlayerEntity().sendMessage(new TextComponentString(TextFormatting.RED + s).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, Loader.instance().getConfigDir() + "/horsepower.cfg")).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Changed in in-game config or click to open the config file to fix this"))))));
FMLClientHandler.instance().getClientPlayerEntity().sendMessage(new TextComponentString(TextFormatting.RED + "" + TextFormatting.BOLD + "-----------------------------------------"));
HPRecipes.ERRORS.clear();
}
}
use of net.minecraft.util.text.event.ClickEvent in project GregTech by GregTechCE.
the class AdvancedTextWidget method handleCustomComponentClick.
@SideOnly(Side.CLIENT)
private boolean handleCustomComponentClick(ITextComponent textComponent) {
Style style = textComponent.getStyle();
if (style.getClickEvent() != null) {
ClickEvent clickEvent = style.getClickEvent();
String componentText = clickEvent.getValue();
if (clickEvent.getAction() == Action.OPEN_URL && componentText.startsWith("@!")) {
String rawText = componentText.substring(2);
ClickData clickData = new ClickData(Mouse.getEventButton(), isShiftDown(), isCtrlDown());
writeClientAction(1, buf -> {
clickData.writeToBuf(buf);
buf.writeString(rawText);
});
return true;
}
}
return false;
}
use of net.minecraft.util.text.event.ClickEvent in project minecolonies by Minecolonies.
the class WindowTownHall method teleportToColony.
/**
* On Button click teleport to the colony..
*
* @param button the clicked button.
*/
private void teleportToColony(@NotNull final Button button) {
final int row = alliesList.getListElementIndexByPane(button);
final ColonyView ally = allies.get(row);
final ITextComponent teleport = new TextComponentString(LanguageHandler.format(DO_REALLY_WANNA_TP, ally.getName())).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, TELEPORT_COMMAND + ally.getID())));
Minecraft.getMinecraft().player.sendMessage(teleport);
}
Aggregations