use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class ClickTrigger method clickTrigger.
// <--[language]
// @name Click Triggers
// @group NPC Interact Scripts
// @description
// Click Triggers are triggered when a player right clicks the NPC.
//
// These are very basic with no extraneous complexity.
//
// <code>
// click trigger:
// script:
// - narrate "hi <player.name>"
// </code>
//
// They can optionally have an item matcher with multiple triggers, for the item in the player's hand. For example:
// <code>
// click trigger:
// 1:
// trigger: my_item_script
// script:
// - narrate "Nice item script"
// 2:
// trigger: stone
// script:
// - narrate "Nice vanilla item"
// 3:
// script:
// - narrate "I don't recognize your held item"
// </code>
//
// -->
// <--[action]
// @Actions
// no click trigger
//
// @Triggers when the NPC is clicked but no click trigger fires.
//
// @Context
// None
//
// -->
// Technically defined in TriggerTrait, but placing here instead.
// <--[action]
// @Actions
// click
//
// @Triggers when the NPC is clicked by a player.
//
// @Context
// None
//
// @Determine
// "cancelled" to cancel the click event completely.
//
// -->
@EventHandler
public void clickTrigger(NPCRightClickEvent event) {
if (!event.getNPC().hasTrait(TriggerTrait.class)) {
return;
}
NPCTag npc = new NPCTag(event.getNPC());
if (!npc.getTriggerTrait().isEnabled(name)) {
return;
}
PlayerTag player = PlayerTag.mirrorBukkitPlayer(event.getClicker());
TriggerTrait.TriggerContext trigger = npc.getTriggerTrait().trigger(this, player);
if (!trigger.wasTriggered()) {
return;
}
if (trigger.hasDetermination() && trigger.getDeterminations().containsCaseInsensitive("cancelled")) {
event.setCancelled(true);
return;
}
List<InteractScriptContainer> scripts = npc.getInteractScripts(player, ClickTrigger.class);
boolean any = false;
if (scripts != null) {
for (InteractScriptContainer script : scripts) {
String id = null;
Map<String, String> idMap = script.getIdMapFor(ClickTrigger.class, player);
if (!idMap.isEmpty()) {
ItemTag heldItem = new ItemTag(player.getPlayerEntity().getEquipment().getItemInMainHand());
for (Map.Entry<String, String> entry : idMap.entrySet()) {
String entry_value = TagManager.tag(entry.getValue(), new BukkitTagContext(player, npc, null, false, null));
boolean isMatch = entry_value.isEmpty() || BukkitScriptEvent.tryItem(heldItem, entry_value);
if (script.shouldDebug()) {
Debug.echoDebug(script, "Comparing click trigger '<A>" + entry_value + "<W>' with item '<A>" + heldItem.debuggable() + "<W>': " + (isMatch ? "<GR>Match!" : "<Y>Not a match"));
}
if (isMatch) {
id = entry.getKey();
break;
}
}
}
if (parse(npc, player, script, id)) {
any = true;
}
}
}
if (!any) {
npc.action("no click trigger", player);
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityDrinkingPotion method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("drinking_potion") && mechanism.requireObject(ItemTag.class)) {
ItemTag potion = mechanism.valueAsType(ItemTag.class);
if (potion.getBukkitMaterial() != Material.POTION) {
mechanism.echoError("Invalid item input '" + potion + "': item must be a potion");
return;
}
getWitch().setDrinkingPotion(potion.getItemStack());
}
// -->
if (mechanism.matches("potion_drink_duration") && mechanism.requireObject(DurationTag.class)) {
getWitch().setPotionUseTimeLeft(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class EquipCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
Map<String, ItemTag> equipment = (Map<String, ItemTag>) scriptEntry.getObject("equipment");
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("entities", entities), db("equipment", equipment));
}
for (EntityTag entity : entities) {
if (entity.isGeneric()) {
Debug.echoError(scriptEntry, "Cannot equip generic entity " + entity.identify() + "!");
} else if (entity.isCitizensNPC()) {
NPCTag npc = entity.getDenizenNPC();
if (npc != null) {
Equipment trait = npc.getEquipmentTrait();
if (equipment.get("hand") != null) {
trait.set(0, equipment.get("hand").getItemStack());
}
if (equipment.get("head") != null) {
trait.set(1, equipment.get("head").getItemStack());
}
if (equipment.get("chest") != null) {
trait.set(2, equipment.get("chest").getItemStack());
}
if (equipment.get("legs") != null) {
trait.set(3, equipment.get("legs").getItemStack());
}
if (equipment.get("boots") != null) {
trait.set(4, equipment.get("boots").getItemStack());
}
if (equipment.get("offhand") != null) {
trait.set(5, equipment.get("offhand").getItemStack());
}
if (npc.isSpawned()) {
LivingEntity livingEntity = npc.getLivingEntity();
// TODO: Citizens API for this blob?
if (livingEntity instanceof AbstractHorse) {
if (equipment.get("saddle") != null) {
((AbstractHorse) livingEntity).getInventory().setSaddle(equipment.get("saddle").getItemStack());
}
if (equipment.get("horse_armor") != null) {
if (((AbstractHorse) livingEntity).getInventory() instanceof HorseInventory) {
((HorseInventory) ((AbstractHorse) livingEntity).getInventory()).setArmor(equipment.get("horse_armor").getItemStack());
}
}
} else if (livingEntity instanceof Steerable) {
if (equipment.get("saddle") != null) {
ItemTag saddle = equipment.get("saddle");
if (saddle.getBukkitMaterial() == Material.SADDLE) {
((Steerable) livingEntity).setSaddle(true);
} else {
((Steerable) livingEntity).setSaddle(false);
}
}
}
}
}
} else {
LivingEntity livingEntity = entity.getLivingEntity();
if (livingEntity != null) {
if (livingEntity instanceof AbstractHorse) {
if (equipment.get("saddle") != null) {
((AbstractHorse) livingEntity).getInventory().setSaddle(equipment.get("saddle").getItemStack());
}
if (equipment.get("horse_armor") != null) {
if (((AbstractHorse) livingEntity).getInventory() instanceof HorseInventory) {
((HorseInventory) ((AbstractHorse) livingEntity).getInventory()).setArmor(equipment.get("horse_armor").getItemStack());
}
}
} else if (livingEntity instanceof Steerable) {
if (equipment.get("saddle") != null) {
ItemTag saddle = equipment.get("saddle");
if (saddle.getBukkitMaterial() == Material.SADDLE) {
((Steerable) livingEntity).setSaddle(true);
} else {
((Steerable) livingEntity).setSaddle(false);
}
}
} else {
if (equipment.get("hand") != null) {
livingEntity.getEquipment().setItemInMainHand(equipment.get("hand").getItemStack());
}
if (equipment.get("head") != null) {
livingEntity.getEquipment().setHelmet(equipment.get("head").getItemStack());
}
if (equipment.get("chest") != null) {
livingEntity.getEquipment().setChestplate(equipment.get("chest").getItemStack());
}
if (equipment.get("legs") != null) {
livingEntity.getEquipment().setLeggings(equipment.get("legs").getItemStack());
}
if (equipment.get("boots") != null) {
livingEntity.getEquipment().setBoots(equipment.get("boots").getItemStack());
}
if (equipment.get("offhand") != null) {
livingEntity.getEquipment().setItemInOffHand(equipment.get("offhand").getItemStack());
}
}
}
}
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemRawNBT method setFullNBT.
public void setFullNBT(ItemTag item, MapTag input, TagContext context, boolean retainOld) {
CompoundTag compoundTag = retainOld ? NMSHandler.getItemHelper().getNbtData(item.getItemStack()) : null;
Map<String, Tag> result = compoundTag == null ? new LinkedHashMap<>() : new LinkedHashMap<>(compoundTag.getValue());
for (Map.Entry<StringHolder, ObjectTag> entry : input.map.entrySet()) {
try {
Tag tag = convertObjectToNbt(entry.getValue().toString(), context, "(item).");
if (tag != null) {
result.put(entry.getKey().str, tag);
}
} catch (Exception ex) {
Debug.echoError("Raw_Nbt input failed for root key '" + entry.getKey().str + "'.");
Debug.echoError(ex);
return;
}
}
compoundTag = NMSHandler.getInstance().createCompoundTag(result);
item.setItemStack(NMSHandler.getItemHelper().setNbtData(item.getItemStack(), compoundTag));
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class LingeringPotionSplashScriptEvent method onLingeringPotionSplash.
@EventHandler
public void onLingeringPotionSplash(LingeringPotionSplashEvent event) {
item = new ItemTag(event.getEntity().getItem());
location = new LocationTag(event.getAreaEffectCloud().getLocation());
this.event = event;
fire(event);
}
Aggregations