mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Upgrade Ranges in crafting stations now supported. Also works in the workbench (when using latest MythicLib).
```yml crafting: shaped: '1': - m MATERIAL WEAPON_POWDER 1|m MATERIAL WEAPON_POWDER 1|m MATERIAL WEAPON_POWDER 1 - m MATERIAL WEAPON_POWDER 1|m SWORD PLATINUM_SWORD{level=2..5} 1|m MATERIAL WEAPON_POWDER 1 - m MATERIAL WEAPON_POWDER 1|m MATERIAL WEAPON_POWDER 1|m MATERIAL WEAPON_POWDER 1 ```
This commit is contained in:
parent
96e09c07ed
commit
0a41192838
2
pom.xml
2
pom.xml
@ -100,7 +100,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.lumine</groupId>
|
<groupId>io.lumine</groupId>
|
||||||
<artifactId>MythicLib</artifactId>
|
<artifactId>MythicLib</artifactId>
|
||||||
<version>1.0.18</version>
|
<version>1.0.19</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -287,8 +288,21 @@ public class MMOItems extends LuminePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) {
|
if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) {
|
||||||
new MMOItemsRewardTypes().register();
|
|
||||||
getLogger().log(Level.INFO, "Hooked onto BossShopPro");
|
getLogger().log(Level.INFO, "Hooked onto BossShopPro");
|
||||||
|
(new BukkitRunnable() {
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
//noinspection ProhibitedExceptionCaught
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Apparently might generate a null pointer exception when DungeonsXL is present.
|
||||||
|
new MMOItemsRewardTypes().register();
|
||||||
|
} catch (NullPointerException ignored) { getLogger().log(Level.INFO, "Could not Hook onto BossShopPro"); }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}).runTaskLater(this, 10L);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// compatibility with /reload
|
// compatibility with /reload
|
||||||
|
@ -2,6 +2,8 @@ package net.Indyuce.mmoitems.api.crafting;
|
|||||||
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
|
import io.lumine.mythic.lib.api.util.ui.QuickNumberRange;
|
||||||
|
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient;
|
import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient;
|
||||||
import net.Indyuce.mmoitems.manager.CraftingManager.IngredientType;
|
import net.Indyuce.mmoitems.manager.CraftingManager.IngredientType;
|
||||||
@ -9,6 +11,8 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -22,9 +26,7 @@ public class IngredientInventory {
|
|||||||
*/
|
*/
|
||||||
private final Map<String, PlayerIngredient> ingredients = new HashMap<>();
|
private final Map<String, PlayerIngredient> ingredients = new HashMap<>();
|
||||||
|
|
||||||
public IngredientInventory(Player player) {
|
public IngredientInventory(Player player) { this(player.getInventory()); }
|
||||||
this(player.getInventory());
|
|
||||||
}
|
|
||||||
|
|
||||||
public IngredientInventory(Inventory inv) {
|
public IngredientInventory(Inventory inv) {
|
||||||
loop: for (ItemStack item : inv.getContents())
|
loop: for (ItemStack item : inv.getContents())
|
||||||
@ -57,13 +59,55 @@ public class IngredientInventory {
|
|||||||
ingredients.put(key, new PlayerIngredient(item.getItem()));
|
ingredients.put(key, new PlayerIngredient(item.getItem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerIngredient getIngredient(Ingredient ingredient, IngredientLookupMode lookupMode) {
|
@Nullable
|
||||||
|
public PlayerIngredient getIngredient(@NotNull Ingredient ingredient, @NotNull IngredientLookupMode lookupMode) {
|
||||||
String key = ingredient.getKey();
|
String key = ingredient.getKey();
|
||||||
|
|
||||||
|
// Find level
|
||||||
|
QuickNumberRange lvl = null;
|
||||||
|
int dsh = key.indexOf('-');
|
||||||
|
if (dsh > 0) {
|
||||||
|
|
||||||
|
// Get lvl
|
||||||
|
String itemCrop = key.substring(dsh + 1);
|
||||||
|
String itemLevel = itemCrop.substring(0, itemCrop.indexOf('_'));
|
||||||
|
lvl = QuickNumberRange.getFromString(itemLevel);
|
||||||
|
key = key.substring(0, dsh) + key.substring(dsh + 1 + itemLevel.length()); }
|
||||||
|
|
||||||
|
// Remove lvl
|
||||||
|
//ING//MMOItems.log("\u00a7a>\u00a78>\u00a77 Reading ingredient\u00a7a " + key + "\u00a77 (of level \u00a7a" + lvl + "\u00a77)");
|
||||||
|
|
||||||
for (String invKey : ingredients.keySet()) {
|
for (String invKey : ingredients.keySet()) {
|
||||||
String ingredientKey = lookupMode == IngredientLookupMode.IGNORE_ITEM_LEVEL ? invKey.replaceFirst("-\\d*_", "_") : invKey;
|
|
||||||
if (ingredientKey.equals(key))
|
int dash = invKey.indexOf('-');
|
||||||
return ingredients.get(invKey);
|
Integer itemLvl = null;
|
||||||
|
String ingredientKey = invKey;
|
||||||
|
if (dash > 0) {
|
||||||
|
|
||||||
|
// Get lvl
|
||||||
|
String itemCrop = invKey.substring(dash + 1);
|
||||||
|
String itemLevel = itemCrop.substring(0, itemCrop.indexOf('_'));
|
||||||
|
itemLvl = SilentNumbers.IntegerParse(itemLevel);
|
||||||
|
ingredientKey = invKey.substring(0, dash) + invKey.substring(dash + 1 + itemLevel.length()); }
|
||||||
|
|
||||||
|
|
||||||
|
// Compare removing level
|
||||||
|
//ING//MMOItems.log(" \u00a7a>\u00a77 Comparing to \u00a7b" + invKey + "\u00a77 (\u00a73" + ingredientKey + "\u00a77)");
|
||||||
|
|
||||||
|
if (ingredientKey.equals(key)) {
|
||||||
|
|
||||||
|
// Get level
|
||||||
|
boolean levelMet = true;
|
||||||
|
if (lookupMode != IngredientLookupMode.IGNORE_ITEM_LEVEL && lvl != null) {
|
||||||
|
|
||||||
|
// Parse
|
||||||
|
if (itemLvl == null) { itemLvl = 0; }
|
||||||
|
levelMet = lvl.inRange(itemLvl);
|
||||||
|
//ING//MMOItems.log(" \u00a7a>\u00a77 Was level \u00a7e" + invKey + "\u00a77 (\u00a76" + levelMet + "\u00a77)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (levelMet) { return ingredients.get(invKey); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -5,14 +5,18 @@ import io.lumine.mythic.lib.api.crafting.uimanager.UIFilterManager;
|
|||||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||||
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
|
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
|
||||||
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
|
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
|
||||||
|
import io.lumine.mythic.lib.api.util.ui.QuickNumberRange;
|
||||||
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
||||||
import io.lumine.mythic.utils.items.ItemFactory;
|
import io.lumine.mythic.utils.items.ItemFactory;
|
||||||
|
import net.Indyuce.mmoitems.ItemStats;
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.api.Type;
|
import net.Indyuce.mmoitems.api.Type;
|
||||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
||||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||||
|
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
|
||||||
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
||||||
import net.Indyuce.mmoitems.api.item.util.DynamicLore;
|
import net.Indyuce.mmoitems.api.item.util.DynamicLore;
|
||||||
|
import net.Indyuce.mmoitems.stat.data.UpgradeData;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -58,6 +62,15 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strip data
|
||||||
|
@NotNull String dataments = "";
|
||||||
|
if (data.contains("{")) {
|
||||||
|
|
||||||
|
// Just clip them out for now yea
|
||||||
|
dataments = data.substring(data.indexOf('{') + 1);
|
||||||
|
data = data.substring(0, data.indexOf('{'));
|
||||||
|
if (dataments.endsWith("}")) { dataments = dataments.substring(0, dataments.length()-1); } }
|
||||||
|
|
||||||
// All right get its Type and ID
|
// All right get its Type and ID
|
||||||
if (!mmo.getType().getId().equals(argument) || !mmo.getId().equals(data)) {
|
if (!mmo.getType().getId().equals(argument) || !mmo.getId().equals(data)) {
|
||||||
|
|
||||||
@ -70,6 +83,32 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find upgrade?
|
||||||
|
if (!dataments.isEmpty()) {
|
||||||
|
VolatileMMOItem vmmo = new VolatileMMOItem(asNBT);
|
||||||
|
|
||||||
|
// Get
|
||||||
|
QuickNumberRange upgradeReq = SilentNumbers.rangeFromBracketsTab(dataments, "level");
|
||||||
|
if (upgradeReq != null) {
|
||||||
|
|
||||||
|
// Upgrade data?
|
||||||
|
int identifiedLvl = 0;
|
||||||
|
if (vmmo.hasData(ItemStats.UPGRADE)) { identifiedLvl = vmmo.getUpgradeLevel(); }
|
||||||
|
|
||||||
|
// Not matched?
|
||||||
|
if (!upgradeReq.inRange(identifiedLvl)) {
|
||||||
|
|
||||||
|
// Notify
|
||||||
|
FriendlyFeedbackProvider.log(ffp, FriendlyFeedbackCategory.FAILURE,
|
||||||
|
"MMOItem $r{0} {1}$b is of level $u{2}$b though $r{3}$b was expected. $fNo Match. ",
|
||||||
|
mmo.getType().getId(), mmo.getId(), String.valueOf(identifiedLvl), upgradeReq.toString());
|
||||||
|
|
||||||
|
// Fail
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Notify
|
// Notify
|
||||||
FriendlyFeedbackProvider.log(ffp, FriendlyFeedbackCategory.SUCCESS,
|
FriendlyFeedbackProvider.log(ffp, FriendlyFeedbackCategory.SUCCESS,
|
||||||
"Detected $r{0} {1} $sSuccessfully. ", mmo.getType().getId(), mmo.getId());
|
"Detected $r{0} {1} $sSuccessfully. ", mmo.getType().getId(), mmo.getId());
|
||||||
@ -96,6 +135,12 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse data
|
||||||
|
if (data.contains("{") && data.contains("}")) {
|
||||||
|
|
||||||
|
// Just clip them out for now yea
|
||||||
|
data = data.substring(0, data.indexOf('{')); }
|
||||||
|
|
||||||
// Can find item?
|
// Can find item?
|
||||||
if (MMOItems.plugin.getMMOItem(t, data) == null) {
|
if (MMOItems.plugin.getMMOItem(t, data) == null) {
|
||||||
|
|
||||||
@ -107,7 +152,6 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Error
|
// Error
|
||||||
FriendlyFeedbackProvider.log(ffp, FriendlyFeedbackCategory.SUCCESS,
|
FriendlyFeedbackProvider.log(ffp, FriendlyFeedbackCategory.SUCCESS,
|
||||||
"Valid MMOItem $r{0} {1}$b. $snice. ", argument, data);
|
"Valid MMOItem $r{0} {1}$b. $snice. ", argument, data);
|
||||||
@ -131,9 +175,60 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
|
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
|
|
||||||
|
// Strip data
|
||||||
|
@NotNull String dataments = "", datamentsTab = "";
|
||||||
|
if (data.contains("{")) {
|
||||||
|
|
||||||
|
// Just clip them out for now yea
|
||||||
|
dataments = data.substring(data.indexOf('{') + 1);
|
||||||
|
data = data.substring(0, data.indexOf('{'));
|
||||||
|
|
||||||
|
int datashort = 0;
|
||||||
|
if (dataments.contains(",")) { datashort = dataments.lastIndexOf(',') + 1; }
|
||||||
|
|
||||||
|
datamentsTab = dataments.substring(datashort);
|
||||||
|
dataments = dataments.substring(0, datashort);
|
||||||
|
}
|
||||||
|
|
||||||
// Just filter among template names of this type
|
// Just filter among template names of this type
|
||||||
return SilentNumbers.smartFilter(MMOItems.plugin.getTemplates().getTemplateNames(t), data, true);
|
ArrayList<String> suggestions = SilentNumbers.smartFilter(MMOItems.plugin.getTemplates().getTemplateNames(t), data, true);
|
||||||
|
ArrayList<String> trueSuggestions = suggestions;
|
||||||
|
|
||||||
|
// So, what things may be put in data?
|
||||||
|
if (!datamentsTab.isEmpty()) {
|
||||||
|
ArrayList<String> datamentsSug = new ArrayList<>();
|
||||||
|
|
||||||
|
// All right, so right now
|
||||||
|
if (datamentsTab.contains("=")) {
|
||||||
|
|
||||||
|
// All right grab
|
||||||
|
String datamentsUsed = datamentsTab.substring(0, datamentsTab.indexOf('='));
|
||||||
|
switch (datamentsUsed.toLowerCase()) {
|
||||||
|
case "level":
|
||||||
|
SilentNumbers.addAll(datamentsSug, "level=1..", "level=2..4", "level=..6");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
datamentsSug.add(datamentsTab);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No equals sign, suggest dataments
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Suggest that
|
||||||
|
datamentsSug = SilentNumbers.smartFilter(getValidDataments(), datamentsTab, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile
|
||||||
|
for (String sug : suggestions) {
|
||||||
|
for (String comp : datamentsSug) {
|
||||||
|
// All the suggestions that could complete this..
|
||||||
|
trueSuggestions.add(sug + "{" + dataments + comp); } }
|
||||||
|
}
|
||||||
|
|
||||||
|
// That's it
|
||||||
|
return trueSuggestions;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Typo in the Type
|
// Typo in the Type
|
||||||
@ -141,6 +236,9 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayList<String> validDataments;
|
||||||
|
@NotNull public ArrayList<String> getValidDataments() { if (validDataments != null) { return validDataments; } validDataments = SilentNumbers.toArrayList("level"); return validDataments; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fullyDefinesItem() { return true; }
|
public boolean fullyDefinesItem() { return true; }
|
||||||
|
|
||||||
@ -158,9 +256,39 @@ public class MMOItemUIFilter implements UIFilter {
|
|||||||
public ItemStack getDisplayStack(@NotNull String argument, @NotNull String data, @Nullable FriendlyFeedbackProvider ffp) {
|
public ItemStack getDisplayStack(@NotNull String argument, @NotNull String data, @Nullable FriendlyFeedbackProvider ffp) {
|
||||||
if (!isValid(argument, data, ffp)) { return ItemFactory.of(Material.STRUCTURE_VOID).name("\u00a7cInvalid MMOItem \u00a7e" + argument + " " + data).build(); }
|
if (!isValid(argument, data, ffp)) { return ItemFactory.of(Material.STRUCTURE_VOID).name("\u00a7cInvalid MMOItem \u00a7e" + argument + " " + data).build(); }
|
||||||
argument = argument.replace(" ", "_").replace("-", "_").toUpperCase();
|
argument = argument.replace(" ", "_").replace("-", "_").toUpperCase();
|
||||||
|
|
||||||
|
// Strip data
|
||||||
|
@NotNull String dataments = "";
|
||||||
|
if (data.contains("{")) {
|
||||||
|
|
||||||
|
// Just clip them out for now yea
|
||||||
|
dataments = data.substring(data.indexOf('{') + 1);
|
||||||
|
data = data.substring(0, data.indexOf('{'));
|
||||||
|
if (dataments.endsWith("}")) { dataments = dataments.substring(0, dataments.length()-1); } }
|
||||||
|
|
||||||
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
|
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
|
||||||
MMOItem m = MMOItems.plugin.getMMOItem(MMOItems.plugin.getType(argument), data);
|
MMOItem m = MMOItems.plugin.getMMOItem(MMOItems.plugin.getType(argument), data);
|
||||||
|
|
||||||
|
// Find upgrade?
|
||||||
|
if (!dataments.isEmpty()) {
|
||||||
|
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Dataments of \u00a7e" + argument + " " + data + "\u00a77: \u00a73 " + dataments);
|
||||||
|
|
||||||
|
// Requires upgrade template :flushed:
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
if (m.hasUpgradeTemplate()) {
|
||||||
|
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Seeking upgrade\u00a7b " + SilentNumbers.valueFromBracketsTab(dataments, "level"));
|
||||||
|
|
||||||
|
// Get
|
||||||
|
QuickNumberRange upgradeReq = SilentNumbers.rangeFromBracketsTab(dataments, "level");
|
||||||
|
if (upgradeReq != null) {
|
||||||
|
//UPGR//MMOItems.log(" \u00a73>\u00a7a> \u00a77Found upgrade\u00a76 " + upgradeReq);
|
||||||
|
UpgradeData ud = ((UpgradeData) m.getData(ItemStats.UPGRADE)).clone();
|
||||||
|
ud.setLevel(SilentNumbers.floor(upgradeReq.getAsDouble(0)));
|
||||||
|
m.setData(ItemStats.UPGRADE, ud);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
ItemStackBuilder builder = m.newBuilder();
|
ItemStackBuilder builder = m.newBuilder();
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.api.crafting.IngredientInventory.PlayerIngredient;
|
|||||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public abstract class Ingredient {
|
public abstract class Ingredient {
|
||||||
private final String id;
|
private final String id;
|
||||||
@ -49,23 +49,32 @@ public abstract class Ingredient {
|
|||||||
/**
|
/**
|
||||||
* Apply specific placeholders to display the ingredient in the item lore.
|
* Apply specific placeholders to display the ingredient in the item lore.
|
||||||
*
|
*
|
||||||
* @param string String with unparsed placeholders
|
* @param s String with unparsed placeholders
|
||||||
* @return String with parsed placeholders
|
* @return String with parsed placeholders
|
||||||
*/
|
*/
|
||||||
public abstract String formatDisplay(String string);
|
public abstract String formatDisplay(String s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the player right-clicks one of the items in a station, they can
|
||||||
|
* preview the stats if itself and the components it is made of. This
|
||||||
|
* is called to displace those preview elements.
|
||||||
|
*
|
||||||
|
* @param player Player looking at the recipe
|
||||||
|
*
|
||||||
|
* @return The ItemStack to display to the player
|
||||||
|
*/
|
||||||
@NotNull public abstract ItemStack generateItemStack(@NotNull RPGPlayer player);
|
@NotNull public abstract ItemStack generateItemStack(@NotNull RPGPlayer player);
|
||||||
|
|
||||||
public CheckedIngredient evaluateIngredient(IngredientInventory inv) {
|
public CheckedIngredient evaluateIngredient(@NotNull IngredientInventory inv) {
|
||||||
return new CheckedIngredient(this, inv.getIngredient(this, IngredientLookupMode.BASIC));
|
return new CheckedIngredient(this, inv.getIngredient(this, IngredientLookupMode.BASIC));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CheckedIngredient {
|
public static class CheckedIngredient {
|
||||||
private final Ingredient ingredient;
|
@NotNull private final Ingredient ingredient;
|
||||||
private final PlayerIngredient found;
|
@Nullable private final PlayerIngredient found;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instanciated everytime an ingredient is evaluated for a player when a
|
* Instantiated everytime an ingredient is evaluated for a player when a
|
||||||
* CheckedRecipe is being created (when a player is opening a crafting
|
* CheckedRecipe is being created (when a player is opening a crafting
|
||||||
* station). This helps greatly reducing ingredient checkups by caching
|
* station). This helps greatly reducing ingredient checkups by caching
|
||||||
* the items the plugin will need to take off the player's ingredient
|
* the items the plugin will need to take off the player's ingredient
|
||||||
@ -74,28 +83,20 @@ public abstract class Ingredient {
|
|||||||
* @param found The corresponding ingredient found in the player's
|
* @param found The corresponding ingredient found in the player's
|
||||||
* ingredient
|
* ingredient
|
||||||
*/
|
*/
|
||||||
private CheckedIngredient(Ingredient ingredient, PlayerIngredient found) {
|
private CheckedIngredient(@NotNull Ingredient ingredient, @Nullable PlayerIngredient found) {
|
||||||
this.ingredient = ingredient;
|
this.ingredient = ingredient;
|
||||||
this.found = found;
|
this.found = found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* checks if the player has a specific item or not
|
* @return If the player has enough of the specific item or not
|
||||||
*/
|
*/
|
||||||
public boolean isHad() {
|
public boolean isHad() { return found != null && found.getAmount() >= ingredient.getAmount(); }
|
||||||
return found != null && found.getAmount() >= ingredient.getAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Ingredient getIngredient() {
|
@NotNull public Ingredient getIngredient() { return ingredient; }
|
||||||
return ingredient;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerIngredient getPlayerIngredient() {
|
@Nullable public PlayerIngredient getPlayerIngredient() { return found; }
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String format() {
|
@NotNull public String format() { return ingredient.formatDisplay(isHad() ? ingredient.getDisplay().getPositive() : ingredient.getDisplay().getNegative()); }
|
||||||
return ingredient.formatDisplay(isHad() ? ingredient.getDisplay().getPositive() : ingredient.getDisplay().getNegative());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package net.Indyuce.mmoitems.api.crafting.ingredient;
|
package net.Indyuce.mmoitems.api.crafting.ingredient;
|
||||||
|
|
||||||
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
|
import io.lumine.mythic.lib.api.util.ui.QuickNumberRange;
|
||||||
|
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
|
||||||
import net.Indyuce.mmoitems.ItemStats;
|
import net.Indyuce.mmoitems.ItemStats;
|
||||||
|
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||||
import net.Indyuce.mmoitems.stat.DisplayName;
|
import net.Indyuce.mmoitems.stat.DisplayName;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -12,31 +16,37 @@ import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
|||||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||||
import net.Indyuce.mmoitems.stat.data.MaterialData;
|
import net.Indyuce.mmoitems.stat.data.MaterialData;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class MMOItemIngredient extends Ingredient {
|
public class MMOItemIngredient extends Ingredient {
|
||||||
private final MMOItemTemplate template;
|
private final MMOItemTemplate template;
|
||||||
|
|
||||||
// TODO check level code.
|
@NotNull private final QuickNumberRange level;
|
||||||
private final int level;
|
|
||||||
private final String display;
|
private final String display;
|
||||||
|
|
||||||
public MMOItemIngredient(MMOLineConfig config) {
|
public MMOItemIngredient(MMOLineConfig config) {
|
||||||
super("mmoitem", config);
|
super("mmoitem", config);
|
||||||
|
|
||||||
|
// Which MMOItem?
|
||||||
config.validate("type", "id");
|
config.validate("type", "id");
|
||||||
Type type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
|
Type type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||||
template = MMOItems.plugin.getTemplates().getTemplateOrThrow(type, config.getString("id"));
|
template = MMOItems.plugin.getTemplates().getTemplateOrThrow(type, config.getString("id"));
|
||||||
|
|
||||||
level = config.getInt("level", 0);
|
// Read level, the default is that any level will work
|
||||||
|
QuickNumberRange qnr = QuickNumberRange.getFromString(config.getString("level", ".."));
|
||||||
|
if (qnr != null) { level = qnr; } else { level = new QuickNumberRange(null, null); }
|
||||||
|
|
||||||
|
// Find the display name of the item
|
||||||
display = config.contains("display") ? config.getString("display") : findName();
|
display = config.contains("display") ? config.getString("display") : findName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MMOItemIngredient(ConfigMMOItem mmoitem) {
|
public MMOItemIngredient(ConfigMMOItem mmoitem) {
|
||||||
super("mmoitem", mmoitem.getAmount());
|
super("mmoitem", mmoitem.getAmount());
|
||||||
|
|
||||||
|
// Just the defaults
|
||||||
template = mmoitem.getTemplate();
|
template = mmoitem.getTemplate();
|
||||||
level = 0;
|
level = new QuickNumberRange(null, null);
|
||||||
display = findName();
|
display = findName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,21 +56,34 @@ public class MMOItemIngredient extends Ingredient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return "mmoitem:" + template.getType().getId().toLowerCase() + (level != 0 ? "-" + level : "") + "_" + template.getId().toLowerCase();
|
return "mmoitem:" + template.getType().getId().toLowerCase() + (level.hasMax() || level.hasMax() ? "-" + level.toString() : "") + "_" + template.getId().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String formatDisplay(String string) {
|
public String formatDisplay(String s) {
|
||||||
return string.replace("#item#", display).replace("#level#", level != 0 ? "lvl." + level + " " : "").replace("#amount#", "" + getAmount());
|
return s.replace("#item#", display).replace("#level#", (level.hasMax() || level.hasMax()) ? "lvl." + level.toString() + " " : "").replace("#amount#", String.valueOf(getAmount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull @Override public ItemStack generateItemStack(@NotNull RPGPlayer player) {
|
||||||
@Override
|
|
||||||
public ItemStack generateItemStack(@NotNull RPGPlayer player) {
|
|
||||||
|
|
||||||
// For display, obviously
|
// Generate fresh from the template
|
||||||
ItemStack item = template.newBuilder(player).build().newBuilder().build(true);
|
MMOItem mmo = template.newBuilder(player).build();
|
||||||
|
|
||||||
|
// Build it for display, obviously
|
||||||
|
ItemStack item = mmo.newBuilder().build(true);
|
||||||
|
|
||||||
|
// Set level lma0
|
||||||
|
int lvl = SilentNumbers.floor(level.getAsDouble(0));
|
||||||
|
if (lvl != 0 && item.getItemMeta() != null) {
|
||||||
|
|
||||||
|
ItemMeta iMeta = item.getItemMeta();
|
||||||
|
iMeta.setDisplayName(MythicLib.plugin.parseColors(findName()));
|
||||||
|
item.setItemMeta(iMeta); }
|
||||||
|
|
||||||
|
// Set the amount
|
||||||
item.setAmount(getAmount());
|
item.setAmount(getAmount());
|
||||||
|
|
||||||
|
// Lets go
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +101,9 @@ public class MMOItemIngredient extends Ingredient {
|
|||||||
name = MMOUtils.caseOnWords(((MaterialData) template.getBaseItemData().get(ItemStats.MATERIAL)).getMaterial().name().toLowerCase().replace("_", " "));
|
name = MMOUtils.caseOnWords(((MaterialData) template.getBaseItemData().get(ItemStats.MATERIAL)).getMaterial().name().toLowerCase().replace("_", " "));
|
||||||
|
|
||||||
if (name == null) { name = "Unrecognized Item"; }
|
if (name == null) { name = "Unrecognized Item"; }
|
||||||
if (level != 0) { return DisplayName.appendUpgradeLevel(name, level); }
|
|
||||||
|
// Append upgrade level
|
||||||
|
if (SilentNumbers.floor(level.getAsDouble(0)) != 0) { return DisplayName.appendUpgradeLevel(name, SilentNumbers.floor(level.getAsDouble(0))); }
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ public class VanillaIngredient extends Ingredient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String formatDisplay(String string) {
|
public String formatDisplay(String s) {
|
||||||
return string.replace("#item#", display).replace("#amount#", "" + getAmount());
|
return s.replace("#item#", display).replace("#amount#", "" + getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -153,7 +153,7 @@ public class GemStone extends UseItem {
|
|||||||
/*
|
/*
|
||||||
* Get the item's level, important for the GemScalingStat
|
* Get the item's level, important for the GemScalingStat
|
||||||
*/
|
*/
|
||||||
Integer levelIdentified = null; String scaling = GemUpgradeScaling.SUBSEQUENT;
|
Integer levelIdentified = null; String scaling = GemUpgradeScaling.defaultValue;
|
||||||
if (gemMMOItem.hasData(ItemStats.GEM_UPGRADE_SCALING)) { scaling = gemMMOItem.getData(ItemStats.GEM_UPGRADE_SCALING).toString(); }
|
if (gemMMOItem.hasData(ItemStats.GEM_UPGRADE_SCALING)) { scaling = gemMMOItem.getData(ItemStats.GEM_UPGRADE_SCALING).toString(); }
|
||||||
//UPGRD//MMOItems.log("Scaling Identified: \u00a73" + scaling);
|
//UPGRD//MMOItems.log("Scaling Identified: \u00a73" + scaling);
|
||||||
switch (scaling) {
|
switch (scaling) {
|
||||||
|
@ -35,8 +35,8 @@ public class MythicItemIngredient extends Ingredient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String formatDisplay(String string) {
|
public String formatDisplay(String s) {
|
||||||
return string.replace("#item#", display).replace("#amount#", "" + getAmount());
|
return s.replace("#item#", display).replace("#amount#", "" + getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -13,6 +13,7 @@ import net.Indyuce.mmoitems.api.item.util.ConfigItems;
|
|||||||
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
|
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
|
||||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||||
import net.Indyuce.mmoitems.command.item.IdentifyCommandTreeNode;
|
import net.Indyuce.mmoitems.command.item.IdentifyCommandTreeNode;
|
||||||
|
import net.Indyuce.mmoitems.stat.GemUpgradeScaling;
|
||||||
import net.Indyuce.mmoitems.stat.LuteAttackEffectStat.LuteAttackEffect;
|
import net.Indyuce.mmoitems.stat.LuteAttackEffectStat.LuteAttackEffect;
|
||||||
import net.Indyuce.mmoitems.stat.StaffSpiritStat.StaffSpirit;
|
import net.Indyuce.mmoitems.stat.StaffSpiritStat.StaffSpirit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -216,6 +217,7 @@ public class ConfigManager implements Reloadable {
|
|||||||
soulboundBaseDamage = MMOItems.plugin.getConfig().getDouble("soulbound.damage.base");
|
soulboundBaseDamage = MMOItems.plugin.getConfig().getDouble("soulbound.damage.base");
|
||||||
soulboundPerLvlDamage = MMOItems.plugin.getConfig().getDouble("soulbound.damage.per-lvl");
|
soulboundPerLvlDamage = MMOItems.plugin.getConfig().getDouble("soulbound.damage.per-lvl");
|
||||||
upgradeRequirementsCheck = MMOItems.plugin.getConfig().getBoolean("item-upgrade-requirements-check");
|
upgradeRequirementsCheck = MMOItems.plugin.getConfig().getBoolean("item-upgrade-requirements-check");
|
||||||
|
GemUpgradeScaling.defaultValue = MMOItems.plugin.getConfig().getString("gem-upgrade-default", GemUpgradeScaling.SUBSEQUENT);
|
||||||
keepSoulboundOnDeath = MMOItems.plugin.getConfig().getBoolean("soulbound.keep-on-death");
|
keepSoulboundOnDeath = MMOItems.plugin.getConfig().getBoolean("soulbound.keep-on-death");
|
||||||
rerollOnItemUpdate = MMOItems.plugin.getConfig().getBoolean("item-revision.reroll-when-updated");
|
rerollOnItemUpdate = MMOItems.plugin.getConfig().getBoolean("item-revision.reroll-when-updated");
|
||||||
levelSpread = MMOItems.plugin.getConfig().getDouble("item-level-spread");
|
levelSpread = MMOItems.plugin.getConfig().getDouble("item-level-spread");
|
||||||
|
@ -17,6 +17,7 @@ import java.util.HashMap;
|
|||||||
*/
|
*/
|
||||||
public class GemUpgradeScaling extends ChooseStat implements GemStoneStat {
|
public class GemUpgradeScaling extends ChooseStat implements GemStoneStat {
|
||||||
public static final String NEVER = "NEVER", HISTORIC = "HISTORIC", SUBSEQUENT = "SUBSEQUENT";
|
public static final String NEVER = "NEVER", HISTORIC = "HISTORIC", SUBSEQUENT = "SUBSEQUENT";
|
||||||
|
public static String defaultValue = SUBSEQUENT;
|
||||||
|
|
||||||
public GemUpgradeScaling() {
|
public GemUpgradeScaling() {
|
||||||
super("GEM_UPGRADE_SCALING", VersionMaterial.LIME_DYE.toMaterial(), "Gem Upgrade Scaling", new String[] { "Gem stones add their stats to items, but you may also", "upgrade your items via crafting stations or consumables.", "", "\u00a76Should this gem stone stats be affected by upgrading?" }, new String[] { "gem_stone" });
|
super("GEM_UPGRADE_SCALING", VersionMaterial.LIME_DYE.toMaterial(), "Gem Upgrade Scaling", new String[] { "Gem stones add their stats to items, but you may also", "upgrade your items via crafting stations or consumables.", "", "\u00a76Should this gem stone stats be affected by upgrading?" }, new String[] { "gem_stone" });
|
||||||
@ -38,5 +39,5 @@ public class GemUpgradeScaling extends ChooseStat implements GemStoneStat {
|
|||||||
HintChooseableDefs(definitions);
|
HintChooseableDefs(definitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull @Override public StatData getClearStatData() { return new StringData(SUBSEQUENT); }
|
@NotNull @Override public StatData getClearStatData() { return new StringData(defaultValue); }
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,6 @@ public class NBTTags extends StringListStat {
|
|||||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last tag.");
|
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last tag.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StatData data) { item.addItemTag(getAppliedNBT(data)); }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlike other StringLists, this adds every content of the array as a different tag rather than as a JsonArray compound.
|
* Unlike other StringLists, this adds every content of the array as a different tag rather than as a JsonArray compound.
|
||||||
*/
|
*/
|
||||||
@ -120,7 +117,6 @@ public class NBTTags extends StringListStat {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object calculateObjectType(String input) {
|
public Object calculateObjectType(String input) {
|
||||||
if (input.equalsIgnoreCase("true"))
|
if (input.equalsIgnoreCase("true"))
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
package net.Indyuce.mmoitems.stat.data;
|
package net.Indyuce.mmoitems.stat.data;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.Indyuce.mmoitems.ItemStats;
|
|
||||||
import net.Indyuce.mmoitems.MMOItems;
|
import net.Indyuce.mmoitems.MMOItems;
|
||||||
import net.Indyuce.mmoitems.api.UpgradeTemplate;
|
import net.Indyuce.mmoitems.api.UpgradeTemplate;
|
||||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
|
||||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
|
||||||
import net.Indyuce.mmoitems.stat.type.StatHistory;
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -23,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* <p> • Chance of successful upgrade
|
* <p> • Chance of successful upgrade
|
||||||
* </p> • May it get destroyed if unsucessful upgrade?
|
* </p> • May it get destroyed if unsucessful upgrade?
|
||||||
*/
|
*/
|
||||||
public class UpgradeData implements StatData, RandomStatData {
|
public class UpgradeData implements StatData, RandomStatData, Cloneable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The String a consumable must match to Upgrade this Item
|
* @return The String a consumable must match to Upgrade this Item
|
||||||
@ -169,4 +164,10 @@ public class UpgradeData implements StatData, RandomStatData {
|
|||||||
public StatData randomize(MMOItemBuilder builder) {
|
public StatData randomize(MMOItemBuilder builder) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UpgradeData clone() {
|
||||||
|
try { super.clone(); } catch (CloneNotSupportedException ignored) { }
|
||||||
|
|
||||||
|
return new UpgradeData(reference, template, workbench, destroy, max, success); }
|
||||||
}
|
}
|
@ -307,7 +307,11 @@ item-revision:
|
|||||||
# keep its gems, this will give the gems back to the
|
# keep its gems, this will give the gems back to the
|
||||||
# player so that they don't get lost forever.
|
# player so that they don't get lost forever.
|
||||||
drop-extra-gems: true
|
drop-extra-gems: true
|
||||||
|
|
||||||
|
# When keeping lore data, only lore that starts with this
|
||||||
|
# will actually be kept.
|
||||||
|
kept-lore-prefix: '&7'
|
||||||
|
|
||||||
# Whether or not specific stats should be kept
|
# Whether or not specific stats should be kept
|
||||||
# when an item is updated to latest revision.
|
# when an item is updated to latest revision.
|
||||||
keep-data:
|
keep-data:
|
||||||
@ -352,5 +356,9 @@ lootsplosion:
|
|||||||
offset: .2
|
offset: .2
|
||||||
height: .6
|
height: .6
|
||||||
|
|
||||||
|
# When Upgrading meets Gems, one must decide if
|
||||||
|
# gems' stats will increase as well.
|
||||||
|
gem-upgrade-default: 'NEVER'
|
||||||
|
|
||||||
# When I was a kid, I saw the Mona Lisa in my school art book...
|
# When I was a kid, I saw the Mona Lisa in my school art book...
|
||||||
# The fist time I saw her, with her hands on her knee... how do I say this...
|
# The fist time I saw her, with her hands on her knee... how do I say this...
|
Loading…
Reference in New Issue
Block a user