2016-03-30 15:42:36 +02:00
|
|
|
package com.gamingmesh.jobs.commands.list;
|
|
|
|
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2016-04-03 16:22:44 +02:00
|
|
|
import org.bukkit.inventory.Inventory;
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
import com.gamingmesh.jobs.Jobs;
|
|
|
|
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.ChatColor;
|
2016-06-28 11:33:28 +02:00
|
|
|
import com.gamingmesh.jobs.stuff.Debug;
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
public class join implements Cmd {
|
|
|
|
|
2016-06-25 17:56:59 +02:00
|
|
|
@Override
|
2016-03-30 15:42:36 +02:00
|
|
|
@JobCommand(100)
|
2016-08-08 16:36:56 +02:00
|
|
|
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
2016-04-03 16:22:44 +02:00
|
|
|
if (!(sender instanceof Player)) {
|
2016-03-30 15:42:36 +02:00
|
|
|
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length != 1 && args.length != 0) {
|
|
|
|
Jobs.getCommandManager().sendUsage(sender, "join");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length == 0) {
|
2016-04-03 16:22:44 +02:00
|
|
|
if (sender instanceof Player && Jobs.getGCManager().JobsGUIOpenOnJoin) {
|
|
|
|
Inventory inv = null;
|
|
|
|
try {
|
|
|
|
inv = Jobs.getGUIManager().CreateJobsGUI((Player) sender);
|
|
|
|
} catch (Exception e) {
|
|
|
|
((Player) sender).closeInventory();
|
|
|
|
Jobs.getGUIManager().GuiList.remove(((Player) sender).getName());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (inv == null)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
((Player) sender).openInventory(inv);
|
|
|
|
} else
|
2016-03-30 15:42:36 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player pSender = (Player) sender;
|
|
|
|
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender);
|
|
|
|
|
|
|
|
String jobName = args[0];
|
|
|
|
Job job = Jobs.getJob(jobName);
|
|
|
|
if (job == null) {
|
|
|
|
// job does not exist
|
|
|
|
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.job"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Jobs.getCommandManager().hasJobPermission(pSender, job)) {
|
|
|
|
// you do not have permission to join the job
|
|
|
|
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.permission"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jPlayer.isInJob(job)) {
|
|
|
|
// already in job message
|
|
|
|
String message = ChatColor.RED + Jobs.getLanguage().getMessage("command.join.error.alreadyin");
|
|
|
|
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.RED);
|
|
|
|
sender.sendMessage(message);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-28 11:33:28 +02:00
|
|
|
Debug.D("s");
|
2016-03-30 15:42:36 +02:00
|
|
|
if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots()) {
|
|
|
|
String message = ChatColor.RED + Jobs.getLanguage().getMessage("command.join.error.fullslots");
|
|
|
|
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.RED);
|
|
|
|
sender.sendMessage(message);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int confMaxJobs = Jobs.getGCManager().getMaxJobs();
|
|
|
|
short PlayerMaxJobs = (short) jPlayer.getJobProgression().size();
|
2016-06-28 11:33:28 +02:00
|
|
|
Debug.D(confMaxJobs > 0);
|
|
|
|
Debug.D(PlayerMaxJobs >= confMaxJobs);
|
|
|
|
Debug.D(!Jobs.getPlayerManager().getJobsLimit(pSender, PlayerMaxJobs));
|
2016-03-30 15:42:36 +02:00
|
|
|
if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(pSender, PlayerMaxJobs)) {
|
|
|
|
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.join.error.maxjobs"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Jobs.getPlayerManager().joinJob(jPlayer, job);
|
|
|
|
|
|
|
|
String message = Jobs.getLanguage().getMessage("command.join.success");
|
|
|
|
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
|
|
|
|
sender.sendMessage(message);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|