Skip to content

Commit

Permalink
fix: NPE while collecting fees
Browse files Browse the repository at this point in the history
ClanPlayer#toPlayer() returns null when the player is not connected
  • Loading branch information
RoinujNosde committed Jun 12, 2022
1 parent 7769060 commit c47289c
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import net.sacredlabyrinth.phaed.simpleclans.*;
import net.sacredlabyrinth.phaed.simpleclans.loggers.BankOperator;
import net.sacredlabyrinth.phaed.simpleclans.managers.PermissionsManager;
import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable;

import static net.sacredlabyrinth.phaed.simpleclans.SimpleClans.lang;
Expand Down Expand Up @@ -42,24 +43,24 @@ public void start() {
*/
@Override
public void run() {
PermissionsManager pm = plugin.getPermissionsManager();
for (Clan clan : plugin.getClanManager().getClans()) {
final double memberFee = clan.getMemberFee();

if (clan.isMemberFeeEnabled() && memberFee > 0) {
for (ClanPlayer cp : clan.getFeePayers()) {
boolean success = plugin.getPermissionsManager()
.playerChargeMoney(Bukkit.getOfflinePlayer(cp.getUniqueId()), memberFee);
if (success) {
Player player = cp.toPlayer();
ChatBlock.sendMessage(player, AQUA + lang("fee.collected", cp, memberFee));
if (!clan.isMemberFeeEnabled() || memberFee <= 0) {
continue;
}

clan.deposit(new BankOperator(cp, plugin.getPermissionsManager().playerGetMoney(player)), Cause.MEMBER_FEE, memberFee);
plugin.getStorageManager().updateClan(clan);
} else {
clan.removePlayerFromClan(cp.getUniqueId());
clan.addBb(AQUA + lang("bb.fee.player.kicked", cp.getName()));
}
for (ClanPlayer cp : clan.getFeePayers()) {
OfflinePlayer player = Bukkit.getOfflinePlayer(cp.getUniqueId());
boolean success = pm.playerChargeMoney(player, memberFee);
if (success) {
ChatBlock.sendMessage(cp, AQUA + lang("fee.collected", cp, memberFee));

clan.deposit(new BankOperator(cp, pm.playerGetMoney(player)), Cause.MEMBER_FEE, memberFee);
plugin.getStorageManager().updateClan(clan);
} else {
clan.removePlayerFromClan(cp.getUniqueId());
clan.addBb(AQUA + lang("bb.fee.player.kicked", cp.getName()));
}
}
}
Expand Down

0 comments on commit c47289c

Please # to comment.