use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class BossBarCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element id = scriptEntry.getElement("id");
Element action = scriptEntry.getElement("action");
dList players = scriptEntry.getdObject("players");
Element title = scriptEntry.getElement("title");
Element progress = scriptEntry.getElement("progress");
Element color = scriptEntry.getElement("color");
Element style = scriptEntry.getElement("style");
dList flags = scriptEntry.getdObject("flags");
dB.report(scriptEntry, getName(), id.debug() + action.debug() + (players != null ? players.debug() : "") + (title != null ? title.debug() : "") + (progress != null ? progress.debug() : "") + (color != null ? color.debug() : "") + (style != null ? style.debug() : "") + (flags != null ? flags.debug() : ""));
String idString = CoreUtilities.toLowerCase(id.asString());
switch(Action.valueOf(action.asString().toUpperCase())) {
case CREATE:
if (bossBarMap.containsKey(idString)) {
dB.echoError("BossBar '" + idString + "' already exists!");
return;
}
String barTitle = title != null ? title.asString() : "";
List<dPlayer> barPlayers = players.filter(dPlayer.class);
double barProgress = progress != null ? progress.asDouble() : 1D;
BarColor barColor = color != null ? BarColor.valueOf(color.asString().toUpperCase()) : BarColor.WHITE;
BarStyle barStyle = style != null ? BarStyle.valueOf(style.asString().toUpperCase()) : BarStyle.SOLID;
BarFlag[] barFlags = new BarFlag[flags != null ? flags.size() : 0];
if (flags != null) {
for (int i = 0; i < flags.size(); i++) {
barFlags[i] = (BarFlag.valueOf(flags.get(i).toUpperCase()));
}
}
BossBar bossBar = Bukkit.createBossBar(barTitle, barColor, barStyle, barFlags);
bossBar.setProgress(barProgress);
for (dPlayer player : barPlayers) {
if (!player.isOnline()) {
dB.echoError("Player must be online to show a BossBar to them!");
continue;
}
bossBar.addPlayer(player.getPlayerEntity());
}
bossBar.setVisible(true);
bossBarMap.put(idString, bossBar);
break;
case UPDATE:
if (!bossBarMap.containsKey(idString)) {
dB.echoError("BossBar '" + idString + "' does not exist!");
return;
}
BossBar bossBar1 = bossBarMap.get(idString);
if (title != null) {
bossBar1.setTitle(title.asString());
}
if (progress != null) {
bossBar1.setProgress(progress.asDouble());
}
if (color != null) {
bossBar1.setColor(BarColor.valueOf(color.asString().toUpperCase()));
}
if (style != null) {
bossBar1.setStyle(BarStyle.valueOf(style.asString().toUpperCase()));
}
if (players != null) {
for (dPlayer player : players.filter(dPlayer.class)) {
bossBar1.addPlayer(player.getPlayerEntity());
}
}
break;
case REMOVE:
if (!bossBarMap.containsKey(idString)) {
dB.echoError("BossBar '" + idString + "' does not exist!");
return;
}
if (players != null) {
BossBar bar = bossBarMap.get(idString);
for (dPlayer player : players.filter(dPlayer.class)) {
bar.removePlayer(player.getPlayerEntity());
}
break;
}
bossBarMap.get(idString).setVisible(false);
bossBarMap.remove(idString);
break;
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class ExecuteCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element cmd = scriptEntry.getElement("command");
Element type = scriptEntry.getElement("type");
Element silent = scriptEntry.getElement("silent");
// Report to dB
dB.report(scriptEntry, getName(), type.debug() + cmd.debug() + silent.debug());
String command = cmd.asString();
switch(Type.valueOf(type.asString())) {
case AS_PLAYER:
try {
PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity(), "/" + command);
Bukkit.getPluginManager().callEvent(pcpe);
if (!pcpe.isCancelled()) {
boolean silentBool = silent.asBoolean();
Player player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity();
if (silentBool) {
silencedPlayers.add(player.getUniqueId());
}
player.performCommand(pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1) : pcpe.getMessage());
if (silentBool) {
silencedPlayers.remove(player.getUniqueId());
}
}
} catch (Throwable e) {
dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as player.");
dB.echoError(scriptEntry.getResidingQueue(), e);
}
break;
case AS_OP:
if (CoreUtilities.toLowerCase(command).equals("stop")) {
dB.echoError("Please use as_server to execute 'stop'.");
return;
}
Player player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity();
PlayerHelper playerHelper = NMSHandler.getInstance().getPlayerHelper();
boolean isOp = player.isOp();
if (!isOp) {
playerHelper.setTemporaryOp(player, true);
}
try {
PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(player, "/" + command);
Bukkit.getPluginManager().callEvent(pcpe);
if (!pcpe.isCancelled()) {
boolean silentBool = silent.asBoolean();
if (silentBool) {
silencedPlayers.add(player.getUniqueId());
}
player.performCommand(pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1) : pcpe.getMessage());
if (silentBool) {
silencedPlayers.remove(player.getUniqueId());
}
}
} catch (Throwable e) {
dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as OP.");
dB.echoError(scriptEntry.getResidingQueue(), e);
}
if (!isOp) {
playerHelper.setTemporaryOp(player, false);
}
break;
case AS_NPC:
if (!((BukkitScriptEntryData) scriptEntry.entryData).getNPC().isSpawned()) {
dB.echoError(scriptEntry.getResidingQueue(), "Cannot EXECUTE AS_NPC unless the NPC is Spawned.");
return;
}
if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity().getType() != EntityType.PLAYER) {
dB.echoError(scriptEntry.getResidingQueue(), "Cannot EXECUTE AS_NPC unless the NPC is Player-Type.");
return;
}
((Player) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).setOp(true);
try {
((Player) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).performCommand(command);
} catch (Throwable e) {
dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as NPC-OP.");
dB.echoError(scriptEntry.getResidingQueue(), e);
}
((Player) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).setOp(false);
break;
case AS_SERVER:
dcs.clearOutput();
dcs.silent = silent.asBoolean();
ServerCommandEvent sce = new ServerCommandEvent(dcs, command);
Bukkit.getPluginManager().callEvent(sce);
DenizenAPI.getCurrentInstance().getServer().dispatchCommand(dcs, sce.getCommand());
scriptEntry.addObject("output", new dList(dcs.getOutput()));
break;
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class ScoreboardCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Initialize necessary fields
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
scriptEntry.addObject("action", arg.asElement());
} else if (!scriptEntry.hasObject("lines") && arg.matchesPrefix("lines", "l")) {
scriptEntry.addObject("lines", arg.asElement());
} else if (!scriptEntry.hasObject("id") && arg.matchesPrefix("id")) {
scriptEntry.addObject("id", arg.asElement());
} else if (!scriptEntry.hasObject("objective") && arg.matchesPrefix("objective", "obj", "o")) {
scriptEntry.addObject("objective", arg.asElement());
} else if (!scriptEntry.hasObject("criteria") && arg.matchesPrefix("criteria", "c")) {
scriptEntry.addObject("criteria", arg.asElement());
} else if (!scriptEntry.hasObject("score") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
scriptEntry.addObject("score", arg.asElement());
} else if (!scriptEntry.hasObject("displayslot") && (arg.matchesEnum(DisplaySlot.values()) || arg.matches("none"))) {
scriptEntry.addObject("displayslot", arg.asElement());
} else if (!scriptEntry.hasObject("viewers") && arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("viewers", arg.asType(dList.class).filter(dPlayer.class));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("action", new Element("add"));
scriptEntry.defaultObject("id", new Element("main"));
scriptEntry.defaultObject("criteria", new Element("dummy"));
scriptEntry.defaultObject("displayslot", new Element("sidebar"));
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class AnimateChestCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dLocation location = (dLocation) scriptEntry.getObject("location");
Element action = scriptEntry.getElement("action");
Element sound = scriptEntry.getElement("sound");
List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
dB.report(scriptEntry, getName(), location.debug() + action.debug() + sound.debug() + aH.debugObj("players", players.toString()));
PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
switch(ChestAction.valueOf(action.asString().toUpperCase())) {
case OPEN:
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
ent.playSound(location, NMSHandler.getInstance().getSoundHelper().getChestOpen(), 1, 1);
}
packetHelper.showBlockAction(ent, location, 1, 1);
}
break;
case CLOSE:
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
ent.playSound(location, NMSHandler.getInstance().getSoundHelper().getChestClose(), 1, 1);
}
packetHelper.showBlockAction(ent, location, 1, 0);
}
break;
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class ChunkLoadCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
Element action = scriptEntry.getElement("action");
dLocation chunkloc = (dLocation) scriptEntry.getObject("location");
Duration length = (Duration) scriptEntry.getObject("duration");
dB.report(scriptEntry, getName(), action.debug() + chunkloc.debug() + length.debug());
Chunk chunk = chunkloc.getChunk();
String chunkString = chunk.getX() + ", " + chunk.getZ();
switch(Action.valueOf(action.asString())) {
case ADD:
if (length.getSeconds() != 0) {
chunkDelays.put(chunkString, System.currentTimeMillis() + length.getMillis());
} else {
chunkDelays.put(chunkString, (long) 0);
}
dB.echoDebug(scriptEntry, "...added chunk " + chunk.getX() + ", " + chunk.getZ() + " with a delay of " + length.getSeconds() + " seconds.");
if (!chunk.isLoaded()) {
chunk.load();
}
break;
case REMOVE:
if (chunkDelays.containsKey(chunkString)) {
chunkDelays.remove(chunkString);
dB.echoDebug(scriptEntry, "...allowing unloading of chunk " + chunk.getX() + ", " + chunk.getZ());
} else {
dB.echoError("Chunk was not on the load list!");
}
break;
case REMOVEALL:
dB.echoDebug(scriptEntry, "...allowing unloading of all stored chunks");
chunkDelays.clear();
break;
}
}
Aggregations