use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerFishesScriptEvent method onPlayerFishes.
@EventHandler
public void onPlayerFishes(PlayerFishEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
Entity hookEntity = NMSHandler.getEntityHelper().getFishHook(event);
EntityTag.rememberEntity(hookEntity);
hook = new EntityTag(hookEntity);
state = new ElementTag(event.getState().toString());
item = null;
entity = null;
Entity caughtEntity = event.getCaught();
if (caughtEntity != null) {
EntityTag.rememberEntity(caughtEntity);
entity = new EntityTag(caughtEntity);
if (caughtEntity instanceof Item) {
item = new ItemTag(((Item) caughtEntity).getItemStack());
}
}
this.event = event;
fire(event);
EntityTag.forgetEntity(hookEntity);
EntityTag.forgetEntity(caughtEntity);
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class VehicleCollidesEntityScriptEvent method onVehicleCollidesEntity.
@EventHandler
public void onVehicleCollidesEntity(VehicleEntityCollisionEvent event) {
entity = new EntityTag(event.getEntity());
vehicle = new EntityTag(event.getVehicle());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class VehicleMoveScriptEvent method onVehicleMove.
@EventHandler
public void onVehicleMove(VehicleMoveEvent event) {
to = new LocationTag(event.getTo());
from = new LocationTag(event.getFrom());
vehicle = new EntityTag(event.getVehicle());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNPCHelper method despawn.
// <--[action]
// @Actions
// despawn
// @Triggers when the NPC is despawned.
// This can be because a command was issued, or a chunk has been unloaded.
//
// @Context
// None
// -->
/**
* Fires a world script event and then NPC action when the NPC despawns.
*
* @param event NPCDespawnEvent
*/
@EventHandler
public void despawn(NPCDespawnEvent event) {
NPCTag npc = new NPCTag(event.getNPC());
if (npc.isValid()) {
EntityDespawnScriptEvent.instance.entity = new EntityTag(event.getNPC().getEntity());
EntityDespawnScriptEvent.instance.cause = new ElementTag("CITIZENS");
EntityDespawnScriptEvent.instance.fire(event);
npc.action("despawn", null);
}
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenChat method talk.
@Override
public void talk(SpeechContext speechContext) {
if (!(speechContext instanceof DenizenSpeechContext)) {
return;
}
DenizenSpeechContext context = (DenizenSpeechContext) speechContext;
Talkable talker = context.getTalker();
if (talker == null) {
return;
}
ScriptEntry entry = context.getScriptEntry();
ScriptQueue queue = entry.getResidingQueue();
String defTalker = null;
if (queue.hasDefinition("talker")) {
defTalker = queue.getDefinition("talker");
}
queue.addDefinition("talker", new EntityTag(talker.getEntity()).identify());
String defMessage = null;
if (queue.hasDefinition("message")) {
defMessage = queue.getDefinition("message");
}
queue.addDefinition("message", context.getMessage());
// Chat to the world using Denizen chat settings
if (!context.hasRecipients()) {
String text = TagManager.tag(Settings.chatNoTargetFormat(), new BukkitTagContext(entry));
talkToBystanders(talker, text, context);
} else // Single recipient
if (context.size() <= 1) {
// Send chat to target
String text = TagManager.tag(Settings.chatToTargetFormat(), new BukkitTagContext(entry));
for (Talkable entity : context) {
entity.talkTo(context, text, this);
}
// Check if bystanders hear targeted chat
if (context.isBystandersEnabled()) {
String defTarget = null;
if (queue.hasDefinition("target")) {
defTarget = queue.getDefinition("target");
}
queue.addDefinition("target", new EntityTag(context.iterator().next().getEntity()).identify());
String bystanderText = TagManager.tag(Settings.chatWithTargetToBystandersFormat(), new BukkitTagContext(entry));
talkToBystanders(talker, bystanderText, context);
if (defTarget != null) {
queue.addDefinition("target", defTarget);
}
}
} else // Multiple recipients
{
// Send chat to targets
String text = TagManager.tag(Settings.chatToTargetFormat(), new BukkitTagContext(entry));
for (Talkable entity : context) {
entity.talkTo(context, text, this);
}
if (context.isBystandersEnabled()) {
String[] format = Settings.chatMultipleTargetsFormat().split("%target%");
if (format.length <= 1) {
Debug.echoError("Invalid 'Commands.Chat.Options.Multiple targets format' in config.yml! Must have at least 1 %target%");
}
StringBuilder parsed = new StringBuilder();
Iterator<Talkable> iter = context.iterator();
int i = 0;
while (iter.hasNext()) {
if (i == format.length - 1) {
parsed.append(format[i]);
break;
}
parsed.append(format[i]).append(new EntityTag(iter.next().getEntity()).getName());
i++;
}
String targets = TagManager.tag(parsed.toString(), new BukkitTagContext(entry));
String defTargets = null;
if (queue.hasDefinition("targets")) {
defTargets = queue.getDefinition("targets");
}
queue.addDefinition("targets", targets);
String bystanderText = TagManager.tag(Settings.chatWithTargetsToBystandersFormat(), new BukkitTagContext(entry));
talkToBystanders(talker, bystanderText, context);
if (defTargets != null) {
queue.addDefinition("targets", defTargets);
}
}
}
if (defMessage != null) {
queue.addDefinition("message", defMessage);
}
if (defTalker != null) {
queue.addDefinition("talker", defTalker);
}
}
Aggregations