mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-02 14:29:07 +01:00
Merge pull request #1279 from BeepoWuff/enchantment-fixes
Enchantment Fixes
This commit is contained in:
commit
3f9206b389
@ -40,4 +40,8 @@ public class EnchantActionInfo extends BaseActionInfo {
|
|||||||
public String getNameWithSub() {
|
public String getNameWithSub() {
|
||||||
return name + ":" + level;
|
return name + ":" + level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ import java.util.Map;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
|
import com.gamingmesh.jobs.actions.EnchantActionInfo;
|
||||||
|
import com.gamingmesh.jobs.stuff.Util;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -307,6 +309,10 @@ public class Job {
|
|||||||
return jobInfo.getName().equalsIgnoreCase(subName) || (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(subName);
|
return jobInfo.getName().equalsIgnoreCase(subName) || (jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(subName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actionInfo instanceof EnchantActionInfo) {
|
||||||
|
return Util.enchantMatchesActionInfo(jobInfo.getName(), (EnchantActionInfo) actionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) ||
|
return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) ||
|
||||||
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) ||
|
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) ||
|
||||||
jobInfo.getName().equalsIgnoreCase(action.getName());
|
jobInfo.getName().equalsIgnoreCase(action.getName());
|
||||||
|
@ -4,6 +4,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.gamingmesh.jobs.actions.EnchantActionInfo;
|
||||||
|
import com.gamingmesh.jobs.stuff.Util;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
|
||||||
@ -97,7 +99,9 @@ public class QuestProgression {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Map<String, QuestObjective> byAction = quest.getObjectives().get(action.getType());
|
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;
|
return;
|
||||||
|
|
||||||
org.bukkit.entity.Player player = jPlayer.getPlayer();
|
org.bukkit.entity.Player player = jPlayer.getPlayer();
|
||||||
@ -118,20 +122,12 @@ public class QuestProgression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isCompleted()) {
|
if (
|
||||||
QuestObjective objective = null;
|
!isCompleted() &&
|
||||||
|
objective != null
|
||||||
if (byAction != null) {
|
) {
|
||||||
objective = byAction.get(action.getName());
|
Integer old = done.getOrDefault(objective, 0);
|
||||||
|
done.put(objective, old < objective.getAmount() ? old + 1 : objective.getAmount());
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jPlayer.setSaved(false);
|
jPlayer.setSaved(false);
|
||||||
@ -159,4 +155,32 @@ public class QuestProgression {
|
|||||||
public void setGivenReward(boolean givenReward) {
|
public void setGivenReward(boolean givenReward) {
|
||||||
this.givenReward = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -844,6 +844,19 @@ public final class JobsPaymentListener implements Listener {
|
|||||||
return a.getAmount() + b.getAmount() <= a.getType().getMaxStackSize();
|
return a.getAmount() + b.getAmount() <= a.getType().getMaxStackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getEnchantName(Enchantment enchant) {
|
||||||
|
try {
|
||||||
|
return enchant.getKey().getKey().toLowerCase().replace("_", "").replace("minecraft:", "");
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
CMIEnchantment cmiEnchant = CMIEnchantment.get(enchant);
|
||||||
|
if (cmiEnchant != null)
|
||||||
|
return cmiEnchant.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onInventoryRepair(InventoryClickEvent event) {
|
public void onInventoryRepair(InventoryClickEvent event) {
|
||||||
// If event is nothing or place, do nothing
|
// If event is nothing or place, do nothing
|
||||||
@ -955,14 +968,16 @@ public final class JobsPaymentListener implements Listener {
|
|||||||
ItemStack secondSlotItem = inv.getItem(1);
|
ItemStack secondSlotItem = inv.getItem(1);
|
||||||
|
|
||||||
if (Jobs.getGCManager().PayForEnchantingOnAnvil && secondSlotItem != null && secondSlotItem.getType() == Material.ENCHANTED_BOOK) {
|
if (Jobs.getGCManager().PayForEnchantingOnAnvil && secondSlotItem != null && secondSlotItem.getType() == Material.ENCHANTED_BOOK) {
|
||||||
for (Map.Entry<Enchantment, Integer> oneEnchant : resultStack.getEnchantments().entrySet()) {
|
Map<Enchantment, Integer> newEnchantments = Util.mapUnique(resultStack.getEnchantments(), firstSlot.getEnchantments());
|
||||||
|
|
||||||
|
for (Map.Entry<Enchantment, Integer> oneEnchant : newEnchantments.entrySet()) {
|
||||||
Enchantment enchant = oneEnchant.getKey();
|
Enchantment enchant = oneEnchant.getKey();
|
||||||
if (enchant == null)
|
if (enchant == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CMIEnchantment e = CMIEnchantment.get(enchant);
|
String enchantName = getEnchantName(enchant);
|
||||||
if (e != null)
|
if (enchantName != null)
|
||||||
Jobs.action(jPlayer, new EnchantActionInfo(e.toString(), oneEnchant.getValue(), ActionType.ENCHANT));
|
Jobs.action(jPlayer, new EnchantActionInfo(enchantName, oneEnchant.getValue(), ActionType.ENCHANT));
|
||||||
}
|
}
|
||||||
} else if (secondSlotItem == null || secondSlotItem.getType() != Material.ENCHANTED_BOOK) // Enchanted books does not have durability
|
} else if (secondSlotItem == null || secondSlotItem.getType() != Material.ENCHANTED_BOOK) // Enchanted books does not have durability
|
||||||
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
|
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
|
||||||
@ -1017,16 +1032,7 @@ public final class JobsPaymentListener implements Listener {
|
|||||||
if (enchant == null)
|
if (enchant == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String enchantName = null;
|
String enchantName = getEnchantName(enchant);
|
||||||
|
|
||||||
try {
|
|
||||||
enchantName = enchant.getKey().getKey().toLowerCase().replace("_", "").replace("minecraft:", "");
|
|
||||||
} catch (Throwable e) {
|
|
||||||
CMIEnchantment ench = CMIEnchantment.get(enchant);
|
|
||||||
if (ench != null)
|
|
||||||
enchantName = ench.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enchantName != null)
|
if (enchantName != null)
|
||||||
Jobs.action(jPlayer, new EnchantActionInfo(enchantName, oneEnchant.getValue(), ActionType.ENCHANT));
|
Jobs.action(jPlayer, new EnchantActionInfo(enchantName, oneEnchant.getValue(), ActionType.ENCHANT));
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ import java.util.UUID;
|
|||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
|
||||||
|
import com.gamingmesh.jobs.actions.EnchantActionInfo;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -395,4 +397,25 @@ public final class Util {
|
|||||||
|
|
||||||
return listOfCommands;
|
return listOfCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <K, V> Map<K, V> mapUnique(Map<K, V> left, Map<K, V> right) {
|
||||||
|
Map<K, V> difference = new HashMap<>();
|
||||||
|
|
||||||
|
difference.putAll(left);
|
||||||
|
difference.putAll(right);
|
||||||
|
difference.entrySet().removeAll(right.entrySet());
|
||||||
|
|
||||||
|
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())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user