net.citizensnpcs.api.CitizensAPI Java Examples
The following examples show how to use
net.citizensnpcs.api.CitizensAPI.
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 void registerTrait() { try { Class<TraitInfo> class_TraitInfo = TraitInfo.class; Constructor<TraitInfo> constructor = class_TraitInfo.getDeclaredConstructor(Class.class); constructor.setAccessible(true); this.traitInfo = constructor.newInstance(TraitCombatLogX.class); this.traitInfo.withSupplier(() -> new TraitCombatLogX(this.expansion)); TraitFactory traitFactory = CitizensAPI.getTraitFactory(); traitFactory.registerTrait(traitInfo); } catch(ReflectiveOperationException ex) { Logger logger = this.expansion.getLogger(); logger.log(Level.WARNING, "Failed to register the CombatLogX NPC Trait:", ex); } }
Example #2
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 #3
Source File: SentinelTrait.java From Sentinel with MIT License | 6 votes |
/** * Gets the entity this NPC is guarding, or null. */ public LivingEntity getGuardingEntity() { if (guardedNPC >= 0) { NPC npc = CitizensAPI.getNPCRegistry().getById(guardedNPC); if (npc != null && npc.isSpawned()) { return (LivingEntity) npc.getEntity(); } } UUID guardId = getGuarding(); if (guardId == null) { return null; } Player player = Bukkit.getPlayer(guardId); if (player != null) { return player; } if (SentinelVersionCompat.v1_12) { Entity entity = Bukkit.getEntity(guardId); if (entity instanceof LivingEntity) { return (LivingEntity) entity; } } return null; }
Example #4
Source File: NPCRegionCondition.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@Override protected Boolean execute(String playerID) throws QuestRuntimeException { NPC npc = CitizensAPI.getNPCRegistry().getById(ID); if (npc == null) { throw new QuestRuntimeException("NPC with ID " + ID + " does not exist"); } Entity npcEntity = npc.getEntity(); if (npcEntity == null) return false; Player player = PlayerConverter.getPlayer(playerID); WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform(); RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(player.getWorld())); if (manager == null) { return false; } ApplicableRegionSet set = manager.getApplicableRegions(BlockVector3.at(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ())); for (ProtectedRegion compare : set) { if (compare.equals(region)) return true; } return false; }
Example #5
Source File: NPCRangeObjective.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onMove(PlayerMoveEvent event) { qreHandler.handle(() -> { final Player player = event.getPlayer(); final String playerID = PlayerConverter.getID(player); if (!containsPlayer(playerID)) return; final NPC npc = CitizensAPI.getNPCRegistry().getById(id); if (npc == null) throw new QuestRuntimeException("NPC with ID " + id + " does not exist"); final double radius = this.radius.getDouble(playerID); final Entity npcEntity = npc.getEntity(); if (npcEntity == null) return; if (!npcEntity.getWorld().equals(event.getTo().getWorld())) return; final double distanceSqrd = npcEntity.getLocation().distanceSquared(event.getTo()); final double radiusSqrd = radius * radius; if ((trigger == Trigger.ENTER && distanceSqrd <= radiusSqrd) || (trigger == Trigger.LEAVE && distanceSqrd >= radiusSqrd)) { if (checkConditions(playerID)) completeObjective(playerID); } }); }
Example #6
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 #7
Source File: SentinelSquads.java From Sentinel with MIT License | 6 votes |
@Override public boolean isTarget(LivingEntity ent, String prefix, String value) { try { if (prefix.equals("squad") && CitizensAPI.getNPCRegistry().isNPC(ent) && CitizensAPI.getNPCRegistry().getNPC(ent).hasTrait(SentinelTrait.class)) { SentinelTrait sentinel = CitizensAPI.getNPCRegistry().getNPC(ent).getTrait(SentinelTrait.class); if (sentinel.squad != null) { String squadName = value.toLowerCase(Locale.ENGLISH); if (squadName.equals(sentinel.squad)) { return true; } } } } catch (Exception ex) { ex.printStackTrace(); } return false; }
Example #8
Source File: NPCKillObjective.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onNpcKill(MobKilledEvent event) { NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getEntity()); if (npc == null) { return; } if (npc.getId() != ID) { return; } String playerID = PlayerConverter.getID(event.getPlayer()); NPCData playerData = (NPCData) dataMap.get(playerID); if (containsPlayer(playerID) && checkConditions(playerID)) { playerData.kill(); if (playerData.killed()) { completeObjective(playerID); } } }
Example #9
Source File: CitizensMobProvider.java From DungeonsXL with GNU General Public License v3.0 | 6 votes |
@Override public void summon(String mob, Location location) { NPC source = CitizensAPI.getNPCRegistry().getById(NumberUtil.parseInt(mob)); if (!(source instanceof AbstractNPC)) { return; } NPC npc = registry.createTransientClone((AbstractNPC) source); if (npc.isSpawned()) { npc.despawn(); } npc.spawn(location); spawnedNPCs.add(npc); GameWorld gameWorld = DungeonsXL.getInstance().getGameWorld(location.getWorld()); if (gameWorld == null) { return; } new DMob((LivingEntity) npc.getEntity(), gameWorld, mob); }
Example #10
Source File: SentinelEventHandler.java From Sentinel with MIT License | 6 votes |
/** * Called when an inventory is closed. */ @EventHandler public void onInvClose(InventoryCloseEvent event) { String invTitle = SentinelUtilities.getInventoryTitle(event); if (invTitle.startsWith(InvPrefix)) { int id = Integer.parseInt(invTitle.substring(InvPrefix.length())); NPC npc = CitizensAPI.getNPCRegistry().getById(id); if (npc != null && npc.hasTrait(SentinelTrait.class)) { ArrayList<ItemStack> its = npc.getTrait(SentinelTrait.class).drops; its.clear(); for (ItemStack it : event.getInventory().getContents()) { if (it != null && it.getType() != Material.AIR) { its.add(it); } } } } }
Example #11
Source File: EffCitizenSleep.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)) { if (type) { PlayerAnimation.STOP_SLEEPING.play((Player) npc.getEntity()); } else { PlayerAnimation.SLEEP.play((Player) npc.getEntity()); } } }
Example #12
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 #13
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 #14
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 #15
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 #16
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 #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: CitizensHandler.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
public static void disable() { if (!enabled) { // already disabled return; } Plugin citizensPlugin = getPlugin(); if (citizensPlugin != null) { // unregister shopkeeper trait: if (shopkeeperTrait != null) { try { CitizensAPI.getTraitFactory().deregisterTrait(shopkeeperTrait); } catch (Throwable ex) { Log.debug("Shopkeeper trait unregistration error: " + ex.getMessage()); if (Settings.debug) { ex.printStackTrace(); } } finally { shopkeeperTrait = null; } } } // unregister citizens listener: if (citizensListener != null) { HandlerList.unregisterAll(citizensListener); citizensListener = null; } // disabled: enabled = false; }
Example #19
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 #20
Source File: EffCitizenSetCrouch.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)) { if (shouldCrouch) { // Make crouch here ((Player) npc.getEntity()).setSneaking(true); } else { // Make uncrouch here ((Player) npc.getEntity()).setSneaking(false); } } }
Example #21
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!"); } }
Example #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
Source File: NPCDistanceCondition.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@Override protected Boolean execute(String playerID) throws QuestRuntimeException { Player player = PlayerConverter.getPlayer(playerID); NPC npc = CitizensAPI.getNPCRegistry().getById(id); double distance = this.distance.getDouble(playerID); if (npc == null) { throw new QuestRuntimeException("NPC with ID " + id + " does not exist"); } Entity npcEntity = npc.getEntity(); if (npcEntity == null) return false; if (!npcEntity.getWorld().equals(player.getWorld())) return false; return npcEntity.getLocation().distanceSquared(player.getLocation()) <= distance * distance; }