use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ExecuteCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag cmd = scriptEntry.getElement("command");
ElementTag type = scriptEntry.getElement("type");
boolean silent = scriptEntry.argAsBoolean("silent");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), type, cmd, db("silent", silent));
}
String command = cmd.asString();
switch(Type.valueOf(type.asString())) {
case AS_PLAYER:
try {
PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(Utilities.getEntryPlayer(scriptEntry).getPlayerEntity(), "/" + command);
Bukkit.getPluginManager().callEvent(pcpe);
if (!pcpe.isCancelled()) {
Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
if (silent) {
NetworkInterceptHelper.enable();
silencedPlayers.add(player.getUniqueId());
}
player.performCommand(pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1) : pcpe.getMessage());
if (silent) {
silencedPlayers.remove(player.getUniqueId());
}
}
} catch (Throwable e) {
Debug.echoError(scriptEntry, "Exception while executing command as player.");
Debug.echoError(scriptEntry, e);
}
break;
case AS_OP:
if (CoreUtilities.equalsIgnoreCase(command, "stop")) {
Debug.echoError("Please use as_server to execute 'stop'.");
return;
}
Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
PlayerHelper playerHelper = NMSHandler.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()) {
if (silent) {
NetworkInterceptHelper.enable();
silencedPlayers.add(player.getUniqueId());
}
player.performCommand(pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1) : pcpe.getMessage());
if (silent) {
silencedPlayers.remove(player.getUniqueId());
}
}
} catch (Throwable e) {
Debug.echoError(scriptEntry, "Exception while executing command as OP.");
Debug.echoError(scriptEntry, e);
}
if (!isOp) {
playerHelper.setTemporaryOp(player, false);
}
break;
case AS_NPC:
if (!Utilities.getEntryNPC(scriptEntry).isSpawned()) {
Debug.echoError(scriptEntry, "Cannot EXECUTE AS_NPC unless the NPC is Spawned.");
return;
}
if (Utilities.getEntryNPC(scriptEntry).getEntity().getType() != EntityType.PLAYER) {
Debug.echoError(scriptEntry, "Cannot EXECUTE AS_NPC unless the NPC is Player-Type.");
return;
}
Utilities.getEntryNPC(scriptEntry).getEntity().setOp(true);
try {
((Player) Utilities.getEntryNPC(scriptEntry).getEntity()).performCommand(command);
} catch (Throwable e) {
Debug.echoError(scriptEntry, "Exception while executing command as NPC-OP.");
Debug.echoError(scriptEntry, e);
}
Utilities.getEntryNPC(scriptEntry).getEntity().setOp(false);
break;
case AS_SERVER:
dcs.clearOutput();
dcs.silent = silent;
ServerCommandEvent sce = new ServerCommandEvent(dcs, command);
Bukkit.getPluginManager().callEvent(sce);
Denizen.getInstance().getServer().dispatchCommand(dcs, sce.getCommand());
scriptEntry.addObject("output", new ListTag(dcs.getOutput()));
break;
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ChunkLoadCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag action = scriptEntry.getElement("action");
ListTag chunklocs = scriptEntry.getObjectTag("location");
DurationTag length = scriptEntry.getObjectTag("duration");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), action, chunklocs, length);
}
for (String chunkText : chunklocs) {
Chunk chunk;
if (ChunkTag.matches(chunkText)) {
chunk = ChunkTag.valueOf(chunkText, scriptEntry.context).getChunk();
} else if (LocationTag.matches(chunkText)) {
chunk = LocationTag.valueOf(chunkText, scriptEntry.context).getChunk();
} else {
Debug.echoError("Chunk input '" + chunkText + "' is invalid.");
return;
}
ChunkCoordinate coord = new ChunkCoordinate(chunk);
switch(Action.valueOf(action.asString())) {
case ADD:
if (length.getSeconds() != 0) {
chunkDelays.put(coord, System.currentTimeMillis() + length.getMillis());
} else {
chunkDelays.put(coord, (long) 0);
}
Debug.echoDebug(scriptEntry, "...added chunk " + chunk.getX() + ", " + chunk.getZ() + " with a delay of " + length.getSeconds() + " seconds.");
if (!chunk.isLoaded()) {
chunk.load();
}
chunk.addPluginChunkTicket(Denizen.getInstance());
if (length.getSeconds() > 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
if (chunkDelays.containsKey(coord) && chunkDelays.get(coord) <= System.currentTimeMillis()) {
chunk.removePluginChunkTicket(Denizen.getInstance());
chunkDelays.remove(coord);
}
}, length.getTicks() + 20);
}
break;
case REMOVE:
if (chunkDelays.containsKey(coord)) {
chunkDelays.remove(coord);
chunk.removePluginChunkTicket(Denizen.getInstance());
Debug.echoDebug(scriptEntry, "...allowing unloading of chunk " + chunk.getX() + ", " + chunk.getZ());
} else {
Debug.echoDebug(scriptEntry, "Chunk '" + coord + "' was not on the load list, ignoring.");
}
break;
case REMOVEALL:
Debug.echoDebug(scriptEntry, "...allowing unloading of all stored chunks");
for (ChunkCoordinate loopCoord : chunkDelays.keySet()) {
loopCoord.getChunk().getChunk().removePluginChunkTicket(Denizen.getInstance());
}
chunkDelays.clear();
break;
}
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ExplodeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("power") && arg.matchesFloat() && arg.matchesPrefix("power", "p")) {
scriptEntry.addObject("power", arg.asElement());
} else if (!scriptEntry.hasObject("source") && arg.matchesArgumentType(EntityTag.class) && arg.matchesPrefix("source")) {
scriptEntry.addObject("source", arg.asType(EntityTag.class));
} else if (!scriptEntry.hasObject("breakblocks") && arg.matches("breakblocks")) {
scriptEntry.addObject("breakblocks", new ElementTag(true));
} else if (!scriptEntry.hasObject("fire") && arg.matches("fire")) {
scriptEntry.addObject("fire", new ElementTag(true));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("power", new ElementTag(1.0));
scriptEntry.defaultObject("fire", new ElementTag(false));
scriptEntry.defaultObject("breakblocks", new ElementTag(false));
scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location argument!");
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayEffectCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
ParticleHelper particleHelper = NMSHandler.getParticleHelper();
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("location") && arg.matchesArgumentList(LocationTag.class) && (arg.matchesPrefix("at") || !arg.hasPrefix())) {
if (arg.matchesPrefix("at")) {
scriptEntry.addObject("no_offset", new ElementTag(true));
}
scriptEntry.addObject("location", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
continue;
} else if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
if (particleHelper.hasParticle(arg.getValue())) {
scriptEntry.addObject("particleeffect", particleHelper.getParticle(arg.getValue()));
continue;
} else if (arg.matches("barrier") && NMSHandler.getVersion().isAtLeast(NMSVersion.v1_18)) {
scriptEntry.addObject("particleeffect", particleHelper.getParticle("block_marker"));
scriptEntry.addObject("special_data", new ElementTag("barrier"));
continue;
} else if (arg.matches("random")) {
// Get another effect if "RANDOM" is used
List<Particle> visible = particleHelper.getVisibleParticles();
scriptEntry.addObject("particleeffect", visible.get(CoreUtilities.getRandom().nextInt(visible.size())));
continue;
} else if (arg.startsWith("iconcrack_")) {
Deprecations.oldPlayEffectSpecials.warn(scriptEntry);
// Allow iconcrack_[item] for item break effects (ex: iconcrack_stone)
String shrunk = arg.getValue().substring("iconcrack_".length());
ItemTag item = ItemTag.valueOf(shrunk, scriptEntry.context);
if (item != null) {
scriptEntry.addObject("iconcrack", item);
} else {
Debug.echoError("Invalid iconcrack_[item]. Must be a valid ItemTag!");
}
continue;
} else if (arg.matchesEnum(Effect.class)) {
scriptEntry.addObject("effect", Effect.valueOf(arg.getValue().toUpperCase()));
continue;
}
}
if (!scriptEntry.hasObject("radius") && arg.matchesFloat() && arg.matchesPrefix("visibility", "v", "radius", "r")) {
scriptEntry.addObject("radius", arg.asElement());
} else if (!scriptEntry.hasObject("data") && arg.matchesFloat() && arg.matchesPrefix("data", "d")) {
scriptEntry.addObject("data", arg.asElement());
} else if (!scriptEntry.hasObject("special_data") && arg.matchesPrefix("special_data")) {
scriptEntry.addObject("special_data", arg.asElement());
} else if (!scriptEntry.hasObject("quantity") && arg.matchesInteger() && arg.matchesPrefix("qty", "q", "quantity")) {
if (arg.matchesPrefix("q", "qty")) {
Deprecations.qtyTags.warn(scriptEntry);
}
scriptEntry.addObject("quantity", arg.asElement());
} else if (!scriptEntry.hasObject("offset") && arg.matchesFloat() && arg.matchesPrefix("offset", "o")) {
double offset = arg.asElement().asDouble();
scriptEntry.addObject("offset", new LocationTag(null, offset, offset, offset));
} else if (!scriptEntry.hasObject("offset") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("offset", "o")) {
scriptEntry.addObject("offset", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("velocity") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("velocity")) {
scriptEntry.addObject("velocity", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("targets") && arg.matchesArgumentList(PlayerTag.class) && arg.matchesPrefix("targets", "target", "t")) {
scriptEntry.addObject("targets", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("data", new ElementTag(0));
scriptEntry.defaultObject("radius", new ElementTag(15));
scriptEntry.defaultObject("quantity", new ElementTag(1));
scriptEntry.defaultObject("offset", new LocationTag(null, 0.5, 0.5, 0.5));
if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
throw new InvalidArgumentsException("Missing effect argument!");
}
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location argument!");
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class NarrateCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
if (scriptEntry.getResidingQueue().procedural) {
Debug.echoError("'Narrate' should not be used in a procedure script. Consider the 'debug' command instead.");
}
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
String text = scriptEntry.getElement("text").asString();
ScriptTag formatObj = scriptEntry.getObjectTag("format");
ElementTag perPlayerObj = scriptEntry.getElement("per_player");
ElementTag from = scriptEntry.getElement("from");
boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
if (!perPlayer || targets == null) {
text = TagManager.tag(text, context);
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Narrating", text), db("Targets", targets), formatObj, perPlayerObj, from);
}
UUID fromId = null;
if (from != null) {
if (from.asString().startsWith("p@")) {
fromId = UUID.fromString(from.asString().substring("p@".length()));
} else {
fromId = UUID.fromString(from.asString());
}
}
FormatScriptContainer format = formatObj == null ? null : (FormatScriptContainer) formatObj.getContainer();
if (targets == null) {
Bukkit.getServer().getConsoleSender().spigot().sendMessage(FormattedTextHelper.parse(format != null ? format.getFormattedText(text, scriptEntry) : text, ChatColor.WHITE));
return;
}
for (PlayerTag player : targets) {
if (player != null) {
if (!player.isOnline()) {
Debug.echoDebug(scriptEntry, "Player is offline, can't narrate to them. Skipping.");
continue;
}
String personalText = text;
if (perPlayer) {
context.player = player;
personalText = TagManager.tag(personalText, context);
}
BaseComponent[] component = FormattedTextHelper.parse(format != null ? format.getFormattedText(personalText, scriptEntry) : personalText, ChatColor.WHITE);
if (fromId == null) {
player.getPlayerEntity().spigot().sendMessage(component);
} else {
player.getPlayerEntity().spigot().sendMessage(ChatMessageType.CHAT, fromId, component);
}
} else {
Debug.echoError("Narrated to non-existent player!?");
}
}
}
Aggregations