mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-15 07:05:51 +01:00
Replace all unnecessary regex usage
This commit is contained in:
parent
081e14dc64
commit
f7ddf641aa
@ -1244,7 +1244,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
}
|
}
|
||||||
if (found == null) {
|
if (found == null) {
|
||||||
String error = Lang.get("questWGInvalidRegion");
|
String error = Lang.get("questWGInvalidRegion");
|
||||||
error = error.replaceAll("<region>", ChatColor.RED + input + ChatColor.YELLOW);
|
error = error.replace("<region>", ChatColor.RED + input + ChatColor.YELLOW);
|
||||||
player.sendMessage(ChatColor.YELLOW + error);
|
player.sendMessage(ChatColor.YELLOW + error);
|
||||||
return new RegionPrompt();
|
return new RegionPrompt();
|
||||||
} else {
|
} else {
|
||||||
@ -1379,7 +1379,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
|||||||
saveQuest(context, newSection);
|
saveQuest(context, newSection);
|
||||||
data.save(new File(plugin.getDataFolder(), "quests.yml"));
|
data.save(new File(plugin.getDataFolder(), "quests.yml"));
|
||||||
context.getForWhom().sendRawMessage(ChatColor.GREEN
|
context.getForWhom().sendRawMessage(ChatColor.GREEN
|
||||||
+ Lang.get("questEditorSaved").replaceAll("<command>", "/questadmin "
|
+ Lang.get("questEditorSaved").replace("<command>", "/questadmin "
|
||||||
+ Lang.get("COMMAND_QUESTADMIN_RELOAD")));
|
+ Lang.get("COMMAND_QUESTADMIN_RELOAD")));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -330,7 +330,7 @@ public class Action {
|
|||||||
if (commands.isEmpty() == false) {
|
if (commands.isEmpty() == false) {
|
||||||
for (String s : commands) {
|
for (String s : commands) {
|
||||||
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),
|
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),
|
||||||
s.replaceAll("<player>", quester.getPlayer().getName()));
|
s.replace("<player>", quester.getPlayer().getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (potionEffects.isEmpty() == false) {
|
if (potionEffects.isEmpty() == false) {
|
||||||
@ -364,7 +364,7 @@ public class Action {
|
|||||||
quest.failQuest(quester);
|
quest.failQuest(quester);
|
||||||
}
|
}
|
||||||
if (timer > 0) {
|
if (timer > 0) {
|
||||||
player.sendMessage(Lang.get(player, "timerStart").replaceAll("<time>", String.valueOf(timer)));
|
player.sendMessage(Lang.get(player, "timerStart").replace("<time>", String.valueOf(timer)));
|
||||||
if (timer > 60) {
|
if (timer > 60) {
|
||||||
quester.getTimers().put(new ActionTimer(quester, quest, 60, false)
|
quester.getTimers().put(new ActionTimer(quester, quest, 60, false)
|
||||||
.runTaskLater(plugin, (timer-60)*20).getTaskId(), quest);
|
.runTaskLater(plugin, (timer-60)*20).getTaskId(), quest);
|
||||||
|
@ -2705,9 +2705,9 @@ public class ActionFactory implements ConversationAbandonedListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Effect getProperEffect(String properName) {
|
public Effect getProperEffect(String properName) {
|
||||||
properName = properName.replaceAll("_", "").replaceAll(" ", "").toUpperCase();
|
properName = properName.replace("_", "").replace(" ", "").toUpperCase();
|
||||||
for (Effect eff : Effect.values()) {
|
for (Effect eff : Effect.values()) {
|
||||||
if (eff.name().replaceAll("_", "").equalsIgnoreCase(properName)) {
|
if (eff.name().replace("_", "").equalsIgnoreCase(properName)) {
|
||||||
return eff;
|
return eff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,7 +350,7 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
public Prompt acceptInput(ConversationContext cc, String input) {
|
public Prompt acceptInput(ConversationContext cc, String input) {
|
||||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||||
try {
|
try {
|
||||||
double amt = Double.parseDouble(input.replaceAll("UTC", "").replace(":", "."));
|
double amt = Double.parseDouble(input.replace("UTC", "").replace(":", "."));
|
||||||
if (amt < -12.0 || amt > 14.0) {
|
if (amt < -12.0 || amt > 14.0) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
|
||||||
.replace("<least>", "-12:00").replace("<greatest>", "14:00"));
|
.replace("<least>", "-12:00").replace("<greatest>", "14:00"));
|
||||||
|
@ -72,7 +72,7 @@ public class GUIDisplayPrompt extends NumericPrompt {
|
|||||||
if (quest.getGUIDisplay() != null) {
|
if (quest.getGUIDisplay() != null) {
|
||||||
if (ItemUtil.compareItems(stack, quest.getGUIDisplay(), false) == 0) {
|
if (ItemUtil.compareItems(stack, quest.getGUIDisplay(), false) == 0) {
|
||||||
String error = Lang.get("questGUIError");
|
String error = Lang.get("questGUIError");
|
||||||
error = error.replaceAll("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED);
|
error = error.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED);
|
||||||
context.getForWhom().sendRawMessage(ChatColor.RED + error);
|
context.getForWhom().sendRawMessage(ChatColor.RED + error);
|
||||||
failed = true;
|
failed = true;
|
||||||
break;
|
break;
|
||||||
|
@ -427,7 +427,7 @@ public class ItemStackPrompt extends FixedSetPrompt {
|
|||||||
@Override
|
@Override
|
||||||
public String getPromptText(ConversationContext cc) {
|
public String getPromptText(ConversationContext cc) {
|
||||||
String text = Lang.get("itemCreateEnterLevel");
|
String text = Lang.get("itemCreateEnterLevel");
|
||||||
text = text.replaceAll("<enchantment>", enchantment);
|
text = text.replace("<enchantment>", enchantment);
|
||||||
return ChatColor.AQUA + text;
|
return ChatColor.AQUA + text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class MobsPrompt extends FixedSetPrompt {
|
|||||||
= (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES);
|
= (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES);
|
||||||
for (int i = 0; i < mobs.size(); i++) {
|
for (int i = 0; i < mobs.size(); i++) {
|
||||||
String msg = Lang.get("blocksWithin");
|
String msg = Lang.get("blocksWithin");
|
||||||
msg = msg.replaceAll("<amount>", ChatColor.DARK_PURPLE + "" + radii.get(i) + ChatColor.GRAY);
|
msg = msg.replace("<amount>", ChatColor.DARK_PURPLE + "" + radii.get(i) + ChatColor.GRAY);
|
||||||
text += ChatColor.GRAY + " - " + ChatColor.BLUE
|
text += ChatColor.GRAY + " - " + ChatColor.BLUE
|
||||||
+ MiscUtil.getPrettyMobName(MiscUtil.getProperMobType(mobs.get(i))) + ChatColor.GRAY + " x "
|
+ MiscUtil.getPrettyMobName(MiscUtil.getProperMobType(mobs.get(i))) + ChatColor.GRAY + " x "
|
||||||
+ ChatColor.DARK_AQUA + amnts.get(i) + ChatColor.GRAY + msg + ChatColor.YELLOW
|
+ ChatColor.DARK_AQUA + amnts.get(i) + ChatColor.GRAY + msg + ChatColor.YELLOW
|
||||||
|
@ -367,11 +367,11 @@ public class RequirementsPrompt extends NumericPrompt {
|
|||||||
public String getPromptText(ConversationContext context) {
|
public String getPromptText(ConversationContext context) {
|
||||||
String text = Lang.get("reqMoneyPrompt");
|
String text = Lang.get("reqMoneyPrompt");
|
||||||
if (plugin.getDependencies().getVaultEconomy() != null) {
|
if (plugin.getDependencies().getVaultEconomy() != null) {
|
||||||
text = text.replaceAll("<money>", ChatColor.DARK_PURPLE+ ((plugin.getDependencies().getVaultEconomy()
|
text = text.replace("<money>", ChatColor.DARK_PURPLE+ ((plugin.getDependencies().getVaultEconomy()
|
||||||
.currencyNamePlural().isEmpty() ? Lang.get("money") : plugin.getDependencies().getVaultEconomy()
|
.currencyNamePlural().isEmpty() ? Lang.get("money") : plugin.getDependencies().getVaultEconomy()
|
||||||
.currencyNamePlural())) + ChatColor.YELLOW);
|
.currencyNamePlural())) + ChatColor.YELLOW);
|
||||||
} else {
|
} else {
|
||||||
text = text.replaceAll("<money>", ChatColor.DARK_PURPLE + Lang.get("money") + ChatColor.YELLOW);
|
text = text.replace("<money>", ChatColor.DARK_PURPLE + Lang.get("money") + ChatColor.YELLOW);
|
||||||
}
|
}
|
||||||
return ChatColor.YELLOW + text;
|
return ChatColor.YELLOW + text;
|
||||||
}
|
}
|
||||||
@ -468,7 +468,7 @@ public class RequirementsPrompt extends NumericPrompt {
|
|||||||
for (String s : args) {
|
for (String s : args) {
|
||||||
if (plugin.getQuest(s) == null) {
|
if (plugin.getQuest(s) == null) {
|
||||||
String text = Lang.get("reqNotAQuestName");
|
String text = Lang.get("reqNotAQuestName");
|
||||||
text = text.replaceAll("<quest>", ChatColor.LIGHT_PURPLE + s + ChatColor.RED);
|
text = text.replace("<quest>", ChatColor.LIGHT_PURPLE + s + ChatColor.RED);
|
||||||
context.getForWhom().sendRawMessage(text);
|
context.getForWhom().sendRawMessage(text);
|
||||||
return new QuestListPrompt(isRequiredQuest);
|
return new QuestListPrompt(isRequiredQuest);
|
||||||
}
|
}
|
||||||
@ -628,7 +628,7 @@ public class RequirementsPrompt extends NumericPrompt {
|
|||||||
booleans.add(false);
|
booleans.add(false);
|
||||||
} else {
|
} else {
|
||||||
String text = Lang.get("reqTrueFalseError");
|
String text = Lang.get("reqTrueFalseError");
|
||||||
text = text.replaceAll("<input>", ChatColor.LIGHT_PURPLE + s + ChatColor.RED);
|
text = text.replace("<input>", ChatColor.LIGHT_PURPLE + s + ChatColor.RED);
|
||||||
context.getForWhom().sendRawMessage(ChatColor.RED + text);
|
context.getForWhom().sendRawMessage(ChatColor.RED + text);
|
||||||
return new RemoveItemsPrompt();
|
return new RemoveItemsPrompt();
|
||||||
}
|
}
|
||||||
@ -823,7 +823,7 @@ public class RequirementsPrompt extends NumericPrompt {
|
|||||||
text += ChatColor.GOLD + descriptions.get(temp) + "\n";
|
text += ChatColor.GOLD + descriptions.get(temp) + "\n";
|
||||||
}
|
}
|
||||||
String lang = Lang.get("stageEditorCustomDataPrompt");
|
String lang = Lang.get("stageEditorCustomDataPrompt");
|
||||||
lang = lang.replaceAll("<data>", temp);
|
lang = lang.replace("<data>", temp);
|
||||||
text += ChatColor.YELLOW + lang;
|
text += ChatColor.YELLOW + lang;
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@ -921,7 +921,7 @@ public class RequirementsPrompt extends NumericPrompt {
|
|||||||
return new mcMMOSkillsPrompt();
|
return new mcMMOSkillsPrompt();
|
||||||
} else {
|
} else {
|
||||||
String text = Lang.get("reqMcMMOError");
|
String text = Lang.get("reqMcMMOError");
|
||||||
text = text.replaceAll("<input>", ChatColor.RED + s + ChatColor.YELLOW);
|
text = text.replace("<input>", ChatColor.RED + s + ChatColor.YELLOW);
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.YELLOW + text);
|
cc.getForWhom().sendRawMessage(ChatColor.YELLOW + text);
|
||||||
return new mcMMOSkillsPrompt();
|
return new mcMMOSkillsPrompt();
|
||||||
}
|
}
|
||||||
@ -957,7 +957,7 @@ public class RequirementsPrompt extends NumericPrompt {
|
|||||||
amounts.add(i);
|
amounts.add(i);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
String text = Lang.get("reqNotANumber");
|
String text = Lang.get("reqNotANumber");
|
||||||
text = text.replaceAll("<input>", ChatColor.RED + s + ChatColor.YELLOW);
|
text = text.replace("<input>", ChatColor.RED + s + ChatColor.YELLOW);
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.YELLOW + text);
|
cc.getForWhom().sendRawMessage(ChatColor.YELLOW + text);
|
||||||
return new mcMMOAmountsPrompt();
|
return new mcMMOAmountsPrompt();
|
||||||
}
|
}
|
||||||
@ -1052,7 +1052,7 @@ public class RequirementsPrompt extends NumericPrompt {
|
|||||||
return new HeroesPrompt();
|
return new HeroesPrompt();
|
||||||
} else {
|
} else {
|
||||||
String text = Lang.get("reqHeroesNotPrimary");
|
String text = Lang.get("reqHeroesNotPrimary");
|
||||||
text = text.replaceAll("<class>", ChatColor.LIGHT_PURPLE + hc.getName() + ChatColor.RED);
|
text = text.replace("<class>", ChatColor.LIGHT_PURPLE + hc.getName() + ChatColor.RED);
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + text);
|
cc.getForWhom().sendRawMessage(ChatColor.RED + text);
|
||||||
return new HeroesPrimaryPrompt();
|
return new HeroesPrimaryPrompt();
|
||||||
}
|
}
|
||||||
@ -1104,7 +1104,7 @@ public class RequirementsPrompt extends NumericPrompt {
|
|||||||
return new HeroesPrompt();
|
return new HeroesPrompt();
|
||||||
} else {
|
} else {
|
||||||
String text = Lang.get("reqHeroesNotSecondary");
|
String text = Lang.get("reqHeroesNotSecondary");
|
||||||
text = text.replaceAll("<class>", ChatColor.LIGHT_PURPLE + hc.getName() + ChatColor.RED);
|
text = text.replace("<class>", ChatColor.LIGHT_PURPLE + hc.getName() + ChatColor.RED);
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + text);
|
cc.getForWhom().sendRawMessage(ChatColor.RED + text);
|
||||||
return new HeroesSecondaryPrompt();
|
return new HeroesSecondaryPrompt();
|
||||||
}
|
}
|
||||||
|
@ -1792,7 +1792,7 @@ public class StageMainPrompt extends NumericPrompt {
|
|||||||
text += ChatColor.GOLD + descriptions.get(temp) + "\n";
|
text += ChatColor.GOLD + descriptions.get(temp) + "\n";
|
||||||
}
|
}
|
||||||
String msg = Lang.get("stageEditorCustomDataPrompt");
|
String msg = Lang.get("stageEditorCustomDataPrompt");
|
||||||
msg = msg.replaceAll("<data>", ChatColor.BOLD + temp + ChatColor.RESET + ChatColor.YELLOW);
|
msg = msg.replace("<data>", ChatColor.BOLD + temp + ChatColor.RESET + ChatColor.YELLOW);
|
||||||
text += ChatColor.YELLOW + msg;
|
text += ChatColor.YELLOW + msg;
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ public class Lang {
|
|||||||
public static String getModified(String key, String[] tokens) {
|
public static String getModified(String key, String[] tokens) {
|
||||||
String orig = langMap.get(key);
|
String orig = langMap.get(key);
|
||||||
for (int i = 0; i < tokens.length; i++) {
|
for (int i = 0; i < tokens.length; i++) {
|
||||||
orig = orig.replaceAll("%" + (i + 1), tokens[i]);
|
orig = orig.replace("%" + (i + 1), tokens[i]);
|
||||||
}
|
}
|
||||||
return orig;
|
return orig;
|
||||||
}
|
}
|
||||||
@ -182,30 +182,30 @@ public class Lang {
|
|||||||
String cmdCancel = allStrings.get("cmdCancel");
|
String cmdCancel = allStrings.get("cmdCancel");
|
||||||
String cmdDone = allStrings.get("cmdDone");
|
String cmdDone = allStrings.get("cmdDone");
|
||||||
|
|
||||||
String strAdd = allStrings.get("strAdd").replaceAll("<command>", cmdAdd);
|
String strAdd = allStrings.get("strAdd").replace("<command>", cmdAdd);
|
||||||
String strClear = allStrings.get("strClear").replaceAll("<command>", cmdClear);
|
String strClear = allStrings.get("strClear").replace("<command>", cmdClear);
|
||||||
String strCancel = allStrings.get("strCancel").replaceAll("<command>", cmdCancel);
|
String strCancel = allStrings.get("strCancel").replace("<command>", cmdCancel);
|
||||||
String strDone = allStrings.get("strDone").replaceAll("<command>", cmdDone);
|
String strDone = allStrings.get("strDone").replace("<command>", cmdDone);
|
||||||
String strSpace = allStrings.get("strSpace");
|
String strSpace = allStrings.get("strSpace");
|
||||||
String strSemicolon = allStrings.get("strSemicolon");
|
String strSemicolon = allStrings.get("strSemicolon");
|
||||||
for (Entry<String, String> entry : allStrings.entrySet()) {
|
for (Entry<String, String> entry : allStrings.entrySet()) {
|
||||||
if (entry.getValue().contains("<add>")) {
|
if (entry.getValue().contains("<add>")) {
|
||||||
allStrings.put(entry.getKey(), entry.getValue().replaceAll("<add>", strAdd));
|
allStrings.put(entry.getKey(), entry.getValue().replace("<add>", strAdd));
|
||||||
}
|
}
|
||||||
if (entry.getValue().contains("<clear>")) {
|
if (entry.getValue().contains("<clear>")) {
|
||||||
allStrings.put(entry.getKey(), entry.getValue().replaceAll("<clear>", strClear));
|
allStrings.put(entry.getKey(), entry.getValue().replace("<clear>", strClear));
|
||||||
}
|
}
|
||||||
if (entry.getValue().contains("<cancel>")) {
|
if (entry.getValue().contains("<cancel>")) {
|
||||||
allStrings.put(entry.getKey(), entry.getValue().replaceAll("<cancel>", strCancel));
|
allStrings.put(entry.getKey(), entry.getValue().replace("<cancel>", strCancel));
|
||||||
}
|
}
|
||||||
if (entry.getValue().contains("<done>")) {
|
if (entry.getValue().contains("<done>")) {
|
||||||
allStrings.put(entry.getKey(), entry.getValue().replaceAll("<done>", strDone));
|
allStrings.put(entry.getKey(), entry.getValue().replace("<done>", strDone));
|
||||||
}
|
}
|
||||||
if (entry.getValue().contains("<space>")) {
|
if (entry.getValue().contains("<space>")) {
|
||||||
allStrings.put(entry.getKey(), entry.getValue().replaceAll("<space>", strSpace));
|
allStrings.put(entry.getKey(), entry.getValue().replace("<space>", strSpace));
|
||||||
}
|
}
|
||||||
if (entry.getValue().contains("<semicolon>")) {
|
if (entry.getValue().contains("<semicolon>")) {
|
||||||
allStrings.put(entry.getKey(), entry.getValue().replaceAll("<semicolon>", strSemicolon));
|
allStrings.put(entry.getKey(), entry.getValue().replace("<semicolon>", strSemicolon));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
langMap.putAll(allStrings);
|
langMap.putAll(allStrings);
|
||||||
|
@ -248,13 +248,15 @@ public class MiscUtil {
|
|||||||
* @param lineColor Color to use at start of each new line
|
* @param lineColor Color to use at start of each new line
|
||||||
* @return Converted text
|
* @return Converted text
|
||||||
*/
|
*/
|
||||||
public static LinkedList<String> makeLines(String input, String wordDelimiter, int lineLength, ChatColor lineColor) {
|
public static LinkedList<String> makeLines(String input, String wordDelimiter, int lineLength
|
||||||
|
, ChatColor lineColor) {
|
||||||
LinkedList<String> toReturn = new LinkedList<String>();
|
LinkedList<String> toReturn = new LinkedList<String>();
|
||||||
String[] split = input.split(wordDelimiter);
|
String[] split = input.split(wordDelimiter);
|
||||||
String line = "";
|
String line = "";
|
||||||
int currentLength = 0;
|
int currentLength = 0;
|
||||||
for (String piece : split) {
|
for (String piece : split) {
|
||||||
if ((currentLength + piece.length()) > (lineLength + 1)) {
|
if ((currentLength + piece.length()) > (lineLength + 1)) {
|
||||||
|
// TODO - determine whether replaceAll and carots (^) are necessary here
|
||||||
if (lineColor != null) {
|
if (lineColor != null) {
|
||||||
toReturn.add(lineColor + line.replaceAll("^" + wordDelimiter, ""));
|
toReturn.add(lineColor + line.replaceAll("^" + wordDelimiter, ""));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user