mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-02 11:21:20 +01:00
!Fixed template preloading and editing
This commit is contained in:
parent
7bccc1b922
commit
da3bc90f6c
@ -89,9 +89,10 @@ import net.mmogroup.mmolib.api.player.MMOPlayerData;
|
|||||||
import net.mmogroup.mmolib.version.SpigotPlugin;
|
import net.mmogroup.mmolib.version.SpigotPlugin;
|
||||||
|
|
||||||
public class MMOItems extends JavaPlugin {
|
public class MMOItems extends JavaPlugin {
|
||||||
/* Introducing: The commit comment!
|
|
||||||
* Just change this a tiny bit each time you
|
/*
|
||||||
* need to push a new build. It's convenient!
|
* Introducing: The commit comment! Just change this a tiny bit each time
|
||||||
|
* you need to push a new build. It's convenient!
|
||||||
*/
|
*/
|
||||||
public static MMOItems plugin;
|
public static MMOItems plugin;
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ public class MMOItems extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
statManager = new StatManager();
|
statManager = new StatManager();
|
||||||
typeManager.reload();
|
typeManager.reload();
|
||||||
templateManager.loadCompatibility();
|
templateManager.preloadTemplates();
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null)
|
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null)
|
||||||
new MMOCoreMMOLoader();
|
new MMOCoreMMOLoader();
|
||||||
@ -180,11 +181,12 @@ public class MMOItems extends JavaPlugin {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* After tiers, sets and upgrade templates are loaded, MI template data
|
* After tiers, sets and upgrade templates are loaded, MI template data
|
||||||
* CAN be fully loaded
|
* can be fully loaded
|
||||||
*/
|
*/
|
||||||
tierManager = new TierManager();
|
tierManager = new TierManager();
|
||||||
setManager = new SetManager();
|
setManager = new SetManager();
|
||||||
upgradeManager = new UpgradeManager();
|
upgradeManager = new UpgradeManager();
|
||||||
|
templateManager.postloadTemplates();
|
||||||
|
|
||||||
dropTableManager = new DropTableManager();
|
dropTableManager = new DropTableManager();
|
||||||
dynamicUpdater = new UpdaterManager();
|
dynamicUpdater = new UpdaterManager();
|
||||||
@ -301,7 +303,6 @@ public class MMOItems extends JavaPlugin {
|
|||||||
if (getConfig().getBoolean("recipes.use-recipe-book"))
|
if (getConfig().getBoolean("recipes.use-recipe-book"))
|
||||||
RecipeBookUtil.enableBook();
|
RecipeBookUtil.enableBook();
|
||||||
|
|
||||||
|
|
||||||
// amount and bukkit recipes
|
// amount and bukkit recipes
|
||||||
getLogger().log(Level.INFO, "Loading recipes, please wait...");
|
getLogger().log(Level.INFO, "Loading recipes, please wait...");
|
||||||
recipeManager.loadRecipes();
|
recipeManager.loadRecipes();
|
||||||
|
@ -20,8 +20,9 @@ import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
|||||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||||
|
import net.mmogroup.mmolib.api.util.PostLoadObject;
|
||||||
|
|
||||||
public class MMOItemTemplate implements ItemReference {
|
public class MMOItemTemplate extends PostLoadObject implements ItemReference {
|
||||||
private final Type type;
|
private final Type type;
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
@ -42,6 +43,8 @@ public class MMOItemTemplate implements ItemReference {
|
|||||||
* different item types share the same ID
|
* different item types share the same ID
|
||||||
*/
|
*/
|
||||||
public MMOItemTemplate(Type type, String id) {
|
public MMOItemTemplate(Type type, String id) {
|
||||||
|
super(null);
|
||||||
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
@ -55,11 +58,15 @@ public class MMOItemTemplate implements ItemReference {
|
|||||||
* The config file read to load the template
|
* The config file read to load the template
|
||||||
*/
|
*/
|
||||||
public MMOItemTemplate(Type type, ConfigurationSection config) {
|
public MMOItemTemplate(Type type, ConfigurationSection config) {
|
||||||
|
super(config);
|
||||||
Validate.notNull(config, "Could not load template config");
|
Validate.notNull(config, "Could not load template config");
|
||||||
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.id = config.getName().toUpperCase().replace("-", "_").replace(" ", "_");
|
this.id = config.getName().toUpperCase().replace("-", "_").replace(" ", "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void whenPostLoaded(ConfigurationSection config) {
|
||||||
if (config.contains("option"))
|
if (config.contains("option"))
|
||||||
for (TemplateOption option : TemplateOption.values())
|
for (TemplateOption option : TemplateOption.values())
|
||||||
if (config.getBoolean("option." + option.name().toLowerCase().replace("_", "-")))
|
if (config.getBoolean("option." + option.name().toLowerCase().replace("_", "-")))
|
||||||
|
@ -113,6 +113,7 @@ public class TemplateManager {
|
|||||||
try {
|
try {
|
||||||
MMOItemTemplate template = new MMOItemTemplate(type,
|
MMOItemTemplate template = new MMOItemTemplate(type,
|
||||||
type.getConfigFile().getConfig().getConfigurationSection(id));
|
type.getConfigFile().getConfig().getConfigurationSection(id));
|
||||||
|
template.postLoad();
|
||||||
registerTemplate(template);
|
registerTemplate(template);
|
||||||
return template;
|
return template;
|
||||||
|
|
||||||
@ -174,6 +175,58 @@ public class TemplateManager {
|
|||||||
return (int) found;
|
return (int) found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Templates must be loaded whenever MMOItems enables so that other plugins
|
||||||
|
* like MMOCore can load template references in drop items or other objects.
|
||||||
|
* Template data is only loaded when MMOItems enables, once sets, tiers..
|
||||||
|
* are initialized
|
||||||
|
*/
|
||||||
|
public void preloadTemplates() {
|
||||||
|
for (Type type : MMOItems.plugin.getTypes().getAll()) {
|
||||||
|
FileConfiguration config = type.getConfigFile().getConfig();
|
||||||
|
for (String key : config.getKeys(false))
|
||||||
|
try {
|
||||||
|
registerTemplate(new MMOItemTemplate(type, config.getConfigurationSection(key)));
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
MMOItems.plugin.getLogger().log(Level.INFO, "Could not preload item template '" + key + "': " + exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads item generator modifiers and post load item templates.
|
||||||
|
*/
|
||||||
|
public void postloadTemplates() {
|
||||||
|
|
||||||
|
MMOItems.plugin.getLogger().log(Level.INFO, "Loading template modifiers, please wait..");
|
||||||
|
for (File file : new File(MMOItems.plugin.getDataFolder() + "/modifiers").listFiles()) {
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
for (String key : config.getKeys(false))
|
||||||
|
try {
|
||||||
|
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
|
||||||
|
modifiers.put(modifier.getId(), modifier);
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
MMOItems.plugin.getLogger().log(Level.INFO, "Could not load template modifier '" + key + "': " + exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MMOItems.plugin.getLogger().log(Level.INFO, "Loading item templates, please wait..");
|
||||||
|
templates.forEach(template -> {
|
||||||
|
try {
|
||||||
|
template.postLoad();
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
MMOItems.plugin.getLogger().log(Level.INFO, "Could not load item template '" + template.getId() + "': " + exception.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads the item templates. This is the method used to reload the manager
|
||||||
|
* when the server is already running. It clears all the maps and loads
|
||||||
|
* everything again. Template references in other plugins like MMOCore must
|
||||||
|
* be refreshed afterwards.
|
||||||
|
*/
|
||||||
public void reload() {
|
public void reload() {
|
||||||
templates.clear();
|
templates.clear();
|
||||||
modifiers.clear();
|
modifiers.clear();
|
||||||
@ -186,8 +239,7 @@ public class TemplateManager {
|
|||||||
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
|
TemplateModifier modifier = new TemplateModifier(config.getConfigurationSection(key));
|
||||||
modifiers.put(modifier.getId(), modifier);
|
modifiers.put(modifier.getId(), modifier);
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOItems.plugin.getLogger().log(Level.INFO,
|
MMOItems.plugin.getLogger().log(Level.INFO, "Could not load template modifier '" + key + "': " + exception.getMessage());
|
||||||
"Could not load template modifier '" + key + "': " + exception.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,28 +250,8 @@ public class TemplateManager {
|
|||||||
try {
|
try {
|
||||||
registerTemplate(new MMOItemTemplate(type, config.getConfigurationSection(key)));
|
registerTemplate(new MMOItemTemplate(type, config.getConfigurationSection(key)));
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOItems.plugin.getLogger().log(Level.INFO,
|
MMOItems.plugin.getLogger().log(Level.INFO, "Could not load item template '" + key + "': " + exception.getMessage());
|
||||||
"Could not load item template '" + key + "': " + exception.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this loads dummy items for on load so
|
|
||||||
// plugins that enable before mmoitems that use
|
|
||||||
// items (mmocore) don't error out and need
|
|
||||||
// a reload
|
|
||||||
public void loadCompatibility() {
|
|
||||||
templates.clear();
|
|
||||||
|
|
||||||
for (Type type : MMOItems.plugin.getTypes().getAll()) {
|
|
||||||
FileConfiguration config = type.getConfigFile().getConfig();
|
|
||||||
for (String key : config.getKeys(false))
|
|
||||||
try {
|
|
||||||
registerTemplate(new MMOItemTemplate(type, key));
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user