Help with Projectiles

Discussion in 'Plugin Development' started by AussieBacom, Mar 30, 2012.

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

    AussieBacom

    Is it possible to make a TNT explosion when the Bottle O' Enchanting hit the ground?

    If so, could someone run me through with an example on how to structure the class, thanks.
     
  2. Offline

    CorrieKay

    First, you need to listen for ProjectileHitEvent. Then grab the event.getEntity(), and check if its an instanceof ThrownExpBottle, if so, grab the location of the entity, and do location.getWorld()createExplosion(location, 4);

    If you really want, i can give you the exact code to do this, but i think you'll learn better by figuring it out yourself c:

    edit: hehe, this is fun
     
    AussieBacom likes this.
  3. Offline

    AussieBacom

    Cheers corrie, i prefer to learn for myself otherwise ill never get anywhere by copy and paste :)

    I'm having a problem with the ProjectileHitEvent:
    Code:
    public void ProjectileHitEvent(ProjectileHitEvent event) {
     
       
    }
    It says it cant resolve "ProjectileHitEvent" to a type.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
    CorrieKay likes this.
  4. Offline

    CorrieKay

    try adding the import manually: "import org.bukkit.event.entity.ProjectileHitEvent;"
     
    AussieBacom likes this.
  5. Offline

    AussieBacom

    So far I have come up with this:
    Code:
    public void ProjectileHitEvent(ProjectileHitEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof  ThrownExpBottle){
            TNTPrimed tnt = (TNTPrimed) entity;
            event.getEntity().getWorld().createExplosion(tnt.getLocation(), 0);
     
        }
    It doesn't seem to be working, any pointers?
     
  6. Offline

    CorrieKay

    few issues, youre trying to typecast the exp potion into TNT, that wont work.
    Youre missing your event handler annotation, and youre missing your closing bracket. :eek:

    as far as the code goes, even if you didnt get a typecast error for the (TNTPrimed)entity thing, you dont need to create an explosion at a location containing tnt.

    all you need to do is find out if the projectile is a thrown exp bottle. If that, grab the location (event.getLocation()) and do
    location.getWorld().createExplosion(location, int power[4 is the power of a creeper])

    No need to even deal with TNTPrimed :3
     
    AussieBacom likes this.
  7. Offline

    AussieBacom

    I finally got it working and found out the problem I was having.
    The explosions work more smoothly with a creeper kind of explosion. :)
    I had to make a Listener Class.
    I had to register the listener as well.
    Thank you so much!, finally my very first plugin works :)
     
    CorrieKay likes this.
Thread Status:
Not open for further replies.

Share This Page