use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.
the class BanCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element action = scriptEntry.getElement("action");
List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
Element reason = scriptEntry.getElement("reason");
Duration duration = scriptEntry.getdObject("duration");
Date expiration = null;
if (duration != null && duration.getTicks() != 0) {
expiration = new Date(new Duration(System.currentTimeMillis() / 50 + duration.getTicks()).getTicks() * 50);
}
dB.report(scriptEntry, getName(), action.debug() + aH.debugObj("targets", targets) + reason.debug() + (duration != null ? duration.debug() : ""));
Actions banAction = Actions.valueOf(action.toString().toUpperCase());
switch(banAction) {
case ADD:
for (dPlayer player : targets) {
if (player.isValid()) {
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), reason.toString(), expiration, null);
if (player.isOnline()) {
player.getPlayerEntity().kickPlayer(reason.toString());
}
}
}
break;
case REMOVE:
for (dPlayer player : targets) {
if (player.isValid()) {
if (player.getOfflinePlayer().isBanned()) {
Bukkit.getBanList(BanList.Type.NAME).pardon(player.getName());
}
}
}
break;
}
}
use of net.aufdemrand.denizencore.objects.Duration 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;
}
}
use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.
the class TimeCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Fetch objects
Duration value = (Duration) scriptEntry.getObject("value");
dWorld world = (dWorld) scriptEntry.getObject("world");
Element type_element = scriptEntry.getElement("type");
Type type = Type.valueOf(type_element.asString().toUpperCase());
// Report to dB
dB.report(scriptEntry, getName(), type_element.debug() + value.debug() + world.debug());
if (type.equals(Type.GLOBAL)) {
world.getWorld().setTime(value.getTicks());
} else {
if (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
dB.echoError("Must have a valid player link!");
} else {
((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setPlayerTime(value.getTicks(), true);
}
}
}
use of net.aufdemrand.denizencore.objects.Duration 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"));
}
use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.
the class PushableCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dNPC denizenNPC = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
if (denizenNPC == null) {
throw new CommandExecutionException("No valid NPC attached to this queue!");
}
PushableTrait trait = denizenNPC.getPushableTrait();
Element state = scriptEntry.getElement("state");
Duration delay = scriptEntry.getdObject("delay");
Element returnable = scriptEntry.getElement("return");
if (state == null && delay == null && returnable == null) {
state = new Element("TOGGLE");
}
dB.report(scriptEntry, getName(), (state != null ? state.debug() : "") + (delay != null ? delay.debug() : "") + (returnable != null ? returnable.debug() : ""));
if (delay != null) {
trait.setDelay(delay.getSecondsAsInt());
}
if (returnable != null) {
trait.setReturnable(returnable.asBoolean());
}
if (state != null) {
switch(Toggle.valueOf(state.asString().toUpperCase())) {
case TRUE:
case ON:
trait.setPushable(true);
break;
case FALSE:
case OFF:
trait.setPushable(false);
break;
case TOGGLE:
trait.setPushable(!trait.isPushable());
break;
}
}
}
Aggregations