Exemplo n.º 1
0
  static Player getOfflinePlayer(String player, UUID uuid) {
    Player pplayer = null;
    try {
      File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");

      for (File playerfile : playerfolder.listFiles()) {
        String filename = playerfile.getName();
        String playername = filename.substring(0, filename.length() - 4);

        GameProfile profile = new GameProfile(uuid, playername);

        if (playername.trim().equalsIgnoreCase(player)) {
          MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
          EntityPlayer entity =
              new EntityPlayer(
                  server,
                  server.getWorldServer(0),
                  profile,
                  new PlayerInteractManager(server.getWorldServer(0)));
          Player target = entity == null ? null : (Player) entity.getBukkitEntity();
          if (target != null) {
            target.loadData();
            return target;
          }
        }
      }
    } catch (Exception e) {
      return null;
    }
    return pplayer;
  }
Exemplo n.º 2
0
  public static Cow 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 = ((CraftWorld) location.getWorld()).getHandle();
    final CowNPC customEntity = new CowNPC(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 (CraftCow) customEntity.getBukkitEntity();
  }