Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.filipenock.Addon.Habilidades;
- import java.util.HashMap;
- import java.util.Map;
- import org.bukkit.Material;
- import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
- import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.entity.EntityDamageEvent;
- import org.bukkit.event.entity.PlayerLeashEntityEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerItemHeldEvent;
- import org.bukkit.event.player.PlayerMoveEvent;
- import org.bukkit.util.Vector;
- import me.filipenock.Addon.Main;
- import me.filipenock.Addon.kit.KitAPI;
- import net.minecraft.server.v1_8_R3.EntityHuman;
- import net.minecraft.server.v1_8_R3.World;
- public class Grappler implements Listener
- {
- private Main plugin;
- Map<Player, CopyOfFishingHook> hooks;
- public Grappler(final Main plugin) {
- this.hooks = new HashMap<Player, CopyOfFishingHook>();
- this.plugin = plugin;
- }
- public Grappler() {
- this.hooks = new HashMap<Player, CopyOfFishingHook>();
- }
- @EventHandler
- public void onSlot(final PlayerItemHeldEvent e) {
- final Player p = e.getPlayer();
- if (KitAPI.grappler.contains(p.getName()) && this.hooks.containsKey(e.getPlayer())) {
- this.hooks.get(e.getPlayer()).remove();
- this.hooks.remove(e.getPlayer());
- }
- }
- @EventHandler
- public void onMove(final PlayerMoveEvent e) {
- final Player p = e.getPlayer();
- if (KitAPI.grappler.contains(p.getName()) && this.hooks.containsKey(e.getPlayer()) && !e.getPlayer().getItemInHand().getType().equals((Object)Material.LEASH)) {
- this.hooks.get(e.getPlayer()).remove();
- this.hooks.remove(e.getPlayer());
- }
- }
- @EventHandler
- public void onLeash(final PlayerLeashEntityEvent e) {
- final Player p = e.getPlayer();
- if (KitAPI.grappler.contains(p.getName()) && e.getPlayer().getItemInHand().getType().equals((Object)Material.LEASH)) {
- e.setCancelled(true);
- e.getPlayer().updateInventory();
- e.setCancelled(true);
- if (!this.hooks.containsKey(p)) {
- return;
- }
- if (!this.hooks.get(p).isHooked()) {
- return;
- }
- final double t;
- final double d = t = this.hooks.get(p).getBukkitEntity().getLocation().distance(p.getLocation());
- final double v_x = (1.0 + 0.07 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getX() - p.getLocation().getX()) / t;
- final double v_y = (1.0 + 0.03 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getY() - p.getLocation().getY()) / t;
- final double v_z = (1.0 + 0.07 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getZ() - p.getLocation().getZ()) / t;
- final Vector v = p.getVelocity();
- v.setX(v_x);
- v.setY(v_y);
- v.setZ(v_z);
- p.setVelocity(v);
- }
- }
- @EventHandler
- public void onDamageByFall(final EntityDamageEvent e) {
- if (e.getEntity() instanceof Player) {
- final Player player = (Player)e.getEntity();
- if (!KitAPI.grappler.contains(player.getName()) || e.getCause() != EntityDamageEvent.DamageCause.FALL) {
- return;
- }
- if (!this.hooks.containsKey(player)) {
- return;
- }
- if (this.hooks.get(player).isHooked()) {
- e.setDamage(e.getDamage() / 10.0);
- }
- }
- }
- @EventHandler
- public void onClick(final PlayerInteractEvent e) {
- final Player p = e.getPlayer();
- if (KitAPI.grappler.contains(p.getName()) && e.getPlayer().getItemInHand().getType().equals((Object)Material.LEASH)) {
- e.setCancelled(true);
- if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
- if (this.hooks.containsKey(p)) {
- this.hooks.get(p).remove();
- }
- final CopyOfFishingHook nmsHook = new CopyOfFishingHook((CraftWorld) p.getWorld(), (EntityHuman)((CraftPlayer)p).getHandle());
- nmsHook.spawn(p.getEyeLocation().add(p.getLocation().getDirection().getX(), p.getLocation().getDirection().getY(), p.getLocation().getDirection().getZ()));
- nmsHook.move(p.getLocation().getDirection().getX() * 5.0, p.getLocation().getDirection().getY() * 5.0, p.getLocation().getDirection().getZ() * 5.0);
- this.hooks.put(p, nmsHook);
- }
- else {
- if (!this.hooks.containsKey(p)) {
- return;
- }
- if (!this.hooks.get(p).isHooked()) {
- return;
- }
- final double t;
- final double d = t = this.hooks.get(p).getBukkitEntity().getLocation().distance(p.getLocation());
- final double v_x = (1.0 + 0.07 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getX() - p.getLocation().getX()) / t;
- final double v_y = (1.0 + 0.03 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getY() - p.getLocation().getY()) / t;
- final double v_z = (1.0 + 0.07 * t) * (this.hooks.get(p).getBukkitEntity().getLocation().getZ() - p.getLocation().getZ()) / t;
- final Vector v = p.getVelocity();
- v.setX(v_x);
- v.setY(v_y);
- v.setZ(v_z);
- p.setVelocity(v);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement