Solved Changing the look of a URL

Discussion in 'Spigot Plugin Development' started by TheITx, Jul 16, 2019.

Thread Status:
Not open for further replies.
  1. Hello,
    So i'm wanting a way for a user to easily navigate to a voting website. At first i wanted to create a Item that you could click and it would bring up the URL confirmation screen (not putting the URL in chat) and send you to the URL. Unfortunately it seems that isn't something MC is capable of (if im wrong please let me know). alternatively, i decided i would make a clickable chat link (even though its not what i wanted) but i really don't wanna just spit the link onto the screen for a user to click, i would rather it display something like
    "-> Click me <-" and you click it and the URL confirmation screen pops ups.
    but this ->
    Code (Text):
    urlMessage.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, https://www.google.com/));
    doesn't seem to open a URL (in fact nothing happens despite knowing that the line does execute and the message displays on the screen) and without that line working, i cant just hide it behind some text like a click me text or something.

    So i guess my question is, Is there a way to do either of these things that im not thinking of? or even more ambigious, Is there another way a user can open a URL link without displaying the URL within the chat?

    Thanks!
     
  2. How about a book? On item right click ->open custom book with the link on it :)
     
    • Agree Agree x 1
  3. Problem is still the same though, i dont wanna just display the link, i would like it to be bit hidden with like a Click me text instead of the URL. I understand that you would still see the URL when the confirmation message popped up, but before that i would like to not have to shoot a Link at a player, via chat or book.
     
    • Agree Agree x 1
  4. This is what i have been using. Ive used Chat compoents before, but mostly to issue commands or suggest commands, not open URL. when i try to use OPEN_URL. nothing happens. The text is displayed on the screen, and it will have all components as specified, but for what ever reason clicking it wont prompt the usual URL confirmation. This is what i planned to use after i couldn't get the Item way to work, as you can set the text to say anything you like, but open a URL of a different name behind it.
    -Edit: although i saw in that second link they do a string#replace(" ","%20"), which i didnt do, maybe it might help? idk im about to try it.
     
  5. I'm pretty sure that's just to replace the spaces with %20 because a URL cannot have spaces. (and then it uses that instead)
    EDIT: I found this link: https://en.wikipedia.org/wiki/Percent-encoding, the characters used after the % is the hexadecimal values for ASCII characters. You can see all the ASCII characters here: https://www.ascii-code.com/
     
  6. Uhh yeah it's done because urls don't accept spaces, but better way to do it would be to use
    Code (Text):
    URLEncoder.encode("apples oranges", "utf-8");
    so that any character is encoded and not just spaces.
     
  7. Yeah i know but that is just a bit of error checking that i had not done before hand.

    Ill try that instead, but even so, shouldnt the confirmation window still pop up even with invald URL? i mean shouldnt it pop up even if you type "https://www.spigotmc.org" and "https://www.spigot mc.org" the main difference being one would be a valid URL and the other wouldnt, but the confirmation should still show up.. shouldnt it?

    -Edit:ive done some testing with the above changes, and nothing has changed. Below is a picture of what the text outputted looks like (or at least what i would like it to look like) but no URL confirmation pops. also attached is the method im building the message in.
    Code (Java):
    public boolean buildMessage() throws UnsupportedEncodingException
      {
        message = new TextComponent("Vote by clicking on this link ");
        message.setColor(ChatColor.LIGHT_PURPLE);
        String url = (String) this.getURLSettings();
     
        BaseComponent[] link =
                new ComponentBuilder("-> Click Me to vote <-")
                        .underlined(true)
                        .event(new ClickEvent(ClickEvent.Action.OPEN_URL, URLEncoder.encode(url, "utf-8")))
                        .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click Me to Vote").color(ChatColor.GREEN).create()))
                        .create();
     
        for (BaseComponent baseComponent : link) {
          message.addExtra(baseComponent);
        }
        return true;
      }
    Sorry for the poor image quality
    https://ibb.co/yd7N1bV

    [​IMG]
     
    #8 TheITx, Jul 16, 2019
    Last edited: Jul 16, 2019
    • Like Like x 1
  8. Is your Web Link ON in Chat Settings (In Minecraft)
     
  9. yeah, if i try the same thing but as plain text chat (ie just typing in https://google.com) i get the confirmation popup
     
  10. -bump.Still really hoping for a good solution to this problem
     
  11. Do you have the full source code availiable for download? I'd love to actually download it all and take a deeper look into it. Not promising I can do anything with it but the offer is there anyway.

    Of course the plugin is yours, your intelectual property and copyrighted to you so I cannot do anything with it.
     
  12. Yeah
    https://github.com/EMcKee10/MilkyVote
    Full disclaimer, Im currently working in this repository so PLEASE, PLEASE dont critize me for the fairly common mistakes and Unclean code/Structure. I usually get the components and logic in place first, before doing major cleanup and revision.

    -Edit, I made the readme file a explination of what im aiming for and what has been accomplished
     
    #13 TheITx, Jul 18, 2019
    Last edited: Jul 18, 2019
  13. It's okay. I'll take a look through it and see what I can try and figure out. I'll get back to you later
     
  14. Okay, so from what I've figured out it's the URL encoding that is messing it up. If you remove the url encode(url)and just have url in the componant builder all works fine.

    Code (Java):
    BaseComponent[] link = new ComponentBuilder("-> Click Me to vote <-").underlined(true).event(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click Me to Vote").color(ChatColor.GREEN).create())).create();
    What I would suggest doing is allowing more than one argument and if there is more than one argument itterate through them and do url = args[0] + "%20" + args[1] + "%20" + args2 etc. Save all that to the settings file and it should look like voteurl.com/vote%20here%20now. That works with the plugin. Also you need to check if there's a protocol (http:// or https://) and if there's not add it. I'd suggestest adding http:// if not specified so it connects to http://voteurl.com and if the website has an ssl cert they should forward users to the https://
     
    • Winner Winner x 1
  15. I fixed it with testing in my plugin, you need the correct url, and afaik you dont need the url-encoder or anything. might be nice for making sure the link is valid though. Link, exactly as this: "https://google.com" works
     
    • Like Like x 1
  16. Well I'm glad you have that part fixed but it still raises the question of what if there is a space in the URL? Also if the user misses the protocol on the setvotelink command spigot doesn't open the URL
     
    • Informative Informative x 1
  17. Spaces shouldn't matter, they are written as %20 I believe. You only need to make sure you correct for any user mistakes, this also applies to converting the space to the correct character, %20. I'm sure there are syntax tables online for correcting userinput to valid URL's
     
    • Optimistic Optimistic x 1
  18. Thank you! I had originally done this and it wouldn't work, but it may have been the protocol. been trying for days, i need to continue testing and making sure that it works on the server then ill let you know.
    @ThtGamerGirlLexi There are definitely checks i am missing, just wanted to lay down the foundation before building the walls if you catch my drift XD But thank you for the suggestion, the protocol was something i accounted for and planed on implementing. However the idea of spaces in a URL just seems like i'm over achieving. i mean if a user types in spaces in a URL, they dont really understand how URL syntax is. That being said i do need to make sure i put in checks to validate the URL (which i also plan to implement).
     
  19. When you get stuck on something try dropping it for a day, or maybe even a single break. Rethink your idea after and if you still land on your original idea with your new knowledge, this is probably the way to go but you messed up somewhere else.
     
    • Agree Agree x 1
Thread Status:
Not open for further replies.