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.lobby.jumpandrun;
|
||||
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedTimer;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.listener.PlayerSpawn;
|
||||
import de.steamwar.lobby.util.LeaderboardManager;
|
||||
@@ -60,52 +61,51 @@ public class JumpAndRun implements Listener {
|
||||
|
||||
private static final LeaderboardManager LEADERBOARD = new LeaderboardManager(LobbySystem.getEntityServer(false), JUMP_AND_RUN_CONFIG, new Location(Bukkit.getWorlds().get(0), 2338.5, 42.5, 1231.5));
|
||||
|
||||
{
|
||||
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
|
||||
Set<Player> toReset = new HashSet<>();
|
||||
CURRENT_POS.forEach((player, index) -> {
|
||||
if (System.currentTimeMillis() - CLICKED.getOrDefault(player, 0L) > 500) {
|
||||
CLICKED.remove(player);
|
||||
CLICKED_COUNT.remove(player);
|
||||
} else {
|
||||
CLICKED_COUNT.put(player, CLICKED_COUNT.getOrDefault(player, -1) + 1);
|
||||
}
|
||||
@LinkedTimer(delay = 1, period = 1)
|
||||
private void updatePlayers() {
|
||||
Set<Player> toReset = new HashSet<>();
|
||||
CURRENT_POS.forEach((player, index) -> {
|
||||
if (System.currentTimeMillis() - CLICKED.getOrDefault(player, 0L) > 500) {
|
||||
CLICKED.remove(player);
|
||||
CLICKED_COUNT.remove(player);
|
||||
} else {
|
||||
CLICKED_COUNT.put(player, CLICKED_COUNT.getOrDefault(player, -1) + 1);
|
||||
}
|
||||
|
||||
Location location = player.getLocation();
|
||||
Vector point = points.get(index);
|
||||
if (index < points.size() - 1) {
|
||||
Vector nextPoint = points.get(index + 1);
|
||||
double y = Math.min(point.getY(), nextPoint.getY()) - 2;
|
||||
if (location.getY() < y) {
|
||||
location.setX(point.getX());
|
||||
location.setY(point.getY());
|
||||
location.setZ(point.getZ());
|
||||
player.teleport(location);
|
||||
player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, 1, 1);
|
||||
FAILS.put(player, FAILS.getOrDefault(player, 0) + 1);
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
Vector point = points.get(index);
|
||||
if (index < points.size() - 1) {
|
||||
Vector nextPoint = points.get(index + 1);
|
||||
double y = Math.min(point.getY(), nextPoint.getY()) - 2;
|
||||
if (location.getY() < y) {
|
||||
location.setX(point.getX());
|
||||
location.setY(point.getY());
|
||||
location.setZ(point.getZ());
|
||||
player.teleport(location);
|
||||
player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, 1, 1);
|
||||
FAILS.put(player, FAILS.getOrDefault(player, 0) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int count = CLICKED_COUNT.getOrDefault(player, -1);
|
||||
if (count >= 0) {
|
||||
if (count > 20) {
|
||||
toReset.add(player);
|
||||
return;
|
||||
}
|
||||
count = Math.min(count / 2, 30);
|
||||
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_CANCEL", player, ChatMessageType.ACTION_BAR, "§e" + BAR_EMPTY.substring(0, count) + "§7" + BAR_EMPTY.substring(count));
|
||||
} else {
|
||||
long time = System.currentTimeMillis() - START.get(player);
|
||||
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
|
||||
String parsed = format.format(new Date(time));
|
||||
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PROGRESS", player, ChatMessageType.ACTION_BAR, index + 1, points.size(), FAILS.get(player), parsed);
|
||||
int count = CLICKED_COUNT.getOrDefault(player, -1);
|
||||
if (count >= 0) {
|
||||
if (count > 20) {
|
||||
toReset.add(player);
|
||||
return;
|
||||
}
|
||||
});
|
||||
toReset.forEach(player -> {
|
||||
reset(player);
|
||||
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation().clone().add(0.5, 0, 0.5));
|
||||
});
|
||||
}, 1, 1);
|
||||
count = Math.min(count / 2, 30);
|
||||
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_CANCEL", player, ChatMessageType.ACTION_BAR, "§e" + BAR_EMPTY.substring(0, count) + "§7" + BAR_EMPTY.substring(count));
|
||||
} else {
|
||||
long time = System.currentTimeMillis() - START.get(player);
|
||||
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
|
||||
String parsed = format.format(new Date(time));
|
||||
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PROGRESS", player, ChatMessageType.ACTION_BAR, index + 1, points.size(), FAILS.get(player), parsed);
|
||||
}
|
||||
});
|
||||
toReset.forEach(player -> {
|
||||
reset(player);
|
||||
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation().clone().add(0.5, 0, 0.5));
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isPlayerInJumpAndRun(Player player) {
|
||||
|
||||
Reference in New Issue
Block a user