2013-12-06 23:05:11 +01:00
|
|
|
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;
|
|
|
|
|
2013-12-09 22:12:32 +01:00
|
|
|
import com.graywolf336.jail.beans.Jail;
|
2013-12-06 23:05:11 +01:00
|
|
|
import com.graywolf336.jail.command.CommandHandler;
|
|
|
|
import com.graywolf336.jail.listeners.BlockListener;
|
|
|
|
import com.graywolf336.jail.listeners.EntityListener;
|
|
|
|
import com.graywolf336.jail.listeners.PlayerListener;
|
|
|
|
|
|
|
|
public class JailMain extends JavaPlugin {
|
2013-12-25 00:51:41 +01:00
|
|
|
private CommandHandler cmdHand;
|
2013-12-06 23:05:11 +01:00
|
|
|
private JailIO io;
|
|
|
|
private JailManager jm;
|
2013-12-25 00:51:41 +01:00
|
|
|
private PrisonerManager pm;
|
2013-12-06 23:05:11 +01:00
|
|
|
|
|
|
|
public void onEnable() {
|
|
|
|
loadConfig();
|
|
|
|
|
2013-12-07 21:16:16 +01:00
|
|
|
jm = new JailManager(this);
|
2013-12-06 23:05:11 +01:00
|
|
|
io = new JailIO(this);
|
2013-12-23 21:31:27 +01:00
|
|
|
io.loadLanguage();
|
2013-12-06 23:05:11 +01:00
|
|
|
io.prepareStorage();
|
|
|
|
io.loadJails();
|
|
|
|
|
|
|
|
cmdHand = new CommandHandler(this);
|
2013-12-25 00:51:41 +01:00
|
|
|
pm = new PrisonerManager(this);
|
2013-12-06 23:05:11 +01:00
|
|
|
|
2013-12-25 00:51:41 +01:00
|
|
|
PluginManager plm = this.getServer().getPluginManager();
|
|
|
|
plm.registerEvents(new BlockListener(), this);
|
|
|
|
plm.registerEvents(new EntityListener(), this);
|
|
|
|
plm.registerEvents(new PlayerListener(this), this);
|
2013-12-06 23:05:11 +01:00
|
|
|
|
|
|
|
//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() {
|
2013-12-09 22:12:32 +01:00
|
|
|
if(jm != null)
|
|
|
|
for(Jail j : jm.getJails())
|
|
|
|
io.saveJail(j);
|
|
|
|
|
2013-12-06 23:05:11 +01:00
|
|
|
cmdHand = null;
|
2013-12-25 00:51:41 +01:00
|
|
|
pm = null;
|
2013-12-06 23:05:11 +01:00
|
|
|
jm = null;
|
|
|
|
io = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadConfig() {
|
|
|
|
//Only create the default config if it doesn't exist
|
|
|
|
saveDefaultConfig();
|
|
|
|
|
2013-12-23 20:40:47 +01:00
|
|
|
//Append new key-value pairs to the config
|
|
|
|
getConfig().options().copyDefaults(true);
|
|
|
|
|
2013-12-06 23:05:11 +01:00
|
|
|
// 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;
|
|
|
|
}
|
2013-12-25 00:51:41 +01:00
|
|
|
|
|
|
|
/** Gets the {@link PrisonerManager} instance. */
|
|
|
|
public PrisonerManager getPrisonerManager() {
|
|
|
|
return this.pm;
|
|
|
|
}
|
2013-12-06 23:05:11 +01:00
|
|
|
}
|