Solved Where to add a permission to a plugin with no commands?

Discussion in 'Plugin Development' started by croc122, Oct 12, 2014.

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

    croc122

    I'm currently learning Java, so I decided to decompile some plugins in order to learn what makes them tick. There is one plugin that I always wish had a single permission so that it could be used as a donator perk and that is SethBling's (youtuber) Homing Arrows plugin. Unfortunately, Seth doesn't add permissions to any of his plugins as he doesn't expect them to be used on large servers. I no longer have a server anymore, so I won't be using this plugin on my server.
    So anyway, here is the decompiled code (it is two class files). Just tell me at which line number I should add the permission and the best way to approach it. Thank you!

    Class File #1
    Code:java
    1. package com.sethbling.blinghomingarrows;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Location;
    5. import org.bukkit.Server;
    6. import org.bukkit.entity.Arrow;
    7. import org.bukkit.entity.Entity;
    8. import org.bukkit.entity.LivingEntity;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.EntityShootBowEvent;
    12. import org.bukkit.plugin.PluginManager;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.util.Vector;
    15.  
    16. public class BlingHomingArrows
    17. extends JavaPlugin
    18. implements Listener
    19. {
    20. public void onEnable()
    21. {
    22. getLogger().info("BlingGravity has been loaded.");
    23. getServer().getPluginManager().registerEvents(this, this);
    24. }
    25.  
    26. public void onDisable()
    27. {
    28. getLogger().info("BlingGravity has been unloaded.");
    29. }
    30.  
    31. @EventHandler
    32. public void eventArrowFired(EntityShootBowEvent e)
    33. {
    34. if (((e.getEntity() instanceof LivingEntity)) && ((e.getProjectile() instanceof Arrow)))
    35. {
    36. LivingEntity player = e.getEntity();
    37.  
    38. double minAngle = 6.283185307179586D;
    39. Entity minEntity = null;
    40. for (Entity entity : player.getNearbyEntities(64.0D, 64.0D, 64.0D)) {
    41. if ((player.hasLineOfSight(entity)) && ((entity instanceof LivingEntity)) && (!entity.isDead()))
    42. {
    43. Vector toTarget = entity.getLocation().toVector().clone().subtract(player.getLocation().toVector());
    44. double angle = e.getProjectile().getVelocity().angle(toTarget);
    45. if (angle < minAngle)
    46. {
    47. minAngle = angle;
    48. minEntity = entity;
    49. }
    50. }
    51. }
    52. if (minEntity != null) {
    53. new HomingTask((Arrow)e.getProjectile(), (LivingEntity)minEntity, this);
    54. }
    55. }
    56. }
    57. }


    Class File #2
    Code:java
    1. package com.sethbling.blinghomingarrows;
    2.  
    3. import org.bukkit.Effect;
    4. import org.bukkit.Location;
    5. import org.bukkit.World;
    6. import org.bukkit.entity.Arrow;
    7. import org.bukkit.entity.LivingEntity;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.Plugin;
    10. import org.bukkit.scheduler.BukkitRunnable;
    11. import org.bukkit.util.Vector;
    12.  
    13. public class HomingTask
    14. extends BukkitRunnable
    15. {
    16. private static final double MaxRotationAngle = 0.12D;
    17. private static final double TargetSpeed = 1.4D;
    18. Arrow arrow;
    19. LivingEntity target;
    20.  
    21. public HomingTask(Arrow arrow, LivingEntity target, Plugin plugin)
    22. {
    23. this.arrow = arrow;
    24. this.target = target;
    25. runTaskTimer(plugin, 1L, 1L);
    26. }
    27.  
    28. public void run()
    29. {
    30. double speed = this.arrow.getVelocity().length();
    31. if ((this.arrow.isOnGround()) || (this.arrow.isDead()) || (this.target.isDead()))
    32. {
    33. cancel();
    34. return;
    35. }
    36. Vector toTarget = this.target.getLocation().clone().add(new Vector(0.0D, 0.5D, 0.0D)).subtract(this.arrow.getLocation()).toVector();
    37.  
    38. Vector dirVelocity = this.arrow.getVelocity().clone().normalize();
    39. Vector dirToTarget = toTarget.clone().normalize();
    40. double angle = dirVelocity.angle(dirToTarget);
    41.  
    42.  
    43.  
    44. double newSpeed = 0.9D * speed + 0.13999999999999999D;
    45. if (((this.target instanceof Player)) && (this.arrow.getLocation().distance(this.target.getLocation()) < 8.0D))
    46. {
    47. Player player = (Player)this.target;
    48. if (player.isBlocking()) {
    49. newSpeed = speed * 0.6D;
    50. }
    51. }
    52. Vector newVelocity;
    53. Vector newVelocity;
    54. if (angle < 0.12D)
    55. {
    56. newVelocity = dirVelocity.clone().multiply(newSpeed);
    57. }
    58. else
    59. {
    60. Vector newDir = dirVelocity.clone().multiply((angle - 0.12D) / angle).add(dirToTarget.clone().multiply(0.12D / angle));
    61. newDir.normalize();
    62. newVelocity = newDir.clone().multiply(newSpeed);
    63. }
    64. this.arrow.setVelocity(newVelocity.add(new Vector(0.0D, 0.03D, 0.0D)));
    65. this.arrow.getWorld().playEffect(this.arrow.getLocation(), Effect.SMOKE, 0);
    66. }
    67. }

     
  2. croc122 You can put player.hasPermission() anywhere you like ;)
     
  3. Offline

    croc122

    AdamQpzm okay thanks, wasn't sure if it mattered where
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page