use of com.denizenscript.denizen.objects.MaterialTag 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.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class SignCommand method setWallSign.
public void setWallSign(Block sign, BlockFace bf, MaterialTag material) {
sign.setType(material == null ? Material.OAK_WALL_SIGN : material.getMaterial(), false);
MaterialTag signMaterial = new MaterialTag(sign);
MaterialDirectional.getFrom(signMaterial).setFacing(bf);
sign.setBlockData(signMaterial.getModernData());
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class TakeCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
InventoryTag inventory = scriptEntry.getObjectTag("inventory");
ElementTag quantity = scriptEntry.getElement("quantity");
ListTag displayNameList = scriptEntry.getObjectTag("displayname");
List<ItemTag> scriptItemList = scriptEntry.getObjectTag("scriptitem");
ListTag slotList = scriptEntry.getObjectTag("slot");
ListTag titleAuthor = scriptEntry.getObjectTag("cover");
ElementTag nbtKey = scriptEntry.getElement("nbt_key");
ElementTag matcherText = scriptEntry.getElement("matcher_text");
ListTag flagList = scriptEntry.getObjectTag("flag_name");
List<MaterialTag> materialList = scriptEntry.getObjectTag("material");
Type type = (Type) scriptEntry.getObject("type");
List<ItemTag> items = scriptEntry.getObjectTag("items");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Type", type.name()), quantity, inventory, displayNameList, db("scriptname", scriptItemList), db("Items", items), slotList, nbtKey, flagList, matcherText, db("material", materialList), titleAuthor);
}
switch(type) {
case INVENTORY:
{
inventory.clear();
break;
}
case ITEMINHAND:
{
Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
int inHandAmt = player.getEquipment().getItemInMainHand().getAmount();
int theAmount = (int) quantity.asDouble();
ItemStack newHandItem = new ItemStack(Material.AIR);
if (theAmount > inHandAmt) {
Debug.echoDebug(scriptEntry, "...player did not have enough of the item in hand, taking all...");
player.getEquipment().setItemInMainHand(newHandItem);
} else {
// amount is just right!
if (theAmount == inHandAmt) {
player.getEquipment().setItemInMainHand(newHandItem);
} else {
// amount is less than what's in hand, need to make a new itemstack of what's left...
newHandItem = player.getEquipment().getItemInMainHand().clone();
newHandItem.setAmount(inHandAmt - theAmount);
player.getEquipment().setItemInMainHand(newHandItem);
player.updateInventory();
}
}
break;
}
case CURSORITEM:
{
Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
int currentAmount = player.getItemOnCursor().getAmount();
int takeAmount = (int) quantity.asDouble();
ItemStack newItem = new ItemStack(Material.AIR);
if (takeAmount > currentAmount) {
Debug.echoDebug(scriptEntry, "...player did not have enough of the item on cursor, taking all...");
player.setItemOnCursor(newItem);
} else {
if (takeAmount == currentAmount) {
player.setItemOnCursor(newItem);
} else {
newItem = player.getItemOnCursor().clone();
newItem.setAmount(currentAmount - takeAmount);
player.setItemOnCursor(newItem);
player.updateInventory();
}
}
break;
}
case MONEY:
{
if (Depends.economy == null) {
Debug.echoError(scriptEntry, "No economy loaded! Have you installed Vault and a compatible economy plugin?");
return;
}
Depends.economy.withdrawPlayer(Utilities.getEntryPlayer(scriptEntry).getOfflinePlayer(), quantity.asDouble());
break;
}
case XP:
{
Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().giveExp(-quantity.asInt());
break;
}
case RAWEXACT:
{
if (items == null) {
Debug.echoError(scriptEntry, "Must specify item/items!");
return;
}
for (ItemTag targetItem : items) {
takeByMatcher(inventory, (item) -> targetItem.matchesRawExact(new ItemTag(item)), quantity.asInt());
}
break;
}
case ITEM:
{
if (items == null) {
Debug.echoError(scriptEntry, "Must specify item/items!");
return;
}
for (ItemTag item : items) {
ItemStack is = item.getItemStack().clone();
is.setAmount(quantity.asInt());
if (!removeItem(inventory.getInventory(), item, item.getAmount())) {
Debug.echoDebug(scriptEntry, "Inventory does not contain at least " + quantity.asInt() + " of " + item.identify() + "... Taking all...");
}
}
break;
}
case BYDISPLAY:
{
if (displayNameList == null) {
Debug.echoError(scriptEntry, "Must specify a displayname!");
return;
}
for (String name : displayNameList) {
takeByMatcher(inventory, (item) -> item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equalsIgnoreCase(name), quantity.asInt());
}
break;
}
case BYCOVER:
{
if (titleAuthor == null) {
Debug.echoError(scriptEntry, "Must specify a cover!");
return;
}
takeByMatcher(inventory, (item) -> item.hasItemMeta() && item.getItemMeta() instanceof BookMeta && equalOrNull(titleAuthor.get(0), ((BookMeta) item.getItemMeta()).getTitle()) && (titleAuthor.size() == 1 || equalOrNull(titleAuthor.get(1), ((BookMeta) item.getItemMeta()).getAuthor())), quantity.asInt());
break;
}
case FLAGGED:
{
if (flagList == null) {
Debug.echoError(scriptEntry, "Must specify a flag name!");
return;
}
for (String flag : flagList) {
takeByMatcher(inventory, (item) -> new ItemTag(item).getFlagTracker().hasFlag(flag), quantity.asInt());
}
break;
}
case NBT:
{
if (nbtKey == null) {
Debug.echoError(scriptEntry, "Must specify an NBT key!");
return;
}
takeByMatcher(inventory, (item) -> CustomNBT.hasCustomNBT(item, nbtKey.asString(), CustomNBT.KEY_DENIZEN), quantity.asInt());
break;
}
case SCRIPTNAME:
{
if (scriptItemList == null) {
Debug.echoError(scriptEntry, "Must specify a valid script name!");
return;
}
for (ItemTag scriptedItem : scriptItemList) {
String script = scriptedItem.getScriptName();
if (script == null) {
Debug.echoError(scriptEntry, "Item '" + scriptedItem.debuggable() + "' is not a scripted item, cannot take by scriptname.");
continue;
}
takeByMatcher(inventory, (item) -> script.equalsIgnoreCase(new ItemTag(item).getScriptName()), quantity.asInt());
}
break;
}
case MATERIAL:
{
if (materialList == null) {
Debug.echoError(scriptEntry, "Must specify a valid material!");
return;
}
for (MaterialTag material : materialList) {
takeByMatcher(inventory, (item) -> item.getType() == material.getMaterial() && !(new ItemTag(item).isItemscript()), quantity.asInt());
}
break;
}
case MATCHER:
{
if (matcherText == null) {
Debug.echoError(scriptEntry, "Must specify an item matcher!");
return;
}
takeByMatcher(inventory, (item) -> BukkitScriptEvent.tryItem(new ItemTag(item), matcherText.asString()), quantity.asInt());
break;
}
case SLOT:
{
for (String slot : slotList) {
int slotId = SlotHelper.nameToIndexFor(slot, inventory.getInventory().getHolder());
if (slotId == -1 || slotId >= inventory.getSize()) {
Debug.echoError(scriptEntry, "The input '" + slot + "' is not a valid slot!");
return;
}
ItemStack original = inventory.getInventory().getItem(slotId);
if (original != null && original.getType() != Material.AIR) {
if (original.getAmount() > quantity.asInt()) {
original.setAmount(original.getAmount() - quantity.asInt());
inventory.setSlots(slotId, original);
} else {
inventory.setSlots(slotId, new ItemStack(Material.AIR));
}
}
}
break;
}
}
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class HeadCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
Deprecations.headCommand.warn(scriptEntry);
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
ElementTag skin = scriptEntry.getElement("skin");
MaterialTag material = scriptEntry.getObjectTag("material");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("entities", entities), skin, material);
}
ItemStack item = null;
if (skin != null) {
item = new ItemStack(Material.PLAYER_HEAD);
ItemMeta itemMeta = item.getItemMeta();
((SkullMeta) itemMeta).setOwner(skin.asString());
item.setItemMeta(itemMeta);
} else if (material != null) {
item = new ItemStack(material.getMaterial());
}
for (EntityTag entity : entities) {
if (entity.isCitizensNPC()) {
if (!entity.getDenizenNPC().getCitizen().hasTrait(Equipment.class)) {
entity.getDenizenNPC().getCitizen().addTrait(Equipment.class);
}
Equipment trait = entity.getDenizenNPC().getCitizen().getOrAddTrait(Equipment.class);
trait.set(1, item);
} else if (entity.isPlayer()) {
entity.getPlayer().getInventory().setHelmet(item);
} else {
if (entity.isLivingEntity() && entity.getLivingEntity().getEquipment() != null) {
entity.getLivingEntity().getEquipment().setHelmet(item);
} else {
Debug.echoError(scriptEntry, entity.identify() + " is not a living entity!");
}
}
}
}
use of com.denizenscript.denizen.objects.MaterialTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemBlockMaterial method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("block_material") && mechanism.requireObject(MaterialTag.class)) {
BlockDataMeta meta = (BlockDataMeta) item.getItemMeta();
MaterialTag mat = mechanism.valueAsType(MaterialTag.class);
meta.setBlockData(mat.getModernData());
item.setItemMeta(meta);
}
}
Aggregations