Atlatl kit potion effect

Discussion in 'Plugin Development' started by TCO_007, Jun 8, 2014.

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

    TCO_007

    Hello! I have successfully made the first part of my kit Atlatl. It shoots the arrow somewhat well (I would like to increase the velocity/distance of the arrow but unfortunately, I do not know how) and makes sure to remove one arrow from the inventory. However, when this arrow hits a player, I want it to give the player it hits the potion effect of Weakness 1 for 20 seconds. Unfortunately, I have no idea how to do this. If anyone could explain a way for me to input that into my code with a 45 second cool down of shooting arrows, that would be absolutely fantastic! Thanks!
    Code:java
    1. @EventHandler
    2. public void onAtlatlThrow(PlayerInteractEvent e){
    3. Player player = e.getPlayer();
    4. if (e.getAction() == Action.RIGHT_CLICK_AIR && player.getItemInHand().getType() == Material.ARROW){
    5. Arrow arrow = player.launchProjectile(Arrow.class);
    6. if (player.getGameMode() != GameMode.CREATIVE){
    7. if (player.getItemInHand().getAmount() > 1){
    8. player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
    9. arrow.setVelocity(player.getLocation().getDirection());
    10.  
    11. }else{
    12. arrow.setVelocity(player.getLocation().getDirection());
    13. player.setItemInHand(new ItemStack(Material.AIR)); }
    14. }
    15.  
    16. }
    17. }

    By the way, this code is in a seperate class from the main class.
     
  2. Offline

    Gater12

    TCO_007
    invoke .multiply(int i) to getDirection I believe. Attach metadata to the arrow to mark it as some special form of arrow (So not every arrow will cause the PotionEffect) Listen to EntityDamageByEntityEvent. Check if the damager is the arrow with the specified metadata and if the entity is a player. Apply potion effect to player.
     
  3. Offline

    TCO_007

    Sweet! I got velocity to work but I have never added metadata to an entity before. I have to an ItemStack but not an entity like an arrow. This is what I tried to put but it keeps trying to change it to an itemstack so I might need help with this.
    Code:java
    1. Arrow arrow = player.launchProjectile(Arrow.class);
    2. ItemMeta arrowmeta = arrow.getItemMeta();
    3. arrowmeta.setDisplayName(ChatColor.BLUE + "Spears");
    4. ArrayList<String> ArrowLore = new ArrayList<String>();
    5. ArrowLore.add(ChatColor.BLACK + "Shoot this at your enemy to slow them down!");
    6. arrowmeta.setLore(ArrowLore);
    7. arrow.setItemMeta(arrowmeta);

    Gater12
     
  4. Offline

    Gater12

  5. Offline

    TCO_007

    So should it look something like this? I am so sorry if its really easy and I am just completely missing it XD
    Code:java
    1. Arrow arrowdata = (Arrow) arrow.getMetadata("Spear");
    Gater12
     
  6. Offline

    Gater12

  7. Offline

    TCO_007

    Ok, I read that article so maybe I should ask this. Is what I am suppose to do involving .setMetadata()? Or does it use something else? Gater12

    So something like this? But what would fill in the null?
    Code:java
    1. arrow.setMetadata(null, null);

    Gater12

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page