mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01: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: ![bm](https://user-images.githubusercontent.com/24858857/87236993-6b679180-c3e8-11ea-83a7-002194f5c467.png) After changes: ![mailafter](https://user-images.githubusercontent.com/24858857/87237060-3576dd00-c3e9-11ea-8020-d5a80a958ca0.png) -------------------------- **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: ![sb](https://user-images.githubusercontent.com/24858857/87237038-e9c43380-c3e8-11ea-8294-8f91e8b6f25d.png) After changes: ![seenafter](https://user-images.githubusercontent.com/24858857/87237067-53444200-c3e9-11ea-92c5-1784b4dcd739.png) ---------------- ###725128e
Catch more specfic exception `PlayerNotFoundException`. Before changes: ![banbefore](https://user-images.githubusercontent.com/24858857/87237021-c1d4d000-c3e8-11ea-99e4-eb97b5a5ba6d.png) After changes: ![afterunban](https://user-images.githubusercontent.com/24858857/87237081-8d154880-c3e9-11ea-9d35-a25b8c105969.png)
This commit is contained in:
parent
97e3f32d7f
commit
f9de6763d3
@ -56,8 +56,10 @@ public class Commandmail extends EssentialsCommand {
|
|||||||
throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff));
|
throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff));
|
||||||
}
|
}
|
||||||
|
|
||||||
User u = getPlayer(server, args[1], true, true);
|
User u;
|
||||||
if (u == null) {
|
try {
|
||||||
|
u = getPlayer(server, args[1], true, true);
|
||||||
|
} catch (PlayerNotFoundException e) {
|
||||||
throw new Exception(tl("playerNeverOnServer", args[1]));
|
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])) {
|
} else if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) {
|
||||||
throw new Exception(tl("onlyPlayers", commandLabel + " clear"));
|
throw new Exception(tl("onlyPlayers", commandLabel + " clear"));
|
||||||
} else if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) {
|
} else if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) {
|
||||||
User u = getPlayer(server, args[1], true, true);
|
User u;
|
||||||
if (u == null) {
|
try {
|
||||||
|
u = getPlayer(server, args[1], true, true);
|
||||||
|
} catch (PlayerNotFoundException e) {
|
||||||
throw new Exception(tl("playerNeverOnServer", args[1]));
|
throw new Exception(tl("playerNeverOnServer", args[1]));
|
||||||
}
|
}
|
||||||
u.addMail(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 2))));
|
u.addMail(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 2))));
|
||||||
@ -124,8 +128,10 @@ public class Commandmail extends EssentialsCommand {
|
|||||||
return;
|
return;
|
||||||
} else if (args.length >= 2) {
|
} else if (args.length >= 2) {
|
||||||
//allow sending from console without "send" argument, since it's the only thing the console can do
|
//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);
|
User u;
|
||||||
if (u == null) {
|
try {
|
||||||
|
u = getPlayer(server, args[0], true, true);
|
||||||
|
} catch (PlayerNotFoundException e) {
|
||||||
throw new Exception(tl("playerNeverOnServer", args[0]));
|
throw new Exception(tl("playerNeverOnServer", args[0]));
|
||||||
}
|
}
|
||||||
u.addMail(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 1))));
|
u.addMail(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 1))));
|
||||||
|
@ -69,7 +69,11 @@ public class Commandseen extends EssentialsCommand {
|
|||||||
if (userFromBukkit != null) {
|
if (userFromBukkit != null) {
|
||||||
showUserSeen(userFromBukkit);
|
showUserSeen(userFromBukkit);
|
||||||
} else {
|
} 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) {
|
} catch (Exception e) {
|
||||||
ess.showError(sender, e, commandLabel);
|
ess.showError(sender, e, commandLabel);
|
||||||
@ -77,9 +81,6 @@ public class Commandseen extends EssentialsCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showUserSeen(User user) throws Exception {
|
private void showUserSeen(User user) throws Exception {
|
||||||
if (user == null) {
|
|
||||||
throw new PlayerNotFoundException();
|
|
||||||
}
|
|
||||||
showSeenMessage(server, sender, user, showBan, showIp, showLocation);
|
showSeenMessage(server, sender, user, showBan, showIp, showLocation);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -22,16 +22,17 @@ public class Commandunban extends EssentialsCommand {
|
|||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
try {
|
try {
|
||||||
final User user = getPlayer(server, args, 0, true, true);
|
final User user = getPlayer(server, args, 0, true, true);
|
||||||
name = user.getName();
|
name = user.getName();
|
||||||
ess.getServer().getBanList(BanList.Type.NAME).pardon(name);
|
ess.getServer().getBanList(BanList.Type.NAME).pardon(name);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (PlayerNotFoundException e) {
|
||||||
final OfflinePlayer player = server.getOfflinePlayer(args[0]);
|
final OfflinePlayer player = server.getOfflinePlayer(args[0]);
|
||||||
name = player.getName();
|
name = player.getName();
|
||||||
if (!player.isBanned()) {
|
if (!player.isBanned()) {
|
||||||
throw new Exception(tl("playerNotFound"), e);
|
throw new Exception(tl("playerNeverOnServer", args[0]));
|
||||||
}
|
}
|
||||||
ess.getServer().getBanList(BanList.Type.NAME).pardon(name);
|
ess.getServer().getBanList(BanList.Type.NAME).pardon(name);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user