Let's try to load the data from flatfile, or rather start.

This commit is contained in:
graywolf336 2013-12-06 16:05:11 -06:00
parent e07c657a40
commit 4adffd7b4a
2 changed files with 137 additions and 114 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}
}