use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerClicksBlockScriptEvent method playerClicksBlock.
@EventHandler
public void playerClicksBlock(PlayerInteractEvent event) {
if (event.getAction() == Action.PHYSICAL) {
return;
}
blockMaterial = event.hasBlock() ? new MaterialTag(event.getClickedBlock()) : new MaterialTag(Material.AIR);
hand = new ElementTag(event.getHand().name());
item = new ItemTag(event.getItem());
location = event.hasBlock() ? new LocationTag(event.getClickedBlock().getLocation()) : null;
click_type = new ElementTag(event.getAction().name());
// Spigot is dumb!
cancelled = event.isCancelled() && event.useItemInHand() == Event.Result.DENY;
this.event = event;
// Explicitly don't use `fire(event)` due to spigot bork
fire();
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemEnchantedScriptEvent method onItemEnchanted.
@EventHandler
public void onItemEnchanted(EnchantItemEvent event) {
entity = new EntityTag(event.getEnchanter());
location = new LocationTag(event.getEnchantBlock().getLocation());
inventory = InventoryTag.mirrorBukkitInventory(event.getInventory());
item = new ItemTag(event.getItem());
button = new ElementTag(event.whichButton());
cost = event.getExpLevelCost();
this.event = event;
fire(event);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerBreaksBlockScriptEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String determination = determinationObj.toString();
Block block = event.getBlock();
if (determinationObj instanceof ElementTag) {
String lower = CoreUtilities.toLowerCase(determination);
if (lower.equals("nothing")) {
event.setExpToDrop(0);
event.setDropItems(false);
return true;
} else if (((ElementTag) determinationObj).isInt()) {
event.setExpToDrop(((ElementTag) determinationObj).asInt());
return true;
}
}
if (Argument.valueOf(determination).matchesArgumentList(ItemTag.class)) {
event.setDropItems(false);
for (ItemTag newItem : ListTag.valueOf(determination, getTagContext(path)).filter(ItemTag.class, path.container, true)) {
// Drop each item
block.getWorld().dropItemNaturally(block.getLocation(), newItem.getItemStack());
}
return true;
}
return super.applyDetermination(path, determinationObj);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerChangesGamemodeScriptEvent method onPlayerChangesGamemode.
@EventHandler
public void onPlayerChangesGamemode(PlayerGameModeChangeEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
gamemode = new ElementTag(event.getNewGameMode().name());
this.event = event;
fire(event);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityShootsBowEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String determination = determinationObj.toString();
if (determinationObj instanceof ElementTag) {
String lower = CoreUtilities.toLowerCase(determination);
if (lower.equals("keep_item")) {
event.setConsumeItem(false);
if (entity.isPlayer()) {
final Player p = entity.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), p::updateInventory, 1);
}
return true;
}
}
if (Argument.valueOf(determination).matchesArgumentList(EntityTag.class)) {
cancelled = true;
cancellationChanged();
// Get the list of entities
List<EntityTag> newProjectiles = ListTag.getListFor(determinationObj, getTagContext(path)).filter(EntityTag.class, path.container, true);
// Go through all the entities, spawning/teleporting them
for (EntityTag newProjectile : newProjectiles) {
newProjectile.spawnAt(entity.getEyeLocation().add(entity.getEyeLocation().getDirection()));
// where applicable
if (newProjectile.isProjectile()) {
newProjectile.setShooter(entity);
}
}
// Mount the projectiles on top of each other
Position.mount(Conversion.convertEntities(newProjectiles));
// Get the last entity on the list, i.e. the one at the bottom
// if there are many mounted on top of each other
Entity lastProjectile = newProjectiles.get(newProjectiles.size() - 1).getBukkitEntity();
// Give it the same velocity as the arrow that would
// have been shot by the bow
// Note: No, I can't explain why this has to be multiplied by three, it just does.
lastProjectile.setVelocity(event.getEntity().getLocation().getDirection().multiply(event.getForce() * 3));
return true;
}
return super.applyDetermination(path, determinationObj);
}
Aggregations