Solved Shoot fishingline out of leash (Grappler)

Discussion in 'Plugin Development' started by jensdeboom, Apr 3, 2014.

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

    jensdeboom

    Hi everyone,
    I know there are already over 20 posts about grappler but i still cant figure out why mine doesnt work. This is my code (yes most of it is based on code from others):

    Code:java
    1. import org.bukkit.Location;
    2. import org.bukkit.craftbukkit.v1_7_R1.CraftWorld;
    3. import org.bukkit.entity.Player;
    4.  
    5. import net.minecraft.server.v1_7_R1.EntityFishingHook;
    6. import net.minecraft.server.v1_7_R1.Item;
    7. import net.minecraft.server.v1_7_R1.ItemStack;
    8.  
    9. import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
    10.  
    11. public class LeashRod extends EntityFishingHook {
    12. private Item item;
    13.  
    14. public LeashRod(Player player, Item item2){
    15. super(((CraftWorld) player.getWorld()).getHandle(), ((CraftPlayer) player).getHandle());
    16. item2 = this.item = item2;
    17. }
    18. @Override
    19. public void h(){
    20. if(item != null){
    21. ItemStack hand = this.owner.bD();
    22. boolean shouldRemove = false;
    23.  
    24. if(this.owner.dead || !(this.owner.isAlive())){
    25. shouldRemove = true;
    26. }
    27.  
    28. if(hand == null){
    29. shouldRemove = true;
    30. } else {
    31. if(hand.getItem() != item){
    32. shouldRemove = true;
    33. }
    34. }
    35.  
    36. if(this.e(this.owner) > 1024.0D){
    37. shouldRemove = true;
    38. }
    39.  
    40. if(shouldRemove){
    41. super.die();
    42. super.owner.hookedFish = null;
    43. }
    44. }
    45. }
    46.  
    47. public void spawn(Location loc){
    48. net.minecraft.server.v1_7_R1.World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
    49.  
    50. nmsWorld.addEntity(this);
    51. this.setPosition(loc.getX(), loc.getY(), loc.getZ());
    52. }
    53. }


    Code:java
    1. public void onPlayerFish(PlayerFishEvent e){
    2. Player p = e.getPlayer();
    3. if(kitGrappler.contains(p.getName())){
    4. if(e.getState() == State.CAUGHT_ENTITY){
    5. grappleTo(p, e.getCaught().getLocation());
    6. }else if(e.getState() == State.IN_GROUND){
    7. grappleTo(p, e.getHook().getLocation());
    8. }else{
    9. p.sendMessage(ChatColor.RED + "The hook is not attached yet!");
    10. e.setCancelled(true);
    11. }
    12. }
    13. }
    14.  
    15. @EventHandler
    16. public void onInteract(PlayerInteractEvent event){
    17. Player p = event.getPlayer();
    18. Item item = (Item) net.minecraft.server.v1_7_R1.Item.REGISTRY.a("lead");
    19. if ((kitGrappler.contains(p.getName())) && (
    20. ((event.getAction() == Action.LEFT_CLICK_AIR) && (event.getMaterial() == Material.LEASH)) || ((event.getAction() == Action.LEFT_CLICK_BLOCK) && (event.getMaterial() == Material.LEASH)))) {
    21. event.setCancelled(true);
    22. LeashRod fish = new LeashRod(p, (net.minecraft.server.v1_7_R1.Item) item);
    23. Location location = p.getLocation();
    24. fish.spawn(location);
    25. Vector v = p.getLocation().getDirection().multiply(3);
    26. List<Entity> hooks = p.getNearbyEntities(2, 2, 2);
    27. for(Entity e : hooks){
    28. if(e.getType() == EntityType.FISHING_HOOK){
    29. e.setVelocity(v);
    30. }
    31. }
    32. }
    33. }
    34.  
    35. public static void grappleTo(Entity paramEntity, Location paramLocation){
    36. Location localLocation = paramEntity.getLocation();
    37. localLocation.setY(localLocation.getY() + 0.5D);
    38. paramEntity.teleport(localLocation);
    39. double d1 = -0.08D;
    40. double d2 = paramLocation.distance(localLocation);
    41. double d3 = d2;
    42. double d4 = (1.0D + 0.07000000000000001D * d3) * (paramLocation.getX() - localLocation.getX()) / d3;
    43. double d5 = (1.0D + 0.03D * d3) * (paramLocation.getY() - localLocation.getY()) / d3 - 0.5D * d1 * d3;
    44. double d6 = (1.0D + 0.07000000000000001D * d3) * (paramLocation.getZ() - localLocation.getZ()) / d3;
    45. Vector localVector = paramEntity.getVelocity();
    46. localVector.setX(d4);
    47. localVector.setY(d5);
    48. localVector.setZ(d6);
    49. paramEntity.setVelocity(localVector);
    50. }


    There is no fishing line coming out of the leash. No errors. I hope someone can help me :)
    ~ jens
     
  2. Offline

    MooshViolet

    Two problems I see just in those classes.
    1. Have you registered events? I dont know if anyone of those is your main class but you need to register events in your main class.

    You can easily do this with implementing listener and:
    Code:java
    1. this.getServer.getPluginManager.registerEvents(this, this);
    2. //However that is only registering for the main class. You have to register for your other classes aswell


    2. On line 1 of the second java code you gave us, you did not put an
    Code:java
    1. @EventHandler

    Above your onPlayerFishEvent.
     
  3. Offline

    jensdeboom

    MooshViolet
    I will check this when i am back on my computer. I'm pretty sure i put the @EventHandler, just didn't paste it.
    For registering it would be this.getServer().getPluginManager().registerEvents(LeashRod, this) ?
     
  4. Offline

    d3v1n302418

    It would be getServer().getPluginManager().registerEvents(this, new Eventclassname());
     
  5. Offline

    jensdeboom

    Ok, sorry that i didnt reply earlier to this thread but i cant manage to register the events of the other class.
    i tried, like d3v1n302418 said, to do
    Code:java
    1. getServer().getPluginManager().registerEvents(this, new LeashRod();

    but that gave me red lines under "registerEvents" and "new LeashRod".
    So when i hovered over it, Eclipse told me to fix it kinda like this:
    Code:java
    1. getServer().getPluginManager().registerEvents(this, (Plugin) new LeashRod(null, null));

    It fixes the red lines but it doesnt work in-game. If anyone can tell me how i can register the events from my other class, plz do so! MooshViolet ?
     
  6. Offline

    Code0

    Your code is really complicated :/. You could do it way easier.
     
  7. Offline

    jensdeboom

    Code0 k feel free to tell me. I searched pretty hard and most people say this: "Bukkit doesn't like spawning in fishing hooks without a fishing rod. You will need to override the h() method." But, if you really found an easy way to do this i would love to hear it!
     
  8. Offline

    Dahwn

    jensdeboom
    You are trying to code something with NMS but don't even know how to register events...
     
  9. Offline

    jensdeboom

    Dahwn can you tell me how to do it or are you just here to post stupid comments that don't help at all? I made pretty big things with bukkit and im not a beginner anymore. So i am trying to learn something new, but how am i supposed to learn something when someone like you comment these things. I think they made the forums for people that have questions about coding when they can't find an answer for their problem themselves, even if they its a really stupid problem. I've seen much more stupid questions and I don't think there is any need for posting comments like this. Thank you very much for your comment, it helped me a lot.

    ~ jens
     
  10. Offline

    Dahwn

    jensdeboom

    In your onEnable method:
    Code:java
    1. getServer().getPluginManager().registerEvents(new LeashRod(), this;

    not
    Code:java
    1. getServer().getPluginManager().registerEvents(this, new LeashRod();

    -Dahwn
     
  11. Offline

    jensdeboom

    Dahwn Thanks for helping me. You are probably not someone like i explained in my last pots :p, sorry for that. So if i do what you told me to do, it still gives me a red line under "new LeashRod()" and i told me to make it:
    Code:java
    1. getServer().getPluginManager().registerEvents(new LeashRod(null, null), this);

    This probably sounds super noobish but when i registered my other classes before, it never told me to add these parameters. Does the null, null need to be there or did i do something wrong?

    EDIT: My fish, interact and grappleto aren't in my LeashRod() class so why do i have to register events there? Does the h() method count as an event?
    ~ jens
     
  12. Offline

    Dahwn

    jensdeboom
    So this is probably the problem, I didn't read the first post good enough, I'm sorry, Hopefully you added to the class where you have Interact and PlayerFishEvent in "implements Listener" you have to register this class how I told you in the last post!:
    Code:java
    1. getServer().getPluginManager().registerEvents(new "yourlistenerclass"(), this;

    -Dahwn
     
  13. Offline

    jensdeboom

    Dahwn ok but my events are in my main class. I already had it doing
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);

    and my other events in the main class work. So there is probably something wrong with the LeashRod() class.
    In my onEnable i just registered the events in the main class. Should i link the LeashRod() class to the main class in any other way you can think off?
    ~ jens
     
  14. Offline

    Dahwn

    jensdeboom
    What isn't working now? If it doesn't even spawn the custom hook then your LeashRod class isn't working. Then you will probably have to search another one.. I have a working one but I don't want to give it away because everyone wants grappler with lead! :)
    -Dahwn
     
  15. Offline

    jensdeboom

    Dahwn yeah i understand that. I will try it again now and i will tell you if it works or not in 5 min.
    ~ jens

    Dahwn It didn't work :( . I will try something else now. I will post my new code when im done

    Dahwn i searched for some other methods but none of them worked. I felt like a read 738282 Posts and i was tired af. So i saw 1 other post and i was like, ok this is the last one. If this doesn't work grappler can ** **** *******. First i checked if the post was outdated but it was from a few days ago. I looked for the name and guess what his name was? Dahwn! Yep, i found your post. I fixed the problem you had with it (looked if damager was a projectile and if the shooter was = the entity) and i managed to get it working. Like 5 minutes after i fixed it. Someone just send me the exact code...Anyway, thanks everyone for your help!

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

    Dahwn

    jensdeboom
    See you only copy pasted it from me..
    I should've deleted it!
    You only stole my code -.-
     
  17. Offline

    mrgreen33gamer

    Bump, I really want to see this complete :p
     
  18. Offline

    jensdeboom

    Dahwn your code was not working and someone send me the code anyway...you cant finish your code so why could i not use it? I fixed it and used it, yes.
     
  19. Offline

    Dahwn

    jensdeboom
    I fixed my code hahaha? btw. maybe I coded this on my own and don't want anyone else to use it?

    mrgreen33gamer It's complete, thanks to copy paste my ideas! Can't even register events! gg
     
  20. Offline

    jensdeboom

    Dahwn lol? Are u kidding me? First, it turned out i didnt even have to register events from that class so ur stupid. And u cant (in your post) even check if the shooter of the damager = entity... But alright...ill use the other code now go cry a bit. Ty
     
  21. Offline

    Dahwn

    jensdeboom You didn't post your whole code so I couldn't even see the whole system of your plugin, get ignored!
     
  22. Offline

    mrgreen33gamer

  23. Offline

    vRiiP

    Can you guys send me a download link or something for this plugin? Or atleast show me the code and tell me how to compile it?
     
Thread Status:
Not open for further replies.

Share This Page