1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Added tipped_arrow to pay for crafted arrows (#772)

Closes #732
This commit is contained in:
kikelkik 2020-05-24 19:50:50 +02:00 committed by GitHub
parent 554eb6c941
commit 12ffc67eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 168 additions and 23 deletions

6
.gitignore vendored
View File

@ -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

View File

@ -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)

View File

@ -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);

View File

@ -0,0 +1,38 @@
/*
Jobs Plugin for Bukkit
Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
<p>
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.
<p>
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.
<p>
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -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();
}
}

View File

@ -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<JobInfo, ActionInfo> 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;
}
/**

View File

@ -0,0 +1,60 @@
/*
Jobs Plugin for Bukkit
Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
package com.gamingmesh.jobs.container;
/**
* <a href="https://minecraft.gamepedia.com/Potion#Java_Edition">Minecraft-WIKI reference</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");
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;
}
}

View File

@ -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;
}