use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class GameRuleCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Fetch objects
dWorld world = scriptEntry.getdObject("world");
Element gamerule = scriptEntry.getElement("gamerule");
Element value = scriptEntry.getElement("value");
// Report to dB
dB.report(scriptEntry, getName(), world.debug() + gamerule.debug() + value.debug());
// Execute
if (!world.getWorld().setGameRuleValue(gamerule.asString(), value.asString())) {
dB.echoError(scriptEntry.getResidingQueue(), "Invalid gamerule!");
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class PlayEffectCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Extract objects from ScriptEntry
List<dLocation> locations = (List<dLocation>) scriptEntry.getObject("location");
List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
Effect effect = (Effect) scriptEntry.getObject("effect");
Particle particleEffect = (Particle) scriptEntry.getObject("particleeffect");
Element iconcrack = scriptEntry.getElement("iconcrack");
Element iconcrack_data = scriptEntry.getElement("iconcrack_data");
Element iconcrack_type = scriptEntry.getElement("iconcrack_type");
Element radius = scriptEntry.getElement("radius");
Element data = scriptEntry.getElement("data");
Element qty = scriptEntry.getElement("qty");
dLocation offset = scriptEntry.getdObject("offset");
// Report to dB
dB.report(scriptEntry, getName(), (effect != null ? aH.debugObj("effect", effect.getName()) : particleEffect != null ? aH.debugObj("special effect", particleEffect.getName()) : iconcrack_type.debug() + iconcrack.debug() + (iconcrack_data != null ? iconcrack_data.debug() : "")) + aH.debugObj("locations", locations.toString()) + (targets != null ? aH.debugObj("targets", targets.toString()) : "") + radius.debug() + data.debug() + qty.debug() + offset.debug());
for (dLocation location : locations) {
// Slightly increase the location's Y so effects don't seem to come out of the ground
location.add(0, 1, 0);
// Play the Bukkit effect the number of times specified
if (effect != null) {
for (int n = 0; n < qty.asInt(); n++) {
if (targets != null) {
for (dPlayer player : targets) {
if (player.isValid() && player.isOnline()) {
effect.playFor(player.getPlayerEntity(), location, data.asInt());
}
}
} else {
effect.play(location, data.asInt(), radius.asInt());
}
}
} else // Play a ParticleEffect
if (particleEffect != null) {
float osX = (float) offset.getX();
float osY = (float) offset.getY();
float osZ = (float) offset.getZ();
List<Player> players = new ArrayList<Player>();
if (targets == null) {
float rad = radius.asFloat();
for (Player player : location.getWorld().getPlayers()) {
if (player.getLocation().distanceSquared(location) < rad * rad) {
players.add(player);
}
}
} else {
for (dPlayer player : targets) {
if (player.isValid() && player.isOnline()) {
players.add(player.getPlayerEntity());
}
}
}
for (Player player : players) {
particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat());
}
} else // Play an iconcrack (item break) effect
{
List<Player> players = new ArrayList<Player>();
if (targets == null) {
float rad = radius.asFloat();
for (Player player : location.getWorld().getPlayers()) {
if (player.getLocation().distanceSquared(location) < rad * rad) {
players.add(player);
}
}
} else {
for (dPlayer player : targets) {
if (player.isValid() && player.isOnline()) {
players.add(player.getPlayerEntity());
}
}
}
// TODO: better this all
if (iconcrack_type.asString().equalsIgnoreCase("iconcrack")) {
ItemStack itemStack = new ItemStack(iconcrack.asInt(), 1, (short) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("ITEM_CRACK");
for (Player player : players) {
particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), itemStack);
}
} else if (iconcrack_type.asString().equalsIgnoreCase("blockcrack")) {
MaterialData materialData = new MaterialData(iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_CRACK");
for (Player player : players) {
particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData);
}
} else {
// blockdust
MaterialData materialData = new MaterialData(iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_DUST");
for (Player player : players) {
particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData);
}
}
}
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class PlaySoundCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities") && arg.matchesArgumentList(dLocation.class)) {
scriptEntry.addObject("locations", arg.asType(dList.class).filter(dLocation.class));
} else if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities") && arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dPlayer.class));
} else if (!scriptEntry.hasObject("volume") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("volume, v")) {
scriptEntry.addObject("volume", arg.asElement());
} else if (!scriptEntry.hasObject("pitch") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("pitch, p")) {
scriptEntry.addObject("pitch", arg.asElement());
} else if (!scriptEntry.hasObject("sound") && arg.matchesPrimitive(aH.PrimitiveType.String)) {
scriptEntry.addObject("sound", arg.asElement());
} else if (!scriptEntry.hasObject("custom") && arg.matches("custom")) {
scriptEntry.addObject("custom", Element.TRUE);
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("sound")) {
throw new InvalidArgumentsException("Missing sound argument!");
}
if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Missing location argument!");
}
scriptEntry.defaultObject("volume", new Element(1));
scriptEntry.defaultObject("pitch", new Element(1));
scriptEntry.defaultObject("custom", Element.FALSE);
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class SignCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
String direction = scriptEntry.hasObject("direction") ? ((Element) scriptEntry.getObject("direction")).asString() : null;
Element typeElement = scriptEntry.getElement("type");
dList text = (dList) scriptEntry.getObject("text");
dLocation location = (dLocation) scriptEntry.getObject("location");
// Report to dB
dB.report(scriptEntry, getName(), typeElement.debug() + location.debug() + text.debug());
Type type = Type.valueOf(typeElement.asString().toUpperCase());
Block sign = location.getBlock();
if (type != Type.AUTOMATIC || (sign.getType() != Material.WALL_SIGN && sign.getType() != Material.SIGN_POST)) {
sign.setType(type == Type.WALL_SIGN ? Material.WALL_SIGN : Material.SIGN_POST, false);
}
BlockState signState = sign.getState();
Utilities.setSignLines((Sign) signState, text.toArray(4));
if (direction != null) {
Utilities.setSignRotation(signState, direction);
} else if (type == Type.WALL_SIGN) {
Utilities.setSignRotation(signState);
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class SwitchCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(dLocation.class)) {
scriptEntry.addObject("locations", arg.asType(dList.class));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class)) {
scriptEntry.addObject("duration", arg.asType(Duration.class));
} else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.values())) {
scriptEntry.addObject("switchstate", new Element(arg.getValue().toUpperCase()));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("locations")) {
throw new InvalidArgumentsException("Must specify a location!");
}
scriptEntry.defaultObject("duration", new Duration(0));
scriptEntry.defaultObject("switchstate", new Element("TOGGLE"));
}
Aggregations