Refactoring for getter/setter methods, part 9

This commit is contained in:
BuildTools 2019-01-19 13:14:10 -05:00
parent 69caf13bcd
commit 570d589f3f
7 changed files with 145 additions and 77 deletions

View File

@ -1,8 +1,8 @@
# Quests # Quests [![Build Status](http://ci.ac3-servers.eu/buildStatus/icon?job=Quests)](http://ci.ac3-servers.eu/job/Quests/)
Quests plugin for Spigot. This work depends on contributions from coders like you! Quests plugin for Spigot. This work depends on contributions from coders like you!
## Download [![Build Status](http://ci.ac3-servers.eu/buildStatus/icon?job=Quests)](http://ci.ac3-servers.eu/job/Quests/) ## Download
Distributed exclusively through Spigot: https://www.spigotmc.org/resources/quests.3711/ Distributed exclusively through Spigot: https://www.spigotmc.org/resources/quests.3711/
@ -12,8 +12,7 @@ Documentation can be found in the Wiki: https://github.com/FlyingPikachu/Quests/
## Compile ## Compile
Building requires Java 8 and Maven: Requires Java 8 and Maven: https://github.com/FlyingPikachu/Quests/wiki/Master-%E2%80%90-Plugin-Compilation
https://github.com/FlyingPikachu/Quests/wiki/Master-%E2%80%90-Plugin-Compilation
## Localization [![Crowdin](https://d322cqt584bo4o.cloudfront.net/translate-quests/localized.svg)](https://crowdin.com/project/translate-quests) ## Localization [![Crowdin](https://d322cqt584bo4o.cloudfront.net/translate-quests/localized.svg)](https://crowdin.com/project/translate-quests)

View File

@ -25,8 +25,8 @@ public abstract class CustomObjective implements Listener {
private String author = null; private String author = null;
private Map<String, Object> data = new HashMap<String, Object>(); private Map<String, Object> data = new HashMap<String, Object>();
private Map<String, String> descriptions = new HashMap<String, String>(); private Map<String, String> descriptions = new HashMap<String, String>();
private String countPrompt = "null"; private String countPrompt = "Enter number";
private String display = "null"; private String display = "%data%: %count%";
private boolean showCount = true; private boolean showCount = true;
private int count = 1; private int count = 1;
@ -51,53 +51,42 @@ public abstract class CustomObjective implements Listener {
} }
/** /**
* Add a detailed piece of datum to the data map * Add a new prompt<p>
* *
* @param name * Note that the "defaultValue" Object will be cast to a String internally
* @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 * @param title Prompt name
* @param description Description of expected input
* @param defaultValue Value to be used if input is not received
*/ */
public void addDatum(String name) { public void addStringPrompt(String title, String description, Object defaultValue) {
data.put(name, null); data.put(name, defaultValue);
descriptions.put(name, description);
} }
/** /**
* Add a detailed piece of datum to the data map * Set the title of a prompt
* *
* @param name * @param name Prompt title
* @deprecated use addDatum(name, o) * @deprecated use addPrompt(name, description)
*/
public void addData(String name, Object o) {
addDatum(name, o);
}
/**
* Add a blank piece of datum to the data map
*
* @param name
* @deprecated use addDatum(name)
*/ */
public void addData(String name) { public void addData(String name) {
addDatum(name); data.put(name, null);
} }
public Map<String, String> getDescriptions() { public Map<String, String> getDescriptions() {
return descriptions; return descriptions;
} }
public void addDescription(String data, String description) { /**
descriptions.put(data, description); * Set the description for the specified prompt
*
* @param name Prompt title
* @param description Description of expected input
* @deprecated use addTaskPrompt(name, description)
*/
public void addDescription(String name, String description) {
descriptions.put(name, description);
} }
public int getCount() { public int getCount() {
@ -108,7 +97,7 @@ public abstract class CustomObjective implements Listener {
this.count = count; this.count = count;
} }
public String getCountPrompt() { public String getCountPrompt() {
return countPrompt; return countPrompt;
} }

View File

@ -21,8 +21,8 @@ public abstract class CustomRequirement {
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>();
public abstract boolean testRequirement(Player p, Map<String, Object> m); public abstract boolean testRequirement(Player p, Map<String, Object> m);
@ -42,11 +42,46 @@ public abstract class CustomRequirement {
this.author = author; this.author = author;
} }
public void addData(String name) { public Map<String, Object> getData() {
datamap.put(name, null); return data;
} }
public void addDescription(String data, String description) { /**
descriptions.put(data, description); * Add a new prompt<p>
*
* Note that the "defaultValue" Object will be cast to a String internally
*
* @param title Prompt name
* @param description Description of expected input
* @param defaultValue Value to be used if input is not received
*/
public void addStringPrompt(String title, String description, Object defaultValue) {
data.put(name, defaultValue);
descriptions.put(name, description);
}
/**
* Set the title of a prompt
*
* @param name Prompt title
* @deprecated use addPrompt(name, description)
*/
public void addData(String name) {
data.put(name, null);
}
public Map<String, String> getDescriptions() {
return descriptions;
}
/**
* Set the description for the specified prompt
*
* @param name Prompt title
* @param description Description of expected input
* @deprecated use addTaskPrompt(name, description)
*/
public void addDescription(String name, String description) {
descriptions.put(name, description);
} }
} }

View File

@ -22,8 +22,8 @@ public abstract class CustomReward {
private String name = null; private String name = null;
private String author = null; private String author = null;
private String rewardName = null; private String rewardName = 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>();
public abstract void giveReward(Player p, Map<String, Object> m); public abstract void giveReward(Player p, Map<String, Object> m);
@ -43,19 +43,54 @@ public abstract class CustomReward {
this.author = author; this.author = author;
} }
public Map<String, Object> getData() {
return data;
}
/**
* Add a new prompt<p>
*
* Note that the "defaultValue" Object will be cast to a String internally
*
* @param title Prompt name
* @param description Description of expected input
* @param defaultValue Value to be used if input is not received
*/
public void addStringPrompt(String title, String description, Object defaultValue) {
data.put(name, defaultValue);
descriptions.put(name, description);
}
/**
* Set the title of a prompt
*
* @param name Prompt title
* @deprecated use addPrompt(name, description)
*/
public void addData(String name) { public void addData(String name) {
datamap.put(name, null); data.put(name, null);
} }
public void addDescription(String data, String description) { public Map<String, String> getDescriptions() {
descriptions.put(data, description); return descriptions;
} }
public void setRewardName(String name) { /**
rewardName = name; * Set the description for the specified prompt
*
* @param name Prompt title
* @param description Description of expected input
* @deprecated use addTaskPrompt(name, description)
*/
public void addDescription(String name, String description) {
descriptions.put(name, description);
} }
public String getRewardName() { public String getRewardName() {
return rewardName; return rewardName;
} }
public void setRewardName(String name) {
rewardName = name;
}
} }

View File

@ -2016,7 +2016,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());
temp.put(name, data); temp.put(name, data);
} }
} }
@ -2040,7 +2040,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
skipQuestProcess((String) null); // null bc we warn, not severe for this one skipQuestProcess((String) null); // null bc we warn, not severe for this one
} 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());
temp.put(name, data); temp.put(name, data);
} }
} }
@ -2054,10 +2054,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
*/ */
static Map<String, Object> populateCustoms(ConfigurationSection sec2,Map<String, Object> datamap) { static Map<String, Object> populateCustoms(ConfigurationSection sec2,Map<String, Object> datamap) {
Map<String,Object>data=new HashMap<String,Object>(); Map<String,Object> data = new HashMap<String,Object>();
if(sec2!=null) { if(sec2 != null) {
for(String key:datamap.keySet()) { for(String key : datamap.keySet()) {
data.put(key,sec2.contains(key)?sec2.get(key):datamap.get(key)!=null?datamap.get(key):new String()); data.put(key, sec2.contains(key) ? sec2.get(key):datamap.get(key) != null ? datamap.get(key) : new String());
} }
} }
return data; return data;

View File

@ -490,6 +490,7 @@ public class RequirementsPrompt extends FixedSetPrompt {
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
CustomRequirement found = null; CustomRequirement found = null;
// Check if we have a custom requirement with the specified name
for (CustomRequirement cr : plugin.getCustomRequirements()) { for (CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getName().equalsIgnoreCase(input)) { if (cr.getName().equalsIgnoreCase(input)) {
found = cr; found = cr;
@ -497,6 +498,7 @@ public class RequirementsPrompt extends FixedSetPrompt {
} }
} }
if (found == null) { if (found == null) {
// No? Check again, but with locale sensitivity
for (CustomRequirement cr : plugin.getCustomRequirements()) { for (CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getName().toLowerCase().contains(input.toLowerCase())) { if (cr.getName().toLowerCase().contains(input.toLowerCase())) {
found = cr; found = cr;
@ -506,31 +508,34 @@ public class RequirementsPrompt extends FixedSetPrompt {
} }
if (found != null) { if (found != null) {
if (context.getSessionData(CK.REQ_CUSTOM) != null) { if (context.getSessionData(CK.REQ_CUSTOM) != null) {
// The custom requirement may already have been added, so let's check that
LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM); LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM);
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA); LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
if (list.contains(found.getName()) == false) { if (list.contains(found.getName()) == false) {
// Hasn't been added yet, so let's do it
list.add(found.getName()); list.add(found.getName());
datamapList.add(found.datamap); datamapList.add(found.getData());
context.setSessionData(CK.REQ_CUSTOM, list); context.setSessionData(CK.REQ_CUSTOM, list);
context.setSessionData(CK.REQ_CUSTOM_DATA, datamapList); context.setSessionData(CK.REQ_CUSTOM_DATA, datamapList);
} else { } else {
// Already added, so inform user
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomAlreadyAdded")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomAlreadyAdded"));
return new CustomRequirementsPrompt(); return new CustomRequirementsPrompt();
} }
} else { } else {
// The custom requirement hasn't been added yet, so let's do it
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>(); LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
datamapList.add(found.datamap); datamapList.add(found.getData());
LinkedList<String> list = new LinkedList<String>(); LinkedList<String> list = new LinkedList<String>();
list.add(found.getName()); list.add(found.getName());
context.setSessionData(CK.REQ_CUSTOM, list); context.setSessionData(CK.REQ_CUSTOM, list);
context.setSessionData(CK.REQ_CUSTOM_DATA, datamapList); context.setSessionData(CK.REQ_CUSTOM_DATA, datamapList);
} }
// Send user to the custom data prompt if there is any needed // Send user to the custom data prompt if there is any needed
if (found.datamap.isEmpty() == false) { if (found.getData().isEmpty() == false) {
context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, found.descriptions); context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, found.getDescriptions());
return new RequirementCustomDataListPrompt(); return new RequirementCustomDataListPrompt();
} }
//
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomNotFound")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomNotFound"));
return new CustomRequirementsPrompt(); return new CustomRequirementsPrompt();

View File

@ -769,6 +769,7 @@ public class RewardsPrompt extends FixedSetPrompt {
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
CustomReward found = null; CustomReward found = null;
// Check if we have a custom reward with the specified name
for (CustomReward cr : plugin.getCustomRewards()) { for (CustomReward cr : plugin.getCustomRewards()) {
if (cr.getName().equalsIgnoreCase(input)) { if (cr.getName().equalsIgnoreCase(input)) {
found = cr; found = cr;
@ -776,6 +777,7 @@ public class RewardsPrompt extends FixedSetPrompt {
} }
} }
if (found == null) { if (found == null) {
// No? Check again, but with locale sensitivity
for (CustomReward cr : plugin.getCustomRewards()) { for (CustomReward cr : plugin.getCustomRewards()) {
if (cr.getName().toLowerCase().contains(input.toLowerCase())) { if (cr.getName().toLowerCase().contains(input.toLowerCase())) {
found = cr; found = cr;
@ -785,31 +787,34 @@ public class RewardsPrompt extends FixedSetPrompt {
} }
if (found != null) { if (found != null) {
if (context.getSessionData(CK.REW_CUSTOM) != null) { if (context.getSessionData(CK.REW_CUSTOM) != null) {
// The custom reward may already have been added, so let's check that
LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REW_CUSTOM); LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REW_CUSTOM);
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REW_CUSTOM_DATA); LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REW_CUSTOM_DATA);
if (list.contains(found.getName()) == false) { if (list.contains(found.getName()) == false) {
// Hasn't been added yet, so let's do it
list.add(found.getName()); list.add(found.getName());
datamapList.add(found.datamap); datamapList.add(found.getData());
context.setSessionData(CK.REW_CUSTOM, list); context.setSessionData(CK.REW_CUSTOM, list);
context.setSessionData(CK.REW_CUSTOM_DATA, datamapList); context.setSessionData(CK.REW_CUSTOM_DATA, datamapList);
} else { } else {
// Already added, so inform user
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewCustomAlreadyAdded")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewCustomAlreadyAdded"));
return new CustomRewardsPrompt(); return new CustomRewardsPrompt();
} }
} else { } else {
// The custom reward hasn't been added yet, so let's do it
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>(); LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
datamapList.add(found.datamap); datamapList.add(found.getData());
LinkedList<String> list = new LinkedList<String>(); LinkedList<String> list = new LinkedList<String>();
list.add(found.getName()); list.add(found.getName());
context.setSessionData(CK.REW_CUSTOM, list); context.setSessionData(CK.REW_CUSTOM, list);
context.setSessionData(CK.REW_CUSTOM_DATA, datamapList); context.setSessionData(CK.REW_CUSTOM_DATA, datamapList);
} }
// Send user to the custom data prompt if there is any needed // Send user to the custom data prompt if there is any needed
if (found.datamap.isEmpty() == false) { if (found.getData().isEmpty() == false) {
context.setSessionData(CK.REW_CUSTOM_DATA_DESCRIPTIONS, found.descriptions); context.setSessionData(CK.REW_CUSTOM_DATA_DESCRIPTIONS, found.getDescriptions());
return new RewardCustomDataListPrompt(); return new RewardCustomDataListPrompt();
} }
//
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewCustomNotFound")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewCustomNotFound"));
return new CustomRewardsPrompt(); return new CustomRewardsPrompt();