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;
|
2014-03-13 18:59:47 +01:00
|
|
|
import com.graywolf336.jail.beans.Prisoner;
|
2013-12-06 23:05:11 +01:00
|
|
|
import com.graywolf336.jail.command.CommandHandler;
|
2014-01-28 01:02:24 +01:00
|
|
|
import com.graywolf336.jail.command.JailHandler;
|
2013-12-28 20:37:18 +01:00
|
|
|
import com.graywolf336.jail.enums.Settings;
|
2014-03-14 21:18:36 +01:00
|
|
|
import com.graywolf336.jail.legacy.LegacyManager;
|
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;
|
2014-03-06 23:51:25 +01:00
|
|
|
import com.graywolf336.jail.listeners.JailingListener;
|
2014-02-01 18:52:50 +01:00
|
|
|
import com.graywolf336.jail.listeners.MoveProtectionListener;
|
2013-12-06 23:05:11 +01:00
|
|
|
import com.graywolf336.jail.listeners.PlayerListener;
|
2014-01-19 21:40:39 +01:00
|
|
|
import com.graywolf336.jail.listeners.ProtectionListener;
|
2013-12-06 23:05:11 +01:00
|
|
|
|
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;
|
2014-01-28 01:02:24 +01:00
|
|
|
private JailHandler jh;
|
2013-12-06 23:05:11 +01:00
|
|
|
private JailIO io;
|
|
|
|
private JailManager jm;
|
2014-03-20 21:33:42 +01:00
|
|
|
private JailPayManager jpm;
|
2014-03-09 05:53:31 +01:00
|
|
|
private JailStickManager jsm;
|
2014-01-03 21:10:38 +01:00
|
|
|
private JailTimer jt;
|
2013-12-25 00:51:41 +01:00
|
|
|
private PrisonerManager pm;
|
2014-03-13 18:59:47 +01:00
|
|
|
private ScoreBoardManager sbm;
|
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-02-20 23:20:27 +01:00
|
|
|
debug = getConfig().getBoolean(Settings.DEBUG.getPath());
|
|
|
|
if(debug) getLogger().info("Debugging enabled.");
|
|
|
|
|
2014-01-01 23:19:04 +01:00
|
|
|
hcm = new HandCuffManager();
|
2013-12-07 21:16:16 +01:00
|
|
|
jm = new JailManager(this);
|
2014-03-14 21:18:36 +01:00
|
|
|
|
|
|
|
//Try to load the old stuff before we load anything, esp the storage stuff
|
|
|
|
LegacyManager lm = new LegacyManager(this);
|
|
|
|
if(lm.doWeNeedToConvert()) {
|
2014-03-14 23:40:44 +01:00
|
|
|
boolean converted = lm.convertOldData();
|
2014-03-14 21:18:36 +01:00
|
|
|
if(!converted) getLogger().severe("We was unable to convert some, or all, of the old data.");
|
|
|
|
}
|
|
|
|
|
2013-12-06 23:05:11 +01:00
|
|
|
io = new JailIO(this);
|
2013-12-23 21:31:27 +01:00
|
|
|
io.loadLanguage();
|
2014-02-20 23:20:27 +01: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 23:05:11 +01:00
|
|
|
io.loadJails();
|
|
|
|
|
|
|
|
cmdHand = new CommandHandler(this);
|
2014-01-28 01:02:24 +01:00
|
|
|
jh = new JailHandler(this);
|
2013-12-25 00:51:41 +01:00
|
|
|
pm = new PrisonerManager(this);
|
2014-03-09 05:53:31 +01:00
|
|
|
jsm = new JailStickManager(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);
|
2014-01-08 22:27:38 +01:00
|
|
|
plm.registerEvents(new EntityListener(this), this);
|
2014-01-02 00:39:21 +01:00
|
|
|
plm.registerEvents(new HandCuffListener(this), this);
|
2014-03-06 23:51:25 +01:00
|
|
|
plm.registerEvents(new JailingListener(this), this);
|
2013-12-25 00:51:41 +01:00
|
|
|
plm.registerEvents(new PlayerListener(this), this);
|
2014-01-19 21:40:39 +01:00
|
|
|
plm.registerEvents(new ProtectionListener(this), this);
|
2013-12-06 23:05:11 +01:00
|
|
|
|
2014-02-01 18:52:50 +01: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 21:10:38 +01:00
|
|
|
jt = new JailTimer(this);
|
2014-03-20 21:33:42 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
jpm = new JailPayManager(this);
|
|
|
|
} catch (Exception e) {
|
|
|
|
getLogger().severe(e.getMessage());
|
|
|
|
jpm = null;
|
|
|
|
}
|
|
|
|
|
2014-03-13 18:59:47 +01:00
|
|
|
sbm = new ScoreBoardManager(this);
|
2014-01-03 21:10:38 +01:00
|
|
|
|
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-02-20 23:20:27 +01:00
|
|
|
if(io != null)
|
|
|
|
io.closeConnection();
|
|
|
|
|
2014-01-03 21:18:16 +01:00
|
|
|
jt = null;
|
2014-03-13 18:59:47 +01:00
|
|
|
sbm = null;
|
2014-03-20 21:33:42 +01:00
|
|
|
jpm = 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;
|
2014-03-09 05:53:31 +01:00
|
|
|
jsm = null;
|
2013-12-06 23:05:11 +01:00
|
|
|
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) {
|
2014-01-28 01:02:24 +01:00
|
|
|
if(command.getName().equalsIgnoreCase("jail")) {
|
2014-02-12 03:44:19 +01:00
|
|
|
jh.parseCommand(jm, sender, args);
|
2014-01-28 01:02:24 +01:00
|
|
|
}else {
|
|
|
|
cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args);
|
|
|
|
}
|
|
|
|
|
2013-12-06 23:05:11 +01:00
|
|
|
return true;//Always return true here, that way we can handle the help and command usage ourself.
|
|
|
|
}
|
|
|
|
|
2014-03-13 18:59:47 +01: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()) {
|
|
|
|
if(getServer().getPlayerExact(p.getName()) != null) {
|
2014-03-20 21:33:42 +01:00
|
|
|
this.sbm.addScoreBoard(getServer().getPlayerExact(p.getName()), p);
|
2014-03-13 18:59:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 21:15:30 +01: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 21:33:42 +01:00
|
|
|
/**
|
|
|
|
* Reloads the {@link JailPayManager}.
|
|
|
|
*
|
|
|
|
* @throws Exception If we couldn't successfully create a new Jail Pay Manager instance.
|
|
|
|
*/
|
|
|
|
public void reloadJailPayManager() throws Exception {
|
|
|
|
this.jpm = null;
|
|
|
|
this.jpm = new JailPayManager(this);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-03-20 21:33:42 +01:00
|
|
|
/** Gets the {@link JailPayManager} instance. */
|
|
|
|
public JailPayManager getJailPayManager() {
|
|
|
|
return this.jpm;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-03-09 05:53:31 +01:00
|
|
|
/** Gets the {@link JailStickManager} instance. */
|
|
|
|
public JailStickManager getJailStickManager() {
|
|
|
|
return this.jsm;
|
|
|
|
}
|
|
|
|
|
2014-03-13 18:59:47 +01:00
|
|
|
/** Gets the {@link ScoreBoardManager} instance. */
|
|
|
|
public ScoreBoardManager getScoreBoardManager() {
|
|
|
|
return this.sbm;
|
|
|
|
}
|
|
|
|
|
2014-03-14 21:35:50 +01:00
|
|
|
/** Sets whether the plugin is in debugging or not. */
|
|
|
|
public void setDebugging(boolean debug) {
|
|
|
|
this.debug = debug;
|
|
|
|
}
|
|
|
|
|
2013-12-28 20:37:18 +01:00
|
|
|
/** Returns if the plugin is in debug state or not. */
|
|
|
|
public boolean inDebug() {
|
|
|
|
return this.debug;
|
|
|
|
}
|
2014-02-04 20:30:12 +01: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 23:05:11 +01:00
|
|
|
}
|