Web page

Discussion in 'Plugin Development' started by SkyGlue, Oct 2, 2015.

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

    SkyGlue

    Hello all,
    I was wondering if someone can push me in the direction of making a plugin that opens a web page to a certain link.

    Thanks in advance
    Rege
     
  2. Online

    timtower Administrator Administrator Moderator

    @SkyGlue And do what with it? Do you just need to view the source from within the plugin? Do you want it to open clientside?
     
  3. Offline

    mine-care

    @SkyGlue Asuming you mean get the source code (because i cant thing of something you can do with it server-side),
    Get the url, open the stream, put it on a BufferedReader or whatever you prefer, read from that, while reading you can append the Strings read to a StringBuilder to have the entire source later.. This can be resource leaky if not handled properly or the remote page/file is massive.
     
  4. Offline

    teej107

    @SkyGlue It'll only open the webpage on the computer that the server is running on if you open it from the plugin. Are you talking about using clickable text that opens a website from MC? You can send a player JSON that'll do that.
     
  5. Offline

    DoggyCode™

    Spiggot has a built-in method for this.
     
  6. Offline

    teej107

    I'm not surprised. It's pretty easy to send JSON to players anyway.
     
  7. Offline

    DoggyCode™

    Yea. I know, but with the events, how would you do that? Like with a onClick event and such? And how would you differ the actions, like Action.OPEN_URL, or Action.PERFORM_COMMAND? You know what I mean.
     
  8. Offline

    Gonmarte

    @SkyGlue i didnt want to do this but here we go... you can check this video First thing i must say that you shouldnt watch his videos because it would be a bad influence to you but if you are really looking for it go ahead =)
     
  9. Offline

    teej107

    All those actions are handled in the JSON that you send.
     
  10. Offline

    SkyGlue

    I tried video but this is what I got:

    Main Class

    Code:
    package me.SkyGlue.Wiki;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Wiki extends JavaPlugin{
    
       
        public void registerCommand() {
            getCommand("wiki").setExecutor(new Wiki());
        }
    }
    
    My command file.

    Code:
    package me.SkyGlue.Wiki;
    
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    import net.minecraft.server.v1_8_R3.CommandExecute;
    import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
    import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
    import net.minecraft.server.v1_8_R3.PlayerConnection;
    
    public class Command extends CommandExecute {
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You are not a player!");
                return false;
            }
            Player player = (Player) sender;
            PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
            PacketPlayOutChat packet = new PacketPlayOutChat(ChatSerializer.a(
                    "[\"\",{\"text\":\"Click me to check out the wiki!\",\"color\":\"green\",\"bold\":true,\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http://pixelmonmod.com/wiki/index.php?title=Welcome_to_the_Pixelmon_Wiki\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click me!\",\"color\":\"light_purple\"}]}}}]"));
    
            connection.sendPacket(packet);
            return true;
        }
    
    }
    
    Plugin.YML

    Code:
    name: PixelmonWiki
    main: me.SkyGlue.Wiki.Wiki
    version: 1.0
    commands:
    wiki:
      description: Opens thePixelmon wiki page!
    So When I export it, I get no errors but when I get ingame and do /wiki nothing happens. Any Suggestions?
     
  11. @SkyGlue The yml file is not properly formatted.

    Code:
    commands:
      command: 
        description: A command.
     
    Gonmarte likes this.
  12. Offline

    Gonmarte

    @SkyGlue like @bwfcwalshy sad you need to change the yml file and probably when yuo run the plugin the console says plugin.yml invalid.
     
  13. Offline

    SkyGlue

    @bwfcwalshy @Gonmarte

    I still get this error in the console


    Code:
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
    found character          '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation)
    in 'reader', line 5, column 1:
            wiki:
        ^
    
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:420) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:381) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:232) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:159) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            ... 5 more

    I know it says that I shouldn't use tabs but I didn't and it didn't work!
     
  14. Offline

    Gonmarte

    @SkyGlue Can you show us all the classes of your plugin?
     
  15. Online

    timtower Administrator Administrator Moderator

    bwfcwalshy likes this.
  16. Offline

    SkyGlue

    @timtower I did that. Let me show you my code again.

    Main class called "Wiki"

    Code:
    package me.SkyGlue.Wiki;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Wiki extends JavaPlugin{
    
       
        public void registerCommand() {
            getCommand("wiki").setExecutor(new Wiki());
        }
    }
    
    Class called "Command"

    Code:
    package me.SkyGlue.Wiki;
    
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    import net.minecraft.server.v1_8_R3.CommandExecute;
    import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
    import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
    import net.minecraft.server.v1_8_R3.PlayerConnection;
    
    public class Command extends CommandExecute {
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You are not a player!");
                return false;
            }
            Player player = (Player) sender;
            PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
            PacketPlayOutChat packet = new PacketPlayOutChat(ChatSerializer.a(
                    "[\"\",{\"text\":\"Click me to check out the wiki!\",\"color\":\"green\",\"bold\":true,\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http://pixelmonmod.com/wiki/index.php?title=Welcome_to_the_Pixelmon_Wiki\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click me!\",\"color\":\"light_purple\"}]}}}]"));
    
            connection.sendPacket(packet);
            return true;
        }
    
    }
    Plugin.yml

    Code:
    name: PixelmonWiki
    main: me.SkyGlue.Wiki.Wiki
    version: 1.0
    commands:
      wiki:
        description: Sends the user to the Pixelmon Wiki!
    
    pls help
     
  17. Online

    timtower Administrator Administrator Moderator

    @SkyGlue Your code in irrelevant for the issue with a plugin.yml.
    Do you get the same error?
     
  18. Offline

    SkyGlue

    This is the error I get;


    Code:
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:164) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:133) [spigot.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:291) [spigot.jar:git-Spigot-044d928-e8c6403]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) [spigot.jar:git-Spigot-044d928-e8c6403]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:528) [spigot.jar:git-Spigot-044d928-e8c6403]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
    found character          '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation)
    in 'reader', line 5, column 1:
            wiki:
        ^
    
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:420) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:381) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:232) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:159) ~[spigot.jar:git-Spigot-044d928-e8c6403]
            ... 5 more
     
  19. Offline

    boomboompower

    Code:
    name: PixelmonWiki
    version: 1.0
    main: me.SkyGlue.Wiki.Wiki
    commands:
      wiki:
        description: Sends the user to the pixelmon wiki!
    It should work. Are you compiling it to the right place? Are you reloading your server (If so don't, use /restart) go back through and make sure there are no tabs. Rewrite the config if you have to Just Do It
     
  20. Offline

    mythbusterma

    @SkyGlue

    No. You didn't. Can't you read the first line of the output?

     
Thread Status:
Not open for further replies.

Share This Page