Guest User

Untitled

a guest
Nov 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. package io.github.bxnie.events;
  2.  
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Effect;
  9. import org.bukkit.Material;
  10. import org.bukkit.Particle;
  11. import org.bukkit.attribute.Attribute;
  12. import org.bukkit.entity.Donkey;
  13. import org.bukkit.entity.Entity;
  14. import org.bukkit.entity.Horse;
  15. import org.bukkit.entity.Horse.Color;
  16. import org.bukkit.entity.Horse.Variant;
  17. import org.bukkit.entity.Llama;
  18. import org.bukkit.entity.Player;
  19. import org.bukkit.entity.SkeletonHorse;
  20. import org.bukkit.entity.ZombieHorse;
  21. import org.bukkit.event.EventHandler;
  22. import org.bukkit.event.Listener;
  23. import org.bukkit.event.block.Action;
  24. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  25. import org.bukkit.event.player.PlayerInteractEvent;
  26. import org.bukkit.event.vehicle.VehicleExitEvent;
  27. import org.bukkit.inventory.ItemStack;
  28. import org.bukkit.plugin.Plugin;
  29. import org.bukkit.scheduler.BukkitScheduler;
  30.  
  31. import io.github.bxnie.FiorePlugin;
  32.  
  33. public class HorseSpawn implements Listener {
  34.  
  35. private HashMap<UUID, Long> cooldownwhite = new HashMap<UUID, Long>();
  36.  
  37. private HashMap<UUID, Long> horsecombat = new HashMap<UUID, Long>();
  38.  
  39. @EventHandler
  40. public void onPlayerInteract(PlayerInteractEvent e) {
  41. if(e.getAction() == Action.RIGHT_CLICK_AIR){
  42. Player p = e.getPlayer();
  43. ItemStack item = e.getItem();
  44.  
  45. if(!(item.getType() == Material.SADDLE)) {
  46. return;
  47. } else {
  48. if(item.getItemMeta().getDisplayName().equals(ChatColor.WHITE + "White Horse")) {
  49. if (horsecombat.containsKey(p.getUniqueId()) && horsecombat.get(p.getUniqueId()) > System.currentTimeMillis()) {
  50. e.setCancelled(true);
  51. p.sendMessage(ChatColor.RED + "Your horse is afraid to come out..");
  52. } else {
  53. if(cooldownwhite.containsKey(p.getUniqueId()) && cooldownwhite.get(p.getUniqueId()) > System.currentTimeMillis()) {
  54. e.setCancelled(true);
  55. long remainingTime = cooldownwhite.get(p.getUniqueId()) - System.currentTimeMillis();
  56. p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Horses" + ChatColor.DARK_GRAY + "]" + ChatColor.GRAY + ChatColor.ITALIC + " You cannot spawn your horse for another " + ChatColor.RED + ChatColor.ITALIC + remainingTime/1000 + ChatColor.GRAY + ChatColor.ITALIC + " seconds");
  57. } else {
  58. cooldownwhite.put(p.getUniqueId(), System.currentTimeMillis() + (10 * 1000));
  59. if(item.getItemMeta().hasLore()) {
  60. if (p.hasPermission("fh.skin.skeletonactive") || p.hasPermission("fh.skin.zombieactive")) {
  61. if (p.hasPermission("fh.skin.skeletonactive")) {
  62. SkeletonHorse horsewhite = (SkeletonHorse) p.getWorld().spawn(p.getLocation(), SkeletonHorse.class);
  63. horsewhite.setAdult();
  64. horsewhite.setTamed(true);
  65. horsewhite.setOwner(p);
  66. horsewhite.getInventory().setSaddle(new ItemStack(Material.SADDLE));
  67. horsewhite.setPassenger(p);
  68. horsewhite.setJumpStrength(1.2);
  69. horsewhite.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.65);
  70. horsewhite.setInvulnerable(true);
  71. horsewhite.setCustomName(item.getItemMeta().getLore().get(2));
  72. horsewhite.setCustomNameVisible(true);
  73. }
  74. if (p.hasPermission("fh.skin.zombieactive")) {
  75. ZombieHorse horsewhite = (ZombieHorse) p.getWorld().spawn(p.getLocation(), ZombieHorse.class);
  76. horsewhite.setAdult();
  77. horsewhite.setTamed(true);
  78. horsewhite.setOwner(p);
  79. horsewhite.getInventory().setSaddle(new ItemStack(Material.SADDLE));
  80. horsewhite.setPassenger(p);
  81. horsewhite.setJumpStrength(1.2);
  82. horsewhite.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.65);
  83. horsewhite.setInvulnerable(true);
  84. horsewhite.setCustomName(item.getItemMeta().getLore().get(2));
  85. horsewhite.setCustomNameVisible(true);
  86. }
  87. } else {
  88. Horse horsewhite = (Horse) p.getWorld().spawn(p.getLocation(), Horse.class);
  89. horsewhite.setAdult();
  90. horsewhite.setTamed(true);
  91. horsewhite.setOwner(p);
  92. horsewhite.getInventory().setSaddle(new ItemStack(Material.SADDLE));
  93. horsewhite.setPassenger(p);
  94. horsewhite.setJumpStrength(1.2);
  95. horsewhite.setColor(Color.WHITE);
  96. horsewhite.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.65);
  97. horsewhite.setInvulnerable(true);
  98. horsewhite.setCustomName(item.getItemMeta().getLore().get(2));
  99. horsewhite.setCustomNameVisible(true);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. @EventHandler
  109. public void onPLayerDismount(VehicleExitEvent e) {
  110. if(e.getExited() instanceof Player) {
  111. if(e.getVehicle() instanceof Horse) {
  112. Horse horse = (Horse) e.getVehicle();
  113. if(horse.getCustomName() != null) {
  114. horse.remove();
  115. }
  116. }
  117. }
  118. }
  119. @EventHandler
  120. public void CombatChecker(EntityDamageByEntityEvent e) {
  121. if ((e.getEntity() instanceof Player) && (e.getDamager() instanceof Player)) {
  122. final Player player = (Player) e.getDamager();
  123. final Player target = (Player) e.getEntity();
  124. horsecombat.remove(player.getUniqueId());
  125. horsecombat.remove(target.getUniqueId());
  126. horsecombat.put(player.getUniqueId(), System.currentTimeMillis() + (15 * 1000));
  127. horsecombat.put(target.getUniqueId(), System.currentTimeMillis() + (15 * 1000));
  128. }
  129. }
  130. }
Add Comment
Please, Sign In to add comment