[TuT] How To Toggle Something

Discussion in 'Resources' started by RobotA69, Jun 12, 2012.

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

    RobotA69

    Let me start off by saying I don't know if I can post this here or if there's even a section for tutorials on Bukkit. But, if so I will be posting tutorials on kind of simple things that some people have trouble with. Hopefully, this will inspire some brand new fresh creative plugins and I hope everyone can learn something new! Thanks for reading!
    Example Plugin : My plugin performs a event when something is toggle on/true. So, let's get done to it!
    1. Make a boolean, it should be public & static so it can be accessed by other classes.
    If your using just one class, then it can just be a boolean with a name.
    2. Now, just make it so that when something happens, it toggles.
    3. Now, just add that if the boolean is true/false, something happens.
    4. Done (Pseudocode Below!)
    PHP:
    Step 1.
     
    One 
    Class : boolean toggle;
    Multiple Classes : public static boolean toggle;
    //Toggle is our name!
     
    Step 2.
     
    Command Toggle 
    : if(player.types("/toggle")) {
    One Class : toggle = !toggle;
    Multiple Classes ClassName.toggle = !ClassName.toggle;
    //This means if our toggle is true, it makes it false
    //If our toggle is false, it makes it true
    }
     
    Action Toggle :
    @
    EventHandler
    public void onPoop(PlayerPoopEvent e) {
    if(
    player.isOp && player.poops) {
    toggle = !toggle//One Class
    ClassName.toggle = !ClassName.toggle//Multiple Classes
    }
    }
     
    Step 3.
     
    if(toggle) { //If our boolean is true
    player.sendMessage("STOP POOPING!");
    } else {
    player.sendMessage("GOOD JOB NOT POOPING!");
    }
     
    Step 4. DONE!
    Hopefully, this tutorial belongs/is allowed here and it both encourages and inspires developers to make more tutorials and/or to try to make more creative and advanced plugins! Thanks for reading. Leave a like if this tutorial helped you. If this is allowed here, comment if I should add more tutorials!
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    best not to use static, even though it adds significant complexity to the psudo code.

    EDIT: Please feel free to contribute to the bukkit wiki
     
  3. Offline

    JxAxVxAx

    The Next Time You Are Posting Your TUTs Please Go To Resources And Post It There !
     
  4. Offline

    RobotA69

    Thanks, I knew about the Resources section, but I thought it was more for API's and Dev. Tools, hopefully a staff can move this there.
     
  5. Offline

    JxAxVxAx

    No Problem !
     
  6. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    moved
     
Thread Status:
Not open for further replies.

Share This Page