Skip to content

Commit

Permalink
Add Chat Prefix and Chat Suffix tags and mechanisms.
Browse files Browse the repository at this point in the history
Tested, confirmed works with PEX.
Update some Meta.
  • Loading branch information
Fortifier42 committed Feb 12, 2016
1 parent d8fc599 commit 1644a27
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -20,6 +20,7 @@
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.milkbowl.vault.chat.Chat;
import net.minecraft.server.v1_8_R3.PacketPlayOutGameStateChange;
import org.bukkit.*;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -806,6 +807,7 @@ public String getAttribute(Attribute attribute) {
// @description
// Returns the amount of money the player has with the registered Economy system.
// May work offline depending on economy plugin.
// @mechanism dPlayer.money
// -->

if (attribute.startsWith("money")) {
Expand Down Expand Up @@ -1051,6 +1053,7 @@ else if (attribute.startsWith("uuid") && !isOnline())
// Returns the location of the player's bed spawn location, null if
// it doesn't exist.
// Works with offline players.
// @mechanism dPlayer.bed_spawn_location
// -->
if (attribute.startsWith("bed_spawn")) {
if (getOfflinePlayer().getBedSpawnLocation() == null) {
Expand Down Expand Up @@ -1147,6 +1150,7 @@ else if (attribute.startsWith("uuid") && !isOnline())
// @returns Element(Boolean)
// @description
// Returns whether the player is banned.
// @mechanism dPlayer.is_banned
// -->
if (attribute.startsWith("is_banned")) {
BanEntry ban = Bukkit.getBanList(BanList.Type.NAME).getBanEntry(getName());
Expand Down Expand Up @@ -1176,6 +1180,7 @@ else if (ban.getExpiration() == null) {
// @description
// Returns whether the player is a full server operator.
// Works with offline players.
// @mechanism dPlayer.is_op
// -->
if (attribute.startsWith("is_op")) {
return new Element(getOfflinePlayer().isOp())
Expand All @@ -1188,6 +1193,7 @@ else if (ban.getExpiration() == null) {
// @description
// Returns whether the player is whitelisted.
// Works with offline players.
// @mechanism dPlayer.is_whitelisted
// -->
if (attribute.startsWith("is_whitelisted")) {
return new Element(getOfflinePlayer().isWhitelisted())
Expand Down Expand Up @@ -2036,6 +2042,41 @@ else if (obj instanceof dEntity) {
.getAttribute(attribute.fulfill(1));
}

if (Depends.chat != null) {

// <--[tag]
// @attribute <p@player.chat_prefix>
// @returns Element
// @description
// Returns the player's chat prefix.
// NOTE: May work with offline players.
// @mechanism dPlayer.chat_prefix
// -->
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));
}

// <--[tag]
// @attribute <p@player.chat_suffix>
// @returns Element
// @description
// Returns the player's chat suffix.
// NOTE: May work with offline players.
// @mechanism dPlayer.chat_suffix
// -->
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);
Expand Down Expand Up @@ -2119,7 +2160,7 @@ public void adjust(Mechanism mechanism) {
// @tags
// None
// -->
// TODO: Player achievement/statistics tags.
// TODO: Player achievement tags.
if (mechanism.matches("award_achievement") && mechanism.requireEnum(false, Achievement.values())) {
getPlayerEntity().awardAchievement(Achievement.valueOf(value.asString().toUpperCase()));
}
Expand Down Expand Up @@ -2850,6 +2891,8 @@ else if (split.length > 1) {
// @input Element(Boolean)
// @description
// Changes whether the player is whitelisted or not.
// @tags
// <p@player.is_whitelisted>
// -->
if (mechanism.matches("is_whitelisted") && mechanism.requireBoolean()) {
getPlayerEntity().setWhitelisted(mechanism.getValue().asBoolean());
Expand All @@ -2861,6 +2904,8 @@ else if (split.length > 1) {
// @input Element(Boolean)
// @description
// Changes whether the player is a server operator or not.
// @tags
// <p@player.is_op>
// -->
if (mechanism.matches("is_op") && mechanism.requireBoolean()) {
getPlayerEntity().setOp(mechanism.getValue().asBoolean());
Expand All @@ -2872,6 +2917,11 @@ else if (split.length > 1) {
// @input Element(Boolean)
// @description
// Set whether the player is banned or not.
// @tags
// <p@player.is_banned>
// <p@player.ban_info.expiration>
// <p@player.ban_info.reason>
// <p@player.ban_info.created>
// -->
if (mechanism.matches("is_banned") && mechanism.requireBoolean()) {
getOfflinePlayer().setBanned(mechanism.getValue().asBoolean());
Expand All @@ -2898,6 +2948,34 @@ else if (bal > goal) {
}
}

if (Depends.chat != null) {
// <--[mechanism]
// @object dPlayer
// @name chat_prefix
// @input Element
// @description
// Set the player's chat prefix.
// @tags
// <p@player.chat_prefix>
// -->
if (mechanism.matches("chat_prefix")) {
Depends.chat.setPlayerPrefix(getPlayerEntity(), value.asString());
}

// <--[mechanism]
// @object dPlayer
// @name chat_suffix
// @input Element
// @description
// Set the player's chat suffix.
// @tags
// <p@player.chat_suffix>
// -->
if (mechanism.matches("chat_suffix")) {
Depends.chat.setPlayerSuffix(getPlayerEntity(), value.asString());
}
}

// Iterate through this object's properties' mechanisms
for (Property property : PropertyParser.getProperties(this)) {
property.adjust(mechanism);
Expand Down

0 comments on commit 1644a27

Please sign in to comment.