Minigame event help

Discussion in 'Plugin Development' started by ItsLeoFTW, Jul 28, 2014.

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

    ItsLeoFTW

    *first post in a while*
    So, I'm working on a new minigame for my server. I have an Ability class which can be extended to create custom "abilities". Now, the problem is, I can't figure out how to make an event that checks to see when an ability is used, and checks to see if a cooldown is in place for the player using the ability.

    (Ability class)
    Code:java
    1. package net.minerzone.minigames.mad.abilities;
    2.  
    3. import net.minerzone.minigames.mad.etc.Cooldown;
    4. import net.minerzone.minigames.mad.etc.CooldownManager;
    5.  
    6. public class Ability {
    7. public int id;
    8. public String name;
    9. public int cooldowntime;
    10. public Cooldown cooldown;
    11. public Ability(int id, String name, int cooldown, CooldownManager.Time type){
    12. this.id = id;
    13. this.name = name;
    14. this.cooldowntime = cooldown;
    15. this.cooldown = new Cooldown(this.cooldowntime, type);
    16. }
    17. public int getCooldown(){
    18. return this.cooldowntime;
    19. }
    20. public String getName(){
    21. return this.name;
    22. }
    23. }
    24.  


    (AbilityUseEvent class)
    Code:java
    1. package net.minerzone.minigames.mad.abilities;
    2.  
    3. import org.bukkit.event.Cancellable;
    4. import org.bukkit.event.Event;
    5. import org.bukkit.event.HandlerList;
    6.  
    7. public class AbilityUseEvent extends Event implements Cancellable {
    8. private boolean cancelled;
    9. private String name;
    10.  
    11. private static HandlerList handlers = new HandlerList();
    12. @Override
    13. public HandlerList getHandlers() {
    14. return handlers;
    15. }
    16. public static HandlerList getHandlerList(){
    17. return handlers;
    18. }
    19. @Override
    20. public boolean isCancelled() {
    21. return this.cancelled;
    22. }
    23.  
    24. @Override
    25. public void setCancelled(boolean bln) {
    26. this.cancelled = bln;
    27. }
    28.  
    29. }
    30.  


    Can anyone help me with figuring out how to check when a certain ability has been used?
    Thanks!
     
  2. Offline

    GameplayJDK

    ItsLeoFTW You can use an interface as somthing like a callback.. e.g.
    Code:
    public interface AbilityCallBack {
        public void onUse();
    }
    //And give it to the constrcutor:
    public Ability(..., AbilityCallback abc) {
        ...
        this.abc = abc;
    }
     
    // call it when the ability is used:
    public void use() {
        this.abc.onUse();
    }
    I'm not familiar enough with custom events to help you out with 'em :/
     
  3. Offline

    Dragonphase

    ItsLeoFTW

    First off, your AbilityUseEvent has no constructor, so you won't be able to call it.

    Wherever you call the code which uses the ability, you can do the following:

    Code:java
    1. AbilityUseEvent event = new AbilityUseEvent(ability variables here);
    2.  
    3. Bukkit.getServer().getPluginManager().callEvent(event);


    Then you would create a Listener and listen for your AbilityUseEvents
     
    ItsLeoFTW likes this.
  4. Offline

    ItsLeoFTW

    Thanks, that helped! Not gonna mark as solved just yet, since I might run into other problems.
    +1 like for you!
     
Thread Status:
Not open for further replies.

Share This Page