Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
fix uuid logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenmai committed Jun 15, 2018
1 parent c8be326 commit a697efb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
Expand Up @@ -314,13 +314,18 @@ public String getName() {
// -->
handlers.put("match_player", (dat, obj) -> {
String matchInput = CoreUtilities.toLowerCase( dat.getNextModifier().toString());
UUID uuid = CoreUtilities.tryGetUUID(matchInput);
if (uuid != null) {
Optional<Player> opt = Sponge.getServer().getPlayer(uuid);
if (!opt.isPresent()) {
return NullTag.NULL;
try {
UUID uuid = CoreUtilities.tryGetUUID(matchInput);
if (uuid != null) {
Optional<Player> opt = Sponge.getServer().getPlayer(uuid);
if (!opt.isPresent()) {
return NullTag.NULL;
}
return new PlayerTag(opt.get());
}
return new PlayerTag(opt.get());
}
catch (Exception e) {
// Ignore.
}
Collection<Player> players = Sponge.getServer().getOnlinePlayers();
for (Player player : players) {
Expand Down
Expand Up @@ -1019,19 +1019,25 @@ else if (ent instanceof Ageable) {
}

public static EntityTag getFor(Action<String> error, String text) {
UUID uuid = CoreUtilities.tryGetUUID(text);
if (uuid == null) {
error.run("Invalid EntityTag UUID input (input is not a valid UUID)!");
try {
UUID uuid = CoreUtilities.tryGetUUID(text);
if (uuid == null) {
error.run("Invalid EntityTag UUID input (input is not a valid UUID)!");
return null;
}
for (World world : Sponge.getServer().getWorlds()) {
Optional<Entity> e = world.getEntity(uuid);
if (e.isPresent()) {
return new EntityTag(e.get());
}
}
error.run("Invalid EntityTag UUID input (that UUID cannot be matched to a real entity)!");
return null;
}
for (World world : Sponge.getServer().getWorlds()) {
Optional<Entity> e = world.getEntity(uuid);
if (e.isPresent()) {
return new EntityTag(e.get());
}
catch (Exception e) {
error.run("Invalid EntityTag UUID input (input is not a valid UUID)!");
return null;
}
error.run("Invalid EntityTag UUID input (that UUID cannot be matched to a real entity)!");
return null;
}

public static EntityTag getFor(Action<String> error, AbstractTagObject ato) {
Expand Down
Expand Up @@ -411,14 +411,19 @@ else if (map.getInternal().containsKey("item")) {
}

public static PlayerTag getFor(Action<String> error, String text) {
UUID uuid = CoreUtilities.tryGetUUID(text);
if (uuid != null) {
Optional<Player> oplayer = Sponge.getServer().getPlayer(uuid);
if (!oplayer.isPresent()) {
error.run("Invalid PlayerTag UUID input!");
return null;
try {
UUID uuid = CoreUtilities.tryGetUUID(text);
if (uuid != null) {
Optional<Player> oplayer = Sponge.getServer().getPlayer(uuid);
if (!oplayer.isPresent()) {
error.run("Invalid PlayerTag UUID input!");
return null;
}
return new PlayerTag(oplayer.get());
}
return new PlayerTag(oplayer.get());
}
catch (Exception e) {
// Ignore.
}
Optional<Player> oplayer = Sponge.getServer().getPlayer(text);
if (!oplayer.isPresent()) {
Expand Down

0 comments on commit a697efb

Please sign in to comment.