mirror of
https://github.com/PikaMug/Quests.git
synced 2025-02-16 12:31:19 +01:00
Started Custom Rewards API (Unstable)
This commit is contained in:
parent
91c7e5a26c
commit
f33786a746
BIN
lib/CustomReward.jar
Normal file
BIN
lib/CustomReward.jar
Normal file
Binary file not shown.
49
src/main/java/me/blackvein/quests/CustomReward.java
Normal file
49
src/main/java/me/blackvein/quests/CustomReward.java
Normal file
@ -0,0 +1,49 @@
|
||||
package me.blackvein.quests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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>();
|
||||
|
||||
public abstract void giveReward(Player p, Map<String, Object> m);
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public void addData(String name) {
|
||||
datamap.put(name, null);
|
||||
}
|
||||
|
||||
public void addDescription(String data, String description){
|
||||
descriptions.put(data, description);
|
||||
}
|
||||
|
||||
public void setRewardName(String name){
|
||||
rewardName = name;
|
||||
}
|
||||
|
||||
public String getRewardName(){
|
||||
return rewardName;
|
||||
}
|
||||
|
||||
}
|
@ -55,6 +55,7 @@ public class Quest {
|
||||
String heroesPrimaryClassReq = null;
|
||||
String heroesSecondaryClassReq = null;
|
||||
Map<String, Map<String, Object>> customRequirements = new HashMap<String, Map<String, Object>>();
|
||||
Map<String, Map<String, Object>> customRewards = new HashMap<String, Map<String, Object>>();
|
||||
public String failRequirements = null;
|
||||
//
|
||||
//Rewards
|
||||
@ -477,6 +478,27 @@ public class Quest {
|
||||
}
|
||||
none = null;
|
||||
}
|
||||
|
||||
for (String s : customRewards.keySet()){
|
||||
|
||||
CustomReward found = null;
|
||||
for(CustomReward cr : plugin.customRewards){
|
||||
if(cr.getName().equalsIgnoreCase(s)){
|
||||
found = cr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(found != null){
|
||||
player.sendMessage("- " + ChatColor.GOLD + found.getRewardName());
|
||||
found.giveReward(player, customRewards.get(s));
|
||||
}else{
|
||||
Quests.printWarning("[Quests] Quester \"" + player.getName() + "\" completed the Quest \"" + name + "\", but the Custom Reward \"" + s + "\" could not be found. Does it still exist?");
|
||||
}
|
||||
|
||||
none = null;
|
||||
|
||||
}
|
||||
|
||||
if (none != null) {
|
||||
player.sendMessage(none);
|
||||
@ -664,6 +686,10 @@ public class Quest {
|
||||
if (other.customRequirements.equals(customRequirements) == false){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.customRewards.equals(customRewards) == false){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.permissions.equals(permissions) == false) {
|
||||
return false;
|
||||
|
@ -114,6 +114,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
public final Map<String, Quester> questers = new HashMap<String, Quester>();
|
||||
public final List<String> questerBlacklist = new LinkedList<String>();
|
||||
public final List<CustomRequirement> customRequirements = new LinkedList<CustomRequirement>();
|
||||
public final List<CustomReward> customRewards = new LinkedList<CustomReward>();
|
||||
public final LinkedList<Quest> quests = new LinkedList<Quest>();
|
||||
public final LinkedList<Event> events = new LinkedList<Event>();
|
||||
public final LinkedList<NPC> questNPCs = new LinkedList<NPC>();
|
||||
@ -471,13 +472,30 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
String className = je.getName().substring(0, je.getName().length() - 6);
|
||||
className = className.replace('/', '.');
|
||||
Class<?> c = Class.forName(className, true, cl);
|
||||
Class<? extends CustomRequirement> requirementClass = c.asSubclass(CustomRequirement.class);
|
||||
Constructor<? extends CustomRequirement> cstrctr = requirementClass.getConstructor();
|
||||
CustomRequirement requirement = cstrctr.newInstance();
|
||||
customRequirements.add(requirement);
|
||||
String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName();
|
||||
String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor();
|
||||
printInfo("[Quests] Loaded Module: " + name + " by " + author);
|
||||
|
||||
if(CustomRequirement.class.isAssignableFrom(c)){
|
||||
|
||||
Class<? extends CustomRequirement> requirementClass = c.asSubclass(CustomRequirement.class);
|
||||
Constructor<? extends CustomRequirement> cstrctr = requirementClass.getConstructor();
|
||||
CustomRequirement requirement = cstrctr.newInstance();
|
||||
customRequirements.add(requirement);
|
||||
String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName();
|
||||
String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor();
|
||||
printInfo("[Quests] Loaded Module: " + name + " by " + author);
|
||||
|
||||
}else if(CustomReward.class.isAssignableFrom(c)){
|
||||
|
||||
Class<? extends CustomReward> rewardClass = c.asSubclass(CustomReward.class);
|
||||
Constructor<? extends CustomReward> cstrctr = rewardClass.getConstructor();
|
||||
CustomReward reward = cstrctr.newInstance();
|
||||
customRewards.add(reward);
|
||||
String name = reward.getName() == null ? "[" + jar.getName() + "]" : reward.getName();
|
||||
String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor();
|
||||
printInfo("[Quests] Loaded Module: " + name + " by " + author);
|
||||
|
||||
}else{
|
||||
printSevere("[Quests] Error: Unable to load module from file: " + jar.getName() + ", jar file is not a valid module!");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -3674,6 +3692,40 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.contains("quests." + s + ".rewards.custom-rewards")) {
|
||||
|
||||
ConfigurationSection sec = config.getConfigurationSection("quests." + s + ".rewards.custom-rewards");
|
||||
for (String path : sec.getKeys(false)) {
|
||||
|
||||
String name = sec.getString(path + ".name");
|
||||
boolean found = false;
|
||||
|
||||
for (CustomReward cr : customRewards) {
|
||||
if (cr.getName().equalsIgnoreCase(name)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
printWarning("[Quests] Custom reward \"" + name + "\" for Quest \"" + quest.name + "\" could not be found!");
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
ConfigurationSection sec2 = sec.getConfigurationSection(path + ".data");
|
||||
if (sec2 != null) {
|
||||
for (String dataPath : sec2.getKeys(false)) {
|
||||
data.put(dataPath, sec2.get(dataPath));
|
||||
}
|
||||
}
|
||||
|
||||
quest.customRewards.put(name, data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
quests.add(quest);
|
||||
|
@ -31,7 +31,7 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
|
||||
|
||||
public RewardsPrompt(Quests plugin, QuestFactory qf) {
|
||||
|
||||
super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
|
||||
super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");
|
||||
quests = plugin;
|
||||
factory = qf;
|
||||
|
||||
@ -180,8 +180,20 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
|
||||
text += GRAY + "10 - Set PhatLoot rewards (PhatLoots not installed)\n";
|
||||
|
||||
}
|
||||
|
||||
if (context.getSessionData(CK.REW_CUSTOM) == null) {a
|
||||
text += BLUE + "" + BOLD + "11 - " + RESET + ITALIC + PURPLE + "Custom Rewards (None set)\n";
|
||||
} else {
|
||||
text += BLUE + "" + BOLD + "11 - " + RESET + ITALIC + PURPLE + "Custom Rewards\n";
|
||||
LinkedList<String> customRews = (LinkedList<String>) context.getSessionData(CK.REW_CUSTOM);
|
||||
for(String s : customRews){
|
||||
|
||||
text += RESET + "" + PURPLE + " - " + PINK + s + "\n";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
text += GREEN + "" + BOLD + "11" + RESET + YELLOW + " - Done";
|
||||
text += GREEN + "" + BOLD + "12" + RESET + YELLOW + " - Done";
|
||||
|
||||
return text;
|
||||
|
||||
@ -1106,5 +1118,195 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private class CustomRequirementsPrompt extends StringPrompt {
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
String text = PINK + "- Custom Requirements -\n";
|
||||
if(quests.customRequirements.isEmpty()){
|
||||
text += BOLD + "" + PURPLE + "(No modules loaded)";
|
||||
}else {
|
||||
for(CustomRequirement cr : quests.customRequirements)
|
||||
text += PURPLE + " - " + cr.getName() + "\n";
|
||||
}
|
||||
|
||||
return text + YELLOW + "Enter the name of a custom requirement to add, or enter \'clear\' to clear all custom requirements, or \'cancel\' to return.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
|
||||
if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) {
|
||||
|
||||
CustomRequirement found = null;
|
||||
for(CustomRequirement cr : quests.customRequirements){
|
||||
if(cr.getName().equalsIgnoreCase(input)){
|
||||
found = cr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(found == null){
|
||||
for(CustomRequirement cr : quests.customRequirements){
|
||||
if(cr.getName().toLowerCase().contains(input.toLowerCase())){
|
||||
found = cr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(found != null){
|
||||
|
||||
if(context.getSessionData(CK.REQ_CUSTOM) != null){
|
||||
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){
|
||||
list.add(found.getName());
|
||||
datamapList.add(found.datamap);
|
||||
}else{
|
||||
context.getForWhom().sendRawMessage(YELLOW + "That custom requirement has already been added!");
|
||||
return new CustomRequirementsPrompt();
|
||||
}
|
||||
}else{
|
||||
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
|
||||
datamapList.add(found.datamap);
|
||||
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);
|
||||
return new RequirementCustomDataListPrompt();
|
||||
|
||||
}
|
||||
//
|
||||
|
||||
}else{
|
||||
context.getForWhom().sendRawMessage(YELLOW + "Custom requirement module not found.");
|
||||
return new CustomRequirementsPrompt();
|
||||
}
|
||||
|
||||
} else if (input.equalsIgnoreCase("clear")) {
|
||||
context.setSessionData(CK.REQ_CUSTOM, null);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA, null);
|
||||
context.getForWhom().sendRawMessage(YELLOW + "Custom requirements cleared.");
|
||||
}
|
||||
|
||||
return new RequirementsPrompt(quests, factory);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private class RequirementCustomDataListPrompt extends StringPrompt {
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
|
||||
String text = BOLD + "" + AQUA + "- ";
|
||||
|
||||
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);
|
||||
|
||||
String reqName = list.getLast();
|
||||
Map<String, Object> datamap = datamapList.getLast();
|
||||
|
||||
text += reqName + " -\n";
|
||||
int index = 1;
|
||||
|
||||
LinkedList<String> datamapKeys = new LinkedList<String>();
|
||||
for(String key : datamap.keySet())
|
||||
datamapKeys.add(key);
|
||||
Collections.sort(datamapKeys);
|
||||
|
||||
for(String dataKey : datamapKeys){
|
||||
|
||||
text += BOLD + "" + DARKBLUE + index + " - " + RESET + BLUE + dataKey;
|
||||
if(datamap.get(dataKey) != null)
|
||||
text += GREEN + " (" + (String) datamap.get(dataKey) + ")\n";
|
||||
else
|
||||
text += RED + " (Value required)\n";
|
||||
|
||||
index++;
|
||||
|
||||
}
|
||||
|
||||
text += BOLD + "" + DARKBLUE + index + " - " + AQUA + "Finish";
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
|
||||
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
Map<String, Object> datamap = datamapList.getLast();
|
||||
|
||||
int numInput;
|
||||
|
||||
try{
|
||||
numInput = Integer.parseInt(input);
|
||||
}catch(NumberFormatException nfe){
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
|
||||
if(numInput < 1 || numInput > datamap.size() + 1)
|
||||
return new RequirementCustomDataListPrompt();
|
||||
|
||||
if(numInput < datamap.size() + 1){
|
||||
|
||||
LinkedList<String> datamapKeys = new LinkedList<String>();
|
||||
for(String key : datamap.keySet())
|
||||
datamapKeys.add(key);
|
||||
Collections.sort(datamapKeys);
|
||||
|
||||
String selectedKey = datamapKeys.get(numInput - 1);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, selectedKey);
|
||||
return new RequirementCustomDataPrompt();
|
||||
|
||||
}else{
|
||||
|
||||
if(datamap.containsValue(null)){
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}else{
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, null);
|
||||
return new RequirementsPrompt(quests, factory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class RequirementCustomDataPrompt extends StringPrompt {
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
String text = "";
|
||||
String temp = (String)context.getSessionData(CK.REQ_CUSTOM_DATA_TEMP);
|
||||
Map<String, String> descriptions = (Map<String, String>) context.getSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS);
|
||||
if(descriptions.get(temp) != null)
|
||||
text += GOLD + descriptions.get(temp) + "\n";
|
||||
|
||||
text += YELLOW + "Enter value for ";
|
||||
text += BOLD + temp + RESET + YELLOW + ":";
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA);
|
||||
Map<String, Object> datamap = datamapList.getLast();
|
||||
datamap.put((String)context.getSessionData(CK.REQ_CUSTOM_DATA_TEMP), input);
|
||||
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, null);
|
||||
return new RequirementCustomDataListPrompt();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,10 @@ public class CK {
|
||||
public static final String REW_HEROES_CLASSES = "heroesClassRews";
|
||||
public static final String REW_HEROES_AMOUNTS = "heroesAmountRews";
|
||||
public static final String REW_PHAT_LOOTS = "phatLootRews";
|
||||
|
||||
public static final String REW_CUSTOM = "customRews";
|
||||
public static final String REW_CUSTOM_DATA = "customRewData";
|
||||
public static final String REW_CUSTOM_DATA_DESCRIPTIONS = "customRewDataDesc";
|
||||
public static final String REW_CUSTOM_DATA_TEMP = "customRewDataTemp";
|
||||
//Stages
|
||||
public static final String S_BREAK_IDS = "breakIds";
|
||||
public static final String S_BREAK_AMOUNTS = "breakAmounts";
|
||||
|
Loading…
Reference in New Issue
Block a user