123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package me.km.api;
- import java.io.File;
- import me.hammerle.snuviscript.code.Script;
- import me.hammerle.snuviscript.config.SnuviConfig;
- import me.km.dimensions.ModDimensions;
- import me.km.exception.IllegalItemStackStringException;
- import me.km.utils.ItemStackUtils;
- import net.minecraft.item.ItemStack;
- public class SimpleConfig extends SnuviConfig
- {
- public SimpleConfig(Module m, String path, String name, boolean load)
- {
- super((String message, Exception ex, String function, String scriptname, Script sc, int line) ->
- {
- m.sendToConsole("error in config '" + name + "'");
- if(message != null)
- {
- m.sendListElementToConsole(message);
- }
- if(ex != null)
- {
- m.sendListElementToConsole(ex.getClass().getSimpleName());
- }
- if(function != null)
- {
- m.sendHelpListElementToConsole("function", function);
- }
- if(line != -1)
- {
- m.sendHelpListElementToConsole("line", function);
- }
- }, path, name);
-
- if(load && exists())
- {
- load();
- }
- }
-
- public SimpleConfig(Module m, Script sc, String path, String name, boolean load)
- {
- super(sc, path, name);
- if(load && exists())
- {
- load();
- }
- }
-
- public static File[] getFiles(String path)
- {
- return new File("./" + path).listFiles();
- }
-
- // -----------------------------------------------------------------------------------
- // get
- // -----------------------------------------------------------------------------------
-
- public Location getLocation(String key)
- {
- return new Location(ModDimensions.getWorldFromName(getString(key + ".world")),
- getDouble(key + ".x", 0), getDouble(key + ".y", 0), getDouble(key + ".z", 0),
- getFloat(key + ".yaw", 0), getFloat(key + ".pitch", 0));
- }
-
- public ItemStack getItemStack(String key)
- {
- Object s = conf.get(key);
- if(s == null)
- {
- return ItemStack.EMPTY;
- }
- try
- {
- return ItemStackUtils.getStackFromNbtString(s.toString());
- }
- catch(IllegalItemStackStringException ex)
- {
- return ItemStack.EMPTY;
- }
- }
-
- // -----------------------------------------------------------------------------------
- // Add Data
- // -----------------------------------------------------------------------------------
-
- public void setLocation(String key, Location l)
- {
- set(key + ".world", l.getWorld().getWorldInfo().getWorldName());
- set(key + ".x", l.getX());
- set(key + ".y", l.getY());
- set(key + ".z", l.getZ());
- set(key + ".yaw", l.getYaw());
- set(key + ".pitch", l.getPitch());
- }
-
- public void setItemStack(String key, ItemStack stack)
- {
- set(key, ItemStackUtils.getNbtString(stack));
- }
- }
|