mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Merge remote-tracking branch 'origin/1019-bug-config-option-item-revision-keep-data-reroll-doesn-t-work'
# Conflicts: # .gitignore
This commit is contained in:
commit
0da5c6877c
@ -18,21 +18,31 @@ public class ReforgeOptions {
|
||||
private final boolean keepSkins;
|
||||
private final boolean keepUpgrades;
|
||||
private final boolean keepGemStones;
|
||||
private final boolean keepSoulbind;
|
||||
private final boolean keepSoulBind;
|
||||
private final boolean keepExternalSH;
|
||||
private final boolean keepModifications;
|
||||
@Nullable private final Boolean keepTier;
|
||||
@Nullable
|
||||
private final Boolean keepTier;
|
||||
|
||||
private final boolean reroll;
|
||||
private final boolean reRoll;
|
||||
|
||||
// Third Party Stuff
|
||||
private final boolean keepAdvancedEnchantments;
|
||||
|
||||
@NotNull String keepCase = ChatColor.GRAY.toString();
|
||||
public void setKeepCase(@NotNull String kc) { keepCase = kc; }
|
||||
@NotNull public String getKeepCase() { return keepCase; }
|
||||
@NotNull
|
||||
String keepCase = ChatColor.GRAY.toString();
|
||||
|
||||
@NotNull ArrayList<String> blacklistedItems = new ArrayList<>();
|
||||
public void setKeepCase(@NotNull String kc) {
|
||||
keepCase = kc;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKeepCase() {
|
||||
return keepCase;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
ArrayList<String> blacklistedItems = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Apparently, people like to use MMOItems for quests. This
|
||||
@ -41,14 +51,15 @@ public class ReforgeOptions {
|
||||
* @param mmoitemID Item ID. Listen, including MMOItem Type as
|
||||
* well is unnecessary hassle, complicates the
|
||||
* implementation.
|
||||
*
|
||||
* <p>
|
||||
* People who name all their items "1", "2", ...
|
||||
* can learn to not use magic numbers ffs.
|
||||
*
|
||||
* @return If this item should not update with RevID (when passing
|
||||
* these options, of course).
|
||||
*/
|
||||
public boolean isBlacklisted(@NotNull String mmoitemID) { return blacklistedItems.contains(mmoitemID); }
|
||||
public boolean isBlacklisted(@NotNull String mmoitemID) {
|
||||
return blacklistedItems.contains(mmoitemID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apparently, people like to use MMOItems for quests. This
|
||||
@ -57,16 +68,20 @@ public class ReforgeOptions {
|
||||
* @param mmoitemID Item ID. Listen, including MMOItem Type as
|
||||
* well is unnecessary hassle, complicates the
|
||||
* implementation.
|
||||
*
|
||||
* <p>
|
||||
* People who name all their items "1", "2", ...
|
||||
* can learn to not use magic numbers ffs.
|
||||
*/
|
||||
public void addToBlacklist(@NotNull String mmoitemID) { blacklistedItems.add(mmoitemID); }
|
||||
public void addToBlacklist(@NotNull String mmoitemID) {
|
||||
blacklistedItems.add(mmoitemID);
|
||||
}
|
||||
|
||||
/**
|
||||
* No MMOItem-ID restrictions on RevID.
|
||||
*/
|
||||
public void clearBlacklist() { blacklistedItems.clear(); }
|
||||
public void clearBlacklist() {
|
||||
blacklistedItems.clear();
|
||||
}
|
||||
|
||||
public ReforgeOptions(ConfigurationSection config) {
|
||||
keepName = config.getBoolean("display-name");
|
||||
@ -75,11 +90,11 @@ public class ReforgeOptions {
|
||||
keepUpgrades = config.getBoolean("upgrades");
|
||||
keepGemStones = config.getBoolean("gemstones", false) || config.getBoolean("gems", false);
|
||||
keepSkins = config.getBoolean("skins", false);
|
||||
keepSoulbind = config.getBoolean("soulbound");
|
||||
keepSoulBind = config.getBoolean("soulbound");
|
||||
keepCase = config.getString("kept-lore-prefix", ChatColor.GRAY.toString());
|
||||
keepExternalSH = config.getBoolean("external-sh", true);
|
||||
keepModifications = config.getBoolean("modifications");
|
||||
reroll = config.getBoolean("reroll");
|
||||
reRoll = config.getBoolean("reroll");
|
||||
keepAdvancedEnchantments = config.getBoolean("advanced-enchantments");
|
||||
keepTier = config.contains("tier") ? config.getBoolean("tier", true) : null;
|
||||
}
|
||||
@ -90,9 +105,9 @@ public class ReforgeOptions {
|
||||
keepEnchantments = arr(values, 2);
|
||||
keepUpgrades = arr(values, 3);
|
||||
keepGemStones = arr(values, 4);
|
||||
keepSoulbind = arr(values, 5);
|
||||
keepSoulBind = arr(values, 5);
|
||||
keepExternalSH = arr(values, 6);
|
||||
reroll = arr(values, 7);
|
||||
reRoll = arr(values, 7);
|
||||
keepModifications = arr(values, 8);
|
||||
keepAdvancedEnchantments = arr(values, 9);
|
||||
keepSkins = arr(values, 10);
|
||||
@ -100,65 +115,82 @@ public class ReforgeOptions {
|
||||
}
|
||||
|
||||
boolean arr(@NotNull boolean[] booleans, int idx) {
|
||||
|
||||
if (booleans.length > idx) { return booleans[idx]; }
|
||||
|
||||
return false;
|
||||
return booleans.length > idx && booleans[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the display name of the item.
|
||||
*/
|
||||
public boolean shouldReroll() { return reroll; }
|
||||
public boolean shouldReRoll() {
|
||||
return reRoll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the display name of the item.
|
||||
*/
|
||||
public boolean shouldKeepName() { return keepName; }
|
||||
public boolean shouldKeepName() {
|
||||
return keepName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the modifiers of the item.
|
||||
*/
|
||||
public boolean shouldKeepMods() { return keepModifications; }
|
||||
public boolean shouldKeepMods() {
|
||||
return keepModifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps all lore lines that begin with {@link org.bukkit.ChatColor#GRAY}
|
||||
*/
|
||||
public boolean shouldKeepLore() { return keepLore; }
|
||||
public boolean shouldKeepLore() {
|
||||
return keepLore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps skins
|
||||
*/
|
||||
public boolean shouldKeepSkins() { return keepSkins; }
|
||||
public boolean shouldKeepSkins() {
|
||||
return keepSkins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should keep the tier? defaults to {@link MMOItemReforger#keepTiersWhenReroll}
|
||||
*/
|
||||
public boolean shouldKeepTier() { return keepTier == null ? MMOItemReforger.keepTiersWhenReroll : keepTier; }
|
||||
public boolean shouldKeepTier() {
|
||||
return keepTier == null ? MMOItemReforger.keepTiersWhenReroll : keepTier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should this keep the enchantments the player
|
||||
* manually cast onto this item? (Not from gem
|
||||
* stones nor upgrades).
|
||||
*/
|
||||
public boolean shouldKeepEnchantments() { return keepEnchantments; }
|
||||
public boolean shouldKeepEnchantments() {
|
||||
return keepEnchantments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should this keep the enchantments the player
|
||||
* manually cast onto this item? (Not from gem
|
||||
* stones nor upgrades).
|
||||
*/
|
||||
public boolean shouldKeepAdvancedEnchants() { return keepAdvancedEnchantments; }
|
||||
public boolean shouldKeepAdvancedEnchants() {
|
||||
return keepAdvancedEnchantments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep 'extraneous' data registered onto the Stat History
|
||||
*/
|
||||
public boolean shouldKeepExternalSH() { return keepExternalSH; }
|
||||
public boolean shouldKeepExternalSH() {
|
||||
return keepExternalSH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains the upgrade level of the item.
|
||||
*/
|
||||
public boolean shouldKeepUpgrades() { return keepUpgrades; }
|
||||
public boolean shouldKeepUpgrades() {
|
||||
return keepUpgrades;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains all gem stones if there are any, removing
|
||||
@ -166,10 +198,14 @@ public class ReforgeOptions {
|
||||
* <p></p>
|
||||
* Gemstones remember at what upgrade level they were inserted.
|
||||
*/
|
||||
public boolean shouldKeepGemStones() { return keepGemStones; }
|
||||
public boolean shouldKeepGemStones() {
|
||||
return keepGemStones;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains the soulbind if it has any.
|
||||
*/
|
||||
public boolean shouldKeepSoulbind() { return keepSoulbind; }
|
||||
public boolean shouldKeepSoulBind() {
|
||||
return keepSoulBind;
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ public class MMOItemReforger {
|
||||
Validate.isTrue(stack.getItemMeta() != null, "ItemStack has no ItemMeta, cannot be reforged.");
|
||||
meta = stack.getItemMeta();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this reforger to handle all operations regarding RevID
|
||||
* increases on any ItemStack, including: <br>
|
||||
@ -81,6 +82,7 @@ public class MMOItemReforger {
|
||||
Validate.isTrue(stack.getItemMeta() != null, "ItemStack has no ItemMeta, cannot be reforged.");
|
||||
meta = stack.getItemMeta();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this reforger to handle all operations regarding RevID
|
||||
* increases on any ItemStack, including: <br>
|
||||
@ -89,11 +91,9 @@ public class MMOItemReforger {
|
||||
* * Transfer stats from old to fresh <br>
|
||||
* * Build the fresh version <br>
|
||||
*
|
||||
*
|
||||
* @param nbtItem If for any reason you already generated an NBTItem,
|
||||
* you may pass it here to ease the performance of
|
||||
* generating it again from the ItemStack.
|
||||
*
|
||||
* @param stack The ItemStack you want to update, or at least
|
||||
* know if it should update due to RevID increase.
|
||||
*/
|
||||
@ -108,62 +108,97 @@ public class MMOItemReforger {
|
||||
/**
|
||||
* The original ItemStack itself, not even a clone.
|
||||
*/
|
||||
@NotNull final ItemStack stack;
|
||||
@NotNull
|
||||
final ItemStack stack;
|
||||
|
||||
/**
|
||||
* @return The original ItemStack, not even a clone.
|
||||
*/
|
||||
@NotNull public ItemStack getStack() { return stack; }
|
||||
@NotNull
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* The original ItemStack itself, not even a clone.
|
||||
*/
|
||||
@Nullable ItemStack result;
|
||||
@Nullable
|
||||
ItemStack result;
|
||||
|
||||
/**
|
||||
* @return The original ItemStack, not even a clone.
|
||||
*/
|
||||
@Nullable public ItemStack getResult() { return result; }
|
||||
@Nullable
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The original ItemStack itself, not even a clone.
|
||||
*/
|
||||
public void setResult(@Nullable ItemStack item) { result = item; }
|
||||
public void setResult(@Nullable ItemStack item) {
|
||||
result = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* The original NBTItem information.
|
||||
*/
|
||||
@NotNull final NBTItem nbtItem;
|
||||
@NotNull
|
||||
final NBTItem nbtItem;
|
||||
|
||||
/**
|
||||
* @return The original NBTItem information.
|
||||
*/
|
||||
@NotNull public NBTItem getNBTItem() { return nbtItem; }
|
||||
@NotNull
|
||||
public NBTItem getNBTItem() {
|
||||
return nbtItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* The meta of {@link #getStack()} but without
|
||||
* that pesky {@link Nullable} annotation.
|
||||
*/
|
||||
@NotNull final ItemMeta meta;
|
||||
@NotNull
|
||||
final ItemMeta meta;
|
||||
|
||||
/**
|
||||
* @return The meta of {@link #getStack()} but without that
|
||||
* pesky {@link Nullable} annotation.
|
||||
*/
|
||||
@NotNull public ItemMeta getMeta() { return meta; }
|
||||
@NotNull
|
||||
public ItemMeta getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* The player to reroll modifiers based on their level
|
||||
*/
|
||||
@Nullable RPGPlayer player;
|
||||
@Nullable
|
||||
RPGPlayer player;
|
||||
|
||||
/**
|
||||
* @return player The player to reroll modifiers based on their level
|
||||
*/
|
||||
@Nullable public RPGPlayer getPlayer() { return player; }
|
||||
@Nullable
|
||||
public RPGPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player The player to reroll modifiers based on their level
|
||||
*/
|
||||
public void setPlayer(@Nullable RPGPlayer player) { this.player = player;}
|
||||
public void setPlayer(@Nullable RPGPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player The player to reroll modifiers based on their level
|
||||
*/
|
||||
public void setPlayer(@Nullable Player player) {
|
||||
if (player == null) { this.player = null; return; }
|
||||
if (player == null) {
|
||||
this.player = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get data
|
||||
this.player = PlayerData.get(player).getRPG();
|
||||
@ -171,53 +206,73 @@ public class MMOItemReforger {
|
||||
|
||||
/**
|
||||
* If the item should update, this wont be null anymore.
|
||||
*
|
||||
* <p>
|
||||
* Guaranteed not-null when updating.
|
||||
*/
|
||||
@Nullable LiveMMOItem oldMMOItem;
|
||||
@Nullable
|
||||
LiveMMOItem oldMMOItem;
|
||||
|
||||
/**
|
||||
* @return The MMOItem being updated. For safety, it should be cloned,
|
||||
* in case any plugin decides to make changes in it... though
|
||||
* this should be entirely for <b>reading purposes only</b>.
|
||||
*/
|
||||
@SuppressWarnings({"NullableProblems", "ConstantConditions"})
|
||||
@NotNull public LiveMMOItem getOldMMOItem() { return oldMMOItem; }
|
||||
@NotNull
|
||||
public LiveMMOItem getOldMMOItem() {
|
||||
return oldMMOItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* The loaded template of the MMOItem in question.
|
||||
*
|
||||
* <p>
|
||||
* Guaranteed not-null when updating.
|
||||
*/
|
||||
@Nullable private MMOItemTemplate template;
|
||||
@Nullable
|
||||
private MMOItemTemplate template;
|
||||
|
||||
/**
|
||||
* @return The loaded template of the MMOItem in question.
|
||||
*/
|
||||
@SuppressWarnings({"NullableProblems", "ConstantConditions"})
|
||||
@NotNull public MMOItemTemplate getTemplate() { return template; }
|
||||
@NotNull
|
||||
public MMOItemTemplate getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Updated version of the MMOItem, with
|
||||
* its revised stats.
|
||||
*
|
||||
* <p>
|
||||
* Guaranteed not-null when updating.
|
||||
*/
|
||||
@Nullable private MMOItem freshMMOItem;
|
||||
@Nullable
|
||||
private MMOItem freshMMOItem;
|
||||
|
||||
/**
|
||||
* @return The Updated version of the MMOItem, with
|
||||
* its revised stats.
|
||||
*/
|
||||
@SuppressWarnings({"NullableProblems", "ConstantConditions"})
|
||||
@NotNull public MMOItem getFreshMMOItem() { return freshMMOItem; }
|
||||
@NotNull
|
||||
public MMOItem getFreshMMOItem() {
|
||||
return freshMMOItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mmo The Updated version of the MMOItem, with
|
||||
* the revised stats.
|
||||
*/
|
||||
public void setFreshMMOItem(@NotNull MMOItem mmo) { freshMMOItem = mmo; }
|
||||
public void setFreshMMOItem(@NotNull MMOItem mmo) {
|
||||
freshMMOItem = mmo;
|
||||
}
|
||||
|
||||
/**
|
||||
* If it is possible to update this ItemStack via this class.
|
||||
*/
|
||||
@Nullable Boolean canUpdate;
|
||||
@Nullable
|
||||
Boolean canUpdate;
|
||||
|
||||
/**
|
||||
* The value is stored so the operations don't have to run again on
|
||||
* subsequent calls, which also means you have to make a new
|
||||
@ -230,14 +285,14 @@ public class MMOItemReforger {
|
||||
//RFG//MMOItems.log("§8Reforge §4CAN §7Can reforge? " + SilentNumbers.getItemName(getStack()));
|
||||
|
||||
// Already went through these operations ~
|
||||
if (canUpdate != null) { return canUpdate; }
|
||||
if (canUpdate != null) return canUpdate;
|
||||
|
||||
// Does it not have type?
|
||||
if (!getNBTItem().hasType()) { return canUpdate = false; }
|
||||
if (!getNBTItem().hasType()) return canUpdate = false;
|
||||
|
||||
// Ay get template
|
||||
template = MMOItems.plugin.getTemplates().getTemplate(getNBTItem());
|
||||
if (template == null) { return canUpdate = false; }
|
||||
if (template == null) return canUpdate = false;
|
||||
|
||||
// Success
|
||||
return canUpdate = true;
|
||||
@ -246,18 +301,19 @@ public class MMOItemReforger {
|
||||
/**
|
||||
* If it is recommended to update because the RevID value in the ItemStack is outdated.
|
||||
*/
|
||||
@Nullable Boolean shouldUpdate;
|
||||
@Nullable
|
||||
Boolean shouldUpdate;
|
||||
|
||||
/**
|
||||
* The value is stored so the operations don't have to run again on
|
||||
* subsequent calls, which also means you have to make a new
|
||||
* MMOItemReforger if you make changes, because it wont be read again.
|
||||
*
|
||||
* @param reason Why the item should be updated?
|
||||
*
|
||||
* <p>
|
||||
* Used to disable updating items in the config,
|
||||
* only during specific 'reasons' like the player
|
||||
* joining or picking the item up.
|
||||
*
|
||||
* @return If this is an MMOItem with an outdated RevID value.
|
||||
*/
|
||||
@SuppressWarnings("NestedAssignment")
|
||||
@ -265,25 +321,31 @@ public class MMOItemReforger {
|
||||
//RFG//MMOItems.log("§8Reforge §4SHD §7Should reforge? " + SilentNumbers.getItemName(getStack()));
|
||||
|
||||
// Already went through these operations ~
|
||||
if (shouldUpdate != null) { return shouldUpdate; }
|
||||
if (shouldUpdate != null)
|
||||
return shouldUpdate;
|
||||
|
||||
// Fist of all, can it update?
|
||||
if (!canReforge()) { return shouldUpdate = false; }
|
||||
if (!canReforge())
|
||||
return shouldUpdate = false;
|
||||
|
||||
// Its not GooP Converter's VANILLA is it?
|
||||
if ("VANILLA".equals(nbtItem.getString("MMOITEMS_ITEM_ID"))) { return false; }
|
||||
if ("VANILLA".equals(nbtItem.getString("MMOITEMS_ITEM_ID")))
|
||||
return false;
|
||||
|
||||
// Disabled in config?
|
||||
if (reason != null && MMOItems.plugin.getConfig().getBoolean("item-revision.disable-on." + reason)) { return shouldUpdate = false; }
|
||||
if (reason != null && MMOItems.plugin.getConfig().getBoolean("item-revision.disable-on." + reason))
|
||||
return shouldUpdate = false;
|
||||
|
||||
// Greater RevID in template? Go ahead, update!
|
||||
int templateRevision = getTemplate().getRevisionId();
|
||||
int mmoitemRevision = (getNBTItem().hasTag(ItemStats.REVISION_ID.getNBTPath()) ? getNBTItem().getInteger(ItemStats.REVISION_ID.getNBTPath()) : 1);
|
||||
if (templateRevision > mmoitemRevision) { return shouldUpdate = true; }
|
||||
if (templateRevision > mmoitemRevision)
|
||||
return shouldUpdate = true;
|
||||
|
||||
// What about in the internal revision?
|
||||
int internalRevision = (nbtItem.hasTag(ItemStats.INTERNAL_REVISION_ID.getNBTPath()) ? nbtItem.getInteger(ItemStats.INTERNAL_REVISION_ID.getNBTPath()) : 1);
|
||||
if (MMOItems.INTERNAL_REVISION_ID > internalRevision) { return shouldUpdate = true; }
|
||||
if (MMOItems.INTERNAL_REVISION_ID > internalRevision)
|
||||
return shouldUpdate = true;
|
||||
|
||||
// Actually, no need
|
||||
return shouldUpdate = false;
|
||||
@ -300,7 +362,9 @@ public class MMOItemReforger {
|
||||
* event runs, the gemstone updater stores the gem items here
|
||||
* so that the player gets them back at the completion of this.
|
||||
*/
|
||||
@NotNull final ArrayList<ItemStack> reforgingOutput = new ArrayList<>();
|
||||
@NotNull
|
||||
final ArrayList<ItemStack> reforgingOutput = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Sometimes, reforging will take away things from the item that
|
||||
* we don't want to be destroyed forever, these items will drop
|
||||
@ -315,14 +379,12 @@ public class MMOItemReforger {
|
||||
* @param item Add an item to this process.
|
||||
*/
|
||||
public void addReforgingOutput(@Nullable ItemStack item) {
|
||||
|
||||
// Ew
|
||||
if (SilentNumbers.isAir(item)) { return; }
|
||||
if (!item.getType().isItem()) { return; }
|
||||
|
||||
if (!SilentNumbers.isAir(item) && item.getType().isItem())
|
||||
// Add that
|
||||
reforgingOutput.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes, reforging will take away things from the item that
|
||||
* we don't want to be destroyed forever, these items will drop
|
||||
@ -334,7 +396,10 @@ public class MMOItemReforger {
|
||||
* event runs, the gemstone updater stores the gem items here
|
||||
* so that the player gets them back at the completion of this.
|
||||
*/
|
||||
public void clearReforgingOutput() { reforgingOutput.clear(); }
|
||||
public void clearReforgingOutput() {
|
||||
reforgingOutput.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes, reforging will take away things from the item that
|
||||
* we don't want to be destroyed forever, these items will drop
|
||||
@ -348,18 +413,24 @@ public class MMOItemReforger {
|
||||
*
|
||||
* @return All the items that will be dropped. The list itself.
|
||||
*/
|
||||
@NotNull public ArrayList<ItemStack> getReforgingOutput() { return reforgingOutput; }
|
||||
@NotNull
|
||||
public ArrayList<ItemStack> getReforgingOutput() {
|
||||
return reforgingOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* The item level modifying the values of RandomStatData
|
||||
* upon creating a new MMOItem from the template.
|
||||
*/
|
||||
int generationItemLevel;
|
||||
|
||||
/**
|
||||
* @return The item level modifying the values of RandomStatData
|
||||
* upon creating a new MMOItem from the template.
|
||||
*/
|
||||
public int getGenerationItemLevel() { return generationItemLevel; }
|
||||
public int getGenerationItemLevel() {
|
||||
return generationItemLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>Make sure to check {@link #canReforge()} because an
|
||||
@ -371,20 +442,21 @@ public class MMOItemReforger {
|
||||
* generate a brand-new one.
|
||||
*
|
||||
* @param options Additional options to pass onto the modules.
|
||||
*
|
||||
* @return If reforged successfully. Basically <code>true</code>, unless cancelled.
|
||||
*/
|
||||
public boolean reforge(@NotNull ReforgeOptions options) {
|
||||
//RFG//MMOItems.log("§8Reforge §4RFG§7 Reforging " + SilentNumbers.getItemName(getStack()));
|
||||
|
||||
// Throw fail
|
||||
if (!canReforge()) { throw new IllegalArgumentException("Unreforgable Item " + SilentNumbers.getItemName(getStack())); }
|
||||
if (!canReforge())
|
||||
throw new IllegalArgumentException("Unreforgable Item " + SilentNumbers.getItemName(getStack()));
|
||||
|
||||
// Prepare everything properly
|
||||
oldMMOItem = new LiveMMOItem(getNBTItem());
|
||||
|
||||
// Not blacklisted right!?
|
||||
if (options.isBlacklisted(getOldMMOItem().getId())) { return false; }
|
||||
if (options.isBlacklisted(getOldMMOItem().getId()))
|
||||
return false;
|
||||
|
||||
/*
|
||||
* THis chunk will determine the level the item was, and
|
||||
@ -412,8 +484,6 @@ public class MMOItemReforger {
|
||||
: iLevel;
|
||||
|
||||
|
||||
|
||||
|
||||
// Identify tier.
|
||||
ItemTier tier =
|
||||
|
||||
@ -436,19 +506,18 @@ public class MMOItemReforger {
|
||||
Bukkit.getPluginManager().callEvent(mmoREV);
|
||||
|
||||
// Cancelled? it ends there
|
||||
if (mmoREV.isCancelled()) {
|
||||
if (mmoREV.isCancelled())
|
||||
//RFG//MMOItems.log("§8Reforge §4RFG§c Event Cancelled");
|
||||
return false; }
|
||||
return false;
|
||||
//RFG//MMOItems.log("§8Reforge §2RFG§7 Running Reforge Finish");
|
||||
|
||||
/*
|
||||
* Properly recalculate all based on histories
|
||||
*/
|
||||
for (StatHistory hist : getFreshMMOItem().getStatHistories()) {
|
||||
|
||||
for (StatHistory hist : getFreshMMOItem().getStatHistories())
|
||||
// Recalculate that shit
|
||||
getFreshMMOItem().setData(hist.getItemStat(), hist.recalculate(getFreshMMOItem().getUpgradeLevel()));
|
||||
}
|
||||
|
||||
if (getFreshMMOItem().hasUpgradeTemplate()) {
|
||||
|
||||
for (ItemStat stat : getFreshMMOItem().getUpgradeTemplate().getKeys()) {
|
||||
@ -493,47 +562,64 @@ public class MMOItemReforger {
|
||||
//region Deprecated API
|
||||
@Deprecated
|
||||
public void update(@Nullable Player p, @NotNull ReforgeOptions options) {
|
||||
if (p != null) { setPlayer(p); }
|
||||
if (p != null)
|
||||
setPlayer(p);
|
||||
reforge(options);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void update(@Nullable RPGPlayer player, @NotNull ReforgeOptions options) {
|
||||
if (player != null) { setPlayer(player); }
|
||||
if (player != null)
|
||||
setPlayer(player);
|
||||
reforge(options);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
void regenerate(@Nullable RPGPlayer p) {
|
||||
if (p != null) { setPlayer(p); }
|
||||
if (p != null)
|
||||
setPlayer(p);
|
||||
reforge(new ReforgeOptions(false, false, false, false, false, false, false, true));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
int regenerate(@Nullable RPGPlayer player, @NotNull MMOItemTemplate template) {
|
||||
if (player != null) { setPlayer(player); }
|
||||
if (player != null)
|
||||
setPlayer(player);
|
||||
canUpdate = true; //If the template exists, it EXISTS!
|
||||
this.template = template;
|
||||
reforge(new ReforgeOptions(false, false, false, false, false, false, false, true));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void reforge(@Nullable Player p, @NotNull ReforgeOptions options) {
|
||||
if (p != null) { setPlayer(p); }
|
||||
if (p != null)
|
||||
setPlayer(p);
|
||||
reforge(options);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void reforge(@Nullable RPGPlayer player, @NotNull ReforgeOptions options) {
|
||||
if (player != null) { setPlayer(player); }
|
||||
if (player != null)
|
||||
setPlayer(player);
|
||||
reforge(options);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ItemStack toStack() {
|
||||
return getResult();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean hasChanges() {
|
||||
return getResult() != null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@NotNull public ArrayList<MMOItem> getDestroyedGems() { return new ArrayList<>(); }
|
||||
@NotNull
|
||||
public ArrayList<MMOItem> getDestroyedGems() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
//endregion
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class RevisionInventory extends EditionInventory {
|
||||
break;
|
||||
case 30:
|
||||
which = soulbind.clone();
|
||||
enable = MMOItems.plugin.getLanguage().revisionOptions.shouldKeepSoulbind();
|
||||
enable = MMOItems.plugin.getLanguage().revisionOptions.shouldKeepSoulBind();
|
||||
break;
|
||||
case 33:
|
||||
id = getEditedSection().getInt(ItemStats.REVISION_ID.getPath(), 1);
|
||||
|
@ -21,6 +21,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemListener implements Listener {
|
||||
|
||||
// Aye
|
||||
@ -96,34 +98,32 @@ public class ItemListener implements Listener {
|
||||
if (newItem != null) player.getEquipment().setItemInOffHand(newItem);
|
||||
}
|
||||
|
||||
@Nullable private ItemStack modifyItem(@Nullable ItemStack stack, @NotNull Player player, @NotNull String reason) {
|
||||
@Nullable
|
||||
private ItemStack modifyItem(@Nullable ItemStack stack, @NotNull Player player, @NotNull String reason) {
|
||||
//RFG//MMOItems.log("§8Reforge §cMOD§7 Modifying " + SilentNumbers.getItemName(stack) + " §7due to§3 " + reason);
|
||||
|
||||
// Sleep on metaless stacks
|
||||
if (stack == null) { return null; }
|
||||
if (!stack.hasItemMeta()) { return null; }
|
||||
if (stack == null || !stack.hasItemMeta())
|
||||
return null;
|
||||
|
||||
// Create a reforger to look at it
|
||||
MMOItemReforger mod = new MMOItemReforger(stack);
|
||||
|
||||
// Shouldn't update? I sleep
|
||||
if (!mod.shouldReforge(reason)) { return null; }
|
||||
if (!mod.shouldReforge(reason)) return null;
|
||||
|
||||
// All right update then
|
||||
mod.setPlayer(player);
|
||||
if (!mod.reforge(MMOItems.plugin.getLanguage().revisionOptions)) {
|
||||
|
||||
return null; }
|
||||
if (!mod.reforge(MMOItems.plugin.getLanguage().revisionOptions))
|
||||
return null;
|
||||
|
||||
// Drop all those items
|
||||
for (ItemStack drop : player.getInventory().addItem(
|
||||
mod.getReforgingOutput().toArray(new ItemStack[0])).values()) {
|
||||
|
||||
// Not air right
|
||||
if (SilentNumbers.isAir(drop)) { continue; }
|
||||
|
||||
// Drop to the world
|
||||
player.getWorld().dropItem(player.getLocation(), drop); }
|
||||
player.getInventory()
|
||||
.addItem(mod.getReforgingOutput().toArray(new ItemStack[0]))
|
||||
.values()
|
||||
.stream()
|
||||
.filter(drop -> !SilentNumbers.isAir(drop))
|
||||
.forEach(drop -> player.getWorld().dropItem(player.getLocation(), drop));
|
||||
|
||||
// That's it
|
||||
return mod.getResult();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.Indyuce.mmoitems.listener.reforging;
|
||||
|
||||
import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.event.MMOItemReforgeEvent;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.random.UpdatableRandomStatData;
|
||||
@ -24,40 +23,35 @@ public class RFGKeepRNG implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onReforge(MMOItemReforgeEvent event) {
|
||||
|
||||
// Rerolling stats? Nevermind
|
||||
if (event.getOptions().shouldReroll()) {
|
||||
if (event.getOptions().shouldReRoll()) {
|
||||
event.setCancelled(true);
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping new item (Complete RNG Reroll)");
|
||||
return; }
|
||||
return;
|
||||
}
|
||||
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping old RNG Rolls");
|
||||
|
||||
/*
|
||||
* Proceed to go through all stats
|
||||
*/
|
||||
for (ItemStat stat : event.getOldMMOItem().getStats()) {
|
||||
|
||||
event.getOldMMOItem()
|
||||
.getStats()
|
||||
.stream()
|
||||
// Skip if it cant merge
|
||||
if (!(stat.getClearStatData() instanceof Mergeable)) {
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is \u00a7cnot\u00a77 even mergeable");
|
||||
continue; }
|
||||
|
||||
.filter(stat -> stat.getClearStatData() instanceof Mergeable)
|
||||
/*
|
||||
* These stats are exempt from this 'keeping' operation.
|
||||
* Probably because there is a ReforgeOption specifically
|
||||
* designed for them that keeps them separately
|
||||
*/
|
||||
if (ItemStats.LORE.equals(stat) ||
|
||||
.filter(stat -> !(ItemStats.LORE.equals(stat) ||
|
||||
ItemStats.NAME.equals(stat) ||
|
||||
ItemStats.UPGRADE.equals(stat) ||
|
||||
ItemStats.ENCHANTS.equals(stat) ||
|
||||
ItemStats.SOULBOUND.equals(stat) ||
|
||||
ItemStats.GEM_SOCKETS.equals(stat)) {
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is \u00a7cnot\u00a77 processed here");
|
||||
continue; }
|
||||
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 being \u00a7bprocessed\u00a77...");
|
||||
|
||||
ItemStats.GEM_SOCKETS.equals(stat)))
|
||||
.forEach(stat -> {
|
||||
// Stat history in the old item
|
||||
StatHistory hist = StatHistory.from(event.getOldMMOItem(), stat);
|
||||
|
||||
@ -69,22 +63,23 @@ public class RFGKeepRNG implements Listener {
|
||||
* preserve its rolls, even if it should be
|
||||
* preserving the rolls.
|
||||
*/
|
||||
StatData keptData = shouldRerollRegardless(stat, source, hist.getOriginalData(), event.getReforger().getGenerationItemLevel());
|
||||
StatData keptData = shouldReRollRegardless(stat, source, hist.getOriginalData(), event.getReforger().getGenerationItemLevel());
|
||||
|
||||
// Old roll is ridiculously low probability under the new parameters. Forget.
|
||||
if (keptData == null) { continue; }
|
||||
if (keptData == null)
|
||||
return;
|
||||
|
||||
// Fetch History from the new item
|
||||
StatHistory clear = StatHistory.from(event.getNewMMOItem(), stat);
|
||||
|
||||
// Replace original data of the new one with the roll from the old one
|
||||
clear.setOriginalData(keptData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The item is supposedly being updated, but that doesnt mean all its stats must remain the same.
|
||||
*
|
||||
* <p>
|
||||
* In contrast to reforging, in which it is expected its RNG to be rerolled, updating should not do it
|
||||
* except in the most dire scenarios:
|
||||
* <br><br>
|
||||
@ -95,15 +90,12 @@ public class RFGKeepRNG implements Listener {
|
||||
* <br><br>
|
||||
* + There is a new stat: The original data is null so this method cannot be called, will roll the
|
||||
* new stat to actually add it for the first time.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Nullable StatData shouldRerollRegardless(@NotNull ItemStat stat, @NotNull RandomStatData source, @NotNull StatData original, int determinedItemLevel) {
|
||||
|
||||
@Nullable StatData shouldReRollRegardless(@NotNull ItemStat stat, @NotNull RandomStatData source, @NotNull StatData original, int determinedItemLevel) {
|
||||
// Not Mergeable, impossible to keep
|
||||
if (!(source instanceof UpdatableRandomStatData)) {
|
||||
if (!(source instanceof UpdatableRandomStatData))
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is not updatable!");
|
||||
return null; }
|
||||
return null;
|
||||
|
||||
// Just pass on
|
||||
return ((UpdatableRandomStatData) source).reroll(stat, original, determinedItemLevel);
|
||||
|
@ -1,9 +1,7 @@
|
||||
package net.Indyuce.mmoitems.listener.reforging;
|
||||
|
||||
import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.event.MMOItemReforgeEvent;
|
||||
import net.Indyuce.mmoitems.api.util.MMOItemReforger;
|
||||
import net.Indyuce.mmoitems.stat.data.SoulboundData;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -36,7 +34,7 @@ public class RFGKeepSoulbound implements Listener {
|
||||
// event.getNewMMOItem().setData(ItemStats.SOULBOUND, new SoulboundData(event.getPlayer().getUniqueId(), event.getPlayer().getName(), MMOItemReforger.autoSoulbindLevel));
|
||||
// }
|
||||
|
||||
} else if (event.getOptions().shouldKeepSoulbind()) {
|
||||
} else if (event.getOptions().shouldKeepSoulBind()) {
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping Soulbound");
|
||||
|
||||
// Keep it
|
||||
|
Loading…
Reference in New Issue
Block a user