How to change what my sword shoots?

Discussion in 'Plugin Development' started by MrTurtle, Apr 22, 2014.

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

    MrTurtle

    Hello I wanted to know how can I change what my custom sword shoots all it can do is shoot a arrow but I want it to shoot a custom arrow how can I do this? Hope I can get some help :D
    Code:java
    1.  
    2. @EventHandler
    3.  
    4. public void onInteract(PlayerInteractEvent e) {
    5. final Player p = e.getPlayer();
    6.  
    7.  
    8. if(e.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getItemMeta().getDisplayName().contains("Arrow")) {
    9. p.launchProjectile(Arrow.class);
    10.  
    11.  
    12. }
    13. }
     
  2. Offline

    amhokies

    Define "custom arrow"
     
  3. Offline

    MrTurtle

  4. Offline

    TGRHavoc

    I think something like (This would be in "CustomArrow.java" class):
    Code:java
    1. public class CustomArrow extends Arrow{
    2.  
    3. }
     
  5. Offline

    Garris0n

    He means that you should define "custom arrow".
     
  6. Offline

    amhokies

    MrTurtle
    Yes, I was unsure exactly what you meant by the term "custom arrow."
     
  7. If you mean what I think you mean then
    Arrow arrow = p.launchProjectile(Arrow.class);
    Then you can do whatever you want to the arrow with
    arrow.Whatever

    Hope this is what u needed :D
     
  8. Offline

    MrTurtle

    amhokies
    By custom arrow I mean its a arrow I made so when it hits a block it plays a effect
     
  9. MrTurtle, your code is correct, ignore the post above me
    Code:java
    1. List<UUID> arrows; //Put at the top above onEnable
    2. arrows = new HashMap<UUID>(); //Put in OnEnable
    3. Arrow arrow = p.launchProjectile(Arrow.class); //Put under OnInteract thing
    4. arrows.add(arrow.getUniqueId());
    //Put under OnInteract thing

    Then on ProjectileHitEvent
    Code:java
    1. public void onHit(ProjectileHitEvent e) {
    2. if (e.getEntityType().equals(EntityType.ARROW)) {
    3. Arrow arrow = (Arrow) e.getEntity();
    4. if (arrows.contains(arrow.getUniqueId())) {
    5. //PlaySound Here
    6. }
    7. }
    8. }
     
  10. Offline

    MrTurtle

    Synapz
    The PlayerInterActionEvent is for when a player right clicks or left clicks on a sword name "Arrow" it shoots my custom arrow

    WD_MUFFINFLUFFER
    What goes in the <UUID>?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  11. Basically the code adds the arrows UniqueId to the list
    Code:
    arrows.add(arrow.getUniqueId());
    Then it checks if the arrow is in the list when it lands on something:
    Code:
    if(arrows.contains(arrow.getUniqueId())){
    After that, just play your sound and remove the arrow from the list
    Code:
    arrows.remove(arrow.getUniqueId());
     
Thread Status:
Not open for further replies.

Share This Page