Search in sources :

Example 36 with ObjectTag

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);
    }
}
Also used : StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) TimeTag(com.denizenscript.denizencore.objects.core.TimeTag)

Example 37 with ObjectTag

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);
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag)

Example 38 with ObjectTag

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);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) HashMap(java.util.HashMap) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) EntityDamageByBlockEvent(org.bukkit.event.entity.EntityDamageByBlockEvent) Projectile(org.bukkit.entity.Projectile) LivingEntity(org.bukkit.entity.LivingEntity) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) NPCTag(com.denizenscript.denizen.objects.NPCTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)38 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)21 MapTag (com.denizenscript.denizencore.objects.core.MapTag)19 ListTag (com.denizenscript.denizencore.objects.core.ListTag)16 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)11 NPCTag (com.denizenscript.denizen.objects.NPCTag)8 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)7 ItemTag (com.denizenscript.denizen.objects.ItemTag)6 ArrayList (java.util.ArrayList)6 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)5 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 EntityTag (com.denizenscript.denizen.objects.EntityTag)4 UUID (java.util.UUID)4 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)3 AbstractCommand (com.denizenscript.denizencore.scripts.commands.AbstractCommand)3 AttributeModifier (org.bukkit.attribute.AttributeModifier)3 Player (org.bukkit.entity.Player)3 TriggerTrait (com.denizenscript.denizen.npc.traits.TriggerTrait)2