From 4adffd7b4aae1b266bdbe85ce8e716c0bcb2f5d2 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Fri, 6 Dec 2013 16:05:11 -0600 Subject: [PATCH] Let's try to load the data from flatfile, or rather start. --- .../java/com/graywolf336/jail/JailIO.java | 88 ++++++---- .../java/com/graywolf336/jail/JailMain.java | 163 +++++++++--------- 2 files changed, 137 insertions(+), 114 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/JailIO.java b/src/main/java/com/graywolf336/jail/JailIO.java index d478a39..400203c 100644 --- a/src/main/java/com/graywolf336/jail/JailIO.java +++ b/src/main/java/com/graywolf336/jail/JailIO.java @@ -1,33 +1,55 @@ -package com.graywolf336.jail; - -public class JailIO { - private JailMain pl; - private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql - - public JailIO(JailMain plugin) { - this.pl = plugin; - - String st = pl.getConfig().getString("storage.type", "flatfile"); - if(st.equalsIgnoreCase("sqlite")) { - storage = 1; - }else if(st.equalsIgnoreCase("mysql")) { - storage = 2; - }else { - storage = 0; - } - } - - public void PrepareStorage() { - switch(storage) { - case 1: - //prepare sqlite, I need to research this - break; - case 2: - //prepare mysql, research this as well - break; - default: - //File system, prepare it somehow.. Maybe load in the files - break; - } - } -} +package com.graywolf336.jail; + +import java.io.File; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +public class JailIO { + private JailMain pl; + private FileConfiguration flat; + private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql + + public JailIO(JailMain plugin) { + this.pl = plugin; + + String st = pl.getConfig().getString("storage.type", "flatfile"); + if(st.equalsIgnoreCase("sqlite")) { + storage = 1; + }else if(st.equalsIgnoreCase("mysql")) { + storage = 2; + }else { + storage = 0; + } + } + + public void prepareStorage() { + switch(storage) { + case 1: + //prepare sqlite, I need to research this + break; + case 2: + //prepare mysql, research this as well + break; + default: + flat = YamlConfiguration.loadConfiguration(new File(pl.getDataFolder(), "data.yml")); + break; + } + } + + public void loadJails() { + switch(storage) { + case 1: + //load the jails from sqlite + break; + case 2: + //load the jails from mysql + break; + default: + //load the jails from flatfile + if(flat.contains("jails")) + pl.getLogger().info("Jails exists"); + break; + } + } +} diff --git a/src/main/java/com/graywolf336/jail/JailMain.java b/src/main/java/com/graywolf336/jail/JailMain.java index a040173..905820a 100644 --- a/src/main/java/com/graywolf336/jail/JailMain.java +++ b/src/main/java/com/graywolf336/jail/JailMain.java @@ -1,81 +1,82 @@ -package com.graywolf336.jail; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import com.graywolf336.jail.command.CommandHandler; -import com.graywolf336.jail.listeners.BlockListener; -import com.graywolf336.jail.listeners.EntityListener; -import com.graywolf336.jail.listeners.PlayerListener; -import com.graywolf336.jail.listeners.PlayerPreventionsListener; - -public class JailMain extends JavaPlugin { - private JailIO io; - private JailManager jm; - private CommandHandler cmdHand; - - public void onEnable() { - loadConfig(); - - io = new JailIO(this); - io.PrepareStorage(); - - jm = new JailManager(this); - cmdHand = new CommandHandler(this); - - PluginManager pm = this.getServer().getPluginManager(); - pm.registerEvents(new BlockListener(), this); - pm.registerEvents(new EntityListener(), this); - pm.registerEvents(new PlayerListener(this), this); - pm.registerEvents(new PlayerPreventionsListener(this), this); - - //For the time, we will use: - //http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/TimeUnit.html#convert(long, java.util.concurrent.TimeUnit) - } - - public void onDisable() { - cmdHand = null; - jm = null; - io = null; - } - - private void loadConfig() { - //Only create the default config if it doesn't exist - saveDefaultConfig(); - - // Set the header and save - getConfig().options().header(getHeader()); - saveConfig(); - } - - private String getHeader() { - String sep = System.getProperty("line.separator"); - - return "###################" + sep - + "Jail v" + this.getDescription().getVersion() + " config file" + sep - + "Note: You -must- use spaces instead of tabs!" + sep + - "###################"; - } - - /* Majority of the new command system was heavily influenced by the MobArena. - * Thank you garbagemule for the great system you have in place there. - * - * Send the command off to the CommandHandler class, that way this main class doesn't get clogged up. - */ - public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { - cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args); - return true;//Always return true here, that way we can handle the help and command usage ourself. - } - - /** Gets the {@link JailIO} instance. */ - public JailIO getJailIO() { - return this.io; - } - - /** Gets the {@link JailManager} instance. */ - public JailManager getJailManager() { - return this.jm; - } -} +package com.graywolf336.jail; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import com.graywolf336.jail.command.CommandHandler; +import com.graywolf336.jail.listeners.BlockListener; +import com.graywolf336.jail.listeners.EntityListener; +import com.graywolf336.jail.listeners.PlayerListener; +import com.graywolf336.jail.listeners.PlayerPreventionsListener; + +public class JailMain extends JavaPlugin { + private JailIO io; + private JailManager jm; + private CommandHandler cmdHand; + + public void onEnable() { + loadConfig(); + + io = new JailIO(this); + io.prepareStorage(); + io.loadJails(); + + jm = new JailManager(this); + cmdHand = new CommandHandler(this); + + PluginManager pm = this.getServer().getPluginManager(); + pm.registerEvents(new BlockListener(), this); + pm.registerEvents(new EntityListener(), this); + pm.registerEvents(new PlayerListener(this), this); + pm.registerEvents(new PlayerPreventionsListener(this), this); + + //For the time, we will use: + //http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/TimeUnit.html#convert(long, java.util.concurrent.TimeUnit) + } + + public void onDisable() { + cmdHand = null; + jm = null; + io = null; + } + + private void loadConfig() { + //Only create the default config if it doesn't exist + saveDefaultConfig(); + + // Set the header and save + getConfig().options().header(getHeader()); + saveConfig(); + } + + private String getHeader() { + String sep = System.getProperty("line.separator"); + + return "###################" + sep + + "Jail v" + this.getDescription().getVersion() + " config file" + sep + + "Note: You -must- use spaces instead of tabs!" + sep + + "###################"; + } + + /* Majority of the new command system was heavily influenced by the MobArena. + * Thank you garbagemule for the great system you have in place there. + * + * Send the command off to the CommandHandler class, that way this main class doesn't get clogged up. + */ + public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { + cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args); + return true;//Always return true here, that way we can handle the help and command usage ourself. + } + + /** Gets the {@link JailIO} instance. */ + public JailIO getJailIO() { + return this.io; + } + + /** Gets the {@link JailManager} instance. */ + public JailManager getJailManager() { + return this.jm; + } +}