mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-20 23:31:36 +01:00
Custom objectives respect alt color codes again
This commit is contained in:
parent
9b402c28bf
commit
a7a03eca5b
@ -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;
|
||||
@ -54,7 +54,7 @@ public abstract class CustomObjective implements Listener {
|
||||
public void setAuthor(final String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
|
||||
public String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
@ -62,7 +62,7 @@ public abstract class CustomObjective implements Listener {
|
||||
public void setDisplay(final String display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Short> getItems() {
|
||||
return items;
|
||||
}
|
||||
@ -70,7 +70,7 @@ public abstract class CustomObjective implements Listener {
|
||||
public void addItem(final String type, final short durability) {
|
||||
this.items.put(type, durability);
|
||||
}
|
||||
|
||||
|
||||
public LinkedList<Entry<String, Object>> getData() {
|
||||
return data;
|
||||
}
|
||||
@ -85,11 +85,11 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getDescriptions() {
|
||||
return descriptions;
|
||||
}
|
||||
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -917,61 +917,68 @@ 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);
|
||||
if (CustomRequirement.class.isAssignableFrom(c)) {
|
||||
final Class<? extends CustomRequirement> requirementClass = c.asSubclass(CustomRequirement.class);
|
||||
final Constructor<? extends CustomRequirement> cstrctr = requirementClass.getConstructor();
|
||||
final CustomRequirement requirement = cstrctr.newInstance();
|
||||
final Optional<CustomRequirement>oo=getCustomRequirement(requirement.getClass().getName());
|
||||
oo.ifPresent(customRequirements::remove);
|
||||
customRequirements.add(requirement);
|
||||
final String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName();
|
||||
final String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor();
|
||||
count++;
|
||||
getLogger().info("Loaded Module: " + name + " by " + author);
|
||||
} else if (CustomReward.class.isAssignableFrom(c)) {
|
||||
final Class<? extends CustomReward> rewardClass = c.asSubclass(CustomReward.class);
|
||||
final Constructor<? extends CustomReward> cstrctr = rewardClass.getConstructor();
|
||||
final CustomReward reward = cstrctr.newInstance();
|
||||
final Optional<CustomReward>oo=getCustomReward(reward.getClass().getName());
|
||||
oo.ifPresent(customRewards::remove);
|
||||
customRewards.add(reward);
|
||||
final String name = reward.getName() == null ? "[" + jar.getName() + "]" : reward.getName();
|
||||
final String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor();
|
||||
count++;
|
||||
getLogger().info("Loaded Module: " + name + " by " + author);
|
||||
} else if (CustomObjective.class.isAssignableFrom(c)) {
|
||||
final Class<? extends CustomObjective> objectiveClass = c.asSubclass(CustomObjective.class);
|
||||
final Constructor<? extends CustomObjective> cstrctr = objectiveClass.getConstructor();
|
||||
final CustomObjective objective = cstrctr.newInstance();
|
||||
final Optional<CustomObjective>oo=getCustomObjective(objective.getClass().getName());
|
||||
if (oo.isPresent()) {
|
||||
HandlerList.unregisterAll(oo.get());
|
||||
customObjectives.remove(oo.get());
|
||||
}
|
||||
customObjectives.add(objective);
|
||||
final String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName();
|
||||
final String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor();
|
||||
count++;
|
||||
getLogger().info("Loaded Module: " + name + " by " + author);
|
||||
try {
|
||||
getServer().getPluginManager().registerEvents(objective, this);
|
||||
getLogger().info("Registered events for custom objective \"" + name + "\"");
|
||||
} catch (final Exception ex) {
|
||||
getLogger().warning("Failed to register events for custom objective \"" + name
|
||||
+ "\". Does the objective class listen for events?");
|
||||
ex.printStackTrace();
|
||||
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();
|
||||
final CustomRequirement requirement = cstrctr.newInstance();
|
||||
final Optional<CustomRequirement>oo=getCustomRequirement(requirement.getClass().getName());
|
||||
oo.ifPresent(customRequirements::remove);
|
||||
customRequirements.add(requirement);
|
||||
final String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName();
|
||||
final String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor();
|
||||
count++;
|
||||
getLogger().info("Loaded Module: " + name + " by " + author);
|
||||
} else if (CustomReward.class.isAssignableFrom(c)) {
|
||||
final Class<? extends CustomReward> rewardClass = c.asSubclass(CustomReward.class);
|
||||
final Constructor<? extends CustomReward> cstrctr = rewardClass.getConstructor();
|
||||
final CustomReward reward = cstrctr.newInstance();
|
||||
final Optional<CustomReward>oo=getCustomReward(reward.getClass().getName());
|
||||
oo.ifPresent(customRewards::remove);
|
||||
customRewards.add(reward);
|
||||
final String name = reward.getName() == null ? "[" + jar.getName() + "]" : reward.getName();
|
||||
final String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor();
|
||||
count++;
|
||||
getLogger().info("Loaded Module: " + name + " by " + author);
|
||||
} else if (CustomObjective.class.isAssignableFrom(c)) {
|
||||
final Class<? extends CustomObjective> objectiveClass = c.asSubclass(CustomObjective.class);
|
||||
final Constructor<? extends CustomObjective> cstrctr = objectiveClass.getConstructor();
|
||||
final CustomObjective objective = cstrctr.newInstance();
|
||||
final Optional<CustomObjective>oo=getCustomObjective(objective.getClass().getName());
|
||||
if (oo.isPresent()) {
|
||||
HandlerList.unregisterAll(oo.get());
|
||||
customObjectives.remove(oo.get());
|
||||
}
|
||||
customObjectives.add(objective);
|
||||
final String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName();
|
||||
final String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor();
|
||||
count++;
|
||||
getLogger().info("Loaded Module: " + name + " by " + author);
|
||||
try {
|
||||
getServer().getPluginManager().registerEvents(objective, this);
|
||||
getLogger().info("Registered events for custom objective \"" + name + "\"");
|
||||
} catch (final Exception ex) {
|
||||
getLogger().warning("Failed to register events for custom objective \"" + name
|
||||
+ "\". Does the objective class listen for events?");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user