package de.fanta.challengesjoinentities.commands.AdventureCommand;
import de.fanta.challengesjoinentities.ChallengesJoinEntities;
import de.fanta.challengesjoinentities.ChatUtil;
import de.fanta.challengesjoinentities.loadgui.AdventureLoadGUI;
import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.commands.ArgsParser;
import de.iani.playerUUIDCache.CachedPlayer;
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;
}
CachedPlayer savePlayer;
if (args.hasNext()) {
if (!p.hasPermission("challenges.load.admin")) {
ChatUtil.sendErrorMessage(p, "Keine Rechte! (Du kannst nur eigene maps Laden)");
return true;
}
String savePlayerName = args.getNext();
savePlayer = plugin.getPlayerUUIDCache().getPlayer(savePlayerName);
} else {
savePlayer = plugin.getPlayerUUIDCache().getPlayer(p.getUniqueId());
}
if (savePlayer != null) {
new AdventureLoadGUI(p, savePlayer).open();
} else {
ChatUtil.sendErrorMessage(p, "Spieler nicht gefunden!");
}
return true;
}
}