Skip to content

Commit

Permalink
Add ability for CommandParserArgs to only return online players - sho…
Browse files Browse the repository at this point in the history
…uld fix #1679
  • Loading branch information
luacs1998 committed Aug 4, 2015
1 parent 281138a commit 06e1aba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/forgeessentials/api/UserIdent.java
Expand Up @@ -329,6 +329,11 @@ public GameProfile getGameProfile()
return gameProfile;
}

public boolean isOnline()
{
return MinecraftServer.getServer().getConfigurationManager().playerEntityList.contains(player);
}

/* ------------------------------------------------------------ */

public static UserIdent fromString(String string)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/forgeessentials/teleport/CommandTPA.java
Expand Up @@ -68,7 +68,7 @@ public void parse(final CommandParserArgs arguments)
return;
}

final UserIdent player = arguments.parsePlayer(true);
final UserIdent player = arguments.parsePlayer(true, true);
if (arguments.isEmpty())
{
if (arguments.isTabCompletion)
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/forgeessentials/util/CommandParserArgs.java
Expand Up @@ -111,10 +111,16 @@ public boolean hasPlayer()
@Deprecated
public UserIdent parsePlayer()
{
return parsePlayer(true);
return parsePlayer(true, false);
}

@Deprecated
public UserIdent parsePlayer(boolean mustExist)
{
return parsePlayer(mustExist, false);
}

public UserIdent parsePlayer(boolean mustExist, boolean mustBeOnline)
{
if (isTabCompletion && size() == 1)
{
Expand Down Expand Up @@ -142,6 +148,8 @@ public UserIdent parsePlayer(boolean mustExist)
UserIdent ident = UserIdent.get(name, sender, mustExist);
if (mustExist && (ident == null || !ident.hasUuid()))
throw new TranslatedCommandException("Player %s not found", name);
else if (mustBeOnline && !ident.isOnline())
throw new TranslatedCommandException("Player %s is not online", name);
return ident;
}
}
Expand Down

0 comments on commit 06e1aba

Please sign in to comment.