Stop using deprecated event

This commit is contained in:
extendedclip 2018-03-24 12:42:08 -04:00
parent 7db3bab4d8
commit 3b136b7aa2

View File

@ -20,6 +20,7 @@
*/ */
package me.clip.placeholderapi; package me.clip.placeholderapi;
import me.clip.placeholderapi.events.ExpansionUnregisterEvent;
import me.clip.placeholderapi.events.PlaceholderHookUnloadEvent; import me.clip.placeholderapi.events.PlaceholderHookUnloadEvent;
import me.clip.placeholderapi.expansion.*; import me.clip.placeholderapi.expansion.*;
import me.clip.placeholderapi.expansion.cloud.CloudExpansion; import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
@ -36,7 +37,7 @@ import org.bukkit.event.server.PluginEnableEvent;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@SuppressWarnings("deprecation")
public class PlaceholderListener implements Listener { public class PlaceholderListener implements Listener {
private PlaceholderAPIPlugin plugin; private PlaceholderAPIPlugin plugin;
@ -47,25 +48,23 @@ public class PlaceholderListener implements Listener {
} }
@EventHandler @EventHandler
public void onInternalUnload(PlaceholderHookUnloadEvent event) { public void onExpansionUnregister(ExpansionUnregisterEvent event) {
if (event.getHook() instanceof Listener) { if (event.getExpansion() instanceof Listener) {
HandlerList.unregisterAll((Listener)event.getHook()); HandlerList.unregisterAll((Listener)event.getExpansion());
plugin.getLogger().info("Unregistered event listener for placeholder expansion: " + event.getHookName());
} }
if (event.getHook() instanceof Taskable) { if (event.getExpansion() instanceof Taskable) {
plugin.getLogger().info("Cancelling scheduled task for placeholder expansion: " + event.getHookName()); ((Taskable) event.getExpansion()).stop();
((Taskable) event.getHook()).stop();
} }
if (event.getHook() instanceof Cacheable) { if (event.getExpansion() instanceof Cacheable) {
((Cacheable) event.getHook()).clear(); ((Cacheable) event.getExpansion()).clear();
} }
if (plugin.getExpansionCloud() != null) { if (plugin.getExpansionCloud() != null) {
CloudExpansion ex = plugin.getExpansionCloud().getCloudExpansion(event.getHookName()); CloudExpansion ex = plugin.getExpansionCloud().getCloudExpansion(event.getExpansion().getName());
if (ex != null) { if (ex != null) {
ex.setHasExpansion(false); ex.setHasExpansion(false);