X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FSoneAccessor.java;h=d0a287f34d8b249e662816b4c57ce32fa655df5a;hb=916b45a47c8dce3c6837c12d4facb6eb572bb987;hp=bfb289ebf176c9acf372e383367723aaf4483f3e;hpb=f0387ede3f3140032cb4e2b9fff9622c153a4a37;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java
index bfb289e..d0a287f 100644
--- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java
+++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java
@@ -29,6 +29,13 @@ import net.pterodactylus.util.template.ReflectionAccessor;
*
niceName
* Will show a combination of first name, middle name, and last name, if
* available, otherwise the username of the Sone is returned.
+ * friend
+ * Will return {@code true} if the sone in question is a friend of the
+ * currently logged in Sone (as determined by accessing the âcurrentSoneâ
+ * variable of the given {@link DataProvider}).
+ * current
+ * Will return {@code true} if the sone in question is the currently logged
+ * in Sone.
*
*
* @author David âBombeâ Roden
@@ -42,19 +49,45 @@ public class SoneAccessor extends ReflectionAccessor {
public Object get(DataProvider dataProvider, Object object, String member) {
Sone sone = (Sone) object;
if (member.equals("niceName")) {
- Profile profile = sone.getProfile();
- String firstName = profile.getFirstName();
- String middleName = profile.getMiddleName();
- String lastName = profile.getLastName();
- if (firstName == null) {
- if (lastName == null) {
- return sone.getName();
- }
- return lastName;
- }
- return firstName + ((middleName != null) ? " " + middleName : "") + ((lastName != null) ? " " + lastName : "");
+ return getNiceName(sone);
+ } else if (member.equals("friend")) {
+ Sone currentSone = (Sone) dataProvider.getData("currentSone");
+ return currentSone.hasFriend(sone) ? true : null;
+ } else if (member.equals("current")) {
+ Sone currentSone = (Sone) dataProvider.getData("currentSone");
+ return currentSone.equals(sone);
+ } else if (member.equals("blocked")) {
+ Sone currentSone = (Sone) dataProvider.getData("currentSone");
+ return currentSone.isSoneBlocked(sone.getId());
+ } else if (member.equals("modified")) {
+ return sone.getModificationCounter() > 0;
}
return super.get(dataProvider, object, member);
}
+ //
+ // STATIC METHODS
+ //
+
+ /**
+ * Returns the nice name of the given Sone.
+ *
+ * @param sone
+ * The Sone to get the nice name for
+ * @return The nice name of the Sone
+ */
+ public static String getNiceName(Sone sone) {
+ Profile profile = sone.getProfile();
+ String firstName = profile.getFirstName();
+ String middleName = profile.getMiddleName();
+ String lastName = profile.getLastName();
+ if (firstName == null) {
+ if (lastName == null) {
+ return sone.getName();
+ }
+ return lastName;
+ }
+ return firstName + ((middleName != null) ? " " + middleName : "") + ((lastName != null) ? " " + lastName : "");
+ }
+
}