use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class TeamCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag id = scriptEntry.getElement("id");
ElementTag name = scriptEntry.getElement("name");
ListTag add = scriptEntry.getObjectTag("add");
ListTag remove = scriptEntry.getObjectTag("remove");
ElementTag prefix = scriptEntry.getElement("prefix");
ElementTag suffix = scriptEntry.getElement("suffix");
ElementTag option = scriptEntry.getElement("option");
ElementTag status = scriptEntry.getElement("status");
ElementTag color = scriptEntry.getElement("color");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), id, name, add, remove, prefix, suffix, color, option, status);
}
Scoreboard board;
if (id.asString().equalsIgnoreCase("main")) {
board = ScoreboardHelper.getMain();
} else {
if (ScoreboardHelper.hasScoreboard(id.asString())) {
board = ScoreboardHelper.getScoreboard(id.asString());
} else {
board = ScoreboardHelper.createScoreboard(id.asString());
}
}
Team team = board.getTeam(name.asString());
if (team == null) {
String low = CoreUtilities.toLowerCase(name.asString());
team = board.getTeams().stream().filter(t -> CoreUtilities.toLowerCase(t.getName()).equals(low)).findFirst().orElse(null);
if (team == null) {
team = board.registerNewTeam(name.asString());
}
}
if (add != null) {
for (String string : add) {
string = translateEntry(string, scriptEntry.context);
if (!team.hasEntry(string)) {
team.addEntry(string);
}
}
}
if (remove != null) {
for (String string : remove) {
string = translateEntry(string, scriptEntry.context);
if (team.hasEntry(string)) {
team.removeEntry(string);
}
}
}
if (option != null) {
String optName = CoreUtilities.toLowerCase(option.asString());
String statusName = CoreUtilities.toLowerCase(status.asString());
if (optName.equals("friendly_fire")) {
team.setAllowFriendlyFire(statusName.equals("always"));
} else if (optName.equals("see_invisible")) {
team.setCanSeeFriendlyInvisibles(statusName.equals("always"));
} else {
team.setOption(Team.Option.valueOf(optName.toUpperCase()), Team.OptionStatus.valueOf(statusName.toUpperCase()));
}
}
if (prefix != null) {
team.setPrefix(prefix.asString());
}
if (suffix != null) {
team.setSuffix(suffix.asString());
}
if (color != null) {
team.setColor(ChatColor.valueOf(color.asString().toUpperCase()));
}
if (team.getEntries().isEmpty()) {
team.unregister();
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ToastCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag text = scriptEntry.getElement("text");
ElementTag frame = scriptEntry.getElement("frame");
ItemTag icon = scriptEntry.getObjectTag("icon");
final List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, name, text, frame, icon, db("targets", targets));
}
final Advancement advancement = new Advancement(true, new NamespacedKey(Denizen.getInstance(), UUID.randomUUID().toString()), null, icon.getItemStack(), text.asString(), "", null, Advancement.Frame.valueOf(frame.asString().toUpperCase()), true, false, true, 0, 0, 1);
final AdvancementHelper advancementHelper = NMSHandler.getAdvancementHelper();
for (PlayerTag target : targets) {
Player player = target.getPlayerEntity();
if (player != null) {
advancementHelper.grant(advancement, player);
advancementHelper.revoke(advancement, player);
}
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ToastCommand method parseArgs.
// <--[command]
// @Name Toast
// @Syntax toast [<text>] (targets:<player>|...) (icon:<item>) (frame:{task}/challenge/goal)
// @Required 1
// @Maximum 4
// @Short Shows the player a custom advancement toast.
// @Group player
//
// @Description
// Displays a client-side custom advancement "toast" notification popup to the player(s).
// If no target is specified it will default to the attached player.
// The icon argument changes the icon displayed in the toast pop-up notification.
// The frame argument changes the type of advancement.
//
// @Tags
// None
//
// @Usage
// Welcomes the player with an advancement toast.
// - toast "Welcome <player.name>!"
//
// @Usage
// Sends the player an advancement toast with a custom icon.
// - toast "Diggy Diggy Hole" icon:iron_spade
//
// @Usage
// Sends the player a "Challenge Complete!" type advancement toast.
// - toast "You finished a challenge!" frame:challenge icon:diamond
//
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t") && arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("targets", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("icon") && arg.matchesPrefix("icon", "i") && arg.matchesArgumentType(ItemTag.class)) {
scriptEntry.addObject("icon", arg.asType(ItemTag.class));
} else if (!scriptEntry.hasObject("frame") && arg.matchesPrefix("frame", "f") && arg.matchesEnum(Advancement.Frame.class)) {
scriptEntry.addObject("frame", arg.asElement());
} else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", arg.getRawElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Must specify a message!");
}
if (!scriptEntry.hasObject("targets")) {
if (!Utilities.entryHasPlayer(scriptEntry)) {
throw new InvalidArgumentsException("Must specify valid player targets!");
} else {
scriptEntry.addObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
}
}
scriptEntry.defaultObject("icon", new ItemTag(Material.AIR));
scriptEntry.defaultObject("frame", new ElementTag("TASK"));
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class AnimateChestCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag action = scriptEntry.getElement("action");
ElementTag sound = scriptEntry.getElement("sound");
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, db("block type", location.getBlock().getType().name()), action, sound, db("players", players));
}
PacketHelper packetHelper = NMSHandler.getPacketHelper();
switch(ChestAction.valueOf(action.asString().toUpperCase())) {
case OPEN:
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_OPEN, 1, 1, "BLOCKS");
}
packetHelper.showBlockAction(ent, location, 1, 1);
}
break;
case CLOSE:
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
NMSHandler.getSoundHelper().playSound(ent, location, Sound.BLOCK_CHEST_CLOSE, 1, 1, "BLOCKS");
}
packetHelper.showBlockAction(ent, location, 1, 0);
}
break;
}
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class FireworkCommand 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("type") && arg.matches("random")) {
scriptEntry.addObject("type", new ElementTag(FireworkEffect.Type.values()[CoreUtilities.getRandom().nextInt(FireworkEffect.Type.values().length)].name()));
} else if (!scriptEntry.hasObject("type") && arg.matchesEnum(FireworkEffect.Type.class)) {
scriptEntry.addObject("type", arg.asElement());
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location!");
}
scriptEntry.defaultObject("type", new ElementTag("ball"));
}
Aggregations