From 399bf8e3b99fd909f906a9e2c27b7bbb503474a6 Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 20 Mar 2013 03:11:16 -0400 Subject: [PATCH] Use BukkitRunnable. --- .../commands/database/MmoupdateCommand.java | 2 +- .../commands/player/McrankCommand.java | 2 +- .../nossr50/commands/player/MctopCommand.java | 2 +- .../nossr50/database/DatabaseManager.java | 2 +- .../nossr50/listeners/BlockListener.java | 2 +- src/main/java/com/gmail/nossr50/mcMMO.java | 23 +++++---- .../nossr50/runnables/SaveTimerTask.java | 7 ++- .../runnables/StickyPistonTrackerTask.java | 3 +- .../commands/McrankCommandAsyncTask.java | 39 ++------------- .../commands/McrankCommandDisplayTask.java | 50 +++++++++++++++++++ .../commands/MctopCommandAsyncTask.java | 30 ++--------- .../commands/MctopCommandDisplayTask.java | 48 ++++++++++++++++++ .../runnables/database/SQLConversionTask.java | 4 +- .../runnables/database/SQLReconnectTask.java | 3 +- .../runnables/database/UserPurgeTask.java | 4 +- .../runnables/party/PartyAutoKickTask.java | 3 +- .../runnables/party/PartyLoaderTask.java | 4 +- .../player/PlayerProfileSaveTask.java | 4 +- .../runnables/skills/AwardCombatXpTask.java | 3 +- .../runnables/skills/BleedTimerTask.java | 3 +- .../skills/HerbalismBlockUpdaterTask.java | 3 +- .../runnables/skills/SkillMonitorTask.java | 4 +- .../nossr50/skills/archery/TrackedEntity.java | 12 ++--- .../skills/herbalism/HerbalismManager.java | 2 +- .../nossr50/util/skills/CombatUtils.java | 2 +- 25 files changed, 159 insertions(+), 102 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java create mode 100644 src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java diff --git a/src/main/java/com/gmail/nossr50/commands/database/MmoupdateCommand.java b/src/main/java/com/gmail/nossr50/commands/database/MmoupdateCommand.java index 6c819920a..8492ac34e 100644 --- a/src/main/java/com/gmail/nossr50/commands/database/MmoupdateCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/database/MmoupdateCommand.java @@ -46,6 +46,6 @@ public class MmoupdateCommand implements CommandExecutor { return; } - mcMMO.p.getServer().getScheduler().runTaskLaterAsynchronously(mcMMO.p, new SQLConversionTask(), 1); + new SQLConversionTask().runTaskLaterAsynchronously(mcMMO.p, 1); } } diff --git a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java index a17639bc6..760afc788 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java @@ -104,6 +104,6 @@ public class McrankCommand implements CommandExecutor { } private void sqlDisplay(CommandSender sender, String playerName) { - mcMMO.p.getServer().getScheduler().runTaskAsynchronously(mcMMO.p, new McrankCommandAsyncTask(playerName, sender)); + new McrankCommandAsyncTask(playerName, sender).runTaskAsynchronously(mcMMO.p); } } diff --git a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java index 794a1934f..4d9b63f22 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java @@ -111,7 +111,7 @@ public class MctopCommand implements CommandExecutor { } private void sqlDisplay(int page, String query, CommandSender sender) { - mcMMO.p.getServer().getScheduler().runTaskAsynchronously(mcMMO.p, new MctopCommandAsyncTask(page, query, sender)); + new MctopCommandAsyncTask(page, query, sender).runTaskAsynchronously(mcMMO.p); } private boolean extractSkill(CommandSender sender, String skillName) { diff --git a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java index 45cba591a..89c630285 100644 --- a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java @@ -336,7 +336,7 @@ public final class DatabaseManager { if (connection != null && !connection.isClosed()) { // Schedule a database save if we really had an outage if (reconnectAttempt > 1) { - mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new SQLReconnectTask(), 5); + new SQLReconnectTask().runTaskLater(mcMMO.p, 5); } nextReconnectTimestamp = 0; reconnectAttempt = 0; diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 0998b3cb1..46b859b7f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -88,7 +88,7 @@ public class BlockListener implements Listener { public void onBlockPistonRetract(BlockPistonRetractEvent event) { if (event.isSticky()) { // Needed only because under some circumstances Minecraft doesn't move the block - plugin.getServer().getScheduler().runTaskLater(plugin, new StickyPistonTrackerTask(event), 2); + new StickyPistonTrackerTask(event).runTaskLater(plugin, 2); } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 9381d9c73..0af3fe9f4 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -13,7 +13,6 @@ import org.bukkit.event.HandlerList; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitScheduler; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; @@ -402,42 +401,44 @@ public class mcMMO extends JavaPlugin { } private void scheduleTasks() { - BukkitScheduler scheduler = getServer().getScheduler(); - // Parties are loaded at the end of first server tick otherwise Server.getOfflinePlayer throws an IndexOutOfBoundsException - scheduler.runTaskLater(this, new PartyLoaderTask(), 0); + new PartyLoaderTask().runTaskLater(this, 0); // Periodic save timer (Saves every 10 minutes by default) long saveIntervalTicks = Config.getInstance().getSaveInterval() * 1200; - scheduler.runTaskTimer(this, new SaveTimerTask(), saveIntervalTicks, saveIntervalTicks); + new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks); + // Regen & Cooldown timer (Runs every second) - scheduler.runTaskTimer(this, new SkillMonitorTask(), 20, 20); + new SkillMonitorTask().runTaskTimer(this, 20, 20); + // Bleed timer (Runs every two seconds) - scheduler.runTaskTimer(this, new BleedTimerTask(), 40, 40); + new BleedTimerTask().runTaskTimer(this, 40, 40); // Old & Powerless User remover int purgeInterval = Config.getInstance().getPurgeInterval(); + UserPurgeTask userPurgeTask = new UserPurgeTask(); if (purgeInterval == 0) { - scheduler.runTaskLater(this, new UserPurgeTask(), 40); // Start 2 seconds after startup. + userPurgeTask.runTaskLater(this, 40); } else if (purgeInterval > 0) { long purgeIntervalTicks = purgeInterval * 60 * 60 * 20; - scheduler.runTaskTimer(this, new UserPurgeTask(), purgeIntervalTicks, purgeIntervalTicks); + userPurgeTask.runTaskTimer(this, purgeIntervalTicks, purgeIntervalTicks); } // Automatically remove old members from parties long kickInterval = Config.getInstance().getAutoPartyKickInterval(); + PartyAutoKickTask partyAutoKickTask = new PartyAutoKickTask(); if (kickInterval == 0) { - scheduler.runTaskLater(this, new PartyAutoKickTask(), 40); // Start 2 seconds after startup. + partyAutoKickTask.runTaskLater(this, 40); // Start 2 seconds after startup. } else if (kickInterval > 0) { long kickIntervalTicks = kickInterval * 60 * 60 * 20; - scheduler.runTaskTimer(this, new PartyAutoKickTask(), kickIntervalTicks, kickIntervalTicks); + partyAutoKickTask.runTaskTimer(this, kickIntervalTicks, kickIntervalTicks); } } } diff --git a/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java b/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java index 1b1aaaf79..a1652250d 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.runnables; -import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.player.McMMOPlayer; @@ -8,15 +8,14 @@ import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask; import com.gmail.nossr50.util.player.UserManager; -public class SaveTimerTask implements Runnable { +public class SaveTimerTask extends BukkitRunnable { @Override public void run() { // All player data will be saved periodically through this int count = 1; - BukkitScheduler bukkitScheduler = mcMMO.p.getServer().getScheduler(); for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers().values()) { - bukkitScheduler.runTaskLater(mcMMO.p, new PlayerProfileSaveTask(mcMMOPlayer), count); + new PlayerProfileSaveTask(mcMMOPlayer).runTaskLater(mcMMO.p, count); count++; } diff --git a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java index fcdda3c43..76a5716a3 100644 --- a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTrackerTask.java @@ -3,10 +3,11 @@ package com.gmail.nossr50.runnables; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.mcMMO; -public class StickyPistonTrackerTask implements Runnable { +public class StickyPistonTrackerTask extends BukkitRunnable { BlockPistonRetractEvent event; public StickyPistonTrackerTask(BlockPistonRetractEvent event) { diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandAsyncTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandAsyncTask.java index eb7338320..6010e5a4e 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandAsyncTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandAsyncTask.java @@ -3,16 +3,12 @@ package com.gmail.nossr50.runnables.commands; import java.util.Map; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.database.DatabaseManager; -import com.gmail.nossr50.datatypes.skills.SkillType; -import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.skills.SkillUtils; -public class McrankCommandAsyncTask implements Runnable { +public class McrankCommandAsyncTask extends BukkitRunnable { private final String playerName; private final CommandSender sender; @@ -23,35 +19,8 @@ public class McrankCommandAsyncTask implements Runnable { @Override public void run() { - final Map skills = DatabaseManager.readSQLRank(playerName); + Map skills = DatabaseManager.readSQLRank(playerName); - mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() { - @Override - public void run() { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading")); - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName)); - - for (SkillType skillType : SkillType.values()) { - if ((sender instanceof Player && !Permissions.skillEnabled(sender, skillType)) || skillType.isChildSkill()) { - continue; - } - - if (skills.get(skillType.name()) == null) { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); - } - else { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), skills.get(skillType.name()))); - } - } - - if (skills.get("ALL") == null) { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", LocaleLoader.getString("Commands.mcrank.Unranked"))); - } - else { - sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", skills.get("ALL"))); - } - } - - }, 1L); + new McrankCommandDisplayTask(skills, sender, playerName).runTaskLater(mcMMO.p, 1); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java new file mode 100644 index 000000000..5b18d86d4 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java @@ -0,0 +1,50 @@ +package com.gmail.nossr50.runnables.commands; + +import java.util.Map; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.skills.SkillUtils; + +public class McrankCommandDisplayTask extends BukkitRunnable { + private final Map skills; + private final CommandSender sender; + private final String playerName; + + public McrankCommandDisplayTask(Map skills, CommandSender sender, String playerName) { + this.skills = skills; + this.sender = sender; + this.playerName = playerName; + } + + @Override + public void run() { + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Heading")); + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Player", playerName)); + + for (SkillType skillType : SkillType.values()) { + if ((sender instanceof Player && !Permissions.skillEnabled(sender, skillType)) || skillType.isChildSkill()) { + continue; + } + + if (skills.get(skillType.name()) == null) { + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), LocaleLoader.getString("Commands.mcrank.Unranked"))); + } + else { + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Skill", SkillUtils.getSkillName(skillType), skills.get(skillType.name()))); + } + } + + if (skills.get("ALL") == null) { + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", LocaleLoader.getString("Commands.mcrank.Unranked"))); + } + else { + sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", skills.get("ALL"))); + } + } +} diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java index 1d35f68ab..3865896a1 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java @@ -3,16 +3,14 @@ package com.gmail.nossr50.runnables.commands; import java.util.ArrayList; import java.util.HashMap; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.DatabaseManager; -import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.util.StringUtils; -public class MctopCommandAsyncTask implements Runnable { +public class MctopCommandAsyncTask extends BukkitRunnable { private CommandSender sender; private String query; @@ -28,30 +26,8 @@ public class MctopCommandAsyncTask implements Runnable { public void run() { String tablePrefix = Config.getInstance().getMySQLTablePrefix(); final HashMap> userslist = DatabaseManager.read("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT " + ((page * 10) - 10) + ",10"); - mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new Runnable() { - @Override - public void run() { - if (query.equalsIgnoreCase("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) { - sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); - } - else { - sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(query))); - } - int place = (page * 10) - 9; - for (int i = 1; i <= 10; i++) { - if (userslist.get(i) == null) { - break; - } - - // Format: 1. Playername - skill value - sender.sendMessage(place + ". " + ChatColor.GREEN + userslist.get(i).get(1) + " - " + ChatColor.WHITE + userslist.get(i).get(0)); - place++; - } - - sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip")); - } - }, 1L); + new MctopCommandDisplayTask(userslist, page, tablePrefix, sender).runTaskLater(mcMMO.p, 1); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java new file mode 100644 index 000000000..6fd9e1ef2 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -0,0 +1,48 @@ +package com.gmail.nossr50.runnables.commands; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitRunnable; + +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.StringUtils; + +public class MctopCommandDisplayTask extends BukkitRunnable { + private HashMap> userslist; + private CommandSender sender; + private String query; + private int page; + + public MctopCommandDisplayTask(HashMap> userslist, int page, String query, CommandSender sender) { + this.userslist = userslist; + this.page = page; + this.query = query; + this.sender = sender; + } + + @Override + public void run() { + if (query.equalsIgnoreCase("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) { + sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); + } + else { + sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(query))); + } + + int place = (page * 10) - 9; + for (int i = 1; i <= 10; i++) { + if (userslist.get(i) == null) { + break; + } + + // Format: 1. Playername - skill value + sender.sendMessage(place + ". " + ChatColor.GREEN + userslist.get(i).get(1) + " - " + ChatColor.WHITE + userslist.get(i).get(0)); + place++; + } + + sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip")); + } +} diff --git a/src/main/java/com/gmail/nossr50/runnables/database/SQLConversionTask.java b/src/main/java/com/gmail/nossr50/runnables/database/SQLConversionTask.java index e2a840519..c1f34aac6 100644 --- a/src/main/java/com/gmail/nossr50/runnables/database/SQLConversionTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/database/SQLConversionTask.java @@ -3,13 +3,15 @@ package com.gmail.nossr50.runnables.database; import java.io.BufferedReader; import java.io.FileReader; +import org.bukkit.scheduler.BukkitRunnable; + import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.StringUtils; -public class SQLConversionTask implements Runnable { +public class SQLConversionTask extends BukkitRunnable { private String tablePrefix = Config.getInstance().getMySQLTablePrefix(); @Override diff --git a/src/main/java/com/gmail/nossr50/runnables/database/SQLReconnectTask.java b/src/main/java/com/gmail/nossr50/runnables/database/SQLReconnectTask.java index e4896a3c4..56904c1b4 100644 --- a/src/main/java/com/gmail/nossr50/runnables/database/SQLReconnectTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/database/SQLReconnectTask.java @@ -1,12 +1,13 @@ package com.gmail.nossr50.runnables.database; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.util.player.UserManager; -public class SQLReconnectTask implements Runnable { +public class SQLReconnectTask extends BukkitRunnable { @Override public void run() { if (DatabaseManager.checkConnected()) { diff --git a/src/main/java/com/gmail/nossr50/runnables/database/UserPurgeTask.java b/src/main/java/com/gmail/nossr50/runnables/database/UserPurgeTask.java index d0d1dc261..0206c054f 100644 --- a/src/main/java/com/gmail/nossr50/runnables/database/UserPurgeTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/database/UserPurgeTask.java @@ -1,10 +1,12 @@ package com.gmail.nossr50.runnables.database; +import org.bukkit.scheduler.BukkitRunnable; + import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.LeaderboardManager; -public class UserPurgeTask implements Runnable { +public class UserPurgeTask extends BukkitRunnable { @Override public void run() { if (Config.getInstance().getUseMySQL()) { diff --git a/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java b/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java index 5a78978c5..432615862 100644 --- a/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java @@ -3,12 +3,13 @@ package com.gmail.nossr50.runnables.party; import java.util.Iterator; import org.bukkit.OfflinePlayer; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.party.PartyManager; -public class PartyAutoKickTask implements Runnable { +public class PartyAutoKickTask extends BukkitRunnable { @Override public void run() { updatePartyMembers(); diff --git a/src/main/java/com/gmail/nossr50/runnables/party/PartyLoaderTask.java b/src/main/java/com/gmail/nossr50/runnables/party/PartyLoaderTask.java index 2f8986d27..4a7a2ee41 100644 --- a/src/main/java/com/gmail/nossr50/runnables/party/PartyLoaderTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/party/PartyLoaderTask.java @@ -1,8 +1,10 @@ package com.gmail.nossr50.runnables.party; +import org.bukkit.scheduler.BukkitRunnable; + import com.gmail.nossr50.party.PartyManager; -public class PartyLoaderTask implements Runnable { +public class PartyLoaderTask extends BukkitRunnable { @Override public void run() { PartyManager.loadParties(); diff --git a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileSaveTask.java b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileSaveTask.java index 6ed2f1c91..76b0ea4a2 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileSaveTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileSaveTask.java @@ -1,10 +1,12 @@ package com.gmail.nossr50.runnables.player; +import org.bukkit.scheduler.BukkitRunnable; + import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.util.player.UserManager; -public class PlayerProfileSaveTask implements Runnable { +public class PlayerProfileSaveTask extends BukkitRunnable { private McMMOPlayer mcMMOPlayer; private PlayerProfile playerProfile; diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java index 645193c9b..883f1e890 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java @@ -1,11 +1,12 @@ package com.gmail.nossr50.runnables.skills; import org.bukkit.entity.LivingEntity; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.SkillType; -public class AwardCombatXpTask implements Runnable { +public class AwardCombatXpTask extends BukkitRunnable { private McMMOPlayer mcMMOPlayer; private double baseXp; private SkillType skillType; diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java index 768ec5d8b..4ac8c2c00 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/BleedTimerTask.java @@ -7,12 +7,13 @@ import java.util.Map.Entry; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.ParticleEffectUtils; -public class BleedTimerTask implements Runnable { +public class BleedTimerTask extends BukkitRunnable { private final static int MAX_BLEED_TICKS = 10; private static Map bleedList = new HashMap(); diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/HerbalismBlockUpdaterTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/HerbalismBlockUpdaterTask.java index 5674273a3..38f5eb84d 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/HerbalismBlockUpdaterTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/HerbalismBlockUpdaterTask.java @@ -1,8 +1,9 @@ package com.gmail.nossr50.runnables.skills; import org.bukkit.block.BlockState; +import org.bukkit.scheduler.BukkitRunnable; -public class HerbalismBlockUpdaterTask implements Runnable { +public class HerbalismBlockUpdaterTask extends BukkitRunnable { private BlockState blockState; public HerbalismBlockUpdaterTask(BlockState blockState) { diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java index 4dbc73a52..916499f74 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java @@ -1,12 +1,14 @@ package com.gmail.nossr50.runnables.skills; +import org.bukkit.scheduler.BukkitRunnable; + import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; -public class SkillMonitorTask implements Runnable { +public class SkillMonitorTask extends BukkitRunnable { @Override public void run() { long curTime = System.currentTimeMillis(); diff --git a/src/main/java/com/gmail/nossr50/skills/archery/TrackedEntity.java b/src/main/java/com/gmail/nossr50/skills/archery/TrackedEntity.java index c6faab97e..ef7e7993c 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/TrackedEntity.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/TrackedEntity.java @@ -3,29 +3,27 @@ package com.gmail.nossr50.skills.archery; import java.util.UUID; import org.bukkit.entity.LivingEntity; -import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.mcMMO; -public class TrackedEntity implements Runnable { +public class TrackedEntity extends BukkitRunnable { private LivingEntity livingEntity; private UUID id; private int arrowCount; - private int taskId; - private BukkitScheduler scheduler; protected TrackedEntity(LivingEntity livingEntity) { this.livingEntity = livingEntity; this.id = livingEntity.getUniqueId(); - this.scheduler = mcMMO.p.getServer().getScheduler(); - this.taskId = scheduler.runTaskTimer(mcMMO.p, this, 12000, 12000).getTaskId(); + + this.runTaskTimer(mcMMO.p, 12000, 12000); } @Override public void run() { if (!livingEntity.isValid()) { Archery.removeFromTracker(this); - scheduler.cancelTask(taskId); + this.cancel(); } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 27b4e33ee..4479e9661 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -289,7 +289,7 @@ public class HerbalismManager extends SkillManager { playerInventory.removeItem(seed); player.updateInventory(); // Needed until replacement available - mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new HerbalismBlockUpdaterTask(blockState), 0); + new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0); } private boolean handleBlockState(BlockState blockState, boolean greenTerra) { diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index cba499eb4..8c6d95b02 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -486,7 +486,7 @@ public final class CombatUtils { } if (baseXP != 0) { - mcMMO.p.getServer().getScheduler().runTaskLater(mcMMO.p, new AwardCombatXpTask(mcMMOPlayer, skillType, baseXP, target), 0); + new AwardCombatXpTask(mcMMOPlayer, skillType, baseXP, target).runTaskLater(mcMMO.p, 0); } }