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
@ -9,167 +9,203 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ReforgeOptions {
|
||||
public static boolean dropRestoredGems;
|
||||
public static boolean dropRestoredGems;
|
||||
|
||||
// MMOItems stuff
|
||||
private final boolean keepName;
|
||||
private final boolean keepLore;
|
||||
private final boolean keepEnchantments;
|
||||
private final boolean keepSkins;
|
||||
private final boolean keepUpgrades;
|
||||
private final boolean keepGemStones;
|
||||
private final boolean keepSoulbind;
|
||||
private final boolean keepExternalSH;
|
||||
private final boolean keepModifications;
|
||||
@Nullable private final Boolean keepTier;
|
||||
// MMOItems stuff
|
||||
private final boolean keepName;
|
||||
private final boolean keepLore;
|
||||
private final boolean keepEnchantments;
|
||||
private final boolean keepSkins;
|
||||
private final boolean keepUpgrades;
|
||||
private final boolean keepGemStones;
|
||||
private final boolean keepSoulBind;
|
||||
private final boolean keepExternalSH;
|
||||
private final boolean keepModifications;
|
||||
@Nullable
|
||||
private final Boolean keepTier;
|
||||
|
||||
private final boolean reroll;
|
||||
private final boolean reRoll;
|
||||
|
||||
// Third Party Stuff
|
||||
private final boolean keepAdvancedEnchantments;
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apparently, people like to use MMOItems for quests. This
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
public String getKeepCase() {
|
||||
return keepCase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apparently, people like to use MMOItems for quests. This
|
||||
* 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); }
|
||||
@NotNull
|
||||
ArrayList<String> blacklistedItems = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* No MMOItem-ID restrictions on RevID.
|
||||
*/
|
||||
public void clearBlacklist() { blacklistedItems.clear(); }
|
||||
/**
|
||||
* Apparently, people like to use MMOItems for quests. This
|
||||
* will make items NEVER update with RevID
|
||||
*
|
||||
* @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");
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Apparently, people like to use MMOItems for quests. This
|
||||
* will make items NEVER update with RevID
|
||||
*
|
||||
* @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 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);
|
||||
}
|
||||
/**
|
||||
* No MMOItem-ID restrictions on RevID.
|
||||
*/
|
||||
public void clearBlacklist() {
|
||||
blacklistedItems.clear();
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
public boolean shouldReroll() { return reroll; }
|
||||
/**
|
||||
* Keeps the display name of the item.
|
||||
*/
|
||||
public boolean shouldReRoll() {
|
||||
return reRoll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the display name of the item.
|
||||
*/
|
||||
public boolean shouldKeepName() { return keepName; }
|
||||
/**
|
||||
* Keeps the display name of the item.
|
||||
*/
|
||||
public boolean shouldKeepName() {
|
||||
return keepName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the modifiers of the item.
|
||||
*/
|
||||
public boolean shouldKeepMods() { return keepModifications; }
|
||||
/**
|
||||
* Keeps the modifiers of the item.
|
||||
*/
|
||||
public boolean shouldKeepMods() {
|
||||
return keepModifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps all lore lines that begin with {@link org.bukkit.ChatColor#GRAY}
|
||||
*/
|
||||
public boolean shouldKeepLore() { return keepLore; }
|
||||
/**
|
||||
* Keeps all lore lines that begin with {@link org.bukkit.ChatColor#GRAY}
|
||||
*/
|
||||
public boolean shouldKeepLore() {
|
||||
return keepLore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps skins
|
||||
*/
|
||||
public boolean shouldKeepSkins() { return keepSkins; }
|
||||
/**
|
||||
* Keeps skins
|
||||
*/
|
||||
public boolean shouldKeepSkins() {
|
||||
return keepSkins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should keep the tier? defaults to {@link MMOItemReforger#keepTiersWhenReroll}
|
||||
*/
|
||||
public boolean shouldKeepTier() { return keepTier == null ? MMOItemReforger.keepTiersWhenReroll : keepTier; }
|
||||
/**
|
||||
* Should keep the tier? defaults to {@link MMOItemReforger#keepTiersWhenReroll}
|
||||
*/
|
||||
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; }
|
||||
/**
|
||||
* Should this keep the enchantments the player
|
||||
* manually cast onto this item? (Not from gem
|
||||
* stones nor upgrades).
|
||||
*/
|
||||
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; }
|
||||
/**
|
||||
* Should this keep the enchantments the player
|
||||
* manually cast onto this item? (Not from gem
|
||||
* stones nor upgrades).
|
||||
*/
|
||||
public boolean shouldKeepAdvancedEnchants() {
|
||||
return keepAdvancedEnchantments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep 'extraneous' data registered onto the Stat History
|
||||
*/
|
||||
public boolean shouldKeepExternalSH() { return keepExternalSH; }
|
||||
/**
|
||||
* Keep 'extraneous' data registered onto the Stat History
|
||||
*/
|
||||
public boolean shouldKeepExternalSH() {
|
||||
return keepExternalSH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains the upgrade level of the item.
|
||||
*/
|
||||
public boolean shouldKeepUpgrades() { return keepUpgrades; }
|
||||
/**
|
||||
* Retains the upgrade level of the item.
|
||||
*/
|
||||
public boolean shouldKeepUpgrades() {
|
||||
return keepUpgrades;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains all gem stones if there are any, removing
|
||||
* one gem socket for every gemstone kept.
|
||||
* <p></p>
|
||||
* Gemstones remember at what upgrade level they were inserted.
|
||||
*/
|
||||
public boolean shouldKeepGemStones() { return keepGemStones; }
|
||||
/**
|
||||
* Retains all gem stones if there are any, removing
|
||||
* one gem socket for every gemstone kept.
|
||||
* <p></p>
|
||||
* Gemstones remember at what upgrade level they were inserted.
|
||||
*/
|
||||
public boolean shouldKeepGemStones() {
|
||||
return keepGemStones;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retains the soulbind if it has any.
|
||||
*/
|
||||
public boolean shouldKeepSoulbind() { return keepSoulbind; }
|
||||
/**
|
||||
* Retains the soulbind if it has any.
|
||||
*/
|
||||
public boolean shouldKeepSoulBind() {
|
||||
return keepSoulBind;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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,111 +21,111 @@ 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
|
||||
public ItemListener() {
|
||||
//RFG//MMOItems.log(" §b>§a>§e> §7Registering Listeners");
|
||||
// Aye
|
||||
public ItemListener() {
|
||||
//RFG//MMOItems.log(" §b>§a>§e> §7Registering Listeners");
|
||||
|
||||
// Register Reforger Listeners
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepName(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepLore(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepEnchantments(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepExternalSH(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepGems(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepModifications(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepSoulbound(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepUpgrades(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepRNG(), MMOItems.plugin);
|
||||
// Register Reforger Listeners
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepName(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepLore(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepEnchantments(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepExternalSH(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepGems(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepModifications(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepSoulbound(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepUpgrades(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepRNG(), MMOItems.plugin);
|
||||
|
||||
// Amount ones
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepDurability(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFFKeepAmount(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFFKeepSkins(), MMOItems.plugin);
|
||||
// Amount ones
|
||||
Bukkit.getPluginManager().registerEvents(new RFGKeepDurability(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFFKeepAmount(), MMOItems.plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new RFFKeepSkins(), MMOItems.plugin);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void itemPickup(EntityPickupItemEvent e) {
|
||||
if (!e.getEntity().getType().equals(EntityType.PLAYER)) return;
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void itemPickup(EntityPickupItemEvent e) {
|
||||
if (!e.getEntity().getType().equals(EntityType.PLAYER)) return;
|
||||
|
||||
ItemStack newItem = modifyItem(e.getItem().getItemStack(), (Player) e.getEntity(), "pickup");
|
||||
if (newItem != null) e.getItem().setItemStack(newItem);
|
||||
}
|
||||
ItemStack newItem = modifyItem(e.getItem().getItemStack(), (Player) e.getEntity(), "pickup");
|
||||
if (newItem != null) e.getItem().setItemStack(newItem);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void itemCraft(CraftItemEvent e) {
|
||||
if(!(e.getWhoClicked() instanceof Player)) return;
|
||||
ItemStack newItem = modifyItem(e.getCurrentItem(), (Player) e.getWhoClicked(), "craft");
|
||||
if (newItem != null) e.setCurrentItem(newItem);
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void itemCraft(CraftItemEvent e) {
|
||||
if (!(e.getWhoClicked() instanceof Player)) return;
|
||||
ItemStack newItem = modifyItem(e.getCurrentItem(), (Player) e.getWhoClicked(), "craft");
|
||||
if (newItem != null) e.setCurrentItem(newItem);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void inventoryMove(InventoryClickEvent e) {
|
||||
if (e.getInventory().getType() != InventoryType.CRAFTING || !(e.getWhoClicked() instanceof Player)) return;
|
||||
ItemStack newItem = modifyItem(e.getCurrentItem(), (Player) e.getWhoClicked(), "click");
|
||||
if (newItem != null) e.setCurrentItem(newItem);
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void inventoryMove(InventoryClickEvent e) {
|
||||
if (e.getInventory().getType() != InventoryType.CRAFTING || !(e.getWhoClicked() instanceof Player)) return;
|
||||
ItemStack newItem = modifyItem(e.getCurrentItem(), (Player) e.getWhoClicked(), "click");
|
||||
if (newItem != null) e.setCurrentItem(newItem);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void dropItem(PlayerDropItemEvent event) {
|
||||
NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack());
|
||||
if (!MMOItems.plugin.getConfig().getBoolean("soulbound.can-drop") && nbt.hasTag("MMOITEMS_SOULBOUND"))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
private void dropItem(PlayerDropItemEvent event) {
|
||||
NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack());
|
||||
if (!MMOItems.plugin.getConfig().getBoolean("soulbound.can-drop") && nbt.hasTag("MMOITEMS_SOULBOUND"))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void playerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void playerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
ItemStack newItem = modifyItem(player.getEquipment().getHelmet(), player, "join");
|
||||
if(newItem != null) player.getEquipment().setHelmet(newItem);
|
||||
newItem = modifyItem(player.getEquipment().getChestplate(), player, "join");
|
||||
if(newItem != null) player.getEquipment().setChestplate(newItem);
|
||||
newItem = modifyItem(player.getEquipment().getLeggings(), player, "join");
|
||||
if(newItem != null) player.getEquipment().setLeggings(newItem);
|
||||
newItem = modifyItem(player.getEquipment().getBoots(), player, "join");
|
||||
if(newItem != null) player.getEquipment().setBoots(newItem);
|
||||
ItemStack newItem = modifyItem(player.getEquipment().getHelmet(), player, "join");
|
||||
if (newItem != null) player.getEquipment().setHelmet(newItem);
|
||||
newItem = modifyItem(player.getEquipment().getChestplate(), player, "join");
|
||||
if (newItem != null) player.getEquipment().setChestplate(newItem);
|
||||
newItem = modifyItem(player.getEquipment().getLeggings(), player, "join");
|
||||
if (newItem != null) player.getEquipment().setLeggings(newItem);
|
||||
newItem = modifyItem(player.getEquipment().getBoots(), player, "join");
|
||||
if (newItem != null) player.getEquipment().setBoots(newItem);
|
||||
|
||||
for (int j = 0; j < 9; j++) {
|
||||
newItem = modifyItem(player.getInventory().getItem(j), player, "join");
|
||||
if (newItem != null) player.getInventory().setItem(j, newItem);
|
||||
}
|
||||
for (int j = 0; j < 9; j++) {
|
||||
newItem = modifyItem(player.getInventory().getItem(j), player, "join");
|
||||
if (newItem != null) player.getInventory().setItem(j, newItem);
|
||||
}
|
||||
|
||||
newItem = modifyItem(player.getEquipment().getItemInOffHand(), player, "join");
|
||||
if(newItem != null) player.getEquipment().setItemInOffHand(newItem);
|
||||
}
|
||||
newItem = modifyItem(player.getEquipment().getItemInOffHand(), player, "join");
|
||||
if (newItem != null) player.getEquipment().setItemInOffHand(newItem);
|
||||
}
|
||||
|
||||
@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);
|
||||
@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; }
|
||||
// Sleep on metaless stacks
|
||||
if (stack == null || !stack.hasItemMeta())
|
||||
return null;
|
||||
|
||||
// Create a reforger to look at it
|
||||
MMOItemReforger mod = new MMOItemReforger(stack);
|
||||
// Create a reforger to look at it
|
||||
MMOItemReforger mod = new MMOItemReforger(stack);
|
||||
|
||||
// Shouldn't update? I sleep
|
||||
if (!mod.shouldReforge(reason)) { return null; }
|
||||
// Shouldn't update? I sleep
|
||||
if (!mod.shouldReforge(reason)) return null;
|
||||
|
||||
// All right update then
|
||||
mod.setPlayer(player);
|
||||
if (!mod.reforge(MMOItems.plugin.getLanguage().revisionOptions)) {
|
||||
// All right update then
|
||||
mod.setPlayer(player);
|
||||
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
|
||||
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); }
|
||||
|
||||
// That's it
|
||||
return mod.getResult();
|
||||
}
|
||||
// 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,86 +23,79 @@ 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
|
||||
.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
|
||||
if (!(stat.getClearStatData() instanceof Mergeable)) {
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is \u00a7cnot\u00a77 even mergeable");
|
||||
continue; }
|
||||
// Alr what the template say, this roll too rare to be kept?
|
||||
RandomStatData source = event.getReforger().getTemplate().getBaseItemData().get(stat);
|
||||
|
||||
/*
|
||||
* 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) ||
|
||||
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; }
|
||||
/*
|
||||
* 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());
|
||||
|
||||
//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
|
||||
StatHistory hist = StatHistory.from(event.getOldMMOItem(), stat);
|
||||
// Fetch History from the new item
|
||||
StatHistory clear = StatHistory.from(event.getNewMMOItem(), stat);
|
||||
|
||||
// Alr what the template say, this roll too rare to be kept?
|
||||
RandomStatData source = event.getReforger().getTemplate().getBaseItemData().get(stat);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
// 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.
|
||||
*
|
||||
* 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>
|
||||
* + The mean/standard deviation changing significantly:
|
||||
* If the chance of getting the same roll is ridiculously low (3.5SD) under the new settings, reroll.
|
||||
* <br><br>
|
||||
* + The stat is no longer there: Mean and SD become zero, so the rule above always removes the old roll.
|
||||
* <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.
|
||||
*
|
||||
*
|
||||
* <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>
|
||||
* + The mean/standard deviation changing significantly:
|
||||
* If the chance of getting the same roll is ridiculously low (3.5SD) under the new settings, reroll.
|
||||
* <br><br>
|
||||
* + The stat is no longer there: Mean and SD become zero, so the rule above always removes the old roll.
|
||||
* <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