Whats wrong with the way I'm firing this event

Discussion in 'Spigot Plugin Development' started by WildPvPer, Jun 30, 2016.

  1. What is wrong with the way I'm trying to fire this event?

    Code (Text):
    if ((args.length == 1) && (args[0].equalsIgnoreCase("testvote")) && (sender.hasPermission("vc.testvote")))
          {
            VoteEventListener event = new VoteEventListener();
            voteEventListener.onVotifierEvent(event);
    onVotifierEvent has an error

    onVotifierEvent is a event handler in the class VoteEventListener fyi
     
  2. If only I remembered my crystal ball to tell me what the error was :p

    Sorry :)


    Can you post what the error was. I can't give you help/advice with nothing to work off of.
     
  3. @Hunky524
    I haven't even been able to get it out of Eclipse yet but anyways- The method onVotifierEvent (VotifierEvent) in the type VotifierEventListener is not applicable for the arguments (VoteEventListener)
     
  4. That means you are giving it the wrong arguments.

    This line:
    Code (Java):
    voteEventListener.onVotifierEvent(event);
     
  5. @Hunky524
    What argument should i give it then?
     
  6. Code (Text):
    Bukkit.getPluginManager().callEvent(event);
     
    • Agree Agree x 1
  7. I have no idea. What does the method say it needs, or can you show your voteEventListener class?
     
  8. @Hunky524
    Here's the class-
    Code (Text):
    package me.awesomehenderson.votecelebration;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;

    import com.vexsoftware.votifier.model.VotifierEvent;

    public class VoteEventListener
      implements Listener
      {
           
       
      @EventHandler
      public void onVotifierEvent(VotifierEvent event)
      {
         
       if (VoteCelebration.onlyVoters.booleanValue())
        {
          @SuppressWarnings("deprecation")
        Player player = Bukkit.getPlayer(event.getVote().getUsername());
           if ((player != null) && (player.isOnline())) {
            VoteCelebration.includedPlayers.add(player.getUniqueId());
          }
        }
        int difference = VoteCelebration.getVotesNeeded() - VoteCelebration.getTotalVotes();
        if (VoteCelebration.voteMessages.containsKey(Integer.valueOf(difference))) {
          VoteCelebration.getInstance().broadcastMessage((String)VoteCelebration.voteMessages.get(Integer.valueOf(difference)));
        }
        if (VoteCelebration.getTotalVotes() == VoteCelebration.getVotesNeeded()) {
          VoteCelebration.triggerDropParty();
        }
      }
           
         


       

    }
     
     

  9. Did you make these classes?





    Either way, these two lines of code here:
    Code (Java):
    VoteEventListener event = new VoteEventListener();
    voteEventListener.onVotifierEvent(event);
    Are giving you issues.




    As seen in the VoteEventListener class, this method:
    Code (Java):
    public void onVotifierEvent(VotifierEvent event)
    takes a VotifierEvent object as its parameter, but you are giving it a VoteEventListener object as its parameters.
     
  10. @Hunky524
    About 6 months ago yes, then i took a break from coding and i forgot how to fix it ;/
     
  11. @Hunky524
    How would i fix the problem?
     
  12. If that's a custom event, just use the callEvent method.
     
  13. @Hunky524
    I don't know if you would call it custom so to say. It's a votifier eventhandler in a different class that I'm trying to register to a command in the main class, and have no idea how to do it. And also, callEvent doesn't work i've tried
     
  14. JamesJ

    Supporter

    Bukkit#getPluginManager#callEvent(event)
     
  15. A Listener isn't an Event...

    You're passing a square peg in a round hole, that's why it's complaining. You fire events, you receive them on Listeners.

    What are you actually trying to accomplish?
     
  16. @JamesJ
    I've tried that but i get errors
    Code (Text):
    if ((args.length == 1) && (args[0].equalsIgnoreCase("testvote")) && (sender.hasPermission("dropparty.testvote")))
          {
              VoteEventListener voteEventListener = new VoteEventListener();
            Bukkit.getPluginManager().callEvent(voteEventListener);
         
          }
    .callEvent has the error and then wants to change the code to this-
    Code (Text):
     if ((args.length == 1) && (args[0].equalsIgnoreCase("testvote")) && (sender.hasPermission("dropparty.testvote")))
          {
              Event voteEventListener = new VoteEventListener();
            Bukkit.getPluginManager().callEvent(voteEventListener);
    Now new VoteEventListener(); has the error and wants to change the code back to the first piece of code i posted its just a cycle of it and neither of them work
     
  17. @1Rogue
    The command /vc testvote sends a fakevote to the VoteEventListener class that registers both fake votes & actual votes then that class registers to the other classes telling them to take votes of the vote counter once the vote counter is at 0 the party begins
     
  18. So you have a listener, you would register it as such via PluginManager#registerEvents.

    If you're firing an event, then you should be firing something which extends the Event class, not a Listener. They're two separate classes and definitely should not be used within the same class.
     
  19. @1Rogue
    I have it registered -
    Code (Text):
        getServer().getPluginManager().registerEvents(voteEventListener, this);
    So i should make another class that extends Event to fire my VoteEventListener class?