Solved Issue Handling PlayerEvent

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

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


    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.


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

    public void PlayerEvent(PlayerEvent event) {"PlayerEvent Activated");
    for(@SuppressWarnings("rawtypes") ArrayList Abilities : AbilityData) {"Ability: "+Abilities.get(0).toString());"Event: "+Abilities.get(1).toString());"Item: "+(ItemStack) Abilities.get(2));"ItemType: "+Abilities.get(3).toString());"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);
    } 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 Administrator Moderator

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


    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


    @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 Administrator 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


    @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. @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:
    1. public class AnyPlayerEvent extends Event {
    3. public AnyPlayerEvent(PlayerEvent event) {}
    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


    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