My commands does work properly how do I fix?

Discussion in 'Spigot Plugin Help' started by Toxicmine, Jul 8, 2021.

  1. When I do /challenge join or challenge quit
    it does the /challenge stop
    I added return true to it tho but still it does it :/
    heres ma code
  2. Of course it does - first, clean your code, meaning WTF is going on with the if statements?!

    If you don't mind the jumble of mess that's barely decipherable, then your problem is in lines 50-56: the moment args's length is bigger than 0 the timer is purged, you get the message the challenge was cancelled, and it returns.
    Just add { at the end of line 51 and } after line 54.

    But seriously - clean up the if statements so you have a better understanding of your own code... The should be a lot shorter and a lot less messy.
    • Agree Agree x 1
  3. I know its messy but- I know this sounds weird but I work best with a messy code LOL, no joke HAHA, My friend and I was coding a plugin and when he gave the git access to me I didnt know what was going on with the code but when I jambled some stuff I understood it LOL. Anyways I will try this when I go on my comp lol thx!
  4. Strahan


    If you intend to do more programming in the future, get out of this habit. It's terrible. That aside, this is not a very good idea. Ticks do not represent a fixed period of time; the 20 ticks = 1 second is ideal not guaranteed. A better approach would be to store a long representing current time when the "timer" is started, then have a runnable that checks if stored time + desired delay has passed and act on that. Also you realize if the server is restarted, the timer is hosed and needs to be restarted right? Your args length == 0 check also is missing the bracketing for the label check, though that's not a huge deal because this command is the only one registered to the class, so it can never fail that check. You really don't need to check label when that is the only possible label it could be. Plus, it should be cmd.getName() anyway.

    Code (Text):
    Scanner scanner = new Scanner(;
    player.sendMessage("Are you sure to remove yourself from the challenge? [Yes/No]");
    String opinion = scanner.nextLine();
    This is all sorts of bad. First, it will only work if the person running the command is at the console, and as you do a Player check that means it will not ever work. does not get input from players, it is an InputStream connected to the system's console. Second, it is blocking so if it were magically able to get remote player input, if the player sat there hemming and hawing about whether or not to remove from the challenge, the whole server would be hung while they do that.