use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class InvisibleCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
Element state = scriptEntry.getElement("state");
dEntity target = (dEntity) scriptEntry.getObject("target");
// Report to dB
dB.report(scriptEntry, getName(), state.debug() + target.debug());
if (target.isCitizensNPC()) {
NPC npc = target.getDenizenNPC().getCitizen();
if (!npc.hasTrait(InvisibleTrait.class)) {
npc.addTrait(InvisibleTrait.class);
}
InvisibleTrait trait = npc.getTrait(InvisibleTrait.class);
switch(Action.valueOf(state.asString().toUpperCase())) {
case FALSE:
trait.setInvisible(false);
break;
case TRUE:
trait.setInvisible(true);
break;
case TOGGLE:
trait.toggle();
break;
}
} else {
switch(Action.valueOf(state.asString().toUpperCase())) {
case FALSE:
if (target.getBukkitEntity() instanceof ArmorStand) {
((ArmorStand) target.getBukkitEntity()).setVisible(true);
} else {
target.getLivingEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
}
break;
case TRUE:
if (target.getBukkitEntity() instanceof ArmorStand) {
((ArmorStand) target.getBukkitEntity()).setVisible(false);
} else {
new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1).apply(target.getLivingEntity());
}
break;
case TOGGLE:
if (target.getBukkitEntity() instanceof ArmorStand) {
if (((ArmorStand) target.getBukkitEntity()).isVisible()) {
((ArmorStand) target.getBukkitEntity()).setVisible(true);
} else {
((ArmorStand) target.getBukkitEntity()).setVisible(false);
}
} else {
if (target.getLivingEntity().hasPotionEffect(PotionEffectType.INVISIBILITY)) {
target.getLivingEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
} else {
new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1).apply(target.getLivingEntity());
}
}
break;
}
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class TakeCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dInventory inventory = (dInventory) scriptEntry.getObject("inventory");
Element qty = scriptEntry.getElement("qty");
Element displayname = scriptEntry.getElement("displayname");
Element slot = scriptEntry.getElement("slot");
dList titleAuthor = scriptEntry.getdObject("cover");
Type type = (Type) scriptEntry.getObject("type");
Object items_object = scriptEntry.getObject("items");
List<dItem> items = null;
if (items_object != null) {
items = (List<dItem>) items_object;
}
dB.report(scriptEntry, getName(), aH.debugObj("Type", type.name()) + qty.debug() + (inventory != null ? inventory.debug() : "") + (displayname != null ? displayname.debug() : "") + aH.debugObj("Items", items) + (slot != null ? slot.debug() : "") + (titleAuthor != null ? titleAuthor.debug() : ""));
switch(type) {
case INVENTORY:
inventory.clear();
break;
case ITEMINHAND:
int inHandAmt = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getItemInHand().getAmount();
int theAmount = (int) qty.asDouble();
ItemStack newHandItem = new ItemStack(0);
if (theAmount > inHandAmt) {
dB.echoDebug(scriptEntry, "...player did not have enough of the item in hand, so Denizen just took as many as it could. To avoid this situation, use an IF <PLAYER.ITEM_IN_HAND.QTY>.");
((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setItemInHand(newHandItem);
} else {
// amount is just right!
if (theAmount == inHandAmt) {
((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setItemInHand(newHandItem);
} else {
// amount is less than what's in hand, need to make a new itemstack of what's left...
newHandItem = new ItemStack(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getItemInHand().getType(), inHandAmt - theAmount, ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getItemInHand().getData().getData());
newHandItem.setItemMeta(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().getItemInHand().getItemMeta());
((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setItemInHand(newHandItem);
((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().updateInventory();
}
}
break;
case MONEY:
if (Depends.economy != null) {
Depends.economy.withdrawPlayer(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer(), qty.asDouble());
} else {
dB.echoError(scriptEntry.getResidingQueue(), "No economy loaded! Have you installed Vault and a compatible economy plugin?");
}
break;
case ITEM:
for (dItem item : items) {
ItemStack is = item.getItemStack();
is.setAmount(qty.asInt());
if (!inventory.removeItem(item, item.getAmount())) {
dB.echoDebug(scriptEntry, "Inventory does not contain at least " + qty.asInt() + " of " + item.getFullString() + "... Taking as much as possible...");
}
}
break;
case BYDISPLAY:
int found_items = 0;
if (displayname == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Must specify a displayname!");
return;
}
for (ItemStack it : inventory.getContents()) {
if (found_items < qty.asInt() && it != null && it.hasItemMeta() && it.getItemMeta().hasDisplayName() && it.getItemMeta().getDisplayName().equalsIgnoreCase(displayname.identify())) {
int amt = it.getAmount();
if (found_items + it.getAmount() <= qty.asInt()) {
inventory.getInventory().removeItem(it);
} else {
it.setAmount(it.getAmount() - (qty.asInt() - found_items));
break;
}
found_items += amt;
}
}
break;
case SLOT:
inventory.setSlots(slot.asInt() - 1, new ItemStack(Material.AIR));
break;
case BYCOVER:
inventory.removeBook(titleAuthor.get(0), titleAuthor.size() > 1 ? titleAuthor.get(1) : null, qty.asInt());
break;
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class AnchorCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
Action action = (Action) scriptEntry.getObject("action");
dLocation location = (dLocation) scriptEntry.getObject("location");
Element range = (Element) scriptEntry.getObject("range");
Element id = (Element) scriptEntry.getObject("id");
dNPC npc = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
// Report to dB
dB.report(scriptEntry, getName(), npc.debug() + action.name() + id.debug() + (location != null ? location.debug() : "") + (range != null ? range.debug() : ""));
if (!npc.getCitizen().hasTrait(Anchors.class)) {
npc.getCitizen().addTrait(Anchors.class);
}
switch(action) {
case ADD:
npc.getCitizen().getTrait(Anchors.class).addAnchor(id.asString(), location);
return;
case ASSUME:
{
Anchor n = npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString());
if (n == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
} else {
npc.getEntity().teleport(n.getLocation());
}
}
return;
case WALKNEAR:
{
Anchor n = npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString());
if (n == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
} else if (range == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Must specify a range!");
} else {
npc.getNavigator().setTarget(Utilities.getWalkableLocationNear(n.getLocation(), range.asInt()));
}
}
return;
case WALKTO:
{
Anchor n = npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString());
if (n == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
} else {
npc.getNavigator().setTarget(n.getLocation());
}
}
return;
case REMOVE:
{
Anchor n = npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString());
if (n == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
} else {
npc.getCitizen().getTrait(Anchors.class).removeAnchor(n);
}
}
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class BreakCommand method execute.
// <--[action]
// @Actions
// dig
//
// @Triggers when the NPC breaks a block with the Break Command
//
// @Context
// <context.location> returns the location the NPC Dug
// <context.material> Returns the Block dug
//
// -->
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
final dLocation location = (dLocation) scriptEntry.getObject("location");
final dNPC npc = (dNPC) scriptEntry.getObject("entity");
Element radius = scriptEntry.getElement("radius");
final HashMap<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
context.put("location", location);
context.put("material", material);
dB.report(scriptEntry, getName(), location.debug() + npc.debug() + radius.debug());
final ScriptEntry se = scriptEntry;
BlockBreaker.BlockBreakerConfiguration config = new BlockBreaker.BlockBreakerConfiguration();
config.item(npc.getLivingEntity().getEquipment().getItemInHand());
config.radius(radius.asDouble());
config.callback(new Runnable() {
@Override
public void run() {
npc.action("dig", null, context);
se.setFinished(true);
}
});
BlockBreaker breaker = npc.getCitizen().getBlockBreaker(location.getBlock(), config);
if (breaker.shouldExecute()) {
TaskRunnable run = new TaskRunnable(breaker);
run.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), run, 0, 1);
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class TextTags method specialCharacterTags.
@TagManager.TagEvents
public void specialCharacterTags(ReplaceableTagEvent event) {
if (!event.getName().startsWith("&")) {
return;
}
String lower = CoreUtilities.toLowerCase(event.getName());
Attribute attribute = event.getAttributes();
// -->
if (lower.equals("&nl")) {
event.setReplaced(new Element("\n").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&")) {
event.setReplaced(new Element("&").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&cm")) {
event.setReplaced(new Element(",").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&ss")) {
event.setReplaced(new Element("§").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&sq")) {
event.setReplaced(new Element("'").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&sp")) {
event.setReplaced(new Element(String.valueOf(' ')).getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals(" ")) {
event.setReplaced(new Element(String.valueOf((char) 0x00A0)).getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&dq")) {
event.setReplaced(new Element("\"").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&co")) {
event.setReplaced(new Element(":").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&sc")) {
event.setReplaced(new Element(String.valueOf((char) 0x2011)).getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&rb")) {
event.setReplaced(new Element("]").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&lb")) {
event.setReplaced(new Element("[").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&rc")) {
event.setReplaced(new Element("}").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&lc")) {
event.setReplaced(new Element("{").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&ns")) {
event.setReplaced(new Element("#").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&pc")) {
event.setReplaced(new Element("%").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&pipe")) {
event.setReplaced(new Element("|").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&ds")) {
event.setReplaced(new Element("$").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("<")) {
event.setReplaced(new Element(String.valueOf((char) 0x01)).getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals(">")) {
event.setReplaced(new Element(String.valueOf((char) 0x02)).getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&bs")) {
event.setReplaced(new Element("\\").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&at")) {
event.setReplaced(new Element("@").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&dot")) {
event.setReplaced(new Element(".").getAttribute(attribute.fulfill(1)));
} else // -->
if (lower.equals("&hrt")) {
event.setReplaced(new Element("♥").getAttribute(attribute.fulfill(1)));
}
// -->
if (attribute.startsWith("&chr") && attribute.hasContext(1)) {
event.setReplaced(String.valueOf((char) Integer.parseInt(attribute.getContext(1), 16)));
}
}
Aggregations