mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
fix punishments not being retrieved from sql
This commit is contained in:
parent
c92a4bbdb9
commit
c071195aaf
@ -5,6 +5,7 @@ import dev.plex.Plex;
|
|||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -36,7 +37,7 @@ public class SQLPunishment
|
|||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
while (set.next())
|
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.setActive(set.getBoolean("active"));
|
||||||
punishment.setType(PunishmentType.valueOf(set.getString("type")));
|
punishment.setType(PunishmentType.valueOf(set.getString("type")));
|
||||||
punishment.setCustomTime(set.getBoolean("customTime"));
|
punishment.setCustomTime(set.getBoolean("customTime"));
|
||||||
@ -46,8 +47,7 @@ public class SQLPunishment
|
|||||||
punishment.setIp(set.getString("ip"));
|
punishment.setIp(set.getString("ip"));
|
||||||
punishments.add(punishment);
|
punishments.add(punishment);
|
||||||
}
|
}
|
||||||
}
|
} catch (SQLException e)
|
||||||
catch (SQLException e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return punishments;
|
return punishments;
|
||||||
@ -76,8 +76,7 @@ public class SQLPunishment
|
|||||||
punishment.setIp(set.getString("ip"));
|
punishment.setIp(set.getString("ip"));
|
||||||
punishments.add(punishment);
|
punishments.add(punishment);
|
||||||
}
|
}
|
||||||
}
|
} catch (SQLException e)
|
||||||
catch (SQLException e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -104,14 +103,28 @@ public class SQLPunishment
|
|||||||
statement.setLong(9, punishment.getEndDate().toInstant(ZoneOffset.UTC).toEpochMilli());
|
statement.setLong(9, punishment.getEndDate().toInstant(ZoneOffset.UTC).toEpochMilli());
|
||||||
PlexLog.debug("Executing punishment");
|
PlexLog.debug("Executing punishment");
|
||||||
statement.execute();
|
statement.execute();
|
||||||
}
|
} catch (SQLException e)
|
||||||
catch (SQLException e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
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)
|
public CompletableFuture<Void> removeBan(UUID uuid)
|
||||||
{
|
{
|
||||||
return CompletableFuture.runAsync(() ->
|
return CompletableFuture.runAsync(() ->
|
||||||
@ -124,8 +137,7 @@ public class SQLPunishment
|
|||||||
statement.setString(3, uuid.toString());
|
statement.setString(3, uuid.toString());
|
||||||
statement.setString(4, PunishmentType.BAN.name());
|
statement.setString(4, PunishmentType.BAN.name());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
} catch (SQLException e)
|
||||||
catch (SQLException e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,6 @@ import dev.plex.punishment.PunishmentType;
|
|||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -25,6 +22,10 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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")
|
@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)
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||||
|
|
||||||
@ -47,6 +48,8 @@ public class BanCMD extends PlexCommand
|
|||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||||
Player player = Bukkit.getPlayer(targetUUID);
|
Player player = Bukkit.getPlayer(targetUUID);
|
||||||
|
|
||||||
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
|
{
|
||||||
if (isAdmin(plexPlayer))
|
if (isAdmin(plexPlayer))
|
||||||
{
|
{
|
||||||
if (!isConsole(sender))
|
if (!isConsole(sender))
|
||||||
@ -59,6 +62,7 @@ public class BanCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) ->
|
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) ->
|
||||||
{
|
{
|
||||||
@ -74,8 +78,7 @@ public class BanCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
reason = StringUtils.join(args, " ", 1, args.length);
|
reason = StringUtils.join(args, " ", 1, args.length);
|
||||||
punishment.setReason(reason);
|
punishment.setReason(reason);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
punishment.setReason("No reason provided.");
|
punishment.setReason("No reason provided.");
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public class PlexPlayer
|
|||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user