Removed Bukkit.getScheduler calls
This commit is contained in:
@@ -27,8 +27,13 @@ public class EcoScheduler extends PluginDependent implements Scheduler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask run(Callable callable) {
|
||||
return Bukkit.getServer().getScheduler().runTask(this.plugin, callable::call);
|
||||
public BukkitTask run(Runnable runnable) {
|
||||
return Bukkit.getServer().getScheduler().runTask(this.plugin, runnable::run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask runAsync(Callable callable) {
|
||||
return Bukkit.getServer().getScheduler().runTaskAsynchronously(this.plugin, callable::call);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,8 @@ public interface Scheduler {
|
||||
BukkitTask runLater(Callable callable, long ticksLater);
|
||||
BukkitTask runTimer(Callable callable, long delay, long repeat);
|
||||
BukkitTask runAsyncTimer(Callable callable, long delay, long repeat);
|
||||
BukkitTask run(Callable callable);
|
||||
BukkitTask run(Runnable runnable);
|
||||
BukkitTask runAsync(Callable callable);
|
||||
int syncRepeating(Runnable runnable, long delay, long repeat);
|
||||
void cancelAll();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -118,7 +118,7 @@ public class InternalDropQueue implements AbstractDropQueue {
|
||||
* Push the queue
|
||||
*/
|
||||
public void push() {
|
||||
if(!hasTelekinesis) hasTelekinesis = AbstractEcoPlugin.getInstance().getTelekineticTests().testPlayer(player);
|
||||
if(!hasTelekinesis) hasTelekinesis = TelekinesisUtils.testPlayer(player);
|
||||
|
||||
World world = loc.getWorld();
|
||||
assert world != null;
|
||||
|
||||
@@ -8,17 +8,19 @@ import org.bukkit.entity.Player;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TelekineticTests extends PluginDependent {
|
||||
public class EcoTelekinesisTests extends PluginDependent implements TelekinesisTests {
|
||||
private final Set<ObjectBiCallable<Boolean, Player>> tests = new HashSet<>();
|
||||
|
||||
public TelekineticTests(AbstractEcoPlugin plugin) {
|
||||
public EcoTelekinesisTests(AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerTest(ObjectBiCallable<Boolean, Player> test) {
|
||||
tests.add(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPlayer(Player player) {
|
||||
for (ObjectBiCallable<Boolean, Player> test : tests) {
|
||||
if(test.call(player)) return true;
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.willfp.eco.util.drops.telekinesis;
|
||||
|
||||
import com.willfp.eco.util.lambda.ObjectBiCallable;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface TelekinesisTests {
|
||||
void registerTest(ObjectBiCallable<Boolean, Player> test);
|
||||
boolean testPlayer(Player player);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.util.drops.telekinesis;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TelekinesisUtils {
|
||||
private static TelekinesisTests tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
|
||||
|
||||
public static boolean testPlayer(Player player) {
|
||||
return tests.testPlayer(player);
|
||||
}
|
||||
|
||||
public static void update() {
|
||||
tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,9 @@ import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.drops.internal.DropManager;
|
||||
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekineticTests;
|
||||
import com.willfp.eco.util.drops.telekinesis.EcoTelekinesisTests;
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisTests;
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
|
||||
import com.willfp.eco.util.events.armorequip.ArmorListener;
|
||||
import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
|
||||
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityListeners;
|
||||
@@ -43,6 +45,7 @@ import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -67,7 +70,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
private final NamespacedKeyFactory namespacedKeyFactory;
|
||||
private final MetadataValueFactory metadataValueFactory;
|
||||
private final ExtensionLoader extensionLoader;
|
||||
private final TelekineticTests telekineticTests;
|
||||
|
||||
protected boolean outdated = false;
|
||||
|
||||
@@ -82,7 +84,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.namespacedKeyFactory = new NamespacedKeyFactory(this);
|
||||
this.metadataValueFactory = new MetadataValueFactory(this);
|
||||
this.extensionLoader = new EcoExtensionLoader(this);
|
||||
this.telekineticTests = new TelekineticTests(this);
|
||||
|
||||
if (!Bukkit.getServicesManager().isProvidedFor(TelekinesisTests.class)) {
|
||||
Bukkit.getServicesManager().register(TelekinesisTests.class, new EcoTelekinesisTests(this), this, ServicePriority.Normal);
|
||||
}
|
||||
|
||||
TelekinesisUtils.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -239,10 +246,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
|
||||
public abstract List<Listener> getListeners();
|
||||
|
||||
public final TelekineticTests getTelekineticTests() {
|
||||
return telekineticTests;
|
||||
}
|
||||
|
||||
public final Logger getLog() {
|
||||
return log;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.willfp.eco.util.updater;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.util.Consumer;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -13,7 +12,7 @@ import java.util.Scanner;
|
||||
* Checks spigot if a plugin is out of date
|
||||
*/
|
||||
public class UpdateChecker {
|
||||
private final Plugin plugin;
|
||||
private final AbstractEcoPlugin plugin;
|
||||
private final int resourceId;
|
||||
|
||||
/**
|
||||
@@ -22,7 +21,7 @@ public class UpdateChecker {
|
||||
* @param plugin The plugin to check
|
||||
* @param resourceId The resource ID of the plugin
|
||||
*/
|
||||
public UpdateChecker(Plugin plugin, int resourceId) {
|
||||
public UpdateChecker(AbstractEcoPlugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
@@ -33,7 +32,7 @@ public class UpdateChecker {
|
||||
* @param consumer The process to run after checking
|
||||
*/
|
||||
public void getVersion(final Consumer<? super String> consumer) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
this.plugin.getScheduler().runAsync(() -> {
|
||||
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
|
||||
if (scanner.hasNext()) {
|
||||
consumer.accept(scanner.next());
|
||||
|
||||
Reference in New Issue
Block a user