mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-10 18:37:57 +01:00
[#845] Added an event that is called when Plan enables.
This includes, but might not be limited to: - First time the plugin enables successfully - Plan is reloaded - Bukkit-BungeeCord setup updates settings - Plan is enabled after it was disabled Following events are available: Bukkit: PlanBukkitEnableEvent Sponge: PlanSpongeEnableEvent BungeeCord: PlanBungeeEnableEvent Velocity: PlanVelocityEnableEvent
This commit is contained in:
parent
30bce4e365
commit
8d199bcdc3
@ -73,6 +73,9 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||||||
command.registerCommands();
|
command.registerCommands();
|
||||||
registerCommand("plan", command);
|
registerCommand("plan", command);
|
||||||
new RegisterCommandFilter().registerFilter();
|
new RegisterCommandFilter().registerFilter();
|
||||||
|
if (system != null) {
|
||||||
|
system.getListenerSystem().callEnableEvent(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.api.events;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that is called when Plan is enabled.
|
||||||
|
* <p>
|
||||||
|
* This includes, but might not be limited to:
|
||||||
|
* - First time the plugin enables successfully
|
||||||
|
* - Plan is reloaded
|
||||||
|
* - Bukkit-BungeeCord setup updates settings
|
||||||
|
* - Plan is enabled after it was disabled
|
||||||
|
* <p>
|
||||||
|
* {@code event.isPlanSystemEnabled()} can be called to determine if the enable was successful.
|
||||||
|
* It is not guaranteed that this event is called when the plugin fails to enable properly.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class PlanBukkitEnableEvent extends Event {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private final boolean enabled;
|
||||||
|
|
||||||
|
public PlanBukkitEnableEvent(boolean enabled) {
|
||||||
|
super(true);
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlanSystemEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -17,8 +17,11 @@
|
|||||||
package com.djrapitops.plan.system.listeners;
|
package com.djrapitops.plan.system.listeners;
|
||||||
|
|
||||||
import com.djrapitops.plan.Plan;
|
import com.djrapitops.plan.Plan;
|
||||||
|
import com.djrapitops.plan.PlanPlugin;
|
||||||
|
import com.djrapitops.plan.api.events.PlanBukkitEnableEvent;
|
||||||
import com.djrapitops.plan.system.listeners.bukkit.*;
|
import com.djrapitops.plan.system.listeners.bukkit.*;
|
||||||
import com.djrapitops.plan.system.status.Status;
|
import com.djrapitops.plan.system.status.Status;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -77,4 +80,10 @@ public class BukkitListenerSystem extends ListenerSystem {
|
|||||||
protected void unregisterListeners() {
|
protected void unregisterListeners() {
|
||||||
HandlerList.unregisterAll(plugin);
|
HandlerList.unregisterAll(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void callEnableEvent(PlanPlugin plugin) {
|
||||||
|
PlanBukkitEnableEvent event = new PlanBukkitEnableEvent(plugin.isSystemEnabled());
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,9 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
|||||||
PlanProxyCommand command = component.planCommand();
|
PlanProxyCommand command = component.planCommand();
|
||||||
command.registerCommands();
|
command.registerCommands();
|
||||||
registerCommand("planbungee", command);
|
registerCommand("planbungee", command);
|
||||||
|
if (system != null) {
|
||||||
|
system.getListenerSystem().callEnableEvent(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.api.events;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that is called when Plan is enabled.
|
||||||
|
* <p>
|
||||||
|
* This includes, but might not be limited to:
|
||||||
|
* - First time the plugin enables successfully
|
||||||
|
* - Plan is reloaded
|
||||||
|
* - Plan is enabled after it was disabled
|
||||||
|
* <p>
|
||||||
|
* {@code event.isPlanSystemEnabled()} can be called to determine if the enable was successful.
|
||||||
|
* It is not guaranteed that this event is called when the plugin fails to enable properly.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class PlanBungeeEnableEvent extends Event {
|
||||||
|
|
||||||
|
private final boolean enabled;
|
||||||
|
|
||||||
|
public PlanBungeeEnableEvent(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlanSystemEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,6 +17,8 @@
|
|||||||
package com.djrapitops.plan.system.listeners;
|
package com.djrapitops.plan.system.listeners;
|
||||||
|
|
||||||
import com.djrapitops.plan.PlanBungee;
|
import com.djrapitops.plan.PlanBungee;
|
||||||
|
import com.djrapitops.plan.PlanPlugin;
|
||||||
|
import com.djrapitops.plan.api.events.PlanBungeeEnableEvent;
|
||||||
import com.djrapitops.plan.system.listeners.bungee.PlayerOnlineListener;
|
import com.djrapitops.plan.system.listeners.bungee.PlayerOnlineListener;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -41,4 +43,10 @@ public class BungeeListenerSystem extends ListenerSystem {
|
|||||||
protected void unregisterListeners() {
|
protected void unregisterListeners() {
|
||||||
plugin.getProxy().getPluginManager().unregisterListeners(plugin);
|
plugin.getProxy().getPluginManager().unregisterListeners(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void callEnableEvent(PlanPlugin plugin) {
|
||||||
|
PlanBungeeEnableEvent event = new PlanBungeeEnableEvent(plugin.isSystemEnabled());
|
||||||
|
((PlanBungee) plugin).getProxy().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,4 +41,8 @@ public interface PlanPlugin extends IPlugin {
|
|||||||
boolean isReloading();
|
boolean isReloading();
|
||||||
|
|
||||||
PlanSystem getSystem();
|
PlanSystem getSystem();
|
||||||
|
|
||||||
|
default boolean isSystemEnabled() {
|
||||||
|
return getSystem().isEnabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,10 @@ public class HookHandler implements SubSystem {
|
|||||||
configHandler.createSection(dataSource);
|
configHandler.createSection(dataSource);
|
||||||
}
|
}
|
||||||
if (configHandler.isEnabled(dataSource)) {
|
if (configHandler.isEnabled(dataSource)) {
|
||||||
|
additionalDataSources.stream()
|
||||||
|
.filter(pluginData -> pluginData.getSourcePlugin().equals(dataSource.getSourcePlugin()))
|
||||||
|
.findAny()
|
||||||
|
.ifPresent(additionalDataSources::remove);
|
||||||
logger.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
|
logger.debug("Registered a new datasource: " + dataSource.getSourcePlugin());
|
||||||
additionalDataSources.add(dataSource);
|
additionalDataSources.add(dataSource);
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ import javax.inject.Singleton;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class PlanSystem implements SubSystem {
|
public class PlanSystem implements SubSystem {
|
||||||
|
|
||||||
|
private boolean enabled = false;
|
||||||
|
|
||||||
private final PlanFiles files;
|
private final PlanFiles files;
|
||||||
private final ConfigSystem configSystem;
|
private final ConfigSystem configSystem;
|
||||||
private final VersionCheckSystem versionCheckSystem;
|
private final VersionCheckSystem versionCheckSystem;
|
||||||
@ -130,6 +132,7 @@ public class PlanSystem implements SubSystem {
|
|||||||
taskSystem,
|
taskSystem,
|
||||||
hookHandler
|
hookHandler
|
||||||
);
|
);
|
||||||
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableSystems(SubSystem... systems) throws EnableException {
|
private void enableSystems(SubSystem... systems) throws EnableException {
|
||||||
@ -140,6 +143,7 @@ public class PlanSystem implements SubSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
|
enabled = false;
|
||||||
disableSystems(
|
disableSystems(
|
||||||
taskSystem,
|
taskSystem,
|
||||||
hookHandler,
|
hookHandler,
|
||||||
@ -240,4 +244,8 @@ public class PlanSystem implements SubSystem {
|
|||||||
public HtmlUtilities getHtmlUtilities() {
|
public HtmlUtilities getHtmlUtilities() {
|
||||||
return htmlUtilities;
|
return htmlUtilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.listeners;
|
package com.djrapitops.plan.system.listeners;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanPlugin;
|
||||||
import com.djrapitops.plan.system.SubSystem;
|
import com.djrapitops.plan.system.SubSystem;
|
||||||
|
|
||||||
public abstract class ListenerSystem implements SubSystem {
|
public abstract class ListenerSystem implements SubSystem {
|
||||||
@ -34,4 +35,6 @@ public abstract class ListenerSystem implements SubSystem {
|
|||||||
|
|
||||||
protected abstract void unregisterListeners();
|
protected abstract void unregisterListeners();
|
||||||
|
|
||||||
|
public abstract void callEnableEvent(PlanPlugin plugin);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,9 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
|||||||
PlanCommand command = component.planCommand();
|
PlanCommand command = component.planCommand();
|
||||||
command.registerCommands();
|
command.registerCommands();
|
||||||
registerCommand("plan", command);
|
registerCommand("plan", command);
|
||||||
|
if (system != null) {
|
||||||
|
system.getListenerSystem().callEnableEvent(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.api.events;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanSponge;
|
||||||
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
|
import org.spongepowered.api.event.cause.EventContext;
|
||||||
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that is called when Plan is enabled.
|
||||||
|
* <p>
|
||||||
|
* This includes, but might not be limited to:
|
||||||
|
* - First time the plugin enables successfully
|
||||||
|
* - Plan is reloaded
|
||||||
|
* - Sponge-BungeeCord setup updates settings
|
||||||
|
* - Plan is enabled after it was disabled
|
||||||
|
* <p>
|
||||||
|
* {@code event.isPlanSystemEnabled()} can be called to determine if the enable was successful.
|
||||||
|
* It is not guaranteed that this event is called when the plugin fails to enable properly.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class PlanSpongeEnableEvent extends AbstractEvent {
|
||||||
|
|
||||||
|
private final PlanSponge plugin;
|
||||||
|
private final boolean enabled;
|
||||||
|
|
||||||
|
public PlanSpongeEnableEvent(PlanSponge plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.enabled = plugin.isSystemEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlanSystemEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cause getCause() {
|
||||||
|
return Cause.builder().append(plugin.getSystem()).build(EventContext.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getSource() {
|
||||||
|
return plugin.getSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EventContext getContext() {
|
||||||
|
return EventContext.empty();
|
||||||
|
}
|
||||||
|
}
|
@ -16,9 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.listeners;
|
package com.djrapitops.plan.system.listeners;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanPlugin;
|
||||||
import com.djrapitops.plan.PlanSponge;
|
import com.djrapitops.plan.PlanSponge;
|
||||||
|
import com.djrapitops.plan.api.events.PlanSpongeEnableEvent;
|
||||||
import com.djrapitops.plan.system.listeners.sponge.*;
|
import com.djrapitops.plan.system.listeners.sponge.*;
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
|
import org.spongepowered.api.event.Event;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -72,4 +75,10 @@ public class SpongeListenerSystem extends ListenerSystem {
|
|||||||
protected void unregisterListeners() {
|
protected void unregisterListeners() {
|
||||||
Sponge.getEventManager().unregisterPluginListeners(plugin);
|
Sponge.getEventManager().unregisterPluginListeners(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void callEnableEvent(PlanPlugin plugin) {
|
||||||
|
Event event = new PlanSpongeEnableEvent((PlanSponge) plugin);
|
||||||
|
Sponge.getEventManager().post(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,9 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
|
|||||||
PlanProxyCommand command = component.planCommand();
|
PlanProxyCommand command = component.planCommand();
|
||||||
command.registerCommands();
|
command.registerCommands();
|
||||||
registerCommand("planvelocity", command);
|
registerCommand("planvelocity", command);
|
||||||
|
if (system != null) {
|
||||||
|
system.getListenerSystem().callEnableEvent(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.api.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that is called when Plan is enabled.
|
||||||
|
* <p>
|
||||||
|
* This includes, but might not be limited to:
|
||||||
|
* - First time the plugin enables successfully
|
||||||
|
* - Plan is reloaded
|
||||||
|
* - Bukkit-BungeeCord setup updates settings
|
||||||
|
* - Plan is enabled after it was disabled
|
||||||
|
* <p>
|
||||||
|
* {@code event.isPlanSystemEnabled()} can be called to determine if the enable was successful.
|
||||||
|
* It is not guaranteed that this event is called when the plugin fails to enable properly.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class PlanVelocityEnableEvent {
|
||||||
|
|
||||||
|
private final boolean enabled;
|
||||||
|
|
||||||
|
public PlanVelocityEnableEvent(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlanSystemEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,7 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.listeners;
|
package com.djrapitops.plan.system.listeners;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.PlanPlugin;
|
||||||
import com.djrapitops.plan.PlanVelocity;
|
import com.djrapitops.plan.PlanVelocity;
|
||||||
|
import com.djrapitops.plan.api.events.PlanVelocityEnableEvent;
|
||||||
import com.djrapitops.plan.system.listeners.velocity.PlayerOnlineListener;
|
import com.djrapitops.plan.system.listeners.velocity.PlayerOnlineListener;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -47,4 +49,10 @@ public class VelocityListenerSystem extends ListenerSystem {
|
|||||||
protected void unregisterListeners() {
|
protected void unregisterListeners() {
|
||||||
plugin.getProxy().getEventManager().unregisterListeners(plugin);
|
plugin.getProxy().getEventManager().unregisterListeners(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void callEnableEvent(PlanPlugin plugin) {
|
||||||
|
PlanVelocityEnableEvent event = new PlanVelocityEnableEvent(plugin.isSystemEnabled());
|
||||||
|
((PlanVelocity) plugin).getProxy().getEventManager().fireAndForget(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user