I'm currently trying to code a plugin where you can also remove the permissions of offline players, I use PermissionsEX to help, but somehow I can't get the offline player to cast. By the way, comments like "Before you even start coding you should first learn how to do it" are not really helpful.
I hope you can help:
Player target = Bukkit.getPlayer (args [0]);
if (target.isOnline ()) {
p.sendMessage (Prefixes.team + "§7" + target.getName () + "§7 is no longer in the team.");
target.sendMessage (Prefixes.team + "§7You are no longer in the server team.");
PermissionsEx.getUser (target) .removePermission ("d.admin");
PermissionsEx.getUser (target) .removePermission ("d.mod");
PermissionsEx.getUser (target) .removePermission ("d.support");
} else {
OfflinePlayer offlinetarget = Bukkit.getOfflinePlayer (args [0]);
PermissionsEx.getUser (offlinetarget.getPlayer ()). RemovePermission ("d.admin");
PermissionsEx.getUser (offlinetarget.getPlayer ()). RemovePermission ("d.mod");
PermissionsEx.getUser (offlinetarget.getPlayer ()). RemovePermission ("d.support");
p.sendMessage (Prefixes.team + "§f" + offlinetarget.getName () + "§7 all team rights were revoked offline.");
Does PeX need the player object or just the name or UUID?
You get the offline player even when the player is online (sounds stupid at first, but it is true). So almost always. It's there for that kind of thing where you just need some information like UUID, but the player is off so you don't get the player.
You can also cast a player to an offline player to get it.
So the part (without if) should be sufficient (you should only call PermissionEx.getUser () once and use an intermediate variable).
OfflinePlayer offlinetarget = Bukkit.getOfflinePlayer (args [0]);
PermissionsEx.getUser (offlinetarget.getPlayer ()). RemovePermission ("d.admin");
PermissionsEx.getUser (offlinetarget.getPlayer ()). RemovePermission ("d.mod");
PermissionsEx.getUser (offlinetarget.getPlayer ()). RemovePermission ("d.support");
p.sendMessage (Prefixes.team + "§f" + offlinetarget.getName () + "§7 all team rights were revoked offline.");
Regardless of this, you should avoid calling up a player by name (regardless of whether it is an offline player or player) when the player is not online, as he can change his name, then someone else takes the name and you are suddenly addressing a completely different player.