Complete BukkitRunnable migration

This commit is contained in:
Shane Freeder 2020-03-04 16:04:48 +00:00
parent a2c88d657c
commit 88767fd0a9
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C
37 changed files with 188 additions and 141 deletions

View File

@ -322,7 +322,9 @@ public class BukkitMMOPlayer implements MMOPlayer<Player> {
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();
}
}

View File

@ -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<Task> {
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());

View File

@ -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<Task> {
private final mcMMO pluginRef;
private List<Block> 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;

View File

@ -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<Task> {
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;

View File

@ -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<Task> {
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;
}

View File

@ -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<Task> {
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<Integer> savedDays = new ArrayList<>(); //TODO: Should probably look into why this isn't used...
HashMap<Integer, List<Integer>> savedYearsWeeks = new HashMap<>(); //TODO: Should probably look into why this isn't used...
List<File> toDelete = new ArrayList<>();

View File

@ -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<Task> {
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<PlayerStat> userStats = pluginRef.getDatabaseManager().readLeaderboard(skill, page, 10);
pluginRef.getPlatformProvider().getScheduler().getTaskBuilder()

View File

@ -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<Task> {
private final mcMMO pluginRef;
private final List<PlayerStat> 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();
}

View File

@ -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<Task> {
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()) {

View File

@ -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<Task> {
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<PrimarySkillType, Integer> skills = pluginRef.getDatabaseManager().readRank(playerName);
pluginRef.getPlatformProvider().getScheduler().getTaskBuilder()

View File

@ -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<Task> {
private final mcMMO pluginRef;
private final Map<PrimarySkillType, Integer> 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();
}

View File

@ -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<Task> {
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());
}

View File

@ -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;

View File

@ -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<Task> {
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()) {

View File

@ -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<Task> {
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);

View File

@ -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<Task> {
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();

View File

@ -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<Task> {
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();
}

View File

@ -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<Task> {
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();

View File

@ -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;

View File

@ -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<Task> {
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();
}

View File

@ -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<Task> {
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<Task> {
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;

View File

@ -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<Task> {
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);
}
}

View File

@ -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<Task> {
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();
}
}

View File

@ -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<Task> {
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();
}
}
}

View File

@ -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<Task> {
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;
}

View File

@ -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<Task> {
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;
}

View File

@ -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<Task> {
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;

View File

@ -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<Task> {
private final mcMMO pluginRef;
private Map<LivingEntity, BleedContainer> 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<Entry<LivingEntity, BleedContainer>> bleedIterator = bleedList.entrySet().iterator();

View File

@ -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<Task> {
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<Task> {
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) {

View File

@ -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<Task> {
private final BukkitMMOPlayer mcMMOPlayer;
private final ArrayList<BlockSnapshot> chorusBlocks;
@ -17,7 +18,7 @@ public class DelayedHerbalismXPCheckTask extends BukkitRunnable {
}
@Override
public void run() {
public void accept(Task task) {
mcMMOPlayer.getHerbalismManager().awardXPForBlockSnapshots(chorusBlocks);
}
}

View File

@ -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<Task> {
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 <code>Runnable</code> is used
* to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing
* thread.
* <p>
* The general contract of the method <code>run</code> 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;

View File

@ -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<Task> {
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);
}
}

View File

@ -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<Task> {
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 <code>Runnable</code> is used
* to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing
* thread.
* <p>
* The general contract of the method <code>run</code> 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);
}

View File

@ -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<Task> {
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;
}

View File

@ -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;

View File

@ -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<PrimarySkillType, ExperienceBarWrapper> experienceBars;
HashMap<PrimarySkillType, ExperienceBarHideTask> experienceBarHideTaskHashMap;
HashMap<PrimarySkillType, Task> 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) {

View File

@ -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<Task> {
@Override
public void run() {
public void accept(Task task) {
updateSidebar();
updateTask = null;
}
}
private class ScoreboardChangeTask extends BukkitRunnable {
private class ScoreboardChangeTask implements Consumer<Task> {
@Override
public void run() {
public void accept(Task task) {
tryRevertBoard();
revertTask = null;
}
}
private class ScoreboardCooldownTask extends BukkitRunnable {
private class ScoreboardCooldownTask implements Consumer<Task> {
@Override
public void run() {
public void accept(Task task) {
// Stop updating if it's no longer something displaying cooldowns
if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) {
doSidebarUpdateSoon();