use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityScriptContainer method getEntityFrom.
public EntityTag getEntityFrom(PlayerTag player, NPCTag npc) {
EntityTag entity;
try {
TagContext context = new BukkitTagContext(player, npc, new ScriptTag(this));
if (contains("entity_type", String.class)) {
String entityType = TagManager.tag((getString("entity_type", "")), context);
entity = EntityTag.valueOf(entityType, context);
} else {
throw new Exception("Missing entity_type argument!");
}
if (contains("flags", Map.class)) {
YamlConfiguration flagSection = getConfigurationSection("flags");
MapTagFlagTracker tracker = new MapTagFlagTracker();
for (StringHolder key : flagSection.getKeys(false)) {
tracker.setFlag(key.str, CoreUtilities.objectToTagForm(flagSection.get(key.str), context, true, true), null);
}
entity.safeAdjust(new Mechanism("flag_map", tracker.map, context));
}
if (contains("mechanisms", Map.class)) {
YamlConfiguration mechSection = getConfigurationSection("mechanisms");
Set<StringHolder> strings = mechSection.getKeys(false);
for (StringHolder string : strings) {
ObjectTag obj = CoreUtilities.objectToTagForm(mechSection.get(string.low), context, true, true);
entity.safeAdjust(new Mechanism(string.low, obj, context));
}
}
boolean any = false;
Set<StringHolder> strings = getContents().getKeys(false);
for (StringHolder string : strings) {
if (!nonMechanismKeys.contains(string.low)) {
any = true;
ObjectTag obj = CoreUtilities.objectToTagForm(getContents().get(string.low), context, true, true);
entity.safeAdjust(new Mechanism(string.low, obj, context));
}
}
if (any) {
Deprecations.entityMechanismsFormat.warn(this);
}
if (entity == null || entity.isUnique()) {
return null;
}
entity.setEntityScript(getName());
} catch (Exception e) {
Debug.echoError("Woah! An exception has been called with this entity script!");
Debug.echoError(e);
entity = null;
}
return entity;
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class StatisticCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag action = scriptEntry.getElement("action");
ListTag players = scriptEntry.getObjectTag("players");
ElementTag statistic = scriptEntry.getElement("statistic");
ElementTag amount = scriptEntry.getElement("amount");
MaterialTag material = scriptEntry.getObjectTag("material");
EntityTag entity = scriptEntry.getObjectTag("entity");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), action, statistic, amount, players, material, entity);
}
Action act = Action.valueOf(action.asString().toUpperCase());
Statistic stat = Statistic.valueOf(statistic.asString().toUpperCase());
int amt = amount.asInt();
switch(stat.getType()) {
case BLOCK:
case ITEM:
Material mat = material.getMaterial();
switch(act) {
case ADD:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.incrementStatistic(stat, mat, amt);
}
break;
case TAKE:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.decrementStatistic(stat, mat, amt);
}
break;
case SET:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.setStatistic(stat, mat, amt);
}
break;
}
break;
case ENTITY:
EntityType ent = entity.getBukkitEntityType();
switch(act) {
case ADD:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.incrementStatistic(stat, ent, amt);
}
break;
case TAKE:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.decrementStatistic(stat, ent, amt);
}
break;
case SET:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.setStatistic(stat, ent, amt);
}
break;
}
break;
case UNTYPED:
switch(act) {
case ADD:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.incrementStatistic(stat, amt);
}
break;
case TAKE:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.decrementStatistic(stat, amt);
}
break;
case SET:
for (PlayerTag player : players.filter(PlayerTag.class, scriptEntry)) {
player.setStatistic(stat, amt);
}
break;
}
break;
}
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerUsesPortalScriptEvent method onPlayerEntersPortal.
@EventHandler
public void onPlayerEntersPortal(PlayerPortalEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
entity = new EntityTag(event.getPlayer());
to = event.getTo() == null ? null : new LocationTag(event.getTo());
from = new LocationTag(event.getFrom());
this.event = event;
fire(event);
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerThrowsEggScriptEvent method onPlayerThrowsEgg.
@EventHandler
public void onPlayerThrowsEgg(PlayerEggThrowEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
Entity eggEntity = event.getEgg();
EntityTag.rememberEntity(eggEntity);
egg = new EntityTag(event.getEgg());
this.event = event;
cancelled = false;
fire(event);
EntityTag.forgetEntity(eggEntity);
}
use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.
the class VehicleDestroyedScriptEvent method onVehicleDestroyed.
@EventHandler
public void onVehicleDestroyed(VehicleDestroyEvent event) {
vehicle = new EntityTag(event.getVehicle());
entity = event.getAttacker() != null ? new EntityTag(event.getAttacker()) : null;
this.event = event;
fire(event);
}
Aggregations