mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-18 23:46:28 +01:00
Minor fixes
This commit is contained in:
parent
bfda48c22e
commit
31711bd2f9
@ -10,3 +10,13 @@ INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.auto.gotwpoints.i
|
||||
INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.auto.gotwpoints.ignore.hotelview', '1');
|
||||
INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.auto.gotwpoints.type', '4');
|
||||
INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.auto.gotwpoints.name', 'shell');
|
||||
|
||||
CREATE TABLE `items_highscore_data` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`item_id` int(11) NOT NULL,
|
||||
`user_ids` varchar(500) NOT NULL,
|
||||
`score` int(11) NOT NULL,
|
||||
`is_win` tinyint(1) NULL DEFAULT 0,
|
||||
`timestamp` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
@ -5,13 +5,13 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredHighscore;
|
||||
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob;
|
||||
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreDataEntry;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamLoses;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamWins;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
||||
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
||||
import com.eu.habbo.plugin.Event;
|
||||
import com.eu.habbo.plugin.events.games.GameHabboJoinEvent;
|
||||
import com.eu.habbo.plugin.events.games.GameHabboLeaveEvent;
|
||||
@ -21,6 +21,7 @@ import com.eu.habbo.threading.runnables.SaveScoreForTeam;
|
||||
import gnu.trove.map.hash.THashMap;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class Game implements Runnable {
|
||||
|
||||
@ -164,16 +165,25 @@ public abstract class Game implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) {
|
||||
Emulator.getGameEnvironment().getItemManager().getHighscoreManager().addHighscoreData(new WiredHighscoreDataEntry(item.getId(), winningTeam.getMembers().stream().map(m -> m.getHabbo().getHabboInfo().getId()).collect(Collectors.toList()), winningTeam.getTotalScore(), true, Emulator.getIntUnixTimestamp()));
|
||||
}
|
||||
|
||||
for (GameTeam team : this.teams.values()) {
|
||||
if (team == winningTeam) continue;
|
||||
|
||||
for (GamePlayer player : winningTeam.getMembers()) {
|
||||
WiredHandler.handleCustomTrigger(WiredTriggerTeamLoses.class, player.getHabbo().getRoomUnit(), this.room, new Object[]{this});
|
||||
}
|
||||
|
||||
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) {
|
||||
Emulator.getGameEnvironment().getItemManager().getHighscoreManager().addHighscoreData(new WiredHighscoreDataEntry(item.getId(), winningTeam.getMembers().stream().map(m -> m.getHabbo().getHabboInfo().getId()).collect(Collectors.toList()), winningTeam.getTotalScore(), false, Emulator.getIntUnixTimestamp()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) {
|
||||
((InteractionWiredHighscore) item).reloadData();
|
||||
this.room.updateItem(item);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ import com.eu.habbo.habbohotel.items.interactions.wired.effects.*;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraRandom;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraUnseen;
|
||||
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreManager;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.triggers.*;
|
||||
import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
@ -69,6 +70,7 @@ public class ItemManager {
|
||||
private final THashSet<ItemInteraction> interactionsList;
|
||||
private final THashMap<String, SoundTrack> soundTracks;
|
||||
private final YoutubeManager youtubeManager;
|
||||
private final WiredHighscoreManager highscoreManager;
|
||||
private final TreeMap<Integer, NewUserGift> newuserGifts;
|
||||
|
||||
public ItemManager() {
|
||||
@ -77,6 +79,7 @@ public class ItemManager {
|
||||
this.interactionsList = new THashSet<>();
|
||||
this.soundTracks = new THashMap<>();
|
||||
this.youtubeManager = new YoutubeManager();
|
||||
this.highscoreManager = new WiredHighscoreManager();
|
||||
this.newuserGifts = new TreeMap<>();
|
||||
}
|
||||
|
||||
@ -90,6 +93,7 @@ public class ItemManager {
|
||||
this.loadCrackable();
|
||||
this.loadSoundTracks();
|
||||
this.youtubeManager.load();
|
||||
this.highscoreManager.load();
|
||||
this.loadNewUserGifts();
|
||||
|
||||
Emulator.getLogging().logStart("Item Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)");
|
||||
@ -784,8 +788,13 @@ public class ItemManager {
|
||||
return this.youtubeManager;
|
||||
}
|
||||
|
||||
public WiredHighscoreManager getHighscoreManager() {
|
||||
return highscoreManager;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
this.items.clear();
|
||||
this.highscoreManager.dispose();
|
||||
|
||||
Emulator.getLogging().logShutdownLine("Item Manager -> Disposed!");
|
||||
}
|
||||
|
@ -3,24 +3,23 @@ package com.eu.habbo.habbohotel.items.interactions;
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
||||
import com.eu.habbo.habbohotel.items.Item;
|
||||
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreRow;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHighscoreClearType;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHighscoreData;
|
||||
import com.eu.habbo.habbohotel.wired.WiredHighscoreScoreType;
|
||||
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreClearType;
|
||||
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreScoreType;
|
||||
import com.eu.habbo.messages.ServerMessage;
|
||||
import gnu.trove.set.hash.THashSet;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class InteractionWiredHighscore extends HabboItem {
|
||||
public WiredHighscoreScoreType scoreType;
|
||||
public WiredHighscoreClearType clearType;
|
||||
|
||||
private THashSet<WiredHighscoreData> data;
|
||||
private int lastUpdate;
|
||||
private List<WiredHighscoreRow> data;
|
||||
|
||||
public InteractionWiredHighscore(ResultSet set, Item baseItem) throws SQLException {
|
||||
super(set, baseItem);
|
||||
@ -37,13 +36,7 @@ public class InteractionWiredHighscore extends HabboItem {
|
||||
Emulator.getLogging().logErrorLine(e);
|
||||
}
|
||||
|
||||
if (this.getRoomId() > 0) {
|
||||
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
||||
|
||||
if (room != null) {
|
||||
this.reloadData(room);
|
||||
}
|
||||
}
|
||||
this.reloadData();
|
||||
}
|
||||
|
||||
public InteractionWiredHighscore(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
|
||||
@ -60,6 +53,8 @@ public class InteractionWiredHighscore extends HabboItem {
|
||||
} catch (Exception e) {
|
||||
Emulator.getLogging().logErrorLine(e);
|
||||
}
|
||||
|
||||
this.reloadData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,7 +81,6 @@ public class InteractionWiredHighscore extends HabboItem {
|
||||
try {
|
||||
int state = Integer.valueOf(this.getExtradata());
|
||||
this.setExtradata(Math.abs(state - 1) + "");
|
||||
this.reloadData(room);
|
||||
room.updateItem(this);
|
||||
} catch (Exception e) {
|
||||
Emulator.getLogging().logErrorLine(e);
|
||||
@ -98,43 +92,22 @@ public class InteractionWiredHighscore extends HabboItem {
|
||||
public void serializeExtradata(ServerMessage serverMessage) {
|
||||
serverMessage.appendInt(6);
|
||||
serverMessage.appendString(this.getExtradata());
|
||||
serverMessage.appendInt(this.scoreType.type); //score type
|
||||
serverMessage.appendInt(this.clearType.type); //clear type
|
||||
serverMessage.appendInt(this.scoreType.type);
|
||||
serverMessage.appendInt(this.clearType.type);
|
||||
|
||||
if (this.getRoomId() == 0) {
|
||||
serverMessage.appendInt(0);
|
||||
} else {
|
||||
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
|
||||
if (this.data != null) {
|
||||
serverMessage.appendInt(this.data.size());
|
||||
|
||||
if (room == null) {
|
||||
serverMessage.appendInt(0);
|
||||
} else {
|
||||
if (Emulator.getIntUnixTimestamp() - this.lastUpdate > 60 * 60) {
|
||||
this.reloadData(room);
|
||||
}
|
||||
for (WiredHighscoreRow row : this.data) {
|
||||
serverMessage.appendInt(row.getValue());
|
||||
|
||||
if (this.data != null) {
|
||||
serverMessage.appendInt(this.data.size()); //count
|
||||
|
||||
for (WiredHighscoreData dataSet : this.data) {
|
||||
if (this.scoreType == WiredHighscoreScoreType.PERTEAM) {
|
||||
serverMessage.appendInt(dataSet.teamScore); //Team score
|
||||
} else if (dataSet.usernames.length == 1) {
|
||||
serverMessage.appendInt(dataSet.score);
|
||||
} else {
|
||||
serverMessage.appendInt(dataSet.totalScore);
|
||||
}
|
||||
|
||||
serverMessage.appendInt(dataSet.usernames.length); //Users count
|
||||
|
||||
for (String codeDragon : dataSet.usernames) {
|
||||
serverMessage.appendString(codeDragon);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
serverMessage.appendInt(0);
|
||||
serverMessage.appendInt(row.getUsers().size());
|
||||
for (String username : row.getUsers()) {
|
||||
serverMessage.appendString(username);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
serverMessage.appendInt(0);
|
||||
}
|
||||
|
||||
super.serializeExtradata(serverMessage);
|
||||
@ -142,7 +115,7 @@ public class InteractionWiredHighscore extends HabboItem {
|
||||
|
||||
@Override
|
||||
public void onPlace(Room room) {
|
||||
this.reloadData(room);
|
||||
this.reloadData();
|
||||
super.onPlace(room);
|
||||
}
|
||||
|
||||
@ -151,11 +124,9 @@ public class InteractionWiredHighscore extends HabboItem {
|
||||
if (this.data != null) {
|
||||
this.data.clear();
|
||||
}
|
||||
this.lastUpdate = 0;
|
||||
}
|
||||
|
||||
private void reloadData(Room room) {
|
||||
this.data = room.getWiredHighscoreData(this.scoreType, this.clearType);
|
||||
this.lastUpdate = Emulator.getIntUnixTimestamp();
|
||||
public void reloadData() {
|
||||
this.data = Emulator.getGameEnvironment().getItemManager().getHighscoreManager().getHighscoreRowsForItem(this.getId(), this.clearType, this.scoreType);
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
private final TIntObjectMap<RoomMoodlightData> moodlightData;
|
||||
private final THashSet<String> wordFilterWords;
|
||||
private final TIntObjectMap<HabboItem> roomItems;
|
||||
private final THashMap<WiredHighscoreScoreType, THashMap<WiredHighscoreClearType, THashSet<WiredHighscoreData>>> wiredHighscoreData;
|
||||
private final Object loadLock = new Object();
|
||||
//Use appropriately. Could potentially cause memory leaks when used incorrectly.
|
||||
public volatile boolean preventUnloading = false;
|
||||
@ -289,7 +288,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
|
||||
this.activeTrades = new THashSet<>(0);
|
||||
this.rights = new TIntArrayList();
|
||||
this.wiredHighscoreData = new THashMap<>();
|
||||
this.userVotes = new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -4211,70 +4209,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public THashSet<WiredHighscoreData> getWiredHighscoreData(WiredHighscoreScoreType scoreType, WiredHighscoreClearType clearType) {
|
||||
if (!this.wiredHighscoreData.containsKey(scoreType)) {
|
||||
this.loadWiredHighscoreData(scoreType, clearType);
|
||||
}
|
||||
|
||||
return this.wiredHighscoreData.get(scoreType).get(clearType);
|
||||
}
|
||||
|
||||
public void loadWiredHighscoreData(WiredHighscoreScoreType scoreType, WiredHighscoreClearType clearType) {
|
||||
this.wiredHighscoreData.clear();
|
||||
THashSet<WiredHighscoreData> wiredData = new THashSet<>();
|
||||
|
||||
try {
|
||||
String query = "SELECT " +
|
||||
"SUM(score + team_score) as total_score, " +
|
||||
"COUNT(*) as wins, " +
|
||||
"users.username, " +
|
||||
"room_game_scores.*, " +
|
||||
"GROUP_CONCAT(users.username) as usernames " +
|
||||
"FROM room_game_scores " +
|
||||
"INNER JOIN users ON room_game_scores.user_id = users.id " +
|
||||
"WHERE room_id = ? AND game_start_timestamp >= ? ";
|
||||
|
||||
int timestamp = 0;
|
||||
if (clearType != WiredHighscoreClearType.ALLTIME) {
|
||||
if (clearType == WiredHighscoreClearType.MONTHLY) {
|
||||
timestamp = Emulator.getIntUnixTimestamp() - (31 * 24 * 60 * 60);
|
||||
} else if (clearType == WiredHighscoreClearType.WEEKLY) {
|
||||
timestamp = Emulator.getIntUnixTimestamp() - (7 * 24 * 60 * 60);
|
||||
} else if (clearType == WiredHighscoreClearType.DAILY) {
|
||||
timestamp = Emulator.getIntUnixTimestamp() - (24 * 60 * 60);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (scoreType == WiredHighscoreScoreType.CLASSIC) {
|
||||
query += "GROUP BY game_start_timestamp, user_id, team_id ORDER BY total_score DESC";
|
||||
} else if (scoreType == WiredHighscoreScoreType.MOSTWIN) {
|
||||
query += "GROUP BY game_start_timestamp, game_name, team_id ORDER BY wins DESC, total_score ASC";
|
||||
} else if (scoreType == WiredHighscoreScoreType.PERTEAM) {
|
||||
query += "GROUP BY game_start_timestamp, team_id ORDER BY team_score DESC";
|
||||
}
|
||||
|
||||
query += " LIMIT " + Emulator.getConfig().getValue("wired.highscores.displaycount");
|
||||
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement(query)) {
|
||||
statement.setInt(1, this.id);
|
||||
statement.setInt(2, timestamp);
|
||||
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
while (set.next()) {
|
||||
wiredData.add(new WiredHighscoreData(set.getString("usernames").split(","), set.getInt("score"), set.getInt("team_score"), set.getInt("total_score")));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
}
|
||||
|
||||
THashMap<WiredHighscoreClearType, THashSet<WiredHighscoreData>> dataMap = new THashMap<>();
|
||||
dataMap.put(clearType, wiredData);
|
||||
this.wiredHighscoreData.put(scoreType, dataMap);
|
||||
}
|
||||
|
||||
public void handleWordQuiz(Habbo habbo, String answer) {
|
||||
synchronized (this.userVotes) {
|
||||
if (!this.wordQuiz.isEmpty() && !this.hasVotedInWordQuiz(habbo)) {
|
||||
|
@ -1,16 +0,0 @@
|
||||
package com.eu.habbo.habbohotel.wired;
|
||||
|
||||
public class WiredHighscoreData {
|
||||
public String[] usernames;
|
||||
public int score;
|
||||
public int teamScore;
|
||||
public int totalScore;
|
||||
|
||||
public WiredHighscoreData(String[] usernames, int score, int teamScore, int totalScore) {
|
||||
this.usernames = usernames;
|
||||
|
||||
this.score = score;
|
||||
this.teamScore = teamScore;
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.eu.habbo.habbohotel.wired;
|
||||
package com.eu.habbo.habbohotel.wired.highscores;
|
||||
|
||||
public enum WiredHighscoreClearType {
|
||||
ALLTIME(0),
|
@ -0,0 +1,51 @@
|
||||
package com.eu.habbo.habbohotel.wired.highscores;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WiredHighscoreDataEntry {
|
||||
private final int itemId;
|
||||
private final List<Integer> userIds;
|
||||
private final int score;
|
||||
private final boolean isWin;
|
||||
private final int timestamp;
|
||||
|
||||
public WiredHighscoreDataEntry(int itemId, List<Integer> userIds, int score, boolean isWin, int timestamp) {
|
||||
this.itemId = itemId;
|
||||
this.userIds = userIds;
|
||||
this.score = score;
|
||||
this.isWin = isWin;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public WiredHighscoreDataEntry(ResultSet set) throws SQLException {
|
||||
this.itemId = set.getInt("item_id");
|
||||
this.userIds = Arrays.stream(set.getString("user_ids").split(",")).map(Integer::valueOf).collect(Collectors.toList());
|
||||
this.score = set.getInt("score");
|
||||
this.isWin = set.getInt("is_win") == 1;
|
||||
this.timestamp = set.getInt("timestamp");
|
||||
}
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public List<Integer> getUserIds() {
|
||||
return userIds;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public boolean isWin() {
|
||||
return isWin;
|
||||
}
|
||||
|
||||
public int getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
package com.eu.habbo.habbohotel.wired.highscores;
|
||||
|
||||
import com.eu.habbo.Emulator;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.*;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.time.temporal.WeekFields;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class WiredHighscoreManager {
|
||||
private final HashMap<Integer, List<WiredHighscoreDataEntry>> data = new HashMap<>();
|
||||
|
||||
private final static DayOfWeek firstDayOfWeek = WeekFields.of(new Locale(System.getProperty("user.language"), System.getProperty("user.country"))).getFirstDayOfWeek();
|
||||
private final static DayOfWeek lastDayOfWeek = DayOfWeek.of(((firstDayOfWeek.getValue() + 5) % DayOfWeek.values().length) + 1);
|
||||
private final static ZoneId zoneId = ZoneId.systemDefault();
|
||||
|
||||
public static ScheduledFuture midnightUpdater = null;
|
||||
|
||||
public void load() {
|
||||
long millis = System.currentTimeMillis();
|
||||
|
||||
this.data.clear();
|
||||
this.loadHighscoreData();
|
||||
|
||||
if (midnightUpdater != null) {
|
||||
midnightUpdater.cancel(true);
|
||||
}
|
||||
midnightUpdater = Emulator.getThreading().run(new WiredHighscoreMidnightUpdater(), WiredHighscoreMidnightUpdater.getNextUpdaterRun());
|
||||
|
||||
Emulator.getLogging().logStart("Highscore Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS, " + this.data.size() + " items)");
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (midnightUpdater != null) {
|
||||
midnightUpdater.cancel(true);
|
||||
}
|
||||
|
||||
this.data.clear();
|
||||
}
|
||||
|
||||
private void loadHighscoreData() {
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM items_highscore_data")) {
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
while (set.next()) {
|
||||
WiredHighscoreDataEntry entry = new WiredHighscoreDataEntry(set);
|
||||
|
||||
if (!this.data.containsKey(entry.getItemId())) {
|
||||
this.data.put(entry.getItemId(), new ArrayList<>());
|
||||
}
|
||||
|
||||
this.data.get(entry.getItemId()).add(entry);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addHighscoreData(WiredHighscoreDataEntry entry) {
|
||||
if (!this.data.containsKey(entry.getItemId())) {
|
||||
this.data.put(entry.getItemId(), new ArrayList<>());
|
||||
}
|
||||
|
||||
this.data.get(entry.getItemId()).add(entry);
|
||||
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO `items_highscore_data` (`item_id`, `user_ids`, `score`, `is_win`, `timestamp`) VALUES (?, ?, ?, ?, ?)")) {
|
||||
statement.setInt(1, entry.getItemId());
|
||||
statement.setString(2, String.join(",", entry.getUserIds().stream().map(Object::toString).collect(Collectors.toList())));
|
||||
statement.setInt(3, entry.getScore());
|
||||
statement.setInt(4, entry.isWin() ? 1 : 0);
|
||||
statement.setInt(5, entry.getTimestamp());
|
||||
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
Emulator.getLogging().logSQLException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<WiredHighscoreRow> getHighscoreRowsForItem(int itemId, WiredHighscoreClearType clearType, WiredHighscoreScoreType scoreType) {
|
||||
if (!this.data.containsKey(itemId)) return null;
|
||||
|
||||
Stream<WiredHighscoreRow> highscores = this.data.get(itemId).stream()
|
||||
.filter(entry -> this.timeMatchesEntry(entry, clearType) && (scoreType != WiredHighscoreScoreType.MOSTWIN || entry.isWin()))
|
||||
.map(entry -> new WiredHighscoreRow(
|
||||
entry.getUserIds().stream()
|
||||
.map(id -> Emulator.getGameEnvironment().getHabboManager().getHabboInfo(id).getUsername())
|
||||
.collect(Collectors.toList()),
|
||||
entry.getScore()
|
||||
));
|
||||
|
||||
if (scoreType == WiredHighscoreScoreType.CLASSIC) {
|
||||
return highscores.sorted(WiredHighscoreRow::compareTo).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (scoreType == WiredHighscoreScoreType.PERTEAM) {
|
||||
return highscores
|
||||
.collect(Collectors.groupingBy(h -> h.getUsers().hashCode()))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(e -> e.getValue().stream()
|
||||
.sorted(WiredHighscoreRow::compareTo)
|
||||
.collect(Collectors.toList())
|
||||
.get(0)
|
||||
)
|
||||
.sorted(WiredHighscoreRow::compareTo)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (scoreType == WiredHighscoreScoreType.MOSTWIN) {
|
||||
return highscores
|
||||
.collect(Collectors.groupingBy(h -> h.getUsers().hashCode()))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(e -> new WiredHighscoreRow(e.getValue().get(0).getUsers(), e.getValue().size()))
|
||||
.sorted(WiredHighscoreRow::compareTo)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean timeMatchesEntry(WiredHighscoreDataEntry entry, WiredHighscoreClearType timeType) {
|
||||
switch (timeType) {
|
||||
case DAILY:
|
||||
return entry.getTimestamp() > this.getTodayStartTimestamp() && entry.getTimestamp() < this.getTodayEndTimestamp();
|
||||
case WEEKLY:
|
||||
return entry.getTimestamp() > this.getWeekStartTimestamp() && entry.getTimestamp() < this.getWeekEndTimestamp();
|
||||
case MONTHLY:
|
||||
return entry.getTimestamp() > this.getMonthStartTimestamp() && entry.getTimestamp() < this.getMonthEndTimestamp();
|
||||
case ALLTIME:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private long getTodayStartTimestamp() {
|
||||
return LocalDateTime.now().with(LocalTime.MIDNIGHT).atZone(zoneId).toEpochSecond();
|
||||
}
|
||||
|
||||
private long getTodayEndTimestamp() {
|
||||
return LocalDateTime.now().with(LocalTime.MIDNIGHT).plusDays(1).plusSeconds(-1).atZone(zoneId).toEpochSecond();
|
||||
}
|
||||
|
||||
private long getWeekStartTimestamp() {
|
||||
return LocalDateTime.now().with(LocalTime.MIDNIGHT).with(TemporalAdjusters.previousOrSame(firstDayOfWeek)).atZone(zoneId).toEpochSecond();
|
||||
}
|
||||
|
||||
private long getWeekEndTimestamp() {
|
||||
return LocalDateTime.now().with(LocalTime.MIDNIGHT).plusDays(1).plusSeconds(-1).with(TemporalAdjusters.nextOrSame(lastDayOfWeek)).atZone(zoneId).toEpochSecond();
|
||||
}
|
||||
|
||||
private long getMonthStartTimestamp() {
|
||||
return LocalDateTime.now().with(LocalTime.MIDNIGHT).with(TemporalAdjusters.firstDayOfMonth()).atZone(zoneId).toEpochSecond();
|
||||
}
|
||||
|
||||
private long getMonthEndTimestamp() {
|
||||
return LocalDateTime.now().with(LocalTime.MIDNIGHT).plusDays(1).plusSeconds(-1).with(TemporalAdjusters.lastDayOfMonth()).atZone(zoneId).toEpochSecond();
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.eu.habbo.habbohotel.wired.highscores;
|
||||
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredHighscore;
|
||||
import com.eu.habbo.habbohotel.rooms.Room;
|
||||
import com.eu.habbo.habbohotel.users.HabboItem;
|
||||
import gnu.trove.set.hash.THashSet;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
|
||||
public class WiredHighscoreMidnightUpdater implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
List<Room> rooms = Emulator.getGameEnvironment().getRoomManager().getActiveRooms();
|
||||
|
||||
for (Room room : rooms) {
|
||||
THashSet<HabboItem> items = room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class);
|
||||
for (HabboItem item : items) {
|
||||
((InteractionWiredHighscore) item).reloadData();
|
||||
room.updateItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
WiredHighscoreManager.midnightUpdater = Emulator.getThreading().run(new WiredHighscoreMidnightUpdater(), getNextUpdaterRun());
|
||||
}
|
||||
|
||||
public static int getNextUpdaterRun() {
|
||||
return Math.toIntExact(LocalDateTime.now().with(LocalTime.MIDNIGHT).plusDays(1).plusSeconds(-1).atZone(ZoneId.systemDefault()).toEpochSecond() - Emulator.getIntUnixTimestamp()) + 5;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.eu.habbo.habbohotel.wired.highscores;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class WiredHighscoreRow implements Comparable<WiredHighscoreRow> {
|
||||
public static final Comparator<WiredHighscoreRow> COMPARATOR = Comparator.comparing(WiredHighscoreRow::getValue).reversed();
|
||||
|
||||
private final List<String> users;
|
||||
private final int value;
|
||||
|
||||
public WiredHighscoreRow(List<String> users, int value) {
|
||||
Collections.sort(users);
|
||||
|
||||
this.users = users;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public List<String> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(WiredHighscoreRow otherRow) {
|
||||
return COMPARATOR.compare(this, otherRow);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.eu.habbo.habbohotel.wired;
|
||||
package com.eu.habbo.habbohotel.wired.highscores;
|
||||
|
||||
public enum WiredHighscoreScoreType {
|
||||
PERTEAM(0),
|
Loading…
Reference in New Issue
Block a user