Skip to content

Commit

Permalink
Cleanup Actor.equals() and .hashCode() + some formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed Sep 13, 2018
1 parent d214b64 commit 2bb9e09
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/main/java/de/diddiz/LogBlock/Actor.java
Expand Up @@ -19,21 +19,16 @@ public class Actor {

@Override
public int hashCode() {
int hash = 5;
hash = 79 * hash + (this.UUID != null ? this.UUID.hashCode() : 0);
return hash;
return this.UUID != null ? this.UUID.hashCode() : 0;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
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;
Expand Down Expand Up @@ -111,29 +106,30 @@ public static Actor actorFromProjectileSource(ProjectileSource psource) {
}

}
/**
* 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
* players and is a "best effort" attempt for use with the pre-UUID API
* <p>
* If you know something is an entity (player or otherwise) use the {@link #actorFromEntity(org.bukkit.entity.Entity) }
* or {@link #actorFromEntity(org.bukkit.entity.EntityType) } methods
* <p>
* 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
*/

/**
* 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
* players and is a "best effort" attempt for use with the pre-UUID API
* <p>
* If you know something is an entity (player or otherwise) use the {@link #actorFromEntity(org.bukkit.entity.Entity) }
* or {@link #actorFromEntity(org.bukkit.entity.EntityType) } methods
* <p>
* 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
*/
public static Actor actorFromString(String actorName) {
Collection<? extends Player> players = Bukkit.getServer().getOnlinePlayers();
for (Player p : players) {
if (p.getName().equalsIgnoreCase(actorName)) {
return actorFromEntity(p);
}
}
// No player found online with that name, assuming non-player entity/effect
return new Actor(actorName);
// No player found online with that name, assuming non-player entity/effect
return new Actor(actorName);
}

public static boolean isValidUUID(String uuid) {
Expand Down

0 comments on commit 2bb9e09

Please sign in to comment.