Merge pull request #643 from FlyingPikachu/api-update

API update
This commit is contained in:
FlyingPikachu 2019-01-17 00:46:35 -05:00 committed by GitHub
commit c4a0709350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 38 deletions

View File

@ -23,8 +23,8 @@ public abstract class CustomObjective implements Listener {
private Quests plugin = Quests.getPlugin(Quests.class); private Quests plugin = Quests.getPlugin(Quests.class);
private String name = null; private String name = null;
private String author = null; private String author = null;
public final Map<String, Object> datamap = new HashMap<String, Object>(); private Map<String, Object> data = new HashMap<String, Object>();
public final Map<String, String> descriptions = new HashMap<String, String>(); private Map<String, String> descriptions = new HashMap<String, String>();
private String countPrompt = "null"; private String countPrompt = "null";
private String display = "null"; private String display = "null";
private boolean enableCount = true; private boolean enableCount = true;
@ -46,9 +46,43 @@ public abstract class CustomObjective implements Listener {
public void setAuthor(String author) { public void setAuthor(String author) {
this.author = author; this.author = author;
} }
public Map<String, Object> getData() {
return data;
}
/**
* Add a detailed piece of datum to the data map
* @param name
* @param o
*/
public void addDatum(String name, Object o) {
if (o == null) {
data.put(name, o);
} else {
data.put(name, null);
}
}
/**
* Add a blank piece of datum to the data map
* @param name
*/
public void addDatum(String name) {
data.put(name, null);
}
/**
* Add null data for name
*
* @param name
* @deprecated use addDatum()
*/
public void addData(String name) { public void addData(String name) {
datamap.put(name, null); addDatum(name);
}
public Map<String, String> getDescriptions() {
return descriptions;
} }
public void addDescription(String data, String description) { public void addDescription(String data, String description) {
@ -94,7 +128,20 @@ public abstract class CustomObjective implements Listener {
public void setEnableCount(boolean enableCount) { public void setEnableCount(boolean enableCount) {
this.enableCount = enableCount; this.enableCount = enableCount;
} }
public Map<String, Object> getDataForPlayer(Player player, CustomObjective customObj, Quest quest) {
return getDatamap(player, customObj, quest);
}
/**
* Get data for specified player's current stage
*
* @param player The player to get data for
* @param obj The CustomObjective to get data for
* @param quest Quest to get player's current stage. Returns null if player is not on quest
* @return data map if everything matches, otherwise null
* @deprecated use getDataForPlayer()
*/
public Map<String, Object> getDatamap(Player player, CustomObjective obj, Quest quest) { public Map<String, Object> getDatamap(Player player, CustomObjective obj, Quest quest) {
Quester quester = plugin.getQuester(player.getUniqueId()); Quester quester = plugin.getQuester(player.getUniqueId());
if (quester != null) { if (quester != null) {
@ -161,13 +208,13 @@ public abstract class CustomObjective implements Listener {
if (other.author.equals(name) == false) { if (other.author.equals(name) == false) {
return false; return false;
} }
for (String s : other.datamap.keySet()) { for (String s : other.getData().keySet()) {
if (datamap.containsKey(s) == false) { if (getData().containsKey(s) == false) {
return false; return false;
} }
} }
for (Object val : other.datamap.values()) { for (Object val : other.getData().values()) {
if (datamap.containsValue(val) == false) { if (getData().containsValue(val) == false) {
return false; return false;
} }
} }

View File

@ -787,7 +787,7 @@ public class Quester {
if (co.getName().equals(entry.getKey())) { if (co.getName().equals(entry.getKey())) {
String display = co.getDisplay(); String display = co.getDisplay();
Map<String, Object> datamap = getCurrentStage(quest).customObjectiveData.get(index); Map<String, Object> datamap = getCurrentStage(quest).customObjectiveData.get(index);
for (String key : co.datamap.keySet()) { for (String key : co.getData().keySet()) {
try { try {
display = display.replace("%" + key + "%", ((String) datamap.get(key))); display = display.replace("%" + key + "%", ((String) datamap.get(key)));
} catch (NullPointerException ne) { } catch (NullPointerException ne) {
@ -1551,7 +1551,7 @@ public class Quester {
} }
} }
Map<String, Object> datamap = getCurrentStage(quest).customObjectiveData.get(index); Map<String, Object> datamap = getCurrentStage(quest).customObjectiveData.get(index);
for (String key : co.datamap.keySet()) { for (String key : co.getData().keySet()) {
message = message.replace("%" + ((String) key) + "%", (String) datamap.get(key)); message = message.replace("%" + ((String) key) + "%", (String) datamap.get(key));
} }
if (co.isCountShown() && co.isEnableCount()) { if (co.isCountShown() && co.isEnableCount()) {

View File

@ -922,14 +922,15 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
} }
if (config.contains("quests." + questKey + ".rewards.commands")) { if (config.contains("quests." + questKey + ".rewards.commands")) {
if (Quests.checkList(config.getList("quests." + questKey + ".rewards.commands"), String.class)) { if (Quests.checkList(config.getList("quests." + questKey + ".rewards.commands"), String.class)) {
rews.setCommands(config.getStringList("quests." + questKey + ".rewards.commands"));
rews.setCommands((LinkedList<String>) config.getStringList("quests." + questKey + ".rewards.commands"));
} else { } else {
skipQuestProcess("commands: Reward in Quest " + quest.getName() + " is not a list of commands!"); skipQuestProcess("commands: Reward in Quest " + quest.getName() + " is not a list of commands!");
} }
} }
if (config.contains("quests." + questKey + ".rewards.permissions")) { if (config.contains("quests." + questKey + ".rewards.permissions")) {
if (Quests.checkList(config.getList("quests." + questKey + ".rewards.permissions"), String.class)) { if (Quests.checkList(config.getList("quests." + questKey + ".rewards.permissions"), String.class)) {
rews.setPermissions(config.getStringList("quests." + questKey + ".rewards.permissions")); rews.setPermissions((LinkedList<String>) config.getStringList("quests." + questKey + ".rewards.permissions"));
} else { } else {
skipQuestProcess("permissions: Reward in Quest " + quest.getName() + " is not a list of permissions!"); skipQuestProcess("permissions: Reward in Quest " + quest.getName() + " is not a list of permissions!");
} }
@ -953,8 +954,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
skipQuestProcess("" + skill + " in mcmmo-skills: Reward in Quest " + quest.getName() + " is not a valid mcMMO skill name!"); skipQuestProcess("" + skill + " in mcmmo-skills: Reward in Quest " + quest.getName() + " is not a valid mcMMO skill name!");
} }
} }
rews.setMcmmoSkills(config.getStringList("quests." + questKey + ".rewards.mcmmo-skills")); rews.setMcmmoSkills((LinkedList<String>) config.getStringList("quests." + questKey + ".rewards.mcmmo-skills"));
rews.setMcmmoAmounts(config.getIntegerList("quests." + questKey + ".rewards.mcmmo-levels")); rews.setMcmmoAmounts((LinkedList<Integer>) config.getIntegerList("quests." + questKey + ".rewards.mcmmo-levels"));
} else { } else {
skipQuestProcess("mcmmo-levels: Reward in Quest " + quest.getName() + " is not a list of numbers!"); skipQuestProcess("mcmmo-levels: Reward in Quest " + quest.getName() + " is not a list of numbers!");
} }
@ -978,8 +979,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
skipQuestProcess("" + heroClass + " in heroes-exp-classes: Reward in Quest " + quest.getName() + " is not a valid Heroes class name!"); skipQuestProcess("" + heroClass + " in heroes-exp-classes: Reward in Quest " + quest.getName() + " is not a valid Heroes class name!");
} }
} }
rews.setHeroesClasses(config.getStringList("quests." + questKey + ".rewards.heroes-exp-classes")); rews.setHeroesClasses((LinkedList<String>) config.getStringList("quests." + questKey + ".rewards.heroes-exp-classes"));
rews.setHeroesAmounts(config.getDoubleList("quests." + questKey + ".rewards.heroes-exp-amounts")); rews.setHeroesAmounts((LinkedList<Double>) config.getDoubleList("quests." + questKey + ".rewards.heroes-exp-amounts"));
} else { } else {
skipQuestProcess("heroes-exp-amounts: Reward in Quest " + quest.getName() + " is not a list of experience amounts (decimal numbers)!"); skipQuestProcess("heroes-exp-amounts: Reward in Quest " + quest.getName() + " is not a list of experience amounts (decimal numbers)!");
} }
@ -1001,7 +1002,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
skipQuestProcess("" + loot + " in phat-loots: Reward in Quest " + quest.getName() + " is not a valid PhatLoot name!"); skipQuestProcess("" + loot + " in phat-loots: Reward in Quest " + quest.getName() + " is not a valid PhatLoot name!");
} }
} }
rews.setPhatLoots(config.getStringList("quests." + questKey + ".rewards.phat-loots")); rews.setPhatLoots((LinkedList<String>) config.getStringList("quests." + questKey + ".rewards.phat-loots"));
} else { } else {
skipQuestProcess("phat-loots: Reward in Quest " + quest.getName() + " is not a list of PhatLoots!"); skipQuestProcess("phat-loots: Reward in Quest " + quest.getName() + " is not a list of PhatLoots!");
} }
@ -1877,7 +1878,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
continue; continue;
} else { } else {
ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data"); ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data");
Map<String, Object> data=populateCustoms(sec2,found.get().datamap); Map<String, Object> data = populateCustoms(sec2, found.get().getData()); // Added in Github PR #554
oStage.customObjectives.add(found.get()); oStage.customObjectives.add(found.get());
oStage.customObjectiveCounts.add(count); oStage.customObjectiveCounts.add(count);
@ -2653,7 +2654,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return hero.getHeroClass().getName().equalsIgnoreCase(primaryClass); return hero.getHeroClass().getName().equalsIgnoreCase(primaryClass);
} }
@SuppressWarnings("deprecation")
public boolean testSecondaryHeroesClass(String secondaryClass, UUID uuid) { public boolean testSecondaryHeroesClass(String secondaryClass, UUID uuid) {
Hero hero = getHero(uuid); Hero hero = getHero(uuid);
return hero.getSecondClass().getName().equalsIgnoreCase(secondaryClass); return hero.getSecondClass().getName().equalsIgnoreCase(secondaryClass);

View File

@ -23,14 +23,14 @@ public class Rewards {
private int money = 0; private int money = 0;
private int questPoints = 0; private int questPoints = 0;
private int exp = 0; private int exp = 0;
private List<String> commands = new LinkedList<String>(); private LinkedList<String> commands = new LinkedList<String>();
private List<String> permissions = new LinkedList<String>(); private LinkedList<String> permissions = new LinkedList<String>();
private LinkedList<ItemStack> items = new LinkedList<ItemStack>(); private LinkedList<ItemStack> items = new LinkedList<ItemStack>();
private List<String> mcmmoSkills = new LinkedList<String>(); private LinkedList<String> mcmmoSkills = new LinkedList<String>();
private List<Integer> mcmmoAmounts = new LinkedList<Integer>(); private LinkedList<Integer> mcmmoAmounts = new LinkedList<Integer>();
private List<String> heroesClasses = new LinkedList<String>(); private LinkedList<String> heroesClasses = new LinkedList<String>();
private List<Double> heroesAmounts = new LinkedList<Double>(); private LinkedList<Double> heroesAmounts = new LinkedList<Double>();
private List<String> phatLoots = new LinkedList<String>(); private LinkedList<String> phatLoots = new LinkedList<String>();
private Map<String, Map<String, Object>> customRewards = new HashMap<String, Map<String, Object>>(); private Map<String, Map<String, Object>> customRewards = new HashMap<String, Map<String, Object>>();
public int getMoney() { public int getMoney() {
@ -54,13 +54,13 @@ public class Rewards {
public List<String> getCommands() { public List<String> getCommands() {
return commands; return commands;
} }
public void setCommands(List<String> commands) { public void setCommands(LinkedList<String> commands) {
this.commands = commands; this.commands = commands;
} }
public List<String> getPermissions() { public List<String> getPermissions() {
return permissions; return permissions;
} }
public void setPermissions(List<String> permissions) { public void setPermissions(LinkedList<String> permissions) {
this.permissions = permissions; this.permissions = permissions;
} }
public LinkedList<ItemStack> getItems() { public LinkedList<ItemStack> getItems() {
@ -72,31 +72,31 @@ public class Rewards {
public List<String> getMcmmoSkills() { public List<String> getMcmmoSkills() {
return mcmmoSkills; return mcmmoSkills;
} }
public void setMcmmoSkills(List<String> mcmmoSkills) { public void setMcmmoSkills(LinkedList<String> mcmmoSkills) {
this.mcmmoSkills = mcmmoSkills; this.mcmmoSkills = mcmmoSkills;
} }
public List<Integer> getMcmmoAmounts() { public List<Integer> getMcmmoAmounts() {
return mcmmoAmounts; return mcmmoAmounts;
} }
public void setMcmmoAmounts(List<Integer> mcmmoAmounts) { public void setMcmmoAmounts(LinkedList<Integer> mcmmoAmounts) {
this.mcmmoAmounts = mcmmoAmounts; this.mcmmoAmounts = mcmmoAmounts;
} }
public List<String> getHeroesClasses() { public List<String> getHeroesClasses() {
return heroesClasses; return heroesClasses;
} }
public void setHeroesClasses(List<String> heroesClasses) { public void setHeroesClasses(LinkedList<String> heroesClasses) {
this.heroesClasses = heroesClasses; this.heroesClasses = heroesClasses;
} }
public List<Double> getHeroesAmounts() { public List<Double> getHeroesAmounts() {
return heroesAmounts; return heroesAmounts;
} }
public void setHeroesAmounts(List<Double> heroesAmounts) { public void setHeroesAmounts(LinkedList<Double> heroesAmounts) {
this.heroesAmounts = heroesAmounts; this.heroesAmounts = heroesAmounts;
} }
public List<String> getPhatLoots() { public List<String> getPhatLoots() {
return phatLoots; return phatLoots;
} }
public void setPhatLoots(List<String> phatLoots) { public void setPhatLoots(LinkedList<String> phatLoots) {
this.phatLoots = phatLoots; this.phatLoots = phatLoots;
} }
public Map<String, Map<String, Object>> getCustomRewards() { public Map<String, Map<String, Object>> getCustomRewards() {

View File

@ -3869,7 +3869,7 @@ public class CreateStagePrompt extends FixedSetPrompt {
LinkedList<Integer> countList = (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT); LinkedList<Integer> countList = (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
if (list.contains(found.getName()) == false) { if (list.contains(found.getName()) == false) {
list.add(found.getName()); list.add(found.getName());
datamapList.add(found.datamap); datamapList.add(found.getData());
countList.add(-999); countList.add(-999);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList);
@ -3880,7 +3880,7 @@ public class CreateStagePrompt extends FixedSetPrompt {
} else { } else {
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>(); LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
LinkedList<Integer> countList = new LinkedList<Integer>(); LinkedList<Integer> countList = new LinkedList<Integer>();
datamapList.add(found.datamap); datamapList.add(found.getData());
countList.add(-999); countList.add(-999);
LinkedList<String> list = new LinkedList<String>(); LinkedList<String> list = new LinkedList<String>();
list.add(found.getName()); list.add(found.getName());
@ -3892,8 +3892,8 @@ public class CreateStagePrompt extends FixedSetPrompt {
if (found.isEnableCount()) { if (found.isEnableCount()) {
return new CustomObjectiveCountPrompt(); return new CustomObjectiveCountPrompt();
} }
if (found.datamap.isEmpty() == false) { if (found.getData().isEmpty() == false) {
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.descriptions); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.getDescriptions());
return new ObjectiveCustomDataListPrompt(); return new ObjectiveCustomDataListPrompt();
} }
// //
@ -3949,8 +3949,8 @@ public class CreateStagePrompt extends FixedSetPrompt {
break; break;
} }
} }
if (found != null && found.datamap.isEmpty() == false) { if (found != null && found.getData().isEmpty() == false) {
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.descriptions); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.getDescriptions());
return new ObjectiveCustomDataListPrompt(); return new ObjectiveCustomDataListPrompt();
} else { } else {
return new CreateStagePrompt(plugin, stageNum, questFactory, citizens); return new CreateStagePrompt(plugin, stageNum, questFactory, citizens);