use of net.aufdemrand.denizencore.objects.Element 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.denizencore.objects.Element 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.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class SidebarCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element action = scriptEntry.getElement("action");
Element elTitle = scriptEntry.getElement("title");
Element elLines = scriptEntry.getElement("lines");
Element elValue = scriptEntry.getElement("value");
Element elIncrement = scriptEntry.getElement("increment");
Element elStart = scriptEntry.getElement("start");
Element elPlayers = scriptEntry.getElement("players");
Element elPerPlayer = scriptEntry.getElement("per_player");
dList players = dList.valueOf(TagManager.tag(elPlayers.asString(), new BukkitTagContext(scriptEntry, false)));
boolean per_player = elPerPlayer.asBoolean();
String perTitle = null;
String perLines = null;
String perValue = null;
String perIncrement = null;
String perStart = null;
Element title = null;
dList lines = null;
dList value = null;
Element increment = null;
Element start = null;
String debug;
if (per_player) {
if (elTitle != null) {
perTitle = elTitle.asString();
}
if (elLines != null) {
perLines = elLines.asString();
}
if (elValue != null) {
perValue = elValue.asString();
}
if (elIncrement != null) {
perIncrement = elIncrement.asString();
}
if (elStart != null) {
perStart = elStart.asString();
}
debug = action.debug() + (elTitle != null ? elTitle.debug() : "") + (elLines != null ? elLines.debug() : "") + (elValue != null ? elValue.debug() : "") + (elIncrement != null ? elIncrement.debug() : "") + (elStart != null ? elStart.debug() : "") + players.debug();
} else {
BukkitTagContext context = (BukkitTagContext) DenizenAPI.getCurrentInstance().getTagContextFor(scriptEntry, false);
if (elTitle != null) {
title = new Element(TagManager.tag(elTitle.asString(), context));
}
if (elLines != null) {
lines = dList.valueOf(TagManager.tag(elLines.asString(), context));
}
if (elValue != null) {
value = dList.valueOf(TagManager.tag(elValue.asString(), context));
}
if (elIncrement != null) {
increment = new Element(TagManager.tag(elIncrement.asString(), context));
}
if (elStart != null) {
start = new Element(TagManager.tag(elStart.asString(), context));
}
debug = action.debug() + (title != null ? title.debug() : "") + (lines != null ? lines.debug() : "") + (value != null ? value.debug() : "") + (increment != null ? increment.debug() : "") + (start != null ? start.debug() : "") + players.debug();
}
dB.report(scriptEntry, getName(), debug);
switch(Action.valueOf(action.asString())) {
case ADD:
for (dPlayer player : players.filter(dPlayer.class)) {
if (player == null || !player.isValid()) {
dB.echoError("Invalid player!");
continue;
}
Sidebar sidebar = createSidebar(player);
if (sidebar == null) {
continue;
}
List<String> current = sidebar.getLines();
if (per_player) {
TagContext context = new BukkitTagContext(player, ((BukkitScriptEntryData) scriptEntry.entryData).getNPC(), false, scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
value = dList.valueOf(TagManager.tag(perValue, context));
if (perLines != null) {
lines = dList.valueOf(TagManager.tag(perLines, context));
}
}
if (lines != null) {
try {
for (int i = 0; i < lines.size(); i++) {
int index = Integer.valueOf(lines.get(i)) - 1;
String line = value.get(i);
current.add(index, line);
}
} catch (Exception e) {
dB.echoError(e);
continue;
}
} else {
current.addAll(value);
}
sidebar.setLines(current);
sidebar.sendUpdate();
}
break;
case REMOVE:
for (dPlayer player : players.filter(dPlayer.class)) {
if (player == null || !player.isValid()) {
dB.echoError("Invalid player!");
continue;
}
Sidebar sidebar = createSidebar(player);
if (sidebar == null) {
continue;
}
List<String> current = sidebar.getLines();
if (per_player) {
TagContext context = new BukkitTagContext(player, ((BukkitScriptEntryData) scriptEntry.entryData).getNPC(), false, scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
if (perValue != null) {
value = dList.valueOf(TagManager.tag(perValue, context));
}
if (perLines != null) {
lines = dList.valueOf(TagManager.tag(perLines, context));
}
}
if (lines != null) {
try {
int offset = 0;
for (String line : lines) {
int index = Integer.valueOf(line) - 1 - offset;
current.remove(index);
offset++;
}
} catch (Exception e) {
dB.echoError(e);
continue;
}
sidebar.setLines(current);
sidebar.sendUpdate();
} else if (value != null) {
try {
Iterator<String> it = current.iterator();
while (it.hasNext()) {
String next = it.next();
for (String line : value) {
if (next.equalsIgnoreCase(line)) {
it.remove();
}
}
}
for (String line : value) {
for (int i = 0; i < current.size(); i++) {
if (current.get(i).equalsIgnoreCase(line)) {
current.remove(i);
}
}
}
} catch (Exception e) {
dB.echoError(e);
continue;
}
sidebar.setLines(current);
sidebar.sendUpdate();
} else {
sidebar.remove();
sidebars.remove(player.getPlayerEntity().getUniqueId());
}
}
break;
case SET:
for (dPlayer player : players.filter(dPlayer.class)) {
if (player == null || !player.isValid()) {
dB.echoError("Invalid player!");
continue;
}
Sidebar sidebar = createSidebar(player);
if (sidebar == null) {
continue;
}
List<String> current = sidebar.getLines();
boolean currEdited = false;
if (per_player) {
TagContext context = new BukkitTagContext(player, ((BukkitScriptEntryData) scriptEntry.entryData).getNPC(), false, scriptEntry, scriptEntry.shouldDebug(), scriptEntry.getScript());
if (perValue != null) {
value = dList.valueOf(TagManager.tag(perValue, context));
}
if (perLines != null) {
lines = dList.valueOf(TagManager.tag(perLines, context));
}
if (perStart != null) {
start = new Element(TagManager.tag(perStart, context));
}
if (perIncrement != null) {
increment = new Element(TagManager.tag(perIncrement, context));
}
if (perTitle != null) {
title = new Element(TagManager.tag(perTitle, context));
}
}
if (lines != null) {
try {
for (int i = 0; i < lines.size(); i++) {
int index = Integer.valueOf(lines.get(i)) - 1;
String line = value.get(i);
if (index > current.size()) {
current.add(line);
} else {
current.set(index, line);
}
}
} catch (Exception e) {
dB.echoError(e);
continue;
}
currEdited = true;
} else if (value != null) {
current = value;
currEdited = true;
}
if (start != null) {
sidebar.setStart(start.asInt());
currEdited = true;
}
if (increment != null) {
sidebar.setIncrement(increment.asInt());
currEdited = true;
}
if (title != null) {
sidebar.setTitle(title.asString());
}
if (currEdited) {
sidebar.setLines(current);
}
sidebar.sendUpdate();
}
break;
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class StatisticCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element action = scriptEntry.getElement("action");
dList players = scriptEntry.getdObject("players");
Element statistic = scriptEntry.getElement("statistic");
Element amount = scriptEntry.getElement("amount");
dMaterial material = scriptEntry.getdObject("material");
dEntity entity = scriptEntry.getdObject("entity");
dB.report(scriptEntry, getName(), action.debug() + statistic.debug() + amount.debug() + players.debug() + (material != null ? material.debug() : entity != null ? entity.debug() : ""));
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 (dPlayer player : players.filter(dPlayer.class)) {
player.incrementStatistic(stat, mat, amt);
}
break;
case TAKE:
for (dPlayer player : players.filter(dPlayer.class)) {
player.decrementStatistic(stat, mat, amt);
}
break;
case SET:
for (dPlayer player : players.filter(dPlayer.class)) {
player.setStatistic(stat, mat, amt);
}
break;
}
break;
case ENTITY:
EntityType ent = entity.getBukkitEntityType();
switch(act) {
case ADD:
for (dPlayer player : players.filter(dPlayer.class)) {
player.incrementStatistic(stat, ent, amt);
}
break;
case TAKE:
for (dPlayer player : players.filter(dPlayer.class)) {
player.decrementStatistic(stat, ent, amt);
}
break;
case SET:
for (dPlayer player : players.filter(dPlayer.class)) {
player.setStatistic(stat, ent, amt);
}
break;
}
break;
}
}
use of net.aufdemrand.denizencore.objects.Element 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