Exemplo n.º 1
0
 public static HumanNPC spawnNPC(
     int UID,
     String name,
     World world,
     double x,
     double y,
     double z,
     float yaw,
     float pitch,
     CreatureNPCType type) {
   try {
     WorldServer ws = getWorldServer(world);
     MinecraftServer ms = getMinecraftServer(ws.getServer());
     CraftNPC eh =
         (CraftNPC)
             type.getEntityClass()
                 .getConstructors()[0]
                 .newInstance(ms, ws, name, new ItemInWorldManager(ws));
     ws.addEntity(eh);
     eh.setLocation(x, y, z, yaw, pitch);
     ws.players.remove(eh);
     return new HumanNPC(eh, UID, name);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Exemplo n.º 2
0
  public Banker spawnBanker(String name, Location l, String id, String bankName) {
    if (bankers.containsKey(id)) {
      Log.warning("NPC with that id already exists, existing NPC returned");
      return bankers.get(id);
    } else {
      if (name.length()
          > 16) { // Check and nag if name is too long, spawn NPC anyway with shortened name.
        String tmp = name.substring(0, 16);
        Log.warning("NPCs can't have names longer than 16 characters,");
        Log.warning(name + " has been shortened to " + tmp);
        name = tmp;
      }
      WorldServer ws = getWorldServer(l.getWorld());
      NPCEntity npcEntity = new NPCEntity(this, ws, name, new ItemInWorldManager(ws));
      npcEntity.setPositionRotation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
      ws.addEntity(npcEntity); // the right way
      Banker npc = new Banker(npcEntity, bankName);
      npc.setYaw(l.getYaw());

      if (Bukkit.getPluginManager().isPluginEnabled("Spout")) {
        SpoutPlayer sp = npc.getSpoutPlayer();
        sp.setSkin("http://dl.dropbox.com/u/18216599/images/bankersskin.png");
        sp.setTitle(ChatColor.GOLD + "Banker\n" + ChatColor.WHITE + "[" + bankName + "]");
      }

      bankers.put(id, npc);
      return npc;
    }
  }
Exemplo n.º 3
0
 public static HumanNPC spawnNPC(HumanNPC npc, Location loc) {
   try {
     WorldServer ws = getWorldServer(loc.getWorld());
     ws.addEntity(npc.getHandle());
     npc.teleport(loc);
     ws.players.remove(npc.getHandle());
     return npc;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Exemplo n.º 4
0
  public void c(int i) {
    if (!this.world.isStatic && !this.dead) {
      this.world.methodProfiler.a("changeDimension");
      MinecraftServer minecraftserver = MinecraftServer.getServer();
      int j = this.dimension;
      WorldServer worldserver = minecraftserver.getWorldServer(j);
      WorldServer worldserver1 = minecraftserver.getWorldServer(i);

      this.dimension = i;
      if (j == 1 && i == 1) {
        worldserver1 = minecraftserver.getWorldServer(0);
        this.dimension = 0;
      }

      this.world.kill(this);
      this.dead = false;
      this.world.methodProfiler.a("reposition");
      minecraftserver.getPlayerList().changeWorld(this, j, worldserver, worldserver1);
      this.world.methodProfiler.c("reloading");
      Entity entity = EntityTypes.createEntityByName(EntityTypes.b(this), worldserver1);

      if (entity != null) {
        entity.n(this);
        if (j == 1 && i == 1) {
          BlockPosition blockposition = this.world.r(worldserver1.getSpawn());

          entity.setPositionRotation(blockposition, entity.yaw, entity.pitch);
        }

        worldserver1.addEntity(entity);
      }

      this.dead = true;
      this.world.methodProfiler.b();
      worldserver.j();
      worldserver1.j();
      this.world.methodProfiler.b();
    }
  }