Bump spigot api version, fix BukkitService.runTaskTimerAsynchronously() #2150

This commit is contained in:
Gabriele C 2020-07-10 20:55:15 +02:00
parent 1cd0ce17a5
commit 990830c395
4 changed files with 24 additions and 16 deletions

View File

@ -64,7 +64,7 @@
<maven.minimumVersion>3.3.9</maven.minimumVersion>
<!-- Dependencies versions -->
<spigot.version>1.15.2-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.16.1-R0.1-SNAPSHOT</spigot.version>
<!-- Versioning properties -->
<project.outputName>AuthMe</project.outputName>

View File

@ -17,6 +17,7 @@ import org.apache.logging.log4j.LogManager;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import javax.inject.Inject;
import java.util.List;
@ -94,7 +95,9 @@ public class OnStartupTasks {
if (!settings.getProperty(RECALL_PLAYERS)) {
return;
}
bukkitService.runTaskTimerAsynchronously(() -> {
bukkitService.runTaskTimerAsynchronously(new BukkitRunnable() {
@Override
public void run() {
List<String> loggedPlayersWithEmptyMail = dataSource.getLoggedPlayersWithEmptyMail();
bukkitService.runTask(() -> {
for (String playerWithoutMail : loggedPlayersWithEmptyMail) {
@ -104,6 +107,7 @@ public class OnStartupTasks {
}
}
});
}
}, 1, TICKS_PER_MINUTE * settings.getProperty(EmailSettings.DELAY_RECALL));
}
}

View File

@ -14,6 +14,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
@ -152,9 +153,10 @@ public class BukkitService implements SettingsDependent {
* @param period the ticks to wait between runs
* @return a BukkitTask that contains the id number
* @throws IllegalArgumentException if task is null
* @throws IllegalStateException if this was already scheduled
*/
public BukkitTask runTaskTimerAsynchronously(Runnable task, long delay, long period) {
return Bukkit.getScheduler().runTaskTimerAsynchronously(authMe, task, delay, period);
public BukkitTask runTaskTimerAsynchronously(BukkitRunnable task, long delay, long period) {
return task.runTaskTimerAsynchronously(authMe, delay, period);
}
/**
@ -167,7 +169,6 @@ public class BukkitService implements SettingsDependent {
* @return a BukkitTask that contains the id number
* @throws IllegalArgumentException if plugin is null
* @throws IllegalStateException if this was already scheduled
* @see BukkitScheduler#runTaskTimer(org.bukkit.plugin.Plugin, Runnable, long, long)
*/
public BukkitTask runTaskTimer(BukkitRunnable task, long delay, long period) {
return task.runTaskTimer(authMe, delay, period);

View File

@ -226,18 +226,21 @@ public class BukkitServiceTest {
@Test
public void shouldRunTaskTimerAsynchronously() {
// given
Runnable task = () -> {/* */};
BukkitRunnable task = new BukkitRunnable() {
@Override
public void run() {
}
};
long delay = 20L;
long period = 4000L;
BukkitTask bukkitTask = mock(BukkitTask.class);
given(scheduler.runTaskTimerAsynchronously(authMe, task, delay, period)).willReturn(bukkitTask);
given(task.runTaskTimerAsynchronously(authMe, delay, period)).willReturn(bukkitTask);
// when
BukkitTask resultingTask = bukkitService.runTaskTimerAsynchronously(task, delay, period);
// then
assertThat(resultingTask, equalTo(bukkitTask));
verify(scheduler).runTaskTimerAsynchronously(authMe, task, delay, period);
}
@Test