From db71cd840671acacfd6719297887f5cf804d5c25 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Wed, 29 Jan 2020 22:03:00 -0600 Subject: [PATCH] rank effects added to EffectsComponent in inventory --- .../habbo/habbohotel/users/HabboManager.java | 9 ++++++++- .../users/inventory/EffectsComponent.java | 20 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java index 0a1a6b00..27adcc59 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolBan; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.Rank; +import com.eu.habbo.habbohotel.users.inventory.EffectsComponent; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.catalog.*; import com.eu.habbo.messages.outgoing.catalog.marketplace.MarketplaceConfigComposer; @@ -246,7 +247,9 @@ public class HabboManager { Rank oldRank = habbo.getHabboInfo().getRank(); if (!oldRank.getBadge().isEmpty()) { habbo.deleteBadge(habbo.getInventory().getBadgesComponent().getBadge(oldRank.getBadge())); - //BadgesComponent.deleteBadge(userId, oldRank.getBadge()); // unnecessary as Habbo.deleteBadge does this + } + if(oldRank.getRoomEffect() > 0) { + habbo.getInventory().getEffectsComponent().effects.remove(oldRank.getRoomEffect()); } habbo.getHabboInfo().setRank(newRank); @@ -255,6 +258,10 @@ public class HabboManager { habbo.addBadge(newRank.getBadge()); } + if(newRank.getRoomEffect() > 0) { + habbo.getInventory().getEffectsComponent().createRankEffect(habbo.getHabboInfo().getRank().getRoomEffect()); + } + habbo.getClient().sendResponse(new UserPermissionsComposer(habbo)); habbo.getClient().sendResponse(new UserPerksComposer(habbo)); 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 b0da325b..6448e23a 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 @@ -31,6 +31,8 @@ public class EffectsComponent { } catch (SQLException e) { Emulator.getLogging().logSQLException(e); } + if(habbo.getHabboInfo().getRank().getRoomEffect() > 0) + this.createRankEffect(habbo.getHabboInfo().getRank().getRoomEffect()); } public HabboEffect createEffect(int effectId) { @@ -58,6 +60,15 @@ public class EffectsComponent { return effect; } + public HabboEffect createRankEffect(int effectId) { + HabboEffect rankEffect = new HabboEffect(effectId, habbo.getHabboInfo().getId()); + rankEffect.duration = 0; + rankEffect.isRankEnable = true; + rankEffect.activationTimestamp = Emulator.getIntUnixTimestamp(); + this.effects.put(effectId, rankEffect); + return rankEffect; + } + public void addEffect(HabboEffect effect) { this.effects.put(effect.effect, effect); @@ -67,9 +78,8 @@ public class EffectsComponent { public void dispose() { synchronized (this.effects) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_effects SET duration = ?, activation_timestamp = ?, total = ? WHERE user_id = ? AND effect = ?")) { - this.effects.forEachValue(new TObjectProcedure() { - @Override - public boolean execute(HabboEffect effect) { + this.effects.forEachValue(effect -> { + if(!effect.isRankEnable) { try { statement.setInt(1, effect.duration); statement.setInt(2, effect.activationTimestamp); @@ -80,9 +90,8 @@ public class EffectsComponent { } catch (SQLException e) { Emulator.getLogging().logSQLException(e); } - - return true; } + return true; }); statement.executeBatch(); @@ -145,6 +154,7 @@ public class EffectsComponent { public int activationTimestamp = -1; public int total = 1; public boolean enabled = false; + public boolean isRankEnable = false; public HabboEffect(ResultSet set) throws SQLException { this.effect = set.getInt("effect");