diff --git a/.gitignore b/.gitignore index eca4d8ce..27b01cab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /bin/ /target/ -/pom.xml -src/main/resources/locale/messages_en.yml +/.idea/ +/pom.xml +/jobs.iml +src/main/resources/locale/messages_en.yml diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java index 256b8417..09fee8da 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java @@ -1270,6 +1270,11 @@ public enum CMIMaterial { } catch (Exception ex) { } } + try { + String metaTag = id.split(":")[1]; + ItemManager.byName.get(id + ":" + metaTag); + } catch (Exception ex) { + } CMIMaterial mat = ItemManager.byName.get(id); if (mat != null) { @@ -1569,6 +1574,10 @@ public enum CMIMaterial { return false; } + public boolean isCanHavePotionType() { + return isPotion() || this == CMIMaterial.TIPPED_ARROW; + } + public static boolean isBoat(Material mat) { CMIMaterial m = CMIMaterial.get(mat); if (m == null) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java b/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java index ac18606f..8fec10f8 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java @@ -16,6 +16,7 @@ import org.bukkit.potion.PotionType; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.VersionChecker.Version; +import com.gamingmesh.jobs.container.Potion; import com.gamingmesh.jobs.stuff.Util; public class ItemManager { @@ -58,7 +59,12 @@ public class ItemManager { mojangName = mojangName == null ? mat.toString().replace("_", "").replace(" ", "").toLowerCase() : mojangName.replace("_", "").replace(" ", "").toLowerCase(); - if (byName.containsKey(cmiName)) { + if (one.isCanHavePotionType()) { + for (Potion p : Potion.values()) { + byName.put(cmiName + ":" + p.getName(), one); + } + } + else if (byName.containsKey(cmiName)) { byName.put(cmiName + ":" + data, one); } else byName.put(cmiName, one); diff --git a/src/main/java/com/gamingmesh/jobs/actions/PotionItemActionInfo.java b/src/main/java/com/gamingmesh/jobs/actions/PotionItemActionInfo.java new file mode 100644 index 00000000..f0b7ffd0 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/actions/PotionItemActionInfo.java @@ -0,0 +1,38 @@ +/* + Jobs Plugin for Bukkit + Copyright (C) 2011 Zak Ford +

+ This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. +

+ This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +

+ You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.gamingmesh.jobs.actions; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionType; + +import com.gamingmesh.jobs.container.ActionType; + +public class PotionItemActionInfo extends ItemActionInfo { + private final PotionType potionType; + + public PotionItemActionInfo(ItemStack items, ActionType type, PotionType potionType) { + super(items, type); + this.potionType = potionType; + } + + public String getNameWithPotion() { + return getName() + ":" + potionType.name(); + } + +} diff --git a/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java b/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java index 4d60166e..b2b4e034 100644 --- a/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java @@ -72,7 +72,13 @@ public class NameTranslatorManager { mat = CMIMaterial.get(materialName + ":" + meta); nameLs = ListOfNames.get(mat); if (nameLs == null) { - return mat.getName(); + mat = CMIMaterial.get(materialName.replace(" ", "")); + nameLs = ListOfNames.get(mat); + NameList nameMeta = ListOfNames.get(CMIMaterial.get(meta.replace(" ", ""))); + if (nameLs != null && nameMeta != null) { + return nameLs + ":" + nameMeta; + } + return mat.getName(); } } diff --git a/src/main/java/com/gamingmesh/jobs/container/Job.java b/src/main/java/com/gamingmesh/jobs/container/Job.java index 68587f57..19897c9b 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Job.java +++ b/src/main/java/com/gamingmesh/jobs/container/Job.java @@ -19,6 +19,7 @@ package com.gamingmesh.jobs.container; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.actions.PotionItemActionInfo; import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.stuff.ChatColor; @@ -29,6 +30,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.*; +import java.util.function.BiPredicate; public class Job { @@ -223,22 +225,27 @@ public class Job { } public JobInfo getJobInfo(ActionInfo action, int level) { - for (JobInfo info : getJobInfo(action.getType())) { - if (info.getName().equalsIgnoreCase(action.getNameWithSub()) || (info.getName() + ":" + info.getMeta()).equalsIgnoreCase(action.getNameWithSub())) { - if (!info.isInLevelRange(level)) - break; - return info; - } - } - for (JobInfo info : getJobInfo(action.getType())) { - if (info.getName().equalsIgnoreCase(action.getName())) { - if (!info.isInLevelRange(level)) - break; - return info; - } - } - return null; + BiPredicate condition = (jobInfo, actionInfo) -> { + if (actionInfo instanceof PotionItemActionInfo) { + 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())) { + if (condition.test(info, action)) { + if (!info.isInLevelRange(level)) { + break; + } + return info; + } + } + return null; } /** diff --git a/src/main/java/com/gamingmesh/jobs/container/Potion.java b/src/main/java/com/gamingmesh/jobs/container/Potion.java new file mode 100644 index 00000000..ee3bec71 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/container/Potion.java @@ -0,0 +1,60 @@ +/* + Jobs Plugin for Bukkit + Copyright (C) 2011 Zak Ford + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.gamingmesh.jobs.container; + +/** + * Minecraft-WIKI reference + */ +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"); + + private final String name; + + Potion(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static Potion getByName(String name) { + name = name.replace("_", ""); + for (Potion one : Potion.values()) { + if (one.name.equalsIgnoreCase(name)) + return one; + } + return null; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 9bc777f6..d324026d 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -78,6 +78,7 @@ 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.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; @@ -592,6 +593,11 @@ 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(); @@ -684,10 +690,21 @@ 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 - Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT)); + 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) { + 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; }