Merge branch 'small-fixes-2' into 'dev'

Followup of code improvement

See merge request morningstar/Arcturus-Community!106
This commit is contained in:
ArpyAge 2025-01-24 19:44:20 +00:00
commit 2ec4f767d8
20 changed files with 27 additions and 59 deletions

View File

@ -630,11 +630,7 @@ public class CatalogManager {
boolean isVisiblePage = object.visible; boolean isVisiblePage = object.visible;
boolean hasRightRank = object.getRank() <= habbo.getHabboInfo().getRank().getId(); boolean hasRightRank = object.getRank() <= habbo.getHabboInfo().getRank().getId();
boolean clubRightsOkay = true; boolean clubRightsOkay = !object.isClubOnly() || habbo.getHabboInfo().getHabboStats().hasActiveClub();
if(object.isClubOnly() && !habbo.getHabboInfo().getHabboStats().hasActiveClub()) {
clubRightsOkay = false;
}
if (isVisiblePage && hasRightRank && clubRightsOkay) { if (isVisiblePage && hasRightRank && clubRightsOkay) {
pages.add(object); pages.add(object);

View File

@ -122,10 +122,7 @@ public class FreezeGamePlayer extends GamePlayer {
} }
public boolean canGetFrozen() { public boolean canGetFrozen() {
if (this.isFrozen() || this.isProtected()) return !this.isFrozen() && !this.isProtected();
return false;
return true;
} }
public void addProtection() { public void addProtection() {

View File

@ -123,7 +123,7 @@ public class ForumThread implements Runnable, ISerialize {
THashSet<ForumThread> threads = null; THashSet<ForumThread> threads = null;
if (guildThreadsCache.containsKey(guildId)) { if (guildThreadsCache.containsKey(guildId)) {
guildThreadsCache.get(guildId); threads = guildThreadsCache.get(guildId);
} }
if (threads != null) if (threads != null)
@ -141,8 +141,8 @@ public class ForumThread implements Runnable, ISerialize {
"WHERE `id` IN (" + "WHERE `id` IN (" +
"SELECT MAX(id) " + "SELECT MAX(id) " +
"FROM `guilds_forums_comments` B " + "FROM `guilds_forums_comments` B " +
"GROUP BY `thread_id` " + "GROUP BY `thread_id` AND B.`id` " +
"ORDER BY B.`id` ASC " + "ORDER BY B.`id` " +
") " + ") " +
"ORDER BY `id` DESC " + "ORDER BY `id` DESC " +
") B ON A.`id` = B.`thread_id` " + ") B ON A.`id` = B.`thread_id` " +
@ -182,8 +182,8 @@ public class ForumThread implements Runnable, ISerialize {
"WHERE `id` IN (" + "WHERE `id` IN (" +
"SELECT MAX(id) " + "SELECT MAX(id) " +
"FROM `guilds_forums_comments` B " + "FROM `guilds_forums_comments` B " +
"GROUP BY `thread_id` " + "GROUP BY `thread_id` AND b.`id`" +
"ORDER BY B.`id` ASC " + "ORDER BY B.`id` " +
") " + ") " +
"ORDER BY `id` DESC " + "ORDER BY `id` DESC " +
") B ON A.`id` = B.`thread_id` " + ") B ON A.`id` = B.`thread_id` " +
@ -219,11 +219,8 @@ public class ForumThread implements Runnable, ISerialize {
guildThreadsCache.put(thread.guildId, guildThreads); guildThreadsCache.put(thread.guildId, guildThreads);
} }
} }
synchronized (guildThreads) {
guildThreads.add(thread); guildThreads.add(thread);
} }
}
public static void clearCache() { public static void clearCache() {
for (THashSet<ForumThread> threads : guildThreadsCache.values()) { for (THashSet<ForumThread> threads : guildThreadsCache.values()) {

View File

@ -202,10 +202,7 @@ public class InteractionTeleport extends HabboItem {
if (unit == null) if (unit == null)
return false; return false;
if (habbo.getHabboInfo().getRiding() != null) return habbo.getHabboInfo().getRiding() == null;
return false;
return true;
} }
public void startTeleport(Room room, Habbo habbo) { public void startTeleport(Room room, Habbo habbo) {

View File

@ -115,9 +115,7 @@ public abstract class InteractionWired extends InteractionDefault {
} else { } else {
if (this.userExecutionCache.containsKey((long)roomUnitId)) { if (this.userExecutionCache.containsKey((long)roomUnitId)) {
long lastTimestamp = this.userExecutionCache.get((long)roomUnitId); long lastTimestamp = this.userExecutionCache.get((long)roomUnitId);
if (timestamp - lastTimestamp < Math.max(100L, this.requiredCooldown())) { return timestamp - lastTimestamp >= Math.max(100L, this.requiredCooldown());
return false;
}
} }
return true; return true;

View File

@ -81,7 +81,7 @@ public class InteractionWiredHighscore extends HabboItem {
@Override @Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception { public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (!((client != null && room != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) if (room == null || !((client != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType)))
return; return;
if (this.getExtradata() == null || this.getExtradata().isEmpty() || this.getExtradata().length() == 0) { if (this.getExtradata() == null || this.getExtradata().isEmpty() || this.getExtradata().length() == 0) {

View File

@ -63,8 +63,7 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable {
@Override @Override
public int getNextRollDelay(int currentStep, int totalSteps) { public int getNextRollDelay(int currentStep, int totalSteps) {
int t = 2500; return (totalSteps == 1) ? 500 : 100 + (currentStep * 100);
return (totalSteps == 1) ? 500 : 100 * ((t = t / t - 1) * t * t * t * t + 1) + (currentStep * 100);
} }
@Override @Override

View File

@ -51,7 +51,7 @@ public class InteractionTotemLegs extends InteractionDefault {
public void onClick(GameClient client, Room room, Object[] objects) throws Exception { public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
super.onClick(client, room, objects); super.onClick(client, room, objects);
if (!((client != null && room != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) if (room == null || !((client != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType)))
return; return;
updateHead(room, room.getLayout().getTile(this.getX(), this.getY())); updateHead(room, room.getLayout().getTile(this.getX(), this.getY()));

View File

@ -390,9 +390,7 @@ public class Pet implements ISerialize, Runnable {
keys.put(RoomUnitStatus.GESTURE, this.roomUnit.getStatus(RoomUnitStatus.GESTURE)); keys.put(RoomUnitStatus.GESTURE, this.roomUnit.getStatus(RoomUnitStatus.GESTURE));
if (this.task == null) { if (this.task == null) {
boolean isDead = false; boolean isDead = this.roomUnit.hasStatus(RoomUnitStatus.RIP);
if (this.roomUnit.hasStatus(RoomUnitStatus.RIP))
isDead = true;
this.roomUnit.clearStatus(); this.roomUnit.clearStatus();

View File

@ -59,10 +59,7 @@ public class RoomLayout {
if (outerSquare.x + outerSquare.width < innerSquare.x + innerSquare.width) if (outerSquare.x + outerSquare.width < innerSquare.x + innerSquare.width)
return false; return false;
if (outerSquare.y + outerSquare.height < innerSquare.y + innerSquare.height) return outerSquare.y + outerSquare.height >= innerSquare.y + innerSquare.height;
return false;
return true;
} }
public static boolean tileInSquare(Rectangle square, RoomTile tile) { public static boolean tileInSquare(Rectangle square, RoomTile tile) {

View File

@ -1035,7 +1035,7 @@ public class RoomManager {
Collections.sort(rooms); Collections.sort(rooms);
return new ArrayList<>(rooms.subList(0, (rooms.size() < count ? rooms.size() : count))); return new ArrayList<>(rooms.subList(0, (Math.min(rooms.size(), count))));
} }
public ArrayList<Room> getPopularRooms(int count, int category) { public ArrayList<Room> getPopularRooms(int count, int category) {
@ -1053,7 +1053,7 @@ public class RoomManager {
Collections.sort(rooms); Collections.sort(rooms);
return new ArrayList<>(rooms.subList(0, (rooms.size() < count ? rooms.size() : count))); return new ArrayList<>(rooms.subList(0, (Math.min(rooms.size(), count))));
} }
public Map<Integer, List<Room>> getPopularRoomsByCategory(int count) { public Map<Integer, List<Room>> getPopularRoomsByCategory(int count) {
@ -1077,7 +1077,7 @@ public class RoomManager {
Collections.sort(set.getValue()); Collections.sort(set.getValue());
result.put(set.getKey(), new ArrayList<>(set.getValue().subList(0, (set.getValue().size() < count ? set.getValue().size() : count)))); result.put(set.getKey(), new ArrayList<>(set.getValue().subList(0, (Math.min(set.getValue().size(), count)))));
} }
return result; return result;
@ -1294,7 +1294,7 @@ public class RoomManager {
Collections.sort(rooms); Collections.sort(rooms);
return rooms.subList(0, (rooms.size() > limit ? limit : rooms.size())); return rooms.subList(0, (Math.min(rooms.size(), limit)));
} }
public ArrayList<Room> getRoomsWithRights(Habbo habbo) { public ArrayList<Room> getRoomsWithRights(Habbo habbo) {

View File

@ -630,11 +630,7 @@ public class RoomSpecialTypes {
} }
public InteractionFreezeExitTile getFreezeExitTile() { public InteractionFreezeExitTile getFreezeExitTile() {
for (InteractionFreezeExitTile t : this.freezeExitTile.values()) { return this.freezeExitTile.values().stream().findFirst().orElse(null);
return t;
}
return null;
} }
public InteractionFreezeExitTile getRandomFreezeExitTile() { public InteractionFreezeExitTile getRandomFreezeExitTile() {

View File

@ -20,10 +20,7 @@ public class RequestOffersEvent extends MessageHandler {
String query = this.packet.readString(); String query = this.packet.readString();
int type = this.packet.readInt(); int type = this.packet.readInt();
boolean tryCache = false; boolean tryCache = min == -1 && max == -1 && query.isEmpty();
if (min == -1 && max == -1 && query.isEmpty()) {
tryCache = true;
}
if (tryCache) { if (tryCache) {
ServerMessage message = cachedResults.get(type); ServerMessage message = cachedResults.get(type);

View File

@ -13,11 +13,7 @@ public class RequestRoomDataEvent extends MessageHandler {
int something = this.packet.readInt(); int something = this.packet.readInt();
int something2 = this.packet.readInt(); int something2 = this.packet.readInt();
if (room != null) { if (room != null) {
boolean unknown = true; boolean unknown = something != 0 || something2 != 1;
if (something == 0 && something2 == 1) {
unknown = false;
}
//this.client.getHabbo().getHabboInfo().getCurrentRoom() != room //this.client.getHabbo().getHabboInfo().getCurrentRoom() != room
this.client.sendResponse(new RoomDataComposer(room, this.client.getHabbo(), true, unknown)); this.client.sendResponse(new RoomDataComposer(room, this.client.getHabbo(), true, unknown));

View File

@ -43,7 +43,7 @@ public class AchievementListComposer extends MessageComposer {
this.response.appendInt(nextLevel != null ? nextLevel.progress : -1); //Progress needed this.response.appendInt(nextLevel != null ? nextLevel.progress : -1); //Progress needed
this.response.appendInt(nextLevel != null ? nextLevel.rewardAmount : -1); //Reward amount this.response.appendInt(nextLevel != null ? nextLevel.rewardAmount : -1); //Reward amount
this.response.appendInt(nextLevel != null ? nextLevel.rewardType : -1); //Reward currency ID this.response.appendInt(nextLevel != null ? nextLevel.rewardType : -1); //Reward currency ID
this.response.appendInt(achievementProgress <= 0 ? 0 : achievementProgress); //Current progress this.response.appendInt(Math.max(achievementProgress, 0)); //Current progress
this.response.appendBoolean(AchievementManager.hasAchieved(this.habbo, achievement)); //Achieved? (Current Progress == MaxLevel.Progress) this.response.appendBoolean(AchievementManager.hasAchieved(this.habbo, achievement)); //Achieved? (Current Progress == MaxLevel.Progress)
this.response.appendString(achievement.category.toString().toLowerCase()); //Category this.response.appendString(achievement.category.toString().toLowerCase()); //Category
this.response.appendString(""); //Empty, completly unused in client code this.response.appendString(""); //Empty, completly unused in client code

View File

@ -32,7 +32,7 @@ public class GuildForumListComposer extends MessageComposer {
this.response.appendInt(this.index); this.response.appendInt(this.index);
Iterator<Guild> it = guilds.iterator(); Iterator<Guild> it = guilds.iterator();
int count = guilds.size() > 20 ? 20 : guilds.size(); int count = Math.min(guilds.size(), 20);
this.response.appendInt(count); this.response.appendInt(count);

View File

@ -35,7 +35,7 @@ public class GuildForumThreadsComposer extends MessageComposer {
Collections.reverse(threads); Collections.reverse(threads);
Iterator<ForumThread> it = threads.iterator(); Iterator<ForumThread> it = threads.iterator();
int count = threads.size() > 20 ? 20 : threads.size(); int count = Math.min(threads.size(), 20);
this.response.init(Outgoing.GuildForumThreadsComposer); this.response.init(Outgoing.GuildForumThreadsComposer);
this.response.appendInt(this.guild.getId()); this.response.appendInt(this.guild.getId());

View File

@ -21,7 +21,7 @@ public class BonusRareComposer extends MessageComposer {
this.response.appendInt(Emulator.getConfig().getInt("hotelview.promotional.points", 120)); //Total Required this.response.appendInt(Emulator.getConfig().getInt("hotelview.promotional.points", 120)); //Total Required
//this.response.appendInt(this.habbo.getHabboInfo().getBonusRarePoints() >= Emulator.getConfig().getInt("hotelview.promotinal.points", 120) ? Emulator.getConfig().getInt("hotelview.promotinal.points", 120) : this.habbo.getHabboInfo().getBonusRarePoints() ); //Total To Gain //this.response.appendInt(this.habbo.getHabboInfo().getBonusRarePoints() >= Emulator.getConfig().getInt("hotelview.promotinal.points", 120) ? Emulator.getConfig().getInt("hotelview.promotinal.points", 120) : this.habbo.getHabboInfo().getBonusRarePoints() ); //Total To Gain
int points = Emulator.getConfig().getInt("hotelview.promotional.points", 120) - this.habbo.getHabboInfo().getBonusRarePoints(); int points = Emulator.getConfig().getInt("hotelview.promotional.points", 120) - this.habbo.getHabboInfo().getBonusRarePoints();
this.response.appendInt(points < 0 ? 0 : points); this.response.appendInt(Math.max(points, 0));
return this.response; return this.response;
} }

View File

@ -29,7 +29,7 @@ public class GiveRespect extends RCONMessage<GiveRespect.JSONGiveRespect> {
habbo.getHabboStats().respectPointsToGive += object.daily_respects; habbo.getHabboStats().respectPointsToGive += object.daily_respects;
habbo.getClient().sendResponse(new UserDataComposer(habbo)); habbo.getClient().sendResponse(new UserDataComposer(habbo));
} else { } else {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET respects_given = respects_give + ?, respects_received = respects_received + ?, daily_respect_points = daily_respect_points + ? WHERE user_id = ? LIMIT 1")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET respects_given = respects_given + ?, respects_received = respects_received + ?, daily_respect_points = daily_respect_points + ? WHERE user_id = ? LIMIT 1")) {
statement.setInt(1, object.respect_received); statement.setInt(1, object.respect_received);
statement.setInt(2, object.respect_given); statement.setInt(2, object.respect_given);
statement.setInt(3, object.daily_respects); statement.setInt(3, object.daily_respects);

View File

@ -22,7 +22,7 @@ class QueryDeleteHabboBadge implements Runnable {
@Override @Override
public void run() { public void run() {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM user_badges WHERE users_id = ? AND badge_code = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_badges WHERE user_id = ? AND badge_code = ?")) {
statement.setInt(1, this.habbo.getHabboInfo().getId()); statement.setInt(1, this.habbo.getHabboInfo().getId());
statement.setString(2, this.name); statement.setString(2, this.name);
statement.execute(); statement.execute();