1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-16 21:21:20 +01:00

Update quest objective matching to better match job task matching.

Allows the default enchanter quest to actually detect ARROW_DAMAGE enchantment.
This commit is contained in:
BeepoWuff 2021-09-21 02:08:15 +10:00
parent a224545d79
commit e9c1937953
No known key found for this signature in database
GPG Key ID: 4C176134BCA5058C
3 changed files with 54 additions and 26 deletions

View File

@ -29,8 +29,8 @@ import java.util.Map;
import java.util.Random;
import java.util.function.BiPredicate;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.actions.EnchantActionInfo;
import com.gamingmesh.jobs.stuff.Util;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
@ -310,16 +310,7 @@ public class Job {
}
if (actionInfo instanceof EnchantActionInfo) {
EnchantActionInfo enchantActionInfo = (EnchantActionInfo)actionInfo;
String enchantName = CMIEnchantment.get(actionInfo.getName()).toString();
return (
// Enchantment without level e.g. silk_touch
jobInfo.getName().equalsIgnoreCase(enchantName) ||
// Enchantment with level e.g. fire_aspect:1
jobInfo.getName().equalsIgnoreCase(enchantName + ":" + enchantActionInfo.getLevel())
);
return Util.enchantMatchesActionInfo(jobInfo.getName(), (EnchantActionInfo) actionInfo);
}
return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) ||

View File

@ -4,6 +4,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import com.gamingmesh.jobs.actions.EnchantActionInfo;
import com.gamingmesh.jobs.stuff.Util;
import org.bukkit.Bukkit;
import org.bukkit.event.server.ServerCommandEvent;
@ -97,7 +99,9 @@ public class QuestProgression {
return;
Map<String, QuestObjective> byAction = quest.getObjectives().get(action.getType());
if (byAction != null && !byAction.containsKey(action.getNameWithSub()) && !byAction.containsKey(action.getName()))
QuestObjective objective = objectiveForAction(action);
if (byAction != null && objective == null)
return;
org.bukkit.entity.Player player = jPlayer.getPlayer();
@ -118,20 +122,12 @@ public class QuestProgression {
}
}
if (!isCompleted()) {
QuestObjective objective = null;
if (byAction != null) {
objective = byAction.get(action.getName());
if (objective == null)
objective = byAction.get(action.getNameWithSub());
}
if (objective != null) {
Integer old = done.getOrDefault(objective, 0);
done.put(objective, old < objective.getAmount() ? old + 1 : objective.getAmount());
}
if (
!isCompleted() &&
objective != null
) {
Integer old = done.getOrDefault(objective, 0);
done.put(objective, old < objective.getAmount() ? old + 1 : objective.getAmount());
}
jPlayer.setSaved(false);
@ -159,4 +155,32 @@ public class QuestProgression {
public void setGivenReward(boolean givenReward) {
this.givenReward = givenReward;
}
private boolean objectiveKeyMatches(String objectiveKey, ActionInfo actionInfo) {
if (actionInfo instanceof EnchantActionInfo) {
return Util.enchantMatchesActionInfo(objectiveKey, (EnchantActionInfo) actionInfo);
}
return (
objectiveKey.equalsIgnoreCase(actionInfo.getNameWithSub()) ||
objectiveKey.equalsIgnoreCase(actionInfo.getName())
);
}
private QuestObjective objectiveForAction(ActionInfo actionInfo) {
Map<String, QuestObjective> byAction = quest.getObjectives().get(actionInfo.getType());
if (byAction == null) {
return null;
}
for (Map.Entry<String, QuestObjective> objectiveEntry : byAction.entrySet()) {
String objectiveKey = objectiveEntry.getKey();
if (objectiveKeyMatches(objectiveKey, actionInfo)) {
return objectiveEntry.getValue();
}
}
return null;
}
}

View File

@ -14,6 +14,8 @@ import java.util.UUID;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.actions.EnchantActionInfo;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Location;
@ -405,4 +407,15 @@ public final class Util {
return difference;
}
public static boolean enchantMatchesActionInfo(String enchant, EnchantActionInfo actionInfo) {
String enchantName = CMIEnchantment.get(actionInfo.getName()).toString();
return (
// Enchantment without level e.g. silk_touch
enchant.equalsIgnoreCase(enchantName) ||
// Enchantment with level e.g. fire_aspect:1
enchant.equalsIgnoreCase(enchantName + ":" + actionInfo.getLevel())
);
}
}