1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-23 16:41:25 +01:00

Better way to fire everyone from every job

fireall all needs a console check
This commit is contained in:
Zrips 2020-03-25 16:42:00 +02:00
parent b6e4b9cfb2
commit 83377ddee0

View File

@ -1,6 +1,8 @@
package com.gamingmesh.jobs.commands.list; package com.gamingmesh.jobs.commands.list;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -11,6 +13,7 @@ import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.dao.JobsDAO.DBTables;
public class fireall implements Cmd { public class fireall implements Cmd {
@ -23,21 +26,21 @@ public class fireall implements Cmd {
} }
if (args[0].equalsIgnoreCase("all")) { if (args[0].equalsIgnoreCase("all")) {
boolean success = false;
for (Player player : Bukkit.getOnlinePlayers()) { if (sender instanceof Player) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.fromconsole"));
List<JobProgression> jobs = jPlayer.getJobProgression(); return true;
if (jobs.isEmpty()) {
continue;
} }
Jobs.getPlayerManager().leaveAllJobs(jPlayer); Jobs.getDBManager().getDB().truncate(DBTables.JobsTable.getTableName());
player.sendMessage(Jobs.getLanguage().getMessage("command.fireall.output.target")); for (Entry<UUID, JobsPlayer> one : Jobs.getPlayerManager().getPlayersCache().entrySet()) {
success = true; one.getValue().leaveAllJobs();
// No need to save as we are clearing database with more efficient method
one.getValue().setSaved(true);
} }
sender.sendMessage(Jobs.getLanguage().getMessage(success ? "general.admin.success" : "command.fireall.error.nojobs")); sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
return true; return true;
} }