use of com.denizenscript.denizencore.objects.ObjectTag in project Denizen-For-Bukkit by DenizenScript.
the class LegacySavesUpdater method applyFlags.
public static void applyFlags(String object, AbstractFlagTracker tracker, YamlConfiguration section) {
try {
if (section == null || section.getKeys(false).isEmpty()) {
return;
}
for (StringHolder flagName : section.getKeys(false)) {
if (flagName.low.endsWith("-expiration")) {
continue;
}
TimeTag expireAt = null;
if (section.contains(flagName + "-expiration")) {
long expireTime = Long.parseLong(section.getString(flagName + "-expiration"));
expireAt = new TimeTag(expireTime);
}
Object value = section.get(flagName.str);
ObjectTag setAs = CoreUtilities.objectToTagForm(value, CoreUtilities.errorButNoDebugContext);
tracker.setFlag(flagName.low, setAs, expireAt);
}
} catch (Throwable ex) {
Debug.echoError("Error while updating legacy flags for " + object);
Debug.echoError(ex);
}
}
use of com.denizenscript.denizencore.objects.ObjectTag in project Denizen-For-Bukkit by DenizenScript.
the class Debug method report.
public static void report(Debuggable caller, String name, Object... values) {
if (!showDebug || !shouldDebug(caller)) {
return;
}
StringBuilder output = new StringBuilder();
for (Object obj : values) {
if (obj == null) {
continue;
}
if (obj instanceof ObjectTag) {
ObjectTag objTag = (ObjectTag) obj;
output.append("<G>").append(objTag.getPrefix()).append("='<Y>").append(objTag.debuggable()).append("<G>' ");
} else {
output.append(obj);
}
}
echo("<Y>+> <G>Executing '<Y>" + name + "<G>': " + trimMessage(output.toString()), caller);
}
use of com.denizenscript.denizencore.objects.ObjectTag 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);
}
Aggregations