use of net.aufdemrand.denizen.flags.FlagManager in project Denizen-For-Bukkit by DenizenScript.
the class dPlayer method getAttribute.
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
if (offlinePlayer == null) {
return null;
}
// Defined in dEntity
if (attribute.startsWith("is_player")) {
return Element.TRUE.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("debug.log")) {
dB.log(debug());
return Element.TRUE.getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("debug.no_color")) {
return new Element(ChatColor.stripColor(debug())).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("debug")) {
return new Element(debug()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("prefix")) {
return new Element(prefix).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("chat_history_list")) {
return // TODO: UUID?
new dList(PlayerTags.playerChatHistory.get(getName())).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("chat_history")) {
int x = 1;
if (attribute.hasContext(1) && aH.matchesInteger(attribute.getContext(1))) {
x = attribute.getIntContext(1);
}
// No playerchathistory? Return null.
if (!PlayerTags.playerChatHistory.containsKey(getName())) {
// TODO: UUID?
return null;
}
// TODO: UUID?
List<String> messages = PlayerTags.playerChatHistory.get(getName());
if (messages.size() < x || x < 1) {
return null;
}
return new Element(messages.get(x - 1)).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("flag") && attribute.hasContext(1)) {
String flag_name = attribute.getContext(1);
if (attribute.getAttribute(2).equalsIgnoreCase("is_expired") || attribute.startsWith("isexpired")) {
return new Element(!FlagManager.playerHasFlag(this, flag_name)).getAttribute(attribute.fulfill(2));
}
if (attribute.getAttribute(2).equalsIgnoreCase("size") && !FlagManager.playerHasFlag(this, flag_name)) {
return new Element(0).getAttribute(attribute.fulfill(2));
}
if (FlagManager.playerHasFlag(this, flag_name)) {
FlagManager.Flag flag = DenizenAPI.getCurrentInstance().flagManager().getPlayerFlag(this, flag_name);
return new dList(flag.toString(), true, flag.values()).getAttribute(attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute);
}
// -->
if (attribute.startsWith("has_flag") && attribute.hasContext(1)) {
String flag_name = attribute.getContext(1);
return new Element(FlagManager.playerHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("list_flags")) {
dList allFlags = new dList(DenizenAPI.getCurrentInstance().flagManager().listPlayerFlags(this));
dList searchFlags = null;
if (!allFlags.isEmpty() && attribute.hasContext(1)) {
searchFlags = new dList();
String search = attribute.getContext(1);
if (search.startsWith("regex:")) {
try {
Pattern pattern = Pattern.compile(search.substring(6), Pattern.CASE_INSENSITIVE);
for (String flag : allFlags) {
if (pattern.matcher(flag).matches()) {
searchFlags.add(flag);
}
}
} catch (Exception e) {
dB.echoError(e);
}
} else {
search = CoreUtilities.toLowerCase(search);
for (String flag : allFlags) {
if (CoreUtilities.toLowerCase(flag).contains(search)) {
searchFlags.add(flag);
}
}
}
}
return searchFlags == null ? allFlags.getAttribute(attribute.fulfill(1)) : searchFlags.getAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("current_step")) {
String outcome = "null";
if (attribute.hasContext(1)) {
try {
outcome = DenizenAPI.getCurrentInstance().getSaves().getString("Players." + getName() + ".Scripts." + dScript.valueOf(attribute.getContext(1)).getName() + ".Current Step");
} catch (Exception e) {
outcome = "null";
}
}
return new Element(outcome).getAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("money")) {
if (Depends.economy != null) {
// -->
if (attribute.startsWith("money.currency_singular")) {
return new Element(Depends.economy.currencyNameSingular()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("money.currency")) {
return new Element(Depends.economy.currencyNamePlural()).getAttribute(attribute.fulfill(2));
}
return new Element(Depends.economy.getBalance(getOfflinePlayer())).getAttribute(attribute.fulfill(1));
} else {
if (!attribute.hasAlternative()) {
dB.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
}
return null;
}
}
if (attribute.startsWith("target")) {
int range = 50;
int attribs = 1;
// -->
if (attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2) && aH.matchesInteger(attribute.getContext(2))) {
attribs = 2;
range = attribute.getIntContext(2);
}
List<Entity> entities = getPlayerEntity().getNearbyEntities(range, range, range);
ArrayList<LivingEntity> possibleTargets = new ArrayList<LivingEntity>();
for (Entity entity : entities) {
if (entity instanceof LivingEntity) {
// if we have a context for entity types, check the entity
if (attribute.hasContext(1)) {
String context = attribute.getContext(1);
if (CoreUtilities.toLowerCase(context).startsWith("li@")) {
context = context.substring(3);
}
for (String ent : context.split("\\|")) {
boolean valid = false;
if (ent.equalsIgnoreCase("npc") && dEntity.isCitizensNPC(entity)) {
valid = true;
} else if (dEntity.matches(ent)) {
// only accept generic entities that are not NPCs
if (dEntity.valueOf(ent).isGeneric()) {
if (dEntity.isCitizensNPC(entity)) {
valid = true;
}
} else {
valid = true;
}
}
if (valid) {
possibleTargets.add((LivingEntity) entity);
}
}
} else {
// no entity type specified
possibleTargets.add((LivingEntity) entity);
entity.getType();
}
}
}
// Find the valid target
BlockIterator bi;
try {
bi = new BlockIterator(getPlayerEntity(), range);
} catch (IllegalStateException e) {
return null;
}
Block b;
Location l;
int bx, by, bz;
double ex, ey, ez;
// Loop through player's line of sight
while (bi.hasNext()) {
b = bi.next();
bx = b.getX();
by = b.getY();
bz = b.getZ();
if (b.getType() != Material.AIR) {
// Line of sight is broken
break;
} else {
// Check for entities near this block in the line of sight
for (LivingEntity possibleTarget : possibleTargets) {
l = possibleTarget.getLocation();
ex = l.getX();
ey = l.getY();
ez = l.getZ();
if ((bx - .50 <= ex && ex <= bx + 1.50) && (bz - .50 <= ez && ez <= bz + 1.50) && (by - 1 <= ey && ey <= by + 2.5)) {
// Entity is close enough, so return it
return new dEntity(possibleTarget).getDenizenObject().getAttribute(attribute.fulfill(attribs));
}
}
}
}
return null;
}
// workaround for <e@entity.list_effects>
if (attribute.startsWith("list_effects")) {
dList effects = new dList();
for (PotionEffect effect : getPlayerEntity().getActivePotionEffects()) {
effects.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + effect.getDuration() + "t");
}
return effects.getAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("list")) {
dB.echoError("DO NOT USE PLAYER.LIST AS A TAG, please use <server.list_online_players> and related tags!");
List<String> players = new ArrayList<String>();
if (attribute.startsWith("list.online")) {
for (Player player : Bukkit.getOnlinePlayers()) {
players.add(player.getName());
}
return new dList(players).getAttribute(attribute.fulfill(2));
} else if (attribute.startsWith("list.offline")) {
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (!player.isOnline()) {
players.add("p@" + player.getUniqueId().toString());
}
}
return new dList(players).getAttribute(attribute.fulfill(2));
} else {
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
players.add("p@" + player.getUniqueId().toString());
}
return new dList(players).getAttribute(attribute.fulfill(1));
}
}
if (attribute.startsWith("name") && !isOnline()) // This can be parsed later with more detail if the player is online, so only check for offline.
{
return new Element(getName()).getAttribute(attribute.fulfill(1));
} else if (attribute.startsWith("uuid") && !isOnline()) // This can be parsed later with more detail if the player is online, so only check for offline.
{
return new Element(offlinePlayer.getUniqueId().toString()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("type")) {
return new Element("Player").getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("save_name")) {
return new Element(getSaveName()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("bed_spawn")) {
if (getOfflinePlayer().getBedSpawnLocation() == null) {
return null;
}
return new dLocation(getOfflinePlayer().getBedSpawnLocation()).getAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("location") && !isOnline()) {
return getLocation().getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("first_played")) {
attribute = attribute.fulfill(1);
if (attribute.startsWith("milliseconds") || attribute.startsWith("in_milliseconds")) {
return new Element(getOfflinePlayer().getFirstPlayed()).getAttribute(attribute.fulfill(1));
}
return new Duration(getOfflinePlayer().getFirstPlayed() / 50).getAttribute(attribute);
}
// -->
if (attribute.startsWith("has_played_before")) {
return new Element(true).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("health.is_scaled")) {
return new Element(getPlayerEntity().isHealthScaled()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("health.scale")) {
return new Element(getPlayerEntity().getHealthScale()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("exhaustion")) {
return new Element(getPlayerEntity().getExhaustion()).getAttribute(attribute.fulfill(1));
}
// Handle dEntity oxygen tags here to allow getting them when the player is offline
if (attribute.startsWith("oxygen.max")) {
return new Duration((long) getMaximumAir()).getAttribute(attribute.fulfill(2));
}
if (attribute.startsWith("oxygen")) {
return new Duration((long) getRemainingAir()).getAttribute(attribute.fulfill(1));
}
// Same with health tags
if (attribute.startsWith("health.formatted")) {
return EntityHealth.getHealthFormatted(new dEntity(getPlayerEntity()), attribute);
}
if (attribute.startsWith("health.percentage")) {
double maxHealth = getPlayerEntity().getMaxHealth();
if (attribute.hasContext(2)) {
maxHealth = attribute.getIntContext(2);
}
return new Element((getPlayerEntity().getHealth() / maxHealth) * 100).getAttribute(attribute.fulfill(2));
}
if (attribute.startsWith("health.max")) {
return new Element(getMaxHealth()).getAttribute(attribute.fulfill(2));
}
if (attribute.matches("health")) {
return new Element(getHealth()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_banned")) {
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(getName());
if (ban == null) {
return Element.FALSE.getAttribute(attribute.fulfill(1));
} else if (ban.getExpiration() == null) {
return Element.TRUE.getAttribute(attribute.fulfill(1));
}
return new Element(ban.getExpiration().after(new Date())).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_online")) {
return new Element(isOnline()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_op")) {
return new Element(getOfflinePlayer().isOp()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_whitelisted")) {
return new Element(getOfflinePlayer().isWhitelisted()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("last_played")) {
attribute = attribute.fulfill(1);
if (attribute.startsWith("milliseconds") || attribute.startsWith("in_milliseconds")) {
if (isOnline()) {
return new Element(System.currentTimeMillis()).getAttribute(attribute.fulfill(1));
}
return new Element(getOfflinePlayer().getLastPlayed()).getAttribute(attribute.fulfill(1));
}
if (isOnline()) {
return new Duration(System.currentTimeMillis() / 50).getAttribute(attribute);
}
return new Duration(getOfflinePlayer().getLastPlayed() / 50).getAttribute(attribute);
}
// -->
if (attribute.startsWith("groups")) {
if (Depends.permissions == null) {
if (!attribute.hasAlternative()) {
dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
}
return null;
}
dList list = new dList();
// TODO: optionally specify world
for (String group : Depends.permissions.getGroups()) {
if (Depends.permissions.playerInGroup(null, offlinePlayer, group)) {
list.add(group);
}
}
return list.getAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("ban_info")) {
attribute.fulfill(1);
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(getName());
if (ban == null) {
return null;
} else if (ban.getExpiration() != null && ban.getExpiration().before(new Date())) {
return null;
}
// -->
if (attribute.startsWith("expiration") && ban.getExpiration() != null) {
return new Duration(ban.getExpiration().getTime() / 50).getAttribute(attribute.fulfill(1));
} else // -->
if (attribute.startsWith("reason")) {
return new Element(ban.getReason()).getAttribute(attribute.fulfill(1));
} else // -->
if (attribute.startsWith("created")) {
return new Duration(ban.getCreated().getTime() / 50).getAttribute(attribute.fulfill(1));
}
return null;
}
// -->
if (attribute.startsWith("in_group")) {
if (Depends.permissions == null) {
if (!attribute.hasAlternative()) {
dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
}
return null;
}
String group = attribute.getContext(1);
// Non-world specific permission
if (attribute.getAttribute(2).startsWith("global")) {
return // TODO: Vault UUID support?
new Element(Depends.permissions.playerInGroup((World) null, getName(), group)).getAttribute(attribute.fulfill(2));
} else // Permission in certain world
if (attribute.getAttribute(2).startsWith("world")) {
return // TODO: Vault UUID support?
new Element(Depends.permissions.playerInGroup(attribute.getContext(2), getName(), group)).getAttribute(attribute.fulfill(2));
} else // Permission in current world
if (isOnline()) {
return new Element(Depends.permissions.playerInGroup(getPlayerEntity(), group)).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("permission") || attribute.startsWith("has_permission")) {
String permission = attribute.getContext(1);
// Non-world specific permission
if (attribute.getAttribute(2).startsWith("global")) {
if (Depends.permissions == null) {
if (!attribute.hasAlternative()) {
dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
}
return null;
}
return // TODO: Vault UUID support?
new Element(Depends.permissions.has((World) null, getName(), permission)).getAttribute(attribute.fulfill(2));
} else // Permission in certain world
if (attribute.getAttribute(2).startsWith("world")) {
if (Depends.permissions == null) {
if (!attribute.hasAlternative()) {
dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
}
return null;
}
return // TODO: Vault UUID support?
new Element(Depends.permissions.has(attribute.getContext(2), getName(), permission)).getAttribute(attribute.fulfill(2));
} else // Permission in current world
if (isOnline()) {
return new Element(getPlayerEntity().hasPermission(permission)).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("inventory")) {
return getInventory().getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("enderchest")) {
return getEnderChest().getAttribute(attribute.fulfill(1));
}
// Player is required to be online after this point...
if (!isOnline()) {
return new Element(identify()).getAttribute(attribute);
}
// -->
if (attribute.startsWith("open_inventory")) {
return new dInventory(getPlayerEntity().getOpenInventory().getTopInventory()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("item_on_cursor")) {
return new dItem(getPlayerEntity().getItemOnCursor()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("item_in_hand.slot")) {
return new Element(getPlayerEntity().getInventory().getHeldItemSlot() + 1).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("sidebar.lines")) {
Sidebar sidebar = SidebarCommand.getSidebar(this);
if (sidebar == null) {
return null;
}
return new dList(sidebar.getLines()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("sidebar.title")) {
Sidebar sidebar = SidebarCommand.getSidebar(this);
if (sidebar == null) {
return null;
}
return new Element(sidebar.getTitle()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("sidebar.scores")) {
Sidebar sidebar = SidebarCommand.getSidebar(this);
if (sidebar == null) {
return null;
}
dList scores = new dList();
for (int score : sidebar.getScores()) {
scores.add(String.valueOf(score));
}
return scores.getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("sidebar.start")) {
Sidebar sidebar = SidebarCommand.getSidebar(this);
if (sidebar == null) {
return null;
}
return new Element(sidebar.getStart()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("sidebar.increment")) {
Sidebar sidebar = SidebarCommand.getSidebar(this);
if (sidebar == null) {
return null;
}
return new Element(sidebar.getIncrement()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("skin_blob")) {
return new Element(NMSHandler.getInstance().getProfileEditor().getPlayerSkinBlob(getPlayerEntity())).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("selected_npc")) {
if (getPlayerEntity().hasMetadata("selected")) {
return getSelectedNPC().getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("entity") && !attribute.startsWith("entity_")) {
return new dEntity(getPlayerEntity()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("ip") || attribute.startsWith("host_name")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("address_only")) {
return new Element(getPlayerEntity().getAddress().toString()).getAttribute(attribute.fulfill(1));
}
String host = getPlayerEntity().getAddress().getHostName();
// -->
if (attribute.startsWith("address")) {
return new Element(getPlayerEntity().getAddress().toString()).getAttribute(attribute.fulfill(1));
}
return new Element(host).getAttribute(attribute);
}
// -->
if (attribute.startsWith("name.display")) {
return new Element(getPlayerEntity().getDisplayName()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("name.list")) {
return new Element(getPlayerEntity().getPlayerListName()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("nameplate")) {
return new Element(NMSHandler.getInstance().getProfileEditor().getPlayerName(getPlayerEntity())).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("name")) {
return new Element(getName()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_finished")) {
dScript script = dScript.valueOf(attribute.getContext(1));
if (script == null) {
return Element.FALSE.getAttribute(attribute.fulfill(1));
}
return new Element(FinishCommand.getScriptCompletes(getName(), script.getName()) > 0).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_failed")) {
dScript script = dScript.valueOf(attribute.getContext(1));
if (script == null) {
return Element.FALSE.getAttribute(attribute.fulfill(1));
}
return new Element(FailCommand.getScriptFails(getName(), script.getName()) > 0).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("compass_target")) {
Location target = getPlayerEntity().getCompassTarget();
if (target != null) {
return new dLocation(target).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("chunk_loaded") && attribute.hasContext(1)) {
dChunk chunk = dChunk.valueOf(attribute.getContext(1));
if (chunk == null) {
return null;
}
return new Element(hasChunkLoaded(chunk.chunk)).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("can_fly") || attribute.startsWith("allowed_flight")) {
return new Element(getPlayerEntity().getAllowFlight()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("fly_speed")) {
return new Element(getPlayerEntity().getFlySpeed()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("food_level.formatted")) {
double maxHunger = getPlayerEntity().getMaxHealth();
if (attribute.hasContext(2)) {
maxHunger = attribute.getIntContext(2);
}
int foodLevel = getFoodLevel();
if (foodLevel / maxHunger < .10) {
return new Element("starving").getAttribute(attribute.fulfill(2));
} else if (foodLevel / maxHunger < .40) {
return new Element("famished").getAttribute(attribute.fulfill(2));
} else if (foodLevel / maxHunger < .75) {
return new Element("parched").getAttribute(attribute.fulfill(2));
} else if (foodLevel / maxHunger < 1) {
return new Element("hungry").getAttribute(attribute.fulfill(2));
} else {
return new Element("healthy").getAttribute(attribute.fulfill(2));
}
}
// -->
if (attribute.startsWith("saturation")) {
return new Element(getPlayerEntity().getSaturation()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("food_level")) {
return new Element(getFoodLevel()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("gamemode")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("id")) {
return new Element(getPlayerEntity().getGameMode().getValue()).getAttribute(attribute.fulfill(1));
}
return new Element(getPlayerEntity().getGameMode().name()).getAttribute(attribute);
}
// -->
if (attribute.startsWith("is_blocking")) {
return new Element(getPlayerEntity().isBlocking()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("ping")) {
return new Element(NMSHandler.getInstance().getPlayerHelper().getPing(getPlayerEntity())).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_flying")) {
return new Element(getPlayerEntity().isFlying()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_sleeping")) {
return new Element(getPlayerEntity().isSleeping()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_sneaking")) {
return new Element(getPlayerEntity().isSneaking()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_sprinting")) {
return new Element(getPlayerEntity().isSprinting()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_achievement")) {
Achievement ach = Achievement.valueOf(attribute.getContext(1).toUpperCase());
return new Element(getPlayerEntity().hasAchievement(ach)).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("statistic")) {
Statistic statistic = Statistic.valueOf(attribute.getContext(1).toUpperCase());
if (statistic == null) {
return null;
}
// -->
if (attribute.getAttribute(2).startsWith("qualifier")) {
dObject obj = ObjectFetcher.pickObjectFor(attribute.getContext(2));
try {
if (obj instanceof dMaterial) {
return new Element(getPlayerEntity().getStatistic(statistic, ((dMaterial) obj).getMaterial())).getAttribute(attribute.fulfill(2));
} else if (obj instanceof dEntity) {
return new Element(getPlayerEntity().getStatistic(statistic, ((dEntity) obj).getBukkitEntityType())).getAttribute(attribute.fulfill(2));
} else {
return null;
}
} catch (Exception e) {
dB.echoError("Invalid statistic: " + statistic + " for this player!");
return null;
}
}
try {
return new Element(getPlayerEntity().getStatistic(statistic)).getAttribute(attribute.fulfill(1));
} catch (Exception e) {
dB.echoError("Invalid statistic: " + statistic + " for this player!");
return null;
}
}
// -->
if (attribute.startsWith("time_asleep")) {
return new Duration(getPlayerEntity().getSleepTicks() / 20).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("time")) {
return new Element(getPlayerEntity().getPlayerTime()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("walk_speed")) {
return new Element(getPlayerEntity().getWalkSpeed()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("weather")) {
if (getPlayerEntity().getPlayerWeather() != null) {
return new Element(getPlayerEntity().getPlayerWeather().name()).getAttribute(attribute.fulfill(1));
} else {
return null;
}
}
// -->
if (attribute.startsWith("xp.level")) {
return new Element(getPlayerEntity().getLevel()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("xp.to_next_level")) {
return new Element(getPlayerEntity().getExpToLevel()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("xp.total")) {
return new Element(getPlayerEntity().getTotalExperience()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("xp")) {
return new Element(getPlayerEntity().getExp() * 100).getAttribute(attribute.fulfill(1));
}
if (Depends.chat != null) {
// -->
if (attribute.startsWith("chat_prefix")) {
String prefix = Depends.chat.getPlayerPrefix(getWorld().getName(), getOfflinePlayer());
if (prefix == null) {
return null;
}
return new Element(prefix).getAttribute(attribute.fulfill(1));
} else // -->
if (attribute.startsWith("chat_suffix")) {
String suffix = Depends.chat.getPlayerSuffix(getWorld().getName(), getOfflinePlayer());
if (suffix == null) {
return null;
}
return new Element(suffix).getAttribute(attribute.fulfill(1));
}
}
// Iterate through this object's properties' attributes
for (Property property : PropertyParser.getProperties(this)) {
String returned = property.getAttribute(attribute);
if (returned != null) {
return returned;
}
}
return new dEntity(getPlayerEntity()).getAttribute(attribute);
}
use of net.aufdemrand.denizen.flags.FlagManager in project Denizen-For-Bukkit by DenizenScript.
the class Denizen method getFlag.
public FlagManager.Flag getFlag(String string) {
if (string.startsWith("fl")) {
FlagManager flag_manager = DenizenAPI.getCurrentInstance().flagManager();
if (string.indexOf('[') == 2) {
int cb = string.indexOf(']');
if (cb > 4) {
String owner = string.substring(3, cb);
String flag = string.substring(cb + 2);
if (dPlayer.matches(owner)) {
dPlayer player = dPlayer.valueOf(owner);
if (FlagManager.playerHasFlag(player, flag)) {
return flag_manager.getPlayerFlag(player, flag);
} else {
dB.echoError("Player '" + owner + "' flag '" + flag + "' not found.");
}
} else if (Depends.citizens != null && dNPC.matches(owner)) {
dNPC npc = dNPC.valueOf(owner);
if (FlagManager.npcHasFlag(npc, flag)) {
return flag_manager.getNPCFlag(npc.getId(), flag);
} else {
dB.echoError("NPC '" + owner + "' flag '" + flag + "' not found.");
}
} else if (dEntity.matches(owner)) {
dEntity entity = dEntity.valueOf(owner);
if (FlagManager.entityHasFlag(entity, flag)) {
return flag_manager.getEntityFlag(entity, flag);
} else {
dB.echoError("Entity '" + owner + "' flag '" + flag + "' not found.");
}
}
} else {
dB.echoError("Invalid dFlag format: " + string);
}
} else if (string.indexOf('@') == 2) {
String flag = string.substring(3);
if (FlagManager.serverHasFlag(flag)) {
return flag_manager.getGlobalFlag(flag);
} else {
dB.echoError("Global flag '" + flag + "' not found.");
}
}
}
return null;
}
Aggregations