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;
|
2014-01-01 23:22:40 +01:00
|
|
|
import com.graywolf336.jail.listeners.HandCuffListener;
|
2013-12-06 23:05:11 +01:00
|
|
|
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;
|
2014-01-01 23:19:04 +01:00
|
|
|
private HandCuffManager hcm;
|
2013-12-06 23:05:11 +01:00
|
|
|
private JailIO io;
|
|
|
|
private JailManager jm;
|
2014-01-03 21:10:38 +01:00
|
|
|
private JailTimer jt;
|
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();
|
|
|
|
|
2014-01-01 23:19:04 +01:00
|
|
|
hcm = new HandCuffManager();
|
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();
|
2014-01-08 22:02:24 +01:00
|
|
|
plm.registerEvents(new BlockListener(this), this);
|
2013-12-25 00:51:41 +01:00
|
|
|
plm.registerEvents(new EntityListener(), this);
|
2014-01-02 00:39:21 +01:00
|
|
|
plm.registerEvents(new HandCuffListener(this), this);
|
2013-12-25 00:51:41 +01:00
|
|
|
plm.registerEvents(new PlayerListener(this), this);
|
2013-12-06 23:05:11 +01:00
|
|
|
|
2014-01-03 21:10:38 +01:00
|
|
|
jt = new JailTimer(this);
|
|
|
|
|
2013-12-28 20:37:18 +01:00
|
|
|
debug = getConfig().getBoolean(Settings.DEBUG.getPath());
|
|
|
|
|
|
|
|
if(debug) getLogger().info("Debugging enabled.");
|
|
|
|
|
2014-01-08 22:02:24 +01:00
|
|
|
getLogger().info("Completed enablement.");
|
2013-12-06 23:05:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDisable() {
|
2013-12-09 22:12:32 +01:00
|
|
|
if(jm != null)
|
|
|
|
for(Jail j : jm.getJails())
|
|
|
|
io.saveJail(j);
|
|
|
|
|
2014-01-03 21:10:38 +01:00
|
|
|
if(jt != null)
|
|
|
|
if(jt.getTimer() != null)
|
|
|
|
jt.getTimer().stop();
|
|
|
|
|
2014-01-03 21:18:16 +01:00
|
|
|
jt = null;
|
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;
|
2014-01-02 01:27:23 +01:00
|
|
|
hcm = null;
|
2013-12-06 23:05:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
2014-01-01 23:19:04 +01:00
|
|
|
/** Gets the {@link HandCuffManager} instance. */
|
|
|
|
public HandCuffManager getHandCuffManager() {
|
|
|
|
return this.hcm;
|
|
|
|
}
|
|
|
|
|
2013-12-06 23:05:11 +01:00
|
|
|
/** 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
|
|
|
}
|