Integration / Scheduling changes
This commit is contained in:
@@ -1,13 +1,27 @@
|
||||
package com.willfp.eco.core.integrations;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* An integration loader runs a runnable only if a specific plugin is present on the server.
|
||||
* <p>
|
||||
* Used by {@link com.willfp.eco.core.EcoPlugin} to load integrations.
|
||||
*/
|
||||
public class IntegrationLoader {
|
||||
/**
|
||||
* All loaded plugins on the server.
|
||||
*/
|
||||
private static final Set<String> LOADED_PLUGINS = Arrays.stream(Bukkit.getPluginManager().getPlugins())
|
||||
.map(Plugin::getName)
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
/**
|
||||
* The lambda to be run if the plugin is present.
|
||||
*/
|
||||
@@ -30,6 +44,15 @@ public class IntegrationLoader {
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the integration if the specified plugin is present on the server.
|
||||
*/
|
||||
public void loadIfPresent() {
|
||||
if (LOADED_PLUGINS.contains(this.pluginName.toLowerCase())) {
|
||||
this.load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the integration.
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.willfp.eco.core.Eco
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.util.PlayerUtils
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
import org.bukkit.event.player.PlayerLoginEvent
|
||||
@@ -12,19 +13,19 @@ import org.bukkit.event.player.PlayerQuitEvent
|
||||
class DataListener(
|
||||
private val plugin: EcoPlugin
|
||||
) : Listener {
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
fun onLeave(event: PlayerQuitEvent) {
|
||||
Eco.getHandler().playerProfileHandler.unloadPlayer(event.player.uniqueId)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onJoin(event: PlayerJoinEvent) {
|
||||
plugin.scheduler.runLater({
|
||||
plugin.scheduler.runLater(5) {
|
||||
PlayerUtils.updateSavedDisplayName(event.player)
|
||||
}, 5)
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
fun onLogin(event: PlayerLoginEvent) {
|
||||
Eco.getHandler().playerProfileHandler.unloadPlayer(event.player.uniqueId)
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ class EntityDeathByEntityListeners(
|
||||
builtEvent.victim = victim
|
||||
builtEvent.damager = event.damager
|
||||
events.add(builtEvent)
|
||||
this.plugin.scheduler.runLater({
|
||||
this.plugin.scheduler.run {
|
||||
events.remove(builtEvent)
|
||||
}, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
Reference in New Issue
Block a user