Added /mmocore quest commands

This commit is contained in:
Indyuce 2020-04-12 22:36:05 +02:00
parent 1112093bd9
commit 44a76e7dbb
3 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package net.Indyuce.mmocore.command.rpg.quest;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.PlayerQuests;
import net.Indyuce.mmocore.command.api.CommandEnd;
import net.Indyuce.mmocore.command.api.CommandMap;
import net.Indyuce.mmocore.command.api.Parameter;
public class CancelCommandEnd extends CommandEnd {
public CancelCommandEnd(CommandMap parent) {
super(parent, "cancel");
addParameter(Parameter.PLAYER);
}
@Override
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 3)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[2]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find player called " + args[2] + ".");
return CommandResult.FAILURE;
}
PlayerQuests quests = PlayerData.get(player).getQuestData();
if (!quests.hasCurrent()) {
if (sender instanceof Player)
sender.sendMessage(ChatColor.RED + player.getName() + " has no ongoing quest.");
return CommandResult.SUCCESS;
}
quests.start(null);
if (sender instanceof Player)
sender.sendMessage(ChatColor.YELLOW + player.getName() + " no longer has any ongoing quest.");
return CommandResult.SUCCESS;
}
}

View File

@ -0,0 +1,20 @@
package net.Indyuce.mmocore.command.rpg.quest;
import org.bukkit.command.CommandSender;
import net.Indyuce.mmocore.command.api.CommandMap;
public class QuestCommandMap extends CommandMap {
public QuestCommandMap(CommandMap parent) {
super(parent, "quest");
addFloor(new StartCommandEnd(this));
addFloor(new CancelCommandEnd(this));
}
@Override
public CommandResult execute(CommandSender sender, String[] args) {
return CommandResult.THROW_USAGE;
}
}

View File

@ -0,0 +1,55 @@
package net.Indyuce.mmocore.command.rpg.quest;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.PlayerQuests;
import net.Indyuce.mmocore.api.quest.Quest;
import net.Indyuce.mmocore.command.api.CommandEnd;
import net.Indyuce.mmocore.command.api.CommandMap;
import net.Indyuce.mmocore.command.api.Parameter;
public class StartCommandEnd extends CommandEnd {
public StartCommandEnd(CommandMap parent) {
super(parent, "start");
addParameter(Parameter.PLAYER);
addParameter(Parameter.QUEST);
}
@Override
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 4)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[2]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find player called " + args[2] + ".");
return CommandResult.FAILURE;
}
Quest quest = null;
try {
quest = MMOCore.plugin.questManager.get(args[3].replace("_", "-").toLowerCase());
} catch (Exception exception) {
sender.sendMessage(ChatColor.RED + "Could not find quest with ID " + args[3].replace("_", "-").toLowerCase() + ".");
return CommandResult.FAILURE;
}
PlayerQuests quests = PlayerData.get(player).getQuestData();
if (quests.hasCurrent()) {
if (sender instanceof Player)
sender.sendMessage(ChatColor.RED + player.getName() + " already has an ongoing quest.");
return CommandResult.SUCCESS;
}
quests.start(quest);
if (sender instanceof Player)
sender.sendMessage(ChatColor.YELLOW + player.getName() + " successfully started " + quest.getName() + ".");
return CommandResult.SUCCESS;
}
}