Let's try to load the data from flatfile, or rather start.
This commit is contained in:
parent
e07c657a40
commit
4adffd7b4a
@ -1,33 +1,55 @@
|
|||||||
package com.graywolf336.jail;
|
package com.graywolf336.jail;
|
||||||
|
|
||||||
public class JailIO {
|
import java.io.File;
|
||||||
private JailMain pl;
|
|
||||||
private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
public JailIO(JailMain plugin) {
|
|
||||||
this.pl = plugin;
|
public class JailIO {
|
||||||
|
private JailMain pl;
|
||||||
String st = pl.getConfig().getString("storage.type", "flatfile");
|
private FileConfiguration flat;
|
||||||
if(st.equalsIgnoreCase("sqlite")) {
|
private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql
|
||||||
storage = 1;
|
|
||||||
}else if(st.equalsIgnoreCase("mysql")) {
|
public JailIO(JailMain plugin) {
|
||||||
storage = 2;
|
this.pl = plugin;
|
||||||
}else {
|
|
||||||
storage = 0;
|
String st = pl.getConfig().getString("storage.type", "flatfile");
|
||||||
}
|
if(st.equalsIgnoreCase("sqlite")) {
|
||||||
}
|
storage = 1;
|
||||||
|
}else if(st.equalsIgnoreCase("mysql")) {
|
||||||
public void PrepareStorage() {
|
storage = 2;
|
||||||
switch(storage) {
|
}else {
|
||||||
case 1:
|
storage = 0;
|
||||||
//prepare sqlite, I need to research this
|
}
|
||||||
break;
|
}
|
||||||
case 2:
|
|
||||||
//prepare mysql, research this as well
|
public void prepareStorage() {
|
||||||
break;
|
switch(storage) {
|
||||||
default:
|
case 1:
|
||||||
//File system, prepare it somehow.. Maybe load in the files
|
//prepare sqlite, I need to research this
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,81 +1,82 @@
|
|||||||
package com.graywolf336.jail;
|
package com.graywolf336.jail;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.graywolf336.jail.command.CommandHandler;
|
import com.graywolf336.jail.command.CommandHandler;
|
||||||
import com.graywolf336.jail.listeners.BlockListener;
|
import com.graywolf336.jail.listeners.BlockListener;
|
||||||
import com.graywolf336.jail.listeners.EntityListener;
|
import com.graywolf336.jail.listeners.EntityListener;
|
||||||
import com.graywolf336.jail.listeners.PlayerListener;
|
import com.graywolf336.jail.listeners.PlayerListener;
|
||||||
import com.graywolf336.jail.listeners.PlayerPreventionsListener;
|
import com.graywolf336.jail.listeners.PlayerPreventionsListener;
|
||||||
|
|
||||||
public class JailMain extends JavaPlugin {
|
public class JailMain extends JavaPlugin {
|
||||||
private JailIO io;
|
private JailIO io;
|
||||||
private JailManager jm;
|
private JailManager jm;
|
||||||
private CommandHandler cmdHand;
|
private CommandHandler cmdHand;
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
io = new JailIO(this);
|
io = new JailIO(this);
|
||||||
io.PrepareStorage();
|
io.prepareStorage();
|
||||||
|
io.loadJails();
|
||||||
jm = new JailManager(this);
|
|
||||||
cmdHand = new CommandHandler(this);
|
jm = new JailManager(this);
|
||||||
|
cmdHand = new CommandHandler(this);
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
|
||||||
pm.registerEvents(new BlockListener(), this);
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
pm.registerEvents(new EntityListener(), this);
|
pm.registerEvents(new BlockListener(), this);
|
||||||
pm.registerEvents(new PlayerListener(this), this);
|
pm.registerEvents(new EntityListener(), this);
|
||||||
pm.registerEvents(new PlayerPreventionsListener(this), 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)
|
//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;
|
public void onDisable() {
|
||||||
jm = null;
|
cmdHand = null;
|
||||||
io = null;
|
jm = null;
|
||||||
}
|
io = null;
|
||||||
|
}
|
||||||
private void loadConfig() {
|
|
||||||
//Only create the default config if it doesn't exist
|
private void loadConfig() {
|
||||||
saveDefaultConfig();
|
//Only create the default config if it doesn't exist
|
||||||
|
saveDefaultConfig();
|
||||||
// Set the header and save
|
|
||||||
getConfig().options().header(getHeader());
|
// Set the header and save
|
||||||
saveConfig();
|
getConfig().options().header(getHeader());
|
||||||
}
|
saveConfig();
|
||||||
|
}
|
||||||
private String getHeader() {
|
|
||||||
String sep = System.getProperty("line.separator");
|
private String getHeader() {
|
||||||
|
String sep = System.getProperty("line.separator");
|
||||||
return "###################" + sep
|
|
||||||
+ "Jail v" + this.getDescription().getVersion() + " config file" + sep
|
return "###################" + sep
|
||||||
+ "Note: You -must- use spaces instead of tabs!" + 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.
|
/* 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.
|
*
|
||||||
*/
|
* 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);
|
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||||
return true;//Always return true here, that way we can handle the help and command usage ourself.
|
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() {
|
/** Gets the {@link JailIO} instance. */
|
||||||
return this.io;
|
public JailIO getJailIO() {
|
||||||
}
|
return this.io;
|
||||||
|
}
|
||||||
/** Gets the {@link JailManager} instance. */
|
|
||||||
public JailManager getJailManager() {
|
/** Gets the {@link JailManager} instance. */
|
||||||
return this.jm;
|
public JailManager getJailManager() {
|
||||||
}
|
return this.jm;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user