!add weapon level condition to crafting station

(still needs review)
This commit is contained in:
Blackdigits 2020-02-15 03:39:53 +07:00
parent 7a08fa3616
commit e5440cf3e5
6 changed files with 317 additions and 11 deletions

14
build.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<project name="mmoitems" default="Build">
<condition property="serverPath" value="D:\Documents\Minecraft Server\Server">
<os family="windows" />
</condition>
<xmlproperty file="pom.xml" prefix="pom" keeproot="false" />
<target name="Build">
<jar jarfile="${serverPath}\plugins\${ant.project.name}.jar" basedir="./target/classes/" includes="**/*"/>
</target>
</project>

260
mmoitems.iml Normal file
View File

@ -0,0 +1,260 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib2" level="project" />
<orderEntry type="library" name="lib1" level="project" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="module-library">
<library name="Maven: net.Indyuce:mmocore:1.1.2">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/MMOCore.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module" module-name="mmolib" />
<orderEntry type="module-library">
<library name="Maven: com.google.code.gson:gson:2.8.5">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/GoogleGSON.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: com.mojang:authlib:1.5.21" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:17.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.0-beta9" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.0-beta9" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:2.0.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="module-library">
<library name="Maven: org.spigotmc:spigot-api:1.14.4">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/spigot.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.github.Eniripsa96:SkillAPI:master-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/SkillAPI.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: n3kas:ae.api:5.7.6">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/AE-API.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: org.black_ixx:BossShop:2.0.8">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/BossShopPro.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.bekvon.bukkit:Residence:4.8.7.2">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/Residence.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.Zrips:CMI:8.6.5.0">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/CMI.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.herocraftonline:heroes:1.9.3">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/Heroes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.gmail.nossr50:mcMMO:2.1.104">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/mcMMO.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: us.eunoians:McRPG:1.1.2">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/McRPG.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: me.baks:rpl:3.9.30">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/RPGPlayerLeveling.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: me.leothepro555:skills:12.3.5">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/Skills.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: me.robin:BattleLevels:6.9.1">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/BattleLevels.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.evill4mer:RealDualWield:1.1.12">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/RealDualWield.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.gmail.filoghost:HolographicDisplays:6.9.1">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/HolographicDisplays.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: io.lumine.xikage:MythicMobs:4.8.0">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/MythicMobs.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: de.tobiyas:RacesAndClasses:1.2.6">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/RacesAndClasses.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: ru.endlesscode:rpginventory:2.3.0">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/RPGInventory.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.sainttx.holograms:holograms:2.9.1">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/Holograms.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.sk89q.worldguard:worldguard-bukkit:7.0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/WorldGuard.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.sk89q.worldedit:worldedit-bukkit:7.0.0">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/WorldEdit.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: net.citizensnpcs:citizens:2.0.25-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/Citizens.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: org.inventivetalent:glowapi:1.4.8-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/GlowAPI.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: me.clip:placeholderapi:2.10.3">
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/PlaceholderAPI.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -6,6 +6,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.Indyuce.mmoitems.api.crafting.ingredient.MMOItemIngredient;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@ -60,12 +61,17 @@ public class IngredientInventory {
ingredients.put(key, new PlayerIngredient(item.getItem()));
}
public PlayerIngredient getIngredient(Ingredient ingredient) {
public PlayerIngredient getIngredient(Ingredient ingredient, boolean isUpgrading) {
String key = ingredient.getKey();
for (String invKey : ingredients.keySet())
if (invKey.equals(key))
for (String invKey : ingredients.keySet()) {
String ingredientKey = invKey;
if(isUpgrading) {
ingredientKey = invKey.replaceFirst("-\\d*_", "_");
}
if (ingredientKey.equals(key))
return ingredients.get(invKey);
}
return null;
}
@ -75,7 +81,7 @@ public class IngredientInventory {
* deprecated because used with upgrading recipes.
*/
public boolean hasIngredient(Ingredient ingredient) {
PlayerIngredient found = getIngredient(ingredient);
PlayerIngredient found = getIngredient(ingredient, true);
return found != null && found.getAmount() >= ingredient.getAmount();
}

View File

@ -11,7 +11,7 @@ public abstract class Ingredient {
private final String id;
private String key, name;
private ConditionalDisplay display;
private int amount;
private int amount, level;
public Ingredient(String id) {
this.id = id;
@ -49,6 +49,10 @@ public abstract class Ingredient {
this.name = name;
}
protected void setLevel(Integer level) {
this.level = level;
}
protected void setDisplay(ConditionalDisplay display) {
this.display = display;
}
@ -66,6 +70,9 @@ public abstract class Ingredient {
return name;
}
public Integer getLevel() {
return level;
}
/*
* apply specific placeholders to display the ingredient in the item lore.
*/
@ -81,7 +88,7 @@ public abstract class Ingredient {
public abstract ItemStack generateItemStack();
public IngredientInfo newIngredientInfo(IngredientInventory inv) {
return new IngredientInfo(this, inv.getIngredient(this));
return new IngredientInfo(this, inv.getIngredient(this, false));
}
public class IngredientInfo {

View File

@ -1,5 +1,8 @@
package net.Indyuce.mmoitems.api.crafting.ingredient;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.Indyuce.mmoitems.stat.Upgrade_Stat;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
@ -20,12 +23,13 @@ public class MMOItemIngredient extends Ingredient {
public MMOItemIngredient() {
super("mmoitem");
setDisplay(new ConditionalDisplay("&8" + AltChar.check + " &7#amount# #item#", "&c" + AltChar.cross + " &7#amount# #item#"));
setDisplay(new ConditionalDisplay("&8" + AltChar.check + " &7#amount# #level# #item#", "&c" + AltChar.cross + " &7#amount# #level# #item#"));
}
public MMOItemIngredient(ConfigMMOItem mmoitem) {
super("mmoitem");
type = mmoitem.getType();
id = mmoitem.getId();
@ -33,6 +37,10 @@ public class MMOItemIngredient extends Ingredient {
setKey(type.getId().toLowerCase() + "_" + id.toLowerCase());
}
public Type getType() {
return type;
}
@Override
public Ingredient load(String[] args) {
try {
@ -42,7 +50,10 @@ public class MMOItemIngredient extends Ingredient {
ingredient.setAmount(args.length > 2 ? Math.max(1, Integer.parseInt(args[2])) : 1);
ingredient.setName(args.length > 3 ? args[3].replace("_", " ") : findName());
ingredient.setKey(ingredient.type.getId().toLowerCase() + "_" + ingredient.id.toLowerCase());
ingredient.setLevel(args.length > 4 ? Math.max(0, Integer.parseInt(args[4])) : 0);
String levelKey = ingredient.getLevel() != 0 ? "-" + ingredient.getLevel() : "";
ingredient.setKey(ingredient.type.getId().toLowerCase() + levelKey + "_" + ingredient.id.toLowerCase());
ingredient.setDisplay(getDisplay());
return ingredient;
@ -53,7 +64,7 @@ public class MMOItemIngredient extends Ingredient {
@Override
public String formatDisplay(String string) {
return string.replace("#item#", getName()).replace("#amount#", "" + getAmount());
return string.replace("#item#", getName()).replace("#level#", getLevel() != 0 ? "lvl." + getLevel() : "").replace("#amount#", "" + getAmount());
}
@Override
@ -72,7 +83,15 @@ public class MMOItemIngredient extends Ingredient {
@Override
public String readKey(NBTItem item) {
return item.getString("MMOITEMS_ITEM_TYPE").toLowerCase() + "_" + item.getString("MMOITEMS_ITEM_ID").toLowerCase();
final String upgradeString = item.getString("MMOITEMS_UPGRADE");
int level = 0;
if(upgradeString != "") {
JsonObject upgradeStat = new JsonParser().parse(upgradeString).getAsJsonObject();
level = upgradeStat.get("Level").getAsInt();
}
final String levelKey = level != 0 ? "-" + level : "";
return item.getString("MMOITEMS_ITEM_TYPE").toLowerCase() + levelKey + "_" + item.getString("MMOITEMS_ITEM_ID").toLowerCase();
}
@Override

View File

@ -62,7 +62,7 @@ public class UpgradingRecipe extends Recipe {
}
UpgradingRecipeInfo recipe = (UpgradingRecipeInfo) uncastRecipe;
if (!(recipe.mmoitem = new MMOItem(MMOLib.plugin.getNMS().getNBTItem(inv.getIngredient(ingredient).getFirstItem()))).hasData(ItemStat.UPGRADE))
if (!(recipe.mmoitem = new MMOItem(MMOLib.plugin.getNMS().getNBTItem(inv.getIngredient(ingredient, false).getFirstItem()))).hasData(ItemStat.UPGRADE))
return false;
if (!(recipe.upgradeData = (UpgradeData) recipe.getMMOItem().getData(ItemStat.UPGRADE)).canLevelUp()) {