mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-28 05:35:33 +01:00
Better support for quest names with color codes
This commit is contained in:
parent
946779b17e
commit
2360f68eda
@ -316,24 +316,11 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
for (Quest q : plugin.getQuests()) {
|
||||
if (q.getName().equalsIgnoreCase(input)) {
|
||||
Quest q = plugin.getQuest(input);
|
||||
if (q != null) {
|
||||
loadQuest(context, q);
|
||||
return new CreateMenuPrompt();
|
||||
}
|
||||
}
|
||||
for (Quest q : plugin.getQuests()) {
|
||||
if (q.getName().toLowerCase().startsWith(input.toLowerCase())) {
|
||||
loadQuest(context, q);
|
||||
return new CreateMenuPrompt();
|
||||
}
|
||||
}
|
||||
for (Quest q : plugin.getQuests()) {
|
||||
if (q.getName().toLowerCase().contains(input.toLowerCase())) {
|
||||
loadQuest(context, q);
|
||||
return new CreateMenuPrompt();
|
||||
}
|
||||
}
|
||||
return new SelectEditPrompt();
|
||||
} else {
|
||||
return new MenuPrompt();
|
||||
@ -533,10 +520,10 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
String text = ChatColor.DARK_GREEN + Lang.get("eventTitle") + "\n";
|
||||
if (plugin.getEvents().isEmpty()) {
|
||||
if (plugin.getActions().isEmpty()) {
|
||||
text += ChatColor.RED + "- " + Lang.get("none");
|
||||
} else {
|
||||
for (Action e : plugin.getEvents()) {
|
||||
for (Action e : plugin.getActions()) {
|
||||
text += ChatColor.GREEN + "- " + e.getName() + "\n";
|
||||
}
|
||||
}
|
||||
@ -547,20 +534,13 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
Player player = (Player) context.getForWhom();
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
|
||||
Action found = null;
|
||||
for (Action e : plugin.getEvents()) {
|
||||
if (e.getName().equalsIgnoreCase(input)) {
|
||||
found = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == null) {
|
||||
player.sendMessage(ChatColor.RED + input + ChatColor.YELLOW + " " + Lang.get("questEditorInvalidEventName"));
|
||||
return new InitialEventPrompt();
|
||||
} else {
|
||||
context.setSessionData(CK.Q_INITIAL_EVENT, found.getName());
|
||||
Action a = plugin.getAction(input);
|
||||
if (a != null) {
|
||||
context.setSessionData(CK.Q_INITIAL_EVENT, a.getName());
|
||||
return new CreateMenuPrompt();
|
||||
}
|
||||
player.sendMessage(ChatColor.RED + input + ChatColor.YELLOW + " " + Lang.get("questEditorInvalidEventName"));
|
||||
return new InitialEventPrompt();
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(CK.Q_INITIAL_EVENT, null);
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get("questEditorEventCleared"));
|
||||
|
@ -277,10 +277,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
return quests;
|
||||
}
|
||||
|
||||
public LinkedList<Action> getActions() {
|
||||
return events;
|
||||
}
|
||||
|
||||
public void setActions(LinkedList<Action> actions) {
|
||||
this.events = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use getActions()
|
||||
*/
|
||||
public LinkedList<Action> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use setActions()
|
||||
*/
|
||||
public void setEvents(LinkedList<Action> events) {
|
||||
this.events = events;
|
||||
}
|
||||
@ -3202,10 +3216,19 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
* @return Quest or null if not found
|
||||
*/
|
||||
public Quest getQuest(String name) {
|
||||
for (Quest q : quests) {
|
||||
if (q.getName().equalsIgnoreCase(name)) {
|
||||
LinkedList<Quest> qs = quests;
|
||||
for (Quest q : qs) {
|
||||
if (q.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) {
|
||||
return q;
|
||||
} else if (q.getName().toLowerCase().startsWith(name.toLowerCase())) {
|
||||
}
|
||||
}
|
||||
for (Quest q : qs) {
|
||||
if (q.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) {
|
||||
return q;
|
||||
}
|
||||
}
|
||||
for (Quest q : qs) {
|
||||
if (q.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) {
|
||||
return q;
|
||||
}
|
||||
}
|
||||
@ -3219,11 +3242,20 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
* @return Action or null if not found
|
||||
*/
|
||||
public Action getAction(String name) {
|
||||
for (Action e : events) {
|
||||
if (e.getName().equalsIgnoreCase(name)){
|
||||
return e;
|
||||
} else if (e.getName().toLowerCase().startsWith(name.toLowerCase())) {
|
||||
return e;
|
||||
LinkedList<Action> as = events;
|
||||
for (Action a : as) {
|
||||
if (a.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
for (Action a : as) {
|
||||
if (a.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
for (Action a : as) {
|
||||
if (a.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -167,7 +167,7 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("2")) {
|
||||
if (player.hasPermission("quests.editor.actions.edit") || player.hasPermission("quests.editor.events.edit")) {
|
||||
if (plugin.getEvents().isEmpty()) {
|
||||
if (plugin.getActions().isEmpty()) {
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + Lang.get("eventEditorNoneToEdit"));
|
||||
return new MenuPrompt();
|
||||
} else {
|
||||
@ -179,7 +179,7 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("3")) {
|
||||
if (player.hasPermission("quests.editor.actions.delete") || player.hasPermission("quests.editor.events.delete")) {
|
||||
if (plugin.getEvents().isEmpty()) {
|
||||
if (plugin.getActions().isEmpty()) {
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.YELLOW + Lang.get("eventEditorNoneToDelete"));
|
||||
return new MenuPrompt();
|
||||
} else {
|
||||
@ -329,8 +329,8 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
String text = ChatColor.GOLD + "- " + Lang.get("eventEditorEdit") + " -\n";
|
||||
for (Action evt : plugin.getEvents()) {
|
||||
text += ChatColor.AQUA + evt.getName() + ChatColor.YELLOW + ", ";
|
||||
for (Action a : plugin.getActions()) {
|
||||
text += ChatColor.AQUA + a.getName() + ChatColor.YELLOW + ", ";
|
||||
}
|
||||
text = text.substring(0, text.length() - 2) + "\n";
|
||||
text += ChatColor.YELLOW + Lang.get("eventEditorEnterEventName");
|
||||
@ -340,14 +340,13 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
for (Action evt : plugin.getEvents()) {
|
||||
if (evt.getName().toLowerCase().startsWith(input.toLowerCase())) {
|
||||
context.setSessionData(CK.E_OLD_EVENT, evt.getName());
|
||||
context.setSessionData(CK.E_NAME, evt.getName());
|
||||
loadData(evt, context);
|
||||
Action a = plugin.getAction(input);
|
||||
if (a != null) {
|
||||
context.setSessionData(CK.E_OLD_EVENT, a.getName());
|
||||
context.setSessionData(CK.E_NAME, a.getName());
|
||||
loadData(a, context);
|
||||
return new CreateMenuPrompt();
|
||||
}
|
||||
}
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorNotFound"));
|
||||
return new SelectEditPrompt();
|
||||
} else {
|
||||
@ -361,8 +360,8 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
String text = ChatColor.GOLD + "- " + Lang.get("eventEditorDelete") + " -\n";
|
||||
for (Action evt : plugin.getEvents()) {
|
||||
text += ChatColor.AQUA + evt.getName() + ChatColor.YELLOW + ",";
|
||||
for (Action a : plugin.getActions()) {
|
||||
text += ChatColor.AQUA + a.getName() + ChatColor.YELLOW + ",";
|
||||
}
|
||||
text = text.substring(0, text.length() - 1) + "\n";
|
||||
text += ChatColor.YELLOW + Lang.get("eventEditorEnterEventName");
|
||||
@ -373,21 +372,21 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
LinkedList<String> used = new LinkedList<String>();
|
||||
for (Action evt : plugin.getEvents()) {
|
||||
if (evt.getName().equalsIgnoreCase(input)) {
|
||||
Action a = plugin.getAction(input);
|
||||
if (a != null) {
|
||||
for (Quest quest : plugin.getQuests()) {
|
||||
for (Stage stage : quest.getStages()) {
|
||||
if (stage.getFinishEvent() != null && stage.getFinishEvent().getName().equalsIgnoreCase(evt.getName())) {
|
||||
if (stage.getFinishEvent() != null && stage.getFinishEvent().getName().equalsIgnoreCase(a.getName())) {
|
||||
used.add(quest.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (used.isEmpty()) {
|
||||
context.setSessionData(CK.ED_EVENT_DELETE, evt.getName());
|
||||
context.setSessionData(CK.ED_EVENT_DELETE, a.getName());
|
||||
return new DeletePrompt();
|
||||
} else {
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorEventInUse") + " \"" + ChatColor.DARK_PURPLE + evt.getName() + ChatColor.RED + "\":");
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorEventInUse") + " \"" + ChatColor.DARK_PURPLE + a.getName() + ChatColor.RED + "\":");
|
||||
for (String s : used) {
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + "- " + ChatColor.DARK_RED + s);
|
||||
}
|
||||
@ -395,7 +394,6 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
return new SelectDeletePrompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
((Player) context.getForWhom()).sendMessage(ChatColor.RED + Lang.get("eventEditorNotFound"));
|
||||
return new SelectDeletePrompt();
|
||||
} else {
|
||||
@ -913,9 +911,9 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
}
|
||||
if (((String) context.getSessionData(CK.E_OLD_EVENT)).isEmpty() == false) {
|
||||
data.set(key + "." + (String) context.getSessionData(CK.E_OLD_EVENT), null);
|
||||
LinkedList<Action> temp = plugin.getEvents();
|
||||
LinkedList<Action> temp = plugin.getActions();
|
||||
temp.remove(plugin.getAction((String) context.getSessionData(CK.E_OLD_EVENT)));
|
||||
plugin.setEvents(temp);
|
||||
plugin.setActions(temp);
|
||||
}
|
||||
ConfigurationSection section = data.createSection(key + "." + (String) context.getSessionData(CK.E_NAME));
|
||||
names.remove((String) context.getSessionData(CK.E_NAME));
|
||||
@ -1067,7 +1065,7 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
for (Action e : plugin.getEvents()) {
|
||||
for (Action e : plugin.getActions()) {
|
||||
if (e.getName().equalsIgnoreCase(input)) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorExists"));
|
||||
return new ActionNamePrompt();
|
||||
@ -1142,7 +1140,7 @@ public class ActionFactory implements ConversationAbandonedListener {
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
for (Action e : plugin.getEvents()) {
|
||||
for (Action e : plugin.getActions()) {
|
||||
if (e.getName().equalsIgnoreCase(input)) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorExists"));
|
||||
return new SetNamePrompt();
|
||||
|
@ -619,17 +619,17 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
if (quester.getCurrentQuests().isEmpty() == false) {
|
||||
Quest q = plugin.getQuest(MiscUtil.concatArgArray(args, 1, args.length - 1, ' '));
|
||||
if (q != null) {
|
||||
if (q.getOptions().getAllowQuitting()) {
|
||||
QuestQuitEvent event = new QuestQuitEvent(q, quester);
|
||||
Quest quest = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' '));
|
||||
if (quest != null) {
|
||||
if (quest.getOptions().getAllowQuitting()) {
|
||||
QuestQuitEvent event = new QuestQuitEvent(quest, quester);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
quester.hardQuit(q);
|
||||
quester.hardQuit(quest);
|
||||
String msg = Lang.get("questQuit");
|
||||
msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + q.getName() + ChatColor.YELLOW);
|
||||
msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW);
|
||||
player.sendMessage(ChatColor.YELLOW + msg);
|
||||
quester.saveData();
|
||||
quester.loadData();
|
||||
@ -654,32 +654,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
if (args.length == 1) {
|
||||
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE"));
|
||||
} else {
|
||||
String name = null;
|
||||
if (args.length == 2) {
|
||||
name = args[1].toLowerCase();
|
||||
} else {
|
||||
boolean first = true;
|
||||
int lastIndex = (args.length - 1);
|
||||
int index = 0;
|
||||
for (String s : args) {
|
||||
if (index != 0) {
|
||||
if (first) {
|
||||
first = false;
|
||||
if (args.length > 2) {
|
||||
name = s.toLowerCase() + " ";
|
||||
} else {
|
||||
name = s.toLowerCase();
|
||||
}
|
||||
} else if (index == lastIndex) {
|
||||
name = name + s.toLowerCase();
|
||||
} else {
|
||||
name = name + s.toLowerCase() + " ";
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
Quest questToFind = plugin.getQuest(name);
|
||||
Quest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' '));
|
||||
if (questToFind != null) {
|
||||
final Quest q = questToFind;
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
@ -1168,7 +1143,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
msg = msg.replace("<player>", target.getName());
|
||||
cs.sendMessage(ChatColor.YELLOW + msg);
|
||||
} else {
|
||||
Quest quest = plugin.getQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' '));
|
||||
Quest quest = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' '));
|
||||
if (quest == null) {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("questNotFound"));
|
||||
return;
|
||||
@ -1228,7 +1203,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
msg = msg.replace("<player>", target.getName());
|
||||
cs.sendMessage(ChatColor.YELLOW + msg);
|
||||
} else {
|
||||
Quest quest = plugin.getQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' '));
|
||||
Quest quest = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' '));
|
||||
if (quest == null) {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("questNotFound"));
|
||||
return;
|
||||
@ -1266,7 +1241,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
msg = msg.replace("<player>", target.getName());
|
||||
cs.sendMessage(ChatColor.YELLOW + msg);
|
||||
} else {
|
||||
Quest quest = plugin.getQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' '));
|
||||
Quest quest = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' '));
|
||||
if (quest == null) {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("questNotFound"));
|
||||
return;
|
||||
@ -1307,7 +1282,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
msg = msg.replace("<player>", target.getName());
|
||||
cs.sendMessage(ChatColor.YELLOW + msg);
|
||||
} else {
|
||||
Quest quest = plugin.getQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' '));
|
||||
Quest quest = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' '));
|
||||
if (quest == null) {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("questNotFound"));
|
||||
return;
|
||||
@ -1392,7 +1367,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
Quest toRemove = plugin.getQuest(MiscUtil.concatArgArray(args, 2, args.length - 1, ' '));
|
||||
Quest toRemove = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' '));
|
||||
if (toRemove == null) {
|
||||
cs.sendMessage(ChatColor.RED + Lang.get("questNotFound"));
|
||||
return;
|
||||
@ -1503,4 +1478,22 @@ public class CmdExecutor implements CommandExecutor {
|
||||
}
|
||||
return sortedMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get quest names that contain spaces from command input
|
||||
*
|
||||
* @param args an array of Strings
|
||||
* @param startingIndex the index to start combining at
|
||||
* @param endingIndex the index to stop combining at
|
||||
* @param delimiter the character for which the array was split
|
||||
* @return a String or null
|
||||
*/
|
||||
private static String concatArgArray(String[] args, int startingIndex, int endingIndex, char delimiter) {
|
||||
String s = "";
|
||||
for (int i = startingIndex; i <= endingIndex; i++) {
|
||||
s += args[i] + delimiter;
|
||||
}
|
||||
s = s.substring(0, s.length());
|
||||
return s.trim().equals("") ? null : s.trim();
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +135,9 @@ public class MiscUtil {
|
||||
return Lang.get("COLOR_" + dc.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Will be removed in a future version of Quests
|
||||
*/
|
||||
public static String concatArgArray(String[] args, int startingIndex, int endingIndex, char delimiter) {
|
||||
String s = "";
|
||||
for (int i = startingIndex; i <= endingIndex; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user