Solved JSON clickenvent

Discussion in 'Plugin Development' started by Badwolf330, Oct 5, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Badwolf330

    Code:
    package nl.eftelingcore.skyrob;
    
    import net.minecraft.server.v1_7_R4.ChatSerializer;
    import net.minecraft.server.v1_7_R4.IChatBaseComponent;
    import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    public class commandhandeler implements CommandExecutor {
    
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if (args.length == 0) {
                sender.sendMessage(ChatColor.GRAY + "*-------------" + ChatColor.YELLOW +  "Efteling-Core" + ChatColor.GRAY + "-------------*");
                sender.sendMessage(ChatColor.GRAY + "/efteling status <status> <attractie>");
            }
            if (args.length == 1)
                if (args[0].equalsIgnoreCase("status")) {
                    sender.sendMessage(ChatColor.AQUA + "Status");
                }
                if (args[0].equalsIgnoreCase("test2")) {
                    exampleJson(e.getPlayer());
                }   
                return false;
                }
      
        public void exampleJson(Player player) {
            IChatBaseComponent comp = ChatSerializer.a("{\"text\":\"Welcome to my server! \",\"extra\":[{\"text\":\"§bClick Here\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"§cThis §dIs §aSo §bCool!\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/list\"}}]}");
            PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
          
        }
            }
    
    if (args[0].equalsIgnoreCase("test2")) {
    is true it have to activate exampleJson(e.getPlayer()); how can i make that???
     
  2. Offline

    mine-care

    And your problem is?
     
  3. Offline

    Badwolf330

    @mine-care
    Code:
        public void exampleJson(Player player) {
            IChatBaseComponent comp = ChatSerializer.a("{\"text\":\"Welcome to my server! \",\"extra\":[{\"text\":\"§bClick Here\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"§cThis §dIs §aSo §bCool!\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/list\"}}]}");
            PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    have to be activate be
    Code:
      if (args[0].equalsIgnoreCase("test2")) {
    (command is /efteling test2
     
    Last edited: Oct 5, 2015
  4. @Badwolf330
    I don't see what your issue is, it seems fine.
     
  5. Offline

    Badwolf330

    @megamichiel
    error in console by typing the command /efteling test1
    Code:
    [19:00:12] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'efteling' in plugin Efteling-Core v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-1544]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[spigot.jar:git-Spigot-1544]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1016) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:846) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:184) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:731) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1544]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1544]
    Caused by: java.lang.Error: Unresolved compilation problem: 
        e cannot be resolved
    
        at nl.eftelingcore.skyrob.commandhandeler.onCommand(commandhandeler.java:27) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-1544]
        ... 13 more
    
    code
    Code:
                if (args[0].equalsIgnoreCase("test2")) {
                    exampleJson(e.getPlayer());
    
    e cannot be resloved
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    Badwolf330

    @timtower i know :) but i did know where the variable e fid. that was my question :p
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Badwolf330 Well, you wrote the code didn't you, where does the player need to come from?
     
  9. Offline

    Badwolf330

    @timtower
    e is the player that execute /efteling test1 but i don't know where to put it :p
     
  10. Offline

    timtower Administrator Administrator Moderator

    @Badwolf330 Check if sender is a player, if so: cast to a player.
    And e seems like an event which you aren't using here ;)
     
  11. Offline

    Badwolf330

    @timtower :p i did juse the wron code i need a code that sends a message to the hole server whif hover and click event :)
     
  12. Offline

    Zombie_Striker

    @Badwolf330
    Do you know how to loop through a collection? If so, Loop through all the players online when sending the message.
     
  13. Offline

    Badwolf330

  14. Offline

    Zombie_Striker

    @Badwolf330
    If you did not know how to loop through a collection, please Learn Java. That is a basic component of Java.
     
  15. Offline

    Badwolf330

    @Zombie_Striker
    I did found it i did know the codes but my english is not verry good so i dont get everything you say :p it is working nog thanks alot!!
     
Thread Status:
Not open for further replies.

Share This Page