Solved Issue Handling PlayerEvent

Discussion in 'Plugin Development' started by BaddCamden, Aug 6, 2020.

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

    BaddCamden

    Recently, I have ran into an issue where when I use PlayerEvent, it will give me an error saying
    Unable to find handler list for event org.bukkit.event.player.PlayerEvent
    And after doing some research, I have learned that it is impossible to fix this issue, but I need PlayerEvent for my program to work.

    Code:

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void createItemAbility(ItemStack item, String event, String ability, String itemType, boolean isFullArmor) {
    ArrayList Abilities = new ArrayList();
    Abilities.add(ability);
    Abilities.add(event);
    Abilities.add(item);
    Abilities.add(itemType);
    Abilities.add(isFullArmor);
    AbilityData.add(Abilities);
    }

    @SuppressWarnings("deprecation")
    /*
    @EventHandler
    public void PlayerEvent(PlayerEvent event) {
    onLog.info("PlayerEvent Activated");
    for(@SuppressWarnings("rawtypes") ArrayList Abilities : AbilityData) {
    onLog.info("Ability: "+Abilities.get(0).toString());
    onLog.info("Event: "+Abilities.get(1).toString());
    onLog.info("Item: "+(ItemStack) Abilities.get(2));
    onLog.info("ItemType: "+Abilities.get(3).toString());
    onLog.info("isFullArmor: "+(Boolean)Abilities.get(4));
    if(event.getEventName().equalsIgnoreCase(Abilities.get(1).toString())) {
    if(Abilities.get(3).toString().equalsIgnoreCase("Armor")) {
    int itemsFound = 0;
    for(ItemStack item : event.getPlayer().getEquipment().getArmorContents()) {
    if(item.isSimilar((ItemStack) Abilities.get(2))) {
    if(!(Boolean)Abilities.get(4)) {
    abilities(Abilities.get(0).toString(), event);
    break;
    } else {
    itemsFound += 1;
    }
    }
    }
    if(itemsFound == 0 && (Boolean)Abilities.get(4)) {
    abilities(Abilities.get(0).toString(), event);
    }
    }
    if(Abilities.get(3).toString().equalsIgnoreCase("Tool")) {
    if(Abilities.get(2).equals(event.getPlayer().getItemInHand())) {
    abilities(Abilities.get(0).toString(), event);
    }
    }
    }
    }
    }
    */




    Is there anything that works the way I want it to, without having to register every player event specifically? Is there a way to actually fix the issue unlike what I thought? Or am I screwed?

    Also, I did indent my code it just didn't transfer for some reason...






     
  2. Online

    timtower Moderator Moderator

    @BaddCamden Ypu can't listen to PlayerEvent, you need to listen to all of its derived classes.
     
  3. Offline

    Strahan

    What he said. You can't do that. What action taken by the player should your desired effect be triggered by?

    Also do not suppress warnings. The compiler is not complaining for nothing; you should address its issues rather than just ignore them.
     
  4. Offline

    BaddCamden

    @Strahan I would like to use the event that was put in the parameter. Also, I supressed the warnings because they took up so much of my scroll bar, and I didn't really care right now about the minor stuff, I usually do that in post.
     
    Last edited by a moderator: Aug 7, 2020
  5. Online

    timtower Moderator Moderator

    @BaddCamden But the PlayerEvent is no action on its own.
    Do you want clicks? Movement? Dying?

    What is the end goal of this event?
     
  6. Offline

    BaddCamden

    @timtower I meant the parameter in CreateItemAbility. You put the event name in the String Event that would call the ability. I thought that if any player event was called, PlayerEvent would be called too, so using that I could just get the Event Name of the event that called PlayerEvent and then if the String Event and the Name of the Event matched, ability would be called if the other requirements were met.
     
    Last edited: Aug 8, 2020
  7. Offline

    KarimAKL

    @BaddCamden The easiest way would probably just be creating your own Event that gets called everytime a PlayerEvent is called, by listening to every event that's a subclass of PlayerEvent, you can see the list in the Javadocs.

    You can do something like this:
    Code:Java
    1. public class AnyPlayerEvent extends Event {
    2.  
    3. public AnyPlayerEvent(PlayerEvent event) {}
    4.  
    5. public static AnyPlayerEventListener implements Listener {
    6. // Listen to all events here and call a new AnyPlayerEvent
    7. }
    8. }

    That's just a start though.

    Of course i know it'll take a long time to write this but, it'll be much easier in case you ever need this again in the future. You'll simply have to listen to this event and do whatever you want, instead of modifying every single event method.
     
  8. Offline

    BaddCamden

    Thank you so so so much! You don't know how much this will help me in the future!
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page