mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
Added /mmocore quest commands
This commit is contained in:
parent
1112093bd9
commit
44a76e7dbb
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user