SHARE
TWEET

Untitled

a guest Jan 24th, 2020 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.veilmc.hcf.timer;
  2.  
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.Sound;
  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.player.PlayerFishEvent;
  15. import org.bukkit.event.player.PlayerInteractEvent;
  16. import org.bukkit.util.Vector;
  17.  
  18. import net.veilmc.hcf.utils.DurationFormatter;
  19.  
  20. public class GrappleTimer extends PlayerTimer implements Listener {
  21.    
  22.     public GrappleTimer() {
  23.         super("Grapple Hook", TimeUnit.SECONDS.toMillis(5L));
  24.         // TODO Auto-generated constructor stub
  25.     }
  26.  
  27.     public static String grappleName = "Grapple Hook";
  28.     public static String grappleLore = "This is real.";
  29.    
  30.     public boolean isGrappleHook(Player player) {
  31.         if(player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + grappleName) && player.getItemInHand().getItemMeta().getLore().contains(ChatColor.GRAY + grappleLore)) {
  32.             return true;
  33.         }else{
  34.             return false;
  35.         }
  36.     }
  37.    
  38.     @EventHandler
  39.     public void onInteract(PlayerInteractEvent event) {
  40.    
  41.         if ((event.getItem() == null) || ((event.getAction() != Action.RIGHT_CLICK_AIR) && (event.getAction() != Action.RIGHT_CLICK_BLOCK)) || (event.getItem().getType() != Material.FISHING_ROD)) {
  42.           return;
  43.         }
  44.        
  45.         if(this.getRemaining(event.getPlayer()) > 0L) {
  46.             event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou still have &6&l" + grappleName + " &ccooldown for another &l" + DurationFormatter.getRemaining(this.getRemaining(event.getPlayer()), true) + "&r&cs."));
  47.             event.getPlayer().updateInventory();
  48.             event.setCancelled(true);
  49.         }
  50.     }
  51.    
  52.     @EventHandler
  53.     public void grapple(PlayerFishEvent event) {
  54.         try {
  55.             Player p = event.getPlayer();
  56.             Location h = event.getHook().getLocation();
  57.             Location h2 = new Location(h.getWorld(), h.getX(), h.getY() + 1.0, h.getZ());
  58.             h.getBlock().getLocation().setY(h.getBlock().getLocation().getY() - 1.0);
  59.             if (p != null && this.isGrappleHook(p) && ((event.getState() == PlayerFishEvent.State.FAILED_ATTEMPT) || event.getState() == PlayerFishEvent.State.IN_GROUND)) {
  60.                 Location pl = p.getLocation();
  61.                 int x1 = pl.getBlockX();
  62.                 int y1 = pl.getBlockZ();
  63.                 Location loc = event.getHook().getLocation();
  64.                 int x2 = loc.getBlockX();
  65.                 int y2 = loc.getBlockZ();
  66.                 loc.setY(loc.getY() - 1.0);
  67.                 if ((x1 != x2 && y1 != y2 && loc.getBlock().getType() != Material.AIR && loc.getBlock().getType() != Material.STATIONARY_WATER) || h2.getBlock().getType() != Material.AIR || event.getState() == PlayerFishEvent.State.IN_GROUND) {
  68.                     double kyori = loc.distance(pl);
  69.                     double y3 = loc.getY();
  70.                     loc.setY(y3 + 1.0);
  71.                     Vector vec = pl.toVector();
  72.                     Vector vec2 = loc.toVector();
  73.                     p.setVelocity(vec2.subtract(vec).normalize().multiply(kyori / 4.5));
  74.                     p.playSound(p.getLocation(), Sound.ZOMBIE_INFECT, 10.0f, 2.0f);
  75.                     this.setCooldown(p, p.getUniqueId(), this.defaultCooldown, false);
  76.                 }
  77.                 else {
  78.                     p.sendMessage(ChatColor.RED + "too quickly!");
  79.                     if(this.getRemaining(event.getPlayer()) > 0L) {
  80.                         this.clearCooldown(p);
  81.                     }
  82.                 }
  83.             }
  84.         }
  85.         catch (NullPointerException ex) {}
  86.     }
  87.    
  88.     @EventHandler
  89.     public void onDamage(EntityDamageEvent event) {
  90.         try {
  91.             if (event.getEntity() instanceof Player) {
  92.                 Player p = (Player)event.getEntity();
  93.                 if (p.getItemInHand().getType() == Material.FISHING_ROD && this.isGrappleHook(p) && event.getCause() == EntityDamageEvent.DamageCause.FALL) {
  94.                     event.setDamage(event.getDamage() / 3.5);
  95.                 }else{
  96.                     return;
  97.                 }
  98.             }
  99.         }
  100.         catch (NullPointerException ex) {
  101.            
  102.         }
  103.     }
  104.  
  105.     @Override
  106.     public ChatColor getScoreboardPrefix() {
  107.         // TODO Auto-generated method stub
  108.         return ChatColor.GOLD;
  109.     }
  110. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top