From a0c1973622ec560cc4d5fc069b4627d183430b05 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 7 Jun 2020 16:19:05 +0300 Subject: [PATCH] Customizable gift wrapping config & gift purchase validation --- sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql | 6 +++- .../catalog/CatalogBuyItemAsGiftEvent.java | 5 +++ .../catalog/GiftConfigurationComposer.java | 34 +++++++------------ .../com/eu/habbo/plugin/PluginManager.java | 5 +++ 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql b/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql index 46a1f7fa..8e71d599 100644 --- a/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql +++ b/sqlupdates/2_4_0-RC-1 to 2_4_0-RC-2.sql @@ -20,4 +20,8 @@ INSERT INTO `emulator_texts`(`key`, `value`) VALUES ('error.bots.max.inventory', UPDATE `emulator_texts` SET `value` = 'You\'ve reached the maximum amount of pets in your inventory! The Limit is %amount%!' WHERE `key` = 'error.pets.max.inventory'; -- Tradelock counter -ALTER TABLE `users_settings` ADD `tradelock_amount` INT(11) NOT NULL DEFAULT '0' AFTER `helper_level`; \ No newline at end of file +ALTER TABLE `users_settings` ADD `tradelock_amount` INT(11) NOT NULL DEFAULT '0' AFTER `helper_level`; + +-- Gift wrapping configuration +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.gifts.box_types', '0,1,2,3,4,5,6,8'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.gifts.ribbon_types', '0,1,2,3,4,5,6,7,8,9,10'); diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java index f201cb83..7504c50a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java @@ -75,6 +75,11 @@ public class CatalogBuyItemAsGiftEvent extends MessageHandler { return; } + if (!GiftConfigurationComposer.BOX_TYPES.contains(color) || !GiftConfigurationComposer.RIBBON_TYPES.contains(ribbonId)) { + this.client.sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR).compose()); + return; + } + Integer iItemId = Emulator.getGameEnvironment().getCatalogManager().giftWrappers.get(spriteId); if (iItemId == null) diff --git a/src/main/java/com/eu/habbo/messages/outgoing/catalog/GiftConfigurationComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/catalog/GiftConfigurationComposer.java index cf66be10..77328100 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/catalog/GiftConfigurationComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/catalog/GiftConfigurationComposer.java @@ -5,9 +5,14 @@ import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; +import java.util.Arrays; +import java.util.List; import java.util.Map; public class GiftConfigurationComposer extends MessageComposer { + public static List BOX_TYPES = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 8); + public static List RIBBON_TYPES = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.GiftConfigurationComposer); @@ -19,28 +24,15 @@ public class GiftConfigurationComposer extends MessageComposer { this.response.appendInt(i); } - this.response.appendInt(8); - this.response.appendInt(0); - this.response.appendInt(1); - this.response.appendInt(2); - this.response.appendInt(3); - this.response.appendInt(4); - this.response.appendInt(5); - this.response.appendInt(6); - this.response.appendInt(8); + this.response.appendInt(BOX_TYPES.size()); + for (Integer type : BOX_TYPES) { + this.response.appendInt(type); + } - this.response.appendInt(11); - this.response.appendInt(0); - this.response.appendInt(1); - this.response.appendInt(2); - this.response.appendInt(3); - this.response.appendInt(4); - this.response.appendInt(5); - this.response.appendInt(6); - this.response.appendInt(7); - this.response.appendInt(8); - this.response.appendInt(9); - this.response.appendInt(10); + this.response.appendInt(RIBBON_TYPES.size()); + for (Integer type : RIBBON_TYPES) { + this.response.appendInt(type); + } this.response.appendInt(Emulator.getGameEnvironment().getCatalogManager().giftFurnis.size()); diff --git a/src/main/java/com/eu/habbo/plugin/PluginManager.java b/src/main/java/com/eu/habbo/plugin/PluginManager.java index 50565833..20b9b0c7 100644 --- a/src/main/java/com/eu/habbo/plugin/PluginManager.java +++ b/src/main/java/com/eu/habbo/plugin/PluginManager.java @@ -34,6 +34,7 @@ import com.eu.habbo.messages.incoming.hotelview.HotelViewRequestLTDAvailabilityE import com.eu.habbo.messages.incoming.rooms.promotions.BuyRoomPromotionEvent; import com.eu.habbo.messages.incoming.users.ChangeNameCheckUsernameEvent; import com.eu.habbo.messages.outgoing.catalog.DiscountComposer; +import com.eu.habbo.messages.outgoing.catalog.GiftConfigurationComposer; import com.eu.habbo.messages.outgoing.navigator.NewNavigatorEventCategoriesComposer; import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent; import com.eu.habbo.plugin.events.emulator.EmulatorLoadedEvent; @@ -58,6 +59,7 @@ import java.net.URLClassLoader; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Objects; +import java.util.stream.Collectors; public class PluginManager { @@ -154,6 +156,9 @@ public class PluginManager { BotManager.MAXIMUM_BOT_INVENTORY_SIZE = Emulator.getConfig().getInt("hotel.bots.max.inventory"); PetManager.MAXIMUM_PET_INVENTORY_SIZE = Emulator.getConfig().getInt("hotel.pets.max.inventory"); + GiftConfigurationComposer.BOX_TYPES = Arrays.stream(Emulator.getConfig().getValue("hotel.gifts.box_types").split(",")).mapToInt(Integer::parseInt).boxed().collect(Collectors.toList()); + GiftConfigurationComposer.RIBBON_TYPES = Arrays.stream(Emulator.getConfig().getValue("hotel.gifts.ribbon_types").split(",")).mapToInt(Integer::parseInt).boxed().collect(Collectors.toList()); + NewNavigatorEventCategoriesComposer.CATEGORIES.clear(); for (String category : Emulator.getConfig().getValue("navigator.eventcategories", "").split(";")) { try {