1.14 support, (sub)command tabcomplete #73

Merged
NorbiPeti merged 19 commits from dev into master 2019-10-30 18:14:12 +00:00
3 changed files with 39 additions and 11 deletions
Showing only changes of commit 14bcebabcd - Show all commits

View file

@ -12,6 +12,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />

View file

@ -1,7 +1,13 @@
package buttondevteam.lib;
import buttondevteam.core.MainPlugin;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import java.util.function.Supplier;
public final class ThorpeUtils {
private ThorpeUtils() {}
@ -51,4 +57,33 @@ public final class ThorpeUtils {
return number.doubleValue();
return number;
}
/**
* Calls the event always asynchronously. The return value is always false if async.
*
* @param event The event to call
* @return The event cancelled state or false if async.
*/
public static <T extends Event & Cancellable> boolean callEventAsync(T event) {
Supplier<Boolean> task = () -> {
Bukkit.getPluginManager().callEvent(event);
return event.isCancelled();
};
return doItAsync(task, false);
}
/**
* Does something always asynchronously. It will execute in the same thread if it's not the server thread.
*
* @param what What to do
* @param def Default if async
* @return The event cancelled state or false if async.
*/
public static <T> T doItAsync(Supplier<T> what, T def) {
if (Bukkit.isPrimaryThread())
Bukkit.getScheduler().runTaskAsynchronously(MainPlugin.Instance, what::get);
else
return what.get();
return def;
}
}

View file

@ -4,10 +4,7 @@ import buttondevteam.core.CommandCaller;
import buttondevteam.core.MainPlugin;
import buttondevteam.core.component.channel.Channel;
import buttondevteam.core.component.channel.Channel.RecipientTestResult;
import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCChatPreprocessEvent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.*;
import buttondevteam.lib.architecture.Component;
import lombok.val;
import org.bukkit.Bukkit;
@ -290,11 +287,7 @@ public class TBMCChatAPI {
Bukkit.getPluginManager().callEvent(event);
return event.isCancelled();
};
if (Bukkit.isPrimaryThread())
Bukkit.getScheduler().runTaskAsynchronously(MainPlugin.Instance, task::get);
else
return task.get();
return false; //Not cancelled if async
return ThorpeUtils.doItAsync(task, false); //Not cancelled if async
}
/**
@ -314,8 +307,7 @@ public class TBMCChatAPI {
if (!Arrays.asList(exceptions).contains("Minecraft"))
Bukkit.getConsoleSender().sendMessage("[" + channel.DisplayName().get() + "] " + message);
TBMCSystemChatEvent event = new TBMCSystemChatEvent(channel, message, rtr.score, rtr.groupID, exceptions, target);
Bukkit.getPluginManager().callEvent(event);
return event.isCancelled();
return ThorpeUtils.callEventAsync(event);
}
private static RecipientTestResult getScoreOrSendError(Channel channel, CommandSender sender) {