2013-12-06 16:05:11 -06: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 15:12:32 -06:00
|
|
|
import com.graywolf336.jail.beans.Jail;
|
2014-03-13 12:59:47 -05:00
|
|
|
import com.graywolf336.jail.beans.Prisoner;
|
2013-12-06 16:05:11 -06:00
|
|
|
import com.graywolf336.jail.command.CommandHandler;
|
2014-01-27 18:02:24 -06:00
|
|
|
import com.graywolf336.jail.command.JailHandler;
|
2013-12-28 13:37:18 -06:00
|
|
|
import com.graywolf336.jail.enums.Settings;
|
2014-03-14 15:18:36 -05:00
|
|
|
import com.graywolf336.jail.legacy.LegacyManager;
|
2013-12-06 16:05:11 -06:00
|
|
|
import com.graywolf336.jail.listeners.BlockListener;
|
|
|
|
import com.graywolf336.jail.listeners.EntityListener;
|
2014-01-01 16:22:40 -06:00
|
|
|
import com.graywolf336.jail.listeners.HandCuffListener;
|
2014-03-06 16:51:25 -06:00
|
|
|
import com.graywolf336.jail.listeners.JailingListener;
|
2014-02-01 11:52:50 -06:00
|
|
|
import com.graywolf336.jail.listeners.MoveProtectionListener;
|
2013-12-06 16:05:11 -06:00
|
|
|
import com.graywolf336.jail.listeners.PlayerListener;
|
2014-01-19 14:40:39 -06:00
|
|
|
import com.graywolf336.jail.listeners.ProtectionListener;
|
2013-12-06 16:05:11 -06:00
|
|
|
|
2013-12-28 19:50:55 -06: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 16:05:11 -06:00
|
|
|
public class JailMain extends JavaPlugin {
|
2013-12-24 17:51:41 -06:00
|
|
|
private CommandHandler cmdHand;
|
2014-01-01 16:19:04 -06:00
|
|
|
private HandCuffManager hcm;
|
2014-01-27 18:02:24 -06:00
|
|
|
private JailHandler jh;
|
2013-12-06 16:05:11 -06:00
|
|
|
private JailIO io;
|
|
|
|
private JailManager jm;
|
2014-03-20 15:33:42 -05:00
|
|
|
private JailPayManager jpm;
|
2014-03-08 22:53:31 -06:00
|
|
|
private JailStickManager jsm;
|
2014-01-03 14:10:38 -06:00
|
|
|
private JailTimer jt;
|
2013-12-24 17:51:41 -06:00
|
|
|
private PrisonerManager pm;
|
2014-03-13 12:59:47 -05:00
|
|
|
private ScoreBoardManager sbm;
|
2013-12-28 13:37:18 -06:00
|
|
|
private boolean debug = false;
|
2013-12-06 16:05:11 -06:00
|
|
|
|
|
|
|
public void onEnable() {
|
|
|
|
loadConfig();
|
|
|
|
|
2014-02-20 16:20:27 -06:00
|
|
|
debug = getConfig().getBoolean(Settings.DEBUG.getPath());
|
|
|
|
if(debug) getLogger().info("Debugging enabled.");
|
|
|
|
|
2014-01-01 16:19:04 -06:00
|
|
|
hcm = new HandCuffManager();
|
2013-12-07 14:16:16 -06:00
|
|
|
jm = new JailManager(this);
|
2014-03-14 15:18:36 -05:00
|
|
|
|
|
|
|
//Try to load the old stuff before we load anything, esp the storage stuff
|
|
|
|
LegacyManager lm = new LegacyManager(this);
|
|
|
|
if(lm.doWeNeedToConvert()) {
|
2014-05-03 01:12:26 -05:00
|
|
|
lm.convertOldData();
|
|
|
|
if(!lm.wasAnythingConverted()) getLogger().severe("We was unable to convert some, or all, of the old data.");
|
2014-03-14 15:18:36 -05:00
|
|
|
}
|
|
|
|
|
2013-12-06 16:05:11 -06:00
|
|
|
io = new JailIO(this);
|
2013-12-23 14:31:27 -06:00
|
|
|
io.loadLanguage();
|
2014-02-20 16:20:27 -06:00
|
|
|
|
|
|
|
//If the prepareStorage returns false, we need to disable the plugin
|
|
|
|
if(!io.prepareStorage(true)) {
|
|
|
|
this.getLogger().severe("An error occured while preparing the connection to the storage, please see the error above for more information.");
|
|
|
|
this.getServer().getPluginManager().disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-06 16:05:11 -06:00
|
|
|
io.loadJails();
|
|
|
|
|
2014-05-03 01:12:26 -05:00
|
|
|
//If we converted something, let's save EVERYTHING including the cells
|
|
|
|
if(lm.wasAnythingConverted()) {
|
|
|
|
io.saveEverything();
|
|
|
|
}
|
|
|
|
|
2013-12-06 16:05:11 -06:00
|
|
|
cmdHand = new CommandHandler(this);
|
2014-01-27 18:02:24 -06:00
|
|
|
jh = new JailHandler(this);
|
2013-12-24 17:51:41 -06:00
|
|
|
pm = new PrisonerManager(this);
|
2014-03-08 22:53:31 -06:00
|
|
|
jsm = new JailStickManager(this);
|
2013-12-06 16:05:11 -06:00
|
|
|
|
2013-12-24 17:51:41 -06:00
|
|
|
PluginManager plm = this.getServer().getPluginManager();
|
2014-01-08 15:02:24 -06:00
|
|
|
plm.registerEvents(new BlockListener(this), this);
|
2014-01-08 15:27:38 -06:00
|
|
|
plm.registerEvents(new EntityListener(this), this);
|
2014-01-01 17:39:21 -06:00
|
|
|
plm.registerEvents(new HandCuffListener(this), this);
|
2014-03-06 16:51:25 -06:00
|
|
|
plm.registerEvents(new JailingListener(this), this);
|
2013-12-24 17:51:41 -06:00
|
|
|
plm.registerEvents(new PlayerListener(this), this);
|
2014-01-19 14:40:39 -06:00
|
|
|
plm.registerEvents(new ProtectionListener(this), this);
|
2013-12-06 16:05:11 -06:00
|
|
|
|
2014-02-01 11:52:50 -06:00
|
|
|
//Only register the move protection listener if this is enabled in the
|
|
|
|
//config when we first start the plugin. The reason for this change is
|
|
|
|
//that the move event is called a ton of times per single move and so
|
|
|
|
//not registering this event listener will hopefully safe some performance.
|
|
|
|
//But doing this also forces people to restart their server if they to
|
|
|
|
//enable it after disabling it.
|
|
|
|
if(getConfig().getBoolean(Settings.MOVEPROTECTION.getPath())) {
|
|
|
|
plm.registerEvents(new MoveProtectionListener(this), this);
|
|
|
|
}
|
|
|
|
|
2014-01-03 14:10:38 -06:00
|
|
|
jt = new JailTimer(this);
|
2014-03-20 15:33:42 -05:00
|
|
|
|
2014-04-01 23:21:24 -05:00
|
|
|
reloadJailPayManager();
|
2014-03-20 15:33:42 -05:00
|
|
|
|
2014-03-13 12:59:47 -05:00
|
|
|
sbm = new ScoreBoardManager(this);
|
2014-01-03 14:10:38 -06:00
|
|
|
|
2014-01-08 15:02:24 -06:00
|
|
|
getLogger().info("Completed enablement.");
|
2013-12-06 16:05:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDisable() {
|
2013-12-09 15:12:32 -06:00
|
|
|
if(jm != null)
|
|
|
|
for(Jail j : jm.getJails())
|
|
|
|
io.saveJail(j);
|
|
|
|
|
2014-01-03 14:10:38 -06:00
|
|
|
if(jt != null)
|
|
|
|
if(jt.getTimer() != null)
|
|
|
|
jt.getTimer().stop();
|
|
|
|
|
2014-02-20 16:20:27 -06:00
|
|
|
if(io != null)
|
|
|
|
io.closeConnection();
|
|
|
|
|
2014-01-03 14:18:16 -06:00
|
|
|
jt = null;
|
2014-03-13 12:59:47 -05:00
|
|
|
sbm = null;
|
2014-03-20 15:33:42 -05:00
|
|
|
jpm = null;
|
2013-12-06 16:05:11 -06:00
|
|
|
cmdHand = null;
|
2013-12-24 17:51:41 -06:00
|
|
|
pm = null;
|
2013-12-06 16:05:11 -06:00
|
|
|
jm = null;
|
2014-03-08 22:53:31 -06:00
|
|
|
jsm = null;
|
2013-12-06 16:05:11 -06:00
|
|
|
io = null;
|
2014-01-01 18:27:23 -06:00
|
|
|
hcm = null;
|
2013-12-06 16:05:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
private void loadConfig() {
|
|
|
|
//Only create the default config if it doesn't exist
|
|
|
|
saveDefaultConfig();
|
|
|
|
|
2013-12-23 13:40:47 -06:00
|
|
|
//Append new key-value pairs to the config
|
|
|
|
getConfig().options().copyDefaults(true);
|
|
|
|
|
2013-12-06 16:05:11 -06: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) {
|
2014-04-27 00:19:23 -05:00
|
|
|
if(commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) {
|
2014-02-11 20:44:19 -06:00
|
|
|
jh.parseCommand(jm, sender, args);
|
2014-01-27 18:02:24 -06:00
|
|
|
}else {
|
|
|
|
cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args);
|
|
|
|
}
|
|
|
|
|
2013-12-06 16:05:11 -06:00
|
|
|
return true;//Always return true here, that way we can handle the help and command usage ourself.
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:59:47 -05:00
|
|
|
/** Reloads the scoreboard manager class, useful when something is changed int he config about it. */
|
|
|
|
public void reloadScoreBoardManager() {
|
|
|
|
this.sbm.removeAllScoreboards();
|
|
|
|
this.sbm = null;
|
|
|
|
this.sbm = new ScoreBoardManager(this);
|
|
|
|
|
|
|
|
if(getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
|
|
|
for(Jail j : jm.getJails()) {
|
|
|
|
for(Prisoner p : j.getAllPrisoners()) {
|
2014-04-28 23:52:52 -05:00
|
|
|
if(getServer().getPlayer(p.getUUID()) != null) {
|
|
|
|
this.sbm.addScoreBoard(getServer().getPlayer(p.getUUID()), p);
|
2014-03-13 12:59:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 15:15:30 -05:00
|
|
|
/** Reloads the Jail Sticks, so the new ones can be loaded from the config. */
|
|
|
|
public void reloadJailSticks() {
|
|
|
|
this.jsm.removeAllStickUsers();
|
|
|
|
this.jsm = null;
|
|
|
|
this.jsm = new JailStickManager(this);
|
|
|
|
}
|
|
|
|
|
2014-03-20 15:33:42 -05:00
|
|
|
/**
|
|
|
|
* Reloads the {@link JailPayManager}.
|
|
|
|
*
|
|
|
|
* @throws Exception If we couldn't successfully create a new Jail Pay Manager instance.
|
|
|
|
*/
|
2014-04-01 23:21:24 -05:00
|
|
|
public void reloadJailPayManager() {
|
2014-03-20 15:33:42 -05:00
|
|
|
this.jpm = null;
|
2014-04-01 23:21:24 -05:00
|
|
|
|
|
|
|
if(getConfig().getBoolean(Settings.JAILPAYENABLED.getPath())) {
|
|
|
|
if(getServer().getPluginManager().isPluginEnabled("Vault")) {
|
|
|
|
this.jpm = new JailPayManager(this);
|
|
|
|
}else {
|
|
|
|
getConfig().set(Settings.JAILPAYENABLED.getPath(), false);
|
|
|
|
getLogger().severe("Jail Pay couldn't find an economy, disabling Jail Pay.");
|
|
|
|
}
|
|
|
|
}
|
2014-03-20 15:33:42 -05:00
|
|
|
}
|
|
|
|
|
2014-01-01 16:19:04 -06:00
|
|
|
/** Gets the {@link HandCuffManager} instance. */
|
|
|
|
public HandCuffManager getHandCuffManager() {
|
|
|
|
return this.hcm;
|
|
|
|
}
|
|
|
|
|
2013-12-06 16:05:11 -06: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-24 17:51:41 -06:00
|
|
|
|
2014-03-20 15:33:42 -05:00
|
|
|
/** Gets the {@link JailPayManager} instance. */
|
|
|
|
public JailPayManager getJailPayManager() {
|
|
|
|
return this.jpm;
|
|
|
|
}
|
|
|
|
|
2013-12-24 17:51:41 -06:00
|
|
|
/** Gets the {@link PrisonerManager} instance. */
|
|
|
|
public PrisonerManager getPrisonerManager() {
|
|
|
|
return this.pm;
|
|
|
|
}
|
2013-12-28 13:37:18 -06:00
|
|
|
|
2014-03-08 22:53:31 -06:00
|
|
|
/** Gets the {@link JailStickManager} instance. */
|
|
|
|
public JailStickManager getJailStickManager() {
|
|
|
|
return this.jsm;
|
|
|
|
}
|
|
|
|
|
2014-03-13 12:59:47 -05:00
|
|
|
/** Gets the {@link ScoreBoardManager} instance. */
|
|
|
|
public ScoreBoardManager getScoreBoardManager() {
|
|
|
|
return this.sbm;
|
|
|
|
}
|
|
|
|
|
2014-03-14 15:35:50 -05:00
|
|
|
/** Sets whether the plugin is in debugging or not. */
|
2014-04-21 22:04:03 -05:00
|
|
|
public boolean setDebugging(boolean debug) {
|
2014-03-14 15:35:50 -05:00
|
|
|
this.debug = debug;
|
2014-04-21 22:04:03 -05:00
|
|
|
|
|
|
|
//Save whether we are debugging when we disable the plugin
|
|
|
|
getConfig().set(Settings.DEBUG.getPath(), this.debug);
|
|
|
|
saveConfig();
|
|
|
|
|
|
|
|
return this.debug;
|
2014-03-14 15:35:50 -05:00
|
|
|
}
|
|
|
|
|
2013-12-28 13:37:18 -06:00
|
|
|
/** Returns if the plugin is in debug state or not. */
|
|
|
|
public boolean inDebug() {
|
|
|
|
return this.debug;
|
|
|
|
}
|
2014-02-04 13:30:12 -06:00
|
|
|
|
|
|
|
/** Logs a debugging message to the console if debugging is enabled. */
|
|
|
|
public void debug(String message) {
|
|
|
|
if(inDebug()) getLogger().info("[Debug]: " + message);
|
|
|
|
}
|
2013-12-06 16:05:11 -06:00
|
|
|
}
|