From 6f6d8a17d99f13e0d0177eefb03b6067e05f0da9 Mon Sep 17 00:00:00 2001 From: chacho4 Date: Tue, 15 Feb 2022 15:12:57 +0900 Subject: [PATCH 1/2] resetexploreregion command is added for cleaning up explorer data of specified world. --- src/main/java/com/gamingmesh/jobs/Jobs.java | 2 +- .../commands/list/resetexploreregion.java | 31 +++++++++++++++++ .../jobs/config/ExploreManager.java | 25 ++++++++++++++ .../jobs/config/LanguageManager.java | 12 +++++-- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 33 ++++++++++++++++++- src/main/resources/locale/messages_ja.yml | 11 +++++-- 6 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index eeefc1fa..66fb3c88 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -389,7 +389,7 @@ public final class Jobs extends JavaPlugin { public static ExploreManager getExplore() { if (exploreManager == null) - exploreManager = new ExploreManager(); + exploreManager = ExploreManager.getInstane(); return exploreManager; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java new file mode 100644 index 00000000..8a4d9ddd --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java @@ -0,0 +1,31 @@ +package com.gamingmesh.jobs.commands.list; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.config.ExploreManager; +import org.bukkit.command.CommandSender; + +public class resetexploreregion implements Cmd { + + private static String WORLD = "world"; + private static String REGEX = "^[0-9a-zA-Z_-]+$"; + + @Override + public boolean perform(Jobs plugin, CommandSender sender, String[] args) { + if (args.length != 2 || !WORLD.equals(args[0])) { + Jobs.getCommandManager().sendUsage(sender, "resetexploreregion"); + return true; + } + + final String worldName = args[1]; + if(!worldName.matches(REGEX)) { + sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.invalidname")); + return true; + } + + ExploreManager manager = ExploreManager.getInstane(); + manager.resetRegion(worldName); + sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.reseted", "%worldname%", worldName)); + return true; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java index 6da9b8d5..d28f91e1 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java @@ -19,6 +19,17 @@ import com.gamingmesh.jobs.stuff.Util; public class ExploreManager { + private static ExploreManager instance; + public static ExploreManager getInstane() { + if(null == instance) { + instance = new ExploreManager(); + } + return instance; + } + + private ExploreManager() { + } + private final Map> worlds = new HashMap<>(); private boolean exploreEnabled = false; private int playerAmount = 1; @@ -139,4 +150,18 @@ public class ExploreManager { } } + public void resetRegion(String worldname) { + Jobs.consoleMsg("&eReseting explorer data. World: " + worldname); + + Map> worlds = getWorlds(); + worlds.put(worldname, new HashMap()); + + boolean r = Jobs.getJobsDAO().deleteExploredWorld(worldname); + if(!r) { + Jobs.consoleMsg("&eFailed in DAO."); + return; + } + + Jobs.consoleMsg("&eCompleted to reset explorer data."); + } } diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index bf1b5718..0315101f 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -209,11 +209,17 @@ public class LanguageManager { c.get("command.limit.output.reachedpointslimit2", "&eYou can check your limit with &2/jobs limit &ecommand"); c.get("command.limit.output.notenabled", "&eMoney limit is not enabled"); - c.get("command.resetlimit.help.info", "Resets a player's payment limits"); + c.get("command.resetexploreregion.help.info", "Resets world data of Explorering"); + c.get("command.resetexploreregion.help.args", "world [worldname]"); + Jobs.getGCManager().getCommandArgs().put("resetlimit", Arrays.asList("world", "[worldname]")); + c.get("command.resetexploreregion.output.invalidname", "&eInvalid world name"); + c.get("command.resetexploreregion.output.reseted", "&eWorld data has been reset for: &2%worldname%"); + + c.get("command.resetlimit.help.info", "Resets a player's payment limits"); 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.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")); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index e9facf16..e133fe8e 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -2613,7 +2613,38 @@ public abstract class JobsDAO { } - /** + /** + * Delete player-explore information + * @param worldName - the world getting removed + */ + public boolean deleteExploredWorld(String worldName) { + if (!Jobs.getExplore().isExploreEnabled()) + return false; + + JobsConnection conn = getConnection(); + if (conn == null) + return false; + + JobsWorld target = Util.getJobsWorld(worldName); + if (null == target) { + return false; + } + + PreparedStatement prest = null; + try { + prest = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;"); + prest.setInt(1, target.getId()); + prest.execute(); + } catch (Throwable e) { + e.printStackTrace(); + return false; + } finally { + close(prest); + } + return true; + } + + /** * Save player-job information * @param jobInfo - the information getting saved * @return diff --git a/src/main/resources/locale/messages_ja.yml b/src/main/resources/locale/messages_ja.yml index ec08eb9c..ff6d1b87 100644 --- a/src/main/resources/locale/messages_ja.yml +++ b/src/main/resources/locale/messages_ja.yml @@ -151,6 +151,13 @@ command: reachedpointslimit: '&4ポイント獲得上限に達しました' reachedpointslimit2: '&2/jobs limit &eコマンドで上限を確認できます' notenabled: '&e上限は有効化されていません' + resetexploreregion: + help: + info: '指定したワールドの探索情報をリセットします' + args: 'world [worldname]' + output: + invalidname: 'ワールド名が不正です' + reseted: '&2%worldname% &eの探索情報をリセットしました' resetlimit: help: info: '[player]の上限をリセットします' @@ -416,14 +423,14 @@ command: info: '[職業名]を離職します' args: '[oldplayerjob]' success: '%jobname% を離職しました' - confirmationNeed: '&cAre you sure you want to leave from&e [jobname]&c job? Type the command again within&6 [time] seconds &cto confirm!' + confirmationNeed: '&c本当に &e[jobname] &cから離職しますか? 離職する場合は &6[time]&c 秒以内に再度コマンドを実行してください' leaveall: help: info: 就いている全ての職業を離職します error: nojobs: 離職できる職業はありません success: 就いている全ての職業を離職しました - confirmationNeed: '&cAre you sure you want to leave from all jobs? Type the command again within&6 [time] seconds &cto confirm!' + confirmationNeed: '&c本当に &e全てのジョブ&c から離職しますか? 離職する場合は &6[time]&c 秒以内に再度コマンドを実行してください' explored: help: info: このチャンクに来たことのある人を確認できます From 383e1b1d61a008f5fcaddf7a4b7ff34b5d9b9575 Mon Sep 17 00:00:00 2001 From: chacho4 Date: Tue, 15 Feb 2022 15:40:30 +0900 Subject: [PATCH 2/2] resetexploreregion is disable by default. --- .../gamingmesh/jobs/commands/list/resetexploreregion.java | 5 +++++ .../com/gamingmesh/jobs/config/GeneralConfigManager.java | 5 ++++- .../java/com/gamingmesh/jobs/config/LanguageManager.java | 5 +++-- src/main/resources/locale/messages_ja.yml | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java index 8a4d9ddd..9d22647f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java @@ -17,6 +17,11 @@ public class resetexploreregion implements Cmd { return true; } + if (!Jobs.getGCManager().resetExploringData) { + sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.notenabled")); + return true; + } + final String worldName = args[1]; if(!worldName.matches(REGEX)) { sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.invalidname")); diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 767072b2..e68e21ba 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -89,7 +89,7 @@ public class GeneralConfigManager { public boolean ignoreOreGenerators, useBlockProtection, enableSchedule, PayForRenaming, PayForEnchantingOnAnvil, PayForEachCraft, SignsEnabled, SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useSilkTouchProtection, UseCustomNames, PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps, - BrowseUseNewLook, payExploringWhenGliding = false, disablePaymentIfMaxLevelReached, disablePaymentIfRiding, + BrowseUseNewLook, payExploringWhenGliding = false, resetExploringData = false, disablePaymentIfMaxLevelReached, disablePaymentIfRiding, boostedItemsInOffHand = false, boostedItemsInMainHand, boostedArmorItems/*, preventCropResizePayment*/, payItemDurabilityLoss, applyToNegativeIncome, useMinimumOveralPayment, useMinimumOveralPoints, useMinimumOveralExp, useBreederFinder, CancelCowMilking, fixAtMaxLevel, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, @@ -456,6 +456,9 @@ public class GeneralConfigManager { payExploringWhenGliding = c.get("enable-pay-for-exploring-when-gliding", false); } + c.addComment("enable-reset-exploring-data", "Option to allow reset exploring data."); + resetExploringData = c.get("enable-reset-exploring-data", false); + c.addComment("disablePaymentIfRiding", "Disables the payment when the player riding on an entity."); disablePaymentIfRiding = c.get("disablePaymentIfRiding", false); diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 0315101f..2bab7cd0 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -209,11 +209,12 @@ public class LanguageManager { c.get("command.limit.output.reachedpointslimit2", "&eYou can check your limit with &2/jobs limit &ecommand"); c.get("command.limit.output.notenabled", "&eMoney limit is not enabled"); - c.get("command.resetexploreregion.help.info", "Resets world data of Explorering"); + c.get("command.resetexploreregion.help.info", "Resets region data of Explorering"); c.get("command.resetexploreregion.help.args", "world [worldname]"); Jobs.getGCManager().getCommandArgs().put("resetlimit", Arrays.asList("world", "[worldname]")); + c.get("command.resetexploreregion.output.notenabled", "&eNot enabled."); c.get("command.resetexploreregion.output.invalidname", "&eInvalid world name"); - c.get("command.resetexploreregion.output.reseted", "&eWorld data has been reset for: &2%worldname%"); + c.get("command.resetexploreregion.output.reseted", "&eExploring region data has been reset for: &2%worldname%"); c.get("command.resetlimit.help.info", "Resets a player's payment limits"); c.get("command.resetlimit.help.args", "[playername]"); diff --git a/src/main/resources/locale/messages_ja.yml b/src/main/resources/locale/messages_ja.yml index ff6d1b87..4cee23e4 100644 --- a/src/main/resources/locale/messages_ja.yml +++ b/src/main/resources/locale/messages_ja.yml @@ -156,6 +156,7 @@ command: info: '指定したワールドの探索情報をリセットします' args: 'world [worldname]' output: + notenabled: '機能が無効化されています' invalidname: 'ワールド名が不正です' reseted: '&2%worldname% &eの探索情報をリセットしました' resetlimit: