Solved Command

Discussion in 'Spigot Plugin Development' started by iMedia, Aug 10, 2018.

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

    Supporter

    I was wondering how would I add a toggleable command that disables/enables an event?
     
  2. Add a command, make it change a variable, make the event check that variable every time it's fired.
     
  3. iMedia

    Supporter

    How would I check the variable/change it?
     
  4. Let's take for example a boolean variable. Each time the command runs check the boolean value, if the value is true set (for example) weather to rainy else if the value is false set (for example) weather to sunny. After each change you need to change the boolean value to the opposite of it.
    Code (Java):
    boolean toggle = true;

    // AFTER THE TOGGLE
    toggle = !toggle;
     
  5. iMedia

    Supporter

    I still don't get how to check it and how do I cancel a event if it is a ! im so cofused xd
     
  6. Code (Kotlin):
    var toCancel = false
    command("togglecancel")
      .implement {
        toCancel = !toCancel
      }
      .register()
    listen<PlayerJoinEvent> {
      if (toCancel) return@listen
      it.player.sendMessage("hello")
    }
    Something along those lines but in Java.
     
    • Informative Informative x 1
Thread Status:
Not open for further replies.