1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-03-12 06:40:09 +01:00

Fixed when tipped arrow for crafting not works (#802)

This commit is contained in:
kikelkik 2020-05-25 19:45:12 +02:00 committed by GitHub
parent 12ffc67eed
commit 0c1d7893f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 124 additions and 92 deletions

View File

@ -1270,10 +1270,13 @@ public enum CMIMaterial {
} catch (Exception ex) {
}
}
try {
if (id.contains(":")) {
String metaTag = id.split(":")[1];
ItemManager.byName.get(id + ":" + metaTag);
} catch (Exception ex) {
CMIMaterial mat = ItemManager.byName.get(id + ":" + metaTag);
if (mat != null) {
return mat;
}
}
CMIMaterial mat = ItemManager.byName.get(id);

View File

@ -61,7 +61,7 @@ public class ItemManager {
if (one.isCanHavePotionType()) {
for (Potion p : Potion.values()) {
byName.put(cmiName + ":" + p.getName(), one);
byName.put(cmiName + ":" + p.getName().toLowerCase(), one);
}
}
else if (byName.containsKey(cmiName)) {

View File

@ -32,7 +32,6 @@ public class PotionItemActionInfo extends ItemActionInfo {
}
public String getNameWithPotion() {
return getName() + ":" + potionType.name();
return getName() + ":" + potionType.toString();
}
}

View File

@ -395,6 +395,9 @@ public class ConfigManager {
subType = ":" + myKey.split("-")[1];
meta = myKey.split("-")[1];
myKey = myKey.split("-")[0];
} else if (myKey.contains(":")) { // when we uses tipped arrow effect types
meta = myKey.split(":")[1];
myKey = myKey.split(":")[0];
}
CMIMaterial material = null;
@ -584,8 +587,15 @@ public class ConfigManager {
}
Jobs.getExplore().setExploreEnabled();
Jobs.getExplore().setPlayerAmount(amount);
} else if (actionType == ActionType.CRAFT && myKey.startsWith("!"))
} else if (actionType == ActionType.CRAFT) {
if (myKey.startsWith("!")) {
type = myKey.substring(1, myKey.length());
}
if (myKey.contains(":")) {
subType = myKey.split(":")[1];
}
}
if (type == null) {
Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + myKey + "!");
@ -1176,6 +1186,9 @@ public class ConfigManager {
subType = ":" + myKey.split("-")[1];
meta = myKey.split("-")[1];
myKey = myKey.split("-")[0];
} else if (myKey.contains(":")) { // when we uses tipped arrow effect types
meta = myKey.split(":")[1];
myKey = myKey.split(":")[0];
}
CMIMaterial material = CMIMaterial.NONE;
@ -1380,8 +1393,15 @@ public class ConfigManager {
Jobs.getExplore().setExploreEnabled();
Jobs.getExplore().setPlayerAmount(amount);
} else if (actionType == ActionType.CRAFT && myKey.startsWith("!"))
} else if (actionType == ActionType.CRAFT) {
if (myKey.startsWith("!")) {
type = myKey.substring(1, myKey.length());
}
if (myKey.contains(":")) {
subType = myKey.split(":")[1];
}
}
if (type == null) {
log.warning("Job " + jobKey + " has an invalid " + actionType.getName() + " type property: " + key + "!");

View File

@ -18,6 +18,7 @@ import com.gamingmesh.jobs.CMILib.ConfigReader;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.NameList;
import com.gamingmesh.jobs.container.Potion;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.stuff.Util;
@ -56,6 +57,10 @@ public class NameTranslatorManager {
NameList nameLs = ListOfNames.get(mat);
if (nameLs != null) {
if (meta != null && !meta.isEmpty() && mat.isCanHavePotionType() && Potion.getByName(meta) != null) {
return nameLs.getName() + ":" + meta;
}
return nameLs.getName();
}
@ -78,6 +83,7 @@ public class NameTranslatorManager {
if (nameLs != null && nameMeta != null) {
return nameLs + ":" + nameMeta;
}
return mat.getName();
}
}

View File

@ -225,16 +225,16 @@ public class Job {
}
public JobInfo getJobInfo(ActionInfo action, int level) {
BiPredicate<JobInfo, ActionInfo> condition = (jobInfo, actionInfo) -> {
if (actionInfo instanceof PotionItemActionInfo) {
Jobs.consoleMsg(jobInfo.getName() + ":" + jobInfo.getMeta());
return jobInfo.getName().equalsIgnoreCase(((PotionItemActionInfo) action).getNameWithPotion()) ||
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(((PotionItemActionInfo) action).getNameWithPotion());
} else {
}
return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) ||
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) ||
jobInfo.getName().equalsIgnoreCase(action.getName());
}
};
for (JobInfo info : getJobInfo(action.getType())) {
@ -242,9 +242,11 @@ public class Job {
if (!info.isInLevelRange(level)) {
break;
}
return info;
}
}
return null;
}

View File

@ -19,25 +19,28 @@
package com.gamingmesh.jobs.container;
/**
* <a href="https://minecraft.gamepedia.com/Potion#Java_Edition">Minecraft-WIKI reference</a>
* <a href="https://papermc.io/javadocs/paper/1.13/org/bukkit/potion/PotionType.html">API reference for names</a>
*/
public enum Potion {
NIGHT_VISION("Night Vision"),
INVISIBILITY("Invisibility"),
LEAPING("Leaping"),
FIRE_RESISTANCE("Fire Resistance"),
SWIFTNESS("Swiftness"),
SLOWNESS("Slowness"),
WATER_BREATHING("Water Breathing"),
HEALING("Instant Health"),
HARMING("Harming"),
POISON("Poison"),
REGENERATION("Regeneration"),
STRENGTH("Strength"),
WEAKNESS("Weakness"),
LUCK("Luck"),
TURTLE_MASTER("The Turtle Master"),
SLOW_FALLING("Slow Falling");
AWKWARD("AWKWARD"),
FIRE_RESISTANCE("FIRE_RESISTANCE"),
INSTANT_DAMAGE("INSTANT_DAMAGE"),
INSTANT_HEAL("INSTANT_HEAL"),
INVISIBILITY("INVISIBILITY"),
JUMP("JUMP"),
LUCK("LUCK"),
MUNDANE("MUNDANE"),
NIGHT_VISION("NIGHT_VISION"),
POISON("POISON"),
REGEN("REGEN"),
SLOW_FALLING("SLOW_FALLING"),
SLOWNESS("SLOWNESS"),
SPEED("SPEED"),
STRENGTH("STRENGTH"),
THICK("THICK"),
TURTLE_MASTER("TURTLE_MASTER"),
WATER_BREATHING("WATER_BREATHING"),
WEAKNESS("WEAKNESS");
private final String name;
@ -52,9 +55,10 @@ public enum Potion {
public static Potion getByName(String name) {
name = name.replace("_", "");
for (Potion one : Potion.values()) {
if (one.name.equalsIgnoreCase(name))
if (one.name.equalsIgnoreCase(name)) {
return one;
}
}
return null;
}
}

View File

@ -78,8 +78,8 @@ import org.bukkit.inventory.EnchantingInventory;
import org.bukkit.inventory.GrindstoneInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.StonecutterInventory;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.projectiles.ProjectileSource;
@ -593,11 +593,6 @@ public class JobsPaymentListener implements Listener {
if (!payIfCreative(player))
return;
ItemStack currentItem = event.getCurrentItem();
if (currentItem == null) {
return;
}
// Checking if item is been repaired, not crafted. Combining 2 items
ItemStack[] sourceItems = event.getInventory().getContents();
@ -688,23 +683,26 @@ public class JobsPaymentListener implements Listener {
}
}
// If we need to pay only by each craft action we will skip calculation how much was crafted
if (!Jobs.getGCManager().PayForEachCraft) {
if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) {
Jobs.action(jPlayer, new ItemNameActionInfo(ChatColor.stripColor(resultStack.getItemMeta()
.getDisplayName()), ActionType.CRAFT));
} else {
if (currentItem.hasItemMeta()) {
if (currentItem.getItemMeta() instanceof PotionMeta) {
ItemStack currentItem = event.getCurrentItem();
if (currentItem != null) {
if (currentItem.hasItemMeta() && currentItem.getItemMeta() instanceof PotionMeta) {
Jobs.consoleMsg(currentItem + " " + currentItem.hasItemMeta() + " " + currentItem.getItemMeta());
PotionMeta potion = (PotionMeta) currentItem.getItemMeta();
Jobs.action(jPlayer, new PotionItemActionInfo(currentItem, ActionType.CRAFT, potion.getBasePotionData().getType()));
} else {
Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.CRAFT));
}
} else {
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT));
return;
}
// If we need to pay only by each craft action we will skip calculation how much was crafted
if (!Jobs.getGCManager().PayForEachCraft) {
if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) {
Jobs.action(jPlayer, new ItemNameActionInfo(ChatColor.stripColor(resultStack.getItemMeta()
.getDisplayName()), ActionType.CRAFT));
}
return;
}