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