From f53a32e35ac297f1e971ba9706ace8e5d626ea9f Mon Sep 17 00:00:00 2001 From: Zrips Date: Fri, 11 Feb 2022 17:18:51 +0200 Subject: [PATCH] New command as resetquesttotal for reseting done quest counter --- src/main/java/com/gamingmesh/jobs/Jobs.java | 9 +-- .../jobs/commands/list/resetquesttotal.java | 58 +++++++++++++++++++ .../jobs/config/LanguageManager.java | 5 ++ .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 18 ++++++ .../jobs/listeners/JobsListener.java | 3 +- .../jobs/listeners/JobsPayment14Listener.java | 2 +- .../jobs/listeners/JobsPaymentListener.java | 4 +- .../jobs/listeners/Listener1_9.java | 8 +-- 8 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/gamingmesh/jobs/commands/list/resetquesttotal.java diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index c2723cf1..eeefc1fa 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -116,6 +116,7 @@ import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.Version.Version; @@ -165,7 +166,7 @@ public final class Jobs extends JavaPlugin { public static LoadStatus status = LoadStatus.Good; - private static boolean hasLimitedItems = false; + private static boolean hasLimitedItems = false; private static final int MAX_ENTRIES = 5; public static final LinkedHashMap FASTPAYMENT = new LinkedHashMap(MAX_ENTRIES + 1, .75F, false) { @@ -1511,7 +1512,7 @@ public final class Jobs extends JavaPlugin { rm.show(sender); } - public static boolean hasLimitedItems() { - return hasLimitedItems; - } + public static boolean hasLimitedItems() { + return hasLimitedItems; + } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetquesttotal.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetquesttotal.java new file mode 100644 index 00000000..1e9c5050 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetquesttotal.java @@ -0,0 +1,58 @@ +package com.gamingmesh.jobs.commands.list; + +import java.util.Map.Entry; +import java.util.UUID; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.container.JobsPlayer; + +public class resetquesttotal implements Cmd { + + @Override + public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (args.length != 0 && args.length != 1) { + Jobs.getCommandManager().sendUsage(sender, "resetquesttotal"); + return true; + } + + if (args[0].equalsIgnoreCase("all")) { + for (Entry pl : Jobs.getPlayerManager().getPlayersCache().entrySet()) { + pl.getValue().setDoneQuests(0); + } + Jobs.getJobsDAO().resetDoneQuests(); + sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquesttotal.output.reseted", "%playername%", Jobs.getPlayerManager().getPlayersCache().size())); + return true; + } + + JobsPlayer jPlayer = null; + Job job = null; + + for (String one : args) { + if (job == null) { + job = Jobs.getJob(one); + if (job != null) + continue; + } + jPlayer = Jobs.getPlayerManager().getJobsPlayer(one); + } + + if (jPlayer == null && sender instanceof Player) + jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); + + if (jPlayer == null) { + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args.length > 0 ? args[0] : "")); + return true; + } + + jPlayer.setDoneQuests(0); + jPlayer.setSaved(false); + jPlayer.save(); + sender.sendMessage(Jobs.getLanguage().getMessage("command.resetquesttotal.output.reseted", "%playername%", jPlayer.getName())); + return true; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index dca132c0..bf1b5718 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -213,6 +213,11 @@ public class LanguageManager { c.get("command.resetlimit.help.args", "[playername]"); Jobs.getGCManager().getCommandArgs().put("resetlimit", Arrays.asList("[playername]")); c.get("command.resetlimit.output.reseted", "&ePayment limits have been reset for: &2%playername%"); + + c.get("command.resetquesttotal.help.info", "Resets a player's done quest counter"); + c.get("command.resetquesttotal.help.args", "[playername]/all"); + Jobs.getGCManager().getCommandArgs().put("resetquesttotal", Arrays.asList("[playername]%%all")); + c.get("command.resetquesttotal.output.reseted", "&eDone quests have been reset for: &2%playername%"); c.get("command.resetquest.help.info", "Resets a player's quest"); c.get("command.resetquest.help.args", "[playername] [jobname]"); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 221fbfc4..e9facf16 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1999,6 +1999,24 @@ public abstract class JobsDAO { } } + public void resetDoneQuests() { + + JobsConnection conn = getConnection(); + if (conn == null) + return; + + PreparedStatement prest = null; + try { + prest = conn.prepareStatement("UPDATE `" + DBTables.UsersTable.getTableName() + "` SET `" + UserTableFields.donequests.getCollumn() + "` = ?;"); + prest.setInt(1, 0); + prest.execute(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + close(prest); + } + } + private void insertPlayer(JobsPlayer player) { JobsConnection conn = getConnection(); if (conn == null) diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index bc822ba7..1cd9e7cb 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -466,8 +466,9 @@ public class JobsListener implements Listener { Chunk from = event.getFrom().getChunk(); Chunk to = event.getTo().getChunk(); - if (from != to) + if (from != to) { plugin.getServer().getPluginManager().callEvent(new JobsChunkChangeEvent(event.getPlayer(), from, to)); + } } @EventHandler(ignoreCancelled = true) diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java index 5846ec9b..ef79ccd1 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java @@ -77,7 +77,7 @@ public final class JobsPayment14Listener implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onCook(BlockCookEvent event) { - if (!(event.getBlock().getType() != Material.CAMPFIRE) || campPlayers.isEmpty()) + if (event.getBlock().getType() != Material.CAMPFIRE || campPlayers.isEmpty()) return; if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index ec83c1ee..cb935279 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -26,7 +26,6 @@ import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.TimeUnit; -import com.bgsoftware.wildstacker.api.enums.StackSplit; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -90,6 +89,7 @@ import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; import org.bukkit.permissions.PermissionAttachmentInfo; +import com.bgsoftware.wildstacker.api.enums.StackSplit; import com.gamingmesh.jobs.ItemBoostManager; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.CMIEnchantment; @@ -128,7 +128,6 @@ import net.Zrips.CMILib.Container.CMILocation; import net.Zrips.CMILib.Entities.CMIEntityType; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; -import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Version.Version; public final class JobsPaymentListener implements Listener { @@ -1775,6 +1774,7 @@ public final class JobsPaymentListener implements Listener { @EventHandler(ignoreCancelled = true) public void onExplore(JobsChunkChangeEvent event) { + if (!Jobs.getExplore().isExploreEnabled()) return; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/Listener1_9.java b/src/main/java/com/gamingmesh/jobs/listeners/Listener1_9.java index 9f88fbf5..6e38fe7f 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/Listener1_9.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/Listener1_9.java @@ -8,8 +8,8 @@ import com.gamingmesh.jobs.Jobs; public class Listener1_9 implements Listener { - @EventHandler - public void onPlayerHandSwap(PlayerSwapHandItemsEvent event) { - Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); - } + @EventHandler + public void onPlayerHandSwap(PlayerSwapHandItemsEvent event) { + Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); + } }