From 9561c0b073ec69ad4f50ca088961b955d35c60c1 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 1 Feb 2020 14:15:49 +0200 Subject: [PATCH] Fix NPE in SecureLoginEvent --- .../users/inventory/EffectsComponent.java | 3 +-- .../incoming/handshake/SecureLoginEvent.java | 2 +- .../outgoing/inventory/UserEffectsListComposer.java | 13 +++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java index b1e50d72..591ab435 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java @@ -14,12 +14,11 @@ import java.sql.ResultSet; import java.sql.SQLException; public class EffectsComponent { - public final THashMap effects; + public final THashMap effects = new THashMap<>(); public final Habbo habbo; public int activatedEffect = 0; public EffectsComponent(Habbo habbo) { - this.effects = new THashMap<>(); this.habbo = habbo; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users_effects WHERE user_id = ?")) { statement.setInt(1, habbo.getHabboInfo().getId()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index 86d75859..0a8f2685 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -102,7 +102,7 @@ public class SecureLoginEvent extends MessageHandler { messages.add(new SecureLoginOKComposer().compose()); messages.add(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), 0).compose()); - messages.add(new UserEffectsListComposer(habbo, client.getHabbo().getInventory().getEffectsComponent().effects.values().toArray(new EffectsComponent.HabboEffect[0])).compose()); + messages.add(new UserEffectsListComposer(habbo, this.client.getHabbo().getInventory().getEffectsComponent().effects.values()).compose()); messages.add(new UserClothesComposer(this.client.getHabbo()).compose()); messages.add(new NewUserIdentityComposer(habbo).compose()); messages.add(new UserPermissionsComposer(this.client.getHabbo()).compose()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/inventory/UserEffectsListComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/inventory/UserEffectsListComposer.java index b1cd6cd6..2c09b324 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/inventory/UserEffectsListComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/inventory/UserEffectsListComposer.java @@ -6,13 +6,15 @@ import com.eu.habbo.habbohotel.users.inventory.EffectsComponent; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; -import gnu.trove.procedure.TObjectProcedure; + +import java.util.Collection; + public class UserEffectsListComposer extends MessageComposer { public final Habbo habbo; - public final EffectsComponent.HabboEffect[] effects; + public final Collection effects; - public UserEffectsListComposer(Habbo habbo, EffectsComponent.HabboEffect[] effects) { + public UserEffectsListComposer(Habbo habbo, Collection effects) { this.habbo = habbo; this.effects = effects; } @@ -26,10 +28,9 @@ public class UserEffectsListComposer extends MessageComposer { this.response.appendInt(0); } else { synchronized (this.habbo.getInventory().getEffectsComponent().effects) { - this.response.appendInt(this.effects.length); - - for(EffectsComponent.HabboEffect effect : effects) { + this.response.appendInt(this.effects.size()); + for (EffectsComponent.HabboEffect effect : effects) { UserEffectsListComposer.this.response.appendInt(effect.effect); UserEffectsListComposer.this.response.appendInt(0); UserEffectsListComposer.this.response.appendInt(effect.duration > 0 ? effect.duration : Integer.MAX_VALUE);