forked from SteamWar/SteamWar
Use @LinkedTimer for the timers of linked classes
The repeating timers that linked classes and the plugin main classes started once for the whole runtime now use @LinkedTimer, on Spigot (BauSystem, SpigotCore, LobbySystem, MissileWars, TowerRun, Teamserver) and Velocity. The FightInfoPacketSenders of MissileWars and TowerRun are linked themselves instead of being started by the main class.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
package de.steamwar.velocitycore;
|
||||
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedTimer;
|
||||
import de.steamwar.messages.Chatter;
|
||||
import de.steamwar.messages.Message;
|
||||
import de.steamwar.persistent.Subserver;
|
||||
@@ -35,7 +36,6 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static de.steamwar.persistent.Storage.eventServer;
|
||||
|
||||
@@ -58,13 +58,13 @@ public class EventStarter {
|
||||
|
||||
public EventStarter() {
|
||||
EventFight.loadAllComingFights();
|
||||
VelocityCore.schedule(this::run).repeat(10, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
public static Map<Integer, Subserver> getEventServer() {
|
||||
return eventServer;
|
||||
}
|
||||
|
||||
@LinkedTimer(delay = 0, period = 10, unit = LinkedTimer.Unit.SECONDS)
|
||||
private void run() {
|
||||
if (eventServer.entrySet().removeIf(entry -> Subserver.getSubserver(entry.getValue().getServer()) == null)) {
|
||||
EventFight.loadAllComingFights();
|
||||
|
||||
@@ -133,7 +133,6 @@ public class VelocityCore implements ReloadablePlugin {
|
||||
return tabCompleter.apply(sender, s);
|
||||
}
|
||||
});
|
||||
schedule(TabCompletionCache::invalidateOldEntries).repeat(1, TimeUnit.SECONDS).schedule();
|
||||
|
||||
initStaticServers();
|
||||
|
||||
@@ -188,12 +187,6 @@ public class VelocityCore implements ReloadablePlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
schedule(() -> {
|
||||
SteamwarUser.clear();
|
||||
Team.clear();
|
||||
SteamwarPrefix.clearCache();
|
||||
}).repeat(1, TimeUnit.HOURS).schedule();
|
||||
|
||||
DiscordConfig discordConfig = DiscordConfig.load();
|
||||
if (discordConfig != null) {
|
||||
try {
|
||||
@@ -204,6 +197,18 @@ public class VelocityCore implements ReloadablePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@LinkedTimer(delay = 0, period = 1, unit = LinkedTimer.Unit.SECONDS)
|
||||
private void invalidateTabCompletions() {
|
||||
TabCompletionCache.invalidateOldEntries();
|
||||
}
|
||||
|
||||
@LinkedTimer(delay = 0, period = 1, unit = LinkedTimer.Unit.HOURS)
|
||||
private void clearCaches() {
|
||||
SteamwarUser.clear();
|
||||
Team.clear();
|
||||
SteamwarPrefix.clearCache();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Override
|
||||
public void onProxyShutdown(ProxyShutdownEvent event) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedTimer;
|
||||
import de.steamwar.messages.Chatter;
|
||||
import de.steamwar.messages.Message;
|
||||
import de.steamwar.messages.PlayerChatter;
|
||||
@@ -41,10 +42,8 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import java.awt.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -76,7 +75,11 @@ public class CheckCommand extends SWCommand {
|
||||
|
||||
public CheckCommand() {
|
||||
super("check");
|
||||
VelocityCore.schedule(() -> Chatter.allStream().forEach(CheckCommand::sendReminder)).delay(10, TimeUnit.MINUTES).repeat(10, TimeUnit.MINUTES).schedule();
|
||||
}
|
||||
|
||||
@LinkedTimer(delay = 10, period = 10, unit = LinkedTimer.Unit.MINUTES)
|
||||
private static void sendReminders() {
|
||||
Chatter.allStream().forEach(CheckCommand::sendReminder);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,11 +29,11 @@ import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedTimer;
|
||||
import de.steamwar.persistent.Storage;
|
||||
import de.steamwar.sql.Mod;
|
||||
import de.steamwar.sql.SWException;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.velocitycore.VelocityCore;
|
||||
import de.steamwar.velocitycore.listeners.BasicListener;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@@ -55,20 +55,21 @@ public class FabricModSender extends BasicListener {
|
||||
|
||||
neededFabricMods.add("fabricloader");
|
||||
neededQuiltMods.add("quilt_loader");
|
||||
}
|
||||
|
||||
VelocityCore.schedule(() -> {
|
||||
synchronized (Storage.fabricExpectPluginMessage) {
|
||||
for (Map.Entry<Player, Long> entry : Storage.fabricExpectPluginMessage.entrySet()) {
|
||||
if (!Storage.fabricCheckedPlayers.containsKey(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) {
|
||||
Storage.fabricExpectPluginMessage.remove(entry.getKey());
|
||||
return;
|
||||
}
|
||||
@LinkedTimer(delay = 0, period = 1, unit = LinkedTimer.Unit.SECONDS)
|
||||
private void removeExpiredExpectations() {
|
||||
synchronized (Storage.fabricExpectPluginMessage) {
|
||||
for (Map.Entry<Player, Long> entry : Storage.fabricExpectPluginMessage.entrySet()) {
|
||||
if (!Storage.fabricCheckedPlayers.containsKey(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) {
|
||||
Storage.fabricExpectPluginMessage.remove(entry.getKey());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}).repeat(1, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
}
|
||||
|
||||
public void handlePluginMessage(PluginMessageEvent e) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedTimer;
|
||||
import de.steamwar.linkage.api.Disable;
|
||||
import de.steamwar.network.packets.common.FightInfoPacket;
|
||||
import de.steamwar.persistent.Storage;
|
||||
@@ -38,7 +39,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Linked
|
||||
public class TablistManager extends BasicListener implements Disable {
|
||||
@@ -63,7 +63,6 @@ public class TablistManager extends BasicListener implements Disable {
|
||||
private int seconds = 0;
|
||||
|
||||
public TablistManager() {
|
||||
VelocityCore.schedule(this::updateTablist).repeat(1, TimeUnit.SECONDS).schedule();
|
||||
synchronized (tablists) {
|
||||
VelocityCore.getProxy().getAllPlayers().forEach(player -> tablists.computeIfAbsent(player, Tablist::new).onServerSwitch());
|
||||
}
|
||||
@@ -102,6 +101,7 @@ public class TablistManager extends BasicListener implements Disable {
|
||||
}
|
||||
}
|
||||
|
||||
@LinkedTimer(delay = 0, period = 1, unit = LinkedTimer.Unit.SECONDS)
|
||||
private void updateTablist() {
|
||||
List<TablistPart> subservers = new ArrayList<>();
|
||||
for (RegisteredServer server : new ArrayList<>(VelocityCore.getProxy().getAllServers())) {
|
||||
|
||||
Reference in New Issue
Block a user