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)) scriptEntry.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: