net.citizensnpcs.api.npc.NPCRegistry Java Examples
The following examples show how to use
net.citizensnpcs.api.npc.NPCRegistry.
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: NPCManager.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
public NPC getNPC(UUID uuid) { if(uuid == null) return null; NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry(); for(NPC npc : npcRegistry) { if(isInvalid(npc)) continue; TraitCombatLogX traitCombatLogX = npc.getTrait(TraitCombatLogX.class); OfflinePlayer owner = traitCombatLogX.getOwner(); if(owner == null) continue; UUID ownerId = owner.getUniqueId(); if(uuid.equals(ownerId)) return npc; } return null; }
Example #2
Source File: ListenerResurrect.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true) public void beforeResurrect(EntityResurrectEvent e) { FileConfiguration config = this.expansion.getConfig("citizens-compatibility.yml"); if(!config.getBoolean("npc-options.prevent-resurrect", true)) return; LivingEntity entity = e.getEntity(); if(!entity.hasMetadata("NPC")) return; NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry(); NPC npc = npcRegistry.getNPC(entity); NPCManager npcManager = this.expansion.getNPCManager(); if(npcManager.isInvalid(npc)) return; e.setCancelled(true); }
Example #3
Source File: EffCitizenAttack.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #4
Source File: NPCManager.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
public void onDisable() { NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry(); for(NPC npc : npcRegistry) { if(isInvalid(npc)) continue; npc.destroy(); } if(this.traitInfo != null) { TraitFactory traitFactory = CitizensAPI.getTraitFactory(); traitFactory.deregisterTrait(traitInfo); } }
Example #5
Source File: EffCitizenMove.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #6
Source File: EffDeleteCitizen.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); if (id != null && registry.getById(id.getSingle(evt).intValue()) != null) { NPC delete = registry.getById(id.getSingle(evt).intValue()); if (delete != null && delete.getOwningRegistry() != null) { delete.destroy(); } } }
Example #7
Source File: EffCitizenSetMaxHealth.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #8
Source File: EffCitizenSetSkin.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #9
Source File: EffSentryStopFollow.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); NPC npc = registry.getById(id.getSingle(evt).intValue()); SentryInstance st = npc.getTrait(SentryTrait.class).getInstance(); st.setGuardTarget(null, false); }
Example #10
Source File: EffDespawnCitizen.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); if (registry.getById(id.getSingle(evt).intValue()) != null) { try { NPC despawn = registry.getById(id.getSingle(evt).intValue()); despawn.despawn(null); } catch (NullPointerException exp) { return; } } }
Example #11
Source File: EffRespawnCitizen.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #12
Source File: EffCitizenSwing.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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)) { PlayerAnimation.ARM_SWING.play((Player) npc.getEntity()); } }
Example #13
Source File: EffGiveLookCloseTrait.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); NPC npc = registry.getById(id.getSingle(evt).intValue()); npc.addTrait(LookClose.class); npc.getTrait(LookClose.class).setRealisticLooking(true); npc.getTrait(LookClose.class).toggle(); }
Example #14
Source File: EffSentryFollowDistance.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #15
Source File: EffCreateCitizen.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override public void execute(Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); EntityType citizenType = ScrubEntityType.getType(type.toString()); NPC npc = registry.createNPC(citizenType, name.getSingle(evt).toString().replace("\"", "")); Location spawnto = location.getSingle(evt); npc.spawn(spawnto); ExprLastCitizen.lastNPC = npc; }
Example #16
Source File: EffStartBuilderBuild.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); NPC npc = registry.getById(id.getSingle(evt).intValue()); npc.addTrait(BuilderTrait.class); npc.teleport(loc.getSingle(evt), null); if (speed != null) { npc.getNavigator().getDefaultParameters().baseSpeed(speed.getSingle(evt).floatValue()); } BuilderTrait bt = npc.getTrait(BuilderTrait.class); bt.oncancel = null; bt.oncomplete = null; bt.onStart = null; bt.ContinueLoc = null; bt.IgnoreAir = false; bt.IgnoreLiquid = false; bt.Excavate = false; bt.GroupByLayer = true; bt.BuildYLayers = 1; bt.BuildPatternXY = net.jrbudda.builder.BuilderTrait.BuildPatternsXZ.spiral; File file = new File("plugins/Builder/schematics/"); try { bt.schematic = MCEditSchematicFormat.load(file, schematic.getSingle(evt).trim().replace("\"", "")); } catch (Exception exception) { exception.printStackTrace(); } bt.TryBuild(player.getSingle(evt)); }
Example #17
Source File: EffCitizenVulnerability.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); NPC npcName = registry.getById(id.getSingle(evt).intValue()); if (vun) { npcName.setProtected(false); } if (!vun) { npcName.setProtected(true); } }
Example #18
Source File: EffSentryProtect.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #19
Source File: ExprBottomRightSchematic.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #20
Source File: NPCManager.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
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 #21
Source File: CondIsNpcIdGeneral.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override public boolean check(Event evt) { if (test.getSingle(evt) != null && id.getSingle(evt) != null && test.getSingle(evt).hasMetadata("NPC")) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); return registry.getNPC(test.getSingle(evt)).getId() == id.getSingle(evt).intValue(); } else { return false; } }
Example #22
Source File: ExprTopLeftSchematic.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 topLeft = loc.getSingle(evt).add((Math.round(bt.schematic.width() / 2)), bt.schematic.height() - 1, (Math.round(bt.schematic.length() / 2))); return new Location[]{topLeft}; } else { Skript.error("A schematic has yet to be loaded for this Builder"); return new Location[]{loc.getSingle(evt)}; } }
Example #23
Source File: ExprGeneralCitizen.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override @org.eclipse.jdt.annotation.Nullable protected Entity[] get(org.bukkit.event.Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); try { NPC npc = registry.getById(this.id.getSingle(evt).intValue()); return new Entity[]{npc.getEntity()}; } catch (NullPointerException exception) { return null; } }
Example #24
Source File: ExprCitizenIdFromEntity.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override @Nullable protected Number[] get(Event evt) { if (entity.getSingle(evt) != null && entity.getSingle(evt).hasMetadata("NPC")) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); return new Number[]{registry.getNPC(entity.getSingle(evt)).getId()}; } return null; }
Example #25
Source File: ExprNameOfCitizen.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #26
Source File: ExprOwnerOfCitizen.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #27
Source File: EffCitizenLookTarget.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #28
Source File: EffCitizenSpeak.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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 #29
Source File: EffCitizenToggleCrouch.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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)) { ((Player) npc.getEntity()).setSneaking(!((Player) npc.getEntity()).isSneaking()); } }
Example #30
Source File: EffCitizenHold.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@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!"); } }