Give player my buffed items

Discussion in 'Plugin Development' started by DogeDebugger, Oct 28, 2014.

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

    DogeDebugger

    Hello Bukkiteers!

    Ok, so i coded a plugin that lets you shoot bows and teleport where the arrow lands.
    I figured out that players who want to use the bow as a normal bow will not want this to happen. So i added a feature where you get a special bow in your inventory by doing /grapplegun which has the teleportation charatheristic.

    I can make the command give me a bow, but how do i make it so that it gives me the custom bow? At the moment, all bows shoot teleport arrows and /grapplegun just gives you a bow.

    Code for command:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. if(sender instanceof Player){
    3. Player player = (Player) sender;
    4. if(cmd.getName().equalsIgnoreCase("grapplegun"));
    5. player.getInventory().addItem(new ItemStack(Material.ARROW));
    6. }
    7. return false;
    8. }


    Code for teleport bow:
    Code:java
    1. @EventHandler
    2. public void onProjectileHit(ProjectileHitEvent event) {
    3.  
    4. Entity entity = event.getEntity();
    5.  
    6. if (entity instanceof Arrow) {
    7.  
    8. Arrow arrow = (Arrow) entity;
    9.  
    10. Entity shooter = arrow.getShooter();
    11.  
    12. if (shooter instanceof Player) {
    13.  
    14. Player player = (Player) shooter;
    15.  
    16. player.teleport(new Location(arrow.getWorld(), arrow
    17.  
    18. .getLocation().getX(), arrow.getLocation().getY(),
    19.  
    20. arrow.getLocation().getZ(), player.getLocation()
    21.  
    22. .getYaw(), player.getLocation().getPitch()));
    23.  
    24. }


    I'm guessing i have to save the bow as a variable and make the command give me that, but i don't know how to save the certain bow...help please!
     
  2. Offline

    Fhbgsdhkfbl

    DogeDebugger
    You can check for a certain display name the item has.
     
  3. Offline

    DogeDebugger

  4. Offline

    wesley27

    DogeDebugger What Fhbgsdhkfbl said is correct. You have the right idea, you're just going at the wrong item. You said it yourself, where the arrow lands is where you are teleported to. Therefore, it is the arrow that is causing the teleportation, not the bow. So, regardless of the bow, every arrow will do this.

    To fix this, rather than changing the name of the bow, you'll have to change the name of the arrow. Whether you want to have a command that gives the player a custom arrow for "grappling" or not, that is up to you. But instead of the bow, you'll need to check the lore of the arrow before teleporting the player. If the arrow has a lore "Grappler" (or whatever you choose), it will teleport the person. If it's a normal arrow, or has another lore, it won't teleport them.
     
  5. Offline

    DogeDebugger

    wesley27
    OOOOHHH i get it "lore" is the name of the item yesh? And thank you for your helpful attitude :3
     
  6. Offline

    wesley27

    DogeDebugger Yes, lore is the actual term for the "name" of the item. You'll need to use the getLore() method to check it. And no problem, just glad to help :)

    If you need help or have more issues with the code once you write it and test it, be sure to tag me in your reply.

    EDIT: Oh, and I'm not entirely sure as to how the lore would work with an arrow once it's been shot.. this may require some testing. I don't know if when an arrow is embedded in the ground, whether it keeps its lore or not. So you may have to(and it'd be easiest probably) to check the lore of the arrow before the player shoots it.
     
  7. Offline

    DogeDebugger

    wesley27
    Thanks for all your help! :D

    Just tested it, ah no it doesn't work :(
     
    korikisulda likes this.
  8. Offline

    wesley27

    DogeDebugger Post some code and explain what isn't working, are there any errors, or a stacktrace?
     
  9. Offline

    DogeDebugger

    wesley27
    No, just the arrow landing thing :p
     
  10. Offline

    wesley27

    DogeDebugger I'm sorry it's not clear.. you mean that it is still teleporting you to the arrow no matter what? If you post your code maybe we can help make it work :p
     
  11. Offline

    DogeDebugger

    wesley27
    No no no, it's just as you said that the arrow won't keep its lore after being picked up :p I'll fix it myself cuz i big boy nao >:D
     
  12. DogeDebugger When the player shoots a bow, check if it's with your special bow. If it is, add the arrow & who fired it to some sort of collection. Then when it lands, you can check if it was fired by your special bow.
     
    korikisulda likes this.
  13. Offline

    Monkey_Swag

    DogeDebugger
    - Check if your bow's displayname or lore is equal to whatever name you want it to have
    - If it is, teleport the player to the landing location of the arrow.

    If you have any other problems just tag me and I'll be able to help
     
  14. Monkey_Swag That's basically what I said except less helpful :p
     
  15. Offline

    Monkey_Swag

    AdamQpzm what happens when I don't really read others' posts when trying to help at 3 am :p
     
    AdamQpzm likes this.
  16. Offline

    DogeDebugger

    My problem was that my arrow doesn't keep its lore after being picked up, but I don't really have concerns on that.
    Thanks Monkey_Swag AdamQpzm and wesley27 for help! :D
     
    wesley27, Monkey_Swag and AdamQpzm like this.
Thread Status:
Not open for further replies.

Share This Page