mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-24 15:01:44 +01:00
Added javadocs and fixed an issue with item gen
This commit is contained in:
parent
8d9631d8f4
commit
5be720c32e
@ -111,11 +111,11 @@ public class GeneratedItemBuilder {
|
||||
nameModifiers.removeIf(current -> current.getType() == modifier.getType() && current.getPriority() < modifier.getPriority());
|
||||
nameModifiers.add(modifier);
|
||||
}
|
||||
|
||||
|
||||
private Collection<GenerationModifier> rollModifiers(GenerationTemplate template) {
|
||||
if (!template.hasOption(TemplateOption.ROLL_MODIFIER_CHECK_ORDER))
|
||||
return template.getModifiers();
|
||||
|
||||
|
||||
List<GenerationModifier> modifiers = new ArrayList<>(template.getModifiers());
|
||||
Collections.shuffle(modifiers);
|
||||
return modifiers;
|
||||
|
@ -31,13 +31,23 @@ public class GenerationModifier {
|
||||
this(null, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an item gen modifier from a configuration section. If you provide
|
||||
* the ItemGenManager, you will be able to use the 'parent' option to
|
||||
* redirect that modifier to a public gen modifier.
|
||||
*
|
||||
* @param manager
|
||||
* Provide the ItemGenManager to use the 'parent' option
|
||||
* @param config
|
||||
* The configuration section to load the modifier from
|
||||
*/
|
||||
public GenerationModifier(ItemGenManager manager, ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not read config");
|
||||
id = config.getName().toLowerCase().replace("_", "-");
|
||||
|
||||
/*
|
||||
* when providing a non-null itemGenManager, it indicates that public
|
||||
* modifiers were loaded and that the constructor can them
|
||||
* modifiers were loaded and that the constructor can use them
|
||||
*/
|
||||
if (manager != null && config.contains("parent")) {
|
||||
String parentFormat = config.get("parent").toString().toLowerCase().replace("_", "-").replace(" ", "_");
|
||||
|
@ -46,8 +46,7 @@ public class GenerationTemplate {
|
||||
if (config.contains("modifiers"))
|
||||
for (String key : config.getConfigurationSection("modifiers").getKeys(false))
|
||||
try {
|
||||
modifiers.add(new GenerationModifier(MMOItems.plugin.getItemGenerator(),
|
||||
config.getConfigurationSection("modifiers." + key)));
|
||||
modifiers.add(new GenerationModifier(MMOItems.plugin.getItemGenerator(), config.getConfigurationSection("modifiers." + key)));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.INFO, "An error occured while trying to load modifier '" + key
|
||||
+ "' from item gen template '" + id + "': " + exception.getMessage());
|
||||
@ -62,8 +61,8 @@ public class GenerationTemplate {
|
||||
ItemStat stat = MMOItems.plugin.getStats().get(id);
|
||||
base.put(stat, stat.whenInitializedGeneration(config.get("base." + key)));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.INFO, "An error occured while trying to load base item data '"
|
||||
+ key + "' from item gen template '" + id + "': " + exception.getMessage());
|
||||
MMOItems.plugin.getLogger().log(Level.INFO, "An error occured while trying to load base item data '" + key
|
||||
+ "' from item gen template '" + id + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,6 +86,12 @@ public class GenerationTemplate {
|
||||
return options.contains(option);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* The rpg info about the player whom you want to give a random
|
||||
* item to
|
||||
* @return A random item builder which scales on the player's level.
|
||||
*/
|
||||
public GeneratedItemBuilder newBuilder(RPGPlayer player) {
|
||||
int itemLevel = MMOItems.plugin.getItemGenerator().rollLevel(player.getLevel());
|
||||
RolledTier itemTier = MMOItems.plugin.getItemGenerator().rollTier(itemLevel);
|
||||
@ -100,8 +105,8 @@ public class GenerationTemplate {
|
||||
public enum TemplateOption {
|
||||
|
||||
/*
|
||||
* when the item is being generated, modifiers are rolled in a random order so
|
||||
* you never the same modifiers again and again
|
||||
* when the item is being generated, modifiers are rolled in a random
|
||||
* order so you never the same modifiers again and again
|
||||
*/
|
||||
ROLL_MODIFIER_CHECK_ORDER;
|
||||
}
|
||||
|
@ -11,6 +11,14 @@ public class NameModifier {
|
||||
private final String format;
|
||||
private final int priority;
|
||||
|
||||
/**
|
||||
* Loads a prefix/suffix from either a config section or a string
|
||||
*
|
||||
* @param type
|
||||
* Either a prefix or a suffix
|
||||
* @param object
|
||||
* The object to load the modifier from
|
||||
*/
|
||||
public NameModifier(ModifierType type, Object object) {
|
||||
Validate.notNull(object, "Object cannot be null");
|
||||
this.type = type;
|
||||
|
@ -2,11 +2,19 @@ package net.Indyuce.mmoitems.api.itemgen;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
|
||||
/**
|
||||
* RandomStatDatas are basically the bricks of the generation templates. They
|
||||
* are the first instances called when loading gen templates from config files.
|
||||
*
|
||||
* @author cympe
|
||||
*/
|
||||
public interface RandomStatData {
|
||||
|
||||
/*
|
||||
* generate a real stat data based on the item builder which contains
|
||||
* information about the item level.
|
||||
/**
|
||||
* @param builder
|
||||
* The builder of the random item being generated
|
||||
* @return A random stat data instance which will then be merged onto the
|
||||
* base item template
|
||||
*/
|
||||
public StatData randomize(GeneratedItemBuilder builder);
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ public class CustomSounds extends ItemStat implements ProperStat {
|
||||
mmoitem.getNBT().getDouble("MMOITEMS_SOUND_" + sound.name() + "_PIT"));
|
||||
}
|
||||
|
||||
if (sounds.total() > 0)
|
||||
if (sounds.getCustomSounds().size() > 0)
|
||||
mmoitem.setData(ItemStat.CUSTOM_SOUNDS, sounds);
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,15 @@ import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
|
||||
public class CommandListData implements StatData, Mergeable, RandomStatData {
|
||||
private final Set<CommandData> commands = new HashSet<>();
|
||||
private final Set<CommandData> commands;
|
||||
|
||||
public CommandListData(Set<CommandData> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public CommandListData(CommandData... commands) {
|
||||
this(new HashSet<>());
|
||||
|
||||
add(commands);
|
||||
}
|
||||
|
||||
@ -34,6 +40,6 @@ public class CommandListData implements StatData, Mergeable, RandomStatData {
|
||||
|
||||
@Override
|
||||
public StatData randomize(GeneratedItemBuilder builder) {
|
||||
return this;
|
||||
return new CommandListData(new HashSet<>(commands));
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -42,7 +43,7 @@ public class GemSocketsData implements StatData, Mergeable, RandomStatData {
|
||||
emptySlots.remove(getEmptySocket(gem));
|
||||
gems.add(gemstone);
|
||||
}
|
||||
|
||||
|
||||
public void addEmptySlot(String slot) {
|
||||
emptySlots.add(slot);
|
||||
}
|
||||
@ -77,6 +78,6 @@ public class GemSocketsData implements StatData, Mergeable, RandomStatData {
|
||||
|
||||
@Override
|
||||
public StatData randomize(GeneratedItemBuilder builder) {
|
||||
return this;
|
||||
return new GemSocketsData(new ArrayList<>(emptySlots));
|
||||
}
|
||||
}
|
||||
|
@ -13,37 +13,41 @@ import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
|
||||
public class SoundListData implements StatData, Mergeable, RandomStatData {
|
||||
private final Map<CustomSound, SoundData> stats = new HashMap<>();
|
||||
private final Map<CustomSound, SoundData> sounds;
|
||||
|
||||
public SoundListData() {
|
||||
this(new HashMap<>());
|
||||
}
|
||||
|
||||
public SoundListData(Map<CustomSound, SoundData> sounds) {
|
||||
this.sounds = sounds;
|
||||
}
|
||||
|
||||
public Set<CustomSound> getCustomSounds() {
|
||||
return stats.keySet();
|
||||
return sounds.keySet();
|
||||
}
|
||||
|
||||
public Map<CustomSound, SoundData> mapData() {
|
||||
return stats;
|
||||
return sounds;
|
||||
}
|
||||
|
||||
public SoundData get(CustomSound sound) {
|
||||
return stats.get(sound);
|
||||
return sounds.get(sound);
|
||||
}
|
||||
|
||||
public void set(CustomSound type, String sound, double volume, double pitch) {
|
||||
this.stats.put(type, new SoundData(sound, volume, pitch));
|
||||
}
|
||||
|
||||
public int total() {
|
||||
return stats.size();
|
||||
this.sounds.put(type, new SoundData(sound, volume, pitch));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof SoundListData, "Cannot merge two different stat data types");
|
||||
SoundListData cast = (SoundListData) data;
|
||||
cast.stats.keySet().forEach(key -> stats.put(key, cast.stats.get(key)));
|
||||
cast.sounds.forEach((sound, soundData) -> sounds.put(sound, soundData));
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatData randomize(GeneratedItemBuilder builder) {
|
||||
return this;
|
||||
return new SoundListData(new HashMap<>(sounds));
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ public class StringListData implements StatData, RandomStatData, Mergeable {
|
||||
|
||||
@Override
|
||||
public StatData randomize(GeneratedItemBuilder builder) {
|
||||
return this;
|
||||
return new StringListData(new ArrayList<>(list));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,8 +2,8 @@ package net.Indyuce.mmoitems.stat.data.type;
|
||||
|
||||
public interface Mergeable {
|
||||
|
||||
/*
|
||||
* merging two stat data is used when either applying a gem stone to an item
|
||||
/**
|
||||
* Merging two stat data is used when either applying a gem stone to an item
|
||||
* which already has this type of item data, or when generating an item
|
||||
* randomly so that the item benefits from all modifiers
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user