Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PetsUtils {
- public static HashMap<String, Integer> mounter = new HashMap<String, Integer>();
- public static void spawnWolf(Player p){
- WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
- make(new CustomLoup(nmsWorld), p);
- }
- public static void spawnHorse(Player p){
- WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
- CustomCheval nmsEntity = new CustomCheval(nmsWorld);
- Horse bEntity = (Horse) nmsEntity.getBukkitEntity();
- bEntity.setVariant(Variant.HORSE);
- bEntity.setColor(Color.WHITE);
- bEntity.setTamed(true);
- bEntity.setOwner(p);
- bEntity.getInventory().setSaddle(new ItemStack(Material.SADDLE));
- make(nmsEntity, p);
- }
- public static void spawnPig(Player p){
- WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
- make(new CustomPig(nmsWorld), p);
- }
- public static void spawnSheep(Player p){
- WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
- make(new CustomSheep(nmsWorld), p);
- }
- public static void spawnChicken(Player p){
- WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
- make(new CustomPoulet(nmsWorld), p);
- }
- public static void spawnMushCow(Player p){
- WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
- make(new CustomCow(nmsWorld), p);
- }
- public static void spawnOcelot(Player p){
- WorldServer nmsWorld = ((CraftWorld) p.getLocation().getWorld()).getHandle();
- make(new CustomOcelot(nmsWorld), p);
- }
- private static void addMounter(int ID, Player p){
- if(!mounter.containsKey(p.getName())){
- mounter.put(p.getName(), ID);
- }
- }
- public static void removeMounter(Player p){
- if(mounter.containsKey(p.getName())){
- int ID = mounter.get(p.getName());
- for(Entity e : p.getWorld().getEntities()){
- if(e.getEntityId() == ID){
- e.remove();
- mounter.remove(p.getName());
- break;
- }
- }
- }
- }
- private static void make(EntityLiving nmsEntity, Player player){
- if(!canSummonMount(player.getLocation())){
- player.sendMessage("§cVous ne pouvez pas avoir votre monture ici !");
- return;
- }
- LivingEntity mount = (LivingEntity) nmsEntity.getBukkitEntity();
- Location loc = player.getLocation();
- World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
- nmsEntity.setPosition(loc.getX(), loc.getY() + 0.3, loc.getZ());
- nmsWorld.addEntity(nmsEntity, SpawnReason.CUSTOM);
- mount.setMaxHealth(mount.getMaxHealth());
- mount.setPassenger(player);
- removeMounter(player);
- addMounter(mount.getEntityId(), player);
- }
- public static boolean canSummonMount(Location location) {
- org.bukkit.World world = location.getWorld();
- Block block = location.getBlock();
- for(int x = location.getBlockX() - 1; x <= location.getBlockX() + 1; x++){
- for(int y = location.getBlockY(); y <= location.getBlockY() + 1; y++){
- for(int z = location.getBlockZ() - 1; z <= location.getBlockZ() + 1; z++){
- block = world.getBlockAt(x, y, z);
- if (block.getType().isSolid()) return false;
- }
- }
- }
- return true;
- }
- public static void removeAllPets(){
- for(Player p : Bukkit.getOnlinePlayers()){
- PetsUtils.removeMounter(p);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment