forked from LogBlock/LogBlock
Cleanup Actor.equals() and .hashCode() + some formatting
This commit is contained in:
@@ -19,21 +19,16 @@ public class Actor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 5;
|
return this.UUID != null ? this.UUID.hashCode() : 0;
|
||||||
hash = 79 * hash + (this.UUID != null ? this.UUID.hashCode() : 0);
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj == null) {
|
if (obj == null || getClass() != obj.getClass()) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getClass() != obj.getClass()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Actor other = (Actor) obj;
|
final Actor other = (Actor) obj;
|
||||||
return ((this.UUID == null && other.UUID == null) || this.UUID.equals(other.UUID));
|
return this.UUID == null ? other.UUID == null : this.UUID.equals(other.UUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
@@ -111,20 +106,21 @@ public class Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Generate an Actor object from a String name, trying to guess if it's an online player
|
/**
|
||||||
* and if so, setting the UUID accordingly. This only checks against currently online
|
* Generate an Actor object from a String name, trying to guess if it's an online player
|
||||||
* players and is a "best effort" attempt for use with the pre-UUID API
|
* and if so, setting the UUID accordingly. This only checks against currently online
|
||||||
* <p>
|
* players and is a "best effort" attempt for use with the pre-UUID API
|
||||||
* If you know something is an entity (player or otherwise) use the {@link #actorFromEntity(org.bukkit.entity.Entity) }
|
* <p>
|
||||||
* or {@link #actorFromEntity(org.bukkit.entity.EntityType) } methods
|
* If you know something is an entity (player or otherwise) use the {@link #actorFromEntity(org.bukkit.entity.Entity) }
|
||||||
* <p>
|
* or {@link #actorFromEntity(org.bukkit.entity.EntityType) } methods
|
||||||
* If you know something is a server effect (like gravity) use {@link #Actor(java.lang.String)}
|
* <p>
|
||||||
* @deprecated Only use this if you have a String of unknown origin
|
* If you know something is a server effect (like gravity) use {@link #Actor(java.lang.String)}
|
||||||
*
|
* @deprecated Only use this if you have a String of unknown origin
|
||||||
* @param actorName String of unknown origin
|
*
|
||||||
* @return
|
* @param actorName String of unknown origin
|
||||||
*/
|
* @return
|
||||||
|
*/
|
||||||
public static Actor actorFromString(String actorName) {
|
public static Actor actorFromString(String actorName) {
|
||||||
Collection<? extends Player> players = Bukkit.getServer().getOnlinePlayers();
|
Collection<? extends Player> players = Bukkit.getServer().getOnlinePlayers();
|
||||||
for (Player p : players) {
|
for (Player p : players) {
|
||||||
@@ -132,8 +128,8 @@ public class Actor {
|
|||||||
return actorFromEntity(p);
|
return actorFromEntity(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// No player found online with that name, assuming non-player entity/effect
|
// No player found online with that name, assuming non-player entity/effect
|
||||||
return new Actor(actorName);
|
return new Actor(actorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidUUID(String uuid) {
|
public static boolean isValidUUID(String uuid) {
|
||||||
|
Reference in New Issue
Block a user