use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class StandCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
if (!(npc.getEntity() instanceof Player || npc.getEntity() instanceof Sittable || npc.getEntity() instanceof Villager)) {
Debug.echoError("Entities of type " + npc.getEntityType().name() + " cannot sit or sleep.");
return;
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("npc", Utilities.getEntryNPC(scriptEntry)));
}
Entity entity = npc.getEntity();
if (entity instanceof Sittable) {
((Sittable) entity).setSitting(false);
} else {
if (npc.getCitizen().hasTrait(SittingTrait.class)) {
SittingTrait trait = npc.getCitizen().getOrAddTrait(SittingTrait.class);
trait.stand();
npc.getCitizen().removeTrait(SittingTrait.class);
}
if (npc.getCitizen().hasTrait(SleepingTrait.class)) {
SleepingTrait trait = npc.getCitizen().getOrAddTrait(SleepingTrait.class);
trait.wakeUp();
npc.getCitizen().removeTrait(SleepingTrait.class);
}
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCommand method tabComplete.
@Override
public List<String> tabComplete(CommandSender commandSender, String alias, String[] arguments) {
if (!script.hasTabCompleteProcedure()) {
return super.tabComplete(commandSender, alias, arguments);
}
Map<String, ObjectTag> context = new HashMap<>();
String raw_args = "";
if (arguments.length > 0) {
StringBuilder rawArgsBuilder = new StringBuilder();
for (String arg : arguments) {
rawArgsBuilder.append(arg).append(' ');
}
raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
}
List<String> args = Arrays.asList(ArgumentHelper.buildArgs(raw_args));
context.put("args", new ListTag(args, true));
context.put("raw_args", new ElementTag(raw_args, true));
context.put("alias", new ElementTag(alias, true));
PlayerTag player = null;
NPCTag npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (EntityTag.isCitizensNPC(pl)) {
npc = NPCTag.fromEntity(pl);
} else {
player = PlayerTag.mirrorBukkitPlayer(pl);
}
context.put("server", new ElementTag(false));
} else {
context.put("server", new ElementTag(true));
}
if (Depends.citizens != null && npc == null) {
NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
if (citizen != null) {
npc = new NPCTag(citizen);
}
}
return script.runTabCompleteProcedure(player, npc, context, arguments);
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCommand method execute.
@Override
public boolean execute(CommandSender commandSender, String commandLabel, String[] arguments) {
if (!testPermission(commandSender)) {
return true;
}
Map<String, ObjectTag> context = new HashMap<>();
String raw_args = "";
if (arguments.length > 0) {
StringBuilder rawArgsBuilder = new StringBuilder();
for (String arg : arguments) {
rawArgsBuilder.append(arg).append(' ');
}
raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
}
List<String> args = Arrays.asList(ArgumentHelper.buildArgs(raw_args));
context.put("args", new ListTag(args, true));
context.put("raw_args", new ElementTag(raw_args, true));
context.put("alias", new ElementTag(commandLabel, true));
PlayerTag player = null;
NPCTag npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (EntityTag.isCitizensNPC(pl)) {
npc = NPCTag.fromEntity(pl);
} else {
player = PlayerTag.mirrorBukkitPlayer(pl);
}
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("player"));
} else {
if (commandSender instanceof BlockCommandSender) {
context.put("command_block_location", new LocationTag(((BlockCommandSender) commandSender).getBlock().getLocation()));
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("command_block"));
} else if (commandSender instanceof CommandMinecart) {
context.put("command_minecart", new EntityTag((CommandMinecart) commandSender));
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("command_minecart"));
} else {
context.put("server", new ElementTag(true));
context.put("source_type", new ElementTag("server"));
}
}
if (Depends.citizens != null && npc == null) {
NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
if (citizen != null) {
npc = new NPCTag(citizen);
}
}
script.runCommandScript(player, npc, context);
return true;
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class NPCTagBase method onDeath.
// <--[action]
// @Actions
// death
// death by entity
// death by <entity>
// death by block
// death by <cause>
//
// @Triggers when the NPC dies.
//
// @Context
// <context.killer> returns the entity that killed the NPC (if any)
// <context.shooter> returns the shooter of the killing projectile (if any)
// <context.damage> returns the last amount of damage applied (if any)
// <context.death_cause> returns the last damage cause (if any)
//
// -->
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(EntityDeathEvent deathEvent) {
NPC citizen = CitizensAPI.getNPCRegistry().getNPC(deathEvent.getEntity());
if (citizen == null || !citizen.hasTrait(AssignmentTrait.class)) {
return;
}
NPCTag npc = new NPCTag(citizen);
EntityDamageEvent event = deathEvent.getEntity().getLastDamageCause();
String deathCause = event == null ? "unknown" : CoreUtilities.toLowerCase(event.getCause().toString()).replace('_', ' ');
Map<String, ObjectTag> context = new HashMap<>();
context.put("damage", new ElementTag(event == null ? 0 : event.getDamage()));
context.put("death_cause", new ElementTag(deathCause));
PlayerTag player = null;
if (event instanceof EntityDamageByEntityEvent) {
Entity killerEntity = ((EntityDamageByEntityEvent) event).getDamager();
context.put("killer", new EntityTag(killerEntity).getDenizenObject());
if (killerEntity instanceof Player) {
player = PlayerTag.mirrorBukkitPlayer((Player) killerEntity);
} else if (killerEntity instanceof Projectile) {
ProjectileSource shooter = ((Projectile) killerEntity).getShooter();
if (shooter instanceof LivingEntity) {
context.put("shooter", new EntityTag((LivingEntity) shooter).getDenizenObject());
if (shooter instanceof Player) {
player = PlayerTag.mirrorBukkitPlayer((Player) shooter);
}
npc.action("death by " + ((LivingEntity) shooter).getType().toString(), player, context);
}
}
npc.action("death by entity", player, context);
npc.action("death by " + killerEntity.getType().toString(), player, context);
} else if (event instanceof EntityDamageByBlockEvent) {
npc.action("death by block", null, context);
}
npc.action("death", player, context);
npc.action("death by " + deathCause, player, context);
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityKilledScriptEvent method getScriptEntryData.
@Override
public ScriptEntryData getScriptEntryData() {
PlayerTag player = entity.isPlayer() ? EntityTag.getPlayerFrom(event.getEntity()) : null;
if (damager != null && player == null && damager.isPlayer()) {
player = EntityTag.getPlayerFrom(damager.getBukkitEntity());
}
NPCTag npc = entity.isCitizensNPC() ? entity.getDenizenNPC() : null;
if (damager != null && npc == null && damager.isCitizensNPC()) {
npc = damager.getDenizenNPC();
}
return new BukkitScriptEntryData(player, npc);
}
Aggregations