use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class BlockCrack method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
Element progress = scriptEntry.getElement("progress");
dLocation location = scriptEntry.getdObject("location");
Element stack = scriptEntry.getElement("stack");
dB.report(scriptEntry, getName(), aH.debugList("players", players) + progress.debug() + location.debug() + stack.debug());
Location loc = location.getBlock().getLocation();
if (!progressTracker.containsKey(loc)) {
progressTracker.put(loc, new HashMap<UUID, IntHolder>());
lastBase += 10;
}
Map<UUID, IntHolder> uuidInt = progressTracker.get(loc);
boolean stackVal = stack.asBoolean();
PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
for (dPlayer player : players) {
if (!player.isOnline()) {
dB.echoError("Players must be online!");
continue;
}
Player playerEnt = player.getPlayerEntity();
UUID uuid = playerEnt.getUniqueId();
if (!uuidInt.containsKey(uuid)) {
IntHolder newIntHolder = new IntHolder();
newIntHolder.theInt = lastBase;
newIntHolder.base = lastBase;
uuidInt.put(uuid, newIntHolder);
}
IntHolder intHolder = uuidInt.get(uuid);
if (!stackVal && intHolder.theInt > intHolder.base) {
for (int i = intHolder.base; i <= intHolder.theInt; i++) {
packetHelper.showBlockCrack(playerEnt, i, loc, -1);
}
intHolder.theInt = intHolder.base;
} else if (stackVal && intHolder.theInt - intHolder.base > 10) {
continue;
}
int id = stackVal ? intHolder.theInt++ : intHolder.theInt;
packetHelper.showBlockCrack(player.getPlayerEntity(), id, loc, progress.asInt() - 1);
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class ChatCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dList talkers = scriptEntry.getdObject("talkers");
dList targets = scriptEntry.getdObject("targets");
Element message = scriptEntry.getElement("message");
Element chatRange = scriptEntry.getElement("range");
dB.report(scriptEntry, getName(), talkers.debug() + targets.debug() + message.debug() + chatRange.debug());
// Create new speech context
DenizenSpeechContext context = new DenizenSpeechContext(TagManager.cleanOutputFully(message.asString()), scriptEntry, chatRange.asDouble());
if (!targets.isEmpty()) {
for (dEntity ent : targets.filter(dEntity.class)) {
context.addRecipient(ent.getBukkitEntity());
}
}
for (dEntity talker : talkers.filter(dEntity.class)) {
Entity entity = talker.getBukkitEntity();
if (entity != null) {
context.setTalker(entity);
new DenizenSpeechController(entity).speak(context);
} else {
dB.echoDebug(scriptEntry, "Chat Talker is not spawned! Cannot talk.");
}
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class GlowCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
final ArrayList<dEntity> entities = (ArrayList<dEntity>) scriptEntry.getObject("entities");
Element glowing = scriptEntry.getElement("glowing");
dB.report(scriptEntry, getName(), aH.debugList("entities", entities) + glowing.debug());
boolean shouldGlow = glowing.asBoolean();
final UUID puuid = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer().getUniqueId();
if (puuid == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Invalid/non-spawned player link!");
return;
}
for (dEntity ent : entities) {
if (Depends.citizens != null && CitizensAPI.getNPCRegistry().isNPC(ent.getLivingEntity())) {
CitizensAPI.getNPCRegistry().getNPC(ent.getLivingEntity()).data().setPersistent(NPC.GLOWING_METADATA, shouldGlow);
}
if (shouldGlow) {
HashSet<UUID> players = glowViewers.get(ent.getLivingEntity().getEntityId());
if (players == null) {
players = new HashSet<UUID>();
glowViewers.put(ent.getLivingEntity().getEntityId(), players);
}
players.add(puuid);
} else {
HashSet<UUID> players = glowViewers.get(ent.getLivingEntity().getEntityId());
if (players != null) {
players.remove(puuid);
shouldGlow = !players.isEmpty();
if (!shouldGlow) {
glowViewers.remove(ent.getLivingEntity().getEntityId());
}
}
}
ent.getLivingEntity().setGlowing(shouldGlow);
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class ListenCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element action = scriptEntry.getElement("action");
Element type = scriptEntry.getElement("type");
Element id = scriptEntry.getElement("id");
dScript finish_script = (dScript) scriptEntry.getObject("finish_script");
dB.report(scriptEntry, getName(), action.debug() + (type != null ? type.debug() : "") + id.debug() + (finish_script != null ? finish_script.debug() : ""));
dB.echoError(scriptEntry.getResidingQueue(), "Warning: Listen is outdated and may become unsupported in the future.");
List<aH.Argument> arguments = (ArrayList<aH.Argument>) scriptEntry.getObject("args");
switch(Action.valueOf(action.asString().toUpperCase())) {
case NEW:
// First make sure there isn't already a 'player listener' for this player with the specified ID.
if (DenizenAPI.getCurrentInstance().getListenerRegistry().getListenersFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()) != null && DenizenAPI.getCurrentInstance().getListenerRegistry().getListenersFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()).containsKey(CoreUtilities.toLowerCase(id.asString()))) {
dB.echoError(scriptEntry.getResidingQueue(), "Cancelled creation of NEW listener! Listener ID '" + id.asString() + "' already exists!");
break;
}
// Also make sure there is a valid script input
if (finish_script == null) {
dB.echoError("Must specify a valid script!");
break;
}
try {
DenizenAPI.getCurrentInstance().getListenerRegistry().get(type.asString()).createInstance(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()).build(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString(), type.asString(), arguments, finish_script, ((BukkitScriptEntryData) scriptEntry.entryData).getNPC());
} catch (Exception e) {
dB.echoDebug(scriptEntry, "Cancelled creation of NEW listener!");
// Why? Maybe a wrong listener type...
if (DenizenAPI.getCurrentInstance().getListenerRegistry().get(type.asString()) == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Invalid listener type!");
} else // Just print the stacktrace if anything else, so we can debug other possible
// problems.
{
dB.echoError(scriptEntry.getResidingQueue(), e);
}
// Deconstruct the listener in case it was partially created while erroring out.
try {
DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()).cancel();
} catch (Exception ex) {
}
}
break;
case FINISH:
if (DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()) != null) {
DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()).finish();
}
break;
case CANCEL:
if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
if (id != null) {
if (DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()) != null) {
DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), id.asString()).cancel();
} else {
for (AbstractListener listener : DenizenAPI.getCurrentInstance().getListenerRegistry().getListenersFor(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()).values()) {
listener.cancel();
}
}
}
} else {
DenizenAPI.getCurrentInstance().getSaves().set("Listeners." + ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getName() + "." + id, null);
}
break;
}
}
use of net.aufdemrand.denizencore.objects.Element 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