Custom item types commit 4

This commit is contained in:
Jules 2024-01-29 04:00:35 +01:00
parent d9b2f2ab43
commit e5a9fc9129
7 changed files with 54 additions and 17 deletions

View File

@ -22,10 +22,9 @@ public class TemplateModifier extends ModifierNode {
Validate.notNull(config.getConfigurationSection("stats"), "Could not find base item data");
for (String key : config.getConfigurationSection("stats").getKeys(false))
try {
String id = key.toUpperCase().replace("-", "_");
Validate.isTrue(MMOItems.plugin.getStats().has(id), "Could not find stat with ID '" + id + "'");
ItemStat stat = MMOItems.plugin.getStats().get(id);
final String statId = key.toUpperCase().replace("-", "_");
final ItemStat stat = MMOItems.plugin.getStats().get(statId);
Validate.notNull(stat, "Could not find stat with ID '" + statId + "'");
TemplateModifier.this.data.put(stat, stat.whenInitialized(config.get("stats." + key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "An error occurred while trying to load modifier node " + getId() + ": " + exception.getMessage());

View File

@ -170,7 +170,7 @@ public class ItemUse implements Listener {
SpecialWeaponAttackEvent called = new SpecialWeaponAttackEvent(usableItem.getPlayerData(), (Weapon) usableItem, target);
Bukkit.getPluginManager().callEvent(called);
if (!called.isCancelled())
new SimpleSkill(onEntityInteract).cast(new TriggerMetadata(usableItem.getPlayerData().getMMOPlayerData(), TriggerType.API));
new SimpleSkill(onEntityInteract).cast(new TriggerMetadata(usableItem.getPlayerData().getMMOPlayerData(), TriggerType.API, target));
}
}

View File

@ -191,6 +191,10 @@ public class StatManager {
stats.put(stat.getId(), stat);
// Register aliases (does NOT support custom registries)
for (String alias : stat.getAliases())
stats.put(alias, stat);
// Custom registries
if (stat instanceof DoubleStat && !(stat instanceof GemStoneStat) && stat.isCompatible(Type.GEM_STONE))
numeric.add((DoubleStat) stat);

View File

@ -1,8 +1,8 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.skill.handler.SkillHandler;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
@ -13,20 +13,24 @@ import org.jetbrains.annotations.NotNull;
public class ActionLeftClick extends StringStat {
public ActionLeftClick() {
super("ON_LEFT_CLICK", Material.COMMAND_BLOCK_MINECART, "Left Click Script", new String[]{"Name of script ran when left clicking. When used,", "The item will naturally apply item costs like", "mana, stamina, cooldown. This option overrides the", "script provided by the item type."}, new String[]{"weapon"});
super("ON_LEFT_CLICK", Material.COMMAND_BLOCK_MINECART, "Left Click Action", new String[]{"ID of skill ran when left clicking. When used,", "The item will naturally apply item costs like", "mana, stamina, cooldown. This option overrides the", "script provided by the item type."}, new String[]{"weapon"});
// Staff spirit set as alias
setAliases("STAFF_SPIRIT");
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
final SkillHandler<?> script = MythicLib.plugin.getSkills().getHandlerOrThrow(message);
inv.getEditedSection().set(getPath(), script.getId());
final String format = UtilityMethods.enumName(message);
MythicLib.plugin.getSkills().getHandlerOrThrow(format);
inv.getEditedSection().set(getPath(), format);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to '" + script.getId() + "'");
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to '" + format + "'");
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
item.addItemTag(new ItemTag(getNBTPath(), data.toString()));
item.addItemTag(new ItemTag(getNBTPath(), UtilityMethods.enumName(data.toString())));
// No lore insertion
}
}

View File

@ -1,8 +1,8 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.skill.handler.SkillHandler;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
@ -13,20 +13,21 @@ import org.jetbrains.annotations.NotNull;
public class ActionRightClick extends StringStat {
public ActionRightClick() {
super("ON_RIGHT_CLICK", Material.COMMAND_BLOCK_MINECART, "Right Click Script", new String[]{"Name of script ran when right clicking. When used,", "The item will naturally apply item costs like", "mana, stamina, cooldown. This option overrides the", "script provided by the item type."}, new String[]{"weapon"});
super("ON_RIGHT_CLICK", Material.COMMAND_BLOCK_MINECART, "Right Click Action", new String[]{"ID of skill ran when right clicking. When used,", "The item will naturally apply item costs like", "mana, stamina, cooldown. This option overrides the", "script provided by the item type."}, new String[]{"weapon"});
}
@Override
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
final SkillHandler<?> script = MythicLib.plugin.getSkills().getHandlerOrThrow(message);
inv.getEditedSection().set(getPath(), script.getId());
final String format = UtilityMethods.enumName(message);
MythicLib.plugin.getSkills().getHandlerOrThrow(format);
inv.getEditedSection().set(getPath(), format);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to '" + script.getId() + "'");
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to '" + format + "'");
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
item.addItemTag(new ItemTag(getNBTPath(), data.toString()));
item.addItemTag(new ItemTag(getNBTPath(), UtilityMethods.enumName(data.toString())));
// No lore insertion
}
}

View File

@ -29,6 +29,9 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
private final List<String> compatibleTypes;
private final List<Material> compatibleMaterials;
@Nullable
private String[] aliases = {};
/**
* The stat can be enabled or not, depending on the server version to
* prevent from displaying useless editable stats in the edition menu.
@ -193,6 +196,25 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
return id;
}
/**
* Mainly for backwards compatibility. Aliases are basically
* other string identifiers that point to the same item stat.
* Useful when changing stat keys inside the item configs.
*
* Aliases have to follow the UPPER_CASE stat identifier format.
*/
@Nullable
public String[] getAliases() {
return aliases;
}
/**
* @see #getAliases()
*/
public void setAliases(String... aliases) {
this.aliases = aliases;
}
/**
* @return The stat ID
* @deprecated Use getId() instead. Type is no longer an util since they can

View File

@ -93,6 +93,7 @@ GAUNTLET:
- '{tier}&8- &7Item Tier: #prefix##tier#'
on-attack: blunt_attack_effect
on-entity-interact: gauntlet_special_attack
WHIP:
display: LEAD
@ -107,6 +108,10 @@ WHIP:
- '{range}&8- &7Lvl Range: &e#range#'
- '{tier}&8- &7Item Tier: #prefix##tier#'
disable-melee-attacks: true
on-left-click:
STAFF:
display: DIAMOND_HOE
name: 'Staff'
@ -123,6 +128,7 @@ STAFF:
disable-melee-attacks: true
on-left-click: staff_default
attack-cooldown-key: "staff"
on-entity-interact: staff_special_attack # Special action when right-clicking entities
BOW:
display: BOW
@ -570,6 +576,7 @@ WAND:
disable-melee-attacks: true
on-left-click: staff_default
attack-cooldown-key: "staff"
on-entity-interact: staff_special_attack # Special action when right-clicking entities
GREATBOW:
display: BOW