use of net.aufdemrand.denizen.BukkitScriptEntryData 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.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class ViewerCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
dB.echoError(scriptEntry.getResidingQueue(), "This command is deprecated! If you use this, please " + "contact Morphan1 or mcmonkey on irc.esper.net#denizen-dev");
// Get objects
String direction = scriptEntry.hasObject("direction") ? ((Element) scriptEntry.getObject("direction")).asString() : null;
Action action = (Action) scriptEntry.getObject("action");
Type type = scriptEntry.hasObject("type") ? (Type) scriptEntry.getObject("type") : null;
Display display = scriptEntry.hasObject("display") ? (Display) scriptEntry.getObject("display") : null;
final String id = scriptEntry.getObject("id").toString();
if (viewers.containsKey(id)) {
((BukkitScriptEntryData) scriptEntry.entryData).setPlayer(dPlayer.valueOf(viewers.get(id).getContent().split("; ")[1]));
}
dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : null;
String content = scriptEntry.hasObject("display") ? display.toString() + "; " + ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer().getUniqueId() : null;
switch(action) {
case CREATE:
if (viewers.containsKey(id)) {
dB.echoDebug(scriptEntry, "Viewer ID " + id + " already exists!");
return;
}
Viewer viewer = new Viewer(id, content, location);
viewers.put(id, viewer);
final Block sign = location.getBlock();
sign.setType(Material.valueOf(type.name()));
if (direction != null) {
Utilities.setSignRotation(sign.getState(), direction);
} else {
Utilities.setSignRotation(sign.getState());
}
int task = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), new Runnable() {
public void run() {
Player player = Bukkit.getPlayer(UUID.fromString(viewers.get(id).getContent().split("; ")[1]));
if (player == null) {
Utilities.setSignLines((Sign) viewers.get(id).getLocation().getBlock().getState(), new String[] { "", viewers.get(id).getContent().split("; ")[1], "is offline.", "" });
} else {
Utilities.setSignLines((Sign) viewers.get(id).getLocation().getBlock().getState(), new String[] { String.valueOf((int) player.getLocation().getX()), String.valueOf((int) player.getLocation().getY()), String.valueOf((int) player.getLocation().getZ()), player.getWorld().getName() });
}
}
}, 0, 20);
viewer.setTask(task);
viewer.save();
break;
case MODIFY:
if (!viewers.containsKey(id)) {
dB.echoDebug(scriptEntry, "Viewer ID " + id + " doesn't exist!");
return;
}
if (content != null) {
viewers.get(id).setContent(content);
}
if (location != null) {
if (type == null) {
type = Type.valueOf(viewers.get(id).getLocation().getBlock().getType().name());
}
Bukkit.getScheduler().cancelTask(viewers.get(id).getTask());
int newTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), new Runnable() {
public void run() {
Player player = Bukkit.getPlayer(UUID.fromString(viewers.get(id).getContent().split("; ")[1]));
if (player == null) {
Utilities.setSignLines((Sign) viewers.get(id).getLocation().getBlock().getState(), new String[] { "", viewers.get(id).getContent().split("; ")[1], "is offline.", "" });
} else {
Utilities.setSignLines((Sign) viewers.get(id).getLocation().getBlock().getState(), new String[] { String.valueOf((int) player.getLocation().getX()), String.valueOf((int) player.getLocation().getY()), String.valueOf((int) player.getLocation().getZ()), player.getWorld().getName() });
}
}
}, 0, 20);
viewers.get(id).getLocation().getBlock().setType(Material.AIR);
viewers.get(id).setLocation(location);
viewers.get(id).setTask(newTask);
location.getBlock().setType(Material.valueOf(type.name()));
}
break;
case REMOVE:
if (!viewers.containsKey(id)) {
dB.echoDebug(scriptEntry, "Viewer ID " + id + " doesn't exist!");
return;
}
Block block = viewers.get(id).getLocation().getBlock();
block.setType(Material.AIR);
Bukkit.getScheduler().cancelTask(viewers.get(id).getTask());
viewers.get(id).remove();
viewers.remove(id);
}
}
use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class CommandScriptContainer method runTabCompleteProcedure.
public List<String> runTabCompleteProcedure(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), "TAB COMPLETE");
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();
if (DetermineCommand.hasOutcome(id)) {
return dList.valueOf(DetermineCommand.getOutcome(id).get(0));
} else {
return new ArrayList<String>();
}
}
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);
}
Aggregations