From bb6a2e5eacd73d7f6b14615e8a03b2454c12f9df Mon Sep 17 00:00:00 2001 From: ArpyAge Date: Mon, 12 Sep 2022 20:20:14 +0200 Subject: [PATCH] Set all credits/points event to the same method, added cancel for login event --- .../habbo/habbohotel/catalog/CatalogManager.java | 12 ++++-------- .../catalog/marketplace/MarketPlace.java | 6 ++---- .../habbohotel/commands/MassCreditsCommand.java | 2 -- .../WiredEffectGiveHotelviewBonusRarePoints.java | 2 +- .../subscriptions/SubscriptionHabboClub.java | 12 ++++-------- .../catalog/CatalogBuyClubDiscountEvent.java | 10 ++-------- .../catalog/CatalogBuyItemAsGiftEvent.java | 5 ++--- .../incoming/catalog/CatalogBuyItemEvent.java | 16 ++++------------ .../incoming/handshake/SecureLoginEvent.java | 9 ++++++++- .../incoming/rooms/items/RedeemItemEvent.java | 6 ++---- 10 files changed, 29 insertions(+), 51 deletions(-) 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 65d05d0d..acd05516 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -548,13 +548,11 @@ public class CatalogManager { voucher.addHistoryEntry(habbo.getHabboInfo().getId()); if (voucher.points > 0) { - client.getHabbo().getHabboInfo().addCurrencyAmount(voucher.pointsType, voucher.points); - client.sendResponse(new UserPointsComposer(client.getHabbo().getHabboInfo().getCurrencyAmount(voucher.pointsType), voucher.points, voucher.pointsType)); + client.getHabbo().givePoints(voucher.pointsType, voucher.points); } if (voucher.credits > 0) { - client.getHabbo().getHabboInfo().addCredits(voucher.credits); - client.sendResponse(new UserCreditsComposer(client.getHabbo())); + client.getHabbo().giveCredits(voucher.credits); } if (voucher.catalogItemId > 0) { @@ -1072,15 +1070,13 @@ public class CatalogManager { if (!free && !habbo.getClient().getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) { if (purchasedEvent.totalCredits > 0) { - habbo.getClient().getHabbo().getHabboInfo().addCredits(-purchasedEvent.totalCredits); - habbo.getClient().sendResponse(new UserCreditsComposer(habbo.getClient().getHabbo())); + habbo.getClient().getHabbo().giveCredits(-purchasedEvent.totalCredits); } } if (!free && !habbo.getClient().getHabbo().hasPermission(Permission.ACC_INFINITE_POINTS)) { if (purchasedEvent.totalPoints > 0) { - habbo.getClient().getHabbo().getHabboInfo().addCurrencyAmount(item.getPointsType(), -purchasedEvent.totalPoints); - habbo.getClient().sendResponse(new UserPointsComposer(habbo.getClient().getHabbo().getHabboInfo().getCurrencyAmount(item.getPointsType()), -purchasedEvent.totalPoints, item.getPointsType())); + habbo.getClient().getHabbo().givePoints(item.getPointsType(), -purchasedEvent.totalPoints); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java index ec8dadfb..f4d9aef5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java @@ -279,12 +279,11 @@ public class MarketPlace { client.getHabbo().getInventory().getItemsComponent().addItem(item); if (MARKETPLACE_CURRENCY == 0) { - client.getHabbo().getHabboInfo().addCredits(-event.price); + client.getHabbo().giveCredits(-event.price); } else { client.getHabbo().givePoints(MARKETPLACE_CURRENCY, -event.price); } - client.sendResponse(new UserCreditsComposer(client.getHabbo())); client.sendResponse(new AddHabboItemComposer(item)); client.sendResponse(new InventoryRefreshComposer()); client.sendResponse(new MarketplaceBuyErrorComposer(MarketplaceBuyErrorComposer.REFRESH, 0, offerId, price)); @@ -381,11 +380,10 @@ public class MarketPlace { offers.clear(); if (MARKETPLACE_CURRENCY == 0) { - client.getHabbo().getHabboInfo().addCredits(credits); + client.getHabbo().giveCredits(credits); } else { client.getHabbo().givePoints(MARKETPLACE_CURRENCY, credits); } - client.sendResponse(new UserCreditsComposer(client.getHabbo())); } private static void removeUser(MarketPlaceOffer offer) { diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/MassCreditsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/MassCreditsCommand.java index 6c7d279a..24f18000 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/MassCreditsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/MassCreditsCommand.java @@ -4,7 +4,6 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.messages.outgoing.users.UserCreditsComposer; import java.util.Map; @@ -30,7 +29,6 @@ public class MassCreditsCommand extends Command { Habbo habbo = set.getValue(); habbo.giveCredits(amount); - habbo.getClient().sendResponse(new UserCreditsComposer(habbo)); if (habbo.getHabboInfo().getCurrentRoom() != null) habbo.whisper(Emulator.getTexts().getValue("commands.generic.cmd_credits.received").replace("%amount%", amount + ""), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java index 63920ffc..4d21822b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java @@ -95,7 +95,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff return false; if (this.amount > 0) { - habbo.getHabboInfo().addCurrencyAmount(Emulator.getConfig().getInt("hotelview.promotional.points.type"), this.amount); + habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), this.amount); habbo.getClient().sendResponse(new BonusRareComposer(habbo)); } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java b/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java index 0c7fc193..defd6e38 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java @@ -375,15 +375,13 @@ public class SubscriptionHabboClub extends Subscription { case "coins": case "credit": case "coin": - habbo.getClient().getHabbo().getHabboInfo().addCredits(amount); - habbo.getClient().sendResponse(new UserCreditsComposer(habbo.getClient().getHabbo())); + habbo.getClient().getHabbo().giveCredits(amount); break; case "diamonds": case "diamond": pointCurrency = 5; - habbo.getClient().getHabbo().getHabboInfo().addCurrencyAmount(pointCurrency, amount); - habbo.getClient().sendResponse(new UserPointsComposer(habbo.getClient().getHabbo().getHabboInfo().getCurrencyAmount(pointCurrency), amount, pointCurrency)); + habbo.getClient().getHabbo().givePoints(pointCurrency, amount); break; case "duckets": @@ -391,8 +389,7 @@ public class SubscriptionHabboClub extends Subscription { case "pixels": case "pixel": pointCurrency = 0; - habbo.getClient().getHabbo().getHabboInfo().addCurrencyAmount(pointCurrency, amount); - habbo.getClient().sendResponse(new UserPointsComposer(habbo.getClient().getHabbo().getHabboInfo().getCurrencyAmount(pointCurrency), amount, pointCurrency)); + habbo.getClient().getHabbo().givePoints(pointCurrency, amount); break; default: @@ -405,8 +402,7 @@ public class SubscriptionHabboClub extends Subscription { } if (pointCurrency >= 0) { - habbo.getClient().getHabbo().getHabboInfo().addCurrencyAmount(pointCurrency, amount); - habbo.getClient().sendResponse(new UserPointsComposer(habbo.getClient().getHabbo().getHabboInfo().getCurrencyAmount(pointCurrency), amount, pointCurrency)); + habbo.getClient().getHabbo().givePoints(pointCurrency, amount); } break; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyClubDiscountEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyClubDiscountEvent.java index 45567242..8a66d92f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyClubDiscountEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyClubDiscountEvent.java @@ -58,10 +58,10 @@ public class CatalogBuyClubDiscountEvent extends MessageHandler { return; if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) - this.client.getHabbo().getHabboInfo().addCredits(-totalCredits); + this.client.getHabbo().giveCredits(-totalCredits); if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_POINTS)) - this.client.getHabbo().getHabboInfo().addCurrencyAmount(deal.getPointsType(), -totalDuckets); + this.client.getHabbo().givePoints(deal.getPointsType(), -totalDuckets); if(this.client.getHabbo().getHabboStats().createSubscription(Subscription.HABBO_CLUB, (totalDays * 86400)) == null) { @@ -69,12 +69,6 @@ public class CatalogBuyClubDiscountEvent extends MessageHandler { throw new Exception("Unable to create or extend subscription"); } - if (totalCredits > 0) - this.client.sendResponse(new UserCreditsComposer(this.client.getHabbo())); - - if (totalDuckets > 0) - this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo())); - this.client.sendResponse(new PurchaseOKComposer(null)); this.client.sendResponse(new InventoryRefreshComposer()); 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 160f3e1a..454b5172 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 @@ -358,11 +358,10 @@ public class CatalogBuyItemAsGiftEvent extends MessageHandler { } if (totalPoints > 0) { if (item.getPointsType() == 0 && !this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_PIXELS)) { - this.client.getHabbo().getHabboInfo().addPixels(-totalPoints); + this.client.getHabbo().givePixels(-totalPoints); } else if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_POINTS)) { - this.client.getHabbo().getHabboInfo().addCurrencyAmount(item.getPointsType(), -totalPoints); + this.client.getHabbo().givePoints(item.getPointsType(), -totalPoints); } - this.client.sendResponse(new UserPointsComposer(this.client.getHabbo().getHabboInfo().getCurrencyAmount(item.getPointsType()), -totalPoints, item.getPointsType())); } this.client.sendResponse(new PurchaseOKComposer(item)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemEvent.java index 68a54353..1d6c06d1 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemEvent.java @@ -106,12 +106,10 @@ public class CatalogBuyItemEvent extends MessageHandler { } ((RoomBundleLayout) page).buyRoom(this.client.getHabbo()); if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) { //if the player has this perm disabled - this.client.getHabbo().getHabboInfo().addCredits(-roomBundleItem.getCredits()); // takes their credits away - this.client.sendResponse(new UserCreditsComposer(this.client.getHabbo())); // Sends the updated currency composer window + this.client.getHabbo().giveCredits(-roomBundleItem.getCredits()); // takes their credits away } if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_POINTS)) { //if the player has this perm disabled - this.client.getHabbo().getHabboInfo().addCurrencyAmount(roomBundleItem.getPointsType(), -roomBundleItem.getPoints()); // takes their points away - this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo())); // Sends the updated currency composer window + this.client.getHabbo().givePoints(roomBundleItem.getPointsType(), -roomBundleItem.getPoints()); // takes their points away } this.client.sendResponse(new PurchaseOKComposer()); // Sends the composer to close the window. @@ -176,10 +174,10 @@ public class CatalogBuyItemEvent extends MessageHandler { return; if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) - this.client.getHabbo().getHabboInfo().addCredits(-totalCredits); + this.client.getHabbo().giveCredits(-totalCredits); if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_POINTS)) - this.client.getHabbo().getHabboInfo().addCurrencyAmount(item.getPointsType(), -totalDuckets); + this.client.getHabbo().givePoints(item.getPointsType(), -totalDuckets); if(this.client.getHabbo().getHabboStats().createSubscription(Subscription.HABBO_CLUB, (totalDays * 86400)) == null) { @@ -195,12 +193,6 @@ public class CatalogBuyItemEvent extends MessageHandler { this.client.sendResponse(new UserPermissionsComposer(this.client.getHabbo())); this.client.sendResponse(new UserClubComposer(this.client.getHabbo()));*/ - if (totalCredits > 0) - this.client.sendResponse(new UserCreditsComposer(this.client.getHabbo())); - - if (totalDuckets > 0) - this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo())); - this.client.sendResponse(new PurchaseOKComposer(null)); this.client.sendResponse(new InventoryRefreshComposer()); 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 2a47300f..7a048f27 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 @@ -33,6 +33,7 @@ import com.eu.habbo.messages.outgoing.unknown.BuildersClubExpiredComposer; import com.eu.habbo.messages.outgoing.mysterybox.MysteryBoxKeysComposer; import com.eu.habbo.messages.outgoing.users.*; import com.eu.habbo.plugin.events.emulator.SSOAuthenticationEvent; +import com.eu.habbo.plugin.events.users.UserExecuteCommandEvent; import com.eu.habbo.plugin.events.users.UserLoginEvent; import gnu.trove.map.hash.THashMap; import org.slf4j.Logger; @@ -186,7 +187,13 @@ public class SecureLoginEvent extends MessageHandler { } } - Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getHabbo().getHabboInfo().getIpLogin())); + UserLoginEvent userLoginEvent = new UserLoginEvent(habbo, this.client.getHabbo().getHabboInfo().getIpLogin()); + Emulator.getPluginManager().fireEvent(userLoginEvent); + + if(userLoginEvent.isCancelled()) { + Emulator.getGameServer().getGameClientManager().disposeClient(this.client); + return; + } if (Emulator.getConfig().getBoolean("hotel.welcome.alert.enabled")) { final Habbo finalHabbo = habbo; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemItemEvent.java index fa5ce66b..096c158e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemItemEvent.java @@ -107,8 +107,7 @@ public class RedeemItemEvent extends MessageHandler { switch (furniRedeemEvent.currencyID) { case FurnitureRedeemedEvent.CREDITS: - this.client.getHabbo().getHabboInfo().addCredits(furniRedeemEvent.amount); - this.client.sendResponse(new UserCreditsComposer(this.client.getHabbo())); + this.client.getHabbo().giveCredits(furniRedeemEvent.amount); break; case FurnitureRedeemedEvent.DIAMONDS: @@ -116,8 +115,7 @@ public class RedeemItemEvent extends MessageHandler { break; case FurnitureRedeemedEvent.PIXELS: - this.client.getHabbo().getHabboInfo().addPixels(furniRedeemEvent.amount); - this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo())); + this.client.getHabbo().givePixels(furniRedeemEvent.amount); break; default: