From fdb367966bc287f44f1c5b4235839f6b8f52ad58 Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Wed, 31 Jul 2019 12:59:58 +0100 Subject: [PATCH 1/2] Calendar is now fixed. Credits to ItsGiuseppe. --- .../catalog/CalendarRewardObject.java | 32 +++++++++++-------- .../habbohotel/catalog/CatalogManager.java | 17 +++++----- .../AdventCalendarForceOpenEvent.java | 3 ++ .../calendar/AdventCalendarOpenDayEvent.java | 2 +- .../calendar/AdventCalendarDataComposer.java | 25 ++++++--------- .../AdventCalendarProductComposer.java | 5 +-- 6 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/CalendarRewardObject.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CalendarRewardObject.java index 6940f759..f2b135b5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CalendarRewardObject.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CalendarRewardObject.java @@ -1,30 +1,32 @@ package com.eu.habbo.habbohotel.catalog; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer; +import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer; import java.sql.ResultSet; import java.sql.SQLException; public class CalendarRewardObject { private final int id; - private final String name; private final String customImage; private final int credits; private final int points; private final int pointsType; private final String badge; - private final int catalogItemId; + private final int itemId; public CalendarRewardObject(ResultSet set) throws SQLException { this.id = set.getInt("id"); - this.name = set.getString("name"); this.customImage = set.getString("custom_image"); this.credits = set.getInt("credits"); this.points = set.getInt("points"); this.pointsType = set.getInt("points_type"); this.badge = set.getString("badge"); - this.catalogItemId = set.getInt("catalog_item_id"); + this.itemId = set.getInt("item_id"); } public void give(Habbo habbo) { @@ -40,11 +42,19 @@ public class CalendarRewardObject { habbo.addBadge(this.badge); } - if (this.catalogItemId > 0) { - CatalogItem item = this.getCatalogItem(); + if (this.itemId > 0) { + Item item = getItem(); if (item != null) { - Emulator.getGameEnvironment().getCatalogManager().purchaseItem(null, item, habbo, 1, "", true); + HabboItem habboItem = Emulator.getGameEnvironment().getItemManager().createItem( + habbo.getHabboInfo().getId(), + item, + 0, + 0, + ""); + habbo.getInventory().getItemsComponent().addItem(habboItem); + habbo.getClient().sendResponse(new AddHabboItemComposer(habboItem)); + habbo.getClient().sendResponse(new InventoryRefreshComposer()); } } } @@ -53,10 +63,6 @@ public class CalendarRewardObject { return this.id; } - public String getName() { - return this.name; - } - public String getCustomImage() { return this.customImage; } @@ -77,7 +83,7 @@ public class CalendarRewardObject { return this.badge; } - public CatalogItem getCatalogItem() { - return Emulator.getGameEnvironment().getCatalogManager().getCatalogItem(this.catalogItemId); + public Item getItem() { + return Emulator.getGameEnvironment().getItemManager().getItem(this.itemId); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java index 5e1e81c1..f5dc975e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -31,6 +31,7 @@ import com.eu.habbo.plugin.events.emulator.EmulatorLoadCatalogManagerEvent; import com.eu.habbo.plugin.events.users.catalog.UserCatalogFurnitureBoughtEvent; import com.eu.habbo.plugin.events.users.catalog.UserCatalogItemPurchasedEvent; import gnu.trove.TCollections; +import gnu.trove.iterator.TIntIterator; import gnu.trove.iterator.TIntObjectIterator; import gnu.trove.map.TIntObjectMap; import gnu.trove.map.hash.THashMap; @@ -1119,15 +1120,15 @@ public class CatalogManager { return offers; } - public void claimCalendarReward(Habbo habbo, int day) { + public void claimCalendarReward(Habbo habbo, int day, boolean force) { if (!habbo.getHabboStats().calendarRewardsClaimed.contains(day)) { - habbo.getHabboStats().calendarRewardsClaimed.add(day); - CalendarRewardObject object = this.calendarRewards.get(day); - - if (object != null) { - object.give(habbo); - habbo.getClient().sendResponse(new InventoryRefreshComposer()); + CalendarRewardObject object = this.calendarRewards.get((day+1)); + int actualDay = (int) Math.floor((Emulator.getIntUnixTimestamp() - Emulator.getConfig().getInt("hotel.calendar.starttimestamp")) / 86400); + int diff = (actualDay - day); + if (((diff <= 2 && diff >= 0) || force) && object != null) { + habbo.getHabboStats().calendarRewardsClaimed.add(day); habbo.getClient().sendResponse(new AdventCalendarProductComposer(true, object)); + object.give(habbo); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO calendar_rewards_claimed (user_id, reward_id, timestamp) VALUES (?, ?, ?)")) { statement.setInt(1, habbo.getHabboInfo().getId()); @@ -1138,8 +1139,6 @@ public class CatalogManager { Emulator.getLogging().logSQLException(e); } } - - } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/events/calendar/AdventCalendarForceOpenEvent.java b/src/main/java/com/eu/habbo/messages/incoming/events/calendar/AdventCalendarForceOpenEvent.java index 99f87ad0..1ab77c2c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/events/calendar/AdventCalendarForceOpenEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/events/calendar/AdventCalendarForceOpenEvent.java @@ -1,5 +1,6 @@ package com.eu.habbo.messages.incoming.events.calendar; +import com.eu.habbo.Emulator; import com.eu.habbo.messages.incoming.MessageHandler; public class AdventCalendarForceOpenEvent extends MessageHandler { @@ -7,5 +8,7 @@ public class AdventCalendarForceOpenEvent extends MessageHandler { public void handle() throws Exception { String campaign = this.packet.readString(); int day = this.packet.readInt(); + + Emulator.getGameEnvironment().getCatalogManager().claimCalendarReward(this.client.getHabbo(), day, true); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/events/calendar/AdventCalendarOpenDayEvent.java b/src/main/java/com/eu/habbo/messages/incoming/events/calendar/AdventCalendarOpenDayEvent.java index 51cbd07a..9c68cfd0 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/events/calendar/AdventCalendarOpenDayEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/events/calendar/AdventCalendarOpenDayEvent.java @@ -9,6 +9,6 @@ public class AdventCalendarOpenDayEvent extends MessageHandler { String campaign = this.packet.readString(); int day = this.packet.readInt(); - Emulator.getGameEnvironment().getCatalogManager().claimCalendarReward(this.client.getHabbo(), day); + Emulator.getGameEnvironment().getCatalogManager().claimCalendarReward(this.client.getHabbo(), day, false); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/outgoing/events/calendar/AdventCalendarDataComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/events/calendar/AdventCalendarDataComposer.java index 6ac6c009..d171c3b2 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/events/calendar/AdventCalendarDataComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/events/calendar/AdventCalendarDataComposer.java @@ -28,33 +28,28 @@ public class AdventCalendarDataComposer extends MessageComposer { this.response.appendString(""); this.response.appendInt(this.currentDay); this.response.appendInt(this.totalDays); - this.response.appendInt(this.unlocked.size()); TIntArrayList expired = new TIntArrayList(); for (int i = 0; i < this.totalDays; i++) { expired.add(i); - expired.remove(this.currentDay); } + expired.remove(this.currentDay); + if(this.currentDay > 1) expired.remove(this.currentDay - 2); + if(this.currentDay > 0) expired.remove(this.currentDay - 1); - this.unlocked.forEach(new TIntProcedure() { - @Override - public boolean execute(int value) { - AdventCalendarDataComposer.this.response.appendInt(value); - expired.remove(value); - return true; - } + this.unlocked.forEach(value -> { + AdventCalendarDataComposer.this.response.appendInt(value); + expired.remove(value); + return true; }); if (this.lockExpired) { this.response.appendInt(expired.size()); - expired.forEach(new TIntProcedure() { - @Override - public boolean execute(int value) { - AdventCalendarDataComposer.this.response.appendInt(value); - return true; - } + expired.forEach(value -> { + AdventCalendarDataComposer.this.response.appendInt(value); + return true; }); } else { this.response.appendInt(0); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/events/calendar/AdventCalendarProductComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/events/calendar/AdventCalendarProductComposer.java index 5352d886..15c08771 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/events/calendar/AdventCalendarProductComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/events/calendar/AdventCalendarProductComposer.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.outgoing.events.calendar; import com.eu.habbo.habbohotel.catalog.CalendarRewardObject; +import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -18,9 +19,9 @@ public class AdventCalendarProductComposer extends MessageComposer { public ServerMessage compose() { this.response.init(Outgoing.AdventCalendarProductComposer); this.response.appendBoolean(this.visible); - this.response.appendString(this.rewardObject.getName()); + this.response.appendString(this.rewardObject.getItem().getName()); this.response.appendString(this.rewardObject.getCustomImage()); - this.response.appendString(this.rewardObject.getCatalogItem() != null ? this.rewardObject.getCatalogItem().getName() : this.rewardObject.getName()); + this.response.appendString(this.rewardObject.getItem().getName()); return this.response; } } \ No newline at end of file From 8d7c9aff70b6fbf3eff791e5520e13a76d10d988 Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Wed, 31 Jul 2019 13:01:47 +0100 Subject: [PATCH 2/2] Calendar is now fixed. Credits to ItsGiuseppe. --- .../eu/habbo/messages/incoming/handshake/UsernameEvent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/UsernameEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/UsernameEvent.java index 62b4d631..aa4d946f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/UsernameEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/UsernameEvent.java @@ -83,8 +83,8 @@ public class UsernameEvent extends MessageHandler { } } - if (calendar && Emulator.getConfig().getBoolean("hotel.calendar.enabled")) { - this.client.sendResponse(new AdventCalendarDataComposer("xmas11", Emulator.getGameEnvironment().getCatalogManager().calendarRewards.size(), (int) Math.floor((Emulator.getIntUnixTimestamp() - Emulator.getConfig().getInt("hotel.calendar.starttimestamp")) / 86400), this.client.getHabbo().getHabboStats().calendarRewardsClaimed, true)); + if (Emulator.getConfig().getBoolean("hotel.calendar.enabled")) { + this.client.sendResponse(new AdventCalendarDataComposer("xmas15", Emulator.getGameEnvironment().getCatalogManager().calendarRewards.size(), (int) Math.floor((Emulator.getIntUnixTimestamp() - Emulator.getConfig().getInt("hotel.calendar.starttimestamp")) / 86400), this.client.getHabbo().getHabboStats().calendarRewardsClaimed, true)); this.client.sendResponse(new NuxAlertComposer("openView/calendar")); }