Player is null when he/she logs out hence the OfflinePlayer. Just use Player player = getPlayer(); You use OfflinePlayer for when the player is offline.
You can't cast real offline players to normal players. You have to work with the name or the UUID only. How would you teleport an offline player for example?
Where are you storing the data about which players are in debt? Assuming you are using a yaml file you can just get the path to the player's data and update it however you want?
Then you need to use offlinePlayer. In that case, check if the Player is not null/online then use Player player = getPlayer(); if it is null/offline use offlinePlayer. Like: Code (Java): if(Bukkit.getPlayer("Henk") == null){ //Player is offline or does not exist. //So use offlinePlayer OfflinePlayer offlineP = getOfflinePlayer(); }else{ //Player is online //Use Player Player player = getPlayer(); }
So heres my thought process: get the players who have registered from yml file i only have their UUIDs btw and have a loop where if the player is offline or online and them to the interest lie these players are the ones over debt and the they are charged interest.
Spoiler: CODE Code (Text): for(UUID u : UUIDs){ if(Bukkit.getPlayer(u) != null){ CardInfo cardInfo = getCard(u); long dayOfLoan = cardInfo.getloanTimestamp(); int chargeDate = plugin.getFileManager().getperdays(); int DOL = convertion(dayOfLoan); int differance = (DOL+30) - now.getDayOfYear(); if( differance > (DOL+30) || differance < 0) { SendConsoleMessage.debug("Player: "+Bukkit.getPlayer(u).getName()); overDuePlayers.add(Bukkit.getPlayer(u)); //SendConsoleMessage.info("Interest for Player: " + Bukkit.getPlayer(u).getName()+ " was added"); } } else if(Bukkit.getOfflinePlayer(u)!= null) { SendConsoleMessage.debug("getOfflinePlayer IS NOT NULL"); CardInfo cardInfo = getCard(u); long dayOfLoan = cardInfo.getloanTimestamp(); int chargeDate = plugin.getFileManager().getperdays(); int DOL = convertion(dayOfLoan); int differance = (DOL+30) - now.getDayOfYear(); String p1 = cardInfo.getName(); if( differance > (DOL+30) || differance < 0) { SendConsoleMessage.debug("Player: "+ Bukkit.getPlayer(p1)); SendConsoleMessage.debug("Player: "+ p1); overDuePlayers.add((Player) Bukkit.getOfflinePlayer(u)); //SendConsoleMessage.info("Interest for Player: " + Bukkit.getPlayer(u).getName()+ " was added"); } } UUIDs is all users in the yml that have a credit card
I had 2 arrays, 1 for players and 1 for offlineplayers, i had a on join and on exit methods. So when they join or exit they switch arrays
Why do you need to get the OfflinePlayer - Object? Is a UUID not enough? Seems like you only use it to fetch player's name.
You can also just get the player. If it's null it doesn't exist, if object#isOnline(), they are online. OfflinePlayer has their UUID. You can fetch a player object with that UUID and test if they are valid and online. Final: You should not store a offline player or online player object. You store the UUID. It's what it is meant for. You than retrieve a object based on that UUID. Not only because it's sane, but easier on memory. When you store a player object, and that object changes in the game, your stored object will not reflect this.