fix NPE and codec issues

This commit is contained in:
Taah
2022-05-28 19:12:18 -07:00
parent d0b1d09f38
commit 9f19bd14ca
5 changed files with 74 additions and 24 deletions

View File

@ -11,6 +11,7 @@ import dev.plex.storage.StorageType;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@ -22,6 +23,7 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.Getter;
import org.apache.commons.io.FileUtils;
@ -105,8 +107,7 @@ public class PunishmentManager implements PlexBase
{
DataUtils.update(plexPlayer);
});
}
else
} else
{
Plex.get().getSqlPunishment().insertPunishment(punishment);
}
@ -117,8 +118,7 @@ public class PunishmentManager implements PlexBase
try
{
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
}
catch (IOException e)
} catch (IOException e)
{
e.printStackTrace();
}
@ -129,6 +129,11 @@ public class PunishmentManager implements PlexBase
{
return CompletableFuture.supplyAsync(() ->
{
if (!DataUtils.hasPlayedBefore(uuid))
{
return false;
}
PlexPlayer player = DataUtils.getPlayer(uuid);
player.loadPunishments();
return player.getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
@ -138,10 +143,10 @@ public class PunishmentManager implements PlexBase
public boolean isBanned(UUID uuid)
{
// TODO: If a person is using MongoDB, this will error out because it is checking for bans on a player that doesn't exist yet
/*if (!DataUtils.hasPlayedBefore(uuid))
if (!DataUtils.hasPlayedBefore(uuid))
{
return false;
}*/
}
return DataUtils.getPlayer(uuid).getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
}
@ -159,8 +164,7 @@ public class PunishmentManager implements PlexBase
List<PlexPlayer> players = Plex.get().getMongoPlayerData().getPlayers();
return players.stream().map(PlexPlayer::getPunishments).flatMap(Collection::stream).filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
});
}
else
} else
{
//PlexLog.debug("Checking active bans mysql");
CompletableFuture<List<Punishment>> future = new CompletableFuture<>();
@ -191,8 +195,7 @@ public class PunishmentManager implements PlexBase
.peek(punishment -> punishment.setActive(false)).collect(Collectors.toList()));
DataUtils.update(plexPlayer);
});
}
else
} else
{
return Plex.get().getSqlPunishment().removeBan(uuid);
}
@ -220,8 +223,7 @@ public class PunishmentManager implements PlexBase
Bukkit.broadcast(PlexUtils.messageComponent("unfrozePlayer", "Plex", Bukkit.getOfflinePlayer(player.getUuid()).getName()));
}
}.runTaskLater(Plex.get(), 20 * seconds);
}
else if (punishment.getType() == PunishmentType.MUTE)
} else if (punishment.getType() == PunishmentType.MUTE)
{
player.setMuted(true);
ZonedDateTime now = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));