Create separate utility class for config

This commit is contained in:
PikaMug 2019-11-05 18:32:52 -05:00
parent 55cef01b94
commit 0eb9c36386
19 changed files with 362 additions and 241 deletions

View File

@ -48,7 +48,7 @@ public class Dependencies {
private static mcMMO mcmmo = null;
private static Heroes heroes = null;
private static PhatLoots phatLoots = null;
private static PlaceholderAPIPlugin placeholder = null;
public static PlaceholderAPIPlugin placeholder = null;
private static CitizensPlugin citizens = null;
private static DenizenAPI denizenApi = null;
private static CitizensBooksAPI citizensBooks = null;

View File

@ -41,6 +41,7 @@ import me.blackvein.quests.events.quester.QuesterPreChangeStageEvent;
import me.blackvein.quests.events.quester.QuesterPreCompleteQuestEvent;
import me.blackvein.quests.events.quester.QuesterPreFailQuestEvent;
import me.blackvein.quests.exceptions.InvalidStageException;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.clip.placeholderapi.PlaceholderAPI;
@ -184,7 +185,7 @@ public class Quest {
}
String stageCompleteMessage = currentStage.completeMessage;
if (stageCompleteMessage != null) {
quester.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageCompleteMessage,
quester.getPlayer().sendMessage(ConfigUtil.parseStringWithPossibleLineBreaks(stageCompleteMessage,
this, quester.getPlayer()));
}
if (plugin.getSettings().canUseCompass()) {
@ -260,7 +261,7 @@ public class Quest {
plugin.showObjectives(this, quester, false);
String stageStartMessage = quester.getCurrentStage(this).startMessage;
if (stageStartMessage != null) {
quester.getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageStartMessage, this,
quester.getPlayer().sendMessage(ConfigUtil.parseStringWithPossibleLineBreaks(stageStartMessage, this,
quester.getPlayer()));
}
quester.updateJournal();

View File

@ -58,6 +58,7 @@ import me.blackvein.quests.prompts.RewardsPrompt;
import me.blackvein.quests.prompts.PlannerPrompt;
import me.blackvein.quests.prompts.StagesPrompt;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
@ -1032,7 +1033,7 @@ public class QuestFactory implements ConversationAbandonedListener {
npcStart = (Integer) cc.getSessionData(CK.Q_START_NPC);
}
if (cc.getSessionData(CK.Q_START_BLOCK) != null) {
blockStart = Quests.getLocationInfo((Location) cc.getSessionData(CK.Q_START_BLOCK));
blockStart = ConfigUtil.getLocationInfo((Location) cc.getSessionData(CK.Q_START_BLOCK));
}
if (cc.getSessionData(CK.REQ_MONEY) != null) {
moneyReq = (Integer) cc.getSessionData(CK.REQ_MONEY);

View File

@ -20,6 +20,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.MiscUtil;
@ -154,7 +155,7 @@ public class QuestMob {
string += "::name-" + name;
}
if (spawnLocation != null) {
string += "::spawn-" + Quests.getLocationInfo(spawnLocation);
string += "::spawn-" + ConfigUtil.getLocationInfo(spawnLocation);
}
if (spawnAmounts != null) {
string += "::amounts-" + spawnAmounts;
@ -196,7 +197,7 @@ public class QuestMob {
} else if (string.startsWith("name-")) {
name = string.substring(5);
} else if (string.startsWith("spawn-")) {
loc = Quests.getLocation(string.substring(6));
loc = ConfigUtil.getLocation(string.substring(6));
} else if (string.startsWith("amounts-")) {
amounts = Integer.parseInt(string.substring(8));
} else if (string.startsWith("hand-")) {

View File

@ -55,6 +55,7 @@ import me.blackvein.quests.events.quest.QuestTakeEvent;
import me.blackvein.quests.events.quester.QuesterPostStartQuestEvent;
import me.blackvein.quests.events.quester.QuesterPreStartQuestEvent;
import me.blackvein.quests.timers.StageTimer;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.LocaleQuery;
@ -419,7 +420,7 @@ public class Quester {
String early = Lang.get("plnTooEarly");
early = early.replace("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW);
early = early.replace("<time>", ChatColor.DARK_PURPLE
+ Quests.getTime(start - System.currentTimeMillis()) + ChatColor.YELLOW);
+ MiscUtil.getTime(start - System.currentTimeMillis()) + ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + early);
return;
}
@ -429,7 +430,7 @@ public class Quester {
String late = Lang.get("plnTooLate");
late = late.replace("<quest>", ChatColor.AQUA + q.getName() + ChatColor.RED);
late = late.replace("<time>", ChatColor.DARK_PURPLE
+ Quests.getTime(System.currentTimeMillis() - end) + ChatColor.RED);
+ MiscUtil.getTime(System.currentTimeMillis() - end) + ChatColor.RED);
player.sendMessage(ChatColor.RED + late);
return;
}
@ -470,7 +471,7 @@ public class Quester {
String early = Lang.get("plnTooEarly");
early = early.replace("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW);
early = early.replace("<time>", ChatColor.DARK_PURPLE
+ Quests.getTime(nextStart - System.currentTimeMillis()) + ChatColor.YELLOW);
+ MiscUtil.getTime(nextStart - System.currentTimeMillis()) + ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + early);
return;
}
@ -516,7 +517,7 @@ public class Quester {
plugin.showObjectives(q, this, false);
String stageStartMessage = stage.startMessage;
if (stageStartMessage != null) {
getPlayer().sendMessage(plugin.parseStringWithPossibleLineBreaks(stageStartMessage, q, getPlayer()));
getPlayer().sendMessage(ConfigUtil.parseStringWithPossibleLineBreaks(stageStartMessage, q, getPlayer()));
}
if (stage.chatEvents.isEmpty() == false) {
for (String chatTrigger : stage.chatEvents.keySet()) {
@ -3153,7 +3154,7 @@ public class Quester {
(long) (getCurrentStage(quest).delay * 0.02));
if (getCurrentStage(quest).delayMessage != null) {
Player p = plugin.getServer().getPlayer(id);
p.sendMessage(plugin.parseStringWithPossibleLineBreaks((getCurrentStage(quest)
p.sendMessage(ConfigUtil.parseStringWithPossibleLineBreaks((getCurrentStage(quest)
.delayMessage), quest, p));
}
}
@ -3241,10 +3242,10 @@ public class Quester {
ItemStack display = quests.get(i).guiDisplay;
ItemMeta meta = display.getItemMeta();
if (completedQuests.contains(quests.get(i).getName())) {
meta.setDisplayName(ChatColor.DARK_PURPLE + Quests.parseString(quests.get(i).getName()
meta.setDisplayName(ChatColor.DARK_PURPLE + ConfigUtil.parseString(quests.get(i).getName()
+ " " + ChatColor.GREEN + Lang.get(player, "redoCompleted"), npc));
} else {
meta.setDisplayName(ChatColor.DARK_PURPLE + Quests.parseString(quests.get(i).getName(), npc));
meta.setDisplayName(ChatColor.DARK_PURPLE + ConfigUtil.parseString(quests.get(i).getName(), npc));
}
if (!meta.hasLore()) {
LinkedList<String> lines = new LinkedList<String>();
@ -3582,7 +3583,7 @@ public class Quester {
if (giveReason) {
String msg = Lang.get(getPlayer(), "questTooEarly");
msg = msg.replace("<quest>", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW);
msg = msg.replace("<time>", ChatColor.DARK_PURPLE + Quests.getTime(getCooldownDifference(quest))
msg = msg.replace("<time>", ChatColor.DARK_PURPLE + MiscUtil.getTime(getCooldownDifference(quest))
+ ChatColor.YELLOW);
getPlayer().sendMessage(ChatColor.YELLOW + msg);
}

View File

@ -84,6 +84,7 @@ import me.blackvein.quests.listeners.NpcListener;
import me.blackvein.quests.listeners.PartiesListener;
import me.blackvein.quests.listeners.PlayerListener;
import me.blackvein.quests.prompts.QuestOfferPrompt;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.LocaleQuery;
@ -3288,152 +3289,67 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
/**
* @deprecated Use ConfigUtil.parseStringWithPossibleLineBreaks(String, Quest, Player)
*/
public String[] parseStringWithPossibleLineBreaks(String s, Quest quest, Player player) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
if (quest.npcStart != null) {
parsed = parsed.replace("<npc>", quest.npcStart.getName());
} else {
Bukkit.getLogger().warning(quest.getName() + " quest uses <npc> tag but doesn't have an NPC start set");
}
}
if (depends.getPlaceholderApi() != null && player != null) {
parsed = PlaceholderAPI.setPlaceholders(player, parsed);
}
return parsed.split("\n");
return ConfigUtil.parseStringWithPossibleLineBreaks(s, quest);
}
/**
* @deprecated Use ConfigUtil.parseStringWithPossibleLineBreaks(String, Quest)
*/
public static String[] parseStringWithPossibleLineBreaks(String s, Quest quest) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
if (quest.npcStart != null) {
parsed = parsed.replace("<npc>", quest.npcStart.getName());
} else {
Bukkit.getLogger().warning(quest.getName() + " quest uses <npc> tag but doesn't have an NPC start set");
}
}
return parsed.split("\n");
return ConfigUtil.parseStringWithPossibleLineBreaks(s, quest);
}
/**
* @deprecated Use ConfigUtil.parseStringWithPossibleLineBreaks(String, NPC)
*/
public static String[] parseStringWithPossibleLineBreaks(String s, NPC npc) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
parsed = parsed.replace("<npc>", npc.getName());
}
return parsed.split("\n");
return ConfigUtil.parseStringWithPossibleLineBreaks(s, npc);
}
/**
* @deprecated Use ConfigUtil.parseString(String, Quest)
*/
public static String parseString(String s, Quest quest) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
if (quest.npcStart != null) {
parsed = parsed.replace("<npc>", quest.npcStart.getName());
} else {
Bukkit.getLogger().warning(quest.getName() + " quest uses <npc> tag but doesn't have an NPC start set");
}
}
return parsed;
return ConfigUtil.parseString(s, quest);
}
/**
* @deprecated Use ConfigUtil.parseString(String, Quest, Player)
*/
public String parseString(String s, Quest quest, Player player) {
String parsed = parseString(s, quest);
if (depends.getPlaceholderApi() != null && player != null) {
parsed = PlaceholderAPI.setPlaceholders(player, parsed);
}
return parsed;
return ConfigUtil.parseString(s, quest, player);
}
/**
* @deprecated Use ConfigUtil.parseString(String, NPC)
*/
public static String parseString(String s, NPC npc) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
parsed = parsed.replace("<npc>", npc.getName());
}
return parsed;
return ConfigUtil.parseString(s);
}
/**
* @deprecated Use ConfigUtil.parseString(String)
*/
public static String parseString(String s) {
String parsed = s;
parsed = parsed.replace("<black>", ChatColor.BLACK.toString());
parsed = parsed.replace("<darkblue>", ChatColor.DARK_BLUE.toString());
parsed = parsed.replace("<darkgreen>", ChatColor.DARK_GREEN.toString());
parsed = parsed.replace("<darkaqua>", ChatColor.DARK_AQUA.toString());
parsed = parsed.replace("<darkred>", ChatColor.DARK_RED.toString());
parsed = parsed.replace("<purple>", ChatColor.DARK_PURPLE.toString());
parsed = parsed.replace("<gold>", ChatColor.GOLD.toString());
parsed = parsed.replace("<grey>", ChatColor.GRAY.toString());
parsed = parsed.replace("<gray>", ChatColor.GRAY.toString());
parsed = parsed.replace("<darkgrey>", ChatColor.DARK_GRAY.toString());
parsed = parsed.replace("<darkgray>", ChatColor.DARK_GRAY.toString());
parsed = parsed.replace("<blue>", ChatColor.BLUE.toString());
parsed = parsed.replace("<green>", ChatColor.GREEN.toString());
parsed = parsed.replace("<aqua>", ChatColor.AQUA.toString());
parsed = parsed.replace("<red>", ChatColor.RED.toString());
parsed = parsed.replace("<pink>", ChatColor.LIGHT_PURPLE.toString());
parsed = parsed.replace("<yellow>", ChatColor.YELLOW.toString());
parsed = parsed.replace("<white>", ChatColor.WHITE.toString());
parsed = parsed.replace("<random>", ChatColor.MAGIC.toString());
parsed = parsed.replace("<italic>", ChatColor.ITALIC.toString());
parsed = parsed.replace("<bold>", ChatColor.BOLD.toString());
parsed = parsed.replace("<underline>", ChatColor.UNDERLINE.toString());
parsed = parsed.replace("<strike>", ChatColor.STRIKETHROUGH.toString());
parsed = parsed.replace("<reset>", ChatColor.RESET.toString());
parsed = parsed.replace("<br>", "\n");
parsed = ChatColor.translateAlternateColorCodes('&', parsed);
return parsed;
return ConfigUtil.parseString(s);
}
/**
* @deprecated Use ConfigUtil.getLocation(String)
*/
public static Location getLocation(String arg) {
String[] info = arg.split(" ");
if (info.length < 4) {
return null;
}
StringBuilder sb = new StringBuilder();
int index = 0;
int xIndex = info.length -3;
int yIndex = info.length -2;
int zIndex = info.length -1;
while (index < xIndex) {
String s = info[index];
if (index == 0) {
sb.append(s);
} else {
sb.append(" " + s);
}
index++;
}
String world = sb.toString();
double x;
double y;
double z;
try {
x = Double.parseDouble(info[xIndex]);
y = Double.parseDouble(info[yIndex]);
z = Double.parseDouble(info[zIndex]);
} catch (Exception e) {
Bukkit.getLogger().severe("Please inform Quests developer location was wrong for "
+ world + " " + info[xIndex] + " " + info[yIndex] + " " + info[zIndex] + " ");
return null;
}
if (Bukkit.getServer().getWorld(world) == null) {
Bukkit.getLogger().severe("Quests could not locate world " + world + ", is it loaded?");
return null;
}
Location finalLocation = new Location(Bukkit.getServer().getWorld(world), x, y, z);
return finalLocation;
return ConfigUtil.getLocation(arg);
}
/**
* @deprecated Use ConfigUtil.getLocationInfo(Location)
*/
public static String getLocationInfo(Location loc) {
String info = "";
info += loc.getWorld().getName();
info += " " + loc.getX();
info += " " + loc.getY();
info += " " + loc.getZ();
return info;
return ConfigUtil.getLocationInfo(loc);
}
/**
@ -3447,53 +3363,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return MiscUtil.getProperMobType(mob);
}
/**
* @deprecated Use MiscUtil.getTime(long)
*/
public static String getTime(long milliseconds) {
String message = "";
long days = milliseconds / 86400000;
long hours = (milliseconds % 86400000) / 3600000;
long minutes = ((milliseconds % 86400000) % 3600000) / 60000;
long seconds = (((milliseconds % 86400000) % 3600000) % 60000) / 1000;
long milliSeconds2 = (((milliseconds % 86400000) % 3600000) % 60000) % 1000;
if (days > 0L) {
if (days == 1L) {
message += " 1 " + Lang.get("timeDay") + ",";
} else {
message += " " + days + " " + Lang.get("timeDays") + ",";
}
}
if (hours > 0L) {
if (hours == 1L) {
message += " 1 " + Lang.get("timeHour") + ",";
} else {
message += " " + hours + " " + Lang.get("timeHours") + ",";
}
}
if (minutes > 0L) {
if (minutes == 1L) {
message += " 1 " + Lang.get("timeMinute") + ",";
} else {
message += " " + minutes + " " + Lang.get("timeMinutes") + ",";
}
}
if (seconds > 0L) {
if (seconds == 1L) {
message += " 1 " + Lang.get("timeSecond") + ",";
} else {
message += " " + seconds + " " + Lang.get("timeSeconds") + ",";
}
} else {
if (milliSeconds2 > 0L) {
if (milliSeconds2 == 1L) {
message += " 1 " + Lang.get("timeMillisecond") + ",";
} else {
message += " " + milliSeconds2 + " " + Lang.get("timeMilliseconds") + ",";
}
}
}
if (message.length() > 0) {
message = message.substring(1, message.length() - 1);
}
return message;
return MiscUtil.getTime(milliseconds);
}
public static SkillType getMcMMOSkill(String s) {
@ -3621,20 +3495,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
*
* Does NOT check whether list objects are null
*
* @deprecated Use ConfigUtil.checkList(List, Class)
* @param list The list to check objects of
* @param clazz The class to compare against
* @return false if list is null or list object does not match
*/
public static boolean checkList(List<?> list, Class<?> clazz) {
if (list == null) {
return false;
}
for (Object o : list) {
if (clazz.isAssignableFrom(o.getClass()) == false) {
return false;
}
}
return true;
return ConfigUtil.checkList(list, clazz);
}
/**

View File

@ -38,6 +38,7 @@ import me.blackvein.quests.QuestMob;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.timers.ActionTimer;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
@ -271,7 +272,7 @@ public class Action {
public void fire(Quester quester, Quest quest) {
Player player = quester.getPlayer();
if (message != null) {
player.sendMessage(plugin.parseStringWithPossibleLineBreaks(message, quest, player));
player.sendMessage(ConfigUtil.parseStringWithPossibleLineBreaks(message, quest, player));
}
if (clearInv == true) {
player.getInventory().clear();
@ -425,7 +426,7 @@ public class Action {
Action action = new Action(plugin);
action.name = name;
if (data.contains(actionKey + "message")) {
action.message = Quests.parseString(data.getString(actionKey + "message"));
action.message = ConfigUtil.parseString(data.getString(actionKey + "message"));
}
if (data.contains(actionKey + "open-book")) {
action.book = data.getString(actionKey + "open-book");
@ -451,9 +452,9 @@ public class Action {
}
}
if (data.contains(actionKey + "explosions")) {
if (Quests.checkList(data.getList(actionKey + "explosions"), String.class)) {
if (ConfigUtil.checkList(data.getList(actionKey + "explosions"), String.class)) {
for (String s : data.getStringList(actionKey + "explosions")) {
Location loc = Quests.getLocation(s);
Location loc = ConfigUtil.getLocation(s);
if (loc == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + loc + ChatColor.GOLD
+ " inside " + ChatColor.GREEN + "explosions: " + ChatColor.GOLD + "inside Action "
@ -472,14 +473,14 @@ public class Action {
}
}
if (data.contains(actionKey + "effects")) {
if (Quests.checkList(data.getList(actionKey + "effects"), String.class)) {
if (ConfigUtil.checkList(data.getList(actionKey + "effects"), String.class)) {
if (data.contains(actionKey + "effect-locations")) {
if (Quests.checkList(data.getList(actionKey + "effect-locations"), String.class)) {
if (ConfigUtil.checkList(data.getList(actionKey + "effect-locations"), String.class)) {
List<String> effectList = data.getStringList(actionKey + "effects");
List<String> effectLocs = data.getStringList(actionKey + "effect-locations");
for (String s : effectList) {
Effect effect = Effect.valueOf(s.toUpperCase());
Location l = Quests.getLocation(effectLocs.get(effectList.indexOf(s)));
Location l = ConfigUtil.getLocation(effectLocs.get(effectList.indexOf(s)));
if (effect == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s
+ ChatColor.GOLD + " inside " + ChatColor.GREEN + "effects: " + ChatColor.GOLD
@ -521,7 +522,7 @@ public class Action {
LinkedList<ItemStack> temp = new LinkedList<ItemStack>(); // TODO - should maybe be = action.getItems() ?
@SuppressWarnings("unchecked")
List<ItemStack> stackList = (List<ItemStack>) data.get(actionKey + "items");
if (Quests.checkList(stackList, ItemStack.class)) {
if (ConfigUtil.checkList(stackList, ItemStack.class)) {
for (ItemStack stack : stackList) {
if (stack != null) {
temp.add(stack);
@ -529,7 +530,7 @@ public class Action {
}
} else {
// Legacy
if (Quests.checkList(stackList, String.class)) {
if (ConfigUtil.checkList(stackList, String.class)) {
List<String> items = data.getStringList(actionKey + "items");
for (String item : items) {
try {
@ -607,7 +608,7 @@ public class Action {
// is a mob, the keys are just a number or something.
for (String s : section.getKeys(false)) {
String mobName = section.getString(s + ".name");
Location spawnLocation = Quests.getLocation(section.getString(s + ".spawn-location"));
Location spawnLocation = ConfigUtil.getLocation(section.getString(s + ".spawn-location"));
EntityType type = MiscUtil.getProperMobType(section.getString(s + ".mob-type"));
Integer mobAmount = section.getInt(s + ".spawn-amounts");
if (spawnLocation == null) {
@ -646,9 +647,9 @@ public class Action {
}
}
if (data.contains(actionKey + "lightning-strikes")) {
if (Quests.checkList(data.getList(actionKey + "lightning-strikes"), String.class)) {
if (ConfigUtil.checkList(data.getList(actionKey + "lightning-strikes"), String.class)) {
for (String s : data.getStringList(actionKey + "lightning-strikes")) {
Location loc = Quests.getLocation(s);
Location loc = ConfigUtil.getLocation(s);
if (loc == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + s + ChatColor.GOLD
+ " inside " + ChatColor.GREEN + " lightning-strikes: " + ChatColor.GOLD
@ -668,7 +669,7 @@ public class Action {
}
}
if (data.contains(actionKey + "commands")) {
if (Quests.checkList(data.getList(actionKey + "commands"), String.class)) {
if (ConfigUtil.checkList(data.getList(actionKey + "commands"), String.class)) {
for (String s : data.getStringList(actionKey + "commands")) {
if (s.startsWith("/")) {
s = s.replaceFirst("/", "");
@ -683,11 +684,11 @@ public class Action {
}
}
if (data.contains(actionKey + "potion-effect-types")) {
if (Quests.checkList(data.getList(actionKey + "potion-effect-types"), String.class)) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-types"), String.class)) {
if (data.contains(actionKey + "potion-effect-durations")) {
if (Quests.checkList(data.getList(actionKey + "potion-effect-durations"), Integer.class)) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-durations"), Integer.class)) {
if (data.contains(actionKey + "potion-effect-amplifiers")) {
if (Quests.checkList(data.getList(actionKey + "potion-effect-amplifiers"), Integer.class)) {
if (ConfigUtil.checkList(data.getList(actionKey + "potion-effect-amplifiers"), Integer.class)) {
List<String> types = data.getStringList(actionKey + "potion-effect-types");
List<Integer> durations = data.getIntegerList(actionKey + "potion-effect-durations");
List<Integer> amplifiers = data.getIntegerList(actionKey + "potion-effect-amplifiers");
@ -763,7 +764,7 @@ public class Action {
}
if (data.contains(actionKey + "teleport-location")) {
if (data.isString(actionKey + "teleport-location")) {
Location l = Quests.getLocation(data.getString(actionKey + "teleport-location"));
Location l = ConfigUtil.getLocation(data.getString(actionKey + "teleport-location"));
if (l == null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + data.getString(actionKey
+ "teleport-location") + ChatColor.GOLD + "for " + ChatColor.GREEN + " teleport-location: "

View File

@ -53,6 +53,7 @@ import me.blackvein.quests.Quests;
import me.blackvein.quests.Stage;
import me.blackvein.quests.prompts.ItemStackPrompt;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
@ -265,7 +266,7 @@ public class ActionFactory implements ConversationAbandonedListener {
if (event.explosions != null && event.explosions.isEmpty() == false) {
LinkedList<String> locs = new LinkedList<String>();
for (Location loc : event.explosions) {
locs.add(Quests.getLocationInfo(loc));
locs.add(ConfigUtil.getLocationInfo(loc));
}
context.setSessionData(CK.E_EXPLOSIONS, locs);
}
@ -273,7 +274,7 @@ public class ActionFactory implements ConversationAbandonedListener {
LinkedList<String> locs = new LinkedList<String>();
LinkedList<String> effs = new LinkedList<String>();
for (Entry<Location, Effect> e : event.effects.entrySet()) {
locs.add(Quests.getLocationInfo((Location) e.getKey()));
locs.add(ConfigUtil.getLocationInfo((Location) e.getKey()));
effs.add(((Effect) e.getValue()).toString());
}
context.setSessionData(CK.E_EFFECTS, effs);
@ -297,7 +298,7 @@ public class ActionFactory implements ConversationAbandonedListener {
if (event.lightningStrikes != null && event.lightningStrikes.isEmpty() == false) {
LinkedList<String> locs = new LinkedList<String>();
for (Location loc : event.lightningStrikes) {
locs.add(Quests.getLocationInfo(loc));
locs.add(ConfigUtil.getLocationInfo(loc));
}
context.setSessionData(CK.E_LIGHTNING, locs);
}
@ -324,7 +325,7 @@ public class ActionFactory implements ConversationAbandonedListener {
context.setSessionData(CK.E_HEALTH, (Float) event.health);
}
if (event.teleport != null) {
context.setSessionData(CK.E_TELEPORT, Quests.getLocationInfo(event.teleport));
context.setSessionData(CK.E_TELEPORT, ConfigUtil.getLocationInfo(event.teleport));
}
if (event.commands != null) {
context.setSessionData(CK.E_COMMANDS, event.commands);
@ -476,7 +477,7 @@ public class ActionFactory implements ConversationAbandonedListener {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + qm.getType().name()
+ ((qm.getName() != null) ? ": " + qm.getName() : "") + ChatColor.GRAY + " x "
+ ChatColor.DARK_AQUA + qm.getSpawnAmounts() + ChatColor.GRAY + " -> " + ChatColor.GREEN
+ Quests.getLocationInfo(qm.getSpawnLocation()) + "\n";
+ ConfigUtil.getLocationInfo(qm.getSpawnLocation()) + "\n";
}
}
if (context.getSessionData(CK.E_FAIL_QUEST) == null) {
@ -578,7 +579,7 @@ public class ActionFactory implements ConversationAbandonedListener {
index++;
text += ChatColor.GRAY + " - " + ChatColor.AQUA + type + ChatColor.DARK_PURPLE + " "
+ RomanNumeral.getNumeral(mags.get(index)) + ChatColor.GRAY + " -> " + ChatColor.DARK_AQUA
+ Quests.getTime(durations.get(index) * 50L) + "\n";
+ MiscUtil.getTime(durations.get(index) * 50L) + "\n";
}
}
if (context.getSessionData(CK.E_HUNGER) == null) {
@ -773,7 +774,7 @@ public class ActionFactory implements ConversationAbandonedListener {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("eventEditorSetStorm") + " (" + ChatColor.AQUA
+ (String) context.getSessionData(CK.E_WORLD_STORM) + ChatColor.YELLOW + " -> "
+ ChatColor.DARK_AQUA + Quests.getTime(Long.valueOf((int)context
+ ChatColor.DARK_AQUA + MiscUtil.getTime(Long.valueOf((int)context
.getSessionData(CK.E_WORLD_STORM_DURATION) * 1000)) + ChatColor.YELLOW + ")\n";
}
if (context.getSessionData(CK.E_WORLD_THUNDER) == null) {
@ -783,7 +784,7 @@ public class ActionFactory implements ConversationAbandonedListener {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("eventEditorSetThunder") + " (" + ChatColor.AQUA
+ (String) context.getSessionData(CK.E_WORLD_THUNDER) + ChatColor.YELLOW + " -> "
+ ChatColor.DARK_AQUA + Quests.getTime(Long.valueOf((int)context
+ ChatColor.DARK_AQUA + MiscUtil.getTime(Long.valueOf((int)context
.getSessionData(CK.E_WORLD_THUNDER_DURATION) * 1000)) + ChatColor.YELLOW + ")\n";
}
@ -1059,7 +1060,7 @@ public class ActionFactory implements ConversationAbandonedListener {
continue;
}
ss.set("name", questMob.getName());
ss.set("spawn-location", Quests.getLocationInfo(questMob.getSpawnLocation()));
ss.set("spawn-location", ConfigUtil.getLocationInfo(questMob.getSpawnLocation()));
ss.set("mob-type", questMob.getType().name());
ss.set("spawn-amounts", questMob.getSpawnAmounts());
ss.set("held-item", ItemUtil.serializeItemStack(questMob.getInventory()[0]));
@ -1192,7 +1193,7 @@ public class ActionFactory implements ConversationAbandonedListener {
} else {
locs = new LinkedList<String>();
}
locs.add(Quests.getLocationInfo(loc));
locs.add(ConfigUtil.getLocationInfo(loc));
context.setSessionData(CK.E_EXPLOSIONS, locs);
selectedExplosionLocations.remove(player.getUniqueId());
} else {
@ -1442,7 +1443,7 @@ public class ActionFactory implements ConversationAbandonedListener {
} else {
locs = new LinkedList<String>();
}
locs.add(Quests.getLocationInfo(loc));
locs.add(ConfigUtil.getLocationInfo(loc));
context.setSessionData(CK.E_EFFECTS_LOCATIONS, locs);
selectedEffectLocations.remove(player.getUniqueId());
} else {
@ -1533,7 +1534,7 @@ public class ActionFactory implements ConversationAbandonedListener {
} else {
int dur = (int) context.getSessionData(CK.E_WORLD_STORM_DURATION);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("eventEditorSetDuration") + " (" + ChatColor.AQUA + Quests.getTime(dur * 1000)
+ Lang.get("eventEditorSetDuration") + " (" + ChatColor.AQUA + MiscUtil.getTime(dur * 1000)
+ ChatColor.YELLOW + ")\n";
}
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - "
@ -1649,7 +1650,7 @@ public class ActionFactory implements ConversationAbandonedListener {
} else {
int dur = (int) context.getSessionData(CK.E_WORLD_THUNDER_DURATION);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("eventEditorSetDuration") + " (" + ChatColor.AQUA + Quests.getTime(dur * 1000)
+ Lang.get("eventEditorSetDuration") + " (" + ChatColor.AQUA + MiscUtil.getTime(dur * 1000)
+ ChatColor.YELLOW + ")\n";
}
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - "
@ -1758,7 +1759,7 @@ public class ActionFactory implements ConversationAbandonedListener {
+ Lang.get("edit") + ": " + ChatColor.AQUA + qm.getType().name()
+ ((qm.getName() != null) ? ": " + qm.getName() : "") + ChatColor.GRAY + " x "
+ ChatColor.DARK_AQUA + qm.getSpawnAmounts() + ChatColor.GRAY + " -> " + ChatColor.GREEN
+ Quests.getLocationInfo(qm.getSpawnLocation()) + "\n";
+ ConfigUtil.getLocationInfo(qm.getSpawnLocation()) + "\n";
}
text += ChatColor.BLUE + "" + ChatColor.BOLD + (types.size() + 1) + ChatColor.RESET + ChatColor.YELLOW
+ " - " + Lang.get("eventEditorAddMobTypes") + "\n";
@ -1848,7 +1849,7 @@ public class ActionFactory implements ConversationAbandonedListener {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("eventEditorAddSpawnLocation") + ChatColor.GRAY + " ("
+ ((questMob.getSpawnLocation() == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA
+ Quests.getLocationInfo(questMob.getSpawnLocation())) + ChatColor.GRAY + ")\n";
+ ConfigUtil.getLocationInfo(questMob.getSpawnLocation())) + ChatColor.GRAY + ")\n";
text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("eventEditorSetMobSpawnAmount") + ChatColor.GRAY + " ("
+ ((questMob.getSpawnAmounts() == null) ? ChatColor.GRAY + Lang.get("noneSet") : ChatColor.AQUA
@ -2184,7 +2185,7 @@ public class ActionFactory implements ConversationAbandonedListener {
} else {
locs = new LinkedList<String>();
}
locs.add(Quests.getLocationInfo(loc));
locs.add(ConfigUtil.getLocationInfo(loc));
context.setSessionData(CK.E_LIGHTNING, locs);
selectedLightningLocations.remove(player.getUniqueId());
} else {
@ -2241,7 +2242,7 @@ public class ActionFactory implements ConversationAbandonedListener {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("noneSet") + "\n";
for (Long l : (LinkedList<Long>) context.getSessionData(CK.E_POTION_DURATIONS)) {
text += ChatColor.GRAY + " - " + ChatColor.DARK_AQUA + Quests.getTime(l * 50L) + "\n";
text += ChatColor.GRAY + " - " + ChatColor.DARK_AQUA + MiscUtil.getTime(l * 50L) + "\n";
}
if (context.getSessionData(CK.E_POTION_STRENGHT) == null) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - "
@ -2523,7 +2524,7 @@ public class ActionFactory implements ConversationAbandonedListener {
Block block = selectedTeleportLocations.get(player.getUniqueId());
if (block != null) {
Location loc = block.getLocation();
context.setSessionData(CK.E_TELEPORT, Quests.getLocationInfo(loc));
context.setSessionData(CK.E_TELEPORT, ConfigUtil.getLocationInfo(loc));
selectedTeleportLocations.remove(player.getUniqueId());
} else {
player.sendMessage(ChatColor.RED + Lang.get("eventEditorSelectBlockFirst"));

View File

@ -189,7 +189,7 @@ public class CmdExecutor implements CommandExecutor {
String msg = ChatColor.YELLOW + "(" + Lang.get(player, "delay") + ") " + ChatColor.RED
+ Lang.get(player, "plnTooEarly");
msg = msg.replace("<quest>", q.getName());
msg = msg.replace("<time>", Quests.getTime(time));
msg = msg.replace("<time>", MiscUtil.getTime(time));
player.sendMessage(msg);
}
}

View File

@ -74,6 +74,7 @@ import me.blackvein.quests.Quests;
import me.blackvein.quests.Stage;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import net.citizensnpcs.api.CitizensAPI;
public class PlayerListener implements Listener {
@ -139,7 +140,7 @@ public class PlayerListener implements Listener {
early = early.replace("<quest>", ChatColor.AQUA + quest.getName()
+ ChatColor.YELLOW);
early = early.replace("<time>", ChatColor.DARK_PURPLE
+ Quests.getTime(quester.getCooldownDifference(quest))
+ MiscUtil.getTime(quester.getCooldownDifference(quest))
+ ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + early);
takeable = false;

View File

@ -36,7 +36,9 @@ import me.blackvein.quests.Quests;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenCreateStagePromptEvent;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
public class CreateStagePrompt extends NumericPrompt {
@ -326,7 +328,7 @@ public class CreateStagePrompt extends NumericPrompt {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
long time = (Long) context.getSessionData(pref + CK.S_DELAY);
return ChatColor.GRAY + "(" + ChatColor.AQUA + Quests.getTime(time) + ChatColor.GRAY + ")";
return ChatColor.GRAY + "(" + ChatColor.AQUA + MiscUtil.getTime(time) + ChatColor.GRAY + ")";
}
}
case 11:
@ -895,7 +897,7 @@ public class CreateStagePrompt extends NumericPrompt {
} else {
locs = new LinkedList<String>();
}
locs.add(Quests.getLocationInfo(loc));
locs.add(ConfigUtil.getLocationInfo(loc));
context.setSessionData(pref + CK.S_REACH_LOCATIONS, locs);
Map<UUID, Block> temp = questFactory.getSelectedReachLocations();
temp.remove(player.getUniqueId());

View File

@ -32,7 +32,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import me.blackvein.quests.Quests;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
@ -473,7 +473,7 @@ public class ItemStackPrompt extends FixedSetPrompt {
String s = input.replace(":", "");
if (s.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& s.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
s = Quests.parseString(s);
s = ConfigUtil.parseString(s);
cc.setSessionData("tempDisplay", s);
} else if (s.equalsIgnoreCase(Lang.get("cmdClear"))) {
cc.setSessionData("tempDisplay", null);
@ -494,7 +494,7 @@ public class ItemStackPrompt extends FixedSetPrompt {
String s = input.replace(":", "");
if (s.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& s.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
s = Quests.parseString(s);
s = ConfigUtil.parseString(s);
LinkedList<String> lore = new LinkedList<String>();
lore.addAll(Arrays.asList(s.split(Lang.get("charSemi"))));
cc.setSessionData("tempLore", lore);

View File

@ -33,6 +33,7 @@ import org.bukkit.entity.Tameable;
import me.blackvein.quests.QuestFactory;
import me.blackvein.quests.Quests;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
@ -440,7 +441,7 @@ public class MobsPrompt extends FixedSetPrompt {
} else {
locs = new LinkedList<String>();
}
locs.add(Quests.getLocationInfo(loc));
locs.add(ConfigUtil.getLocationInfo(loc));
context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, locs);
Map<UUID, Block> temp = questFactory.getSelectedKillLocations();
temp.remove(player.getUniqueId());

View File

@ -23,6 +23,7 @@ import me.blackvein.quests.Quests;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenPlannerPromptEvent;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
@ -119,7 +120,7 @@ public class PlannerPrompt extends NumericPrompt {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
return ChatColor.YELLOW + "("
+ Quests.getTime((Long) context.getSessionData(CK.PLN_REPEAT_CYCLE))
+ MiscUtil.getTime((Long) context.getSessionData(CK.PLN_REPEAT_CYCLE))
+ ChatColor.RESET + ChatColor.YELLOW + ")";
}
}
@ -127,7 +128,7 @@ public class PlannerPrompt extends NumericPrompt {
if (context.getSessionData(CK.PLN_COOLDOWN) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
return ChatColor.YELLOW + "(" + Quests.getTime((Long) context.getSessionData(CK.PLN_COOLDOWN))
return ChatColor.YELLOW + "(" + MiscUtil.getTime((Long) context.getSessionData(CK.PLN_COOLDOWN))
+ ChatColor.RESET + ChatColor.YELLOW + ")";
}
case 5:

View File

@ -29,6 +29,7 @@ import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
public class QuestOfferPrompt extends StringPrompt {
@ -140,7 +141,7 @@ public class QuestOfferPrompt extends StringPrompt {
String early = Lang.get("questTooEarly");
early = early.replace("<quest>", ChatColor.AQUA + q.getName() + ChatColor.YELLOW);
early = early.replace("<time>", ChatColor.DARK_PURPLE
+ Quests.getTime(quester.getCooldownDifference(q)) + ChatColor.YELLOW);
+ MiscUtil.getTime(quester.getCooldownDifference(q)) + ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + early);
} else if (q.getPlanner().getCooldown() < 0) {
String completed = Lang.get("questAlreadyCompleted");

View File

@ -20,6 +20,7 @@ import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.Stage;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.Lang;
public class StageTimer implements Runnable {
@ -78,7 +79,8 @@ public class StageTimer implements Runnable {
plugin.showObjectives(quest, quester, false);
String stageStartMessage = quester.getCurrentStage(quest).getStartMessage();
if (stageStartMessage != null) {
quester.getPlayer().sendMessage(Quests.parseStringWithPossibleLineBreaks(stageStartMessage, quest));
quester.getPlayer().sendMessage(ConfigUtil
.parseStringWithPossibleLineBreaks(stageStartMessage, quest));
}
}
if (quester.getQuestData(quest) != null) {

View File

@ -0,0 +1,193 @@
/*******************************************************************************************************
* Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************************************/
package me.blackvein.quests.util;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import me.blackvein.quests.Dependencies;
import me.blackvein.quests.Quest;
import me.clip.placeholderapi.PlaceholderAPI;
import net.citizensnpcs.api.npc.NPC;
public class ConfigUtil {
/**
* Checks whether items in a list are instances of a class<p>
*
* Does NOT check whether list objects are null
*
* @param list The list to check objects of
* @param clazz The class to compare against
* @return false if list is null or list object does not match
*/
public static boolean checkList(List<?> list, Class<?> clazz) {
if (list == null) {
return false;
}
for (Object o : list) {
if (clazz.isAssignableFrom(o.getClass()) == false) {
return false;
}
}
return true;
}
public static Location getLocation(String arg) {
String[] info = arg.split(" ");
if (info.length < 4) {
return null;
}
StringBuilder sb = new StringBuilder();
int index = 0;
int xIndex = info.length -3;
int yIndex = info.length -2;
int zIndex = info.length -1;
while (index < xIndex) {
String s = info[index];
if (index == 0) {
sb.append(s);
} else {
sb.append(" " + s);
}
index++;
}
String world = sb.toString();
double x;
double y;
double z;
try {
x = Double.parseDouble(info[xIndex]);
y = Double.parseDouble(info[yIndex]);
z = Double.parseDouble(info[zIndex]);
} catch (Exception e) {
Bukkit.getLogger().severe("Please inform Quests developer location was wrong for "
+ world + " " + info[xIndex] + " " + info[yIndex] + " " + info[zIndex] + " ");
return null;
}
if (Bukkit.getServer().getWorld(world) == null) {
Bukkit.getLogger().severe("Quests could not locate world " + world + ", is it loaded?");
return null;
}
Location finalLocation = new Location(Bukkit.getServer().getWorld(world), x, y, z);
return finalLocation;
}
public static String getLocationInfo(Location loc) {
return loc.getWorld().getName() + " " + loc.getX() + " " + loc.getY() + " " + loc.getZ();
}
public static String[] parseStringWithPossibleLineBreaks(String s, Quest quest, Player player) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
if (quest.getNpcStart() != null) {
parsed = parsed.replace("<npc>", quest.getNpcStart().getName());
} else {
Bukkit.getLogger().warning(quest.getName() + " quest uses <npc> tag but doesn't have an NPC start set");
}
}
if (Dependencies.placeholder != null && player != null) {
parsed = PlaceholderAPI.setPlaceholders(player, parsed);
}
return parsed.split("\n");
}
public static String[] parseStringWithPossibleLineBreaks(String s, Quest quest) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
if (quest.getNpcStart() != null) {
parsed = parsed.replace("<npc>", quest.getNpcStart().getName());
} else {
Bukkit.getLogger().warning(quest.getName() + " quest uses <npc> tag but doesn't have an NPC start set");
}
}
return parsed.split("\n");
}
public static String[] parseStringWithPossibleLineBreaks(String s, NPC npc) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
parsed = parsed.replace("<npc>", npc.getName());
}
return parsed.split("\n");
}
public static String parseString(String s, Quest quest) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
if (quest.getNpcStart() != null) {
parsed = parsed.replace("<npc>", quest.getNpcStart().getName());
} else {
Bukkit.getLogger().warning(quest.getName() + " quest uses <npc> tag but doesn't have an NPC start set");
}
}
return parsed;
}
public static String parseString(String s, Quest quest, Player player) {
String parsed = parseString(s, quest);
if (Dependencies.placeholder != null && player != null) {
parsed = PlaceholderAPI.setPlaceholders(player, parsed);
}
return parsed;
}
public static String parseString(String s, NPC npc) {
String parsed = parseString(s);
if (parsed.contains("<npc>")) {
parsed = parsed.replace("<npc>", npc.getName());
}
return parsed;
}
public static String parseString(String s) {
String parsed = s;
parsed = parsed.replace("<black>", ChatColor.BLACK.toString());
parsed = parsed.replace("<darkblue>", ChatColor.DARK_BLUE.toString());
parsed = parsed.replace("<darkgreen>", ChatColor.DARK_GREEN.toString());
parsed = parsed.replace("<darkaqua>", ChatColor.DARK_AQUA.toString());
parsed = parsed.replace("<darkred>", ChatColor.DARK_RED.toString());
parsed = parsed.replace("<purple>", ChatColor.DARK_PURPLE.toString());
parsed = parsed.replace("<gold>", ChatColor.GOLD.toString());
parsed = parsed.replace("<grey>", ChatColor.GRAY.toString());
parsed = parsed.replace("<gray>", ChatColor.GRAY.toString());
parsed = parsed.replace("<darkgrey>", ChatColor.DARK_GRAY.toString());
parsed = parsed.replace("<darkgray>", ChatColor.DARK_GRAY.toString());
parsed = parsed.replace("<blue>", ChatColor.BLUE.toString());
parsed = parsed.replace("<green>", ChatColor.GREEN.toString());
parsed = parsed.replace("<aqua>", ChatColor.AQUA.toString());
parsed = parsed.replace("<red>", ChatColor.RED.toString());
parsed = parsed.replace("<pink>", ChatColor.LIGHT_PURPLE.toString());
parsed = parsed.replace("<yellow>", ChatColor.YELLOW.toString());
parsed = parsed.replace("<white>", ChatColor.WHITE.toString());
parsed = parsed.replace("<random>", ChatColor.MAGIC.toString());
parsed = parsed.replace("<italic>", ChatColor.ITALIC.toString());
parsed = parsed.replace("<bold>", ChatColor.BOLD.toString());
parsed = parsed.replace("<underline>", ChatColor.UNDERLINE.toString());
parsed = parsed.replace("<strike>", ChatColor.STRIKETHROUGH.toString());
parsed = parsed.replace("<reset>", ChatColor.RESET.toString());
parsed = parsed.replace("<br>", "\n");
parsed = ChatColor.translateAlternateColorCodes('&', parsed);
return parsed;
}
}

View File

@ -21,6 +21,55 @@ import org.bukkit.entity.EntityType;
public class MiscUtil {
public static String getTime(long milliseconds) {
String message = "";
long days = milliseconds / 86400000;
long hours = (milliseconds % 86400000) / 3600000;
long minutes = ((milliseconds % 86400000) % 3600000) / 60000;
long seconds = (((milliseconds % 86400000) % 3600000) % 60000) / 1000;
long milliSeconds2 = (((milliseconds % 86400000) % 3600000) % 60000) % 1000;
if (days > 0L) {
if (days == 1L) {
message += " 1 " + Lang.get("timeDay") + ",";
} else {
message += " " + days + " " + Lang.get("timeDays") + ",";
}
}
if (hours > 0L) {
if (hours == 1L) {
message += " 1 " + Lang.get("timeHour") + ",";
} else {
message += " " + hours + " " + Lang.get("timeHours") + ",";
}
}
if (minutes > 0L) {
if (minutes == 1L) {
message += " 1 " + Lang.get("timeMinute") + ",";
} else {
message += " " + minutes + " " + Lang.get("timeMinutes") + ",";
}
}
if (seconds > 0L) {
if (seconds == 1L) {
message += " 1 " + Lang.get("timeSecond") + ",";
} else {
message += " " + seconds + " " + Lang.get("timeSeconds") + ",";
}
} else {
if (milliSeconds2 > 0L) {
if (milliSeconds2 == 1L) {
message += " 1 " + Lang.get("timeMillisecond") + ",";
} else {
message += " " + milliSeconds2 + " " + Lang.get("timeMilliseconds") + ",";
}
}
}
if (message.length() > 0) {
message = message.substring(1, message.length() - 1);
}
return message;
}
/**
* Capitalize first letter of text and set remainder to lowercase
*

View File

@ -19,7 +19,6 @@ public class RomanNumeral {
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
static {
map.put(1000, "M");
map.put(900, "CM");
map.put(500, "D");
@ -33,7 +32,6 @@ public class RomanNumeral {
map.put(5, "V");
map.put(4, "IV");
map.put(1, "I");
}
public final static String getNumeral(int number) {