1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

resetexploreregion command is added for cleaning up explorer data of specified world.

This commit is contained in:
chacho4 2022-02-15 15:12:57 +09:00
parent 5856f9f483
commit 6f6d8a17d9
6 changed files with 107 additions and 7 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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<String, Map<String, ExploreRegion>> 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<String, Map<String, ExploreRegion>> worlds = getWorlds();
worlds.put(worldname, new HashMap<String, ExploreRegion>());
boolean r = Jobs.getJobsDAO().deleteExploredWorld(worldname);
if(!r) {
Jobs.consoleMsg("&eFailed in DAO.");
return;
}
Jobs.consoleMsg("&eCompleted to reset explorer data.");
}
}

View File

@ -209,6 +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.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]"));

View File

@ -2613,6 +2613,37 @@ 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

View File

@ -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: このチャンクに来たことのある人を確認できます