mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-03 11:06:08 +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
|
@ -56,8 +56,10 @@ public class Commandmail extends EssentialsCommand {
|
|||
throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff));
|
||||
}
|
||||
|
||||
User u = getPlayer(server, args[1], true, true);
|
||||
if (u == null) {
|
||||
User u;
|
||||
try {
|
||||
u = getPlayer(server, args[1], true, true);
|
||||
} catch (PlayerNotFoundException e) {
|
||||
throw new Exception(tl("playerNeverOnServer", args[1]));
|
||||
}
|
||||
|
||||
|
@ -111,8 +113,10 @@ public class Commandmail extends EssentialsCommand {
|
|||
} else if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) {
|
||||
throw new Exception(tl("onlyPlayers", commandLabel + " clear"));
|
||||
} else if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) {
|
||||
User u = getPlayer(server, args[1], true, true);
|
||||
if (u == null) {
|
||||
User u;
|
||||
try {
|
||||
u = getPlayer(server, args[1], true, true);
|
||||
} catch (PlayerNotFoundException e) {
|
||||
throw new Exception(tl("playerNeverOnServer", args[1]));
|
||||
}
|
||||
u.addMail(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 2))));
|
||||
|
@ -124,8 +128,10 @@ public class Commandmail extends EssentialsCommand {
|
|||
return;
|
||||
} else if (args.length >= 2) {
|
||||
//allow sending from console without "send" argument, since it's the only thing the console can do
|
||||
User u = getPlayer(server, args[0], true, true);
|
||||
if (u == null) {
|
||||
User u;
|
||||
try {
|
||||
u = getPlayer(server, args[0], true, true);
|
||||
} catch (PlayerNotFoundException e) {
|
||||
throw new Exception(tl("playerNeverOnServer", args[0]));
|
||||
}
|
||||
u.addMail(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 1))));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,16 +22,17 @@ public class Commandunban extends EssentialsCommand {
|
|||
if (args.length < 1) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
String name;
|
||||
try {
|
||||
final User user = getPlayer(server, args, 0, true, true);
|
||||
name = user.getName();
|
||||
ess.getServer().getBanList(BanList.Type.NAME).pardon(name);
|
||||
} catch (NoSuchFieldException e) {
|
||||
} catch (PlayerNotFoundException e) {
|
||||
final OfflinePlayer player = server.getOfflinePlayer(args[0]);
|
||||
name = player.getName();
|
||||
if (!player.isBanned()) {
|
||||
throw new Exception(tl("playerNotFound"), e);
|
||||
throw new Exception(tl("playerNeverOnServer", args[0]));
|
||||
}
|
||||
ess.getServer().getBanList(BanList.Type.NAME).pardon(name);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue