mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 02:55:46 +01:00
Add reload events.
This commit introduces two reload events, MobArenaPreReloadEvent and MobArenaReloadEvent. Both events are fired when MobArena reloads, the former right before the reload, and the latter right after. The reason for two events is to allow plugins to reload either entirely or partially along with MobArena, if it makes sense for them to do so, _when_ it makes sense for them to do so. Some plugins need to reload and re-register themselves with MobArena before the config-file itself is loaded (e.g. ThingParsers), while others either require MobArena to be fully loaded or are more decoupled and thus don't depend on anything in MobArena's innards to function. The "pre" event is for the former, while the other event is for the latter. As for naming, the choice of "Pre" and no prefix was made for the sake of consistency with the event names in the Bukkit API, which has just one example of such a pair (PlayerPreLoginEvent and PlayerLoginEvent). Some event naming conventions (e.g. in the .NET world) seem to favor present and past tense (reloading, reloaded), but this would be wildly inconsistent with the rest of the event names, so it might be better to just stay consistent. Names may change before an actual release, but for now, this is what we're rolling with. Closes #677
This commit is contained in:
parent
903752d23a
commit
b99713f1ec
@ -13,6 +13,7 @@ These changes will (most likely) be included in the next version.
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
- (API) MobArena's internal command handler now supports registering pre-instantiated subcommand instances. This should make it easier for extensions to avoid the Singleton anti-pattern for command dependencies.
|
- (API) MobArena's internal command handler now supports registering pre-instantiated subcommand instances. This should make it easier for extensions to avoid the Singleton anti-pattern for command dependencies.
|
||||||
|
- (API) MobArena now fires MobArenaPreReloadEvent and MobArenaReloadEvent before and after, respectively, reloading its config-file. This should allow extensions and other plugins to better respond to configuration changes.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- The regex pattern for the player list command is now less greedy, so it will only match on `/ma players`, `/ma playerlist`, and `/ma player-list`. The previous pattern matched on anything that starts with `player`, which rendered the `/ma player-stats` command in MobArenaStats impossible to invoke.
|
- The regex pattern for the player list command is now less greedy, so it will only match on `/ma players`, `/ma playerlist`, and `/ma player-list`. The previous pattern matched on anything that starts with `player`, which rendered the `/ma player-stats` command in MobArenaStats impossible to invoke.
|
||||||
|
@ -2,6 +2,8 @@ package com.garbagemule.MobArena;
|
|||||||
|
|
||||||
import com.garbagemule.MobArena.commands.CommandHandler;
|
import com.garbagemule.MobArena.commands.CommandHandler;
|
||||||
import com.garbagemule.MobArena.config.LoadsConfigFile;
|
import com.garbagemule.MobArena.config.LoadsConfigFile;
|
||||||
|
import com.garbagemule.MobArena.events.MobArenaPreReloadEvent;
|
||||||
|
import com.garbagemule.MobArena.events.MobArenaReloadEvent;
|
||||||
import com.garbagemule.MobArena.formula.FormulaMacros;
|
import com.garbagemule.MobArena.formula.FormulaMacros;
|
||||||
import com.garbagemule.MobArena.formula.FormulaManager;
|
import com.garbagemule.MobArena.formula.FormulaManager;
|
||||||
import com.garbagemule.MobArena.framework.Arena;
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
@ -181,6 +183,9 @@ public class MobArena extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
MobArenaPreReloadEvent pre = new MobArenaPreReloadEvent(this);
|
||||||
|
getServer().getPluginManager().callEvent(pre);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
reloadGlobalMessenger();
|
reloadGlobalMessenger();
|
||||||
@ -192,6 +197,9 @@ public class MobArena extends JavaPlugin
|
|||||||
setLastFailureCauseAndRethrow(e);
|
setLastFailureCauseAndRethrow(e);
|
||||||
}
|
}
|
||||||
lastFailureCause = null;
|
lastFailureCause = null;
|
||||||
|
|
||||||
|
MobArenaReloadEvent post = new MobArenaReloadEvent(this);
|
||||||
|
getServer().getPluginManager().callEvent(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.garbagemule.MobArena.events;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.MobArena;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called right before MobArena begins reloading.
|
||||||
|
* <p>
|
||||||
|
* Use this event to re-register components that need to be set up and in
|
||||||
|
* place <i>before</i> MobArena dips into its config-file. This is mostly
|
||||||
|
* relevant for plugins that <code>loadbefore</code> MobArena to register
|
||||||
|
* {@link com.garbagemule.MobArena.things.ThingParser}s and such.
|
||||||
|
* <p>
|
||||||
|
* This event is <i>not</i> suitable for working with the "current" state
|
||||||
|
* of arenas, classes, etc., because MobArena's state at the time of this
|
||||||
|
* event is about to become stale. To work with the "current" state after
|
||||||
|
* a reload, use the {@link MobArenaReloadEvent} instead.
|
||||||
|
*
|
||||||
|
* @see MobArenaReloadEvent
|
||||||
|
*/
|
||||||
|
public class MobArenaPreReloadEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private final MobArena plugin;
|
||||||
|
|
||||||
|
public MobArenaPreReloadEvent(MobArena plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current MobArena plugin instance.
|
||||||
|
*
|
||||||
|
* @return the MobArena plugin instance
|
||||||
|
*/
|
||||||
|
public MobArena getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.garbagemule.MobArena.events;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.MobArena;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called right after MobArena has reloaded.
|
||||||
|
* <p>
|
||||||
|
* The primary goal of this event is to allow extension plugins to "ride
|
||||||
|
* along" with the <code>/ma reload</code> command so they don't have to
|
||||||
|
* implement their own commands. <i>One command to rule them all.</i>
|
||||||
|
* <p>
|
||||||
|
* This event is useful if you need to work with arenas, classes, etc. in
|
||||||
|
* their "current" state. This is typical of plugins that (soft)depend on
|
||||||
|
* MobArena and use its API after the initialization phase.
|
||||||
|
* <p>
|
||||||
|
* This event is <i>not</i> suitable for re-registering components that
|
||||||
|
* need to be in place <i>before</i> MobArena reloads. For that, see the
|
||||||
|
* {@link MobArenaPreReloadEvent}.
|
||||||
|
*
|
||||||
|
* @see MobArenaPreReloadEvent
|
||||||
|
*/
|
||||||
|
public class MobArenaReloadEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private final MobArena plugin;
|
||||||
|
|
||||||
|
public MobArenaReloadEvent(MobArena plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current MobArena plugin instance.
|
||||||
|
*
|
||||||
|
* @return the MobArena plugin instance
|
||||||
|
*/
|
||||||
|
public MobArena getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user