Checking if a painting was shot by an arrow, and get the player that shot it

Discussion in 'Plugin Development' started by teuneboon, Oct 5, 2011.

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

    teuneboon

    So I had the idea to create an archery plugin for my server. I thought it would be easiest if I'd just make a painting which has a bullseye drawn on it(everyone who joins my server has a specific mod and texture pack installed) and then detect wether it was shot in bukkit.

    My first intuition was to use the ENTITY_DAMAGE event. But some test and a look in the source code told me that that was only being called when it was about a LivingEntity.

    Next I noticed the PaintingBreakByEntityEvent, I thought: wow, that's it! But when I use that and do a simple event.getRemover().getEntityId() it's always the same entityId. Is this a bug?

    Anyone has another idea on how to do this(without a painting is also fine, but I do want some nice graphics for the thing you shoot at, red + white wool in rings would also be fine for example, but I don't know a BlockHitByProjectile event).
     
  2. Offline

    Nitnelave

    projectileHitEvent?
     
  3. Offline

    teuneboon

    That seems to only return you the projectile, not the painting it actually hits.
     
  4. Offline

    Nitnelave

    well, get the location of the projectile, and compare it with a list of paintings location you stored along the way.
     
  5. Offline

    teuneboon

    Yeah, could do that, but I'd rather have a solution that's a bit "nicer/cleaner"
     
  6. I think you should listen to a PAINTING_BREAK event.

    It should be something like this:

    Code:java
    1. public void onPaintingBreak(PaintingBreakEvent event) {
    2. if (event instanceof PaintingBreakByEntityEvent) {
    3. PaintingBreakByEntityEvent pEvent = (PaintingBreakByEntityEvent) event;
    4. if (pEvent.getRemover() instanceof Arrow) {
    5. //do stuff
    6. }
    7. }
    8. }
     
  7. @teuneboon If you use the above code, you can do
    Code:java
    1. (Projectile) pEvent.getRemover().getShooter();
     
  8. Fixed. :p
     
  9. Offline

    Pasukaru

    Dont forget the following line to prevent ClassCastExceptions:
    Code:java
    1. if( pEvent.getRemover() instanceof Projectile )


    [Edit]
    opps, didn't notice you added it in a previous post. :p
     
Thread Status:
Not open for further replies.

Share This Page