Search in sources :

Example 76 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag 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)

Example 77 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag 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);
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) BukkitScriptEntryData(com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData) NPCTag(com.denizenscript.denizen.objects.NPCTag)

Example 78 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class ChatScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    if (determinationObj instanceof ElementTag) {
        String determination = determinationObj.toString();
        String lower = CoreUtilities.toLowerCase(determination);
        if (lower.startsWith("format:")) {
            String name = determination.substring("format:".length());
            FormatScriptContainer formatscr = ScriptRegistry.getScriptContainer(name);
            if (formatscr == null) {
                Debug.echoError("Could not find format script matching '" + name + '\'');
            } else {
                String formatstr = formatscr.getFormatText(null, player);
                if (Debug.verbose) {
                    Debug.log("Setting format to " + formatstr);
                }
                if (pcEvent != null) {
                    pcEvent.setFormat(formatstr);
                } else {
                    apcEvent.setFormat(formatstr);
                }
            }
            return true;
        } else if (lower.startsWith("raw_format:")) {
            String form = determination.substring("raw_format:".length());
            if (pcEvent != null) {
                pcEvent.setFormat(form);
            } else {
                apcEvent.setFormat(form);
            }
            return true;
        } else if (lower.startsWith("recipients:")) {
            String rec_new = determination.substring("recipients:".length());
            ListTag recs = ListTag.valueOf(rec_new, getTagContext(path));
            List<PlayerTag> players = recs.filter(PlayerTag.class, path.container, true);
            Set<Player> recipients;
            if (pcEvent != null) {
                recipients = pcEvent.getRecipients();
            } else {
                recipients = apcEvent.getRecipients();
            }
            recipients.clear();
            for (PlayerTag player : players) {
                recipients.add(player.getPlayerEntity());
            }
            return true;
        } else {
            if (pcEvent != null) {
                pcEvent.setMessage(determination);
            } else {
                apcEvent.setMessage(determination);
            }
            return true;
        }
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : Player(org.bukkit.entity.Player) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 79 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class DenizenMapRenderer method render.

@Override
public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
    if (!Denizen.getInstance().isEnabled()) {
        // Special case for shutdown borko
        return;
    }
    if (!active) {
        mapView.removeRenderer(this);
        return;
    }
    if (!autoUpdate && !hasChanged && !isContextual()) {
        return;
    }
    try {
        while (mapCanvas.getCursors().size() > 0) {
            mapCanvas.getCursors().removeCursor(mapCanvas.getCursors().getCursor(0));
        }
        if (displayOriginal) {
            for (MapRenderer oldR : oldMapRenderers) {
                oldR.render(mapView, mapCanvas, player);
            }
        }
        UUID uuid = player.getUniqueId();
        PlayerTag p = PlayerTag.mirrorBukkitPlayer(player);
        for (MapObject object : mapObjects) {
            if (autoUpdate) {
                object.lastMap = mapView;
                object.update(p, uuid);
            }
            if (object.isVisibleTo(p)) {
                object.render(mapView, mapCanvas, p, uuid);
            }
        }
        hasChanged = false;
    } catch (Exception e) {
        Debug.echoError(e);
        mapView.removeRenderer(this);
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) MapRenderer(org.bukkit.map.MapRenderer)

Example 80 with PlayerTag

use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showSignEditor.

@Override
public boolean showSignEditor(Player player, Location location) {
    if (location == null) {
        LocationTag fakeSign = new LocationTag(player.getLocation());
        fakeSign.setY(0);
        FakeBlock.showFakeBlockTo(Collections.singletonList(new PlayerTag(player)), fakeSign, new MaterialTag(org.bukkit.Material.OAK_WALL_SIGN), new DurationTag(1), true);
        BlockPosition pos = new BlockPosition(fakeSign.getX(), 0, fakeSign.getZ());
        ((DenizenNetworkManagerImpl) ((CraftPlayer) player).getHandle().playerConnection.networkManager).packetListener.fakeSignExpected = pos;
        sendPacket(player, new PacketPlayOutOpenSignEditor(pos));
        return true;
    }
    TileEntity tileEntity = ((CraftWorld) location.getWorld()).getHandle().getTileEntity(new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
    if (tileEntity instanceof TileEntitySign) {
        TileEntitySign sign = (TileEntitySign) tileEntity;
        // Prevent client crashing by sending current state of the sign
        sendPacket(player, sign.getUpdatePacket());
        sign.isEditable = true;
        sign.a((EntityHuman) ((CraftPlayer) player).getHandle());
        sendPacket(player, new PacketPlayOutOpenSignEditor(sign.getPosition()));
        return true;
    } else {
        return false;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) DenizenNetworkManagerImpl(com.denizenscript.denizen.nms.v1_16.impl.network.handlers.DenizenNetworkManagerImpl) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Aggregations

PlayerTag (com.denizenscript.denizen.objects.PlayerTag)81 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)41 Player (org.bukkit.entity.Player)26 List (java.util.List)23 NPCTag (com.denizenscript.denizen.objects.NPCTag)22 EntityTag (com.denizenscript.denizen.objects.EntityTag)16 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)15 ListTag (com.denizenscript.denizencore.objects.core.ListTag)15 LocationTag (com.denizenscript.denizen.objects.LocationTag)14 ItemTag (com.denizenscript.denizen.objects.ItemTag)12 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)11 EventHandler (org.bukkit.event.EventHandler)11 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)8 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)8 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)8 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)7 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)7 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)7 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)6 Argument (com.denizenscript.denizencore.objects.Argument)6