From 88767fd0a906dae4fc1b112a27a0d28b87d91285 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Wed, 4 Mar 2020 16:04:48 +0000 Subject: [PATCH] Complete BukkitRunnable migration --- .../datatypes/player/BukkitMMOPlayer.java | 4 +++- .../MobHealthDisplayUpdaterTask.java | 9 ++++++--- .../nossr50/runnables/PistonTrackerTask.java | 8 +++++--- .../nossr50/runnables/SaveTimerTask.java | 8 +++++--- .../runnables/StickyPistonTrackerTask.java | 9 ++++++--- .../backups/CleanBackupFilesTask.java | 7 ++++--- .../LeaderboardsCommandAsyncTask.java | 8 +++++--- .../LeaderboardsCommandDisplayTask.java | 8 +++++--- .../commands/NotifySquelchReminderTask.java | 9 ++++++--- .../commands/RankCommandAsyncTask.java | 8 +++++--- .../commands/RankCommandDisplayTask.java | 8 +++++--- .../commands/ScoreboardKeepTask.java | 11 +++++++---- .../database/DatabaseConversionTask.java | 1 - .../database/FormulaConversionTask.java | 9 ++++++--- .../database/UUIDUpdateAsyncTask.java | 7 ++++--- .../runnables/database/UserPurgeTask.java | 7 ++++--- .../runnables/items/ChimaeraWingWarmup.java | 9 ++++++--- .../runnables/items/TeleportationWarmup.java | 9 ++++++--- .../runnables/party/PartyAutoKickTask.java | 1 - .../player/ClearRegisteredXPGainTask.java | 8 +++++--- .../player/PlayerProfileLoadingTask.java | 13 +++++++------ .../player/PlayerProfileSaveTask.java | 8 +++++--- .../player/PlayerUpdateInventoryTask.java | 11 +++++++---- .../player/PowerLevelUpdatingTask.java | 10 ++++++---- .../runnables/skills/AbilityCooldownTask.java | 8 +++++--- .../runnables/skills/AbilityDisableTask.java | 9 ++++++--- .../runnables/skills/AwardCombatXpTask.java | 9 ++++++--- .../runnables/skills/BleedTimerTask.java | 9 +++++---- .../runnables/skills/DelayedCropReplant.java | 13 ++++++++----- .../skills/DelayedHerbalismXPCheckTask.java | 7 ++++--- .../skills/ExperienceBarHideTask.java | 19 +++++-------------- .../skills/HerbalismBlockUpdaterTask.java | 11 +++++++---- .../skills/SkillUnlockNotificationTask.java | 19 +++++-------------- .../runnables/skills/ToolLowerTask.java | 8 +++++--- .../skills/taming/TrackedTamingEntity.java | 1 - .../util/experience/ExperienceBarManager.java | 11 +++++++---- .../util/scoreboards/ScoreboardWrapper.java | 15 +++++++-------- 37 files changed, 188 insertions(+), 141 deletions(-) diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/datatypes/player/BukkitMMOPlayer.java b/mcmmo-core/src/main/java/com/gmail/nossr50/datatypes/player/BukkitMMOPlayer.java index 0fcf262b1..397c391ee 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/datatypes/player/BukkitMMOPlayer.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/datatypes/player/BukkitMMOPlayer.java @@ -322,7 +322,9 @@ public class BukkitMMOPlayer implements MMOPlayer { public void resetSuperAbilityMode() { for (SuperAbilityType superAbilityType : SuperAbilityType.values()) { // Correctly disable and handle any special deactivate code - new AbilityDisableTask(pluginRef,this, superAbilityType).run(); + pluginRef.getPlatformProvider().getScheduler().getTaskBuilder() + .setTask(new AbilityDisableTask(pluginRef,this, superAbilityType)) + .schedule(); } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/MobHealthDisplayUpdaterTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/MobHealthDisplayUpdaterTask.java index b7dc43815..a383da04a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/MobHealthDisplayUpdaterTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/MobHealthDisplayUpdaterTask.java @@ -2,11 +2,14 @@ package com.gmail.nossr50.runnables; import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.entity.LivingEntity; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; -public class MobHealthDisplayUpdaterTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class MobHealthDisplayUpdaterTask implements Consumer { private final mcMMO pluginRef; private LivingEntity target; @@ -16,7 +19,7 @@ public class MobHealthDisplayUpdaterTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (target.hasMetadata(MetadataConstants.CUSTOM_NAME_METAKEY.getKey())) { target.setCustomName(target.getMetadata(MetadataConstants.CUSTOM_NAME_METAKEY.getKey()).get(0).asString()); target.removeMetadata(MetadataConstants.CUSTOM_NAME_METAKEY.getKey(), (Plugin) pluginRef.getPlatformProvider()); diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/PistonTrackerTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/PistonTrackerTask.java index 03f6d0140..0d7238713 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/PistonTrackerTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/PistonTrackerTask.java @@ -2,14 +2,16 @@ package com.gmail.nossr50.runnables; import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import java.util.List; +import java.util.function.Consumer; -public class PistonTrackerTask extends BukkitRunnable { +public class PistonTrackerTask implements Consumer { private final mcMMO pluginRef; private List blocks; private BlockFace direction; @@ -23,7 +25,7 @@ public class PistonTrackerTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { // Check to see if futureEmptyBlock is empty - if it isn't; the blocks didn't move if (!pluginRef.getBlockTools().isPistonPiece(futureEmptyBlock.getState())) { return; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java index aaccd63f3..8fb585d3e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java @@ -2,10 +2,12 @@ package com.gmail.nossr50.runnables; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask; -import org.bukkit.scheduler.BukkitRunnable; -public class SaveTimerTask implements Runnable { +import java.util.function.Consumer; + +public class SaveTimerTask implements Consumer { private final mcMMO pluginRef; @@ -14,7 +16,7 @@ public class SaveTimerTask implements Runnable { } @Override - public void run() { + public void accept(Task task) { // All player data will be saved periodically through this int count = 1; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java index a35843ef5..68674d70a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java @@ -1,11 +1,14 @@ package com.gmail.nossr50.runnables; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.scheduler.BukkitRunnable; -public class StickyPistonTrackerTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class StickyPistonTrackerTask implements Consumer { private final mcMMO pluginRef; private BlockFace direction; private Block block; @@ -19,7 +22,7 @@ public class StickyPistonTrackerTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (!pluginRef.getPlaceStore().isTrue(movedBlock.getRelative(direction))) { return; } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/backups/CleanBackupFilesTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/backups/CleanBackupFilesTask.java index bba98d044..c86daf551 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/backups/CleanBackupFilesTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/backups/CleanBackupFilesTask.java @@ -1,7 +1,7 @@ package com.gmail.nossr50.runnables.backups; import com.gmail.nossr50.mcMMO; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import java.io.File; import java.text.ParseException; @@ -11,8 +11,9 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; -public class CleanBackupFilesTask extends BukkitRunnable { +public class CleanBackupFilesTask implements Consumer { private final mcMMO pluginRef; private final File BACKUP_DIR; @@ -23,7 +24,7 @@ public class CleanBackupFilesTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { List savedDays = new ArrayList<>(); //TODO: Should probably look into why this isn't used... HashMap> savedYearsWeeks = new HashMap<>(); //TODO: Should probably look into why this isn't used... List toDelete = new ArrayList<>(); diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/LeaderboardsCommandAsyncTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/LeaderboardsCommandAsyncTask.java index de5021379..0dd0b81bd 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/LeaderboardsCommandAsyncTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/LeaderboardsCommandAsyncTask.java @@ -3,14 +3,16 @@ package com.gmail.nossr50.runnables.commands; import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.apache.commons.lang.Validate; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.util.List; +import java.util.function.Consumer; -public class LeaderboardsCommandAsyncTask extends BukkitRunnable { +public class LeaderboardsCommandAsyncTask implements Consumer { private final mcMMO pluginRef; private final CommandSender sender; private final PrimarySkillType skill; @@ -35,7 +37,7 @@ public class LeaderboardsCommandAsyncTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { final List userStats = pluginRef.getDatabaseManager().readLeaderboard(skill, page, 10); pluginRef.getPlatformProvider().getScheduler().getTaskBuilder() diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/LeaderboardsCommandDisplayTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/LeaderboardsCommandDisplayTask.java index 01da87f5e..7fb0e8439 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/LeaderboardsCommandDisplayTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/LeaderboardsCommandDisplayTask.java @@ -4,18 +4,20 @@ import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import java.util.List; +import java.util.function.Consumer; /** * Display the results of {@link LeaderboardsCommandAsyncTask} to the sender. */ -public class LeaderboardsCommandDisplayTask extends BukkitRunnable { +public class LeaderboardsCommandDisplayTask implements Consumer { private final mcMMO pluginRef; private final List userStats; private final CommandSender sender; @@ -34,7 +36,7 @@ public class LeaderboardsCommandDisplayTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (useBoard && pluginRef.getScoreboardSettings().getScoreboardsEnabled()) { displayBoard(); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/NotifySquelchReminderTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/NotifySquelchReminderTask.java index 4ff268600..a4f99f570 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/NotifySquelchReminderTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/NotifySquelchReminderTask.java @@ -1,12 +1,15 @@ package com.gmail.nossr50.runnables.commands; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; + +import java.util.function.Consumer; //TODO: Rewrite, wrote this in a rush. -public class NotifySquelchReminderTask extends BukkitRunnable { +public class NotifySquelchReminderTask implements Consumer { private final mcMMO pluginRef; @@ -15,7 +18,7 @@ public class NotifySquelchReminderTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { for (Player player : Bukkit.getOnlinePlayers()) { if (pluginRef.getUserManager().getPlayer(player) != null) { if (!pluginRef.getUserManager().getPlayer(player).useChatNotifications()) { diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/RankCommandAsyncTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/RankCommandAsyncTask.java index ec18409f6..4c1fc102e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/RankCommandAsyncTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/RankCommandAsyncTask.java @@ -2,14 +2,16 @@ package com.gmail.nossr50.runnables.commands; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.apache.commons.lang.Validate; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.util.Map; +import java.util.function.Consumer; -public class RankCommandAsyncTask extends BukkitRunnable { +public class RankCommandAsyncTask implements Consumer { private final mcMMO pluginRef; private final String playerName; private final CommandSender sender; @@ -31,7 +33,7 @@ public class RankCommandAsyncTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { Map skills = pluginRef.getDatabaseManager().readRank(playerName); pluginRef.getPlatformProvider().getScheduler().getTaskBuilder() diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/RankCommandDisplayTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/RankCommandDisplayTask.java index 0aac2c39c..1556abf77 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/RankCommandDisplayTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/RankCommandDisplayTask.java @@ -3,17 +3,19 @@ package com.gmail.nossr50.runnables.commands; import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import java.util.Map; +import java.util.function.Consumer; /** * Display the results of RankCommandAsyncTask to the sender. */ -public class RankCommandDisplayTask extends BukkitRunnable { +public class RankCommandDisplayTask implements Consumer { private final mcMMO pluginRef; private final Map skills; private final CommandSender sender; @@ -30,7 +32,7 @@ public class RankCommandDisplayTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (useBoard && pluginRef.getScoreboardSettings().getScoreboardsEnabled()) { displayBoard(); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/ScoreboardKeepTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/ScoreboardKeepTask.java index 280bb784d..fcd75fb8c 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/ScoreboardKeepTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/commands/ScoreboardKeepTask.java @@ -1,10 +1,13 @@ package com.gmail.nossr50.runnables.commands; import com.gmail.nossr50.mcMMO; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; -public class ScoreboardKeepTask extends BukkitRunnable { +import org.bukkit.entity.Player; + +import java.util.function.Consumer; + +public class ScoreboardKeepTask implements Consumer { private final mcMMO pluginRef; private Player player; @@ -14,7 +17,7 @@ public class ScoreboardKeepTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (player.isValid() && pluginRef.getScoreboardManager().isBoardShown(player.getName())) { pluginRef.getScoreboardManager().keepBoard(player.getName()); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/DatabaseConversionTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/DatabaseConversionTask.java index 28137c945..16278cd72 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/DatabaseConversionTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/DatabaseConversionTask.java @@ -5,7 +5,6 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitRunnable; import java.util.function.Consumer; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/FormulaConversionTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/FormulaConversionTask.java index a3a373a5f..b2827526e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/FormulaConversionTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/FormulaConversionTask.java @@ -5,8 +5,11 @@ import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitRunnable; + +import java.util.function.Consumer; //TODO: PUUUUUUUUUUURGE /** @@ -16,7 +19,7 @@ import org.bukkit.scheduler.BukkitRunnable; * * Fix this at some point in the future */ -public class FormulaConversionTask extends BukkitRunnable { +public class FormulaConversionTask implements Consumer { private CommandSender sender; private FormulaType previousFormula; private mcMMO pluginRef; @@ -28,7 +31,7 @@ public class FormulaConversionTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { int convertedUsers = 0; long startMillis = System.currentTimeMillis(); for (String playerName : pluginRef.getDatabaseManager().getStoredUsers()) { diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java index 29c98ed4d..8b13b616e 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java @@ -1,16 +1,17 @@ package com.gmail.nossr50.runnables.database; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import com.gmail.nossr50.util.uuid.UUIDFetcher; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.function.Consumer; import java.util.logging.Level; -public class UUIDUpdateAsyncTask extends BukkitRunnable { +public class UUIDUpdateAsyncTask implements Consumer { private mcMMO pluginRef; private final int MAX_LOOKUP = 100; private final int RATE_LIMIT = 300; @@ -31,7 +32,7 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { size = userNames.size(); pluginRef.getLogger().info("Starting to check and update UUIDs, total amount of users: " + size); diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/UserPurgeTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/UserPurgeTask.java index 1385016e8..dcb804454 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/UserPurgeTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/database/UserPurgeTask.java @@ -1,11 +1,12 @@ package com.gmail.nossr50.runnables.database; import com.gmail.nossr50.mcMMO; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Consumer; -public class UserPurgeTask extends BukkitRunnable { +public class UserPurgeTask implements Consumer { private final mcMMO pluginRef; private ReentrantLock lock; @@ -15,7 +16,7 @@ public class UserPurgeTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { lock.lock(); if (pluginRef.getDatabaseCleaningSettings().isPurgePowerlessUsers()) pluginRef.getDatabaseManager().purgePowerlessUsers(); diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java index 4146fa811..6f6e541bb 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/items/ChimaeraWingWarmup.java @@ -2,13 +2,16 @@ package com.gmail.nossr50.runnables.items; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import com.gmail.nossr50.util.ChimaeraWing; + import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; -public class ChimaeraWingWarmup extends BukkitRunnable { +import java.util.function.Consumer; + +public class ChimaeraWingWarmup implements Consumer { private mcMMO pluginRef; private BukkitMMOPlayer mcMMOPlayer; @@ -18,7 +21,7 @@ public class ChimaeraWingWarmup extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { checkChimaeraWingTeleport(); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java index 13422f2ee..79e9e2e59 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/items/TeleportationWarmup.java @@ -2,12 +2,15 @@ package com.gmail.nossr50.runnables.items; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; -public class TeleportationWarmup extends BukkitRunnable { +import java.util.function.Consumer; + +public class TeleportationWarmup implements Consumer { private final mcMMO pluginRef; private BukkitMMOPlayer mcMMOPlayer; private BukkitMMOPlayer mcMMOTarget; @@ -19,7 +22,7 @@ public class TeleportationWarmup extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { Player teleportingPlayer = mcMMOPlayer.getNative(); Player targetPlayer = mcMMOTarget.getNative(); Location previousLocation = mcMMOPlayer.getTeleportCommenceLocation(); diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java index 0f7a2ec6f..4814176a9 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java @@ -6,7 +6,6 @@ import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; import java.util.HashMap; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/ClearRegisteredXPGainTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/ClearRegisteredXPGainTask.java index 72a56b186..e6ab6b28b 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/ClearRegisteredXPGainTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/ClearRegisteredXPGainTask.java @@ -2,9 +2,11 @@ package com.gmail.nossr50.runnables.player; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.mcMMO; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; -public class ClearRegisteredXPGainTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class ClearRegisteredXPGainTask implements Consumer { private final mcMMO pluginRef; @@ -13,7 +15,7 @@ public class ClearRegisteredXPGainTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { for (BukkitMMOPlayer mcMMOPlayer : pluginRef.getUserManager().getPlayers()) { mcMMOPlayer.getProfile().purgeExpiredXpGains(); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java index 236537e7b..f8b60cd21 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java @@ -3,14 +3,16 @@ package com.gmail.nossr50.runnables.player; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import com.gmail.nossr50.runnables.commands.ScoreboardKeepTask; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; -public class PlayerProfileLoadingTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class PlayerProfileLoadingTask implements Consumer { private final mcMMO pluginRef; private final Player player; private int attempt = 0; @@ -29,8 +31,7 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { // WARNING: ASYNC TASK // DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE @Override - public void run() { - + public void accept(Task task) { if (pluginRef.getMiscTools().isNPCIncludingVillagers(player)) { return; } @@ -73,7 +74,7 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { .schedule(); } - private class ApplySuccessfulProfile extends BukkitRunnable { + private class ApplySuccessfulProfile implements Consumer { private final BukkitMMOPlayer mcMMOPlayer; private ApplySuccessfulProfile(BukkitMMOPlayer mcMMOPlayer) { @@ -83,7 +84,7 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { // Synchronized task // No database access permitted @Override - public void run() { + public void accept(Task task) { if (!player.isOnline()) { pluginRef.getLogger().info("Aborting profile loading recovery for " + player.getName() + " - player logged out"); return; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileSaveTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileSaveTask.java index 593d785ca..e4256c297 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileSaveTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileSaveTask.java @@ -1,9 +1,11 @@ package com.gmail.nossr50.runnables.player; import com.gmail.nossr50.datatypes.player.PlayerProfile; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; -public class PlayerProfileSaveTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class PlayerProfileSaveTask implements Consumer { private PlayerProfile playerProfile; private boolean isSync; @@ -13,7 +15,7 @@ public class PlayerProfileSaveTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { playerProfile.save(isSync); } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerUpdateInventoryTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerUpdateInventoryTask.java index 7658f62f2..f434ae364 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerUpdateInventoryTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PlayerUpdateInventoryTask.java @@ -1,9 +1,12 @@ package com.gmail.nossr50.runnables.player; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; -public class PlayerUpdateInventoryTask extends BukkitRunnable { +import org.bukkit.entity.Player; + +import java.util.function.Consumer; + +public class PlayerUpdateInventoryTask implements Consumer { private Player player; public PlayerUpdateInventoryTask(Player player) { @@ -11,7 +14,7 @@ public class PlayerUpdateInventoryTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { player.updateInventory(); } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PowerLevelUpdatingTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PowerLevelUpdatingTask.java index 747ce3728..d0f0d324f 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PowerLevelUpdatingTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/player/PowerLevelUpdatingTask.java @@ -1,9 +1,11 @@ package com.gmail.nossr50.runnables.player; import com.gmail.nossr50.mcMMO; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; -public class PowerLevelUpdatingTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class PowerLevelUpdatingTask implements Consumer { private final mcMMO pluginRef; @@ -12,9 +14,9 @@ public class PowerLevelUpdatingTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (!pluginRef.getScoreboardManager().powerLevelHeartbeat()) { - this.cancel(); + task.cancel(); } } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AbilityCooldownTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AbilityCooldownTask.java index 79539bd40..0754cde28 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AbilityCooldownTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AbilityCooldownTask.java @@ -4,9 +4,11 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.mcMMO; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; -public class AbilityCooldownTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class AbilityCooldownTask implements Consumer { private final mcMMO pluginRef; private final BukkitMMOPlayer mcMMOPlayer; private final SuperAbilityType superAbilityType; @@ -18,7 +20,7 @@ public class AbilityCooldownTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (!mcMMOPlayer.getNative().isOnline() || mcMMOPlayer.getSuperAbilityInformed(superAbilityType)) { return; } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AbilityDisableTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AbilityDisableTask.java index 5293d945b..d7abd0968 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AbilityDisableTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AbilityDisableTask.java @@ -4,12 +4,15 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; -public class AbilityDisableTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class AbilityDisableTask implements Consumer { private final mcMMO pluginRef; private BukkitMMOPlayer mcMMOPlayer; private SuperAbilityType superAbilityType; @@ -21,7 +24,7 @@ public class AbilityDisableTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (!mcMMOPlayer.getSuperAbilityMode(superAbilityType)) { return; } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java index 59006a205..c425d344a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java @@ -4,11 +4,14 @@ import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.entity.LivingEntity; -import org.bukkit.scheduler.BukkitRunnable; + +import java.util.function.Consumer; //TODO: Why is this a task? Investigate later. -public class AwardCombatXpTask extends BukkitRunnable { +public class AwardCombatXpTask implements Consumer { private BukkitMMOPlayer mcMMOPlayer; private double baseXp; private PrimarySkillType primarySkillType; @@ -26,7 +29,7 @@ public class AwardCombatXpTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { double health = target.getHealth(); double damage = baseHealth - health; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java index f2b8ef1c9..1c2b4d78d 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java @@ -4,20 +4,22 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.skills.BleedContainer; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import com.gmail.nossr50.util.sounds.SoundType; + import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Consumer; -public class BleedTimerTask extends BukkitRunnable { +public class BleedTimerTask implements Consumer { private final mcMMO pluginRef; private Map bleedList; private boolean isIterating = false; @@ -71,13 +73,12 @@ public class BleedTimerTask extends BukkitRunnable { BleedContainer newBleedContainer = new BleedContainer(entity, ticks, bleedRank, toolTier, attacker); bleedList.put(entity, newBleedContainer); } - public boolean isBleeding(LivingEntity entity) { return bleedList.containsKey(entity); } @Override - public void run() { + public void accept(Task task) { isIterating = true; Iterator> bleedIterator = bleedList.entrySet().iterator(); diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java index b2dcc1478..4b8c01fe9 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/DelayedCropReplant.java @@ -3,6 +3,8 @@ package com.gmail.nossr50.runnables.skills; import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.datatypes.meta.RecentlyReplantedCropMeta; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -13,9 +15,10 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Directional; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; -public class DelayedCropReplant extends BukkitRunnable { +import java.util.function.Consumer; + +public class DelayedCropReplant implements Consumer { private final int desiredCropAge; private final Location cropLocation; @@ -48,7 +51,7 @@ public class DelayedCropReplant extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { Block cropBlock = cropLocation.getBlock(); BlockState currentState = cropBlock.getState(); @@ -104,7 +107,7 @@ public class DelayedCropReplant extends BukkitRunnable { } - private class markPlantAsOld extends BukkitRunnable { + private class markPlantAsOld implements Consumer { private final Location cropLoc; @@ -113,7 +116,7 @@ public class DelayedCropReplant extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { Block cropBlock = cropLoc.getBlock(); if(cropBlock.getMetadata(MetadataConstants.REPLANT_META_KEY.getKey()).size() > 0) { diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/DelayedHerbalismXPCheckTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/DelayedHerbalismXPCheckTask.java index 6742c63fc..2f25ab95a 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/DelayedHerbalismXPCheckTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/DelayedHerbalismXPCheckTask.java @@ -2,11 +2,12 @@ package com.gmail.nossr50.runnables.skills; import com.gmail.nossr50.datatypes.BlockSnapshot; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import java.util.ArrayList; +import java.util.function.Consumer; -public class DelayedHerbalismXPCheckTask extends BukkitRunnable { +public class DelayedHerbalismXPCheckTask implements Consumer { private final BukkitMMOPlayer mcMMOPlayer; private final ArrayList chorusBlocks; @@ -17,7 +18,7 @@ public class DelayedHerbalismXPCheckTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { mcMMOPlayer.getHerbalismManager().awardXPForBlockSnapshots(chorusBlocks); } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/ExperienceBarHideTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/ExperienceBarHideTask.java index cdbefed2c..5d9467d45 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/ExperienceBarHideTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/ExperienceBarHideTask.java @@ -2,10 +2,12 @@ package com.gmail.nossr50.runnables.skills; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import com.gmail.nossr50.util.experience.ExperienceBarManager; -import org.bukkit.scheduler.BukkitRunnable; -public class ExperienceBarHideTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class ExperienceBarHideTask implements Consumer { private final BukkitMMOPlayer mcMMOPlayer; private final PrimarySkillType primarySkillType; private final ExperienceBarManager experienceBarManagerRef; @@ -16,19 +18,8 @@ public class ExperienceBarHideTask extends BukkitRunnable { this.primarySkillType = primarySkillType; } - /** - * When an object implementing interface Runnable is used - * to create a thread, starting the thread causes the object's - * run method to be called in that separately executing - * thread. - *

- * The general contract of the method run is that it may - * take any action whatsoever. - * - * @see Thread#run() - */ @Override - public void run() { + public void accept(Task task) { if (experienceBarManagerRef == null || mcMMOPlayer == null) return; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/HerbalismBlockUpdaterTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/HerbalismBlockUpdaterTask.java index 102c9b0b7..627acb5e2 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/HerbalismBlockUpdaterTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/HerbalismBlockUpdaterTask.java @@ -1,9 +1,12 @@ package com.gmail.nossr50.runnables.skills; -import org.bukkit.block.BlockState; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; -public class HerbalismBlockUpdaterTask extends BukkitRunnable { +import org.bukkit.block.BlockState; + +import java.util.function.Consumer; + +public class HerbalismBlockUpdaterTask implements Consumer { private final BlockState blockState; public HerbalismBlockUpdaterTask(BlockState blockState) { @@ -11,7 +14,7 @@ public class HerbalismBlockUpdaterTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { blockState.update(true); } } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/SkillUnlockNotificationTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/SkillUnlockNotificationTask.java index a26e46fa2..747ff4c44 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/SkillUnlockNotificationTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/SkillUnlockNotificationTask.java @@ -3,10 +3,12 @@ package com.gmail.nossr50.runnables.skills; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.mcMMO; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; + +import java.util.function.Consumer; -public class SkillUnlockNotificationTask extends BukkitRunnable { +public class SkillUnlockNotificationTask implements Consumer { private final mcMMO pluginRef; private final BukkitMMOPlayer mcMMOPlayer; private final SubSkillType subSkillType; @@ -23,19 +25,8 @@ public class SkillUnlockNotificationTask extends BukkitRunnable { this.subSkillType = subSkillType; } - /** - * When an object implementing interface Runnable is used - * to create a thread, starting the thread causes the object's - * run method to be called in that separately executing - * thread. - *

- * The general contract of the method run is that it may - * take any action whatsoever. - * - * @see Thread#run() - */ @Override - public void run() { + public void accept(Task task) { //mcMMOPlayer.getPlayer().sendTitle(subSkillType.getLocaleName(), "Rank "+rank, 7, 20, 7); pluginRef.getNotificationManager().sendPlayerUnlockNotification(mcMMOPlayer, subSkillType); } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/ToolLowerTask.java b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/ToolLowerTask.java index c17a8926a..16bd222ec 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/ToolLowerTask.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/runnables/skills/ToolLowerTask.java @@ -4,9 +4,11 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.skills.ToolType; import com.gmail.nossr50.mcMMO; -import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; -public class ToolLowerTask extends BukkitRunnable { +import java.util.function.Consumer; + +public class ToolLowerTask implements Consumer { private final mcMMO pluginRef; private final BukkitMMOPlayer mcMMOPlayer; private final ToolType tool; @@ -18,7 +20,7 @@ public class ToolLowerTask extends BukkitRunnable { } @Override - public void run() { + public void accept(Task task) { if (!mcMMOPlayer.getToolPreparationMode(tool)) { return; } diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/skills/taming/TrackedTamingEntity.java b/mcmmo-core/src/main/java/com/gmail/nossr50/skills/taming/TrackedTamingEntity.java index 832c718bf..3d5ce1895 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/skills/taming/TrackedTamingEntity.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/skills/taming/TrackedTamingEntity.java @@ -8,7 +8,6 @@ import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.scheduler.BukkitRunnable; import java.util.UUID; import java.util.function.Consumer; diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/experience/ExperienceBarManager.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/experience/ExperienceBarManager.java index c4e830810..7281d3674 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/experience/ExperienceBarManager.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/experience/ExperienceBarManager.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.util.experience; import com.gmail.nossr50.datatypes.player.BukkitMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.mcmmo.api.platform.scheduler.Task; import com.gmail.nossr50.runnables.skills.ExperienceBarHideTask; import org.bukkit.plugin.Plugin; @@ -14,7 +15,7 @@ import java.util.HashMap; */ public class ExperienceBarManager { HashMap experienceBars; - HashMap experienceBarHideTaskHashMap; + HashMap experienceBarHideTaskHashMap; private BukkitMMOPlayer mcMMOPlayer; private final mcMMO pluginRef; @@ -55,9 +56,11 @@ public class ExperienceBarManager { } private void scheduleHideTask(PrimarySkillType primarySkillType, Plugin plugin) { - ExperienceBarHideTask experienceBarHideTask = new ExperienceBarHideTask(this, mcMMOPlayer, primarySkillType); - experienceBarHideTask.runTaskLater(plugin, 20 * 2); - experienceBarHideTaskHashMap.put(primarySkillType, experienceBarHideTask); + Task task = pluginRef.getPlatformProvider().getScheduler().getTaskBuilder() + .setDelay(20 * 2L) + .setTask(new ExperienceBarHideTask(this, mcMMOPlayer, primarySkillType)) + .schedule(); + experienceBarHideTaskHashMap.put(primarySkillType, task); } public void hideExperienceBar(PrimarySkillType primarySkillType) { diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java b/mcmmo-core/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java index de1297a3b..143bb5ab3 100644 --- a/mcmmo-core/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java @@ -16,8 +16,6 @@ import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Score; @@ -25,6 +23,7 @@ import org.bukkit.scoreboard.Scoreboard; import java.util.List; import java.util.Map; +import java.util.function.Consumer; public class ScoreboardWrapper { // Initialization variables @@ -563,25 +562,25 @@ public class ScoreboardWrapper { powerObjective.getScore(player.getName()).setScore(newPowerLevel); } - private class ScoreboardQuickUpdate extends BukkitRunnable { + private class ScoreboardQuickUpdate implements Consumer { @Override - public void run() { + public void accept(Task task) { updateSidebar(); updateTask = null; } } - private class ScoreboardChangeTask extends BukkitRunnable { + private class ScoreboardChangeTask implements Consumer { @Override - public void run() { + public void accept(Task task) { tryRevertBoard(); revertTask = null; } } - private class ScoreboardCooldownTask extends BukkitRunnable { + private class ScoreboardCooldownTask implements Consumer { @Override - public void run() { + public void accept(Task task) { // Stop updating if it's no longer something displaying cooldowns if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) { doSidebarUpdateSoon();