Can anyone see why this isnt firing?

Discussion in 'Plugin Development' started by dxwarlock, Jun 24, 2012.

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

    dxwarlock

    This is driving me mad, This seems to work fine for when a PLAYER shoots an arrow, I get the 'arrow shot" message fine..so its triggering.

    But Skeletons don't trigger the EntityShootBowEvent at all, anyone see anything I'm missing?

    Code:java
    1.  
    2. package me.dx.seasons.plugin;
    3.  
    4. import net.minecraft.server.MobEffect;
    5.  
    6. import org.bukkit.Effect;
    7. import org.bukkit.Location;
    8. import org.bukkit.World;
    9. import org.bukkit.craftbukkit.CraftWorld;
    10. import org.bukkit.craftbukkit.entity.CraftEntity;
    11. import org.bukkit.entity.Arrow;
    12. import org.bukkit.entity.Entity;
    13. import org.bukkit.entity.EntityType;
    14. import org.bukkit.entity.Skeleton;
    15. import org.bukkit.event.EventHandler;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.entity.CreatureSpawnEvent;
    18. import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    19. import org.bukkit.event.entity.EntityShootBowEvent;
    20. import org.bukkit.util.Vector;
    21.  
    22. public class MobListener implements Listener{
    23. private final Main plugin;
    24. public MobListener(Main plugin) {
    25. this.plugin = plugin;
    26. }
    27. //-----------------------------
    28. //Skele Arrows
    29. //-----------------------------
    30. @EventHandler
    31. public void onShoot(EntityShootBowEvent event) {
    32. plugin.log.info("ARROW SHOT");
    33. Entity e = (Entity) event.getEntity();
    34. if (e instanceof Skeleton) {
    35. if (event.getProjectile() instanceof Arrow) {
    36. Arrow a = (Arrow) event.getProjectile();
    37. a.setFireTicks(20);
    38. }
    39. }
    40. }
    41. //snip rest of class thats not related.
    42.  
     
  2. Offline

    FTWin01Gurl

    Instead, try getting the EntityDamagedByEntityEvent and compare if the hitter is a Skeleton, then set the entity's fire tick to 20.
     
  3. Offline

    dxwarlock

    Well that would work for the fire, but if I can get it working, was also going to add 'more arrows' fired with a synctask when they fired. :\

    But cant get it to trigger when anything but a player fires.
     
  4. Offline

    bartboy8

    did you register the event in the onEnable method in your main class?
     
  5. Offline

    dxwarlock

    I think I did it correctly, since it fires when a player shoots with the debug message, just not skeletons. have this in my on enable of Main:
    pm.registerEvents(new MobListener(this), this);

    and this in my class extends of Main:
    MobListener OnS = new MobListener(this);

    Main class snippet :
    Code:java
    1.  
    2. public class Main extends JavaPlugin implements Runnable {
    3. private static Main instance;
    4. public final Main playerListener = this;
    5. MobListener OnS = new MobListener(this);
    6. Lis lis = new Lis(this);
    7.  


    And on Enable snippet:
    Code:java
    1.  
    2. public void onEnable()
    3. {
    4. instance = this;
    5. this.getCommand("season").setExecutor(new Clis(this));
    6. PluginManager pm = getServer().getPluginManager();
    7. pm.registerEvents(new Lis(this), this);
    8. pm.registerEvents(new MobListener(this), this);
    9.  
     
  6. Offline

    JxAxVxAx

    Try This

    Change Your Code In onEnable To


    pm.registerEvents(new MobListener(), this);

    And delete MobListener OnS = new MobListener(this); from your extends of Main.

    If it doesnt works , then try not deleting MobListener OnS = new MobListener(this); .

    Hope It Helps :p
     
  7. Offline

    r0306

    That won't work at all since his Listener class has an instance of the main class so when registering the plugin, he must have the reference to the main in his constructor as well.
     
  8. Offline

    dxwarlock

    I get "constructor "MobListener()" is undefined"
    if I remove the 'this'. :\

    maybe add:

    public final Main EntityListener = this;
    and
    pm.registerEvents(new MobListener(EntityListener), this);

    ?
    Im about to try that.

    edit:scratch that, just realized that would do nothing..I can call it whatever I want..PlayerListener, EntityListener, JohnListner..it doesn't matter.

    so adding "Entity" to the name wont make it look for mobs...:p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  9. Offline

    r0306

    No. Leave it with "this." You didn't do anything wrong there. Are you sure that the event's not firing at all if it's a skeleton? Remove all other plugins to avoid a possible conflict.
     
  10. Offline

    dxwarlock

    here is the entire "trying to catch Skele arrow shot" class cleaned up to just the basics...Catching any arrow shot with a log of "Something shot arrow" and down to when a skele shoots with "Skele shot arrow:

    Bit still only fires when players shot, and gives the "something"..skele doesnt trigger even that.
    Code:java
    1.  
    2. package me.dx.seasons.plugin;
    3.  
    4. import org.bukkit.entity.Arrow;
    5. import org.bukkit.entity.Entity;
    6. import org.bukkit.entity.Skeleton;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.EntityShootBowEvent;
    10.  
    11. public class MobListener implements Listener{
    12. private final Main plugin;
    13. public MobListener(Main plugin) {
    14. this.plugin = plugin;
    15. }
    16. //-----------------------------
    17. //Skele Arrows
    18. //-----------------------------
    19. @EventHandler
    20. public void onShoot(EntityShootBowEvent event) {
    21. plugin.log.info("ARROW SHOT");
    22. Entity e = (Entity) event.getEntity();
    23. if (e instanceof Skeleton) {
    24. plugin.log.info("SKELO ARROW SHOT");
    25. if (event.getProjectile() instanceof Arrow) {
    26. Arrow a = (Arrow) event.getProjectile();
    27. a.setFireTicks(20);
    28. }
    29. }
    30. }
    31.  


    Yes its the only plugin in place other than permissions.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  11. Offline

    r0306

    dxwarlock
    Does it print the first "arrow shot"?
     
  12. Offline

    dxwarlock

    No, only when player fires does it trigger..the Skeleton doesnt trigger it. why I'm at a loss here.

    and there is code below it for "onCreatureSpawn" that triggers, so I know the class is catching events.
    is there there anything special I need to do to get it to catch 'creature action' events?
     
  13. Offline

    BH72

    Is it possible that skeletons do not actually fire the bow, that they are simply holding the bow for show and that the arrows that they shoot are just being spawned with the appropriate direction and velocity?
     
  14. Offline

    dxwarlock

    I thought that too. so I dug around the forums looking..it seems it SHOULD still trigger it.

    http://forums.bukkit.org/threads/entityshootbowevent.55239/
    This adds the EntityShootBowEvent, which is triggered when either a player releases a pulled bow, or when a Skeleton shoots an arrow.

    So maybe its bugged?
     
  15. I think its bugged, I cant find something about the shoout event inside the source:
    https://github.com/Bukkit/CraftBukk.../net/minecraft/server/EntitySkeleton.java#L19
    https://github.com/Bukkit/CraftBukk...aft/server/PathfinderGoalArrowAttack.java#L77
     
  16. Offline

    dxwarlock

    Yea, I'm still working on it, I went the looong about way of doing it.
    remaking my own EntitySkeleton and PathFinderGoalArrowAttack by copying and tweaking the default one,to changing the way the skeleton shoots... Now I can have Gatling Gun skeletons that hit you for 40 blocks away (not that I need them, but fun to play with on the test server to test it)

    lot more code, but it works :p

    And do you EVER sleep ferrybig?
     
  17. [offtopic]Its now 13:18 at the place where I am[/offtopic]
     
    r0306 likes this.
Thread Status:
Not open for further replies.

Share This Page