2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.users;
|
|
|
|
|
|
|
|
import com.eu.habbo.habbohotel.catalog.marketplace.MarketPlace;
|
|
|
|
import com.eu.habbo.habbohotel.catalog.marketplace.MarketPlaceOffer;
|
|
|
|
import com.eu.habbo.habbohotel.catalog.marketplace.MarketPlaceState;
|
|
|
|
import com.eu.habbo.habbohotel.users.inventory.*;
|
|
|
|
import gnu.trove.set.hash.THashSet;
|
2020-05-04 22:24:09 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class HabboInventory {
|
2020-05-04 22:24:09 +02:00
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(HabboInventory.class);
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
//Configuration. Loaded from database & updated accordingly.
|
|
|
|
public static int MAXIMUM_ITEMS = 10000;
|
2019-05-26 20:14:53 +02:00
|
|
|
private final THashSet<MarketPlaceOffer> items;
|
|
|
|
private final Habbo habbo;
|
2018-07-06 15:30:00 +02:00
|
|
|
private WardrobeComponent wardrobeComponent;
|
|
|
|
private BadgesComponent badgesComponent;
|
|
|
|
private BotsComponent botsComponent;
|
|
|
|
private EffectsComponent effectsComponent;
|
|
|
|
private ItemsComponent itemsComponent;
|
|
|
|
private PetsComponent petsComponent;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public HabboInventory(Habbo habbo) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.habbo = habbo;
|
2019-05-26 20:14:53 +02:00
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.badgesComponent = new BadgesComponent(this.habbo);
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.botsComponent = new BotsComponent(this.habbo);
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.effectsComponent = new EffectsComponent(this.habbo);
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.itemsComponent = new ItemsComponent(this, this.habbo);
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.petsComponent = new PetsComponent(this.habbo);
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
try {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.wardrobeComponent = new WardrobeComponent(this.habbo);
|
2019-05-26 20:14:53 +02:00
|
|
|
} catch (Exception e) {
|
2020-05-04 22:24:09 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.items = MarketPlace.getOwnOffers(this.habbo);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WardrobeComponent getWardrobeComponent() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.wardrobeComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setWardrobeComponent(WardrobeComponent wardrobeComponent) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.wardrobeComponent = wardrobeComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public BadgesComponent getBadgesComponent() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.badgesComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setBadgesComponent(BadgesComponent badgesComponent) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.badgesComponent = badgesComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public BotsComponent getBotsComponent() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.botsComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setBotsComponent(BotsComponent botsComponent) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.botsComponent = botsComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public EffectsComponent getEffectsComponent() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.effectsComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setEffectsComponent(EffectsComponent effectsComponent) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.effectsComponent = effectsComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public ItemsComponent getItemsComponent() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.itemsComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setItemsComponent(ItemsComponent itemsComponent) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.itemsComponent = itemsComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public PetsComponent getPetsComponent() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.petsComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void setPetsComponent(PetsComponent petsComponent) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.petsComponent = petsComponent;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void dispose() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.badgesComponent.dispose();
|
|
|
|
this.botsComponent.dispose();
|
|
|
|
this.effectsComponent.dispose();
|
|
|
|
this.itemsComponent.dispose();
|
|
|
|
this.petsComponent.dispose();
|
|
|
|
this.wardrobeComponent.dispose();
|
|
|
|
|
|
|
|
this.badgesComponent = null;
|
|
|
|
this.botsComponent = null;
|
|
|
|
this.effectsComponent = null;
|
|
|
|
this.itemsComponent = null;
|
|
|
|
this.petsComponent = null;
|
|
|
|
this.wardrobeComponent = null;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void addMarketplaceOffer(MarketPlaceOffer marketPlaceOffer) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.items.add(marketPlaceOffer);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void removeMarketplaceOffer(MarketPlaceOffer marketPlaceOffer) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.items.remove(marketPlaceOffer);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public THashSet<MarketPlaceOffer> getMarketplaceItems() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.items;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getSoldPriceTotal() {
|
2018-07-06 15:30:00 +02:00
|
|
|
int i = 0;
|
2019-05-26 20:14:53 +02:00
|
|
|
for (MarketPlaceOffer offer : this.items) {
|
|
|
|
if (offer.getState().equals(MarketPlaceState.SOLD)) {
|
|
|
|
i += offer.getPrice();
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public MarketPlaceOffer getOffer(int id) {
|
2019-08-05 18:35:26 +02:00
|
|
|
synchronized (this.items) {
|
|
|
|
for (MarketPlaceOffer offer : this.items) {
|
|
|
|
if (offer.getOfferId() == id)
|
|
|
|
return offer;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public Habbo getHabbo() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.habbo;
|
|
|
|
}
|
|
|
|
}
|