Modifier Hiding

This commit is contained in:
Rosenthalk0 2022-11-08 16:18:08 -06:00
parent 6f0e2ff44b
commit 8f52cd2c67
7 changed files with 57 additions and 31 deletions

View File

@ -25,6 +25,7 @@ public class ConfigMMOItem {
Validate.isTrue(config.contains("type") && config.contains("id"), "Config must contain type and ID"); Validate.isTrue(config.contains("type") && config.contains("id"), "Config must contain type and ID");
Type type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")); Type type = MMOItems.plugin.getTypes().getOrThrow(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
template = MMOItems.plugin.getTemplates().getTemplateOrThrow(type, config.getString("id")); template = MMOItems.plugin.getTemplates().getTemplateOrThrow(type, config.getString("id"));
preview = template.newBuilder(0,null,true).build().newBuilder().build();
this.amount = Math.max(1, config.getInt("amount")); this.amount = Math.max(1, config.getInt("amount"));
} }
@ -44,7 +45,7 @@ public class ConfigMMOItem {
* @return A freshly-crafted item to be used by the player. * @return A freshly-crafted item to be used by the player.
*/ */
@NotNull public ItemStack generate(@NotNull RPGPlayer player) { @NotNull public ItemStack generate(@NotNull RPGPlayer player) {
ItemStack item = template.newBuilder(player).build().newBuilder().build(); ItemStack item = template.newBuilder(player,false).build().newBuilder().build();
item.setAmount(amount); item.setAmount(amount);
return item; return item;
} }
@ -57,8 +58,8 @@ public class ConfigMMOItem {
* reduce startup calculations so that item is calculated the first time it * reduce startup calculations so that item is calculated the first time it
* needs to be displayed * needs to be displayed
*/ */
public ItemStack getPreview(boolean hideModifiers) { public ItemStack getPreview(boolean noModifiers) {
return preview == null ? (preview = template.newBuilder(0, null).build(hideModifiers).newBuilder().build(true)).clone() : preview.clone(); return preview == null ? (preview = template.newBuilder(0, null,noModifiers).build().newBuilder().build(true)).clone() : preview.clone();
} }
public ItemStack getPreview(){ public ItemStack getPreview(){

View File

@ -164,7 +164,7 @@ public class CraftingRecipe extends Recipe {
* backwards compatibility, since this is how it used to * backwards compatibility, since this is how it used to
* be done. Don't want to break that without good reason. * be done. Don't want to break that without good reason.
*/ */
return identifiedMMO.getPreview(hasOption(RecipeOption.HIDE_MODIFIERS)); return identifiedMMO.getPreview(true);
} }
// Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection. // Generate from ProvidedUIFilter, guaranteed to not be null don't listen to the inspection.

View File

@ -189,7 +189,6 @@ public abstract class Recipe {
} }
public static enum RecipeOption { public static enum RecipeOption {
HIDE_MODIFIERS(true),
/** /**
* Hide the crafting recipe when one of the condition is not met * Hide the crafting recipe when one of the condition is not met

View File

@ -32,6 +32,9 @@ public class MMOItemBuilder {
*/ */
private final HashMap<UUID, NameModifier> nameModifiers = new HashMap<>(); private final HashMap<UUID, NameModifier> nameModifiers = new HashMap<>();
public MMOItemBuilder(MMOItemTemplate template, int level, @Nullable ItemTier tier){
this(template,level,tier,false);
}
/** /**
* Instance which is created everytime an mmoitem is being randomly * Instance which is created everytime an mmoitem is being randomly
* generated * generated
@ -41,8 +44,9 @@ public class MMOItemBuilder {
* @param tier Specified item tier which determines how many capacity it will * @param tier Specified item tier which determines how many capacity it will
* have. If no tier is given, item uses the default capacity * have. If no tier is given, item uses the default capacity
* formula given in the main config file * formula given in the main config file
* @param noModifiers hides modifiers from previewed items!
*/ */
public MMOItemBuilder(MMOItemTemplate template, int level, @Nullable ItemTier tier) { public MMOItemBuilder(MMOItemTemplate template, int level, @Nullable ItemTier tier, boolean noModifiers) {
this.level = level; this.level = level;
this.tier = tier; this.tier = tier;
@ -62,6 +66,9 @@ public class MMOItemBuilder {
if (level > 0) if (level > 0)
mmoitem.setData(ItemStats.ITEM_LEVEL, new DoubleData(level)); mmoitem.setData(ItemStats.ITEM_LEVEL, new DoubleData(level));
if (noModifiers){
return;
}
// Roll item generation modifiers // Roll item generation modifiers
for (TemplateModifier modifier : rollModifiers(template)) { for (TemplateModifier modifier : rollModifiers(template)) {
// Roll modifier chance; only apply if the rolled item has enough capacity // Roll modifier chance; only apply if the rolled item has enough capacity
@ -96,11 +103,9 @@ public class MMOItemBuilder {
* *
* @return Built MMOItem instance * @return Built MMOItem instance
*/ */
public MMOItem build(boolean hideModifierNames) { public MMOItem build() {
if (hideModifierNames){
return mmoitem;
}
if (!nameModifiers.isEmpty()) { if (!nameModifiers.isEmpty()) {
// Get name data // Get name data
@ -133,9 +138,6 @@ public class MMOItemBuilder {
return mmoitem; return mmoitem;
} }
public MMOItem build(){
return build(false);
}
/** /**
* Applies statData to the builder, either merges it if statData is * Applies statData to the builder, either merges it if statData is

View File

@ -15,6 +15,7 @@ import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -144,17 +145,23 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference {
return options.contains(option); return options.contains(option);
} }
public MMOItemBuilder newBuilder(@Nullable Player player) { public MMOItemBuilder newBuilder(@Nullable Player player, boolean noModifiers) {
if (player != null) { return newBuilder(PlayerData.get(player).getRPG()); } if (player != null) { return newBuilder(PlayerData.get(player).getRPG(),noModifiers); }
return newBuilder((RPGPlayer) null); return newBuilder((RPGPlayer) null,noModifiers);
}
public MMOItemBuilder newBuilder(@Nullable Player player) { return this.newBuilder(player,false); }
public MMOItemBuilder newBuilder(boolean noModifiers) { return newBuilder((RPGPlayer) null,noModifiers); }
public MMOItemBuilder newBuilder() { return this.newBuilder(false); }
public MMOItemBuilder newBuilder(@Nullable PlayerData player, boolean noModifiers) {
if (player != null) { return newBuilder(player.getRPG(),noModifiers); }
return newBuilder((RPGPlayer) null,noModifiers);
}
public MMOItemBuilder newBuilder(@Nullable PlayerData player){
return this.newBuilder(player,false);
} }
public MMOItemBuilder newBuilder() { return newBuilder((RPGPlayer) null); }
public MMOItemBuilder newBuilder(@Nullable PlayerData player) {
if (player != null) { return newBuilder(player.getRPG()); }
return newBuilder((RPGPlayer) null);
}
/** /**
* By default, item templates have item level 0 and no random tier. If the * By default, item templates have item level 0 and no random tier. If the
@ -166,24 +173,38 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference {
* *
* @return Item builder with random level and tier? * @return Item builder with random level and tier?
*/ */
public MMOItemBuilder newBuilder(@Nullable RPGPlayer player) { public MMOItemBuilder newBuilder(@Nullable RPGPlayer player, boolean noModifiers) {
// No player ~ default settings // No player ~ default settings
if (player == null) { return newBuilder(0, null); } if (player == null) { return newBuilder(0, null,noModifiers); }
// Read from player // Read from player
int itemLevel = hasOption(TemplateOption.LEVEL_ITEM) ? MMOItems.plugin.getTemplates().rollLevel(player.getLevel()) : 0; int itemLevel = hasOption(TemplateOption.LEVEL_ITEM) ? MMOItems.plugin.getTemplates().rollLevel(player.getLevel()) : 0;
ItemTier itemTier = hasOption(TemplateOption.TIERED) ? MMOItems.plugin.getTemplates().rollTier() : null; ItemTier itemTier = hasOption(TemplateOption.TIERED) ? MMOItems.plugin.getTemplates().rollTier() : null;
return new MMOItemBuilder(this, itemLevel, itemTier); return new MMOItemBuilder(this, itemLevel, itemTier,noModifiers);
}
public MMOItemBuilder newBuilder(@Nullable RPGPlayer player){
return this.newBuilder(player,false);
} }
/**
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @param noModifiers Whether to add modifiers to the item
* @return Item builder with specific item level and tier
*/
public MMOItemBuilder newBuilder(int itemLevel, @Nullable ItemTier itemTier,boolean noModifiers) {
return new MMOItemBuilder(this, itemLevel, itemTier);
}
/** /**
* @param itemLevel The desired item level * @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null * @param itemTier The desired item tier, can be null
* @return Item builder with specific item level and tier * @return Item builder with specific item level and tier
*/ */
public MMOItemBuilder newBuilder(int itemLevel, @Nullable ItemTier itemTier) { public MMOItemBuilder newBuilder(int itemLevel,@Nullable ItemTier itemTier){
return new MMOItemBuilder(this, itemLevel, itemTier); return this.newBuilder(itemLevel,itemTier,false);
} }
public enum TemplateOption { public enum TemplateOption {

View File

@ -55,8 +55,11 @@ public class TemplateExplorer {
* @return Random item with random tier and item level which matches the * @return Random item with random tier and item level which matches the
* player's level * player's level
*/ */
public Optional<MMOItem> rollItem(RPGPlayer player) { public Optional<MMOItem> rollItem(RPGPlayer player, boolean noModifiers) {
return rollLoot().map(template -> template.newBuilder(player).build()); return rollLoot().map(template -> template.newBuilder(player,noModifiers).build());
}
public Optional<MMOItem> rollItem(RPGPlayer player){
return this.rollItem(player,false);
} }
private <T> Predicate<T> not(Predicate<T> predicate) { private <T> Predicate<T> not(Predicate<T> predicate) {

View File

@ -235,8 +235,8 @@ public class ItemBrowser extends PluginInventory {
continue; continue;
} }
// Build item -> any errors? // Build item -> any errors? [As of now, needs a configuration option for modifiers]
ItemStack item = template.newBuilder(playerData.getRPG()).build().newBuilder().build(); ItemStack item = template.newBuilder(playerData.getRPG(),true).build().newBuilder().build();
if (item == null || item.getType().isAir() || !item.getType().isItem() || item.getItemMeta() == null) { if (item == null || item.getType().isAir() || !item.getType().isItem() || item.getItemMeta() == null) {
// Set Item // Set Item