This doesn't work for some reason

Discussion in 'Plugin Development' started by GamingGo2011, May 23, 2022.

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

    GamingGo2011

    I'm current trying to make a plugin that implements an explosive bow and arrow such that when I shoot, there is an explosion where the arrow lands, I have the items themselves implemented,
    but I need a way to detect if both the bow and arrow are being used to shoot the arrow, all traces I have found lead to this file:
    Events.java:
    Code:
    package me.GamingGo2011.explosivearrows.events;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Projectile;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityShootBowEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    
    import me.GamingGo2011.explosivearrows.Main;
    import me.GamingGo2011.explosivearrows.explosivebow.CustomBow;
    
    public class Events implements Listener {
      @SuppressWarnings("unused")
    private Main plugin;
    
      public Events(Main plugin) {
        this.plugin = plugin;
        Bukkit.getPluginManager().registerEvents(this, (Plugin)plugin);
      }
    
    @SuppressWarnings("unused")
    @EventHandler
      public void explosive(EntityShootBowEvent ev) {
        ItemStack bow = ev.getBow();
        Entity e = ev.getEntity();
        Projectile p = (Projectile)ev.getProjectile();
        if (bow.getItemMeta().equals(CustomBow.Explosive_bow.getItemMeta()) && p.getLocation().getBlock().getType() != null) {}
            p.getWorld().createExplosion(p.getLocation(), 2.0f);
            return;
      }
    }
    (There is no setting for code snippet that says "Java")
    The bow and arrow are in my inventory, I can shoot, but the explosions don't work.
     
  2. Online

    timtower Administrator Administrator Moderator

    @GamingGo2011 That is because you have {} after your if statement.
    And my guess is that the item meta is not the same.
     
  3. Offline

    KarimAKL

    For future reference, you can use this:
    [Syntax=Java]Code here[/Syntax]
     
  4. Offline

    GamingGo2011

    @timtower That's what I'm trying to figure out
     
  5. Online

    timtower Administrator Administrator Moderator

    Then check the displayname, lore, idk what you have on that item.
     
  6. Offline

    GamingGo2011

    @timtower I changed my code to a nested if statement so I can check the conditions one by one using chat messages, the item metas are the same, I just can't detect when the arrow hits the ground
     
  7. Offline

    KarimAKL

    You can use the ProjectileHitEvent for that.
     
Thread Status:
Not open for further replies.

Share This Page