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);
}
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);
}
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);
}
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);
}
}
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;
}
}
Aggregations