DisplayName should not be set. Only gotten. Possibly from a watcher perspective.

This commit is contained in:
Olof Larsson 2014-06-18 23:36:58 +02:00
parent 951367c586
commit 944aaf6853
5 changed files with 19 additions and 39 deletions

View File

@ -3,5 +3,5 @@ package com.massivecraft.massivecore.mixin;
public interface DisplayNameMixin
{
public String getDisplayName(Object senderObject);
public void setDisplayName(Object senderObject, String displayName);
public String getDisplayName(Object senderObject, Object watcherObject);
}

View File

@ -2,5 +2,14 @@ package com.massivecraft.massivecore.mixin;
public abstract class DisplayNameMixinAbstract implements DisplayNameMixin
{
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getDisplayName(Object senderObject)
{
return this.getDisplayName(senderObject, null);
}
}

View File

@ -1,8 +1,5 @@
package com.massivecraft.massivecore.mixin;
import java.util.Map;
import java.util.TreeMap;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -19,24 +16,18 @@ public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
private static DisplayNameMixinDefault i = new DisplayNameMixinDefault();
public static DisplayNameMixinDefault get() { return i; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected Map<String, String> idToDisplayName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getDisplayName(Object senderObject)
public String getDisplayName(Object senderObject, Object watcherObject)
{
String senderId = IdUtil.getId(senderObject);
if (senderId == null) return null;
// Our Map
String ret = this.idToDisplayName.get(senderId);
// Ret
String ret = null;
// Bukkit
if (ret == null)
@ -69,24 +60,4 @@ public class DisplayNameMixinDefault extends DisplayNameMixinAbstract
return ret;
}
@Override
public void setDisplayName(Object senderObject, String displayName)
{
String senderId = IdUtil.getId(senderObject);
if (senderId == null) return;
if (displayName == null)
{
this.idToDisplayName.remove(senderId);
}
else
{
this.idToDisplayName.put(senderId, displayName);
}
Player player = IdUtil.getPlayer(senderObject);
if (player == null) return;
player.setDisplayName(this.getDisplayName(senderObject));
}
}

View File

@ -124,9 +124,9 @@ public class Mixin
return getDisplayNameMixin().getDisplayName(senderObject);
}
public static void setDisplayName(Object senderObject, String displayName)
public static String getDisplayName(Object senderObject, Object watcherObject)
{
getDisplayNameMixin().setDisplayName(senderObject, displayName);
return getDisplayNameMixin().getDisplayName(senderObject, watcherObject);
}
// -------------------------------------------- //

View File

@ -100,9 +100,9 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
return Mixin.getDisplayName(this.getId());
}
public void setDisplayName(String displayName)
public String getDisplayName(Object watcherObject)
{
Mixin.setDisplayName(this.getId(), displayName);
return Mixin.getDisplayName(this.getId(), watcherObject);
}
// CONVENIENCE SEND MESSAGE