Refactoring for getter/setter methods, part 8. See #625

This commit is contained in:
BuildTools 2019-01-15 18:49:01 -05:00
parent 1edc8913e4
commit cff144479b
4 changed files with 56 additions and 16 deletions

View File

@ -23,8 +23,8 @@ public abstract class CustomObjective implements Listener {
private Quests plugin = Quests.getPlugin(Quests.class);
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>();
private String countPrompt = "null";
private String display = "null";
private boolean enableCount = true;
@ -46,9 +46,36 @@ public abstract class CustomObjective implements Listener {
public void setAuthor(String author) {
this.author = author;
}
public Map<String, Object> getData() {
return data;
}
/**
* Add a 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 null data for name
*
* @param name
* @deprecated use addDatum()
*/
public void addData(String name) {
datamap.put(name, null);
addDatum(name, null);
}
public Map<String, String> getDescriptions() {
return descriptions;
}
public void addDescription(String data, String description) {
@ -94,7 +121,20 @@ public abstract class CustomObjective implements Listener {
public void setEnableCount(boolean 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) {
Quester quester = plugin.getQuester(player.getUniqueId());
if (quester != null) {
@ -161,13 +201,13 @@ public abstract class CustomObjective implements Listener {
if (other.author.equals(name) == false) {
return false;
}
for (String s : other.datamap.keySet()) {
if (datamap.containsKey(s) == false) {
for (String s : other.getData().keySet()) {
if (getData().containsKey(s) == false) {
return false;
}
}
for (Object val : other.datamap.values()) {
if (datamap.containsValue(val) == false) {
for (Object val : other.getData().values()) {
if (getData().containsValue(val) == false) {
return false;
}
}

View File

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

View File

@ -1877,7 +1877,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()); // Added in Github PR #554
oStage.customObjectives.add(found.get());
oStage.customObjectiveCounts.add(count);

View File

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