Merge remote-tracking branch 'origin/1019-bug-config-option-item-revision-keep-data-reroll-doesn-t-work'

# Conflicts:
#	.gitignore
This commit is contained in:
Indyuce 2022-11-03 17:56:26 +01:00
commit 0da5c6877c
6 changed files with 834 additions and 722 deletions

View File

@ -9,167 +9,203 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
public class ReforgeOptions { public class ReforgeOptions {
public static boolean dropRestoredGems; public static boolean dropRestoredGems;
// MMOItems stuff // MMOItems stuff
private final boolean keepName; private final boolean keepName;
private final boolean keepLore; private final boolean keepLore;
private final boolean keepEnchantments; private final boolean keepEnchantments;
private final boolean keepSkins; private final boolean keepSkins;
private final boolean keepUpgrades; private final boolean keepUpgrades;
private final boolean keepGemStones; private final boolean keepGemStones;
private final boolean keepSoulbind; private final boolean keepSoulBind;
private final boolean keepExternalSH; private final boolean keepExternalSH;
private final boolean keepModifications; 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 // Third Party Stuff
private final boolean keepAdvancedEnchantments; private final boolean keepAdvancedEnchantments;
@NotNull String keepCase = ChatColor.GRAY.toString(); @NotNull
public void setKeepCase(@NotNull String kc) { keepCase = kc; } String keepCase = ChatColor.GRAY.toString();
@NotNull public String getKeepCase() { return keepCase; }
@NotNull ArrayList<String> blacklistedItems = new ArrayList<>(); public void setKeepCase(@NotNull String kc) {
keepCase = kc;
}
/** @NotNull
* Apparently, people like to use MMOItems for quests. This public String getKeepCase() {
* will make items NEVER update with RevID return keepCase;
* }
* @param mmoitemID Item ID. Listen, including MMOItem Type as
* well is unnecessary hassle, complicates the
* implementation.
*
* 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); }
/** @NotNull
* Apparently, people like to use MMOItems for quests. This ArrayList<String> blacklistedItems = new ArrayList<>();
* will make items NEVER update with RevID
*
* @param mmoitemID Item ID. Listen, including MMOItem Type as
* well is unnecessary hassle, complicates the
* implementation.
*
* 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); }
/** /**
* No MMOItem-ID restrictions on RevID. * Apparently, people like to use MMOItems for quests. This
*/ * will make items NEVER update with RevID
public void clearBlacklist() { blacklistedItems.clear(); } *
* @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 ReforgeOptions(ConfigurationSection config) { /**
keepName = config.getBoolean("display-name"); * Apparently, people like to use MMOItems for quests. This
keepLore = config.getBoolean("lore"); * will make items NEVER update with RevID
keepEnchantments = config.getBoolean("enchantments"); *
keepUpgrades = config.getBoolean("upgrades"); * @param mmoitemID Item ID. Listen, including MMOItem Type as
keepGemStones = config.getBoolean("gemstones", false) || config.getBoolean("gems", false); * well is unnecessary hassle, complicates the
keepSkins = config.getBoolean("skins", false); * implementation.
keepSoulbind = config.getBoolean("soulbound"); * <p>
keepCase = config.getString("kept-lore-prefix", ChatColor.GRAY.toString()); * People who name all their items "1", "2", ...
keepExternalSH = config.getBoolean("external-sh", true); * can learn to not use magic numbers ffs.
keepModifications = config.getBoolean("modifications"); */
reroll = config.getBoolean("reroll"); public void addToBlacklist(@NotNull String mmoitemID) {
keepAdvancedEnchantments = config.getBoolean("advanced-enchantments"); blacklistedItems.add(mmoitemID);
keepTier = config.contains("tier") ? config.getBoolean("tier", true) : null; }
}
public ReforgeOptions(boolean... values) { /**
keepName = arr(values, 0); * No MMOItem-ID restrictions on RevID.
keepLore = arr(values, 1); */
keepEnchantments = arr(values, 2); public void clearBlacklist() {
keepUpgrades = arr(values, 3); blacklistedItems.clear();
keepGemStones = arr(values, 4); }
keepSoulbind = arr(values, 5);
keepExternalSH = arr(values, 6);
reroll = arr(values, 7);
keepModifications = arr(values, 8);
keepAdvancedEnchantments = arr(values, 9);
keepSkins = arr(values, 10);
keepTier = arr(values, 11);
}
boolean arr(@NotNull boolean[] booleans, int idx) { public ReforgeOptions(ConfigurationSection config) {
keepName = config.getBoolean("display-name");
keepLore = config.getBoolean("lore");
keepEnchantments = config.getBoolean("enchantments");
keepUpgrades = config.getBoolean("upgrades");
keepGemStones = config.getBoolean("gemstones", false) || config.getBoolean("gems", false);
keepSkins = config.getBoolean("skins", false);
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");
keepAdvancedEnchantments = config.getBoolean("advanced-enchantments");
keepTier = config.contains("tier") ? config.getBoolean("tier", true) : null;
}
if (booleans.length > idx) { return booleans[idx]; } public ReforgeOptions(boolean... values) {
keepName = arr(values, 0);
keepLore = arr(values, 1);
keepEnchantments = arr(values, 2);
keepUpgrades = arr(values, 3);
keepGemStones = arr(values, 4);
keepSoulBind = arr(values, 5);
keepExternalSH = arr(values, 6);
reRoll = arr(values, 7);
keepModifications = arr(values, 8);
keepAdvancedEnchantments = arr(values, 9);
keepSkins = arr(values, 10);
keepTier = arr(values, 11);
}
return false; boolean arr(@NotNull boolean[] booleans, int idx) {
} return booleans.length > idx && booleans[idx];
}
/** /**
* Keeps the display name of the item. * Keeps the display name of the item.
*/ */
public boolean shouldReroll() { return reroll; } public boolean shouldReRoll() {
return reRoll;
}
/** /**
* Keeps the display name of the item. * Keeps the display name of the item.
*/ */
public boolean shouldKeepName() { return keepName; } public boolean shouldKeepName() {
return keepName;
}
/** /**
* Keeps the modifiers of the item. * 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} * Keeps all lore lines that begin with {@link org.bukkit.ChatColor#GRAY}
*/ */
public boolean shouldKeepLore() { return keepLore; } public boolean shouldKeepLore() {
return keepLore;
}
/** /**
* Keeps skins * Keeps skins
*/ */
public boolean shouldKeepSkins() { return keepSkins; } public boolean shouldKeepSkins() {
return keepSkins;
}
/** /**
* Should keep the tier? defaults to {@link MMOItemReforger#keepTiersWhenReroll} * 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 * Should this keep the enchantments the player
* manually cast onto this item? (Not from gem * manually cast onto this item? (Not from gem
* stones nor upgrades). * stones nor upgrades).
*/ */
public boolean shouldKeepEnchantments() { return keepEnchantments; } public boolean shouldKeepEnchantments() {
return keepEnchantments;
}
/** /**
* Should this keep the enchantments the player * Should this keep the enchantments the player
* manually cast onto this item? (Not from gem * manually cast onto this item? (Not from gem
* stones nor upgrades). * stones nor upgrades).
*/ */
public boolean shouldKeepAdvancedEnchants() { return keepAdvancedEnchantments; } public boolean shouldKeepAdvancedEnchants() {
return keepAdvancedEnchantments;
}
/** /**
* Keep 'extraneous' data registered onto the Stat History * 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. * 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 * Retains all gem stones if there are any, removing
* one gem socket for every gemstone kept. * one gem socket for every gemstone kept.
* <p></p> * <p></p>
* Gemstones remember at what upgrade level they were inserted. * 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. * Retains the soulbind if it has any.
*/ */
public boolean shouldKeepSoulbind() { return keepSoulbind; } public boolean shouldKeepSoulBind() {
return keepSoulBind;
}
} }

View File

@ -122,7 +122,7 @@ public class RevisionInventory extends EditionInventory {
break; break;
case 30: case 30:
which = soulbind.clone(); which = soulbind.clone();
enable = MMOItems.plugin.getLanguage().revisionOptions.shouldKeepSoulbind(); enable = MMOItems.plugin.getLanguage().revisionOptions.shouldKeepSoulBind();
break; break;
case 33: case 33:
id = getEditedSection().getInt(ItemStats.REVISION_ID.getPath(), 1); id = getEditedSection().getInt(ItemStats.REVISION_ID.getPath(), 1);

View File

@ -21,111 +21,111 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class ItemListener implements Listener { public class ItemListener implements Listener {
// Aye // Aye
public ItemListener() { public ItemListener() {
//RFG//MMOItems.log(" §b>§a>§e> §7Registering Listeners"); //RFG//MMOItems.log(" §b>§a>§e> §7Registering Listeners");
// Register Reforger Listeners // Register Reforger Listeners
Bukkit.getPluginManager().registerEvents(new RFGKeepName(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepName(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFGKeepLore(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepLore(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFGKeepEnchantments(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepEnchantments(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFGKeepExternalSH(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepExternalSH(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFGKeepGems(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepGems(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFGKeepModifications(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepModifications(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFGKeepSoulbound(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepSoulbound(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFGKeepUpgrades(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepUpgrades(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFGKeepRNG(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepRNG(), MMOItems.plugin);
// Amount ones // Amount ones
Bukkit.getPluginManager().registerEvents(new RFGKeepDurability(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFGKeepDurability(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFFKeepAmount(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFFKeepAmount(), MMOItems.plugin);
Bukkit.getPluginManager().registerEvents(new RFFKeepSkins(), MMOItems.plugin); Bukkit.getPluginManager().registerEvents(new RFFKeepSkins(), MMOItems.plugin);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
private void itemPickup(EntityPickupItemEvent e) { private void itemPickup(EntityPickupItemEvent e) {
if (!e.getEntity().getType().equals(EntityType.PLAYER)) return; if (!e.getEntity().getType().equals(EntityType.PLAYER)) return;
ItemStack newItem = modifyItem(e.getItem().getItemStack(), (Player) e.getEntity(), "pickup"); ItemStack newItem = modifyItem(e.getItem().getItemStack(), (Player) e.getEntity(), "pickup");
if (newItem != null) e.getItem().setItemStack(newItem); if (newItem != null) e.getItem().setItemStack(newItem);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
private void itemCraft(CraftItemEvent e) { private void itemCraft(CraftItemEvent e) {
if(!(e.getWhoClicked() instanceof Player)) return; if (!(e.getWhoClicked() instanceof Player)) return;
ItemStack newItem = modifyItem(e.getCurrentItem(), (Player) e.getWhoClicked(), "craft"); ItemStack newItem = modifyItem(e.getCurrentItem(), (Player) e.getWhoClicked(), "craft");
if (newItem != null) e.setCurrentItem(newItem); if (newItem != null) e.setCurrentItem(newItem);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
private void inventoryMove(InventoryClickEvent e) { private void inventoryMove(InventoryClickEvent e) {
if (e.getInventory().getType() != InventoryType.CRAFTING || !(e.getWhoClicked() instanceof Player)) return; if (e.getInventory().getType() != InventoryType.CRAFTING || !(e.getWhoClicked() instanceof Player)) return;
ItemStack newItem = modifyItem(e.getCurrentItem(), (Player) e.getWhoClicked(), "click"); ItemStack newItem = modifyItem(e.getCurrentItem(), (Player) e.getWhoClicked(), "click");
if (newItem != null) e.setCurrentItem(newItem); if (newItem != null) e.setCurrentItem(newItem);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
private void dropItem(PlayerDropItemEvent event) { private void dropItem(PlayerDropItemEvent event) {
NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack()); NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack());
if (!MMOItems.plugin.getConfig().getBoolean("soulbound.can-drop") && nbt.hasTag("MMOITEMS_SOULBOUND")) if (!MMOItems.plugin.getConfig().getBoolean("soulbound.can-drop") && nbt.hasTag("MMOITEMS_SOULBOUND"))
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void playerJoin(PlayerJoinEvent event) { public void playerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack newItem = modifyItem(player.getEquipment().getHelmet(), player, "join"); ItemStack newItem = modifyItem(player.getEquipment().getHelmet(), player, "join");
if(newItem != null) player.getEquipment().setHelmet(newItem); if (newItem != null) player.getEquipment().setHelmet(newItem);
newItem = modifyItem(player.getEquipment().getChestplate(), player, "join"); newItem = modifyItem(player.getEquipment().getChestplate(), player, "join");
if(newItem != null) player.getEquipment().setChestplate(newItem); if (newItem != null) player.getEquipment().setChestplate(newItem);
newItem = modifyItem(player.getEquipment().getLeggings(), player, "join"); newItem = modifyItem(player.getEquipment().getLeggings(), player, "join");
if(newItem != null) player.getEquipment().setLeggings(newItem); if (newItem != null) player.getEquipment().setLeggings(newItem);
newItem = modifyItem(player.getEquipment().getBoots(), player, "join"); newItem = modifyItem(player.getEquipment().getBoots(), player, "join");
if(newItem != null) player.getEquipment().setBoots(newItem); if (newItem != null) player.getEquipment().setBoots(newItem);
for (int j = 0; j < 9; j++) { for (int j = 0; j < 9; j++) {
newItem = modifyItem(player.getInventory().getItem(j), player, "join"); newItem = modifyItem(player.getInventory().getItem(j), player, "join");
if (newItem != null) player.getInventory().setItem(j, newItem); if (newItem != null) player.getInventory().setItem(j, newItem);
} }
newItem = modifyItem(player.getEquipment().getItemInOffHand(), player, "join"); newItem = modifyItem(player.getEquipment().getItemInOffHand(), player, "join");
if(newItem != null) player.getEquipment().setItemInOffHand(newItem); if (newItem != null) player.getEquipment().setItemInOffHand(newItem);
} }
@Nullable private ItemStack modifyItem(@Nullable ItemStack stack, @NotNull Player player, @NotNull String reason) { @Nullable
//RFG//MMOItems.log("§8Reforge §cMOD§7 Modifying " + SilentNumbers.getItemName(stack) + " §7due to§3 " + reason); 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 // Sleep on metaless stacks
if (stack == null) { return null; } if (stack == null || !stack.hasItemMeta())
if (!stack.hasItemMeta()) { return null; } return null;
// Create a reforger to look at it // Create a reforger to look at it
MMOItemReforger mod = new MMOItemReforger(stack); MMOItemReforger mod = new MMOItemReforger(stack);
// Shouldn't update? I sleep // Shouldn't update? I sleep
if (!mod.shouldReforge(reason)) { return null; } if (!mod.shouldReforge(reason)) return null;
// All right update then // All right update then
mod.setPlayer(player); mod.setPlayer(player);
if (!mod.reforge(MMOItems.plugin.getLanguage().revisionOptions)) { if (!mod.reforge(MMOItems.plugin.getLanguage().revisionOptions))
return null;
return null; } // Drop all those items
player.getInventory()
.addItem(mod.getReforgingOutput().toArray(new ItemStack[0]))
.values()
.stream()
.filter(drop -> !SilentNumbers.isAir(drop))
.forEach(drop -> player.getWorld().dropItem(player.getLocation(), drop));
// Drop all those items // That's it
for (ItemStack drop : player.getInventory().addItem( return mod.getResult();
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); }
// That's it
return mod.getResult();
}
} }

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmoitems.listener.reforging; package net.Indyuce.mmoitems.listener.reforging;
import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.event.MMOItemReforgeEvent; import net.Indyuce.mmoitems.api.event.MMOItemReforgeEvent;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData; import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.random.UpdatableRandomStatData; import net.Indyuce.mmoitems.stat.data.random.UpdatableRandomStatData;
@ -24,86 +23,79 @@ public class RFGKeepRNG implements Listener {
@EventHandler @EventHandler
public void onReforge(MMOItemReforgeEvent event) { public void onReforge(MMOItemReforgeEvent event) {
// Rerolling stats? Nevermind // 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)"); //RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping new item (Complete RNG Reroll)");
return; } return;
}
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping old RNG Rolls"); //RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping old RNG Rolls");
/* /*
* Proceed to go through all stats * Proceed to go through all stats
*/ */
for (ItemStat stat : event.getOldMMOItem().getStats()) { event.getOldMMOItem()
.getStats()
.stream()
// Skip if it cant merge
.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
*/
.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)))
.forEach(stat -> {
// Stat history in the old item
StatHistory hist = StatHistory.from(event.getOldMMOItem(), stat);
// Skip if it cant merge // Alr what the template say, this roll too rare to be kept?
if (!(stat.getClearStatData() instanceof Mergeable)) { RandomStatData source = event.getReforger().getTemplate().getBaseItemData().get(stat);
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is \u00a7cnot\u00a77 even mergeable");
continue; }
/* /*
* These stats are exempt from this 'keeping' operation. * Decide if this data is too far from RNG to
* Probably because there is a ReforgeOption specifically * preserve its rolls, even if it should be
* designed for them that keeps them separately * preserving the rolls.
*/ */
if (ItemStats.LORE.equals(stat) || StatData keptData = shouldReRollRegardless(stat, source, hist.getOriginalData(), event.getReforger().getGenerationItemLevel());
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..."); // Old roll is ridiculously low probability under the new parameters. Forget.
if (keptData == null)
return;
// Stat history in the old item // Fetch History from the new item
StatHistory hist = StatHistory.from(event.getOldMMOItem(), stat); StatHistory clear = StatHistory.from(event.getNewMMOItem(), stat);
// Alr what the template say, this roll too rare to be kept? // Replace original data of the new one with the roll from the old one
RandomStatData source = event.getReforger().getTemplate().getBaseItemData().get(stat); clear.setOriginalData(keptData);
});
/*
* Decide if this data is too far from RNG to
* preserve its rolls, even if it should be
* preserving the rolls.
*/
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; }
// 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. * @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 * 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: * except in the most dire scenarios:
* <br><br> * <br><br>
* + The mean/standard deviation changing significantly: * + The mean/standard deviation changing significantly:
* If the chance of getting the same roll is ridiculously low (3.5SD) under the new settings, reroll. * If the chance of getting the same roll is ridiculously low (3.5SD) under the new settings, reroll.
* <br><br> * <br><br>
* + The stat is no longer there: Mean and SD become zero, so the rule above always removes the old roll. * + The stat is no longer there: Mean and SD become zero, so the rule above always removes the old roll.
* <br><br> * <br><br>
* + There is a new stat: The original data is null so this method cannot be called, will roll the * + 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. * 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 // 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!"); //RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is not updatable!");
return null; } return null;
// Just pass on // Just pass on
return ((UpdatableRandomStatData) source).reroll(stat, original, determinedItemLevel); return ((UpdatableRandomStatData) source).reroll(stat, original, determinedItemLevel);

View File

@ -1,9 +1,7 @@
package net.Indyuce.mmoitems.listener.reforging; package net.Indyuce.mmoitems.listener.reforging;
import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.event.MMOItemReforgeEvent; import net.Indyuce.mmoitems.api.event.MMOItemReforgeEvent;
import net.Indyuce.mmoitems.api.util.MMOItemReforger;
import net.Indyuce.mmoitems.stat.data.SoulboundData; import net.Indyuce.mmoitems.stat.data.SoulboundData;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; 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)); // 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"); //RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping Soulbound");
// Keep it // Keep it