!Some javadocs

This commit is contained in:
Indyuce 2020-08-09 09:50:15 +02:00
parent 6461c31ab3
commit 9a23f6ae5e
6 changed files with 146 additions and 63 deletions

View File

@ -39,10 +39,6 @@ public abstract class Ability {
this.allowedModes = Arrays.asList(allowedModes);
}
public void addModifier(String modifierPath, double defaultValue) {
modifiers.put(modifierPath, defaultValue);
}
public String getID() {
return id;
}
@ -63,6 +59,10 @@ public abstract class Ability {
return allowedModes.contains(castingMode);
}
/**
* @return The list of all the casting modes which are compatible with this
* ability
*/
public List<CastingMode> getSupportedCastingModes() {
return allowedModes;
}
@ -75,48 +75,83 @@ public abstract class Ability {
return modifiers.keySet();
}
/*
* when that boolean is set to false, the ability will not register when the
* plugin enables which prevents it from being registered in the ability
* manager from MMOItems
public void addModifier(String modifier, double defaultValue) {
modifiers.put(modifier, defaultValue);
}
/**
* Disables an ability. This method must be called before MMOItems registers
* this ability since it is just a boolean check when registering abilities
* through the abilityManager
*/
public void disable() {
enabled = false;
}
/*
* these methods need to be overriden by ability classes depending on their
* ability type
/**
* The first method called when a player uses an ability.
*
* @param stats
* Cached statistics of the player casting the ability
* @param target
* The eventual ability target
* @param ability
* The ability being cast
* @param result
* The melee attack result, which can be edited to
* increase/decrease final damage dealt
* @return If the ability can be cast or not. AbilityResult should cache any
* information used by the ability: target if found, etc.
*/
public abstract AbilityResult whenRan(CachedStats stats, LivingEntity target, AbilityData ability, ItemAttackResult result);
/**
* Called when a player successfully casts an ability
*
* @param stats
* Cached statistics of the player casting the ability
* @param ability
* All the information about the ability being cast. This is the
* same instance as the one returned in whenRan(..)
* @param result
* The melee attack result, which can be edited to
* increase/decrease final damage dealt
*/
public abstract void whenCast(CachedStats stats, AbilityResult ability, ItemAttackResult result);
public enum CastingMode {
/*
* when the player hits another entity.
/**
* When the player hits another entity
*/
ON_HIT(false),
/*
* when the player is hit by another entity
/**
* When the player is hit by another entity
*/
WHEN_HIT(false),
/*
* when the player performs a simple click
/**
* When the player performs a left click
*/
LEFT_CLICK,
/**
* When the player performs a right click
*/
RIGHT_CLICK,
/*
* when the player performs a simple click while sneaking
/**
* Performing a left click while sneaking
*/
SHIFT_LEFT_CLICK,
/**
* Performing a right click while sneaking
*/
SHIFT_RIGHT_CLICK;
private boolean message;
private final boolean message;
private CastingMode() {
this(true);
@ -134,7 +169,7 @@ public abstract class Ability {
return MMOUtils.caseOnWords(name().toLowerCase().replace("_", " "));
}
public String getLowerCaseID() {
public String getLowerCaseId() {
return name().toLowerCase().replace("_", "-");
}

View File

@ -21,6 +21,16 @@ public class MMOItem {
*/
private final Map<ItemStat, StatData> stats = new LinkedHashMap<>();
/**
* Constructor used to generate an ItemStack based on some stat data
*
* @param type
* The type of the item you want to create
* @param id
* The id of the item, make sure it is different from other
* existing items not to interfere with MI features like the
* dynamic item updater
*/
public MMOItem(Type type, String id) {
this.type = type;
this.id = id;
@ -38,6 +48,10 @@ public class MMOItem {
stats.put(stat, data);
}
public void replaceData(ItemStat stat, StatData data) {
stats.replace(stat, data);
}
public void removeData(ItemStat stat) {
stats.remove(stat);
}
@ -50,6 +64,9 @@ public class MMOItem {
return stats.containsKey(stat);
}
/**
* @return Collection of all item stats which have some data on this mmoitem
*/
public Set<ItemStat> getStats() {
return stats.keySet();
}
@ -58,13 +75,14 @@ public class MMOItem {
return new MMOItemBuilder(this);
}
/***
* @return A closed instance of this mmoitem. This does NOT clone the
* StatData instances! If you edit these statDatas, the previous
* mmoitem will be edited as well.
*/
public MMOItem clone() {
MMOItem clone = new MMOItem(type, id);
stats.forEach((stat, data) -> clone.stats.put(stat, data));
return clone;
}
public void replaceData(ItemStat stat, StatData data) {
stats.replace(stat, data);
}
}

View File

@ -39,15 +39,20 @@ public class MMOItemBuilder {
private final MMOItemLore lore = new MMOItemLore();
private final List<ItemTag> tags = new ArrayList<>();
private static final AttributeModifier fakeModifier = new AttributeModifier(
UUID.fromString("87851e28-af12-43f6-898e-c62bde6bd0ec"), "mmoitemsDecoy", 0, Operation.ADD_NUMBER);
private static final AttributeModifier fakeModifier = new AttributeModifier(UUID.fromString("87851e28-af12-43f6-898e-c62bde6bd0ec"),
"mmoitemsDecoy", 0, Operation.ADD_NUMBER);
/***
* Used to build an MMOItem into an ItemStack
*
* @param mmoitem
* The mmoitem you want to build
*/
public MMOItemBuilder(MMOItem mmoitem) {
this.mmoitem = mmoitem;
item = new ItemStack(
mmoitem.hasData(ItemStat.MATERIAL) ? ((MaterialData) mmoitem.getData(ItemStat.MATERIAL)).getMaterial()
: Material.DIAMOND_SWORD);
mmoitem.hasData(ItemStat.MATERIAL) ? ((MaterialData) mmoitem.getData(ItemStat.MATERIAL)).getMaterial() : Material.DIAMOND_SWORD);
meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
@ -55,8 +60,7 @@ public class MMOItemBuilder {
tags.add(new ItemTag("MMOITEMS_ITEM_ID", mmoitem.getId()));
if (MMOItems.plugin.getUpdater().hasData(mmoitem))
tags.add(new ItemTag("MMOITEMS_ITEM_UUID",
MMOItems.plugin.getUpdater().getData(mmoitem).getUniqueId().toString()));
tags.add(new ItemTag("MMOITEMS_ITEM_UUID", MMOItems.plugin.getUpdater().getData(mmoitem).getUniqueId().toString()));
}
public MMOItemLore getLore() {
@ -87,8 +91,8 @@ public class MMOItemBuilder {
try {
stat.whenApplied(this, mmoitem.getData(stat));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occurred while trying to generate item '"
+ mmoitem.getId() + "' with stat '" + stat.getId() + "': " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occurred while trying to generate item '" + mmoitem.getId() + "' with stat '"
+ stat.getId() + "': " + exception.getMessage());
}
// lore
@ -96,15 +100,15 @@ public class MMOItemBuilder {
lore.insert("gem-stone-lore", ItemStat.translate("gem-stone-lore"));
lore.insert("item-type",
ItemStat.translate("item-type").replace("#",
mmoitem.getStats().contains(ItemStat.DISPLAYED_TYPE)
? ((StringData) mmoitem.getData(ItemStat.DISPLAYED_TYPE)).toString()
mmoitem.getStats().contains(ItemStat.DISPLAYED_TYPE) ? ((StringData) mmoitem.getData(ItemStat.DISPLAYED_TYPE)).toString()
: mmoitem.getType().getName()));
meta.setLore(lore.build().toStringList());
/*
* this tag is added to entirely override default vanilla item attribute
* modifiers, this way armor gives no ARMOR or ARMOR TOUGHNESS to the holder.
* since 4.7 attributes are handled via custom calculations
* modifiers, this way armor gives no ARMOR or ARMOR TOUGHNESS to the
* holder. since 4.7 attributes are handled via custom calculations
*/
try {
@ -113,8 +117,9 @@ public class MMOItemBuilder {
return MMOLib.plugin.getNMS().getNBTItem(item).addTag(tags);
/*
* on legacy spigot, it is not required to add a fake modifier to the modifier
* list, so just override the string tag and it works fine.
* on legacy spigot, it is not required to add a fake modifier to
* the modifier list, so just override the string tag and it works
* fine.
*/
} catch (NoSuchMethodError exception) {
item.setItemMeta(meta);
@ -124,6 +129,9 @@ public class MMOItemBuilder {
}
}
/**
* @return Builds an ItemStack
*/
public ItemStack build() {
return buildNBT().toItem();
}
@ -133,14 +141,14 @@ public class MMOItemBuilder {
private final UpgradeData upgradeData;
/*** @deprecated will be improved with mmoitems 6
/***
* @deprecated will be improved with mmoitems 6
*
* @param mmoitem
*/
public StatLore(MMOItem mmoitem) {
this.mmoitem = mmoitem.clone();
this.upgradeData = ((UpgradeData) mmoitem.getData(ItemStat.UPGRADE));
}
public MMOItem getMMOItem() {
@ -154,8 +162,7 @@ public class MMOItemBuilder {
}
public MMOItem generateNewItem() {
if (MMOItems.plugin.getConfig().getBoolean("item-upgrading.display-stat-changes", false)
&& isUpgradable()) {
if (MMOItems.plugin.getConfig().getBoolean("item-upgrading.display-stat-changes", false) && isUpgradable()) {
if (upgradeData.getLevel() > 0)
for (ItemStat stat : upgradeData.getTemplate().getKeys()) {
UpgradeInfo upgradeInfo = upgradeData.getTemplate().getUpgradeInfo(stat);
@ -175,10 +182,8 @@ public class MMOItemBuilder {
if (value > 0)
lore.insert(stat.getPath(), stat.format(value, "#", new StatFormat("##").format(value))
+ new ColorParse(MMOItems.plugin.getConfig()
.getString("item-upgrading.stat-change-suffix", " &e(+#stat#)")
.replace("#stat#", new StatFormat("##").format(value - getBase(stat))))
.toChatColor());
+ new ColorParse(MMOItems.plugin.getConfig().getString("item-upgrading.stat-change-suffix", " &e(+#stat#)")
.replace("#stat#", new StatFormat("##").format(value - getBase(stat)))).toChatColor());
}
}
}
@ -193,8 +198,7 @@ public class MMOItemBuilder {
// does inverse math to get the base
if (info.isRelative()) {
double upgradeAmount = ((DoubleStat.DoubleUpgradeInfo) upgradeData.getTemplate()
.getUpgradeInfo(stat)).getAmount();
double upgradeAmount = ((DoubleStat.DoubleUpgradeInfo) upgradeData.getTemplate().getUpgradeInfo(stat)).getAmount();
for (int i = 1; i <= level; i++) {
value /= 1 + upgradeAmount;

View File

@ -10,6 +10,16 @@ import net.asangarin.hexcolors.ColorParse;
public class MMOItemLore {
private final List<String> lore = MMOItems.plugin.getLanguage().getDefaultLoreFormat();
/**
* Inserts a list of strings in the item lore. The lines are added only if a
* line #item-stat-id# can be found in the lore format.
*
* @param path
* The path of the stat, used to locate where to insert the stat
* in the lore
* @param add
* The lines you want to add
*/
public void insert(String path, String... add) {
int index = lore.indexOf("#" + path + "#");
if (index < 0)
@ -20,6 +30,16 @@ public class MMOItemLore {
lore.remove(index);
}
/**
* Inserts a list of strings in the item lore. The lines are added only if a
* line #item-stat-id# can be found in the lore format.
*
* @param path
* The path of the stat, used to locate where to insert the stat
* in the lore
* @param add
* The lines you want to add
*/
public void insert(String path, List<String> list) {
int index = lore.indexOf("#" + path + "#");
if (index < 0)
@ -29,6 +49,11 @@ public class MMOItemLore {
lore.remove(index);
}
/**
* @return A built item lore. This method must be called after all lines
* have been inserted in the lore. It cleans all unused lore format
* # lines as well as lore bars
*/
public MMOItemLore build() {
/*
@ -40,18 +65,15 @@ public class MMOItemLore {
String line = lore.get(n);
// removed unused placeholders
if (line.startsWith("#")) {
if (line.startsWith("#"))
lore.remove(n);
continue;
}
// remove useless lore stripes
if (line.startsWith("{bar}") && (n == lore.size() - 1 || isBar(lore.get(n + 1)))) {
else if (line.startsWith("{bar}") && (n == lore.size() - 1 || isBar(lore.get(n + 1))))
lore.remove(n);
continue;
}
j++;
else
j++;
}
/*

View File

@ -141,8 +141,8 @@ public class ConfigManager {
abilities.getConfig().set("modifier." + modifier, MMOUtils.caseOnWords(modifier.replace("-", " ")));
}
for (CastingMode mode : CastingMode.values())
if (!abilities.getConfig().contains("cast-mode." + mode.getLowerCaseID()))
abilities.getConfig().set("cast-mode." + mode.getLowerCaseID(), mode.getName());
if (!abilities.getConfig().contains("cast-mode." + mode.getLowerCaseId()))
abilities.getConfig().set("cast-mode." + mode.getLowerCaseId(), mode.getName());
abilities.save();
ConfigFile potionEffects = new ConfigFile("/language", "potion-effects");
@ -232,7 +232,7 @@ public class ConfigManager {
}
public String getCastingModeName(CastingMode mode) {
return abilities.getConfig().getString("cast-mode." + mode.getLowerCaseID());
return abilities.getConfig().getString("cast-mode." + mode.getLowerCaseId());
}
public String getModifierName(String path) {

View File

@ -1,11 +1,15 @@
package net.Indyuce.mmoitems.stat.type;
/**
* Proper statistics are gem stone statistics which must NOT be applied onto an
* item when socketing the gem stone. For instance, 'Success Rate' is a gem
* stone stat but it must not be transfered onto the item.
*
* @author cympe
*/
public interface ProperStat {
/*
* proper stats are statistics which are proper to the item and which cannot
* be modified when applying a gem stone! for instance, "Success Rate" is a
* stat for gem stones but must not be applied onto the item when a gem
* stone with X Success Rate is being used!
* No method is required.
*/
}