use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class LocationTag method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("block_facing") && mechanism.requireObject(LocationTag.class)) {
LocationTag faceVec = mechanism.valueAsType(LocationTag.class);
Block block = getBlock();
MaterialTag material = new MaterialTag(block);
if (!MaterialDirectional.describes(material)) {
mechanism.echoError("LocationTag.block_facing mechanism failed: block is not directional.");
return;
}
MaterialDirectional.getFrom(material).setFacing(Utilities.faceFor(faceVec.toVector()));
block.setBlockData(material.getModernData());
}
// -->
if (mechanism.matches("block_type") && mechanism.requireObject(MaterialTag.class)) {
MaterialTag mat = mechanism.valueAsType(MaterialTag.class);
getBlock().setBlockData(mat.getModernData(), false);
}
// -->
if (mechanism.matches("biome") && mechanism.requireObject(BiomeTag.class)) {
mechanism.valueAsType(BiomeTag.class).getBiome().setTo(getBlock());
}
// -->
if (mechanism.matches("spawner_custom_rules") && mechanism.requireObject(MapTag.class) && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
MapTag map = mechanism.valueAsType(MapTag.class);
ObjectTag skyMin = map.getObject("sky_min"), skyMax = map.getObject("sky_max"), blockMin = map.getObject("block_min"), blockMax = map.getObject("block_max");
if (skyMin == null || skyMax == null || blockMin == null || blockMax == null) {
mechanism.echoError("Invalid spawner_custom_rules input, missing map keys.");
return;
}
NMSHandler.getBlockHelper().setSpawnerCustomRules(spawner, Integer.parseInt(skyMin.toString()), Integer.parseInt(skyMax.toString()), Integer.parseInt(blockMin.toString()), Integer.parseInt(blockMax.toString()));
spawner.update();
}
// -->
if (mechanism.matches("spawner_type") && mechanism.requireObject(EntityTag.class) && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
NMSHandler.getBlockHelper().setSpawnerSpawnedType(spawner, mechanism.valueAsType(EntityTag.class));
spawner.update();
}
// -->
if (mechanism.matches("spawner_delay_data") && getBlockState() instanceof CreatureSpawner) {
ListTag list = mechanism.valueAsType(ListTag.class);
if (list.size() < 3) {
return;
}
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setDelay(Integer.parseInt(list.get(0)));
int minDelay = Integer.parseInt(list.get(1));
int maxDelay = Integer.parseInt(list.get(2));
// or new min would be higher than the current max
if (minDelay > spawner.getMaxSpawnDelay()) {
spawner.setMaxSpawnDelay(maxDelay);
spawner.setMinSpawnDelay(minDelay);
} else {
spawner.setMinSpawnDelay(minDelay);
spawner.setMaxSpawnDelay(maxDelay);
}
spawner.update();
}
// -->
if (mechanism.matches("spawner_max_nearby_entities") && mechanism.requireInteger() && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setMaxNearbyEntities(mechanism.getValue().asInt());
spawner.update();
}
// -->
if (mechanism.matches("spawner_player_range") && mechanism.requireInteger() && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setRequiredPlayerRange(mechanism.getValue().asInt());
spawner.update();
}
// -->
if (mechanism.matches("spawner_range") && mechanism.requireInteger() && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setSpawnRange(mechanism.getValue().asInt());
spawner.update();
}
// -->
if (mechanism.matches("spawner_count") && mechanism.requireInteger() && getBlockState() instanceof CreatureSpawner) {
CreatureSpawner spawner = ((CreatureSpawner) getBlockState());
spawner.setSpawnCount(mechanism.getValue().asInt());
spawner.update();
}
// -->
if (mechanism.matches("lock") && getBlockState() instanceof Lockable) {
BlockState state = getBlockState();
((Lockable) state).setLock(mechanism.hasValue() ? mechanism.getValue().asString() : null);
state.update();
}
// -->
if (mechanism.matches("sign_contents") && getBlockState() instanceof Sign) {
Sign state = (Sign) getBlockState();
for (int i = 0; i < 4; i++) {
AdvancedTextImpl.instance.setSignLine(state, i, "");
}
ListTag list = mechanism.valueAsType(ListTag.class);
CoreUtilities.fixNewLinesToListSeparation(list);
if (list.size() > 4) {
Debug.echoError("Sign can only hold four lines!");
} else {
for (int i = 0; i < list.size(); i++) {
AdvancedTextImpl.instance.setSignLine(state, i, list.get(i));
}
}
state.update();
}
// -->
if (mechanism.matches("skull_skin")) {
final BlockState blockState = getBlockState();
Material material = getBlock().getType();
if (blockState instanceof Skull) {
ListTag list = mechanism.valueAsType(ListTag.class);
String idString = list.get(0);
String texture = null;
if (list.size() > 1) {
texture = list.get(1);
}
PlayerProfile profile;
if (idString.contains("-")) {
UUID uuid = UUID.fromString(idString);
String name = null;
if (list.size() > 2) {
name = list.get(2);
}
profile = new PlayerProfile(name, uuid, texture);
} else {
profile = new PlayerProfile(idString, null, texture);
}
profile = NMSHandler.getInstance().fillPlayerProfile(profile);
if (texture != null) {
// Ensure we didn't get overwritten
profile.setTexture(texture);
}
NMSHandler.getBlockHelper().setPlayerProfile((Skull) blockState, profile);
} else {
Debug.echoError("Unable to set skull_skin on block of type " + material.name() + " with state " + blockState.getClass().getCanonicalName());
}
}
// -->
if (mechanism.matches("hive_max_bees") && mechanism.requireInteger()) {
Beehive hive = (Beehive) getBlockState();
hive.setMaxEntities(mechanism.getValue().asInt());
hive.update();
}
// -->
if (mechanism.matches("release_bees")) {
Beehive hive = (Beehive) getBlockState();
hive.releaseEntities();
hive.update();
}
// -->
if (mechanism.matches("add_bee") && mechanism.requireObject(EntityTag.class)) {
Beehive hive = (Beehive) getBlockState();
hive.addEntity((Bee) mechanism.valueAsType(EntityTag.class).getBukkitEntity());
hive.update();
}
// -->
if (mechanism.matches("command_block_name")) {
if (getBlock().getState() instanceof CommandBlock) {
CommandBlock block = ((CommandBlock) getBlockState());
block.setName(mechanism.getValue().asString());
block.update();
}
}
// -->
if (mechanism.matches("command_block")) {
if (getBlock().getState() instanceof CommandBlock) {
CommandBlock block = ((CommandBlock) getBlockState());
block.setCommand(mechanism.getValue().asString());
block.update();
}
}
// -->
if (mechanism.matches("custom_name")) {
if (getBlockState() instanceof Nameable) {
String title = null;
if (mechanism.hasValue()) {
title = mechanism.getValue().asString();
}
BlockState state = getBlockState();
((Nameable) state).setCustomName(title);
state.update(true);
}
}
// -->
if (mechanism.matches("brewing_time")) {
if (getBlockState() instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) getBlockState();
stand.setBrewingTime(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
stand.update();
}
}
// -->
if (mechanism.matches("brewing_fuel_level")) {
if (getBlockState() instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) getBlockState();
stand.setFuelLevel(mechanism.getValue().asInt());
stand.update();
}
}
// -->
if (mechanism.matches("furnace_burn_duration") && mechanism.requireObject(DurationTag.class)) {
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setBurnTime((short) mechanism.valueAsType(DurationTag.class).getTicks());
furnace.update();
}
}
if (mechanism.matches("furnace_burn_time")) {
Deprecations.furnaceTimeTags.warn(mechanism.context);
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setBurnTime((short) mechanism.getValue().asInt());
furnace.update();
}
}
// -->
if (mechanism.matches("furnace_cook_duration")) {
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setCookTime((short) mechanism.valueAsType(DurationTag.class).getTicks());
furnace.update();
}
}
if (mechanism.matches("furnace_cook_time")) {
Deprecations.furnaceTimeTags.warn(mechanism.context);
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setCookTime((short) mechanism.getValue().asInt());
furnace.update();
}
}
// -->
if (mechanism.matches("furnace_cook_duration_total")) {
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setCookTimeTotal((short) mechanism.valueAsType(DurationTag.class).getTicks());
furnace.update();
}
}
if (mechanism.matches("furnace_cook_time_total")) {
Deprecations.furnaceTimeTags.warn(mechanism.context);
if (getBlockState() instanceof Furnace) {
Furnace furnace = (Furnace) getBlockState();
furnace.setCookTimeTotal((short) mechanism.getValue().asInt());
furnace.update();
}
}
// -->
if (mechanism.matches("patterns")) {
List<org.bukkit.block.banner.Pattern> patterns = new ArrayList<>();
ListTag list = mechanism.valueAsType(ListTag.class);
List<String> split;
for (String string : list) {
try {
split = CoreUtilities.split(string, '/', 2);
patterns.add(new org.bukkit.block.banner.Pattern(DyeColor.valueOf(split.get(0).toUpperCase()), PatternType.valueOf(split.get(1).toUpperCase())));
} catch (Exception e) {
Debug.echoError("Could not apply pattern to banner: " + string);
}
}
Banner banner = (Banner) getBlockState();
banner.setPatterns(patterns);
banner.update();
}
// -->
if (mechanism.matches("head_rotation") && mechanism.requireInteger()) {
Skull sk = (Skull) getBlockState();
sk.setRotation(getSkullBlockFace(mechanism.getValue().asInt() - 1));
sk.update();
}
// -->
if (mechanism.matches("generate_tree") && mechanism.requireEnum(TreeType.class)) {
boolean generated = getWorld().generateTree(this, TreeType.valueOf(mechanism.getValue().asString().toUpperCase()));
if (!generated) {
Debug.echoError("Could not generate tree at " + identifySimple() + ". Make sure this location can naturally generate a tree!");
}
}
// -->
if (mechanism.matches("beacon_primary_effect")) {
Beacon beacon = (Beacon) getBlockState();
beacon.setPrimaryEffect(PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase()));
beacon.update();
}
// -->
if (mechanism.matches("beacon_secondary_effect")) {
Beacon beacon = (Beacon) getBlockState();
beacon.setSecondaryEffect(PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase()));
beacon.update();
}
// -->
if (mechanism.matches("activate")) {
BlockState state = getBlockState();
if (state instanceof Dispenser) {
((Dispenser) state).dispense();
} else if (state instanceof Dropper) {
((Dropper) state).drop();
} else {
Debug.echoError("'activate' mechanism does not work for blocks of type: " + state.getType().name());
}
}
// -->
if (mechanism.matches("lectern_page") && mechanism.requireInteger()) {
BlockState state = getBlockState();
if (state instanceof Lectern) {
((Lectern) state).setPage(mechanism.getValue().asInt());
state.update();
} else {
Debug.echoError("'lectern_page' mechanism can only be called on a lectern block.");
}
}
// -->
if (mechanism.matches("clear_loot_table")) {
BlockState state = getBlockState();
if (state instanceof Lootable) {
((Lootable) state).setLootTable(null);
state.update();
} else {
Debug.echoError("'clear_loot_table' mechanism can only be called on a lootable block (like a chest).");
}
}
// -->
if (mechanism.matches("jukebox_record")) {
BlockState state = getBlockState();
if (state instanceof Jukebox) {
if (mechanism.hasValue() && mechanism.requireObject(ItemTag.class)) {
((Jukebox) state).setRecord(mechanism.valueAsType(ItemTag.class).getItemStack());
} else {
NMSHandler.getBlockHelper().makeBlockStateRaw(state);
((Jukebox) state).setRecord(null);
}
state.update();
} else {
Debug.echoError("'jukebox_record' mechanism can only be called on a jukebox block.");
}
}
// -->
if (mechanism.matches("jukebox_play") && mechanism.requireBoolean()) {
BlockState state = getBlockState();
if (state instanceof Jukebox) {
if (mechanism.getValue().asBoolean()) {
Material mat = ((Jukebox) state).getRecord().getType();
if (mat == Material.AIR) {
Debug.echoError("'jukebox_play' cannot play nothing.");
return;
}
((Jukebox) state).setPlaying(mat);
} else {
((Jukebox) state).stopPlaying();
}
state.update();
} else {
Debug.echoError("'jukebox_play' mechanism can only be called on a jukebox block.");
}
}
// -->
if (mechanism.matches("age") && mechanism.requireObject(DurationTag.class)) {
BlockState state = getBlockState();
if (state instanceof EndGateway) {
((EndGateway) state).setAge(mechanism.valueAsType(DurationTag.class).getTicks());
state.update();
} else {
Debug.echoError("'age' mechanism can only be called on end gateway blocks.");
}
}
// -->
if (mechanism.matches("is_exact_teleport") && mechanism.requireBoolean()) {
BlockState state = getBlockState();
if (state instanceof EndGateway) {
((EndGateway) state).setExactTeleport(mechanism.getValue().asBoolean());
state.update();
} else {
Debug.echoError("'is_exact_teleport' mechanism can only be called on end gateway blocks.");
}
}
// -->
if (mechanism.matches("exit_location") && mechanism.requireObject(LocationTag.class)) {
BlockState state = getBlockState();
if (state instanceof EndGateway) {
((EndGateway) state).setExitLocation(mechanism.valueAsType(LocationTag.class));
state.update();
} else {
Debug.echoError("'exit_location' mechanism can only be called on end gateway blocks.");
}
}
// -->
if (mechanism.matches("vanilla_tick")) {
NMSHandler.getBlockHelper().doRandomTick(this);
}
// -->
if (mechanism.matches("apply_bonemeal") && mechanism.requireEnum(BlockFace.class)) {
getBlock().applyBoneMeal(BlockFace.valueOf(mechanism.getValue().asString().toUpperCase()));
}
// -->
if (mechanism.matches("campfire_items") && mechanism.requireObject(ListTag.class)) {
BlockState state = getBlockState();
if (!(state instanceof Campfire)) {
Debug.echoError("'campfire_items' mechanism can only be called on campfire blocks.");
} else {
Campfire fire = (Campfire) state;
List<ItemTag> list = mechanism.valueAsType(ListTag.class).filter(ItemTag.class, mechanism.context);
for (int i = 0; i < list.size(); i++) {
if (i >= fire.getSize()) {
Debug.echoError("Cannot add item for index " + (i + 1) + " as the campfire can only hold " + fire.getSize() + " items.");
break;
}
fire.setItem(i, list.get(i).getItemStack());
}
fire.update();
}
}
// -->
if (mechanism.matches("ring_bell")) {
BlockState state = getBlockState();
if (!(state instanceof Bell)) {
Debug.echoError("'ring_bell' mechanism can only be called on Bell blocks.");
} else {
NMSHandler.getBlockHelper().ringBell((Bell) state);
}
}
// -->
if (mechanism.matches("sign_glowing") && mechanism.requireBoolean()) {
BlockState state = getBlockState();
if (!(state instanceof Sign)) {
Debug.echoError("'sign_glowing' mechanism can only be called on Sign blocks.");
} else {
Sign sign = (Sign) state;
sign.setGlowingText(mechanism.getValue().asBoolean());
sign.update();
}
}
// -->
if (mechanism.matches("sign_glow_color") && mechanism.requireEnum(DyeColor.class)) {
BlockState state = getBlockState();
if (!(state instanceof Sign)) {
Debug.echoError("'sign_glow_color' mechanism can only be called on Sign blocks.");
} else {
Sign sign = (Sign) state;
sign.setColor(mechanism.getValue().asEnum(DyeColor.class));
sign.update();
}
}
CoreUtilities.autoPropertyMechanism(this, mechanism);
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeModifiers method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
try {
MapTag input = mechanism.valueAsType(MapTag.class);
Attributable ent = getAttributable();
for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
Attribute attr = Attribute.valueOf(subValue.getKey().str.toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
for (AttributeModifier modifier : instance.getModifiers()) {
instance.removeModifier(modifier);
}
for (ObjectTag listValue : CoreUtilities.objectToList(subValue.getValue(), mechanism.context)) {
instance.addModifier(modiferForMap(attr, listValue.asType(MapTag.class, mechanism.context)));
}
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
// -->
if (mechanism.matches("add_attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
try {
MapTag input = mechanism.valueAsType(MapTag.class);
Attributable ent = getAttributable();
for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
Attribute attr = Attribute.valueOf(subValue.getKey().str.toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
for (ObjectTag listValue : CoreUtilities.objectToList(subValue.getValue(), mechanism.context)) {
instance.addModifier(modiferForMap(attr, listValue.asType(MapTag.class, mechanism.context)));
}
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
// -->
if (mechanism.matches("remove_attribute_modifiers") && mechanism.requireObject(ListTag.class)) {
ArrayList<String> inputList = new ArrayList<>(mechanism.valueAsType(ListTag.class));
Attributable ent = getAttributable();
for (String toRemove : new ArrayList<>(inputList)) {
if (new ElementTag(toRemove).matchesEnum(Attribute.class)) {
inputList.remove(toRemove);
Attribute attr = Attribute.valueOf(toRemove.toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
for (AttributeModifier modifier : instance.getModifiers()) {
instance.removeModifier(modifier);
}
}
}
for (String toRemove : inputList) {
UUID id = UUID.fromString(toRemove);
for (Attribute attr : Attribute.values()) {
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
continue;
}
for (AttributeModifier modifer : instance.getModifiers()) {
if (modifer.getUniqueId().equals(id)) {
instance.removeModifier(modifer);
break;
}
}
}
}
}
if (mechanism.matches("attributes") && mechanism.hasValue()) {
Deprecations.legacyAttributeProperties.warn(mechanism.context);
Attributable ent = getAttributable();
ListTag list = mechanism.valueAsType(ListTag.class);
for (String str : list) {
List<String> subList = CoreUtilities.split(str, '/');
Attribute attr = Attribute.valueOf(EscapeTagBase.unEscape(subList.get(0)).toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
instance.setBaseValue(Double.parseDouble(subList.get(1)));
for (AttributeModifier modifier : instance.getModifiers()) {
instance.removeModifier(modifier);
}
for (int x = 2; x < subList.size(); x += 4) {
String slot = subList.get(x + 3).toUpperCase();
AttributeModifier modifier = new AttributeModifier(UUID.randomUUID(), EscapeTagBase.unEscape(subList.get(x)), Double.parseDouble(subList.get(x + 1)), AttributeModifier.Operation.valueOf(subList.get(x + 2).toUpperCase()), slot.equals("ANY") ? null : EquipmentSlot.valueOf(slot));
instance.addModifier(modifier);
}
}
}
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeModifiers method mapify.
public static MapTag mapify(AttributeModifier modifier) {
MapTag result = new MapTag();
result.putObject("name", new ElementTag(modifier.getName()));
result.putObject("amount", new ElementTag(modifier.getAmount()));
result.putObject("operation", new ElementTag(modifier.getOperation().name()));
result.putObject("slot", new ElementTag(modifier.getSlot() == null ? "any" : modifier.getSlot().name()));
result.putObject("id", new ElementTag(modifier.getUniqueId().toString()));
return result;
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class PluginTag method registerTags.
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
// <--[tag]
// @attribute <PluginTag.name>
// @returns ElementTag
// @description
// Gets the name of this plugin.
// -->
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
return new ElementTag(object.plugin.getName());
});
// <--[tag]
// @attribute <PluginTag.version>
// @returns ElementTag
// @description
// Gets the version for the plugin specified.
// -->
tagProcessor.registerTag(ElementTag.class, "version", (attribute, object) -> {
return new ElementTag(object.plugin.getDescription().getVersion());
});
// <--[tag]
// @attribute <PluginTag.description>
// @returns ElementTag
// @description
// Gets the description for the plugin specified.
// -->
tagProcessor.registerTag(ElementTag.class, "description", (attribute, object) -> {
return new ElementTag(object.plugin.getDescription().getDescription());
});
// <--[tag]
// @attribute <PluginTag.authors>
// @returns ListTag
// @description
// Gets the list of authors for the plugin specified.
// -->
tagProcessor.registerTag(ListTag.class, "authors", (attribute, object) -> {
return new ListTag(object.plugin.getDescription().getAuthors());
});
// <--[tag]
// @attribute <PluginTag.depends>
// @returns ListTag
// @description
// Gets the list of hard dependencies for the plugin specified.
// -->
tagProcessor.registerTag(ListTag.class, "depends", (attribute, object) -> {
return new ListTag(object.plugin.getDescription().getDepend());
});
// <--[tag]
// @attribute <PluginTag.soft_depends>
// @returns ListTag
// @description
// Gets the list of soft dependencies for the plugin specified.
// -->
tagProcessor.registerTag(ListTag.class, "soft_depends", (attribute, object) -> {
return new ListTag(object.plugin.getDescription().getSoftDepend());
});
// <--[tag]
// @attribute <PluginTag.commands>
// @returns MapTag(MapTag)
// @description
// Gets a map of commands registered this plugin registers by default.
// Note that dynamically registered commands won't show up (for example, command scripts won't be listed under Denizen).
// Map key is command name, map value is a sub-mapping with keys:
// description (ElementTag), usage (ElementTag), permission (ElementTag), aliases (ListTag)
// Not all keys will be present.
// For example, <plugin[denizen].commands.get[ex]> will return a MapTag with:
// [description=Executes a Denizen script command.;usage=/ex (-q) <Denizen script command> (arguments);permission=denizen.ex]
// -->
tagProcessor.registerTag(MapTag.class, "commands", (attribute, object) -> {
Map<String, Map<String, Object>> commands = object.plugin.getDescription().getCommands();
MapTag output = new MapTag();
if (commands == null || commands.isEmpty()) {
return output;
}
for (Map.Entry<String, Map<String, Object>> command : commands.entrySet()) {
MapTag dataMap = new MapTag();
if (command.getValue().containsKey("description")) {
dataMap.putObject("description", new ElementTag(command.getValue().get("description").toString(), true));
}
if (command.getValue().containsKey("usage")) {
dataMap.putObject("usage", new ElementTag(command.getValue().get("usage").toString(), true));
}
if (command.getValue().containsKey("permission")) {
dataMap.putObject("permission", new ElementTag(command.getValue().get("permission").toString(), true));
}
if (command.getValue().containsKey("aliases")) {
Object obj = command.getValue().get("aliases");
if (obj instanceof List) {
ListTag aliases = new ListTag();
for (Object entry : (List) obj) {
aliases.addObject(new ElementTag(String.valueOf(entry), true));
}
dataMap.putObject("aliases", aliases);
}
}
output.putObject(command.getKey(), dataMap);
}
return output;
});
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityFlags method getPropertyString.
@Override
public String getPropertyString() {
AbstractFlagTracker tracker = entity.getFlagTracker();
if (!(tracker instanceof DataPersistenceFlagTracker)) {
return null;
}
Collection<String> flagNames = tracker.listAllFlags();
if (flagNames.isEmpty()) {
return null;
}
MapTag flags = new MapTag();
for (String name : flagNames) {
flags.putObject(name, ((DataPersistenceFlagTracker) tracker).getRootMap(name));
}
return flags.toString();
}
Aggregations