public static CustomEntityPlayer newInstance(org.bukkit.entity.Player playerDuplicate) { WorldServer worldServer = ((CraftWorld) playerDuplicate.getWorld()).getHandle(); CustomEntityPlayer player = new CustomEntityPlayer( worldServer.getMinecraftServer(), worldServer, ((CraftPlayer) playerDuplicate).getHandle().getProfile(), new PlayerInteractManager(worldServer)); Location loc = playerDuplicate.getLocation(); player.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); ((Player) player.getBukkitEntity()).setItemInHand(playerDuplicate.getItemInHand()); ((Player) player.getBukkitEntity()).setCustomName(playerDuplicate.getName()); ((Player) player.getBukkitEntity()) .getEquipment() .setArmorContents(playerDuplicate.getInventory().getArmorContents()); player.setInventory( new ArrayList<ItemStack>(Arrays.asList(playerDuplicate.getInventory().getContents()))); player.getBukkitEntity().setGameMode(GameMode.SURVIVAL); player.getBukkitEntity().setCanPickupItems(false); ((Player) player.getBukkitEntity()).setHealthScale(playerDuplicate.getHealthScale()); ((Player) player.getBukkitEntity()).setMaxHealth(playerDuplicate.getMaxHealth()); ((Player) player.getBukkitEntity()).setHealth(playerDuplicate.getHealth()); ((Player) player.getBukkitEntity()).setRemoveWhenFarAway(false); worldServer.addEntity(player, SpawnReason.CUSTOM); return player; }
public static Sheep spawn(Location location) { MinecraftServer server = MinecraftServer.getServer(); WorldServer world = server.getWorldServer(0); for (WorldServer ws : server.worlds) { if (ws.getWorld().getName().equals(location.getWorld().getName())) { world = ws; break; } } World mcWorld = (World) ((CraftWorld) location.getWorld()).getHandle(); final SheepNPC customEntity = new SheepNPC(world); customEntity.setLocation( location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); ((CraftLivingEntity) customEntity.getBukkitEntity()).setRemoveWhenFarAway(false); mcWorld.addEntity(customEntity, CreatureSpawnEvent.SpawnReason.CUSTOM); return (CraftSheep) customEntity.getBukkitEntity(); }