Dieser Commit ist enthalten in:
Ursprung
838c67e3e6
Commit
922b2e445e
@ -130,7 +130,7 @@ PARTICLE_EGG_HUNT_HALF = §fThe hunt is on
|
|||||||
|
|
||||||
JUMP_AND_RUN_PROGRESS = §e{0}§8/§f{1} §c{2} §7{3}
|
JUMP_AND_RUN_PROGRESS = §e{0}§8/§f{1} §c{2} §7{3}
|
||||||
JUMP_AND_RUN_CANCEL = {0}
|
JUMP_AND_RUN_CANCEL = {0}
|
||||||
JUMP_AND_RUN_TIME = mm:ss SSS
|
JUMP_AND_RUN_TIME = mm:ss,SSS
|
||||||
JUMP_AND_RUN_FINISHED = §aFinished in {0} with {1} fails
|
JUMP_AND_RUN_FINISHED = §aFinished in {0} with {1} fails
|
||||||
JUMP_AND_RUN_PERSONAL_BEST = §aNice! You beat your personal best by {0}
|
JUMP_AND_RUN_PERSONAL_BEST = §aNice! You beat your personal best by {0}
|
||||||
JUMP_AND_RUN_PERSONAL_BEST_TIME = §aPersonal best in {0}
|
JUMP_AND_RUN_PERSONAL_BEST_TIME = §aPersonal best in {0}
|
||||||
|
@ -77,7 +77,7 @@ public class JumpAndRun extends BasicListener {
|
|||||||
long time = System.currentTimeMillis() - START.get(player);
|
long time = System.currentTimeMillis() - START.get(player);
|
||||||
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
|
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
|
||||||
String parsed = format.format(new Date(time));
|
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.substring(0, parsed.length() - 2));
|
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PROGRESS", player, ChatMessageType.ACTION_BAR, index + 1, points.size(), FAILS.get(player), parsed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
toReset.forEach(player -> {
|
toReset.forEach(player -> {
|
||||||
@ -127,7 +127,7 @@ public class JumpAndRun extends BasicListener {
|
|||||||
long time = System.currentTimeMillis() - START.get(event.getPlayer());
|
long time = System.currentTimeMillis() - START.get(event.getPlayer());
|
||||||
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", event.getPlayer()), Locale.ROOT);
|
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", event.getPlayer()), Locale.ROOT);
|
||||||
String parsed = format.format(new Date(time));
|
String parsed = format.format(new Date(time));
|
||||||
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_FINISHED", event.getPlayer(), parsed.substring(0, parsed.length() - 2), FAILS.get(event.getPlayer()));
|
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_FINISHED", event.getPlayer(), parsed, FAILS.get(event.getPlayer()));
|
||||||
updateJumpAndRunTime(event.getPlayer(), time);
|
updateJumpAndRunTime(event.getPlayer(), time);
|
||||||
reset(event.getPlayer());
|
reset(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
@ -3,57 +3,100 @@ package de.steamwar.lobby.util;
|
|||||||
import de.steamwar.entity.RArmorStand;
|
import de.steamwar.entity.RArmorStand;
|
||||||
import de.steamwar.entity.REntity;
|
import de.steamwar.entity.REntity;
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.lobby.LobbySystem;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.sql.internal.Statement;
|
import de.steamwar.sql.internal.Statement;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Leaderboard {
|
public class Leaderboard implements Listener {
|
||||||
|
|
||||||
private static final Statement LEADERBOARD = new Statement("SELECT User, CAST(Value as integer) AS Time from UserConfig WHERE Config = ? ORDER BY CAST(Value as integer) LIMIT ?");
|
private static final Statement LEADERBOARD = new Statement("SELECT User, CAST(Value as integer) AS Time from UserConfig WHERE Config = ? ORDER BY CAST(Value as integer) LIMIT ?");
|
||||||
|
private static final Statement PLAYER_TIME = new Statement("SELECT CAST(Value as integer) AS Time FROM UserConfig WHERE Config = ? AND User = ?");
|
||||||
|
private static final Statement PLAYER_PLACEMENT = new Statement("SELECT COUNT(*) AS Placement FROM UserConfig WHERE Config = ? AND CAST(Value as integer) < (SELECT CAST(Value as integer) AS Time FROM UserConfig WHERE Config = ? AND User = ?)");
|
||||||
|
|
||||||
private final REntityServer server;
|
private final REntityServer server;
|
||||||
private final String configKey;
|
private final String configKey;
|
||||||
private final Location location;
|
private final Location location;
|
||||||
private final int best;
|
private final int best;
|
||||||
private final List<REntity> entities;
|
private long bestTime;
|
||||||
|
private final Map<Integer, REntityServer> playerPlacements = new HashMap<>();
|
||||||
|
|
||||||
public Leaderboard(REntityServer server, String configKey, Location location, int best) {
|
public Leaderboard(REntityServer server, String configKey, Location location, int best) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.configKey = configKey;
|
this.configKey = configKey;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.best = best;
|
this.best = best;
|
||||||
entities = new ArrayList<>(best + 2);
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
entities.forEach(REntity::die);
|
server.getEntities().forEach(REntity::die);
|
||||||
entities.clear();
|
|
||||||
List<LeaderboardEntry> leaderboard = getLeaderboard();
|
List<LeaderboardEntry> leaderboard = getLeaderboard();
|
||||||
if (leaderboard.isEmpty()) return;
|
if (leaderboard.isEmpty()) return;
|
||||||
long bestTime = leaderboard.get(0).time;
|
bestTime = leaderboard.get(0).time;
|
||||||
for (int i = 0; i <= best; i++) {
|
for (int i = 0; i <= best; i++) {
|
||||||
if (best - i >= leaderboard.size()) continue;
|
if (best - i >= leaderboard.size()) continue;
|
||||||
LeaderboardEntry entry = leaderboard.get(best - i);
|
LeaderboardEntry entry = leaderboard.get(best - i);
|
||||||
RArmorStand entity = new RArmorStand(server, location.clone().add(0, i * 0.32, 0), RArmorStand.Size.MARKER);
|
RArmorStand entity = new RArmorStand(server, location.clone().add(0, i * 0.32, 0), RArmorStand.Size.MARKER);
|
||||||
SteamwarUser user = SteamwarUser.get(entry.user);
|
SteamwarUser user = SteamwarUser.get(entry.user);
|
||||||
|
String color = "§f";
|
||||||
if (i == best) {
|
if (i == best) {
|
||||||
entity.setDisplayName("§6§l" + user.getUserName() + " §8• §6§l" + renderTime(entry.time));
|
color = "§6§l";
|
||||||
} else if (i <= best - 1 && i > best - 3) {
|
} else if (i <= best - 1 && i > best- 3) {
|
||||||
entity.setDisplayName("§e" + user.getUserName() + " §8• §e" + renderTime(entry.time) + " §8• §e+" + renderShortTime(entry.time - bestTime));
|
color = "§e";
|
||||||
} else {
|
|
||||||
entity.setDisplayName("§7" + user.getUserName() + " §8• §7" + renderTime(entry.time) + " §8• §7+" + renderShortTime(entry.time - bestTime));
|
|
||||||
}
|
}
|
||||||
|
entity.setDisplayName(calcName(user, color, i + 1, entry.time));
|
||||||
entity.setInvisible(true);
|
entity.setInvisible(true);
|
||||||
entities.add(entity);
|
|
||||||
}
|
}
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
updatePlayerPlacement(SteamwarUser.get(player.getUniqueId()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePlayerPlacement(SteamwarUser steamwarUser) {
|
||||||
|
if (server.getEntities().isEmpty()) return;
|
||||||
|
int placement = getPlayerPlacement(steamwarUser);
|
||||||
|
if (placement < 5) {
|
||||||
|
REntityServer entityServer = playerPlacements.remove(steamwarUser.getId());
|
||||||
|
if (entityServer == null) return;
|
||||||
|
entityServer.getEntities().forEach(rEntity -> rEntity.hide(true));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
REntityServer entityServer = playerPlacements.computeIfAbsent(steamwarUser.getId(), ignore -> new REntityServer());
|
||||||
|
List<REntity> entities = entityServer.getEntities();
|
||||||
|
RArmorStand entity;
|
||||||
|
if (entities.isEmpty()) {
|
||||||
|
entity = new RArmorStand(server, location.clone().add(0, -2 * 0.32, 0), RArmorStand.Size.MARKER);
|
||||||
|
entity.setInvisible(true);
|
||||||
|
} else {
|
||||||
|
entity = (RArmorStand) entities.get(0);
|
||||||
|
entity.hide(false);
|
||||||
|
}
|
||||||
|
long time = getPlayerTime(steamwarUser);
|
||||||
|
entity.setDisplayName(calcName(steamwarUser, "§7", placement, time));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String calcName(SteamwarUser user, String color, int placement, long time) {
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
st.append(color);
|
||||||
|
st.append(placement).append(". ").append(user.getUserName());
|
||||||
|
st.append(" §8• ");
|
||||||
|
st.append(color).append(renderTime(time));
|
||||||
|
if (time != bestTime) {
|
||||||
|
st.append(" §8• ");
|
||||||
|
st.append(color).append("+").append(renderShortTime(time - bestTime));
|
||||||
|
}
|
||||||
|
return st.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<LeaderboardEntry> getLeaderboard() {
|
private List<LeaderboardEntry> getLeaderboard() {
|
||||||
@ -66,6 +109,18 @@ public class Leaderboard {
|
|||||||
}, configKey, best);
|
}, configKey, best);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long getPlayerTime(SteamwarUser user) {
|
||||||
|
return PLAYER_TIME.select(resultSet -> {
|
||||||
|
return resultSet.getLong("Time");
|
||||||
|
}, configKey, user.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getPlayerPlacement(SteamwarUser user) {
|
||||||
|
return PLAYER_PLACEMENT.select(resultSet -> {
|
||||||
|
return resultSet.getInt("Placement");
|
||||||
|
}, configKey, configKey, user.getId());
|
||||||
|
}
|
||||||
|
|
||||||
public static String renderTime(long time) {
|
public static String renderTime(long time) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"%d:%02d.%03d",
|
"%d:%02d.%03d",
|
||||||
@ -87,4 +142,18 @@ public class Leaderboard {
|
|||||||
private final int user;
|
private final int user;
|
||||||
private final long time;
|
private final long time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
SteamwarUser steamwarUser = SteamwarUser.get(event.getPlayer().getUniqueId());
|
||||||
|
updatePlayerPlacement(steamwarUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
SteamwarUser steamwarUser = SteamwarUser.get(event.getPlayer().getUniqueId());
|
||||||
|
REntityServer entityServer = playerPlacements.remove(steamwarUser.getId());
|
||||||
|
if (entityServer == null) return;
|
||||||
|
entityServer.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren