mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-06 12:33:03 +00:00
Use playerNeverOnServer message where appropriate (#3489)
### Use `playerNeverOnServer` message where it should be used:
### 309e1c470d
`playerNeverOnServer=\u00a74Player\u00a7c {0} \u00a74was never on this server.` is currently used in the **Commandmail** class at [Line 61](https://github.com/EssentialsX/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/commands/Commandmail.java#L61), [Line 116](https://github.com/EssentialsX/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/commands/Commandmail.java#L116) and [Line 129](https://github.com/EssentialsX/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/commands/Commandmail.java#L129) however is **not called** as PlayerNotFoundException is thrown by `#getPlayer` breaking current execution (below).
```
Commandmail#run() throws Exception {
...
User u = getPlayer(server, args[1], true, true); // throws PlayerNotFoundException
if (u == null) {
throw new Exception(tl("playerNeverOnServer", args[1]));
}
...
}
```
Before changes:

After changes:

--------------------------
**Commandseen** currently throws the default PlayerNotFoundException `playerNotFound` message for players that have not logged on to the server where it would be more appropriate to use the `playerNeverOnServer` message.
```
Commandseen#run throws Exception {
...
AsyncRunnable#run() {
User userFromBukkit = ess.getUserMap().getUserFromBukkit(args[0]); <-- ***
try {
if (userFromBukkit != null) { <--- ***
showUserSeen(userFromBukkit);
} else {
showUserSeen(getPlayer(server, sender, args, 0)); <--- ***
}
} catch (Exception e) {
ess.showError(sender, e, commandLabel);
}
}
private void showUserSeen(User user) throws Exception {
if (user == null) { <--- ***
throw new PlayerNotFoundException();
}
showSeenMessage(server, sender, user, showBan, showIp, showLocation);
}
...
}
```
**`<-- ***`:**
`usersFromBukkit` null check is performed before `#showUserSeen` so there is no need for another null check.
`EssentialsCommand#getPlayer` throws **NotEnoughArguementsException** or **PlayerNotFoundException** after [arg checks](https://github.com/EssentialsX/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java#L88) and [player checks](https://github.com/EssentialsX/Essentials/blob/2.x/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java#L103). https://github.com/EssentialsX/Essentials/pull/3489#issuecomment-657138524
Before changes:

After changes:

----------------
### 725128e
Catch more specfic exception `PlayerNotFoundException`.
Before changes:

After changes:

This commit is contained in:
parent
97e3f32d7f
commit
f9de6763d3
3 changed files with 20 additions and 12 deletions
|
@ -69,7 +69,11 @@ public class Commandseen extends EssentialsCommand {
|
|||
if (userFromBukkit != null) {
|
||||
showUserSeen(userFromBukkit);
|
||||
} else {
|
||||
showUserSeen(getPlayer(server, sender, args, 0));
|
||||
try {
|
||||
showUserSeen(getPlayer(server, sender, args, 0));
|
||||
} catch (PlayerNotFoundException e) {
|
||||
throw new Exception(tl("playerNeverOnServer", args[0]));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ess.showError(sender, e, commandLabel);
|
||||
|
@ -77,9 +81,6 @@ public class Commandseen extends EssentialsCommand {
|
|||
}
|
||||
|
||||
private void showUserSeen(User user) throws Exception {
|
||||
if (user == null) {
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
showSeenMessage(server, sender, user, showBan, showIp, showLocation);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue