From 6f6d8a17d99f13e0d0177eefb03b6067e05f0da9 Mon Sep 17 00:00:00 2001 From: chacho4 Date: Tue, 15 Feb 2022 15:12:57 +0900 Subject: [PATCH] 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: このチャンクに来たことのある人を確認できます