Skip to content

Commit 4ea539c

Browse files
authored
Merge pull request #34 from retromcorg/FixGetPlayer
Fix issue where offline players were prioritized in getPlayer()
2 parents fa4ad5e + 1d9c4e0 commit 4ea539c

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.earth2me.essentials.commands;
22

3-
import com.earth2me.essentials.*;
3+
import java.util.List;
4+
import java.util.logging.Logger;
5+
46
import org.bukkit.Server;
57
import org.bukkit.command.Command;
68
import org.bukkit.command.CommandSender;
79
import org.bukkit.entity.Player;
810

9-
import java.util.List;
10-
import java.util.logging.Logger;
11+
import com.earth2me.essentials.IEssentials;
12+
import com.earth2me.essentials.OfflinePlayer;
13+
import com.earth2me.essentials.Trade;
14+
import com.earth2me.essentials.User;
15+
import com.earth2me.essentials.Util;
1116

1217

1318
public abstract class EssentialsCommand implements IEssentialsCommand {
@@ -46,13 +51,19 @@ protected User getPlayer(final Server server, final String[] args, final int pos
4651
if (args.length <= pos) {
4752
throw new NotEnoughArgumentsException();
4853
}
54+
4955
final User user = ess.getUser(args[pos]);
50-
if (user != null) {
51-
if (!getOffline && (user.getBase() instanceof OfflinePlayer || user.isHidden())) {
52-
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
53-
}
54-
return user;
55-
}
56+
if (
57+
user != null && ( // if the user exists, and either
58+
getOffline || // 1) we allow offline players
59+
!( // 2) the player is not offline/hidden
60+
user.getBase() instanceof OfflinePlayer ||
61+
user.isHidden()
62+
)
63+
)
64+
) return user;
65+
66+
// try to find a user that matches the partial string
5667
final List<Player> matches = server.matchPlayer(args[pos]);
5768

5869
if (!matches.isEmpty()) {

0 commit comments

Comments
 (0)