mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Fixed default item type scripts
This commit is contained in:
parent
22d4a22d38
commit
464daef7a8
@ -36,7 +36,7 @@ public class Type implements CooldownObject, PreloadedObject {
|
||||
|
||||
// Blunt
|
||||
public static final Type HAMMER = new Type("HAMMER", true, ModifierSource.MELEE_WEAPON);
|
||||
public static final Type GAUNTLET = new Type("IRON_SHOVEL", true, ModifierSource.MELEE_WEAPON);
|
||||
public static final Type GAUNTLET = new Type("GAUNTLET", true, ModifierSource.MELEE_WEAPON);
|
||||
|
||||
// Range
|
||||
public static final Type WHIP = new Type("WHIP", true, ModifierSource.RANGED_WEAPON);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmoitems.api.crafting;
|
||||
|
||||
import io.lumine.mythic.lib.api.util.PostLoadObject;
|
||||
import io.lumine.mythic.lib.util.PostLoadAction;
|
||||
import io.lumine.mythic.lib.util.PreloadedObject;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.crafting.ingredient.inventory.IngredientInventory;
|
||||
import net.Indyuce.mmoitems.api.crafting.recipe.CheckedRecipe;
|
||||
@ -13,12 +14,13 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CraftingStation extends PostLoadObject {
|
||||
public class CraftingStation implements PreloadedObject {
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final Layout layout;
|
||||
@ -38,8 +40,17 @@ public class CraftingStation extends PostLoadObject {
|
||||
|
||||
private CraftingStation parent;
|
||||
|
||||
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
|
||||
if (!config.contains("parent")) return;
|
||||
|
||||
String id = config.getString("parent").toLowerCase().replace(" ", "-").replace("_", "-");
|
||||
Validate.isTrue(!id.equals(CraftingStation.this.id), "Station cannot use itself as parent");
|
||||
Validate.isTrue(MMOItems.plugin.getCrafting().hasStation(id), "Could not find parent station with ID '" + id + "'");
|
||||
parent = MMOItems.plugin.getCrafting().getStation(id);
|
||||
});
|
||||
|
||||
public CraftingStation(String id, FileConfiguration config) {
|
||||
super(config);
|
||||
postLoadAction.cacheConfig(config);
|
||||
|
||||
this.id = id.toLowerCase().replace("_", "-").replace(" ", "-");
|
||||
this.name = config.getString("name", "Unnamed");
|
||||
@ -59,8 +70,6 @@ public class CraftingStation extends PostLoadObject {
|
||||
}
|
||||
|
||||
public CraftingStation(String id, String name, Layout layout, Sound sound, StationItemOptions itemOptions, int maxQueueSize, CraftingStation parent) {
|
||||
super(null);
|
||||
|
||||
Validate.notNull(id, "Crafting station ID must not be null");
|
||||
Validate.notNull(name, "Crafting station name must not be null");
|
||||
Validate.notNull(sound, "Crafting station sound must not be null");
|
||||
@ -74,6 +83,12 @@ public class CraftingStation extends PostLoadObject {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PostLoadAction getPostLoadAction() {
|
||||
return postLoadAction;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@ -169,16 +184,6 @@ public class CraftingStation extends PostLoadObject {
|
||||
return Math.max(1, (int) Math.ceil((double) recipes / getLayout().getRecipeSlots().size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void whenPostLoaded(ConfigurationSection config) {
|
||||
if (config.contains("parent")) {
|
||||
String id = config.getString("parent").toLowerCase().replace(" ", "-").replace("_", "-");
|
||||
Validate.isTrue(!id.equals(this.id), "Station cannot use itself as parent");
|
||||
Validate.isTrue(MMOItems.plugin.getCrafting().hasStation(id), "Could not find parent station with ID '" + id + "'");
|
||||
parent = MMOItems.plugin.getCrafting().getStation(id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* find type of crafting recipe based on section. there is no 'type' recipe
|
||||
* parameter because old files would be out of date, instead just looks for
|
||||
|
@ -7,7 +7,6 @@ import io.lumine.mythic.lib.comp.flags.CustomFlag;
|
||||
import io.lumine.mythic.lib.damage.AttackMetadata;
|
||||
import io.lumine.mythic.lib.player.PlayerMetadata;
|
||||
import io.lumine.mythic.lib.skill.SimpleSkill;
|
||||
import io.lumine.mythic.lib.skill.Skill;
|
||||
import io.lumine.mythic.lib.skill.SkillMetadata;
|
||||
import io.lumine.mythic.lib.skill.handler.SkillHandler;
|
||||
import io.lumine.mythic.lib.skill.result.SkillResult;
|
||||
@ -23,6 +22,7 @@ import net.Indyuce.mmoitems.api.interaction.util.UntargetedDurabilityItem;
|
||||
import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.LegacyWeapon;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.stat.ActionLeftClick;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -134,7 +134,12 @@ public class Weapon extends UseItem {
|
||||
|
||||
@Nullable
|
||||
private SkillHandler findClickSkill(boolean rightClick) {
|
||||
final String skillId = getNBTItem().getString((rightClick ? ItemStats.RIGHT_CLICK_SCRIPT : ItemStats.LEFT_CLICK_SCRIPT).getNBTPath());
|
||||
String skillId = getNBTItem().getString((rightClick ? ItemStats.RIGHT_CLICK_SCRIPT : ItemStats.LEFT_CLICK_SCRIPT).getNBTPath());
|
||||
|
||||
// (Deprecated) Support for staff spirits on left-clicks
|
||||
if (!rightClick && (skillId == null || skillId.isEmpty()))
|
||||
skillId = getNBTItem().getString(ActionLeftClick.LEGACY_PATH);
|
||||
|
||||
if (skillId == null || skillId.isEmpty()) {
|
||||
|
||||
// Find item type action
|
||||
|
@ -1,8 +1,10 @@
|
||||
package net.Indyuce.mmoitems.api.item.template;
|
||||
|
||||
import io.lumine.mythic.lib.api.util.PostLoadObject;
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
|
||||
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
|
||||
import io.lumine.mythic.lib.util.PostLoadAction;
|
||||
import io.lumine.mythic.lib.util.PreloadedObject;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ItemTier;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
@ -25,7 +27,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class MMOItemTemplate extends PostLoadObject implements ItemReference {
|
||||
public class MMOItemTemplate implements ItemReference, PreloadedObject {
|
||||
private final Type type;
|
||||
private final String id;
|
||||
private final int revId;
|
||||
@ -42,40 +44,7 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference {
|
||||
private ModifierGroup modifierGroup;
|
||||
private final Set<TemplateOption> options = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Public constructor which can be used to register extra item templates
|
||||
* using other addons or plugins
|
||||
*
|
||||
* @param type The item type of your template
|
||||
* @param id The template identifier, it's ok if two templates with
|
||||
* different item types share the same ID
|
||||
*/
|
||||
public MMOItemTemplate(Type type, String id) {
|
||||
super(null);
|
||||
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.revId = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to load MMOItem templates from config files
|
||||
*
|
||||
* @param type The item type of your template
|
||||
* @param config The config file read to load the template
|
||||
*/
|
||||
public MMOItemTemplate(Type type, ConfigurationSection config) {
|
||||
super(config);
|
||||
Validate.notNull(config, "Could not load template config");
|
||||
|
||||
this.type = type;
|
||||
this.id = config.getName().toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
this.revId = config.getInt("base.revision-id", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void whenPostLoaded(ConfigurationSection config) {
|
||||
|
||||
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
|
||||
FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get());
|
||||
ffp.activatePrefix(true, getType().getId() + " " + getId());
|
||||
|
||||
@ -95,7 +64,7 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference {
|
||||
|
||||
// Read modifiers
|
||||
try {
|
||||
modifierGroup = config.contains("modifiers") ? new ModifierGroup(id, config) : null;
|
||||
modifierGroup = config.contains("modifiers") ? new ModifierGroup(getId(), config) : null;
|
||||
if (modifierGroup != null) modifierGroup.getPostLoadAction().performAction();
|
||||
} catch (Exception exception) {
|
||||
ffp.log(FriendlyFeedbackCategory.ERROR, "Could not load modifier group: {0}", exception.getMessage());
|
||||
@ -105,10 +74,9 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference {
|
||||
Validate.notNull(config.getConfigurationSection("base"), FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Could not find base item data"));
|
||||
for (String key : config.getConfigurationSection("base").getKeys(false))
|
||||
try {
|
||||
String id = key.toUpperCase().replace("-", "_");
|
||||
Validate.isTrue(MMOItems.plugin.getStats().has(id), FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Could not find stat with ID '$i{0}$b'", id));
|
||||
|
||||
ItemStat stat = MMOItems.plugin.getStats().get(id);
|
||||
final String id = UtilityMethods.enumName(key);
|
||||
final ItemStat stat = MMOItems.plugin.getStats().get(id);
|
||||
Validate.notNull(stat, FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Could not find stat with ID '$i{0}$b'", id));
|
||||
RandomStatData data = stat.whenInitialized(config.get("base." + key));
|
||||
if (data != null)
|
||||
base.put(stat, data);
|
||||
@ -121,6 +89,42 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference {
|
||||
|
||||
// Print all failures
|
||||
ffp.sendTo(FriendlyFeedbackCategory.INFORMATION, MMOItems.getConsole());
|
||||
});
|
||||
|
||||
/**
|
||||
* Public constructor which can be used to register extra item templates
|
||||
* using other addons or plugins
|
||||
*
|
||||
* @param type The item type of your template
|
||||
* @param id The template identifier, it's ok if two templates with
|
||||
* different item types share the same ID
|
||||
*/
|
||||
public MMOItemTemplate(Type type, String id) {
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.revId = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to load MMOItem templates from config files
|
||||
*
|
||||
* @param type The item type of your template
|
||||
* @param config The config file read to load the template
|
||||
*/
|
||||
public MMOItemTemplate(Type type, ConfigurationSection config) {
|
||||
Validate.notNull(config, "Could not load template config");
|
||||
|
||||
postLoadAction.cacheConfig(config);
|
||||
|
||||
this.type = type;
|
||||
this.id = config.getName().toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
this.revId = config.getInt("base.revision-id", 1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PostLoadAction getPostLoadAction() {
|
||||
return postLoadAction;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -281,8 +285,8 @@ public class MMOItemTemplate extends PostLoadObject implements ItemReference {
|
||||
|
||||
/**
|
||||
* @return Attempts to get the crafted amount registered in the Stat.
|
||||
* <p></p>
|
||||
* Default is <b>1</b> obviously.
|
||||
* <p></p>
|
||||
* Default is <b>1</b> obviously.
|
||||
* @deprecated Don't use this method, the Crafted Amount Stat will be deleted in the near future.
|
||||
*/
|
||||
@Deprecated
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.Indyuce.mmoitems.api.item.template;
|
||||
|
||||
import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.util.PostLoadAction;
|
||||
import io.lumine.mythic.lib.util.PreloadedObject;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
@ -22,7 +22,7 @@ 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 {
|
||||
final String statId = key.toUpperCase().replace("-", "_");
|
||||
final String statId = UtilityMethods.enumName(key);
|
||||
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)));
|
||||
|
@ -109,7 +109,7 @@ public class CraftingManager implements Reloadable {
|
||||
|
||||
for (CraftingStation station : stations.values())
|
||||
try {
|
||||
station.postLoad();
|
||||
station.getPostLoadAction().performAction();
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING,
|
||||
"Could not post-load station '" + station.getId() + "': " + exception.getMessage());
|
||||
|
@ -172,7 +172,7 @@ public class TemplateManager implements Reloadable {
|
||||
|
||||
try {
|
||||
MMOItemTemplate template = new MMOItemTemplate(type, type.getConfigFile().getConfig().getConfigurationSection(id));
|
||||
template.postLoad();
|
||||
template.getPostLoadAction().performAction();
|
||||
registerTemplate(template);
|
||||
return template;
|
||||
|
||||
@ -327,7 +327,7 @@ public class TemplateManager implements Reloadable {
|
||||
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Loading item templates, please wait...");
|
||||
templates.forEach(template -> {
|
||||
try {
|
||||
template.postLoad();
|
||||
template.getPostLoadAction().performAction();
|
||||
} catch (IllegalArgumentException exception) {
|
||||
ffp.activatePrefix(true, "Item Templates \u00a78($r" + template.getType().getId() + "\u00a78)");
|
||||
ffp.log(FriendlyFeedbackCategory.INFORMATION, "Could not post-load item template '" + template.getId() + "': " + exception.getMessage());
|
||||
|
@ -12,7 +12,6 @@ import net.Indyuce.mmoitems.stat.data.StringData;
|
||||
import net.Indyuce.mmoitems.stat.type.StringStat;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -21,7 +20,7 @@ public class ActionLeftClick extends StringStat {
|
||||
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(LEGACY_PATH);
|
||||
setAliases(LEGACY_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,44 +38,25 @@ public class ActionLeftClick extends StringStat {
|
||||
// No lore insertion
|
||||
}
|
||||
|
||||
private static final String LEGACY_PATH = "STAFF_SPIRIT";
|
||||
public static final String LEGACY_ID = "STAFF_SPIRIT";
|
||||
public static final String LEGACY_PATH = "MMOITEMS_" + LEGACY_ID;
|
||||
|
||||
// TODO refactor with stat categories
|
||||
@Override
|
||||
@Deprecated
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||
|
||||
// New path
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
|
||||
// Legacy path
|
||||
if (mmoitem.getNBT().hasTag(LEGACY_PATH))
|
||||
relevantTags.add(ItemTag.getTagAtPath(LEGACY_PATH, mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
relevantTags.add(new ItemTag(getNBTPath(), ItemTag.getTagAtPath(LEGACY_PATH, mmoitem.getNBT(), SupportedNBTTagValues.STRING).getValue()));
|
||||
|
||||
StringData bakedData = getLoadedNBT(relevantTags);
|
||||
if (bakedData != null) mmoitem.setData(this, bakedData);
|
||||
}
|
||||
|
||||
// TODO refactor with stat categories
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
public StringData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
|
||||
// New path
|
||||
ItemTag tg = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
if (tg != null) {
|
||||
String value = (String) tg.getValue();
|
||||
return new StringData(value);
|
||||
}
|
||||
|
||||
// Legacy path
|
||||
tg = ItemTag.getTagAtPath(LEGACY_PATH, storedTags);
|
||||
if (tg != null) {
|
||||
String value = (String) tg.getValue();
|
||||
return new StringData(value);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ HAMMER:
|
||||
on-attack: blunt_attack_effect
|
||||
|
||||
GAUNTLET:
|
||||
display: IRON_HORSE_ARMOR
|
||||
display: IRON_SHOVEL
|
||||
name: 'Gauntlet'
|
||||
unident-item:
|
||||
name: '&f#prefix#Unidentified Gauntlet'
|
||||
@ -109,7 +109,7 @@ WHIP:
|
||||
- '{tier}&8- &7Item Tier: #prefix##tier#'
|
||||
|
||||
disable-melee-attacks: true
|
||||
on-left-click: whip_attack_effect
|
||||
on-left-click: whip_attack
|
||||
on-attack: slashing_attack_effect
|
||||
|
||||
STAFF:
|
||||
|
Loading…
Reference in New Issue
Block a user