Question How can i make this event only apply to an itemmeta and not any bow.

Discussion in 'Bukkit Help' started by BenXII, Apr 1, 2020.

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

    BenXII

    I am trying to make a plugin where the bow that teleports the player to where the arrrow is shot only applys to the itemMeta bow that i made. If that makes sense.



    public class TeleportBow implements Listener {

    @EventHandler
    public void onProjectileHit(ProjectileHitEvent e) {
    if (e.getEntity().getShooter() instanceof Player) {
    Player player = (Player) e.getEntity().getShooter();
    if(player.getInventory().getItemInMainHand().getType().equals(Material.BOW)) {
    if (e.getHitBlock() == null) {
    player.teleport(e.getHitEntity());
    } else if (e.getHitEntity() == null) {
    player.teleport(e.getHitBlock().getLocation().add(0,1,0));


    }
    }
    }

    }



    }

    This is a different class in the same package:

    import java.util.ArrayList;


    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    import net.md_5.bungee.api.ChatColor;

    public class teleportbow implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if (sender instanceof Player) {
    Player player = (Player) sender;
    ItemStack teleportbow = new ItemStack(Material.BOW);

    ItemMeta bowMeta = teleportbow.getItemMeta();

    bowMeta.setDisplayName(ChatColor.BOLD + "Teleportation Bow");

    ArrayList<String> lore = new ArrayList<String>();
    lore.add("This bow allows you to teleport to where your arrow lands!");
    lore.add("Custom Item Only On CrabMC!");
    bowMeta.setLore(lore);

    bowMeta.addEnchant(Enchantment.ARROW_INFINITE, 1, false);
    bowMeta.setUnbreakable(true);

    bowMeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
    bowMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
    bowMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);

    teleportbow.setItemMeta(bowMeta);
    player.getInventory().addItem(teleportbow);
    player.sendMessage("You have been given the teleport bow!");
    }


    return true;

    }


    }

    This is the Main Class
    import org.bukkit.plugin.java.JavaPlugin;


    public class TeleportationBow extends JavaPlugin{

    public static boolean onCommand() =

    public static void main(String[] args) {


    }

    @Override
    public void onEnable() {
    getCommand("teleportbow").setExecutor(new teleportbow());


    }




    }
     
Thread Status:
Not open for further replies.

Share This Page