Custom objectives respect alt color codes again

This commit is contained in:
PikaMug 2021-09-07 14:51:36 -04:00
parent 9b402c28bf
commit a7a03eca5b
3 changed files with 79 additions and 73 deletions

View File

@ -32,9 +32,9 @@ public abstract class CustomObjective implements Listener {
private String name = null;
private String author = null;
private String display = "Progress: %count%";
private final Map<String, Short> items = new HashMap<String, Short>();
private final LinkedList<Entry<String, Object>> data = new LinkedList<Entry<String, Object>>();
private final Map<String, String> descriptions = new HashMap<String, String>();
private final Map<String, Short> items = new HashMap<>();
private final LinkedList<Entry<String, Object>> data = new LinkedList<>();
private final Map<String, String> descriptions = new HashMap<>();
private String countPrompt = "Enter number";
private boolean showCount = true;
private int count = 1;
@ -85,7 +85,7 @@ public abstract class CustomObjective implements Listener {
* @param defaultValue Value to be used if input is not received
*/
public void addStringPrompt(final String title, final String description, final Object defaultValue) {
final Entry<String, Object> prompt = new AbstractMap.SimpleEntry<String, Object>(title, defaultValue);
final Entry<String, Object> prompt = new AbstractMap.SimpleEntry<>(title, defaultValue);
data.add(prompt);
descriptions.put(title, description);
}
@ -120,7 +120,7 @@ public abstract class CustomObjective implements Listener {
/**
* Set whether to let user set required amount for objective
*
* @param showCount Whether or not to show the count
* @param showCount Whether to show the count
*/
public void setShowCount(final boolean showCount) {
this.showCount = showCount;
@ -141,10 +141,10 @@ public abstract class CustomObjective implements Listener {
}
}
if (found != null) {
final Map<String, Object> m = new HashMap<String, Object>();
for (final Entry<String, Object> datamap : found.getData()) {
final Map<String, Object> m = new HashMap<>();
for (final Entry<String, Object> dataMap : found.getData()) {
for (final Entry<String, Object> e : currentStage.customObjectiveData) {
if (e.getKey().equals(datamap.getKey())) {
if (e.getKey().equals(dataMap.getKey())) {
m.put(e.getKey(), e.getValue());
}
}
@ -162,7 +162,7 @@ public abstract class CustomObjective implements Listener {
if (quester != null) {
if (quester.hasCustomObjective(quest, obj.getName())) {
int index = -1;
for (CustomObjective co : quester.getCurrentStage(quest).customObjectives) {
for (final CustomObjective co : quester.getCurrentStage(quest).customObjectives) {
index++;
if (co.getName().equals(this.getName())) {
final int old = quester.getQuestData(quest).customObjectiveCounts.get(index);
@ -185,7 +185,7 @@ public abstract class CustomObjective implements Listener {
new ItemStack(Material.AIR, goal)), null, null, null, null, null, null, obj);
// Multiplayer
int finalIndex = index;
final int finalIndex = index;
quester.dispatchMultiplayerObjectives(quest, quester.getCurrentStage(quest), (final Quester q) -> {
final int old = q.getQuestData(quest).customObjectiveCounts.get(finalIndex);
q.getQuestData(quest).customObjectiveCounts.set(finalIndex, old + count);

View File

@ -873,22 +873,21 @@ public class Quester implements Comparable<Quester> {
public LinkedList<String> getCurrentObjectives(final Quest quest, final boolean ignoreOverrides) {
if (quest == null) {
plugin.getLogger().severe("Quest was null when getting objectives for " + getLastKnownName());
return new LinkedList<String>();
return new LinkedList<>();
}
if (getQuestData(quest) == null) {
plugin.getLogger().warning("Quest data was null when getting objectives for " + quest.getName());
return new LinkedList<String>();
return new LinkedList<>();
}
if (getCurrentStage(quest) == null) {
//plugin.getLogger().warning("Current stage was null when getting objectives for " + quest.getName());
return new LinkedList<String>();
return new LinkedList<>();
}
final Dependencies depends = plugin.getDependencies();
if (!ignoreOverrides && !getCurrentStage(quest).objectiveOverrides.isEmpty()) {
final LinkedList<String> objectives = new LinkedList<String>();
final LinkedList<String> objectives = new LinkedList<>();
for (final String s: getCurrentStage(quest).objectiveOverrides) {
String message = ChatColor.GREEN + ConfigUtil.parseString(
ChatColor.translateAlternateColorCodes('&', s), quest, getPlayer());
String message = ChatColor.GREEN + ConfigUtil.parseString(s, quest, getPlayer());
if (depends.getPlaceholderApi() != null) {
message = PlaceholderAPI.setPlaceholders(getPlayer(), message);
}
@ -1326,7 +1325,7 @@ public class Quester implements Comparable<Quester> {
if (co.canShowCount()) {
message = message.replace("%count%", cleared + "/" + toClear);
}
objectives.add(message);
objectives.add(ConfigUtil.parseString(message));
customIndex++;
}
return objectives;

View File

@ -917,18 +917,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
@SuppressWarnings("resource")
final
JarFile jarFile = new JarFile(jar);
final Enumeration<JarEntry> e = jarFile.entries();
final Enumeration<JarEntry> entry = jarFile.entries();
final URL[] urls = { new URL("jar:file:" + jar.getPath() + "!/") };
final ClassLoader cl = URLClassLoader.newInstance(urls, getClassLoader());
int count = 0;
while (e.hasMoreElements()) {
final JarEntry je = e.nextElement();
while (entry.hasMoreElements()) {
final JarEntry je = entry.nextElement();
if (je.isDirectory() || !je.getName().endsWith(".class")) {
continue;
}
String className = je.getName().substring(0, je.getName().length() - 6);
className = className.replace('/', '.');
final Class<?> c = Class.forName(className, true, cl);
final String className = je.getName().substring(0, je.getName().length() - 6).replace('/', '.');
Class<?> c = null;
try {
c = Class.forName(className, true, cl);
} catch (final NoClassDefFoundError e) {
getLogger().severe("Module error! Seek help from developer of module:");
e.printStackTrace();
}
if (c != null) {
if (CustomRequirement.class.isAssignableFrom(c)) {
final Class<? extends CustomRequirement> requirementClass = c.asSubclass(CustomRequirement.class);
final Constructor<? extends CustomRequirement> cstrctr = requirementClass.getConstructor();
@ -975,6 +981,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
}
}
if (count == 0) {
getLogger().severe("Unable to load module from file: " + jar.getName()
+ ", jar file is not a valid module!");
@ -1011,7 +1018,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (!ignoreOverrides && !quester.getCurrentStage(quest).objectiveOverrides.isEmpty()) {
for (final String s: quester.getCurrentStage(quest).objectiveOverrides) {
String message = ChatColor.GREEN + (s.trim().length() > 0 ? "- " : "") + ConfigUtil
.parseString(ChatColor.translateAlternateColorCodes('&', s), quest, quester.getPlayer());
.parseString(s, quest, quester.getPlayer());
if (depends.getPlaceholderApi() != null) {
message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message);
}
@ -1526,7 +1533,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (co.canShowCount()) {
message = message.replace("%count%", cleared + "/" + toClear);
}
quester.sendMessage(message);
quester.sendMessage(ConfigUtil.parseString(message));
customIndex++;
}
}
@ -3887,7 +3894,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
oStage.customObjectiveData.add(data);
}
} else {
throw new QuestFormatException(name + " custom requirement not found for Stage "
throw new QuestFormatException(name + " custom objective not found for Stage "
+ stageNum, questKey);
}
}