More null debug

This commit is contained in:
Magnus Ulf 2019-02-11 17:26:30 +01:00
parent 0b7fe8d2c6
commit 4df6669131
4 changed files with 19 additions and 6 deletions

View File

@ -24,16 +24,19 @@ public class MixinPlayed extends Mixin
public boolean isOnline(Object senderObject) public boolean isOnline(Object senderObject)
{ {
if (senderObject == null) throw new NullPointerException("senderObject");
return IdUtil.isOnline(senderObject); return IdUtil.isOnline(senderObject);
} }
public boolean isOffline(Object senderObject) public boolean isOffline(Object senderObject)
{ {
if (senderObject == null) throw new NullPointerException("senderObject");
return ! this.isOnline(senderObject); return ! this.isOnline(senderObject);
} }
public Long getFirstPlayed(Object senderObject) public Long getFirstPlayed(Object senderObject)
{ {
if (senderObject == null) throw new NullPointerException("senderObject");
if (MUtil.isNpc(senderObject)) return null; if (MUtil.isNpc(senderObject)) return null;
UUID uuid = IdUtil.getUuid(senderObject); UUID uuid = IdUtil.getUuid(senderObject);
@ -49,6 +52,7 @@ public class MixinPlayed extends Mixin
public Long getLastPlayed(Object senderObject) public Long getLastPlayed(Object senderObject)
{ {
if (senderObject == null) throw new NullPointerException("senderObject");
//if (this.isOnline(senderObject)) return System.currentTimeMillis(); //if (this.isOnline(senderObject)) return System.currentTimeMillis();
// We do in fact NOT want this commented out behavior // We do in fact NOT want this commented out behavior
// It's important we can check the previous played time on join! // It's important we can check the previous played time on join!
@ -68,12 +72,14 @@ public class MixinPlayed extends Mixin
public boolean hasPlayedBefore(Object senderObject) public boolean hasPlayedBefore(Object senderObject)
{ {
if (senderObject == null) throw new NullPointerException("senderObject");
Long firstPlayed = this.getFirstPlayed(senderObject); Long firstPlayed = this.getFirstPlayed(senderObject);
return firstPlayed != null && firstPlayed != 0; return firstPlayed != null && firstPlayed != 0;
} }
public String getIp(Object senderObject) public String getIp(Object senderObject)
{ {
if (senderObject == null) throw new NullPointerException("senderObject");
CommandSender sender = IdUtil.getSender(senderObject); CommandSender sender = IdUtil.getSender(senderObject);
if (MUtil.isntPlayer(senderObject)) return null; if (MUtil.isntPlayer(senderObject)) return null;
return MUtil.getIp(sender); return MUtil.getIp(sender);

View File

@ -39,6 +39,12 @@ public class EntityInternal<E extends EntityInternal<E>> implements Identified
{ {
return this.id; return this.id;
} }
public String getIdOrThrow()
{
String id = this.getId();
if (id == null) throw new NullPointerException("id");
return id;
}
// -------------------------------------------- // // -------------------------------------------- //
// ATTACH AND DETACH // ATTACH AND DETACH

View File

@ -190,32 +190,32 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
public boolean isOnline() public boolean isOnline()
{ {
return MixinPlayed.get().isOnline(this.getId()); return MixinPlayed.get().isOnline(this.getIdOrThrow());
} }
public boolean isOffline() public boolean isOffline()
{ {
return MixinPlayed.get().isOffline(this.getId()); return MixinPlayed.get().isOffline(this.getIdOrThrow());
} }
public Long getLastPlayed() public Long getLastPlayed()
{ {
return MixinPlayed.get().getLastPlayed(this.getId()); return MixinPlayed.get().getLastPlayed(this.getIdOrThrow());
} }
public Long getFirstPlayed() public Long getFirstPlayed()
{ {
return MixinPlayed.get().getFirstPlayed(this.getId()); return MixinPlayed.get().getFirstPlayed(this.getIdOrThrow());
} }
public boolean hasPlayedBefore() public boolean hasPlayedBefore()
{ {
return MixinPlayed.get().hasPlayedBefore(this.getId()); return MixinPlayed.get().hasPlayedBefore(this.getIdOrThrow());
} }
public String getIp() public String getIp()
{ {
return MixinPlayed.get().getIp(this.getId()); return MixinPlayed.get().getIp(this.getIdOrThrow());
} }
public boolean isVisible() public boolean isVisible()

View File

@ -800,6 +800,7 @@ public class IdUtil implements Listener, Runnable
public static boolean isOnline(Object senderObject) public static boolean isOnline(Object senderObject)
{ {
if (senderObject == null) throw new NullPointerException("senderObject");
// Fix the id ... // Fix the id ...
String id = getId(senderObject); String id = getId(senderObject);
if (id == null) return false; if (id == null) return false;