Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,44 @@
* @author Beelzebu
*/
public class InternalListener implements Listener {


private void ban(BanList banlist, PunishmentEvent e) {
try {
banlist.addBan(e.getPunishment().getName(), e.getPunishment().getReason(), new Date(e.getPunishment().getEnd()), e.getPunishment().getOperator());
} catch (NullPointerException ex) {
Bukkit.getLogger().severe("No player is known by the name '" + e.getPunishment().getName() + "'");
}
}
Comment on lines +19 to +41
Copy link
Copy Markdown
Collaborator

@Hopefuls Hopefuls Apr 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be further specified to only catch when the error originates from:

Cannot invoke "com.mojang.authlib.GameProfile.getId()" because "var0" is null
As this may catch-all issues that are not related to this issue.

(Also apply to the pardon too)

Thanks for your help!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can give you access to the PR if you want as I'm not able to fix this within the next week.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I now fixed it better. The problem is that I don't want to check for a certain text in the error message. Neither would I like to go parsing the stack trace. Nor do something with reflection.

The negative thing with the current implementation is that a user has to have been logged on before he's allowed to be banned...

Neither option truly satisfies me, even more because there is no real internal method that I can query (without the use of reflection / fork-specific calls) to check the existence of the username.


@EventHandler
public void onPunish(PunishmentEvent e) {
BanList banlist;
if (e.getPunishment().getType().equals(PunishmentType.BAN) || e.getPunishment().getType().equals(PunishmentType.TEMP_BAN)) {
banlist = Bukkit.getBanList(BanList.Type.NAME);
banlist.addBan(e.getPunishment().getName(), e.getPunishment().getReason(), new Date(e.getPunishment().getEnd()), e.getPunishment().getOperator());
ban(banlist, e);
} else if (e.getPunishment().getType().equals(PunishmentType.IP_BAN) || e.getPunishment().getType().equals(PunishmentType.TEMP_IP_BAN)) {
banlist = Bukkit.getBanList(BanList.Type.IP);
banlist.addBan(e.getPunishment().getName(), e.getPunishment().getReason(), new Date(e.getPunishment().getEnd()), e.getPunishment().getOperator());
ban(banlist, e);
}
}


private void pardon(BanList banlist, RevokePunishmentEvent e) {
try {
banlist.pardon(e.getPunishment().getName());
} catch (NullPointerException ex) {
Bukkit.getLogger().severe("No player is known by the name '" + e.getPunishment().getName() + "'");
}
}

@EventHandler
public void onRevokePunishment(RevokePunishmentEvent e) {
BanList banlist;
if (e.getPunishment().getType().equals(PunishmentType.BAN) || e.getPunishment().getType().equals(PunishmentType.TEMP_BAN)) {
banlist = Bukkit.getBanList(BanList.Type.NAME);
banlist.pardon(e.getPunishment().getName());
pardon(banlist, e);
} else if (e.getPunishment().getType().equals(PunishmentType.IP_BAN) || e.getPunishment().getType().equals(PunishmentType.TEMP_IP_BAN)) {
banlist = Bukkit.getBanList(BanList.Type.IP);
banlist.pardon(e.getPunishment().getName());
pardon(banlist, e);
}
}
}