use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class CommandScriptContainer method runAllowedHelpProcedure.
public boolean runAllowedHelpProcedure(dPlayer player, dNPC npc, Map<String, dObject> context) {
// Add the reqId to each of the entries for the determine command
List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "ALLOWED HELP");
long id = DetermineCommand.getNewId();
ScriptBuilder.addObjectToEntries(entries, "ReqId", id);
ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(getName())).setReqId(id).addEntries(entries);
if (context != null) {
OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
oecs.contexts = context;
queue.setContextSource(oecs);
}
queue.start();
return DetermineCommand.hasOutcome(id) && DetermineCommand.getOutcome(id).get(0).equalsIgnoreCase("true");
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class FireworkCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
final dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation();
Element type = (Element) scriptEntry.getObject("type");
Element power = (Element) scriptEntry.getObject("power");
boolean flicker = scriptEntry.hasObject("flicker");
boolean trail = scriptEntry.hasObject("trail");
List<dColor> primary = (List<dColor>) scriptEntry.getObject("primary");
List<dColor> fade = (List<dColor>) scriptEntry.getObject("fade");
// Report to dB
dB.report(scriptEntry, getName(), location.debug() + type.debug() + power.debug() + (flicker ? aH.debugObj("flicker", flicker) : "") + (trail ? aH.debugObj("trail", trail) : "") + aH.debugObj("primary colors", primary.toString()) + (fade != null ? aH.debugObj("fade colors", fade.toString()) : ""));
Firework firework = location.getWorld().spawn(location, Firework.class);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
fireworkMeta.setPower(power.asInt());
Builder fireworkBuilder = FireworkEffect.builder();
fireworkBuilder.with(FireworkEffect.Type.valueOf(type.asString().toUpperCase()));
fireworkBuilder.withColor(Conversion.convertColors(primary));
if (fade != null) {
fireworkBuilder.withFade(Conversion.convertColors(fade));
}
if (flicker) {
fireworkBuilder.withFlicker();
}
if (trail) {
fireworkBuilder.withTrail();
}
fireworkMeta.addEffects(fireworkBuilder.build());
firework.setFireworkMeta(fireworkMeta);
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class OxygenCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element type = scriptEntry.getElement("type");
Element mode = scriptEntry.getElement("mode");
Element amount = scriptEntry.getElement("amount");
dB.report(scriptEntry, getName(), type.debug() + mode.debug() + amount.debug());
dPlayer player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer();
switch(Type.valueOf(type.asString().toUpperCase())) {
case MAXIMUM:
switch(Mode.valueOf(mode.asString().toUpperCase())) {
case SET:
player.setMaximumAir(amount.asInt());
break;
case ADD:
player.setMaximumAir(player.getMaximumAir() + amount.asInt());
break;
case REMOVE:
player.setMaximumAir(player.getMaximumAir() - amount.asInt());
break;
}
return;
case REMAINING:
switch(Mode.valueOf(mode.asString().toUpperCase())) {
case SET:
player.setRemainingAir(amount.asInt());
break;
case ADD:
player.setRemainingAir(player.getRemainingAir() + amount.asInt());
break;
case REMOVE:
player.setRemainingAir(player.getRemainingAir() - amount.asInt());
break;
}
return;
}
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class PermissionCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element action = scriptEntry.getElement("action");
Element permission = scriptEntry.getElement("permission");
Element group = scriptEntry.getElement("group");
dWorld world = (dWorld) scriptEntry.getObject("world");
// Report to dB
dB.report(scriptEntry, getName(), action.debug() + permission.debug() + (group != null ? group.debug() : "") + (world != null ? world.debug() : ""));
World bukkitWorld = null;
if (world != null) {
bukkitWorld = world.getWorld();
}
OfflinePlayer player = ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer() : null;
switch(Action.valueOf(action.asString().toUpperCase())) {
case ADD:
if (group != null) {
if (Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
dB.echoDebug(scriptEntry, "Group " + group + " already has permission " + permission);
} else {
Depends.permissions.groupAdd(bukkitWorld, group.asString(), permission.asString());
}
} else {
if (Depends.permissions.playerHas(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
dB.echoDebug(scriptEntry, "Player " + player.getName() + " already has permission " + permission);
} else {
Depends.permissions.playerAdd(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
}
}
return;
case REMOVE:
if (group != null) {
if (!Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
dB.echoDebug(scriptEntry, "Group " + group + " does not have access to permission " + permission);
} else {
Depends.permissions.groupRemove(bukkitWorld, group.asString(), permission.asString());
}
} else {
if (!Depends.permissions.playerHas(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
dB.echoDebug(scriptEntry, "Player " + player.getName() + " does not have access to permission " + permission);
} else {
Depends.permissions.playerRemove(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
}
}
return;
}
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class StatisticCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_players = false;
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
scriptEntry.addObject("action", arg.asElement());
} else if (arg.matchesPrefix("players") && !scriptEntry.hasObject("players") && arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("players", arg.asType(dList.class));
specified_players = true;
} else if (!scriptEntry.hasObject("statistic") && arg.matchesEnum(Statistic.values())) {
scriptEntry.addObject("statistic", arg.asElement());
} else if (!scriptEntry.hasObject("amount") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
scriptEntry.addObject("amount", arg.asElement());
} else if (arg.matchesPrefix("qualifier", "q") && !scriptEntry.hasObject("material") && !scriptEntry.hasObject("entity")) {
if (arg.matchesArgumentType(dMaterial.class)) {
scriptEntry.addObject("material", arg.asType(dMaterial.class));
} else if (arg.matchesArgumentType(dEntity.class)) {
scriptEntry.addObject("entity", arg.asType(dEntity.class));
}
}
}
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Must specify a valid action!");
}
if (!scriptEntry.hasObject("statistic")) {
throw new InvalidArgumentsException("Must specify a valid Statistic!");
}
if (!scriptEntry.hasObject("amount")) {
scriptEntry.addObject("amount", new Element(1));
}
Statistic.Type type = Statistic.valueOf(scriptEntry.getElement("statistic").asString().toUpperCase()).getType();
if (type != Statistic.Type.UNTYPED) {
if ((type == Statistic.Type.BLOCK || type == Statistic.Type.ITEM) && !scriptEntry.hasObject("material")) {
throw new InvalidArgumentsException("Must specify a valid " + type.name() + " MATERIAL!");
} else if (type == Statistic.Type.ENTITY && !scriptEntry.hasObject("entity")) {
throw new InvalidArgumentsException("Must specify a valid ENTITY!");
}
}
if (!scriptEntry.hasObject("players") && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && !specified_players) {
scriptEntry.addObject("players", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify()));
}
if (!scriptEntry.hasObject("players")) {
throw new InvalidArgumentsException("Must specify valid players!");
}
}
Aggregations