Load/Disable the move protection listener #88

We now load or disable the move protection listener based upon the
config when the plugin is reloaded.
This commit is contained in:
graywolf336 2015-07-23 14:53:30 -05:00
parent 1648c04745
commit 9ec7f389db
2 changed files with 26 additions and 5 deletions

View File

@ -18,6 +18,7 @@ Beta 5 Changes
* Added a password requirement on the broadcast of jailing, defaults to everyone. [#54](https://github.com/graywolf336/Jail/issues/54)
* Added the ability to show `reason`, `jail`, and `cell` to the broadcast messages. [#53](https://github.com/graywolf336/Jail/issues/53)
* Added tab complete to all the commands. [#77](https://github.com/graywolf336/Jail/issues/77)
* Added reloading the move protection listener, so the reload actually loads/disables it. [#88](https://github.com/graywolf336/Jail/issues/88)
* Changed cell names to be semi-sorted alphabetically. [#80](https://github.com/graywolf336/Jail/issues/80)
* Changed how we handle inventory when storing is set to false. Don't remove their inventory when they are unjailed and we don't store it. [#57](https://github.com/graywolf336/Jail/issues/57)
* Changed offline players jailing, don't allow jailing players unless they've played before (can be overwrote with -f). [#82](https://github.com/graywolf336/Jail/issues/82)
@ -27,6 +28,7 @@ Beta 5 Changes
* Changed the explanation of why the gamemode setting was problematic and give the available options. [#73](https://github.com/graywolf336/Jail/issues/73)
* Changed pretty time to be the default of the signs.
* Fixed a sqlite issue which was preventing plugin from launching. [#78](https://github.com/graywolf336/Jail/issues/78)
* Fixed a sqlite error when deleting a cell. [#89](https://github.com/graywolf336/Jail/issues/89)
* Fixed an issue where cell data was being duplicated (or more) in the database. [#74](https://github.com/graywolf336/Jail/issues/74)
* Fixed an on load issue when the config didn't have four lines for the signs. [#61](https://github.com/graywolf336/Jail/issues/61)
* Fixed cell signs not updating when an offline player is jailed. [#68](https://github.com/graywolf336/Jail/issues/68)

View File

@ -6,6 +6,7 @@ import java.util.concurrent.TimeUnit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@ -114,10 +115,7 @@ public class JailMain extends JavaPlugin {
//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())) {
this.mpl = new MoveProtectionListener(this);
plm.registerEvents(this.mpl, this);
}
this.reloadMoveProtection();
jt = new JailTimer(this);
sbm = new ScoreBoardManager(this);
@ -231,6 +229,7 @@ public class JailMain extends JavaPlugin {
//We don't touch any of the data currently being stored in cache,
//this way you can transfer from flatfile to mysql or flip flopped.
getJailIO().prepareStorage(true);
reloadMoveProtection();
//Reload all that has to do with the scoreboard, name and settings
reloadScoreBoardManager();
//Reload the jail sticks
@ -246,6 +245,26 @@ public class JailMain extends JavaPlugin {
getServer().getPluginManager().callEvent(new JailPluginReloadedEvent(this));
}
/** Reloads/Loads the move protection listener based upon it's previous status and the config. */
private void reloadMoveProtection() {
boolean moveProtection = getConfig().getBoolean(Settings.MOVEPROTECTION.getPath());
//If move protection is not enabled and it used to be,
//unregister it.
if(!moveProtection && this.mpl != null) {
HandlerList.unregisterAll(this.mpl);
this.mpl = null;
this.debug("The move protection listener is now disabled.");
}
//If it is enabled and it used to not be, then enable it.
if(moveProtection && this.mpl == null) {
this.mpl = new MoveProtectionListener(this);
getServer().getPluginManager().registerEvents(mpl, this);
this.debug("The move protection listener is now enabled.");
}
}
/** Reloads the scoreboard manager class, useful when something is changed in the config about it. */
private void reloadScoreBoardManager() {
this.sbm.removeAllScoreboards();