use of net.minecraft.util.text.ITextComponent in project RecurrentComplex by Ivorforce.
the class CommandListStructures method showList.
public static void showList(ICommandSender commandSender, int page, List<String> structureNames) {
int startIndex = page * RESULTS_PER_PAGE;
int endIndex = Math.min((page + 1) * RESULTS_PER_PAGE, structureNames.size());
if (endIndex - startIndex > 0) {
List<ITextComponent> components = new ArrayList<>(endIndex - startIndex + 2);
components.add(new TextComponentString("[<--]"));
if (page > 0)
linkToPage(components.get(0), page - 1, RecurrentComplex.translations.format("commands.rclist.previous"));
for (int i = 0; i < endIndex - startIndex; i++) components.add(RCTextStyle.structure(structureNames.get(startIndex + i)));
components.add(new TextComponentString("[-->]"));
if (page < (structureNames.size() - 1) / RESULTS_PER_PAGE)
linkToPage(components.get(components.size() - 1), page + 1, RecurrentComplex.translations.format("commands.rclist.next"));
commandSender.sendMessage(ServerTranslations.join(components));
} else
commandSender.sendMessage(RecurrentComplex.translations.get("commands.rclist.none"));
}
use of net.minecraft.util.text.ITextComponent in project RecurrentComplex by Ivorforce.
the class CommandLookupStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
String id = parameters.get(0).require();
GenericStructure structure = parameters.get(0).to(p -> RCP.genericStructure(p, false)).require();
Metadata metadata = structure.metadata;
boolean hasWeblink = !metadata.weblink.trim().isEmpty();
ITextComponent weblink = hasWeblink ? new TextComponentString(RCStrings.abbreviateFormatted(metadata.weblink, 30)) : RecurrentComplex.translations.format("commands.rclookup.reply.nolink");
if (hasWeblink) {
weblink.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, metadata.weblink));
weblink.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(metadata.weblink)));
}
ITextComponent level = new TextComponentString(StructureRegistry.INSTANCE.status(id).getLevel().toString());
level.getStyle().setColor(TextFormatting.YELLOW);
commandSender.sendMessage(RecurrentComplex.translations.format(StructureRegistry.INSTANCE.hasActive(id) ? "commands.rclookup.reply.generates" : "commands.rclookup.reply.silent", id, RCTextStyle.users(metadata.authors), level, weblink));
if (!metadata.comment.trim().isEmpty())
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rclookup.reply.comment", metadata.comment));
}
use of net.minecraft.util.text.ITextComponent in project RecurrentComplex by Ivorforce.
the class RCForgeEventHandler method onPlayerJoin.
@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
if (RCConfig.postWorldStatus && event.player.canUseCommand(3, "op")) {
WorldRandomData randomData = WorldRandomData.get(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld());
if (randomData.postWorldStatus(event.player.getName())) {
event.player.getServer().commandManager.executeCommand(event.player, RCCommands.sanity.getName() + " --silent --short");
ITextComponent count = new TextComponentString("" + StructureRegistry.INSTANCE.activeIDs().size());
count.getStyle().setColor(TextFormatting.AQUA);
ITextComponent list = new TextComponentString("[List]");
list.getStyle().setColor(TextFormatting.AQUA);
list.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Show List")));
list.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/%s", RCCommands.structures.list())));
ITextComponent add = new TextComponentString("[Add]");
add.getStyle().setColor(TextFormatting.GREEN);
add.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Browse Repository")));
add.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Repository.browseURL()));
ITextComponent remove = new TextComponentString("[Remove]");
remove.getStyle().setColor(TextFormatting.RED);
remove.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Disabling Structures")));
remove.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Wiki.DISABLING_STRUCTURES));
ITextComponent help = new TextComponentString("[Help]");
help.getStyle().setColor(TextFormatting.AQUA);
help.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Open Wiki")));
help.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Wiki.HOME));
ITextComponent statusMessage = RecurrentComplex.translations.format("reccomplex.server.status", count, list, add, remove, help);
event.player.sendMessage(statusMessage);
}
}
}
use of net.minecraft.util.text.ITextComponent in project RecurrentComplex by Ivorforce.
the class OperationRegistry method queueOperation.
public static boolean queueOperation(Operation operation, ICommandSender commandSender) throws CommandException {
if (operation.checkDead(commandSender))
return false;
boolean instant = true;
if (commandSender instanceof EntityPlayer) {
EntityPlayer player = CommandBase.getCommandSenderAsPlayer(commandSender);
RCEntityInfo info = RCEntityInfo.get(player, null);
if (info != null) {
if (info.getPreviewType() != Operation.PreviewType.NONE) {
info.queueOperation(operation, player);
instant = false;
ITextComponent confirmComponent = new TextComponentString("/" + RCCommands.confirm.getName());
confirmComponent.getStyle().setColor(TextFormatting.GREEN);
confirmComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + RCCommands.confirm.getName()));
confirmComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, RecurrentComplex.translations.get("commands.rcconfirm.run")));
ITextComponent cancelComponent = new TextComponentString("/" + RCCommands.cancel.getName());
cancelComponent.getStyle().setColor(TextFormatting.RED);
cancelComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + RCCommands.cancel.getName()));
cancelComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, RecurrentComplex.translations.get("commands.rccancel.run")));
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rc.queuedOp", confirmComponent, cancelComponent));
}
}
}
if (instant)
operation.perform((WorldServer) commandSender.getEntityWorld());
return true;
}
use of net.minecraft.util.text.ITextComponent in project MinecraftForge by MinecraftForge.
the class ForgeHooks method newChatWithLinks.
public static ITextComponent newChatWithLinks(String string, boolean allowMissingHeader) {
// Includes ipv4 and domain pattern
// Matches an ip (xx.xxx.xx.xxx) or a domain (something.com) with or
// without a protocol or path.
ITextComponent ichat = null;
Matcher matcher = URL_PATTERN.matcher(string);
int lastEnd = 0;
// Find all urls
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
// Append the previous left overs.
String part = string.substring(lastEnd, start);
if (part.length() > 0) {
if (ichat == null)
ichat = new TextComponentString(part);
else
ichat.appendText(part);
}
lastEnd = end;
String url = string.substring(start, end);
ITextComponent link = new TextComponentString(url);
try {
// Add schema so client doesn't crash.
if ((new URI(url)).getScheme() == null) {
if (!allowMissingHeader) {
if (ichat == null)
ichat = new TextComponentString(url);
else
ichat.appendText(url);
continue;
}
url = "http://" + url;
}
} catch (URISyntaxException e) {
// Bad syntax bail out!
if (ichat == null)
ichat = new TextComponentString(url);
else
ichat.appendText(url);
continue;
}
// Set the click event and append the link.
ClickEvent click = new ClickEvent(ClickEvent.Action.OPEN_URL, url);
link.getStyle().setClickEvent(click);
link.getStyle().setUnderlined(true);
link.getStyle().setColor(TextFormatting.BLUE);
if (ichat == null)
ichat = link;
else
ichat.appendSibling(link);
}
// Append the rest of the message.
String end = string.substring(lastEnd);
if (ichat == null)
ichat = new TextComponentString(end);
else if (end.length() > 0)
ichat.appendText(string.substring(lastEnd));
return ichat;
}
Aggregations