Bukkit马禁用马产卵块

时间:2018-11-21 00:44:42

标签: minecraft bukkit

我需要知道是否有一种方法可以检查用户周围3半径内是否有任何块(不高于或低于)。目前,游戏中存在一个错误,即如果您在墙壁旁边的一匹马中产卵,则会在其中出现故障。在RPG服务器上,我不是特别想要那个。我正在尝试建立一个If语句,其中如果一个玩家在3左右的半径内周围有障碍物,它将显示“您的马没有空间,而不是产生它。”

感谢您的帮助

这是我当前的代码(很抱歉,该代码阅读时间很长):

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));
        }
    }
}

0 个答案:

没有答案