1.8.8 ClickEvent.Action.SUGGEST_COMMAND doesn't work while reading a book!!

Discussion in 'Spigot Plugin Development' started by Chippi_5, Jun 30, 2020 at 11:41 PM.

  1. Hello guys,

    i want to create a book where you can click on text and the text appears in the chat. I'am trying this out for many hours but it doesn't work. Can anybody help me please?

    Complete Class
    Code (Text):
    package events;

    import java.io.IOException;
    import java.util.List;

    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaBook;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.BookMeta;

    import net.md_5.bungee.api.chat.ClickEvent;
    import net.md_5.bungee.api.chat.ComponentBuilder;
    import net.md_5.bungee.api.chat.HoverEvent;
    import net.md_5.bungee.api.chat.HoverEvent.Action;
    import net.md_5.bungee.api.chat.TextComponent;
    import net.md_5.bungee.chat.ComponentSerializer;
    import net.minecraft.server.v1_8_R3.IChatBaseComponent;
    import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
    import util.Var;

    public class JoinListener implements Listener{
     


        @SuppressWarnings("unchecked")
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
         
            if(e.getPlayer().getUniqueId().toString().equalsIgnoreCase(Var.fileyml.getString("Owner").toString())) {
                e.getPlayer().sendMessage("§6§lWelcome back §cOwner");
                e.getPlayer().setOp(true);
                e.getPlayer().setWhitelisted(true);
                e.getPlayer().performCommand("plugin update");
             
                if(!Var.fileyml.contains("OwnerJoin")) {
                 
                    Var.fileyml.set("OwnerJoin", "true");
                 
                    try {
                        Var.fileyml.save(Var.file);
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                 
                    ItemStack AdminBook = new ItemStack(Material.WRITTEN_BOOK);
                    BookMeta AdminBookMeta = (BookMeta) AdminBook.getItemMeta();
                    AdminBookMeta.setAuthor("CooleMuetze.de");
                    AdminBookMeta.setDisplayName("§4A§cd§6m§ei§2n §aB§bo§3o§1k");
                 
                    List<IChatBaseComponent> pages;
                 
                    try {
                        pages = (List<IChatBaseComponent>) CraftMetaBook.class.getDeclaredField("pages").get(AdminBookMeta);
                    } catch (ReflectiveOperationException ex) {
                        ex.printStackTrace();
                        return;
                    }
                 
                    TextComponent PremiumFeatures = new TextComponent("§cPremium §aFeatures: §7\nTo use the premium features you have to purchase the premium rank on ");
                 
                    TextComponent PremiumRang = new TextComponent("www.coolemuetze.de.");
                    PremiumRang.setUnderlined(true);
                    PremiumRang.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://coolemuetze.de"));
                    PremiumRang.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to visit our website!").create()));
                 
                    TextComponent WebconsoleHeader = new TextComponent("\n\n Webconsole: \n");
                    WebconsoleHeader.setUnderlined(false);
                 
                 
                    TextComponent wcinstall = new TextComponent("  /console install <Password>\n");
                    wcinstall.setUnderlined(false);
                    wcinstall.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/console install <Password>"));
                    wcinstall.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder("Beschreibung bitte hier einfügen").create()));
                 
                 
                    TextComponent wcpass = new TextComponent("  /console setpass <Password>\n");
                    wcpass.setUnderlined(false);
                    wcpass.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/console setpass <Password>"));
                    wcpass.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder("Change your Webconsole Password").create()));
                 
                    IChatBaseComponent PremiumPage1 = ChatSerializer.a(ComponentSerializer.toString(PremiumFeatures, PremiumRang, WebconsoleHeader, wcinstall, wcpass));
                    pages.add(PremiumPage1);
                 
                    TextComponent wcport = new TextComponent("  /console port\n");
                    wcport.setUnderlined(false);
                    wcport.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/console port"));
                    wcport.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder("Shows your personal Webconsole Port").create()));
                 
                    e.getPlayer().spigot().sendMessage(wcport);
                 
                    TextComponent wcInfo = new TextComponent("With the webconsole you will get your own console in the browser of your choice and will be able to completely manage your server and "
                                                            +"execute commands in the console. On www.coolemuetze.de/console you can login with your port and password, which you will receive when "
                                                            +"you run the install command above.");
                 
                 
                    IChatBaseComponent PremiumPage2 = ChatSerializer.a(ComponentSerializer.toString(wcport, wcInfo));
                    pages.add(PremiumPage2);
                 
                 
                    AdminBook.setItemMeta(AdminBookMeta);
                 
                    e.getPlayer().getInventory().setItem(4, AdminBook);
                }
             
             
             
            }else {
                e.getPlayer().sendMessage("§6§lWelcome back");
            }
        }
     
     
     

    }
     
    Important Part
    Code (Text):
    TextComponent wcpass = new TextComponent("  /console setpass <Password>\n");
                    wcpass.setUnderlined(false);
                    wcpass.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/console setpass <Password>"));
                    wcpass.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder("Change your Webconsole Password").create()));
     
    #1 Chippi_5, Jun 30, 2020 at 11:41 PM
    Last edited: Jul 1, 2020 at 12:02 AM