Java Code Examples for net.citizensnpcs.api.CitizensAPI#getNPCRegistry()

The following examples show how to use net.citizensnpcs.api.CitizensAPI#getNPCRegistry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExprOwnerOfCitizen.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
protected String[] get(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(id.getSingle(evt).intValue());
    if (npc.hasTrait(Owner.class)) {
        return new String[]{npc.getTrait(Owner.class).getOwner()};
    }
    return new String[]{};
}
 
Example 2
Source File: EffSentryFollowDistance.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(id.getSingle(evt).intValue());
    npc.addTrait(SentryTrait.class);
    SentryInstance st = npc.getTrait(SentryTrait.class).getInstance();
    st.FollowDistance = dis.getSingle(evt).intValue();
}
 
Example 3
Source File: EffCitizenLookTarget.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npcLook = registry.getById(id.getSingle(evt).intValue());
    if (npcLook != null) {
        npcLook.faceLocation(targetLoc.getSingle(evt));
    }
}
 
Example 4
Source File: EffCitizenSleep.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(id.getSingle(evt).intValue());
    if (npc != null && npc.getEntity().getType().equals(EntityType.PLAYER)) {
        if (type) {
            PlayerAnimation.STOP_SLEEPING.play((Player) npc.getEntity());
        } else {
            PlayerAnimation.SLEEP.play((Player) npc.getEntity());
        }
    }

}
 
Example 5
Source File: EffCitizenSetCrouch.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(id.getSingle(evt).intValue());
    if (npc != null && npc.getEntity().getType().equals(EntityType.PLAYER)) {
        if (shouldCrouch) {
            // Make crouch here
            ((Player) npc.getEntity()).setSneaking(true);
        } else {
            // Make uncrouch here
            ((Player) npc.getEntity()).setSneaking(false);
        }
    }

}
 
Example 6
Source File: EffCitizenHold.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC getter = registry.getById(id.getSingle(evt).intValue());
    if (getter.getEntity().getType().equals(EntityType.PLAYER)
            || getter.getEntity().getType() == EntityType.ENDERMAN
            || getter.getEntity().getType() == EntityType.ZOMBIE
            || getter.getEntity().getType() == EntityType.SKELETON) {
        Equipment equ = getter.getTrait(Equipment.class);
        equ.set(EquipmentSlot.HAND, item.getSingle(evt));
    } else {
        Skript.error("Entity must be equipable!");
    }

}
 
Example 7
Source File: EffRespawnCitizen.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC respawn = registry.getById(id.getSingle(evt).intValue());
    if (respawn.isSpawned()) {
        Skript.warning("This NPC is still alive!");
    } else {
        respawn.spawn(location.getSingle(evt));
    }
}
 
Example 8
Source File: EffCitizenSpeak.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npcSpeak = registry.getById(id.getSingle(evt).intValue());
    SpeechContext sp =
            new SpeechContext(npcSpeak, speak.getSingle(evt).replace("\"", ""), target.getSingle(evt));
    npcSpeak.getDefaultSpeechController().speak(sp);
}
 
Example 9
Source File: ExprBottomRightSchematic.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
protected Location[] get(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(id.getSingle(evt).intValue());
    BuilderTrait bt = npc.getTrait(BuilderTrait.class);
    if (bt.schematic != null) {
        Location bottomRight = loc.getSingle(evt).add((-1 * Math.floor(bt.schematic.width() / 2)), -1,
                (-1 * Math.floor(bt.schematic.length() / 2)));
        return new Location[]{bottomRight};
    } else {
        Skript.error("A schematic has yet to be loaded for this Builder");
        return new Location[]{loc.getSingle(evt)};
    }
}
 
Example 10
Source File: EffCitizenMove.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(idNum.getSingle(evt).intValue());
    Location moveTo = location.getSingle(evt);
    if (npc != null) {
        if (speed != null) {
            npc.getNavigator().getDefaultParameters().baseSpeed(speed.getSingle(evt).floatValue());
        }
        npc.getNavigator().setTarget(moveTo);
    }
}
 
Example 11
Source File: ExprNameOfCitizen.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
protected String[] get(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npcName = registry.getById(id.getSingle(evt).intValue());
    return new String[]{npcName.getName()};
}
 
Example 12
Source File: EffCitizenAttack.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC attacker = registry.getById(id.getSingle(evt).intValue());
    if (attacker != null) {
        attacker.getNavigator().setTarget(toBeAttacked.getSingle(evt), true);
    }
}
 
Example 13
Source File: EffCitizenSetSkin.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(id.getSingle(evt).intValue());
    npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA,
            toSkin.getSingle(evt).replace("\"", ""));
    Location respawnloc = npc.getEntity().getLocation();
    npc.despawn();
    npc.spawn(respawnloc);
}
 
Example 14
Source File: EffCitizenSetMaxHealth.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npcH = registry.getById(id.getSingle(evt).intValue());
    Damageable npc = (Damageable) npcH.getEntity();
    npc.setMaxHealth(maxHealth.getSingle(evt).doubleValue());
}
 
Example 15
Source File: EffSentryProtect.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(id.getSingle(evt).intValue());
    npc.addTrait(SentryTrait.class);
    SentryInstance st = npc.getTrait(SentryTrait.class).getInstance();
    st.setGuardTarget(target.getSingle(evt).getName(), true);

}
 
Example 16
Source File: NPCManager.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
public void createNPC(Player player, LivingEntity enemy) {
    if(player == null) return;
    
    Location location = player.getLocation().clone();
    EntityType bukkitType = getMobType();
    String playerName = player.getName();
    
    NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
    NPC npc = npcRegistry.createNPC(bukkitType, playerName);
    npc.removeTrait(Owner.class);
    
    TraitCombatLogX traitCombatLogX = npc.getTrait(TraitCombatLogX.class);
    traitCombatLogX.extendLife();
    
    traitCombatLogX.setOwner(player);
    if(enemy instanceof Player) {
        Player enemyPlayer = (Player) enemy;
        traitCombatLogX.setEnemy(enemyPlayer);
    }
    
    boolean spawned = npc.spawn(location);
    if(!spawned) {
        Logger logger = this.expansion.getLogger();
        logger.warning("An NPC could not be spawned for " + playerName + ".");
        return;
    }
    setOptions(npc, player);

    SentinelManager sentinelManager = this.expansion.getSentinelManager();
    FileConfiguration config = this.expansion.getConfig("citizens-compatibility.yml");
    if(sentinelManager != null && config.getBoolean("sentinel-options.enable-sentinel", true)) {
        sentinelManager.setOptions(npc, player, enemy);
    }
}
 
Example 17
Source File: EffSentryEquip.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    @SuppressWarnings("unused")
    NPC npc = registry.getById(id.getSingle(evt).intValue());
}
 
Example 18
Source File: EffEquipCitizen.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC getter = registry.getById(id.getSingle(evt).intValue());
    EquipmentSlot slot = EquipmentSlot.HAND;
    switch (item.getSingle(evt).getType()) {
        case LEATHER_BOOTS:
        case IRON_BOOTS:
        case GOLD_BOOTS:
        case CHAINMAIL_BOOTS:
        case DIAMOND_BOOTS:
            slot = EquipmentSlot.BOOTS;
            break;
        case LEATHER_LEGGINGS:
        case IRON_LEGGINGS:
        case GOLD_LEGGINGS:
        case CHAINMAIL_LEGGINGS:
        case DIAMOND_LEGGINGS:
            slot = EquipmentSlot.LEGGINGS;
            break;
        case LEATHER_CHESTPLATE:
        case IRON_CHESTPLATE:
        case GOLD_CHESTPLATE:
        case CHAINMAIL_CHESTPLATE:
        case DIAMOND_CHESTPLATE:
            slot = EquipmentSlot.CHESTPLATE;
            break;
        case LEATHER_HELMET:
        case IRON_HELMET:
        case GOLD_HELMET:
        case CHAINMAIL_HELMET:
        case DIAMOND_HELMET:
            slot = EquipmentSlot.HELMET;
            break;
        default:
            break;

    }
    if (getter.getEntity().getType().equals(EntityType.PLAYER)
            || getter.getEntity().getType() == EntityType.ENDERMAN
            || getter.getEntity().getType() == EntityType.ZOMBIE
            || getter.getEntity().getType() == EntityType.SKELETON) {
        Equipment equ = getter.getTrait(Equipment.class);
        equ.set(slot, item.getSingle(evt));
    } else {
        Skript.error("Entity must be equipable!");
    }
}
 
Example 19
Source File: EffCitizenAttackDamage.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    @SuppressWarnings("unused")
    NPC target = registry.getById(id.getSingle(evt).intValue());
}
 
Example 20
Source File: EffSetCitizenName.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void execute(Event evt) {
    NPCRegistry registry = CitizensAPI.getNPCRegistry();
    NPC npc = registry.getById(idNum.getSingle(evt).intValue());
    npc.setName(name.getSingle(evt).replace("\"", ""));
}