Advertisement
Guest User

Grappler

a guest
Apr 28th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.74 KB | None | 0 0
  1. package me.filipenock.Addon.Habilidades;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import org.bukkit.Material;
  7. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  8. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.block.Action;
  13. import org.bukkit.event.entity.EntityDamageEvent;
  14. import org.bukkit.event.entity.PlayerLeashEntityEvent;
  15. import org.bukkit.event.player.PlayerInteractEvent;
  16. import org.bukkit.event.player.PlayerItemHeldEvent;
  17. import org.bukkit.event.player.PlayerMoveEvent;
  18. import org.bukkit.util.Vector;
  19.  
  20. import me.filipenock.Addon.Main;
  21. import me.filipenock.Addon.kit.KitAPI;
  22. import net.minecraft.server.v1_8_R3.EntityHuman;
  23. import net.minecraft.server.v1_8_R3.World;
  24.  
  25. public class Grappler implements Listener
  26. {
  27.     private Main plugin;
  28.     Map<Player, CopyOfFishingHook> hooks;
  29.    
  30.     public Grappler(final Main plugin) {
  31.         this.hooks = new HashMap<Player, CopyOfFishingHook>();
  32.         this.plugin = plugin;
  33.     }
  34.    
  35.     public Grappler() {
  36.         this.hooks = new HashMap<Player, CopyOfFishingHook>();
  37.     }
  38.    
  39.     @EventHandler
  40.     public void onSlot(final PlayerItemHeldEvent e) {
  41.         final Player p = e.getPlayer();
  42.         if (KitAPI.grappler.contains(p.getName()) && this.hooks.containsKey(e.getPlayer())) {
  43.             this.hooks.get(e.getPlayer()).remove();
  44.             this.hooks.remove(e.getPlayer());
  45.         }
  46.     }
  47.    
  48.     @EventHandler
  49.     public void onMove(final PlayerMoveEvent e) {
  50.         final Player p = e.getPlayer();
  51.         if (KitAPI.grappler.contains(p.getName()) && this.hooks.containsKey(e.getPlayer()) && !e.getPlayer().getItemInHand().getType().equals((Object)Material.LEASH)) {
  52.             this.hooks.get(e.getPlayer()).remove();
  53.             this.hooks.remove(e.getPlayer());
  54.         }
  55.     }
  56.    
  57.     @EventHandler
  58.     public void onLeash(final PlayerLeashEntityEvent e) {
  59.         final Player p = e.getPlayer();
  60.         if (KitAPI.grappler.contains(p.getName()) && e.getPlayer().getItemInHand().getType().equals((Object)Material.LEASH)) {
  61.             e.setCancelled(true);
  62.             e.getPlayer().updateInventory();
  63.             e.setCancelled(true);
  64.             if (!this.hooks.containsKey(p)) {
  65.                 return;
  66.             }
  67.             if (!this.hooks.get(p).isHooked()) {
  68.                 return;
  69.             }
  70.             final double t;
  71.             final double d = t = this.hooks.get(p).getBukkitEntity().getLocation().distance(p.getLocation());
  72.             final double v_x = (1.0 + 0.07 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getX() - p.getLocation().getX()) / t;
  73.             final double v_y = (1.0 + 0.03 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getY() - p.getLocation().getY()) / t;
  74.             final double v_z = (1.0 + 0.07 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getZ() - p.getLocation().getZ()) / t;
  75.             final Vector v = p.getVelocity();
  76.             v.setX(v_x);
  77.             v.setY(v_y);
  78.             v.setZ(v_z);
  79.             p.setVelocity(v);
  80.         }
  81.     }
  82.    
  83.     @EventHandler
  84.     public void onDamageByFall(final EntityDamageEvent e) {
  85.         if (e.getEntity() instanceof Player) {
  86.             final Player player = (Player)e.getEntity();
  87.             if (!KitAPI.grappler.contains(player.getName()) || e.getCause() != EntityDamageEvent.DamageCause.FALL) {
  88.                 return;
  89.             }
  90.             if (!this.hooks.containsKey(player)) {
  91.                 return;
  92.             }
  93.             if (this.hooks.get(player).isHooked()) {
  94.                 e.setDamage(e.getDamage() / 10.0);
  95.             }
  96.         }
  97.     }
  98.    
  99.     @EventHandler
  100.     public void onClick(final PlayerInteractEvent e) {
  101.         final Player p = e.getPlayer();
  102.         if (KitAPI.grappler.contains(p.getName()) && e.getPlayer().getItemInHand().getType().equals((Object)Material.LEASH)) {
  103.             e.setCancelled(true);
  104.             if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
  105.                 if (this.hooks.containsKey(p)) {
  106.                     this.hooks.get(p).remove();
  107.                 }
  108.                 final CopyOfFishingHook nmsHook = new CopyOfFishingHook((CraftWorld) p.getWorld(), (EntityHuman)((CraftPlayer)p).getHandle());
  109.                 nmsHook.spawn(p.getEyeLocation().add(p.getLocation().getDirection().getX(), p.getLocation().getDirection().getY(), p.getLocation().getDirection().getZ()));
  110.                 nmsHook.move(p.getLocation().getDirection().getX() * 5.0, p.getLocation().getDirection().getY() * 5.0, p.getLocation().getDirection().getZ() * 5.0);
  111.                 this.hooks.put(p, nmsHook);
  112.             }
  113.             else {
  114.                 if (!this.hooks.containsKey(p)) {
  115.                     return;
  116.                 }
  117.                 if (!this.hooks.get(p).isHooked()) {
  118.                     return;
  119.                 }
  120.                 final double t;
  121.                 final double d = t = this.hooks.get(p).getBukkitEntity().getLocation().distance(p.getLocation());
  122.                 final double v_x = (1.0 + 0.07 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getX() - p.getLocation().getX()) / t;
  123.                 final double v_y = (1.0 + 0.03 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getY() - p.getLocation().getY()) / t;
  124.                 final double v_z = (1.0 + 0.07 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getZ() - p.getLocation().getZ()) / t;
  125.                 final Vector v = p.getVelocity();
  126.                 v.setX(v_x);
  127.                 v.setY(v_y);
  128.                 v.setZ(v_z);
  129.                 p.setVelocity(v);
  130.             }
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement