diff --git a/src/main/java/com/eu/habbo/core/CleanerThread.java b/src/main/java/com/eu/habbo/core/CleanerThread.java index 9c174fca..764770d0 100644 --- a/src/main/java/com/eu/habbo/core/CleanerThread.java +++ b/src/main/java/com/eu/habbo/core/CleanerThread.java @@ -147,8 +147,8 @@ public class CleanerThread implements Runnable { statement.execute("DELETE users_favorite_rooms FROM users_favorite_rooms LEFT JOIN rooms ON room_id = rooms.id WHERE rooms.id IS NULL"); } - try (PreparedStatement statement = connection.prepareStatement("UPDATE users_effects SET total = total - 1 WHERE activation_timestamp < ? AND activation_timestamp != 0")) { - statement.setInt(1, Emulator.getIntUnixTimestamp() - 86400); + try (PreparedStatement statement = connection.prepareStatement("UPDATE users_effects SET total = total - 1 WHERE activation_timestamp + duration < ? AND activation_timestamp > 0 AND duration > 0")) { + statement.setInt(1, Emulator.getIntUnixTimestamp()); statement.execute(); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java index f68a0aa8..3b579a54 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java @@ -6,6 +6,8 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.HabboGender; import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.inventory.EffectsComponent; +import com.eu.habbo.messages.outgoing.inventory.UserEffectsListComposer; import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer; import com.eu.habbo.threading.runnables.QueryDeleteHabboItem; @@ -15,41 +17,54 @@ import java.sql.SQLException; public class InteractionFXBox extends InteractionDefault { public InteractionFXBox(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + // this.setExtradata("0"); } public InteractionFXBox(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + // this.setExtradata("0"); } @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { super.onClick(client, room, objects); - if (client != null && room.hasRights(client.getHabbo())) { + if (client != null && this.getUserId() == client.getHabbo().getHabboInfo().getId()) { + if(this.getExtradata().equals("1")) + return; + + int effectId = -1; + if (client.getHabbo().getHabboInfo().getGender().equals(HabboGender.M)) { if (this.getBaseItem().getEffectM() > 0) { - room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1); + effectId = this.getBaseItem().getEffectM(); } } if (client.getHabbo().getHabboInfo().getGender().equals(HabboGender.F)) { if (this.getBaseItem().getEffectF() > 0) { - room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1); + effectId = this.getBaseItem().getEffectF(); } } + if(effectId < 0) + return; + + if(client.getHabbo().getInventory().getEffectsComponent().ownsEffect(effectId)) + return; + + EffectsComponent.HabboEffect effect = client.getHabbo().getInventory().getEffectsComponent().createEffect(effectId, 0); + client.sendResponse(new UserEffectsListComposer(client.getHabbo())); + client.getHabbo().getInventory().getEffectsComponent().enableEffect(effectId); + this.setExtradata("1"); room.updateItemState(this); room.removeHabboItem(this); HabboItem item = this; - Emulator.getThreading().run(new Runnable() { - @Override - public void run() { - new QueryDeleteHabboItem(item.getId()).run(); - room.sendComposer(new RemoveFloorItemComposer(item).compose()); - } + Emulator.getThreading().run(() -> { + new QueryDeleteHabboItem(item.getId()).run(); + room.sendComposer(new RemoveFloorItemComposer(item).compose()); + room.updateTile(room.getLayout().getTile(this.getX(), this.getY())); }, 500); } } 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 6be7b4dd..b0da325b 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 @@ -34,6 +34,10 @@ public class EffectsComponent { } public HabboEffect createEffect(int effectId) { + return createEffect(effectId, 86400); + } + + public HabboEffect createEffect(int effectId, int duration) { HabboEffect effect; synchronized (this.effects) { if (this.effects.containsKey(effectId)) { @@ -44,6 +48,7 @@ public class EffectsComponent { } } else { effect = new HabboEffect(effectId, this.habbo.getHabboInfo().getId()); + effect.duration = duration; effect.insert(); } @@ -159,6 +164,9 @@ public class EffectsComponent { } public boolean isRemaining() { + if(this.duration <= 0) + return true; + if (this.total > 0) { if (this.activationTimestamp >= 0) { if (Emulator.getIntUnixTimestamp() - this.activationTimestamp >= this.duration) { @@ -172,6 +180,9 @@ public class EffectsComponent { } public int remainingTime() { + if(this.duration <= 0) //permanant + return Integer.MAX_VALUE; + return Emulator.getIntUnixTimestamp() - this.activationTimestamp + this.duration; } 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 9fa470af..157c53c9 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 @@ -27,10 +27,16 @@ public class UserEffectsListComposer extends MessageComposer { this.habbo.getInventory().getEffectsComponent().effects.forEachValue(effect -> { UserEffectsListComposer.this.response.appendInt(effect.effect); UserEffectsListComposer.this.response.appendInt(0); - UserEffectsListComposer.this.response.appendInt(effect.duration); - UserEffectsListComposer.this.response.appendInt(effect.total); - UserEffectsListComposer.this.response.appendInt(effect.activationTimestamp >= 0 ? Emulator.getIntUnixTimestamp() - effect.activationTimestamp : -1); - UserEffectsListComposer.this.response.appendBoolean(effect.isActivated()); + UserEffectsListComposer.this.response.appendInt(effect.duration > 0 ? effect.duration : 1); + UserEffectsListComposer.this.response.appendInt(effect.total - (effect.isActivated() ? 1 : 0)); + + if(!effect.isActivated()) { + UserEffectsListComposer.this.response.appendInt(0); + } + else { + UserEffectsListComposer.this.response.appendInt(effect.duration > 0 ? (Emulator.getIntUnixTimestamp() - effect.activationTimestamp) + effect.duration : -1); + } + UserEffectsListComposer.this.response.appendBoolean(effect.duration <= 0); //effect.isActivated()); return true; }); }