@SubscribeEvent public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event){ if(DifficultyManager.enabled && ProgressiveDifficulty.oldConfigExists){ TextComponentString linkComponent = new TextComponentString("[Progressive Difficulty Wiki]"); ITextComponent[] chats = new ITextComponent[]{ new TextComponentString("[ProgressiveDifficulty] It looks like you have a version 1.0 " + "config file. Please check out the Progressive Difficulty Wiki for instructions on how" + " to migrate to a version 2.0 config file."), linkComponent }; ClickEvent goLinkEvent = new ClickEvent(ClickEvent.Action.OPEN_URL,"https://github.com/talandar/ProgressiveDifficulty/wiki/2.0-Transition"); linkComponent.getStyle().setClickEvent(goLinkEvent); linkComponent.getStyle().setColor(TextFormatting.BLUE); linkComponent.getStyle().setUnderlined(true); ChatUtil.sendChat(event.player,chats); } }
@Override public boolean mouseClicked(int mouseX, int mouseY, int y, int virtualWidth) { ITextComponent hoveredComponent = getHoveredComponent(virtualWidth, y, mouseX, mouseY); if (hoveredComponent != null) { ClickEvent clickEvent = hoveredComponent.getStyle().getClickEvent(); if (clickEvent != null && clickEvent.getAction() == ClickEvent.Action.CHANGE_PAGE) { String value = clickEvent.getValue(); String name = null; if (value.contains("=")) { int equalsIndex = value.indexOf('='); name = value.substring(0, equalsIndex); value = value.substring(equalsIndex + 1); } CommandHelpManager.getInstance().displayHelpScreen(name, value); return true; } else { return GeneralUtils.handleClickEvent(clickEvent); } } else return false; }
private void notifyUser(VersionData data, UpdateResponse response) { ITextBuilder builder = new TextBuilder() .translation("update.available") .text(data.getName()) .format(TextFormatting.GOLD) .end() .text(" "); if (data.getUrl() != null) builder.translation("update.clickhere").end() .format(TextFormatting.LIGHT_PURPLE) .click(new ClickEvent(ClickEvent.Action.OPEN_URL, data.getUrl())) .text(". "); ITextComponent msg = builder .text(response.minecraft.version) .text(" - ") .text(response.minecraft.changes) .build(); LogManager.getLogger("Updates").info(msg.getUnformattedText()); this.chatProxy.addToChat("Updates", msg); }
private static ITextComponent makeChat(boolean tag) { ITextComponent chat = new TextComponentString(tag ? "[test] " : ""); chat.getStyle().setBold(true); { ITextComponent colored = new TextComponentString("This should be green. "); colored.getStyle().setColor(TextFormatting.GREEN); chat.appendSibling(colored); } chat.appendText(" "); { ITextComponent link = new TextComponentString("This is a link."); link.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "http://google.com/")); chat.appendSibling(link); } return chat; }
/** * Appends a string with the specified color(s) and an event * triggered on text click and on text hover. Only one actual * color should be specified, any other {@code TextFormatting} * type should be styling. (Bold, Italic, Underline, Strikethrough, * and Obfuscated) * * @param text The string being appended * @param clickEvent Click event to be used * @param hoverEvent Hover event to be used * @param colors Color formatting * @return This builder */ public final ChatBuilder append(String text, @Nullable ClickEvent clickEvent, @Nullable HoverEvent hoverEvent, TextFormatting... colors) { TextComponentString component = new TextComponentString(text); Style style = component.getStyle(); Arrays.stream(colors).forEach(color -> { switch (color) { case BOLD: { style.setBold(true); break; } case ITALIC: { style.setItalic(true); break; } case UNDERLINE: { style.setUnderlined(true); break; } case STRIKETHROUGH: { style.setStrikethrough(true); break; } case OBFUSCATED: { style.setObfuscated(true); break; } default: { style.setColor(color); break; } } }); // noinspection ConstantConditions style.setClickEvent(clickEvent).setHoverEvent(hoverEvent); this.component.appendSibling(component); return this; }
@Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); int info2Start = (this.height / 2) - 50; if (orderPressed && !isSure && mouseY >= info2Start && mouseY <= info2Start + fontRendererObj.FONT_HEIGHT) { ITextComponent comp = getComponent(mouseX, mouseY); ClickEvent clickevent = comp.getStyle().getClickEvent(); if (clickevent != null && clickevent.getAction() == ClickEvent.Action.OPEN_URL) { try { URI uri = new URI(clickevent.getValue()); Class<?> oclass = Class.forName("java.awt.Desktop"); Object object = oclass.getMethod("getDesktop").invoke(null); oclass.getMethod("browse", URI.class).invoke(object, uri); } catch (Throwable t) { CreeperHost.logger.error("Can\'t open url for " + clickevent, t); } return; } } for (TextFieldDetails field : this.fields) { field.myMouseClicked(mouseX, mouseY, mouseButton); } }
public static ITextComponent addURLClick(ITextComponent component, String url) { Style s = component.getStyle(); s.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)); component.setStyle(s); return component; }
/** * Get the formatted ChatComponent that will be used for the sender's username in chat */ public ITextComponent getDisplayName() { ITextComponent itextcomponent = new TextComponentString(ScorePlayerTeam.formatPlayerName(this.getTeam(), this.getName())); itextcomponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + this.getName() + " ")); itextcomponent.getStyle().setHoverEvent(this.getHoverEvent()); itextcomponent.getStyle().setInsertion(this.getName()); return itextcomponent; }
@Nullable /** * The effective chat click event. */ public ClickEvent getClickEvent() { return this.clickEvent == null ? this.getParent().getClickEvent() : this.clickEvent; }
/** * Get the formatted ChatComponent that will be used for the sender's username in chat */ public ITextComponent getDisplayName() { ITextComponent itextcomponent = new TextComponentString(""); if (!prefixes.isEmpty()) for (ITextComponent prefix : prefixes) itextcomponent.appendSibling(prefix); itextcomponent.appendSibling(new TextComponentString(ScorePlayerTeam.formatPlayerName(this.getTeam(), this.getDisplayNameString()))); if (!suffixes.isEmpty()) for (ITextComponent suffix : suffixes) itextcomponent.appendSibling(suffix); itextcomponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + this.getName() + " ")); itextcomponent.getStyle().setHoverEvent(this.getHoverEvent()); itextcomponent.getStyle().setInsertion(this.getName()); return itextcomponent; }
/** * Send record message to the player */ private void sendRecordMessage() { EntityPlayer player = this.mc.thePlayer; if (this.filename.getText().isEmpty()) { L10n.error(player, "recording.fill_filename"); return; } String command = "/action record " + this.filename.getText() + " " + this.pos.getX() + " " + this.pos.getY() + " " + this.pos.getZ(); ITextComponent component = new TextComponentString(stringClickhere); component.getStyle().setClickEvent(new ClickEvent(Action.RUN_COMMAND, command)); component.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(command))); component.getStyle().setColor(TextFormatting.GRAY).setUnderlined(true); L10n.info(player, "recording.message", this.filename.getText(), component); /* Add the command to the history */ List<String> messages = this.mc.ingameGUI.getChatGUI().getSentMessages(); boolean empty = messages.isEmpty(); boolean lastMessageIsntCommand = !empty && !messages.get(messages.size() - 1).equals(command); if (lastMessageIsntCommand || empty) { messages.add(command); } }
@SideOnly(Side.CLIENT) @Override protected void climsg(EntityPlayer p) { final TextComponentTranslation tt = new TextComponentTranslation("mcflux.update.newversion", version); tt.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, R.MF_URL)); p.sendMessage(tt); }
/** * Executes the click event specified by the given chat component */ protected boolean handleComponentClick(ITextComponent component) { ClickEvent clickevent = component.getStyle().getClickEvent(); if (clickevent == null) { return false; } else if (clickevent.getAction() == ClickEvent.Action.CHANGE_PAGE) { String s = clickevent.getValue(); try { int i = Integer.parseInt(s) - 1; if (i >= 0 && i < this.bookTotalPages && i != this.currPage) { this.currPage = i; this.updateButtons(); return true; } } catch (Throwable var5) { ; } return false; } else { boolean flag = super.handleComponentClick(component); if (flag && clickevent.getAction() == ClickEvent.Action.RUN_COMMAND) { this.mc.displayGuiScreen((GuiScreen)null); } return flag; } }
@Override public String execute(CommandSender sender, String[] params) throws CommandException { DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); ITextComponent textModid = new TextComponentString("MODID: ").setStyle(new Style().setColor(TextFormatting.DARK_AQUA)); ITextComponent modid = new TextComponentString(Reference.MODID).setStyle(new Style().setColor(TextFormatting.GREEN)); ITextComponent textVersion = new TextComponentString("VERSION: ").setStyle(new Style().setColor(TextFormatting.DARK_AQUA)); ITextComponent version = new TextComponentString(Reference.VERSION).setStyle(new Style().setColor(TextFormatting.GREEN)); ITextComponent textName = new TextComponentString("NAME: ").setStyle(new Style().setColor(TextFormatting.DARK_AQUA)); ITextComponent name = new TextComponentString(Reference.NAME).setStyle(new Style().setColor(TextFormatting.GREEN)); ITextComponent textModDir = new TextComponentString("MOD_DIR: ").setStyle(new Style().setColor(TextFormatting.DARK_AQUA)); ITextComponent modDir = new TextComponentString(Reference.getModDir().getPath()).setStyle(new Style().setColor(TextFormatting.GREEN)); ITextComponent textBuildDate = new TextComponentString("BUILD_DATE: ").setStyle(new Style().setColor(TextFormatting.DARK_AQUA)); ITextComponent builDate = new TextComponentString(df.format(Reference.BUILD)).setStyle(new Style().setColor(TextFormatting.GREEN)); ITextComponent textWebsite = new TextComponentString("WEBSITE ").setStyle(new Style().setColor(TextFormatting.DARK_AQUA)); ITextComponent website = new TextComponentString(Reference.WEBSITE).setStyle(new Style().setColor(TextFormatting.GREEN).setUnderlined(true).setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Reference.WEBSITE))); sender.sendChatComponent(textModid.appendSibling(modid)); sender.sendChatComponent(textVersion.appendSibling(version)); sender.sendChatComponent(textName.appendSibling(name)); sender.sendChatComponent(textModDir.appendSibling(modDir)); sender.sendChatComponent(textBuildDate.appendSibling(builDate)); sender.sendChatComponent(textWebsite.appendSibling(website)); return null; }
/** * Starts a thread looking for MoreCommands updates */ private void findMoreCommandsUpdates() { this.mod.getLogger().info("Searching for MoreCommands updates"); new Thread(new MoreCommandsUpdater(Loader.MC_VERSION, new MoreCommandsUpdater.UpdateCallback() { @Override public void udpate(String version, String website, String download) { TextComponentString text = new TextComponentString(Reference.VERSION.equals(version) ? "MoreCommands update for this version found " : "new MoreCommands version found: "); text.getStyle().setColor(TextFormatting.BLUE); TextComponentString downloadVersion = new TextComponentString(version); downloadVersion.getStyle().setColor(TextFormatting.YELLOW); TextComponentString homepage = new TextComponentString("Minecraft Forum"); homepage.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, website)).setColor(TextFormatting.GREEN).setItalic(true).setUnderlined(true); TextComponentString downloadPage = new TextComponentString("Download"); downloadPage.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, download)).setColor(TextFormatting.GREEN).setItalic(true).setUnderlined(true); TextComponentString comma = new TextComponentString(", "); comma.getStyle().setColor(TextFormatting.DARK_GRAY); TextComponentString sep = new TextComponentString(" - "); sep.getStyle().setColor(TextFormatting.DARK_GRAY); String rawText = text.getUnformattedText() + (Reference.VERSION.equals(version) ? "" : downloadVersion.getUnformattedText()) + " - " + website + ", " + download; if (!Reference.VERSION.equals(version)) text.appendSibling(downloadVersion); text.appendSibling(sep).appendSibling(homepage).appendSibling(comma).appendSibling(downloadPage); CommonProxy.this.mod.getLogger().info(rawText); CommonProxy.this.updateText = text; if (MoreCommands.isClientSide() && net.minecraft.client.Minecraft.getMinecraft().player != null) { CommonProxy.this.playerNotified = true; net.minecraft.client.Minecraft.getMinecraft().player.sendMessage(text); } } }), "MoreCommands Update Thread").start(); }
@Override public boolean processCommand(ICommandSender sender, String[] parameters) throws CommandException { List list = this.getSortedPossibleCommands(sender); byte b0 = 7; int i = (list.size() - 1) / b0; boolean flag = false; int k; try { k = parameters.length == 0 ? 0 : net.minecraft.command.CommandBase.parseInt(parameters[0], 1, i + 1) - 1; } catch (NumberInvalidException numberinvalidexception) { Map map = this.getCommands(); AbstractCommand icommand = (AbstractCommand) map.get(parameters[0]); if (icommand != null) { CommandManager.throwError(sender, icommand); return true; } if (MathHelper.parseIntWithDefault(parameters[0], -1) != -1) { throw numberinvalidexception; } throw new CommandNotFoundException(); } int j = Math.min((k + 1) * b0, list.size()); TextComponentTranslation chatcomponenttranslation1 = new TextComponentTranslation("crafting.commands.help.header", new Object[] { Integer.valueOf(k + 1), Integer.valueOf(i + 1) }); chatcomponenttranslation1.getStyle().setColor(TextFormatting.DARK_GREEN); sender.addChatMessage(chatcomponenttranslation1); for (int l = k * b0; l < j; ++l) { AbstractCommand icommand1 = (AbstractCommand) list.get(l); TextComponentTranslation chatcomponenttranslation = new TextComponentTranslation(CommandManager.getUsage(icommand1), new Object[0]); chatcomponenttranslation.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + icommand1.getCommandName() + " ")); sender.addChatMessage(chatcomponenttranslation); } return true; }
@Override public boolean mouseClicked(int mouseX, int mouseY, int y, int virtualWidth) { if (clickEvent != null) { String str = TextFormatting.RED + "No image found at " + location; int imageLeft, imageRight, imageBottom; if (theImage == null) { imageLeft = virtualWidth / 2 - fontRenderer.getStringWidth(str) / 2; imageRight = imageLeft + fontRenderer.getStringWidth(str); imageBottom = y + fontRenderer.FONT_HEIGHT; } else { imageLeft = virtualWidth / 2 - viewportWidth / 2; imageRight = imageLeft + viewportWidth; imageBottom = y + viewportHeight; } if (mouseX >= imageLeft && mouseX < imageRight && mouseY >= y && mouseY < imageBottom) { if (clickEvent.getAction() == ClickEvent.Action.CHANGE_PAGE) { String value = clickEvent.getValue(); String name = null; if (value.contains("=")) { int equalsIndex = value.indexOf('='); name = value.substring(0, equalsIndex); value = value.substring(equalsIndex + 1); } CommandHelpManager.getInstance().displayHelpScreen(name, value); return true; } else { return GeneralUtils.handleClickEvent(clickEvent); } } } return false; }
/** * Creates a url chat component. * * @param separateMessages boolean flag to separate by commas and space. * @param url String url to use. * @param maskURL String url mask. * @param messages Messages. * @return IChatComponent. */ public static ITextComponent createURLComponent(boolean separateMessages, String url, String maskURL, String... messages) { if (!StringUtils.nullCheckString(url) || !StringUtils.contains(url, '.')) throw new NullPointerException("URL doesn't exist!"); ITextComponent comp = createComponent(separateMessages, messages); comp.appendText(" " + (StringUtils.nullCheckString(maskURL) ? maskURL : url)); comp.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)); return comp; }
/** * Creates a command chat component. * * @param separateMessages boolean flag to separate by commas and space. * @param command HCommand to use. * @param messages Messages. * @return IChatComponent. */ public static ITextComponent createCmdComponent(boolean separateMessages, HCommand command, String... messages) { if (command == null) return createComponent(false, "<Invalid command>"); ITextComponent comp = createComponent(separateMessages, messages); comp.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.getUsage(null))); return comp; }
/** * Creates a file chat component. * * @param separateMessages boolean flag to separate by commas and space. * @param file File to open. * @param messages Messages. * @return IChatComponent. */ public static ITextComponent createFileComponent(boolean separateMessages, File file, String... messages) { if (file == null || !file.exists()) return createComponent(false, "<missing file>"); ITextComponent comp = createComponent(separateMessages, messages); comp.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath())); return comp; }
@SubscribeEvent public static void playerDeath(LivingDeathEvent event) { if (event.getEntityLiving() instanceof EntityPlayer && printDeathCoords) { TextComponentString posText = new TextComponentString("X: " + MathHelper.floor(event.getEntityLiving().posX) + " Y: " + MathHelper.floor(event.getEntityLiving().posY + 0.5d) + " Z: " + MathHelper.floor(event.getEntityLiving().posZ)); try { MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); if (server.getCommandManager().getPossibleCommands(event.getEntityLiving()).contains(server.getCommandManager().getCommands().get("tp"))) { posText.setStyle(new Style().setItalic(true) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to teleport!"))) .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tp " + MathHelper.floor(event.getEntityLiving().posX) + " " + MathHelper.floor(event.getEntityLiving().posY + 0.5d) + " " + MathHelper.floor(event.getEntityLiving().posZ)))); } if (server.getCommandManager().getPossibleCommands(event.getEntityLiving()).contains(server.getCommandManager().getCommands().get("tpx"))) { posText.setStyle(new Style().setItalic(true) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to teleport!"))) .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpx " + ((EntityPlayer) event.getEntityLiving()).dimension + " " + MathHelper.floor(event.getEntityLiving().posX) + " " + MathHelper.floor(event.getEntityLiving().posY + 0.5d) + " " + MathHelper.floor(event.getEntityLiving().posZ)))); } } catch (Exception ignored) { } event.getEntityLiving().sendMessage(new TextComponentString("You died at ").setStyle(new Style().setColor(TextFormatting.AQUA)).appendSibling(posText)); } }
public static void printFileLink(String msg, File file) { TextComponentTranslation text = new TextComponentTranslation(file.getName()); String path; try { path = file.getAbsoluteFile().getCanonicalPath(); } catch (IOException ex) { path = file.getAbsolutePath(); } text.getStyle().setClickEvent(new ClickEvent(OPEN_FILE, path)); text.getStyle().setUnderlined(true); print(msg, text); }
public static void notifyUpdateDone(){ ICommandSender sender = getSender(); if(verbose && sender != null){ sender.sendMessage(new TextComponentString( TextFormatting.YELLOW + I18n.format("mud.name") + TextFormatting.WHITE + ": "+I18n.format("message.check.done") )); } int outOfDateCount = 0; int failedCount = 0; for(UpdateEntry e : updateMap.values()){ try { if(!e.isUpToDate()){ outOfDateCount ++; } } catch (Exception e1) { failedCount++; } } TextComponentTranslation chat; if(outOfDateCount > 0){ if(sender != null){ chat = new TextComponentTranslation("message.you.have.outdated", outOfDateCount); chat.getStyle().setColor(TextFormatting.RED); sender.sendMessage(chat); chat = new TextComponentTranslation("message.type.to.view"); chat.getStyle().setColor(TextFormatting.RED).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mud")); sender.sendMessage(chat); } }else if (verbose){ if(sender != null){ chat = new TextComponentTranslation("message.up.to.date"); chat.getStyle().setColor(TextFormatting.DARK_GREEN); sender.sendMessage(chat); } } hasChecked = true; }
private void saveFile() { step = Step.values()[step.ordinal() + 1]; new Thread(() -> { JsonObject json = new JsonObject(); // get facings EnumFacing front = EnumFacing.getHorizontal(4 - WMinecraft .getPlayer().getHorizontalFacing().getHorizontalIndex()); EnumFacing left = front.rotateYCCW(); // add sorted blocks JsonArray jsonBlocks = new JsonArray(); for(BlockPos pos : template.sortedBlocks) { // translate pos = pos.subtract(Step.FIRST_BLOCK.pos); // rotate pos = new BlockPos(0, pos.getY(), 0).offset(front, pos.getZ()) .offset(left, pos.getX()); // add to json jsonBlocks.add(JsonUtils.gson.toJsonTree( new int[]{pos.getX(), pos.getY(), pos.getZ()}, int[].class)); } json.add("blocks", jsonBlocks); try(PrintWriter save = new PrintWriter(new FileWriter(file))) { // save file save.print(JsonUtils.prettyGson.toJson(json)); // show success message TextComponentString message = new TextComponentString("Saved template as "); TextComponentString link = new TextComponentString(file.getName()); ClickEvent event = new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getParentFile().getAbsolutePath()); link.getStyle().setUnderlined(true).setClickEvent(event); message.appendSibling(link); ChatUtils.component(message); }catch(IOException e) { e.printStackTrace(); // show error message ChatUtils.error("File could not be saved."); } // update AutoBuild wurst.mods.autoBuildMod.loadTemplates(); // disable TemplateTool setEnabled(false); }, "TemplateTool").start(); }
@Nullable public ClickEvent getClickEvent() { return null; }
public Style setClickEvent(ClickEvent event) { throw new UnsupportedOperationException(); }
/** * Sets the event that should be run when text of this ChatStyle is clicked on. */ public Style setClickEvent(ClickEvent event) { this.clickEvent = event; return this; }
public boolean executeCommand(final EntityPlayer playerIn) { ICommandSender icommandsender = new ICommandSender() { public String getName() { return playerIn.getName(); } public ITextComponent getDisplayName() { return playerIn.getDisplayName(); } public void addChatMessage(ITextComponent component) { } public boolean canCommandSenderUseCommand(int permLevel, String commandName) { return permLevel <= 2; } public BlockPos getPosition() { return TileEntitySign.this.pos; } public Vec3d getPositionVector() { return new Vec3d((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D); } public World getEntityWorld() { return playerIn.getEntityWorld(); } public Entity getCommandSenderEntity() { return playerIn; } public boolean sendCommandFeedback() { return false; } public void setCommandStat(CommandResultStats.Type type, int amount) { if (TileEntitySign.this.world != null && !TileEntitySign.this.world.isRemote) { TileEntitySign.this.stats.setCommandStatForSender(TileEntitySign.this.world.getMinecraftServer(), this, type, amount); } } public MinecraftServer getServer() { return playerIn.getServer(); } }; for (ITextComponent itextcomponent : this.signText) { Style style = itextcomponent == null ? null : itextcomponent.getStyle(); if (style != null && style.getClickEvent() != null) { ClickEvent clickevent = style.getClickEvent(); if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND) { playerIn.getServer().getCommandManager().executeCommand(icommandsender, clickevent.getValue()); } } } return true; }
/** * Callback for when the command is executed */ public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (sender instanceof CommandBlockBaseLogic) { sender.addChatMessage((new TextComponentString("Searge says: ")).appendText(seargeSays[this.rand.nextInt(seargeSays.length) % seargeSays.length])); } else { List<ICommand> list = this.getSortedPossibleCommands(sender, server); int i = 7; int j = (list.size() - 1) / 7; int k = 0; try { k = args.length == 0 ? 0 : parseInt(args[0], 1, j + 1) - 1; } catch (NumberInvalidException numberinvalidexception) { Map<String, ICommand> map = this.getCommandMap(server); ICommand icommand = (ICommand)map.get(args[0]); if (icommand != null) { throw new WrongUsageException(icommand.getCommandUsage(sender), new Object[0]); } if (MathHelper.getInt(args[0], -1) == -1 && MathHelper.getInt(args[0], -2) == -2) { throw new CommandNotFoundException(); } throw numberinvalidexception; } int l = Math.min((k + 1) * 7, list.size()); TextComponentTranslation textcomponenttranslation1 = new TextComponentTranslation("commands.help.header", new Object[] {Integer.valueOf(k + 1), Integer.valueOf(j + 1)}); textcomponenttranslation1.getStyle().setColor(TextFormatting.DARK_GREEN); sender.addChatMessage(textcomponenttranslation1); for (int i1 = k * 7; i1 < l; ++i1) { ICommand icommand1 = (ICommand)list.get(i1); TextComponentTranslation textcomponenttranslation = new TextComponentTranslation(icommand1.getCommandUsage(sender), new Object[0]); textcomponenttranslation.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + icommand1.getCommandName() + " ")); sender.addChatMessage(textcomponenttranslation); } if (k == 0) { TextComponentTranslation textcomponenttranslation2 = new TextComponentTranslation("commands.help.footer", new Object[0]); textcomponenttranslation2.getStyle().setColor(TextFormatting.GREEN); sender.addChatMessage(textcomponenttranslation2); } } }
public void activate(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if(player.isSneaking()) { if(Prep1_11.isEmpty(heldItem)) { if(hasEnchItem()) { if(!world.isRemote) { world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), mainHandler.getStackInSlot(SLOT_ENCH_ITEM))); } mainHandler.setStackInSlot(SLOT_ENCH_ITEM, null); mode = Mode.NONE; pendingIngredients.clear(); markDirty(); world.notifyBlockUpdate(pos, state, state, 8); } else if(world.isRemote) { ITextComponent link1 = new TextComponentString("Infusion Repair"); link1.setStyle(new Style().setBold(true).setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/einsteinsci/betterbeginnings/wiki/Infusion-Repair"))); ITextComponent link2 = new TextComponentString("Enchantment Diffusion"); link2.setStyle(new Style().setBold(true).setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/einsteinsci/betterbeginnings/wiki/Enchantment-Diffusion"))); ITextComponent message = new TextComponentString("See the BB wiki articles on "); message.appendSibling(link1); player.sendMessage(message); player.sendMessage(new TextComponentString("and ").appendSibling(link2)); } } } else { if(Prep1_11.isEmpty(heldItem) || hasEnchItem() || mode != Mode.NONE) return; if(heldItem.getItem() == RegisterItems.cloth) { mode = Mode.DIFFUSION; } else if(heldItem.isItemEnchanted()) { if(heldItem.getEnchantmentTagList().tagCount() > 8) { player.sendMessage(new TextComponentTranslation("diffusion.toomanyenchants")); mode = Mode.NONE; return; } mode = Mode.REPAIR; pendingIngredients.clear(); pendingIngredients.addAll(InfusionRepairUtil.getRequiredStacks(heldItem)); xpLevelsNeeded = InfusionRepairUtil.getTakenLevels(heldItem); markDirty(); } else return; ItemStack newStack = heldItem.copy(); newStack.setCount(1); mainHandler.setStackInSlot(heldItem.isItemEnchanted() ? SLOT_ENCH_ITEM : 1, newStack); heldItem.shrink(1); } }
/** * The effective chat click event. */ @Nullable public ClickEvent getClickEvent() { return null; }
/** * Sets the event that should be run when text of this ChatStyle is clicked on. */ public Style setClickEvent(ClickEvent event) { throw new UnsupportedOperationException(); }
/** * The effective chat click event. */ @Nullable public ClickEvent getClickEvent() { return this.clickEvent == null ? this.getParent().getClickEvent() : this.clickEvent; }