mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-30 01:13:38 +01:00
Added /mmocore quest <cancel/start> <player> <quest>
This commit is contained in:
parent
d8f1e8d9e9
commit
1112093bd9
@ -39,7 +39,7 @@ public class Quest {
|
|||||||
private FileConfiguration loaded;
|
private FileConfiguration loaded;
|
||||||
|
|
||||||
public Quest(String id, FileConfiguration config) {
|
public Quest(String id, FileConfiguration config) {
|
||||||
this.id = id;
|
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
|
||||||
loaded = config;
|
loaded = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import net.Indyuce.mmocore.command.rpg.ReloadCommandMap;
|
|||||||
import net.Indyuce.mmocore.command.rpg.admin.AdminCommandMap;
|
import net.Indyuce.mmocore.command.rpg.admin.AdminCommandMap;
|
||||||
import net.Indyuce.mmocore.command.rpg.booster.BoosterCommandMap;
|
import net.Indyuce.mmocore.command.rpg.booster.BoosterCommandMap;
|
||||||
import net.Indyuce.mmocore.command.rpg.debug.DebugCommandMap;
|
import net.Indyuce.mmocore.command.rpg.debug.DebugCommandMap;
|
||||||
|
import net.Indyuce.mmocore.command.rpg.quest.QuestCommandMap;
|
||||||
import net.Indyuce.mmocore.command.rpg.waypoint.WaypointsCommandMap;
|
import net.Indyuce.mmocore.command.rpg.waypoint.WaypointsCommandMap;
|
||||||
|
|
||||||
public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabCompleter {
|
public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabCompleter {
|
||||||
@ -29,6 +30,7 @@ public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabC
|
|||||||
addFloor(new DebugCommandMap(this));
|
addFloor(new DebugCommandMap(this));
|
||||||
addFloor(new BoosterCommandMap(this));
|
addFloor(new BoosterCommandMap(this));
|
||||||
addFloor(new WaypointsCommandMap(this));
|
addFloor(new WaypointsCommandMap(this));
|
||||||
|
addFloor(new QuestCommandMap(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,7 +52,7 @@ public class MMOCoreCommand extends CommandRoot implements CommandExecutor, TabC
|
|||||||
if (!sender.hasPermission("mmocore.admin"))
|
if (!sender.hasPermission("mmocore.admin"))
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|
||||||
CommandReader reader = readCommand(args);
|
CommandParser reader = readCommand(args);
|
||||||
List<String> list = reader.readTabCompletion();
|
List<String> list = reader.readTabCompletion();
|
||||||
return args[args.length - 1].isEmpty() ? list : list.stream().filter(string -> string.toLowerCase().startsWith(args[args.length - 1].toLowerCase())).collect(Collectors.toList());
|
return args[args.length - 1].isEmpty() ? list : list.stream().filter(string -> string.toLowerCase().startsWith(args[args.length - 1].toLowerCase())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public abstract class CommandMap {
|
public abstract class CommandMap {
|
||||||
@ -14,7 +15,15 @@ public abstract class CommandMap {
|
|||||||
private final String id;
|
private final String id;
|
||||||
private final CommandMap parent;
|
private final CommandMap parent;
|
||||||
|
|
||||||
|
public static final CommandMap EMPTY = new CommandMap(null, "empty") {
|
||||||
|
public CommandResult execute(CommandSender sender, String[] args) {
|
||||||
|
return CommandResult.THROW_USAGE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public CommandMap(CommandMap parent, String id) {
|
public CommandMap(CommandMap parent, String id) {
|
||||||
|
Validate.isTrue(!(parent instanceof CommandEnd), "You cannot use a CommandEnd as a parent");
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
@ -47,26 +56,28 @@ public abstract class CommandMap {
|
|||||||
floors.put(floor.getId(), floor);
|
floors.put(floor.getId(), floor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract CommandResult execute(CommandSender sender, String[] args);
|
|
||||||
|
|
||||||
public Set<String> getKeys() {
|
public Set<String> getKeys() {
|
||||||
return floors.keySet();
|
return floors.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> calculateTabCompletion(int n) {
|
public abstract CommandResult execute(CommandSender sender, String[] args);
|
||||||
|
|
||||||
|
public List<String> calculateTabCompletion(int parameterIndex) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* add extra floor keys
|
* add extra floor keys. only commandEnds can have parameters, that
|
||||||
|
* means commands must be clean and cannot have both floors and
|
||||||
|
* parameters to input
|
||||||
*/
|
*/
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
getKeys().forEach(key -> list.add(key));
|
getKeys().forEach(key -> list.add(key));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* add final arguments if needed.
|
* if the player is at the end of a command branch, display the
|
||||||
|
* parameter with the right index that the player must input
|
||||||
*/
|
*/
|
||||||
if (isEnd())
|
if (isEnd() && ((CommandEnd) this).getParameters().size() > parameterIndex)
|
||||||
if (((CommandEnd) this).getParameters().size() > n)
|
((CommandEnd) this).getParameters().get(parameterIndex).autoComplete(list);
|
||||||
((CommandEnd) this).getParameters().get(n).autoComplete(list);
|
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.Indyuce.mmocore.command.api;
|
package net.Indyuce.mmocore.command.api;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -18,29 +17,33 @@ public abstract class CommandRoot extends CommandMap {
|
|||||||
read.calculateUsageList().forEach(str -> sender.sendMessage(ChatColor.YELLOW + "/" + str));
|
read.calculateUsageList().forEach(str -> sender.sendMessage(ChatColor.YELLOW + "/" + str));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandReader readCommand(String[] args) {
|
public CommandParser readCommand(String[] args) {
|
||||||
return new CommandReader(this, args);
|
return new CommandParser(this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CommandReader {
|
public class CommandParser {
|
||||||
private CommandMap current;
|
private CommandMap current;
|
||||||
private int parameter = 0;
|
private int parameter = 0;
|
||||||
|
|
||||||
public CommandReader(CommandRoot begin, String[] args) {
|
/*
|
||||||
|
* used to parse a command and identify the commandMap which is supposed
|
||||||
|
* to
|
||||||
|
*/
|
||||||
|
public CommandParser(CommandRoot begin, String[] args) {
|
||||||
this.current = begin;
|
this.current = begin;
|
||||||
|
|
||||||
for (String arg : args)
|
for (String arg : args)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check if current command map has the corresponding arg, if so
|
* check if current command floor has the corresponding arg, if
|
||||||
* let the next map handle the command.
|
* so let the next floor handle the command.
|
||||||
*/
|
*/
|
||||||
if (parameter == 0 && current.hasFloor(arg))
|
if (parameter == 0 && current.hasFloor(arg))
|
||||||
current = current.getFloor(arg);
|
current = current.getFloor(arg);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if the plugin cannot find a command map higher, then the
|
* if the plugin cannot find a command map higher, then the
|
||||||
* current map will handle the command.
|
* current floor will handle the command.
|
||||||
*/
|
*/
|
||||||
else
|
else
|
||||||
parameter++;
|
parameter++;
|
||||||
@ -55,7 +58,7 @@ public abstract class CommandRoot extends CommandMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> readTabCompletion() {
|
public List<String> readTabCompletion() {
|
||||||
return parameter < 0 ? new ArrayList<>() : current.calculateTabCompletion(Math.max(0, parameter - 1));
|
return current.calculateTabCompletion(Math.max(0, parameter - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,10 @@ public class Parameter {
|
|||||||
list.add("main");
|
list.add("main");
|
||||||
});
|
});
|
||||||
public static final Parameter PLAYER = new Parameter("<player>", list -> Bukkit.getOnlinePlayers().forEach(online -> list.add(online.getName())));
|
public static final Parameter PLAYER = new Parameter("<player>", list -> Bukkit.getOnlinePlayers().forEach(online -> list.add(online.getName())));
|
||||||
public static final Parameter PLAYER_OPTIONAL = new Parameter("(player)", list -> Bukkit.getOnlinePlayers().forEach(online -> list.add(online.getName())));
|
public static final Parameter QUEST = new Parameter("<quest>",
|
||||||
|
list -> MMOCore.plugin.questManager.getAll().forEach(quest -> list.add(quest.getId())));
|
||||||
|
public static final Parameter PLAYER_OPTIONAL = new Parameter("(player)",
|
||||||
|
list -> Bukkit.getOnlinePlayers().forEach(online -> list.add(online.getName())));
|
||||||
public static final Parameter AMOUNT = new Parameter("<amount>", list -> {
|
public static final Parameter AMOUNT = new Parameter("<amount>", list -> {
|
||||||
for (int j = 0; j <= 10; j++)
|
for (int j = 0; j <= 10; j++)
|
||||||
list.add("" + j);
|
list.add("" + j);
|
||||||
|
@ -15,7 +15,7 @@ import net.Indyuce.mmocore.command.api.CommandEnd;
|
|||||||
import net.Indyuce.mmocore.command.api.CommandMap;
|
import net.Indyuce.mmocore.command.api.CommandMap;
|
||||||
import net.Indyuce.mmocore.command.api.Parameter;
|
import net.Indyuce.mmocore.command.api.Parameter;
|
||||||
|
|
||||||
public class ExperienceCommandMap extends CommandEnd {
|
public class ExperienceCommandMap extends CommandMap {
|
||||||
public ExperienceCommandMap(CommandMap parent) {
|
public ExperienceCommandMap(CommandMap parent) {
|
||||||
super(parent, "exp");
|
super(parent, "exp");
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import net.Indyuce.mmocore.command.api.CommandEnd;
|
|||||||
import net.Indyuce.mmocore.command.api.CommandMap;
|
import net.Indyuce.mmocore.command.api.CommandMap;
|
||||||
import net.Indyuce.mmocore.command.api.Parameter;
|
import net.Indyuce.mmocore.command.api.Parameter;
|
||||||
|
|
||||||
public class ResetCommandMap extends CommandEnd {
|
public class ResetCommandMap extends CommandMap {
|
||||||
public ResetCommandMap(CommandMap parent) {
|
public ResetCommandMap(CommandMap parent) {
|
||||||
super(parent, "reset");
|
super(parent, "reset");
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import net.Indyuce.mmocore.MMOCore;
|
|||||||
import net.Indyuce.mmocore.api.quest.Quest;
|
import net.Indyuce.mmocore.api.quest.Quest;
|
||||||
|
|
||||||
public class QuestManager extends MMOManager {
|
public class QuestManager extends MMOManager {
|
||||||
private Map<String, Quest> quests = new LinkedHashMap<>();
|
private final Map<String, Quest> quests = new LinkedHashMap<>();
|
||||||
|
|
||||||
public void load(File file) {
|
public void load(File file) {
|
||||||
if (file.isDirectory())
|
if (file.isDirectory())
|
||||||
|
Loading…
Reference in New Issue
Block a user