Add basic things:

- Added util to handle config loading and unloading
- Added some base structs for spells
- Added base spell package
This commit is contained in:
2023-05-31 16:33:06 -04:00
commit cca8ae9a55
8 changed files with 313 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package me.sticksdev.runicspells;
import me.sticksdev.runicspells.utils.Yaml;
import org.bukkit.plugin.java.JavaPlugin;
public final class Runic_spells extends JavaPlugin {
public static Runic_spells instance;
private final Yaml config = new Yaml(this); // TODO: Maybe make this use instance instead of this - was dealing with a null pointer exception
@Override
public void onEnable() {
// Plugin startup logic
instance = this;
getLogger().info("Runic Spells has been enabled!");
getLogger().info("Loading config...");
config.init();
}
@Override
public void onDisable() {
config.destroy();
}
public static Runic_spells getInstance() {
return instance;
}
}

View File

@ -0,0 +1,10 @@
package me.sticksdev.runicspells.structures;
/**
* The base class for spells, only contains a name and a description
*/
public class BaseSpell {
public String name;
public String description;
}

View File

@ -0,0 +1,19 @@
package me.sticksdev.runicspells.structures;
public class ItemBasedSpell extends BaseSpell {
// Spell that uses minecraft in-game item to use/cast
public String item;
public int amount;
public int cooldown;
public int manaCost;
public ItemBasedSpell(String name, String description, String item, int amount, int cooldown, int manaCost) {
this.name = name;
this.description = description;
this.item = item;
this.amount = amount;
this.cooldown = cooldown;
this.manaCost = manaCost;
}
}

View File

@ -0,0 +1,64 @@
package me.sticksdev.runicspells.utils;
import me.sticksdev.runicspells.Runic_spells;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public class Yaml {
// Basic YAML Loader and data holder for minecraft plugins
private final Runic_spells plugin;
public FileConfiguration spellsConfig;
private File spellsFilePath;
public Yaml(Runic_spells plugin) {
this.plugin = plugin;
}
/**
* Loads the config file from the plugin's data folder or creates it if it doesn't exist
*/
public void init() {
spellsFilePath = new File(plugin.getDataFolder(), "spells.yml");
if (!spellsFilePath.exists()) {
plugin.getLogger().info("Spells.yml not found, creating...");
spellsFilePath.getParentFile().mkdirs();
plugin.saveResource("spells.yml", false);
}
spellsConfig = new YamlConfiguration();
try {
spellsConfig.load(spellsFilePath);
plugin.getLogger().info("Spells.yml loaded!");
} catch (IOException | InvalidConfigurationException e) {
plugin.getLogger().warning("Spells.yml failed to load - see stack trace below:");
e.printStackTrace();
}
}
/**
* Cleans up when plugin is disabled
*/
public void destroy() {
spellsConfig = null;
spellsFilePath = null;
}
/**
* Returns the currently loaded config file
* @return FileConfiguration
* @throws IllegalStateException if the config file hasn't been loaded yet
*/
public FileConfiguration getConfig() {
if (spellsConfig == null) {
throw new IllegalStateException("YamlError: Config not loaded yet, have you called init()?");
}
return spellsConfig;
}
}

View File

@ -0,0 +1,4 @@
name: runic-spells
version: '${project.version}'
main: me.sticksdev.runicspells.Runic_spells
api-version: 1.19

View File

@ -0,0 +1 @@
# Spells configuration file