1
mirror of https://github.com/CarmJos/EasyPlugin.git synced 2024-09-19 19:25:45 +00:00

feat(main): 添加同步、异步与异步回调唤起事件的方法

This commit is contained in:
Carm Jos 2022-06-07 07:40:15 +08:00
parent 4dbcdfb02c
commit 7e35f49e54
10 changed files with 26 additions and 9 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.5</version>
<version>1.4.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.5</version>
<version>1.4.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.5</version>
<version>1.4.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -7,6 +7,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
@ -17,6 +18,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
public abstract class EasyPlugin extends JavaPlugin {
@ -134,6 +136,21 @@ public abstract class EasyPlugin extends JavaPlugin {
if (isDebugging()) print("&8[DEBUG] &r", messages);
}
public void callEventSync(Event event) {
getScheduler().run(() -> Bukkit.getPluginManager().callEvent(event));
}
public void callEventAsync(Event event) {
getScheduler().runAsync(() -> Bukkit.getPluginManager().callEvent(event));
}
public @NotNull <T extends Event> CompletableFuture<T> callEventFuture(T event) {
return CompletableFuture.supplyAsync(() -> {
Bukkit.getPluginManager().callEvent(event);
return event;
});
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean hasOverride(String methodName) {
Map<Method, Method> methodMap = new HashMap<>();

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.5</version>
<version>1.4.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.5</version>
<version>1.4.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.5</version>
<version>1.4.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.5</version>
<version>1.4.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.5</version>
<version>1.4.6</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -15,7 +15,7 @@
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-parent</artifactId>
<packaging>pom</packaging>
<version>1.4.5</version>
<version>1.4.6</version>
<modules>
<module>base/main</module>