package de.fanta.challengesjoinentities.commands.AdventureCommand;
import de.fanta.challengesjoinentities.ChallengesJoinEntities;
import de.fanta.challengesjoinentities.ChatUtil;
import de.fanta.challengesjoinentities.Server;
import de.fanta.challengesjoinentities.loadgui.AdventureLoadGUI;
import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.commands.ArgsParser;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class AdventureLoadCommand extends SubCommand {
private final ChallengesJoinEntities plugin;
public AdventureLoadCommand(ChallengesJoinEntities plugin) {
this.plugin = plugin;
}
public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
if (!(sender instanceof Player p)) {
ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!");
return true;
}
if (!args.hasNext()) {
AdventureLoadGUI.createloadGUI(p);
return true;
} else {
if (sender.hasPermission("challenges.load.admin")) {
if (args.remaining() != 1 && args.remaining() != 2) {
ChatUtil.sendWarningMessage(p, "/adventure load [key] [Slot]");
return true;
}
String next = args.getNext();
String slot = args.getNext();
if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
this.plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadSaved(p, next.toLowerCase(), slot), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
} else {
ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!");
}
}
}
return true;
}
}