1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Confirmation for leave commands should work

This commit is contained in:
montlikadani 2019-08-01 15:10:36 +02:00
parent d4a2add86e
commit 0cef1e8dfd
4 changed files with 33 additions and 20 deletions

View File

@ -1,8 +1,5 @@
package com.gamingmesh.jobs.commands.list;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -11,11 +8,10 @@ import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Util;
public class leave implements Cmd {
private Set<CommandSender> confirm = new HashSet<>();
@Override
@JobCommand(800)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
@ -28,7 +24,6 @@ public class leave implements Cmd {
}
Player pSender = (Player) sender;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender);
String jobName = args[0];
Job job = Jobs.getJob(jobName);
@ -38,16 +33,24 @@ public class leave implements Cmd {
}
if (Jobs.getGCManager().EnableConfirmation) {
if (!confirm.contains(pSender)) {
confirm.add(pSender);
org.bukkit.Bukkit.getScheduler().runTaskLater(plugin, () -> confirm.remove(pSender), 20 * Jobs.getGCManager().ConfirmExpiryTime);
String uuid = pSender.getUniqueId().toString();
if (!Util.confirmLeave.contains(uuid)) {
Util.confirmLeave.add(uuid);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> Util.confirmLeave.remove(uuid),
20 * Jobs.getGCManager().ConfirmExpiryTime);
pSender.sendMessage(Jobs.getLanguage().getMessage("command.leave.confirmationNeed", "[jobname]", jobName,
"[time]", Jobs.getGCManager().ConfirmExpiryTime));
return true;
}
confirm.remove(pSender);
Util.confirmLeave.remove(uuid);
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender);
if (Jobs.getPlayerManager().leaveJob(jPlayer, job))
pSender.sendMessage(Jobs.getLanguage().getMessage("command.leave.success", "%jobname%", job.getChatColor() + job.getName()));
else

View File

@ -1,8 +1,6 @@
package com.gamingmesh.jobs.commands.list;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -12,11 +10,10 @@ import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Util;
public class leaveall implements Cmd {
private Set<CommandSender> confirm = new HashSet<>();
@Override
@JobCommand(900)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
@ -29,19 +26,26 @@ public class leaveall implements Cmd {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender);
List<JobProgression> jobs = jPlayer.getJobProgression();
if (jobs.size() == 0) {
if (jobs.isEmpty()) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.leaveall.error.nojobs"));
return true;
}
if (Jobs.getGCManager().EnableConfirmation) {
if (!confirm.contains(pSender)) {
confirm.add(pSender);
org.bukkit.Bukkit.getScheduler().runTaskLater(plugin, () -> confirm.remove(pSender), 20 * Jobs.getGCManager().ConfirmExpiryTime);
pSender.sendMessage(Jobs.getLanguage().getMessage("command.leaveall.confirmationNeed", "[time]", Jobs.getGCManager().ConfirmExpiryTime));
String uuid = pSender.getUniqueId().toString();
if (!Util.confirmLeave.contains(uuid)) {
Util.confirmLeave.add(uuid);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> Util.confirmLeave.remove(uuid),
20 * Jobs.getGCManager().ConfirmExpiryTime);
pSender.sendMessage(Jobs.getLanguage().getMessage("command.leaveall.confirmationNeed", "[time]",
Jobs.getGCManager().ConfirmExpiryTime));
return true;
}
confirm.remove(pSender);
Util.confirmLeave.remove(uuid);
}
Jobs.getPlayerManager().leaveAllJobs(jPlayer);

View File

@ -3,6 +3,7 @@ package com.gamingmesh.jobs.stuff;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.bukkit.Color;
@ -23,6 +24,7 @@ import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
public class Util {
private static HashMap<UUID, String> jobsEditorMap = new HashMap<>();
public static List<String> confirmLeave = new ArrayList<>();
@SuppressWarnings("deprecation")
public static ItemStack setEntityType(ItemStack is, EntityType type) throws IllegalArgumentException {

View File

@ -370,12 +370,16 @@ command:
help:
info: 'Elhagyja a megadott munkát.'
args: '[jobname]'
confirmationNeed: '&cBiztos vagy benne, hogy elhagyod a(z)&e [jobname]&c munkát? Írd be a parancsot újra&6 [time]
másodpercen belül, &chogy megerősítsd!'
success: '&cSikeresen elhagytad a(z)&7 %jobname%&c munkát!'
leaveall:
help:
info: 'Elhagyja az összes jelenlegi munkát.'
error:
nojobs: '&cNincs egyetlen munkád sem!'
confirmationNeed: '&cBiztos vagy benne, hogy elhagyod az összes munkát? Írd be a parancsot újra&6 [time]
másodpercen belül, &chogy megerősítsd!'
success: '&cElhagytad az összes munkát!'
explored:
help: