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!
## 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/
@ -12,8 +12,7 @@ Documentation can be found in the Wiki: https://github.com/FlyingPikachu/Quests/
## Compile
Building requires Java 8 and Maven:
https://github.com/FlyingPikachu/Quests/wiki/Master-%E2%80%90-Plugin-Compilation
Requires Java 8 and Maven: 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)

View File

@ -25,8 +25,8 @@ public abstract class CustomObjective implements Listener {
private String author = null;
private Map<String, Object> data = new HashMap<String, Object>();
private Map<String, String> descriptions = new HashMap<String, String>();
private String countPrompt = "null";
private String display = "null";
private String countPrompt = "Enter number";
private String display = "%data%: %count%";
private boolean showCount = true;
private int count = 1;
@ -48,56 +48,45 @@ public abstract class CustomObjective implements Listener {
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);
}
/**
* Add a detailed piece of datum to the data map
* Set the title of a prompt
*
* @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 a detailed piece of datum to the data map
*
* @param name
* @deprecated use addDatum(name, o)
*/
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)
* @param name Prompt title
* @deprecated use addPrompt(name, description)
*/
public void addData(String name) {
addDatum(name);
data.put(name, null);
}
public Map<String, String> getDescriptions() {
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() {
@ -108,7 +97,7 @@ public abstract class CustomObjective implements Listener {
this.count = count;
}
public String getCountPrompt() {
public String getCountPrompt() {
return countPrompt;
}

View File

@ -21,8 +21,8 @@ public abstract class CustomRequirement {
private String name = null;
private String author = null;
public final Map<String, Object> datamap = new HashMap<String, Object>();
public final Map<String, String> descriptions = new HashMap<String, String>();
private Map<String, Object> data = new HashMap<String, Object>();
private Map<String, String> descriptions = new HashMap<String, String>();
public abstract boolean testRequirement(Player p, Map<String, Object> m);
@ -42,11 +42,46 @@ public abstract class CustomRequirement {
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) {
datamap.put(name, null);
data.put(name, null);
}
public void addDescription(String data, String description) {
descriptions.put(data, description);
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 author = null;
private String rewardName = null;
public final Map<String, Object> datamap = new HashMap<String, Object>();
public final Map<String, String> descriptions = new HashMap<String, String>();
private Map<String, Object> data = new HashMap<String, Object>();
private Map<String, String> descriptions = new HashMap<String, String>();
public abstract void giveReward(Player p, Map<String, Object> m);
@ -42,20 +42,55 @@ public abstract class CustomReward {
public void setAuthor(String author) {
this.author = author;
}
public void addData(String name) {
datamap.put(name, null);
public Map<String, Object> getData() {
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);
}
public String getRewardName() {
return rewardName;
}
public void setRewardName(String name) {
rewardName = name;
}
public String getRewardName() {
return rewardName;
}
}

View File

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

View File

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

View File

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