From 2bfd5bef5e80d023cafc61b830a9242a968d32b9 Mon Sep 17 00:00:00 2001 From: Zrips Date: Wed, 20 Sep 2023 12:24:41 +0300 Subject: [PATCH] resetlimit all should reset limits for everyone and not just online players --- .../gamingmesh/jobs/commands/list/resetlimit.java | 13 +++++++------ .../com/gamingmesh/jobs/container/JobsPlayer.java | 4 ++++ .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetlimit.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetlimit.java index 4ac77a30..b7fbb298 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetlimit.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetlimit.java @@ -1,6 +1,7 @@ package com.gamingmesh.jobs.commands.list; import org.bukkit.command.CommandSender; + import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.JobsPlayer; @@ -15,14 +16,14 @@ public class resetlimit implements Cmd { } if (args[0].equalsIgnoreCase("all")) { - for (org.bukkit.entity.Player pl : org.bukkit.Bukkit.getOnlinePlayers()) { - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pl); - if (jPlayer != null) { - jPlayer.resetPaymentLimit(); - } + + for (JobsPlayer jPlayer : Jobs.getPlayerManager().getPlayersCache().values()) { + jPlayer.nullPaymentLimits(); } - Language.sendMessage(sender, "command.resetlimit.output.reseted", "%playername%", ""); + Jobs.getDBManager().getDB().clearLimitsTable(); + + Language.sendMessage(sender, "command.resetlimit.output.reseted", "%playername%", "", "%playerdisplayname%", ""); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 520bef13..14dc5bd6 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -466,6 +466,10 @@ public class JobsPlayer { setSaved(false); } + public void nullPaymentLimits() { + paymentLimits = null; + } + /** * @return an unmodifiable list of job progressions */ diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 2bb4afd8..514a8349 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1423,6 +1423,21 @@ public abstract class JobsDAO { } } + public synchronized void clearLimitsTable() { + JobsConnection conn = getConnection(); + if (conn == null) + return; + PreparedStatement ps = null; + try { + ps = conn.prepareStatement("DELETE FROM `" + DBTables.LimitsTable.getTableName() + "`;"); + ps.execute(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + close(ps); + } + } + public synchronized PaymentData getPlayersLimits(JobsPlayer jPlayer) { PaymentData data = new PaymentData(); JobsConnection conn = getConnection();