Example #1
0
 @EventHandler(ignoreCancelled = true)
 public void onNPCSpawn(NPCSpawnEvent event) {
   Entity npc = event.getNpc();
   if (hasData(event.getData(), ELF)) {
     this.elfs.add(npc);
   }
 }
Example #2
0
  @EventHandler(ignoreCancelled = true)
  public void onNPCSpawn(NPCSpawnEvent event) {
    String name = getData(event.getData(), NPCProperties.NAME, String.class);
    if (name == null) {
      return;
    }
    Preconditions.checkArgument(!name.isEmpty(), "name cannot be empty.");
    Entity npc = event.getNpc();
    ArmorStand armorStand = (ArmorStand) npcManager.spawn(this.blankNametag, npc.getLocation());
    if (armorStand == null) {
      warn("ArmorStand for %s could not be spawned.", event.getData().getId());
      return;
    }
    armorStand.setCustomName(name);
    armorStand.setMetadata(
        nametagMetadata, new FixedMetadataValue(this.npcManager.getOwner(), npc.getEntityId()));

    this.datas.put(npc, new NameData(npc, armorStand));
    if (this.task == null) {
      this.task = new ArmorStandTask();
    }
  }