use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <ItemTag.potion_base_type>
// @returns ElementTag
// @mechanism ItemTag.potion_effects
// @group properties
// @description
// Returns the base potion type name for this potion item.
// The type will be from <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionType.html>.
// -->
PropertyParser.<ItemPotion, ElementTag>registerTag(ElementTag.class, "potion_base_type", (attribute, object) -> {
return new ElementTag(object.getMeta().getBasePotionData().getType().name());
});
// <--[tag]
// @attribute <ItemTag.potion_base>
// @returns ElementTag
// @group attribute
// @mechanism ItemTag.potion_effects
// @deprecated use 'effects_data' instead
// @description
// Deprecated in favor of <@link tag ItemTag.effects_data>
// -->
PropertyParser.<ItemPotion, ElementTag>registerTag(ElementTag.class, "potion_base", (attribute, object) -> {
Deprecations.oldPotionEffects.warn(attribute.context);
PotionMeta meta = object.getMeta();
return new ElementTag(meta.getBasePotionData().getType().name() + "," + (meta.getBasePotionData().isUpgraded() ? 2 : 1) + "," + meta.getBasePotionData().isExtended() + "," + (object.item.getBukkitMaterial() == Material.SPLASH_POTION) + (meta.hasColor() ? "," + new ColorTag(meta.getColor()).identify() : ""));
});
// <--[tag]
// @attribute <ItemTag.potion_effects>
// @returns ListTag
// @group attribute
// @mechanism ItemTag.potion_effects
// @deprecated use 'effects_data' instead
// @description
// Deprecated in favor of <@link tag ItemTag.effects_data>
// -->
PropertyParser.<ItemPotion, ListTag>registerTag(ListTag.class, "potion_effects", (attribute, object) -> {
Deprecations.oldPotionEffects.warn(attribute.context);
ListTag result = new ListTag();
for (PotionEffect pot : object.getMeta().getCustomEffects()) {
result.add(stringifyEffect(pot));
}
return result;
});
// <--[tag]
// @attribute <ItemTag.has_potion_effect>
// @returns ElementTag(Boolean)
// @mechanism ItemTag.potion_effects
// @description
// Returns whether the potion has a potion effect.
// -->
PropertyParser.<ItemPotion, ElementTag>registerTag(ElementTag.class, "has_potion_effect", (attribute, object) -> {
return new ElementTag(object.getMeta().hasCustomEffects());
});
// <--[tag]
// @attribute <ItemTag.potion_effect[<#>]>
// @returns ElementTag
// @group attribute
// @mechanism ItemTag.potion_effects
// @deprecated use 'effects_data' instead
// @description
// Deprecated in favor of <@link tag ItemTag.effects_data>
// -->
PropertyParser.<ItemPotion, ElementTag>registerTag(ElementTag.class, "potion_effect", (attribute, object) -> {
Deprecations.oldPotionEffects.warn(attribute.context);
PotionMeta meta = object.getMeta();
int potN = attribute.hasParam() ? attribute.getIntParam() - 1 : 0;
if (potN < 0 || potN > meta.getCustomEffects().size()) {
return null;
}
if (attribute.startsWith("is_splash", 2)) {
attribute.fulfill(1);
return new ElementTag(object.item.getBukkitMaterial() == Material.SPLASH_POTION);
}
if (attribute.startsWith("is_extended", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getBasePotionData().isExtended());
}
if (attribute.startsWith("level", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getBasePotionData().isUpgraded() ? 2 : 1);
}
if (attribute.startsWith("is_ambient", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).isAmbient());
}
if (attribute.startsWith("icon", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).hasIcon());
}
if (attribute.startsWith("has_particles", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).hasParticles());
}
if (attribute.startsWith("duration", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).getDuration());
}
if (attribute.startsWith("amplifier", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).getAmplifier());
}
if (attribute.startsWith("type", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).getType().getName());
}
if (attribute.startsWith("data", 2)) {
attribute.fulfill(1);
return new ElementTag(0);
}
PotionData data = meta.getBasePotionData();
return new ElementTag(data.getType().name() + "," + (data.isUpgraded() ? 2 : 1) + "," + data.isExtended() + "," + (object.item.getBukkitMaterial() == Material.SPLASH_POTION));
});
// <--[tag]
// @attribute <ItemTag.effects_data>
// @returns ListTag(MapTag)
// @mechanism ItemTag.potion_effects
// @group properties
// @description
// Returns a list of all potion effects on this item, in the same format as the MapTag input to the mechanism.
// Note that the first value in the list is the potion's base type, and all subsequent entries are effect data.
// -->
PropertyParser.<ItemPotion, ListTag>registerTag(ListTag.class, "effects_data", (attribute, object) -> {
return object.getMapTagData();
});
}
use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method getMapTagData.
public ListTag getMapTagData() {
ListTag result = new ListTag();
MapTag base = new MapTag();
PotionMeta meta = getMeta();
base.putObject("type", new ElementTag(meta.getBasePotionData().getType().name()));
base.putObject("upgraded", new ElementTag(meta.getBasePotionData().isUpgraded()));
base.putObject("extended", new ElementTag(meta.getBasePotionData().isExtended()));
if (meta.hasColor()) {
base.putObject("color", new ColorTag(meta.getColor()));
}
result.addObject(base);
for (PotionEffect effect : meta.getCustomEffects()) {
result.addObject(effectToMap(effect));
}
return result;
}
use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class DebugBlockCommand method parseArgs.
// <--[command]
// @Name DebugBlock
// @Syntax debugblock [<location>|.../clear] (color:<color>) (alpha:<#.#>) (name:<name>) (players:<player>|...) (d:<duration>{10s})
// @Required 1
// @Maximum 6
// @Short Shows or clears minecraft debug blocks.
// @Synonyms GameTestMarker
// @Group player
//
// @Description
// Shows or clears minecraft debug blocks, AKA "Game Test Markers".
// These are block-grid-aligned markers that are a perfect cube of a single (specifiable) transparent color, and stay for a specified duration of time or until cleared.
// Markers can optionally also have simple text names.
//
// If arguments are unspecified, the default color is white (in practice: green), the default alpha is 1.0 (most opaque, but not completely opaque),
// the default player is the linked player, the default name is none, and the default duration is 10 seconds.
//
// The underlying color input is a full color value, however the current minecraft client can only render shades between green and gray (ie the red and blue color channels are ignored).
//
// @Tags
// None
//
// @Usage
// Use to show a debug block where the player is looking.
// - debugblock <player.cursor_on>
//
// @Usage
// Use to show a transparent green debug block in front of the player for five seconds.
// - debugblock <player.eye_location.forward[2]> color:green alpha:0.5 d:5s
//
// @Usage
// Use to remove all debug blocks,
// - debugblock clear
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("players") && arg.matchesPrefix("to", "players")) {
scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(DurationTag.class)) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (arg.matchesPrefix("color") && arg.matchesArgumentType(ColorTag.class)) {
scriptEntry.addObject("color", arg.asType(ColorTag.class));
} else if (arg.matchesPrefix("alpha") && arg.matchesFloat()) {
scriptEntry.addObject("alpha", arg.asElement());
} else if (arg.matchesPrefix("name")) {
scriptEntry.addObject("name", arg.asElement());
} else if (arg.matches("clear")) {
scriptEntry.addObject("clear", new ElementTag(true));
} else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
scriptEntry.addObject("locations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("players") && Utilities.entryHasPlayer(scriptEntry)) {
scriptEntry.defaultObject("players", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
}
if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("clear")) {
throw new InvalidArgumentsException("Must specify at least one valid location!");
}
if (!scriptEntry.hasObject("players")) {
throw new InvalidArgumentsException("Must have a valid, online player attached!");
}
scriptEntry.defaultObject("duration", new DurationTag(10));
scriptEntry.defaultObject("color", new ColorTag(255, 255, 255));
scriptEntry.defaultObject("alpha", new ElementTag("1"));
}
use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class DebugBlockCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag clear = scriptEntry.getElement("clear");
List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
ColorTag color = scriptEntry.getObjectTag("color");
ElementTag alpha = scriptEntry.getElement("alpha");
ElementTag name = scriptEntry.getElement("name");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), clear == null ? db("locations", locations) : clear, duration, db("players", players), color, alpha, name);
}
if (clear != null && clear.asBoolean()) {
for (PlayerTag player : players) {
NMSHandler.getPacketHelper().clearDebugTestMarker(player.getPlayerEntity());
}
} else {
int alphaInt = (int) (alpha.asFloat() * 255);
for (LocationTag location : locations) {
for (PlayerTag player : players) {
NMSHandler.getPacketHelper().showDebugTestMarker(player.getPlayerEntity(), location, color, alphaInt, name == null ? "" : name.asString(), (int) duration.getMillis());
}
}
}
}
use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAreaEffectCloud method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("base_potion")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("type")) {
return new ElementTag(getHelper().getBPName()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_upgraded")) {
return new ElementTag(getHelper().getBPUpgraded()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_extended")) {
return new ElementTag(getHelper().getBPExtended()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getBPName() + "," + getHelper().getBPUpgraded() + "," + getHelper().getBPExtended()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("particle")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("color")) {
return new ColorTag(getHelper().getColor()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getParticle()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("duration")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("on_use")) {
return new DurationTag(getHelper().getDurationOnUse()).getObjectAttribute(attribute.fulfill(1));
}
return new DurationTag(getHelper().getDuration()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("radius")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("on_use")) {
return new ElementTag(getHelper().getRadiusOnUse()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("per_tick")) {
return new ElementTag(getHelper().getRadiusPerTick()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getRadius()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("reapplication_delay")) {
return new DurationTag(getHelper().getReappDelay()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("wait_time")) {
return new DurationTag(getHelper().getWaitTime()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_custom_effect")) {
if (attribute.hasParam()) {
PotionEffectType effectType = PotionEffectType.getByName(attribute.getParam());
for (PotionEffect effect : getHelper().getCustomEffects()) {
if (effect.getType().equals(effectType)) {
return new ElementTag(true).getObjectAttribute(attribute.fulfill(1));
}
}
return new ElementTag(false).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().hasCustomEffects()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("source")) {
ProjectileSource shooter = getHelper().getSource();
if (shooter instanceof LivingEntity) {
return new EntityTag((LivingEntity) shooter).getObjectAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("custom_effects")) {
List<PotionEffect> effects = getHelper().getCustomEffects();
if (!attribute.hasParam()) {
ListTag list = new ListTag();
for (PotionEffect effect : effects) {
list.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles());
}
return list.getObjectAttribute(attribute.fulfill(1));
}
int val = attribute.getIntParam() - 1;
if (val < 0 || val >= effects.size()) {
return null;
}
attribute = attribute.fulfill(1);
PotionEffect effect = effects.get(val);
// -->
if (attribute.startsWith("type")) {
return new ElementTag(effect.getType().getName()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("amplifier")) {
return new ElementTag(effect.getAmplifier()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("duration")) {
return new DurationTag((long) effect.getDuration()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_particles")) {
return new ElementTag(effect.hasParticles()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_ambient")) {
return new ElementTag(effect.isAmbient()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles()).getObjectAttribute(attribute);
}
return null;
}
Aggregations