Solved Voting In Game

Discussion in 'Plugin Development' started by XKnucklesX, Jul 19, 2013.

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

    XKnucklesX

    Well I am developing a sort of vote plugin. When the person does /vote <arg> they get taken to the website of that argument.

    I have done the command I just do not know how to bring them there.

    Vote arguments:
    1 -6

    Also how do I check so if player does
    /vote 2

    it checks that argument and in this case that argument is 2 so it brings it to the website that represents 2.
     
  2. Offline

    ZeusAllMighty11

    Can't have a space in a command. Instead, check arguments
     
  3. Offline

    XKnucklesX

    That was my first plan this is how I thought of it in english

    If arg = 1
    try {
    //Something like that
    }

    Would that work.
     
  4. No,
    if(args.lenght >= 1){
    //arg lenght = 2 so player types in vote + arg.
    // in case im wrong I hate java index.
    }
     
  5. Offline

    Henzz

    XKnucklesX
    Yes, just make sure you parse the second argument as an int and handle the exception.
     
  6. Offline

    XKnucklesX

    I mean like if the arg 0 the number they put in. So how do i check if the argument is the right argument like a valid one. Im not checking the length of arguments I want to know how to get the argument and see if the arguments data matches the appropriate info to keep going.

    Also I still need help on connecting to the site without actually doing anything so the plugin does it for you.

    Anyone?

    still need help?

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

    Zethariel

    1. Don't bump so often.
    2. You mean an IF statement? You need to check if the arguments length is 1 or more. Arguments is ALWAYS the thing that comes after the command, since commands can't have spaces. If the args.length == 1, that means that they typed /Vote XXXX, where XXXX is something you need to check.
    Henzz told you to parse the argument. That means that you need to check if it is a number, and if it isn't handle the exception so that your code doesn't cause any errors. you wil need to:
    Code:java
    1. try
    2. {
    3. Integer.parseInt(args[0])
    4. }
    5. {
    6. e.PrintStackTrace();
    7. sender.sendMessage("This is not a number!");
    8. return true;
    9. }

    What this does is check if the argument is a number, and if it isn't, stops right there.

    Now that we know that it is a number, you can do whatever it is that your code was supposed to do
     
  8. Offline

    ZeusAllMighty11

  9. Offline

    XKnucklesX

    I need to check if the arg they put in is between 1-6.

    So I want to something like this

    if arguments value = 1
    continue

    so if the person does /vote 1
    it checks what number the 1 is since I need to repeat it 6 times for all 6 votes and then so if it equals:

    1-minestatus....
    2.planetminecraft
    and sooo on

    Yea also remember that I am looking how to vote so it goes on minestatus it votes. I think that may use another language Ill be back going out for a bit.

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

    xTrollxDudex

    Henzz
    //offtopic
    Your name an sig remind me of ketchup :p
    XKnucklesX
    Some websites have an API for hooking, look into that? Otherwise, I don't think you should be connecting to a voting website directly, giving the user a link would be better.
     
    Henzz likes this.
  11. Offline

    XKnucklesX

    Would this require JavaScript or some web tool in my plugin.
     
  12. Offline

    xTrollxDudex

    XKnucklesX
    probably some php and something about tcp I'm not sure
     
  13. Offline

    XKnucklesX

    What I really need is some web development pro who also knows how to connect with java.

    Post Changed

    Edited

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

    afistofirony

    XKnucklesX Here's a way of doing it. Note that you can't actually take someone to a website; you can only show them a link to it.

    Code:
    public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) {
        if (label.equalsIgnoreCase("vote")) {
            if (args.length == 1) {
                int site;
                try {
                    Integer.parseInt(args[0]);
              } catch (NumberFormatException e) {
                    site = 0;
                 }
                 
                 String message = ChatColor.AQUA + "Vote at ";
                 switch (site) {
                     case 1:
                         message += "example voting site: http://example.com/ourserver/vote";
                         break;
     
                     // Continue to do this for the rest of your numbers. Don't forget your break statements.
     
                     case 0:
                     message = ChatColor.RED + "That is not a valid number!";
                     break;
     
                     default:
                     message = ChatColor.RED + "Unknown voting site!";
                 }
     
                 sender.sendMessage(message);
                 return true;
          } else {
                 // Wrong amount of arguments.
                 sender.sendMessage(ChatColor.RED + "Invalid amount of arguments.\n" +
                                                                                   "Correct syntax: " + ChatColor.AQUA + "/vote [1-6]");
                 return true;
             }
        }
    
        return false;
    }
     
  15. Offline

    microgeek

    Lean Java, this would be a non-issue after an hour or so of watching Java tutorials..
     
  16. Offline

    XKnucklesX

    I have watched many tutorials read books and it doesn't tell me. But afisto Is there away that it actually opens up there internet browser and puts them on a site because if I do what you said i may aswell do

    When they do the command
    send the link to them using
     
  17. Offline

    microgeek

    I don't believe you can. Just send the link in chat and have the click on the link.
     
  18. Offline

    XKnucklesX

    Yes you can. You send the link in chat and they double click/one click on it and it says "are you sure" or something
     
  19. Offline

    Garris0n

    You can do that but it's 100% client sided. What he's saying is you can't force the client to open that gui.
     
  20. TheGreenGamerHD I'm always wrong with that, because, in my mind: java index starts at 0, so I'm like yeah arg starts also from 0..
     
  21. Offline

    xTrollxDudex

  22. Nope he told me that /command lol < lol = 1 arg...Ut like I said, java indexing + my mind = rickroll.
     
  23. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page