From 997fac0d176164ae8f6afdb60adc5fc4216d06ad Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 3 Jul 2019 01:17:06 -0700 Subject: [PATCH] Remove Static Abuse - Player / Party Tasks --- .../runnables/party/PartyAutoKickTask.java | 9 ++- .../runnables/party/PartyChatTask.java | 56 +++++++++---------- .../player/ClearRegisteredXPGainTask.java | 8 +++ .../player/PlayerProfileLoadingTask.java | 14 +++-- .../player/PowerLevelUpdatingTask.java | 8 +++ 5 files changed, 61 insertions(+), 34 deletions(-) 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 4fe65d184..510a62e64 100644 --- a/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.runnables.party; import com.gmail.nossr50.datatypes.party.Party; +import com.gmail.nossr50.mcMMO; import org.bukkit.OfflinePlayer; import org.bukkit.scheduler.BukkitRunnable; @@ -11,7 +12,13 @@ import java.util.Map.Entry; import java.util.UUID; public class PartyAutoKickTask extends BukkitRunnable { - private final static long KICK_TIME = 24L * 60L * 60L * 1000L * pluginRef.getConfigManager().getConfigParty().getPartyCleanup().getPartyAutoKickHoursInterval(); + private final mcMMO pluginRef; + private final long KICK_TIME; + + public PartyAutoKickTask(mcMMO pluginRef) { + this.pluginRef = pluginRef; + KICK_TIME = 24L * 60L * 60L * 1000L * pluginRef.getConfigManager().getConfigParty().getPartyCleanup().getPartyAutoKickHoursInterval(); + } @Override public void run() { diff --git a/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java b/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java index f545436af..13ebbb6c5 100644 --- a/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java @@ -1,28 +1,28 @@ -package com.gmail.nossr50.runnables.party; - -import com.gmail.nossr50.datatypes.party.Party; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; - -public class PartyChatTask extends BukkitRunnable { - private Plugin plugin; - - private Party party; - private String senderName; - private String displayName; - private String message; - - public PartyChatTask(Plugin plugin, Party party, String senderName, String displayName, String message) { - this.plugin = plugin; - - this.party = party; - this.senderName = senderName; - this.displayName = displayName; - this.message = message; - } - - @Override - public void run() { - - } -} +//package com.gmail.nossr50.runnables.party; +// +//import com.gmail.nossr50.datatypes.party.Party; +//import org.bukkit.plugin.Plugin; +//import org.bukkit.scheduler.BukkitRunnable; +// +//public class PartyChatTask extends BukkitRunnable { +// private Plugin plugin; +// +// private Party party; +// private String senderName; +// private String displayName; +// private String message; +// +// public PartyChatTask(Plugin plugin, Party party, String senderName, String displayName, String message) { +// this.plugin = plugin; +// +// this.party = party; +// this.senderName = senderName; +// this.displayName = displayName; +// this.message = message; +// } +// +// @Override +// public void run() { +// +// } +//} diff --git a/src/main/java/com/gmail/nossr50/runnables/player/ClearRegisteredXPGainTask.java b/src/main/java/com/gmail/nossr50/runnables/player/ClearRegisteredXPGainTask.java index e74281edc..93a1caac7 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/ClearRegisteredXPGainTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/ClearRegisteredXPGainTask.java @@ -1,9 +1,17 @@ package com.gmail.nossr50.runnables.player; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.mcMMO; import org.bukkit.scheduler.BukkitRunnable; public class ClearRegisteredXPGainTask extends BukkitRunnable { + + private final mcMMO pluginRef; + + public ClearRegisteredXPGainTask(mcMMO pluginRef) { + this.pluginRef = pluginRef; + } + @Override public void run() { for (McMMOPlayer mcMMOPlayer : pluginRef.getUserManager().getPlayers()) { diff --git a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java index 156a91dad..aff55869a 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.runnables.player; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.runnables.commands.ScoreboardKeepTask; import com.gmail.nossr50.util.Misc; import org.bukkit.Server; @@ -9,14 +10,17 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; public class PlayerProfileLoadingTask extends BukkitRunnable { + private final mcMMO pluginRef; private final Player player; private int attempt = 0; - public PlayerProfileLoadingTask(Player player) { + public PlayerProfileLoadingTask(mcMMO pluginRef, Player player) { + this.pluginRef = pluginRef; this.player = player; } - private PlayerProfileLoadingTask(Player player, int attempt) { + private PlayerProfileLoadingTask(mcMMO pluginRef, Player player, int attempt) { + this.pluginRef = pluginRef; this.player = player; this.attempt = attempt; } @@ -39,7 +43,7 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { PlayerProfile profile = pluginRef.getDatabaseManager().loadPlayerProfile(player.getName(), player.getUniqueId(), true); // If successful, schedule the apply if (profile.isLoaded()) { - new ApplySuccessfulProfile(new McMMOPlayer(player, profile)).runTask(pluginRef); + new ApplySuccessfulProfile(new McMMOPlayer(player, profile, pluginRef)).runTask(pluginRef); return; } @@ -59,7 +63,7 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { // Increment attempt counter and try attempt++; - new PlayerProfileLoadingTask(player, attempt).runTaskLaterAsynchronously(pluginRef, (100 + (attempt * 100))); + new PlayerProfileLoadingTask(pluginRef, player, attempt).runTaskLaterAsynchronously(pluginRef, (100 + (attempt * 100))); } private class ApplySuccessfulProfile extends BukkitRunnable { @@ -87,7 +91,7 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { if (pluginRef.getScoreboardSettings().getShowStatsAfterLogin()) { pluginRef.getScoreboardManager().enablePlayerStatsScoreboard(player); - new ScoreboardKeepTask(player).runTaskLater(pluginRef, Misc.TICK_CONVERSION_FACTOR); + new ScoreboardKeepTask(pluginRef, player).runTaskLater(pluginRef, Misc.TICK_CONVERSION_FACTOR); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/player/PowerLevelUpdatingTask.java b/src/main/java/com/gmail/nossr50/runnables/player/PowerLevelUpdatingTask.java index 3604ee04b..747ce3728 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/PowerLevelUpdatingTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/PowerLevelUpdatingTask.java @@ -1,8 +1,16 @@ package com.gmail.nossr50.runnables.player; +import com.gmail.nossr50.mcMMO; import org.bukkit.scheduler.BukkitRunnable; public class PowerLevelUpdatingTask extends BukkitRunnable { + + private final mcMMO pluginRef; + + public PowerLevelUpdatingTask(mcMMO pluginRef) { + this.pluginRef = pluginRef; + } + @Override public void run() { if (!pluginRef.getScoreboardManager().powerLevelHeartbeat()) {