MMOItemType super type

This commit is contained in:
Roch Blonndiaux 2023-03-06 14:49:30 +01:00
parent e0a0154d1b
commit 3622203e32
13 changed files with 542 additions and 503 deletions

View File

@ -253,7 +253,8 @@ public class Type {
*/
@Deprecated
public boolean canHave(ItemStat stat) {
return stat.isCompatible(this);
// return stat.isCompatible(this);
return false;
}
private ItemStack read(String str) {

View File

@ -6,6 +6,7 @@ import io.lumine.mythic.lib.damage.AttackMetadata;
import io.lumine.mythic.lib.damage.DamageType;
import io.lumine.mythic.lib.version.VersionSound;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.type.MMOItemType;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.interaction.weapon.Weapon;
import net.Indyuce.mmoitems.api.player.PlayerData;
@ -20,6 +21,11 @@ import org.bukkit.potion.PotionEffectType;
import java.util.Random;
/**
* @deprecated This class is deprecated and will be removed in the next major
* update. Use {@link MMOItemType} instead.
* @see MMOItemType
*/
public enum TypeSet {
/**

View File

@ -2,7 +2,6 @@ package net.Indyuce.mmoitems.api.interaction;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.event.item.ApplyGemStoneEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
@ -64,7 +63,7 @@ public class GemStone extends UseItem {
*/
String appliableTypes = getNBTItem().getString(ItemStats.ITEM_TYPE_RESTRICTION.getNBTPath());
if (!appliableTypes.equals("") && (!targetType.isWeapon() || !appliableTypes.contains("WEAPON"))
&& !appliableTypes.contains(targetType.getItemSet().name()) && !appliableTypes.contains(targetType.getId()))
&& !appliableTypes.contains(targetType.getType().name()) && !appliableTypes.contains(targetType.getId()))
return new ApplyResult(ResultType.NONE);
// Check for success rate

View File

@ -110,8 +110,8 @@ public class Weapon extends UseItem {
return false;
// Handle item set attack effects
if (getMMOItem().getType().getItemSet().hasAttackEffect() && !getNBTItem().getBoolean("MMOITEMS_DISABLE_ATTACK_PASSIVE"))
getMMOItem().getType().getItemSet().applyAttackEffect(attackMeta, playerData, target, this);
if (getMMOItem().getType().hasAttackEffect() && !getNBTItem().getBoolean("MMOITEMS_DISABLE_ATTACK_PASSIVE"))
getMMOItem().getType().applyAttackEffect(attackMeta, playerData, target, this);
return true;
}

View File

@ -6,11 +6,11 @@ import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.util.AdventureUtils;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.event.GenerateLoreEvent;
import net.Indyuce.mmoitems.api.event.ItemBuildEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.item.type.MMOItemType;
import net.Indyuce.mmoitems.stat.DisplayName;
import net.Indyuce.mmoitems.stat.Enchants;
import net.Indyuce.mmoitems.stat.data.MaterialData;
@ -35,6 +35,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class ItemStackBuilder {
@NotNull
@ -195,7 +196,7 @@ public class ItemStackBuilder {
}
// Display gem stone lore hint thing
if (builtMMOItem.getType() == Type.GEM_STONE)
if (builtMMOItem.getType().getType() == MMOItemType.Type.GEM_STONE)
lore.insert("gem-stone-lore", ItemStat.translate("gem-stone-lore"));
// Display item type
@ -218,7 +219,7 @@ public class ItemStackBuilder {
Bukkit.getPluginManager().callEvent(event);
AdventureUtils.setLore(meta, event.getParsedLore().stream()
.map(s -> ChatColor.WHITE + s)
.toList());
.collect(Collectors.toList()));
if (meta.hasDisplayName())
AdventureUtils.setDisplayName(meta, ChatColor.WHITE + meta.getDisplayName());

View File

@ -17,6 +17,7 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@ -30,6 +31,7 @@ public class MMOItemType {
private final String id;
private final String name;
private final Type type;
private final ModifierSource modifierSource;
private final boolean weapon;
private final String loreFormat;
@ -39,9 +41,10 @@ public class MMOItemType {
private final @org.jetbrains.annotations.Nullable Script script;
protected MMOItemType(String id, String name, ModifierSource modifierSource, boolean weapon, String loreFormat, ItemStack item, @org.jetbrains.annotations.Nullable Script script, List<ItemStat<?, ?>> stats) {
protected MMOItemType(String id, String name, Type type, ModifierSource modifierSource, boolean weapon, String loreFormat, ItemStack item, @org.jetbrains.annotations.Nullable Script script, List<ItemStat<?, ?>> stats) {
this.id = id;
this.name = name;
this.type = type;
this.modifierSource = modifierSource;
this.weapon = weapon;
this.loreFormat = loreFormat;
@ -71,6 +74,9 @@ public class MMOItemType {
return loreFormat;
}
public Type getType() {
return type;
}
public ItemStack getItem() {
return item;
@ -125,6 +131,7 @@ public class MMOItemType {
", modifierSource=" + modifierSource +
", weapon=" + weapon +
", loreFormat='" + loreFormat + '\'' +
", type=" + type +
'}';
}
@ -173,13 +180,25 @@ public class MMOItemType {
final String loreFormat = section.getString("lore-format");
final ItemStack item = read(section.getString("display", Material.STONE.toString()));
final Script script = section.isString("script") ? MythicLib.plugin.getSkills().getScriptOrThrow(section.getString("script")) : null;
final Type superType = Arrays.stream(Type.values())
.filter(type1 -> Objects.equals(section.getString("type").toLowerCase(), type1.name().toLowerCase()))
.findFirst()
.orElse(Type.NONE);
// TODO: Load the stats
final List<ItemStat<?, ?>> stats = new ArrayList<>();
MMOItemType type = new MMOItemType(id, name, modifierSource, weapon, loreFormat, item, script, stats);
MMOItemType type = new MMOItemType(id, name, superType, modifierSource, weapon, loreFormat, item, script, stats);
type.getUnidentifiedTemplate().update(section.getConfigurationSection("unident-item"));
return type;
}
public enum Type {
GEM_STONE,
RANGE,
BLOCK,
CONSUMABLE,
NONE
}
}

View File

@ -8,7 +8,6 @@ import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import io.lumine.mythic.lib.util.AdventureUtils;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.edition.NewItemEdition;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.item.type.MMOItemType;
@ -177,7 +176,7 @@ public class ItemBrowser extends PluginInventory {
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
previous.setItemMeta(previousMeta);
if (type == Type.BLOCK) {
if (type.getType() == MMOItemType.Type.BLOCK) {
ItemStack downloadPack = new ItemStack(Material.HOPPER);
ItemMeta downloadMeta = downloadPack.getItemMeta();
downloadMeta.setDisplayName(ChatColor.GREEN + "Download Default Resourcepack");

View File

@ -1,14 +1,14 @@
package net.Indyuce.mmoitems.gui.edition;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.item.util.NamedItemStack;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.item.type.MMOItemType;
import net.Indyuce.mmoitems.api.item.util.NamedItemStack;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -24,227 +24,226 @@ import java.util.ArrayList;
import java.util.List;
public class UpgradingEdition extends EditionInventory {
private static final ItemStack notAvailable = new NamedItemStack(VersionMaterial.RED_STAINED_GLASS_PANE.toMaterial(), "&cNot Available");
private static final ItemStack notAvailable = new NamedItemStack(VersionMaterial.RED_STAINED_GLASS_PANE.toMaterial(), "&cNot Available");
public UpgradingEdition(Player player, MMOItemTemplate template) {
super(player, template);
}
public UpgradingEdition(Player player, MMOItemTemplate template) {
super(player, template);
}
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, 54, "Upgrade Setup: " + template.getId());
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, 54, "Upgrade Setup: " + template.getId());
boolean workbench = getEditedSection().getBoolean("upgrade.workbench");
if (!template.getType().corresponds(Type.CONSUMABLE)) {
boolean workbench = getEditedSection().getBoolean("upgrade.workbench");
if (template.getType().getType() != MMOItemType.Type.CONSUMABLE) {
ItemStack workbenchItem = new ItemStack(VersionMaterial.CRAFTING_TABLE.toMaterial());
ItemMeta workbenchItemMeta = workbenchItem.getItemMeta();
workbenchItemMeta.setDisplayName(ChatColor.GREEN + "Workbench Upgrade Only?");
List<String> workbenchItemLore = new ArrayList<>();
workbenchItemLore.add(ChatColor.GRAY + "When toggled on, players must");
workbenchItemLore.add(ChatColor.GRAY + "use a crafting station recipe in");
workbenchItemLore.add(ChatColor.GRAY + "order to upgrade their weapon.");
workbenchItemLore.add("");
workbenchItemLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GOLD + workbench);
workbenchItemLore.add("");
workbenchItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value.");
workbenchItemMeta.setLore(workbenchItemLore);
workbenchItem.setItemMeta(workbenchItemMeta);
inv.setItem(20, workbenchItem);
ItemStack workbenchItem = new ItemStack(VersionMaterial.CRAFTING_TABLE.toMaterial());
ItemMeta workbenchItemMeta = workbenchItem.getItemMeta();
workbenchItemMeta.setDisplayName(ChatColor.GREEN + "Workbench Upgrade Only?");
List<String> workbenchItemLore = new ArrayList<>();
workbenchItemLore.add(ChatColor.GRAY + "When toggled on, players must");
workbenchItemLore.add(ChatColor.GRAY + "use a crafting station recipe in");
workbenchItemLore.add(ChatColor.GRAY + "order to upgrade their weapon.");
workbenchItemLore.add("");
workbenchItemLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GOLD + workbench);
workbenchItemLore.add("");
workbenchItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value.");
workbenchItemMeta.setLore(workbenchItemLore);
workbenchItem.setItemMeta(workbenchItemMeta);
inv.setItem(20, workbenchItem);
String upgradeTemplate = getEditedSection().getString("upgrade.template");
ItemStack templateItem = new ItemStack(VersionMaterial.OAK_SIGN.toMaterial());
ItemMeta templateItemMeta = templateItem.getItemMeta();
templateItemMeta.setDisplayName(ChatColor.GREEN + "Upgrade Template");
List<String> templateItemLore = new ArrayList<>();
templateItemLore.add(ChatColor.GRAY + "This option dictates what stats are improved");
templateItemLore.add(ChatColor.GRAY + "when your item is upgraded. More info on the wiki.");
templateItemLore.add("");
templateItemLore.add(ChatColor.GRAY + "Current Value: "
+ (upgradeTemplate == null ? ChatColor.RED + "No template" : ChatColor.GOLD + upgradeTemplate));
templateItemLore.add("");
templateItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to input the template.");
templateItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
templateItemMeta.setLore(templateItemLore);
templateItem.setItemMeta(templateItemMeta);
inv.setItem(22, templateItem);
String upgradeTemplate = getEditedSection().getString("upgrade.template");
ItemStack templateItem = new ItemStack(VersionMaterial.OAK_SIGN.toMaterial());
ItemMeta templateItemMeta = templateItem.getItemMeta();
templateItemMeta.setDisplayName(ChatColor.GREEN + "Upgrade Template");
List<String> templateItemLore = new ArrayList<>();
templateItemLore.add(ChatColor.GRAY + "This option dictates what stats are improved");
templateItemLore.add(ChatColor.GRAY + "when your item is upgraded. More info on the wiki.");
templateItemLore.add("");
templateItemLore.add(ChatColor.GRAY + "Current Value: "
+ (upgradeTemplate == null ? ChatColor.RED + "No template" : ChatColor.GOLD + upgradeTemplate));
templateItemLore.add("");
templateItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to input the template.");
templateItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
templateItemMeta.setLore(templateItemLore);
templateItem.setItemMeta(templateItemMeta);
inv.setItem(22, templateItem);
int max = getEditedSection().getInt("upgrade.max");
ItemStack maxItem = new ItemStack(Material.BARRIER);
ItemMeta maxItemMeta = maxItem.getItemMeta();
maxItemMeta.setDisplayName(ChatColor.GREEN + "Max Upgrades");
List<String> maxItemLore = new ArrayList<>();
maxItemLore.add(ChatColor.GRAY + "The maximum amount of upgrades your");
maxItemLore.add(ChatColor.GRAY + "item may receive (recipe or consumable).");
maxItemLore.add("");
maxItemLore.add(ChatColor.GRAY + "Current Value: " + (max == 0 ? ChatColor.RED + "No limit" : ChatColor.GOLD + "" + max));
maxItemLore.add("");
maxItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to chance this value.");
maxItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
maxItemMeta.setLore(maxItemLore);
maxItem.setItemMeta(maxItemMeta);
inv.setItem(40, maxItem);
int max = getEditedSection().getInt("upgrade.max");
ItemStack maxItem = new ItemStack(Material.BARRIER);
ItemMeta maxItemMeta = maxItem.getItemMeta();
maxItemMeta.setDisplayName(ChatColor.GREEN + "Max Upgrades");
List<String> maxItemLore = new ArrayList<>();
maxItemLore.add(ChatColor.GRAY + "The maximum amount of upgrades your");
maxItemLore.add(ChatColor.GRAY + "item may receive (recipe or consumable).");
maxItemLore.add("");
maxItemLore.add(ChatColor.GRAY + "Current Value: " + (max == 0 ? ChatColor.RED + "No limit" : ChatColor.GOLD + "" + max));
maxItemLore.add("");
maxItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to chance this value.");
maxItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
maxItemMeta.setLore(maxItemLore);
maxItem.setItemMeta(maxItemMeta);
inv.setItem(40, maxItem);
int min = getEditedSection().getInt("upgrade.min", 0);
ItemStack minItem = new ItemStack(Material.BARRIER);
ItemMeta minItemMeta = minItem.getItemMeta();
minItemMeta.setDisplayName(ChatColor.GREEN + "Min Upgrades");
List<String> minItemLore = new ArrayList<>();
minItemLore.add(ChatColor.GRAY + "The minimum level your item can be");
minItemLore.add(ChatColor.GRAY + "downgraded to (by dying or breaking).");
minItemLore.add("");
minItemLore.add(ChatColor.GRAY + "Current Value: " + (min == 0 ? ChatColor.RED + "0" : ChatColor.GOLD + String.valueOf(min)));
minItemLore.add("");
minItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to chance this value.");
minItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
minItemMeta.setLore(minItemLore);
minItem.setItemMeta(minItemMeta);
inv.setItem(41, minItem);
} else {
inv.setItem(20, notAvailable);
inv.setItem(22, notAvailable);
}
int min = getEditedSection().getInt("upgrade.min", 0);
ItemStack minItem = new ItemStack(Material.BARRIER);
ItemMeta minItemMeta = minItem.getItemMeta();
minItemMeta.setDisplayName(ChatColor.GREEN + "Min Upgrades");
List<String> minItemLore = new ArrayList<>();
minItemLore.add(ChatColor.GRAY + "The minimum level your item can be");
minItemLore.add(ChatColor.GRAY + "downgraded to (by dying or breaking).");
minItemLore.add("");
minItemLore.add(ChatColor.GRAY + "Current Value: " + (min == 0 ? ChatColor.RED + "0" : ChatColor.GOLD + String.valueOf(min)));
minItemLore.add("");
minItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to chance this value.");
minItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
minItemMeta.setLore(minItemLore);
minItem.setItemMeta(minItemMeta);
inv.setItem(41, minItem);
} else {
inv.setItem(20, notAvailable);
inv.setItem(22, notAvailable);
}
if (!workbench || template.getType().getType() == MMOItemType.Type.CONSUMABLE) {
if (!workbench || template.getType().corresponds(Type.CONSUMABLE)) {
String reference = getEditedSection().getString("upgrade.reference");
ItemStack referenceItem = new ItemStack(Material.PAPER);
ItemMeta referenceItemMeta = referenceItem.getItemMeta();
referenceItemMeta.setDisplayName(ChatColor.GREEN + "Upgrade Reference");
List<String> referenceItemLore = new ArrayList<>();
referenceItemLore.add(ChatColor.GRAY + "This option dictates what consumables can");
referenceItemLore.add(ChatColor.GRAY + "upgrade your item. " + ChatColor.AQUA + "The consumable upgrade");
referenceItemLore.add(ChatColor.AQUA + "reference must match your item's reference" + ChatColor.GRAY + ",");
referenceItemLore.add(ChatColor.GRAY + "otherwise it can't upgrade it. Leave this blank");
referenceItemLore.add(ChatColor.GRAY + "so any consumable can upgrade this item.");
referenceItemLore.add("");
referenceItemLore
.add(ChatColor.GRAY + "Current Value: " + (reference == null ? ChatColor.RED + "No reference" : ChatColor.GOLD + reference));
referenceItemLore.add("");
referenceItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to input the reference.");
referenceItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
referenceItemMeta.setLore(referenceItemLore);
referenceItem.setItemMeta(referenceItemMeta);
inv.setItem(38, referenceItem);
} else
inv.setItem(38, notAvailable);
String reference = getEditedSection().getString("upgrade.reference");
ItemStack referenceItem = new ItemStack(Material.PAPER);
ItemMeta referenceItemMeta = referenceItem.getItemMeta();
referenceItemMeta.setDisplayName(ChatColor.GREEN + "Upgrade Reference");
List<String> referenceItemLore = new ArrayList<>();
referenceItemLore.add(ChatColor.GRAY + "This option dictates what consumables can");
referenceItemLore.add(ChatColor.GRAY + "upgrade your item. " + ChatColor.AQUA + "The consumable upgrade");
referenceItemLore.add(ChatColor.AQUA + "reference must match your item's reference" + ChatColor.GRAY + ",");
referenceItemLore.add(ChatColor.GRAY + "otherwise it can't upgrade it. Leave this blank");
referenceItemLore.add(ChatColor.GRAY + "so any consumable can upgrade this item.");
referenceItemLore.add("");
referenceItemLore
.add(ChatColor.GRAY + "Current Value: " + (reference == null ? ChatColor.RED + "No reference" : ChatColor.GOLD + reference));
referenceItemLore.add("");
referenceItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to input the reference.");
referenceItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
referenceItemMeta.setLore(referenceItemLore);
referenceItem.setItemMeta(referenceItemMeta);
inv.setItem(38, referenceItem);
} else
inv.setItem(38, notAvailable);
double success = getEditedSection().getDouble("upgrade.success");
ItemStack successItem = new ItemStack(VersionMaterial.EXPERIENCE_BOTTLE.toMaterial());
ItemMeta successItemMeta = successItem.getItemMeta();
successItemMeta.setDisplayName(ChatColor.GREEN + "Success Chance");
List<String> successItemLore = new ArrayList<>();
successItemLore.add(ChatColor.GRAY + "The chance of successfully upgrading");
successItemLore.add(ChatColor.GRAY + "when using a consumable or when using");
successItemLore.add(ChatColor.GRAY + "a station upgrading recipe.");
successItemLore.add("");
successItemLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GOLD + (success == 0 ? "100" : "" + success) + "%");
successItemLore.add("");
successItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to change this value.");
successItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
successItemMeta.setLore(successItemLore);
successItem.setItemMeta(successItemMeta);
inv.setItem(24, successItem);
double success = getEditedSection().getDouble("upgrade.success");
ItemStack successItem = new ItemStack(VersionMaterial.EXPERIENCE_BOTTLE.toMaterial());
ItemMeta successItemMeta = successItem.getItemMeta();
successItemMeta.setDisplayName(ChatColor.GREEN + "Success Chance");
List<String> successItemLore = new ArrayList<>();
successItemLore.add(ChatColor.GRAY + "The chance of successfully upgrading");
successItemLore.add(ChatColor.GRAY + "when using a consumable or when using");
successItemLore.add(ChatColor.GRAY + "a station upgrading recipe.");
successItemLore.add("");
successItemLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GOLD + (success == 0 ? "100" : "" + success) + "%");
successItemLore.add("");
successItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to change this value.");
successItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset.");
successItemMeta.setLore(successItemLore);
successItem.setItemMeta(successItemMeta);
inv.setItem(24, successItem);
if (success > 0 && template.getType().getType() != MMOItemType.Type.CONSUMABLE) {
ItemStack destroyOnFail = new ItemStack(Material.FISHING_ROD);
ItemMeta destroyOnFailMeta = destroyOnFail.getItemMeta();
((Damageable) destroyOnFailMeta).setDamage(30);
destroyOnFailMeta.setDisplayName(ChatColor.GREEN + "Destroy on fail?");
List<String> destroyOnFailLore = new ArrayList<>();
destroyOnFailLore.add(ChatColor.GRAY + "When toggled on, the item will be");
destroyOnFailLore.add(ChatColor.GRAY + "destroyed when failing at upgrading it.");
destroyOnFailLore.add("");
destroyOnFailLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GOLD + getEditedSection().getBoolean("upgrade.destroy"));
destroyOnFailLore.add("");
destroyOnFailLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value.");
destroyOnFailMeta.setLore(destroyOnFailLore);
destroyOnFail.setItemMeta(destroyOnFailMeta);
inv.setItem(42, destroyOnFail);
}
if (success > 0 && !template.getType().corresponds(Type.CONSUMABLE)) {
ItemStack destroyOnFail = new ItemStack(Material.FISHING_ROD);
ItemMeta destroyOnFailMeta = destroyOnFail.getItemMeta();
((Damageable) destroyOnFailMeta).setDamage(30);
destroyOnFailMeta.setDisplayName(ChatColor.GREEN + "Destroy on fail?");
List<String> destroyOnFailLore = new ArrayList<>();
destroyOnFailLore.add(ChatColor.GRAY + "When toggled on, the item will be");
destroyOnFailLore.add(ChatColor.GRAY + "destroyed when failing at upgrading it.");
destroyOnFailLore.add("");
destroyOnFailLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GOLD + getEditedSection().getBoolean("upgrade.destroy"));
destroyOnFailLore.add("");
destroyOnFailLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value.");
destroyOnFailMeta.setLore(destroyOnFailLore);
destroyOnFail.setItemMeta(destroyOnFailMeta);
inv.setItem(42, destroyOnFail);
}
addEditionInventoryItems(inv, true);
addEditionInventoryItems(inv, true);
return inv;
}
return inv;
}
@Override
public void whenClicked(InventoryClickEvent event) {
ItemStack item = event.getCurrentItem();
@Override
public void whenClicked(InventoryClickEvent event) {
ItemStack item = event.getCurrentItem();
event.setCancelled(true);
if (event.getInventory() != event.getClickedInventory() || !MMOUtils.isMetaItem(item, false))
return;
event.setCancelled(true);
if (event.getInventory() != event.getClickedInventory() || !MMOUtils.isMetaItem(item, false))
return;
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Success Chance")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "rate").enable("Write in the chat the success rate you want.");
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Success Chance")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "rate").enable("Write in the chat the success rate you want.");
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.success")) {
getEditedSection().set("upgrade.success", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset success chance.");
}
}
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.success")) {
getEditedSection().set("upgrade.success", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset success chance.");
}
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Max Upgrades")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "max").enable("Write in the chat the number you want.");
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Max Upgrades")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "max").enable("Write in the chat the number you want.");
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.max")) {
getEditedSection().set("upgrade.max", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset the number of max upgrades.");
}
}
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.max")) {
getEditedSection().set("upgrade.max", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset the number of max upgrades.");
}
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Min Upgrades")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "min").enable("Write in the chat the number you want.");
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Min Upgrades")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "min").enable("Write in the chat the number you want.");
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.min")) {
getEditedSection().set("upgrade.min", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset the number of min level.");
}
}
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.min")) {
getEditedSection().set("upgrade.min", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset the number of min level.");
}
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Upgrade Template")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "template").enable("Write in the chat the upgrade template ID you want.");
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Upgrade Template")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "template").enable("Write in the chat the upgrade template ID you want.");
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.template")) {
getEditedSection().set("upgrade.template", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset upgrade template.");
}
}
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.template")) {
getEditedSection().set("upgrade.template", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset upgrade template.");
}
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Upgrade Reference")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "ref").enable("Write in the chat the upgrade reference (text) you want.");
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Upgrade Reference")) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new StatEdition(this, ItemStats.UPGRADE, "ref").enable("Write in the chat the upgrade reference (text) you want.");
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.reference")) {
getEditedSection().set("upgrade.reference", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset upgrade reference.");
}
}
if (event.getAction() == InventoryAction.PICKUP_HALF && getEditedSection().contains("upgrade.reference")) {
getEditedSection().set("upgrade.reference", null);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reset upgrade reference.");
}
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Workbench Upgrade Only?")) {
boolean bool = !getEditedSection().getBoolean("upgrade.workbench");
getEditedSection().set("upgrade.workbench", bool);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix()
+ (bool ? "Your item must now be upgraded via recipes." : "Your item can now be upgraded using consumables."));
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Workbench Upgrade Only?")) {
boolean bool = !getEditedSection().getBoolean("upgrade.workbench");
getEditedSection().set("upgrade.workbench", bool);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix()
+ (bool ? "Your item must now be upgraded via recipes." : "Your item can now be upgraded using consumables."));
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Destroy on fail?")) {
boolean bool = !getEditedSection().getBoolean("upgrade.destroy");
getEditedSection().set("upgrade.destroy", bool);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix()
+ (bool ? "Your item will be destroyed upon failing upgrade." : "Your item will not be destroyed upon failing upgrade."));
}
}
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Destroy on fail?")) {
boolean bool = !getEditedSection().getBoolean("upgrade.destroy");
getEditedSection().set("upgrade.destroy", bool);
registerTemplateEdition();
player.sendMessage(MMOItems.plugin.getPrefix()
+ (bool ? "Your item will be destroyed upon failing upgrade." : "Your item will not be destroyed upon failing upgrade."));
}
}
}

View File

@ -9,7 +9,6 @@ import io.lumine.mythic.lib.comp.interaction.InteractionType;
import io.lumine.mythic.lib.damage.MeleeAttackMetadata;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.TypeSet;
import net.Indyuce.mmoitems.api.event.item.SpecialWeaponAttackEvent;
import net.Indyuce.mmoitems.api.interaction.*;
import net.Indyuce.mmoitems.api.interaction.weapon.Gauntlet;
@ -109,7 +108,6 @@ public class ItemUse implements Listener {
@EventHandler(ignoreCancelled = true)
public void meleeAttacks(PlayerAttackEvent event) {
// Checks if it's a melee attack
if (!(event.getAttack() instanceof MeleeAttackMetadata))
return;
@ -123,24 +121,24 @@ public class ItemUse implements Listener {
ItemStack weaponUsed = player.getInventory().getItem(((MeleeAttackMetadata) event.getAttack()).getHand().toBukkit());
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(weaponUsed);
if (item.hasType() && Type.get(item.getType()) != Type.BLOCK) {
Weapon weapon = new Weapon(playerData, item);
if (!item.hasType()
|| MMOItemType.get(item.getType()) == null
|| MMOItemType.get(item.getType()).getType() == MMOItemType.Type.BLOCK)
return;
Weapon weapon = new Weapon(playerData, item);
if (weapon.getMMOItem().getType().getItemSet() == TypeSet.RANGE) {
event.setCancelled(true);
return;
}
if (!weapon.checkItemRequirements()) {
event.setCancelled(true);
return;
}
if (!weapon.handleTargetedAttack(event.getAttack(), event.getEntity())) {
event.setCancelled(true);
return;
}
if (weapon.getMMOItem().getType().getType() == MMOItemType.Type.RANGE) {
event.setCancelled(true);
return;
}
if (!weapon.checkItemRequirements()) {
event.setCancelled(true);
return;
}
if (!weapon.handleTargetedAttack(event.getAttack(), event.getEntity()))
event.setCancelled(true);
}
/**

View File

@ -2,10 +2,10 @@ package net.Indyuce.mmoitems.manager;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.block.CustomBlock;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.item.type.MMOItemType;
import net.Indyuce.mmoitems.api.util.MushroomState;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import org.bukkit.Material;
@ -13,13 +13,7 @@ import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.MultipleFacing;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
public class BlockManager implements Reloadable {
@ -109,7 +103,7 @@ public class BlockManager implements Reloadable {
customBlocks.clear();
mushroomStateValue.clear();
for (MMOItemTemplate template : MMOItems.plugin.getTemplates().getTemplates(Type.BLOCK)) {
for (MMOItemTemplate template : MMOItems.plugin.getTemplates().getTemplates(MMOItemType.Type.BLOCK)) {
MMOItem mmoitem = template.newBuilder(0, null).build();
int id = mmoitem.hasData(ItemStats.BLOCK_ID) ? (int) ((DoubleData) mmoitem.getData(ItemStats.BLOCK_ID)).getValue() : 0;
if (id > 0 && id < 161 && id != 54)

View File

@ -5,7 +5,7 @@ import io.lumine.mythic.lib.element.Element;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.type.MMOItemType;
import net.Indyuce.mmoitems.stat.type.*;
import net.Indyuce.mmoitems.util.ElementStatType;
import org.apache.commons.lang3.Validate;
@ -172,7 +172,7 @@ public class StatManager {
stats.put(stat.getId(), stat);
if (stat instanceof DoubleStat && !(stat instanceof GemStoneStat) && stat.isCompatible(Type.GEM_STONE))
if (stat instanceof DoubleStat && !(stat instanceof GemStoneStat) && stat.isCompatible(MMOItemType.Type.GEM_STONE))
numeric.add((DoubleStat) stat);
if (stat instanceof ItemRestriction)

View File

@ -25,303 +25,321 @@ import java.util.stream.Collectors;
public class TemplateManager implements Reloadable {
/*
* registered mmoitem templates
*/
private final TemplateMap<MMOItemTemplate> templates = new TemplateMap<>();
/*
* registered mmoitem templates
*/
private final TemplateMap<MMOItemTemplate> templates = new TemplateMap<>();
/*
* bank of item modifiers which can be used anywhere in generation templates
* to make item generation easier.
*/
private final Map<String, TemplateModifier> modifiers = new HashMap<>();
/*
* bank of item modifiers which can be used anywhere in generation templates
* to make item generation easier.
*/
private final Map<String, TemplateModifier> modifiers = new HashMap<>();
private static final Random random = new Random();
private static final Random random = new Random();
/**
* @param type The MMOItem Type
* @param id The MMOItem ID
*
* @return If these two Strings represent a loaded MMOItem Template
*/
public boolean hasTemplate(@Nullable MMOItemType type, @Nullable String id) {
if (type == null || id == null) { return false; }
return templates.hasValue(type, id);
}
/**
* @param type The MMOItem Type
* @param id The MMOItem ID
* @return If these two Strings represent a loaded MMOItem Template
*/
public boolean hasTemplate(@Nullable MMOItemType type, @Nullable String id) {
if (type == null || id == null) {
return false;
}
return templates.hasValue(type, id);
}
/**
* @param nbt The 'processed' ItemStack you are trying to read.
*
* @return If there is a MMOItem Template information in this NBTItem
*/
public boolean hasTemplate(@Nullable NBTItem nbt) {
if (nbt == null) { return false; }
return hasTemplate(MMOItemType.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID"));
}
/**
* @param nbt The 'processed' ItemStack you are trying to read.
* @return If there is a MMOItem Template information in this NBTItem
*/
public boolean hasTemplate(@Nullable NBTItem nbt) {
if (nbt == null) {
return false;
}
return hasTemplate(MMOItemType.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID"));
}
/**
* Gets the template of such type and ID
*
* @param type Type of MMOItem
* @param id ID of MMOItem
*
* @return A template of these qualifications if it found them,
*/
@Nullable
@Contract("_, null -> null")
public MMOItemTemplate getTemplate(@Nullable MMOItemType type, @Nullable String id) {
if (type == null || id == null) return null;
return templates.getValue(type, id);
}
/**
* Gets the template of such type and ID
*
* @param type Type of MMOItem
* @param id ID of MMOItem
* @return A template of these qualifications if it found them,
*/
@Nullable
@Contract("_, null -> null")
public MMOItemTemplate getTemplate(@Nullable MMOItemType type, @Nullable String id) {
if (type == null || id == null) return null;
return templates.getValue(type, id);
}
/**
* Attempts to get the Item Template of this Item Stack.
*
* @param nbt The NBTItem you are trying to read.
*
* @return The MMOItem Template parent of it, if it has any.
*/
@Nullable
@Contract("null -> null")
public MMOItemTemplate getTemplate(@Nullable NBTItem nbt) {
if (nbt == null) return null;
return getTemplate(MMOItemType.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID"));
}
/**
* Attempts to get the Item Template of this Item Stack.
*
* @param nbt The NBTItem you are trying to read.
* @return The MMOItem Template parent of it, if it has any.
*/
@Nullable
@Contract("null -> null")
public MMOItemTemplate getTemplate(@Nullable NBTItem nbt) {
if (nbt == null) return null;
return getTemplate(MMOItemType.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID"));
}
/**
* Used in class constructors to easily
*
* @param type The item type
* @param id The item ID
* @return MMOItem template if it exists, or throws an IAE otherwise
*/
@NotNull
@Contract("_, null -> fail")
public MMOItemTemplate getTemplateOrThrow(@Nullable MMOItemType type, @Nullable String id) {
Validate.isTrue(type != null && hasTemplate(type, id), "Could not find a template with ID '" + id + "'");
return templates.getValue(type, id);
}
@NotNull
public Collection<MMOItemTemplate> getTemplates(@NotNull MMOItemType type) {
return templates.collectValues(type);
}
/**
* Used in class constructors to easily
*
* @param type The item type
* @param id The item ID
* @return MMOItem template if it exists, or throws an IAE otherwise
*/
@NotNull
@Contract("_, null -> fail")
public MMOItemTemplate getTemplateOrThrow(@Nullable MMOItemType type, @Nullable String id) {
Validate.isTrue(type != null && hasTemplate(type, id), "Could not find a template with ID '" + id + "'");
return templates.getValue(type, id);
}
@NotNull public Collection<MMOItemTemplate> getTemplates(@NotNull MMOItemType type) {
return templates.collectValues(type);
}
@NotNull public List<String> getTemplateNames(@NotNull MMOItemType type) {
return this.templates.collectValues(type)
public List<MMOItemTemplate> getTemplates(@NotNull MMOItemType.Type type) {
return templates.collectValues()
.stream()
.map(MMOItemTemplate::getId)
.filter(template -> template.getType().getType() == type)
.collect(Collectors.toList());
}
/**
* Registers an MMOItem template internally. Can be done at any time
*
* @param template Template to register
*/
public void registerTemplate(@NotNull MMOItemTemplate template) {
Validate.notNull(template, "MMOItem template cannot be null");
@NotNull
public List<String> getTemplateNames(@NotNull MMOItemType type) {
return this.templates.collectValues(type)
.stream()
.map(MMOItemTemplate::getId)
.collect(Collectors.toList());
}
templates.setValue(template.getType(), template.getId(), template);
}
/**
* Registers an MMOItem template internally. Can be done at any time
*
* @param template Template to register
*/
public void registerTemplate(@NotNull MMOItemTemplate template) {
Validate.notNull(template, "MMOItem template cannot be null");
/**
* Unregisters a template from mmoitem registery. Must be used when an item
* is removed from the config files. Also disables the dynamic updater for
* that item
*
* @param type The item type
* @param id The item ID
*/
public void unregisterTemplate(@NotNull MMOItemType type, @NotNull String id) {
templates.removeValue(type, id);
}
templates.setValue(template.getType(), template.getId(), template);
}
/**
* Unregisters a template from mmoitem registery and clears it from the
* config file
*
* @param type The item type
* @param id The item ID
*/
public void deleteTemplate(@NotNull MMOItemType type, @NotNull String id) {
unregisterTemplate(type, id);
/**
* Unregisters a template from mmoitem registery. Must be used when an item
* is removed from the config files. Also disables the dynamic updater for
* that item
*
* @param type The item type
* @param id The item ID
*/
public void unregisterTemplate(@NotNull MMOItemType type, @NotNull String id) {
templates.removeValue(type, id);
}
ConfigFile config = type.getConfigFile();
config.getConfig().set(id, null);
config.save();
}
/**
* Unregisters a template from mmoitem registery and clears it from the
* config file
*
* @param type The item type
* @param id The item ID
*/
public void deleteTemplate(@NotNull MMOItemType type, @NotNull String id) {
unregisterTemplate(type, id);
/**
* Used whenever an item is created or edited through the GUI edition. This
* method unregisters the current template and loads it again from the
* configuration file.
*
* Can also be used right after creating a template after the config file
* has been initialized in order to load the newly created item
*
* @param type The item type
* @param id The item ID
*/
@SuppressWarnings("UnusedReturnValue")
public MMOItemTemplate requestTemplateUpdate(@NotNull MMOItemType type, @NotNull String id) {
templates.removeValue(type, id);
ConfigFile config = type.getConfigFile();
config.getConfig().set(id, null);
config.save();
}
try {
MMOItemTemplate template = new MMOItemTemplate(type, type.getConfigFile().getConfig().getConfigurationSection(id));
template.postLoad();
registerTemplate(template);
return template;
/**
* Used whenever an item is created or edited through the GUI edition. This
* method unregisters the current template and loads it again from the
* configuration file.
* <p>
* Can also be used right after creating a template after the config file
* has been initialized in order to load the newly created item
*
* @param type The item type
* @param id The item ID
*/
@SuppressWarnings("UnusedReturnValue")
public MMOItemTemplate requestTemplateUpdate(@NotNull MMOItemType type, @NotNull String id) {
templates.removeValue(type, id);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occurred while trying to reload item gen template '" + id + "': " + exception.getMessage());
return null;
}
}
try {
MMOItemTemplate template = new MMOItemTemplate(type, type.getConfigFile().getConfig().getConfigurationSection(id));
template.postLoad();
registerTemplate(template);
return template;
/**
* @return Collects all existing mmoitem templates into a set so that it can
* be filtered afterwards to generate random loot
*/
public Collection<MMOItemTemplate> collectTemplates() { return templates.collectValues(); }
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occurred while trying to reload item gen template '" + id + "': " + exception.getMessage());
return null;
}
}
public boolean hasModifier(String id) { return modifiers.containsKey(id); }
/**
* @return Collects all existing mmoitem templates into a set so that it can
* be filtered afterwards to generate random loot
*/
public Collection<MMOItemTemplate> collectTemplates() {
return templates.collectValues();
}
public TemplateModifier getModifier(String id) { return modifiers.get(id); }
public boolean hasModifier(String id) {
return modifiers.containsKey(id);
}
public Collection<TemplateModifier> getModifiers() { return modifiers.values(); }
public TemplateModifier getModifier(String id) {
return modifiers.get(id);
}
public ItemTier rollTier() {
public Collection<TemplateModifier> getModifiers() {
return modifiers.values();
}
double s = 0;
for (ItemTier tier : MMOItems.plugin.getTiers().getAll()) {
if (s >= 1 || random.nextDouble() < tier.getGenerationChance() / (1 - s))
return tier;
public ItemTier rollTier() {
s += tier.getGenerationChance();
}
double s = 0;
for (ItemTier tier : MMOItems.plugin.getTiers().getAll()) {
if (s >= 1 || random.nextDouble() < tier.getGenerationChance() / (1 - s))
return tier;
// default tier
return null;
}
s += tier.getGenerationChance();
}
/**
* @param playerLevel Input player level
* @return Generates a randomly chosen item level. The level
* spread (editable in the main config file)
* corresponding to the standard deviation of a gaussian
* distribution centered on the player level (input)
*/
public int rollLevel(int playerLevel) {
double spread = MMOItems.plugin.getLanguage().levelSpread;
double found = random.nextGaussian() * spread * .7 + playerLevel;
// default tier
return null;
}
// must be in [level - spread, level + spread]
// lower bound must be higher than 1
found = Math.max(Math.min(found, playerLevel + spread), Math.max(1, playerLevel - spread));
/**
* @param playerLevel Input player level
* @return Generates a randomly chosen item level. The level
* spread (editable in the main config file)
* corresponding to the standard deviation of a gaussian
* distribution centered on the player level (input)
*/
public int rollLevel(int playerLevel) {
double spread = MMOItems.plugin.getLanguage().levelSpread;
double found = random.nextGaussian() * spread * .7 + playerLevel;
return (int) found;
}
// must be in [level - spread, level + spread]
// lower bound must be higher than 1
found = Math.max(Math.min(found, playerLevel + spread), Math.max(1, playerLevel - spread));
/**
* Templates must be loaded whenever MMOItems enables so that other plugins
* like MMOCore can load template references in drop items or other objects.
* Template data is only loaded when MMOItems enables, once sets, tiers..
* are initialized
*/
public void preloadTemplates() {
for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();
for (String key : config.getKeys(false))
try {
registerTemplate(new MMOItemTemplate(type, config.getConfigurationSection(key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "Could not preload item template '" + key + "': " + exception.getMessage());
}
}
}
return (int) found;
}
/**
* Loads item generator modifiers and post load item templates.
*/
public void postloadTemplates() {
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
ffp.activatePrefix(true, "Item Templates");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading template modifiers, please wait..");
for (File file : new File(MMOItems.plugin.getDataFolder() + "/modifiers").listFiles()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
ffp.activatePrefix(true, "Item Templates \u00a78($r" + file.getPath() + "\u00a78)");
for (String key : config.getKeys(false))
try {
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
modifiers.put(modifier.getId(), modifier);
} catch (IllegalArgumentException exception) {
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not load template modifier '" + key + "': " + exception.getMessage());
}
}
/**
* Templates must be loaded whenever MMOItems enables so that other plugins
* like MMOCore can load template references in drop items or other objects.
* Template data is only loaded when MMOItems enables, once sets, tiers..
* are initialized
*/
public void preloadTemplates() {
for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();
for (String key : config.getKeys(false))
try {
registerTemplate(new MMOItemTemplate(type, config.getConfigurationSection(key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "Could not preload item template '" + key + "': " + exception.getMessage());
}
}
}
ffp.activatePrefix(true, "Item Templates");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading item templates, please wait...");
templates.forEach(template -> {
try {
template.postLoad();
} catch (IllegalArgumentException exception) {
ffp.activatePrefix(true, "Item Templates \u00a78($r" + template.getType().getId() + "\u00a78)");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not load item template '" + template.getId() + "': " + exception.getMessage());
}
});
/**
* Loads item generator modifiers and post load item templates.
*/
public void postloadTemplates() {
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
ffp.activatePrefix(true, "Item Templates");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading template modifiers, please wait..");
for (File file : new File(MMOItems.plugin.getDataFolder() + "/modifiers").listFiles()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
ffp.activatePrefix(true, "Item Templates \u00a78($r" + file.getPath() + "\u00a78)");
for (String key : config.getKeys(false))
try {
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
modifiers.put(modifier.getId(), modifier);
} catch (IllegalArgumentException exception) {
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not load template modifier '" + key + "': " + exception.getMessage());
}
}
// Print all failures
ffp.sendTo(FriendlyFeedbackCategory.INFORMATION, MMOItems.getConsole());
}
ffp.activatePrefix(true, "Item Templates");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading item templates, please wait...");
templates.forEach(template -> {
try {
template.postLoad();
} catch (IllegalArgumentException exception) {
ffp.activatePrefix(true, "Item Templates \u00a78($r" + template.getType().getId() + "\u00a78)");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not load item template '" + template.getId() + "': " + exception.getMessage());
}
});
/**
* Reloads the item templates. This is the method used to reload the manager
* when the server is already running. It clears all the maps and loads
* everything again. Template references in other plugins like MMOCore must
* be refreshed afterwards.
*/
public void reload() {
templates.clear();
modifiers.clear();
// Print all failures
ffp.sendTo(FriendlyFeedbackCategory.INFORMATION, MMOItems.getConsole());
}
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
ffp.activatePrefix(true, "Item Templates");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading template modifiers, please wait..");
/**
* Reloads the item templates. This is the method used to reload the manager
* when the server is already running. It clears all the maps and loads
* everything again. Template references in other plugins like MMOCore must
* be refreshed afterwards.
*/
public void reload() {
templates.clear();
modifiers.clear();
for (File file : new File(MMOItems.plugin.getDataFolder() + "/modifiers").listFiles()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
ffp.activatePrefix(true, "Item Templates \u00a78($r" + file.getPath() + "\u00a78)");
for (String key : config.getKeys(false))
try {
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
modifiers.put(modifier.getId(), modifier);
} catch (IllegalArgumentException exception) {
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
ffp.activatePrefix(true, "Item Templates");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading template modifiers, please wait..");
// Log
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not load template modifier '" + key + "': " + exception.getMessage());
}
}
for (File file : new File(MMOItems.plugin.getDataFolder() + "/modifiers").listFiles()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
ffp.activatePrefix(true, "Item Templates \u00a78($r" + file.getPath() + "\u00a78)");
for (String key : config.getKeys(false))
try {
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
modifiers.put(modifier.getId(), modifier);
} catch (IllegalArgumentException exception) {
ffp.activatePrefix(true, "Item Templates");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading item templates, please wait...");
for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();
ffp.activatePrefix(true, "Item Templates \u00a78($r" + type.getId() + "\u00a78)");
for (String key : config.getKeys(false))
try {
MMOItemTemplate template = new MMOItemTemplate(type, config.getConfigurationSection(key));
template.postLoad();
registerTemplate(template);
// Log
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not load template modifier '" + key + "': " + exception.getMessage());
}
}
} catch (IllegalArgumentException exception) {
ffp.activatePrefix(true, "Item Templates");
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading item templates, please wait...");
for (MMOItemType type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();
ffp.activatePrefix(true, "Item Templates \u00a78($r" + type.getId() + "\u00a78)");
for (String key : config.getKeys(false))
try {
MMOItemTemplate template = new MMOItemTemplate(type, config.getConfigurationSection(key));
template.postLoad();
registerTemplate(template);
// Log
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not load item template '" + key + "': " + exception.getMessage());
}
}
} catch (IllegalArgumentException exception) {
// Print all failures
ffp.sendTo(FriendlyFeedbackCategory.INFORMATION, MMOItems.getConsole());
}
// Log
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not load item template '" + key + "': " + exception.getMessage());
}
}
// Print all failures
ffp.sendTo(FriendlyFeedbackCategory.INFORMATION, MMOItems.getConsole());
}
}

View File

@ -215,7 +215,12 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
public boolean isCompatible(MMOItemType type) {
String lower = type.getId().toLowerCase();
return !compatibleTypes.contains("!" + lower) && (compatibleTypes.contains("all") || compatibleTypes.contains(lower)
|| compatibleTypes.contains(type.getItemSet().getName().toLowerCase()));
|| compatibleTypes.contains(type.getType().name().toLowerCase()));
}
public boolean isCompatible(MMOItemType.Type type) {
String lower = type.name().toLowerCase();
return !compatibleTypes.contains("!" + lower) && (compatibleTypes.contains("all") || compatibleTypes.contains(lower));
}
public boolean hasValidMaterial(ItemStack item) {