event Hover in bukkit plugin code

Discussion in 'Plugin Development' started by penz5557, Dec 10, 2014.

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

    penz5557

    i cant seem to get this code to work on the bukkit 1.7.9 server of mine it keeps coming up with errors.

    if i could get some help with the full code please :3
     
  2. Offline

    Skionz

    1. Completely wrong section
    2. This isn't a utility + refer to 1.
    3. What is the question? What code? I don't see any code. We have no idea what you are asking.
    4. Post the stack-trace.
    EDIT: 5. Nobody is going to spoon-feed you (give full code)
     
    Last edited: Dec 11, 2014
    Fuzzybear04 and Jaaakee224 like this.
  3. Offline

    penz5557

    right now im just trying to figure out how to put rawtext code into eclipse and have the console run the command
     
  4. Offline

    Skionz

  5. Offline

    penz5557

    so if a player does a command it will run a console command to show rawtext

    im pretty much asking how to do the hoverevent in bukkit plugin code :3

    Code:
    package me.proxy;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    
    public class testCommand implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
    
            Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "{"text":"","extra":[{"text":"Welcome to the network!","color":"red","bold":"true","italic":"true","underlined":"true","clickEvent":{"action":"suggest_command","value":"hello there"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"CLICK HERE! :D","color":"gold"}]}}},{"text":"Type /server to list our servers","color":"aqua","italic":"true","clickEvent":{"action":"run_command","value":"/server"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"Click here to list our servers!","color":"gold"}]}}}]}");
            // TODO Auto-generated method stub
            return false;
        }
    
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  6. Offline

    Lorinthio

    If you're having the problem I had... You'll need to use the escape character \ everytime you have a " in your rawtext line. For example...

    String line = "{\"text\": none, \"extra\":}

    Not exact syntax I'm sure, but you get the idea.

    Also to send the command with bukkit, just use...

    getSever().dispatchCommand(getServer().getConsoleSender, "tellraw " + line);
     
  7. Offline

    penz5557

    it says getSever i need to create a method :/ wut do i do

    also getConsilsender is not able to be used or whatever and if i could have an example tellraw with hover event tht'd be great :3

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  8. Offline

    Lorinthio

    just put Bukkit.

    in front of the getServer() line

    Bukkit.getSever().dispatchCommand(getServer().getConsoleSender, "tellraw " + player.getName() + " " + line);


    EDIT::

    Also I forgot you needed player name in the dispatch command.. so just use that line I put
     
  9. Offline

    penz5557

    ok let me see if that works :)

    when i do the command nothing shows up in chat :c
    Code:
    package me.test.hover;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
    
    
    public void onEnable() {
    
    }
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
        if(cmd.getName().equalsIgnoreCase("testhoverevent"))
             Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),"tellraw"  + String line =("{\"text\":\"Hi\",\"color\":\"white\",\"extra\":[{\"text\":\"<Clik It>\",\"color\":\"yellow\",\"bold\":\"false\",\"italic\":\"true\",\"underlined\":\"false\",\"strikethrough\":\"false\",\"obfuscated\":\"false\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/achievement give <stat_name> [player]\"}}]}"));
       
       
        return true;
    
    }
    }
    
    coming up with unknown command in the console

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  10. Offline

    indyetoile

    Have you registered your command in your plugin.yml?
     
  11. Offline

    penz5557

    yes its somthing to do with the code

    Code:
    11.12 11:04:04 [Server] INFO org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: net/minecraft/server/v1_7_R3/Packet 11.12 11:04:04 [Server] ERROR Could not load 'plugins/TestHover.jar' in folder 'plugins' 11.12 11:04:04 [Server] INFO ... 6 more 11.12 11:04:04 [Server] INFO at 
    this is whats in console

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  12. Offline

    Skionz

    You either are not importing something, or using the wrong CB version.
     
  13. Offline

    penz5557

    cb version?

    version 1.7.9 - 1.8 im usin

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  14. Offline

    Skionz

    @penz5557 Why are you using packets? You have to use reflection if you want to use it on 1.8 and 1.7.9 and reflection is pretty slow. There is another way but I can't think of it right now. I remember seeing a post in the resource section about it.
     
  15. Offline

    penz5557

    can i ask how to do that :3
    Code:
    package me.test.hover;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.minecraft.server.*;
    
    @SuppressWarnings("unused")
    public class Main extends JavaPlugin implements Listener{
    
    
    public void onEnable() {
    
    }
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
        Player p =(Player) sender;
        if(cmd.getName().equalsIgnoreCase("testhoverevent"))
             Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),"tellraw "  + p.getName() + ("{\"text\":\"Hi\",\"color\":\"white\",\"extra\":[{\"text\":\"<Clik It>\",\"color\":\"yellow\",\"bold\":\"false\",\"italic\":\"true\",\"underlined\":\"false\",\"strikethrough\":\"false\",\"obfuscated\":\"false\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/achievement give <stat_name> [player]\"}}]}"));
        // TODO Auto-generated method stub
       
        return true;
    
    }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page