fix punishments not being retrieved from sql

This commit is contained in:
Taah 2022-04-11 00:53:09 -07:00
parent c92a4bbdb9
commit c071195aaf
3 changed files with 36 additions and 21 deletions

View File

@ -5,6 +5,7 @@ import dev.plex.Plex;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.PlexLog;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -36,7 +37,7 @@ public class SQLPunishment
ResultSet set = statement.executeQuery();
while (set.next())
{
Punishment punishment = new Punishment(UUID.fromString(set.getString("punished")), UUID.fromString(set.getString("punisher")));
Punishment punishment = new Punishment(UUID.fromString(set.getString("punished")), set.getString("punisher") != null && set.getString("punisher").isEmpty() ? UUID.fromString(set.getString("punisher")) : null);
punishment.setActive(set.getBoolean("active"));
punishment.setType(PunishmentType.valueOf(set.getString("type")));
punishment.setCustomTime(set.getBoolean("customTime"));
@ -46,8 +47,7 @@ public class SQLPunishment
punishment.setIp(set.getString("ip"));
punishments.add(punishment);
}
}
catch (SQLException e)
} catch (SQLException e)
{
e.printStackTrace();
return punishments;
@ -76,8 +76,7 @@ public class SQLPunishment
punishment.setIp(set.getString("ip"));
punishments.add(punishment);
}
}
catch (SQLException e)
} catch (SQLException e)
{
e.printStackTrace();
}
@ -104,14 +103,28 @@ public class SQLPunishment
statement.setLong(9, punishment.getEndDate().toInstant(ZoneOffset.UTC).toEpochMilli());
PlexLog.debug("Executing punishment");
statement.execute();
}
catch (SQLException e)
} catch (SQLException e)
{
e.printStackTrace();
}
});
}
public void syncRemoveBan(UUID uuid)
{
try (Connection con = Plex.get().getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement(UPDATE_BAN);
statement.setBoolean(1, false);
statement.setBoolean(2, true);
statement.setString(3, uuid.toString());
statement.setString(4, PunishmentType.BAN.name());
} catch (SQLException e)
{
e.printStackTrace();
}
}
public CompletableFuture<Void> removeBan(UUID uuid)
{
return CompletableFuture.runAsync(() ->
@ -124,8 +137,7 @@ public class SQLPunishment
statement.setString(3, uuid.toString());
statement.setString(4, PunishmentType.BAN.name());
statement.executeUpdate();
}
catch (SQLException e)
} catch (SQLException e)
{
e.printStackTrace();
}

View File

@ -14,9 +14,6 @@ import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
@ -25,6 +22,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
@ -47,15 +48,18 @@ public class BanCMD extends PlexCommand
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
Player player = Bukkit.getPlayer(targetUUID);
if (isAdmin(plexPlayer))
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
if (!isConsole(sender))
if (isAdmin(plexPlayer))
{
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
if (!isConsole(sender))
{
return messageComponent("higherRankThanYou");
assert playerSender != null;
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
{
return messageComponent("higherRankThanYou");
}
}
}
}
@ -74,8 +78,7 @@ public class BanCMD extends PlexCommand
{
reason = StringUtils.join(args, " ", 1, args.length);
punishment.setReason(reason);
}
else
} else
{
punishment.setReason("No reason provided.");
}

View File

@ -119,7 +119,7 @@ public class PlexPlayer
{
if (Plex.get().getStorageType() != StorageType.MONGODB)
{
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()).stream().filter(punishment -> punishment.getPunished().equals(this.getUuid())).collect(Collectors.toList()));
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()));
}
}