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;
|
2013-12-28 20:37:18 +01:00
|
|
|
import com.graywolf336.jail.enums.Settings;
|
2013-12-06 23:05:11 +01:00
|
|
|
import com.graywolf336.jail.listeners.BlockListener;
|
|
|
|
import com.graywolf336.jail.listeners.EntityListener;
|
|
|
|
import com.graywolf336.jail.listeners.PlayerListener;
|
|
|
|
|
2013-12-29 02:50:55 +01:00
|
|
|
/**
|
|
|
|
* The main class for this Jail plugin, holds instances of vital classes.
|
|
|
|
*
|
|
|
|
* @author graywolf336
|
|
|
|
* @since 1.x.x
|
|
|
|
* @version 3.0.0
|
|
|
|
*/
|
2013-12-06 23:05:11 +01:00
|
|
|
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-28 20:37:18 +01:00
|
|
|
private boolean debug = false;
|
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
|
|
|
|
2013-12-28 20:37:18 +01:00
|
|
|
debug = getConfig().getBoolean(Settings.DEBUG.getPath());
|
|
|
|
|
|
|
|
if(debug) getLogger().info("Debugging enabled.");
|
|
|
|
|
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-28 20:37:18 +01:00
|
|
|
|
|
|
|
/** Returns if the plugin is in debug state or not. */
|
|
|
|
public boolean inDebug() {
|
|
|
|
return this.debug;
|
|
|
|
}
|
2013-12-06 23:05:11 +01:00
|
|
|
}
|