Solved Set entity UUIDs or name to identify 1 specific entity

Discussion in 'Plugin Development' started by Ward1246, May 12, 2015.

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

    Ward1246

    I need to set an entities UUID, or use some method to specify 1 entity out of all of them so i don't get teleported to the wrong entity. I have it so i can be teleported to only arrows, i would just like to set a UUID to a arrow.


    OLD POST (open)
    I'm making a hookshot plugin, but i have some code that can't be reached. The code that can't be reached can't be moved because moving it would cause a variable to be undefined.
    Code:
            @EventHandler
            public void onPlayerInteract(PlayerInteractEvent event) {
                    if (!(event.getAction() == Action.RIGHT_CLICK_AIR)) return;
               
                    if (!(event.getItem().getType() == Material.ARROW)) return;
               
                    Arrow a = event.getPlayer().launchProjectile(Arrow.class);
                    a.setVelocity(a.getVelocity().multiply(3));
                    Location a2 = a.getLocation();
                    a.getWorld().playEffect(a2, Effect.SMOKE, 1);
    
    // if i separate this, a becomes undefined. I can't define a AFAIK because a is the projectile event. I can't put them together like this because then the string event is unreachable
                
                    if (!(event.getAction() == Action.RIGHT_CLICK_AIR)) return;
               
                    if (!(event.getItem().getType() == Material.STRING)) return;
               
            final Player player = event.getPlayer();
            Location loc = a.getLocation();
            player.teleport(loc);
            }
    
    
    I am trying to teleport to entity "a" which is an arrow after i fire it.

    Is there any loopholes to this problem? If you need to know more, ill tell more about it. It's hard for me to explain. Thanks
     
    Last edited: May 13, 2015
  2. Offline

    Zombie_Striker

    What Line is at fault? What is making it return?
     
  3. Offline

    Ward1246

    It's not that. I will try to be as clear as i can. If i leave the code like that, the Right click string event is never triggered. If i separate the two codes like this:
    Show Spoiler

    Code:
      @EventHandler
            public void onPlayerInteract(PlayerInteractEvent event) {
                    if (!(event.getAction() == Action.RIGHT_CLICK_AIR)) return;
             
                    if (!(event.getItem().getType() == Material.ARROW)) return;
             
                    Arrow a = event.getPlayer().launchProjectile(Arrow.class);
                    a.setVelocity(a.getVelocity().multiply(3));
                    Location a2 = a.getLocation();
                    a.getWorld().playEffect(a2, Effect.SMOKE, 1);
    }
    // separated
                 @EventHandler
            public void onPlayerInteract(PlayerInteractEvent event) {
                    if (!(event.getAction() == Action.RIGHT_CLICK_AIR)) return;
             
                    if (!(event.getItem().getType() == Material.STRING)) return;
             
            final Player player = event.getPlayer();
            Location loc = a.getLocation();
    // creating variable a again, but this creates another projectile with this code, making you teleport where you are right now.
    Arrow a = event.getPlayer().launchProjectile(Arrow.class);
            player.teleport(loc);
            }
    

    I need to something different with the Arrow a = event.getPlayer().launchProjectile(Arrow.class); in the string part, I am not sure what though, or if there is a different solution.
     
    Last edited: May 12, 2015
  4. Offline

    Gater12

    @Ward1246
    What is it that you are trying to accomplish?
     
  5. Offline

    Ward1246

    I want shoot an arrow when right clicking an arrow item, then teleport the player shooting the arrow to that arrow when right clicking string.
     
    Zombie_Striker likes this.
  6. Offline

    Zombie_Striker

    • For what you posted, you don't need a final player (Unless there is more to that method)
    • Instead of checking what it is not (e.g. != rightclick), check what it is (e.g. == RightClick).
    EDIT:

    Check if the player is holding String. Else, Check if its an arrow.
     
  7. Offline

    Ward1246

    Should it look like this?
    Code:
    @EventHandler
            public void onPlayerInteract(PlayerInteractEvent event) {
                final Player player = event.getPlayer();
                if (player.getItemInHand().getType() == Material.ARROW) {
    
                    Arrow a = event.getPlayer().launchProjectile(Arrow.class);
                    a.setVelocity(a.getVelocity().multiply(3));
                    Location a2 = a.getLocation();
                    a.getWorld().playEffect(a2, Effect.SMOKE, 1);
                } else {
            if (player.getItemInHand().getType() == Material.STRING) {
    //a cant be resolved here V
            Location loc = a.getLocation();
            player.teleport(loc);
            }
                }
            }
            
    If so, i still have that one problem, "a" cannot be resolved. Other than that the rest is fine.
     
  8. Offline

    Gater12

    @Ward1246
    Are you looking for to teleport the player when they right click a String to the arrow shot previously by the 'arrow-item'? Kind of like teleporting arrows but with the option of teleporting them to it?

    It's kind of what I understand from your attempt.
     
  9. Offline

    Ward1246

    Yeah, that's about it.
     
  10. Offline

    Zombie_Striker

    Try Casting the Arrow. Also, remove the final modifier, there is no use for it here.

    [EDIT] you are a python user. Please store the Arrow A outside of this method in an Map of UUIDS,Arrows
     
  11. Offline

    Ward1246

    The "final Player player = event.getPlayer();"? If I remove that, all of the "player" variables I put in become undefined, I couldn't get it to cast properly, it didn't work. I will try the last idea.
     
  12. Offline

    Gater12

    @Ward1246
    You have to store a reference of that Arrow to the Player (e.g. Map previously stated). Make sure also to clean up after yourself.

    Remove final modifer not the whole line.
     
  13. Offline

    Ward1246

    Oh, I misread that, ok I removed the final modifier. Fixing up the reference of the arrow to the player.
     
  14. Offline

    Zombie_Striker

    Just two Questions for you @Ward1246 ; Did you learn python, the only language I know that would allow A to be reached, and have you actually learned Java?
     
  15. Offline

    Ward1246

    I have learned java, and a good amount of python.

    [DELETED]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  16. Offline

    Ward1246

    I am using the original method again. I got it working by switching the two around and tampering with the code. Now the question is: How should i identify the arrow? I can't seem to figure out and remember how to set the arrows UUID.
    ------------------------------------------------------------------------------------------------------------------------------

    Edited post so that i don't necro. I never added my solution but i found one and it worked. I did something in the wrong order, and switching them fixed it.
     
    Last edited: Jun 27, 2015
Thread Status:
Not open for further replies.

Share This Page