Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package io.github.bxnie.events;
- import java.util.HashMap;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Effect;
- import org.bukkit.Material;
- import org.bukkit.Particle;
- import org.bukkit.attribute.Attribute;
- import org.bukkit.entity.Donkey;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Horse;
- import org.bukkit.entity.Horse.Color;
- import org.bukkit.entity.Horse.Variant;
- import org.bukkit.entity.Llama;
- import org.bukkit.entity.Player;
- import org.bukkit.entity.SkeletonHorse;
- import org.bukkit.entity.ZombieHorse;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.vehicle.VehicleExitEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.scheduler.BukkitScheduler;
- import io.github.bxnie.FiorePlugin;
- public class HorseSpawn implements Listener {
- private HashMap<UUID, Long> cooldownwhite = new HashMap<UUID, Long>();
- private HashMap<UUID, Long> horsecombat = new HashMap<UUID, Long>();
- @EventHandler
- public void onPlayerInteract(PlayerInteractEvent e) {
- if(e.getAction() == Action.RIGHT_CLICK_AIR){
- Player p = e.getPlayer();
- ItemStack item = e.getItem();
- if(!(item.getType() == Material.SADDLE)) {
- return;
- } else {
- if(item.getItemMeta().getDisplayName().equals(ChatColor.WHITE + "White Horse")) {
- if (horsecombat.containsKey(p.getUniqueId()) && horsecombat.get(p.getUniqueId()) > System.currentTimeMillis()) {
- e.setCancelled(true);
- p.sendMessage(ChatColor.RED + "Your horse is afraid to come out..");
- } else {
- if(cooldownwhite.containsKey(p.getUniqueId()) && cooldownwhite.get(p.getUniqueId()) > System.currentTimeMillis()) {
- e.setCancelled(true);
- long remainingTime = cooldownwhite.get(p.getUniqueId()) - System.currentTimeMillis();
- 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");
- } else {
- cooldownwhite.put(p.getUniqueId(), System.currentTimeMillis() + (10 * 1000));
- if(item.getItemMeta().hasLore()) {
- if (p.hasPermission("fh.skin.skeletonactive") || p.hasPermission("fh.skin.zombieactive")) {
- if (p.hasPermission("fh.skin.skeletonactive")) {
- SkeletonHorse horsewhite = (SkeletonHorse) p.getWorld().spawn(p.getLocation(), SkeletonHorse.class);
- horsewhite.setAdult();
- horsewhite.setTamed(true);
- horsewhite.setOwner(p);
- horsewhite.getInventory().setSaddle(new ItemStack(Material.SADDLE));
- horsewhite.setPassenger(p);
- horsewhite.setJumpStrength(1.2);
- horsewhite.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.65);
- horsewhite.setInvulnerable(true);
- horsewhite.setCustomName(item.getItemMeta().getLore().get(2));
- horsewhite.setCustomNameVisible(true);
- }
- if (p.hasPermission("fh.skin.zombieactive")) {
- ZombieHorse horsewhite = (ZombieHorse) p.getWorld().spawn(p.getLocation(), ZombieHorse.class);
- horsewhite.setAdult();
- horsewhite.setTamed(true);
- horsewhite.setOwner(p);
- horsewhite.getInventory().setSaddle(new ItemStack(Material.SADDLE));
- horsewhite.setPassenger(p);
- horsewhite.setJumpStrength(1.2);
- horsewhite.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.65);
- horsewhite.setInvulnerable(true);
- horsewhite.setCustomName(item.getItemMeta().getLore().get(2));
- horsewhite.setCustomNameVisible(true);
- }
- } else {
- Horse horsewhite = (Horse) p.getWorld().spawn(p.getLocation(), Horse.class);
- horsewhite.setAdult();
- horsewhite.setTamed(true);
- horsewhite.setOwner(p);
- horsewhite.getInventory().setSaddle(new ItemStack(Material.SADDLE));
- horsewhite.setPassenger(p);
- horsewhite.setJumpStrength(1.2);
- horsewhite.setColor(Color.WHITE);
- horsewhite.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.65);
- horsewhite.setInvulnerable(true);
- horsewhite.setCustomName(item.getItemMeta().getLore().get(2));
- horsewhite.setCustomNameVisible(true);
- }
- }
- }
- }
- }
- }
- }
- }
- @EventHandler
- public void onPLayerDismount(VehicleExitEvent e) {
- if(e.getExited() instanceof Player) {
- if(e.getVehicle() instanceof Horse) {
- Horse horse = (Horse) e.getVehicle();
- if(horse.getCustomName() != null) {
- horse.remove();
- }
- }
- }
- }
- @EventHandler
- public void CombatChecker(EntityDamageByEntityEvent e) {
- if ((e.getEntity() instanceof Player) && (e.getDamager() instanceof Player)) {
- final Player player = (Player) e.getDamager();
- final Player target = (Player) e.getEntity();
- horsecombat.remove(player.getUniqueId());
- horsecombat.remove(target.getUniqueId());
- horsecombat.put(player.getUniqueId(), System.currentTimeMillis() + (15 * 1000));
- horsecombat.put(target.getUniqueId(), System.currentTimeMillis() + (15 * 1000));
- }
- }
- }
Add Comment
Please, Sign In to add comment