Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/commands/PromoteTargetOfferCommand.java

73 lines
3.1 KiB
Java
Raw Normal View History

2018-10-07 00:28:00 +02:00
package com.eu.habbo.habbohotel.commands;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.catalog.TargetOffer;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.users.Habbo;
2019-03-18 02:22:00 +01:00
import com.eu.habbo.messages.outgoing.catalog.TargetedOfferComposer;
2019-05-26 20:14:53 +02:00
import com.eu.habbo.messages.outgoing.generic.alerts.MessagesForYouComposer;
2018-10-07 00:28:00 +02:00
import gnu.trove.map.hash.THashMap;
import java.util.ArrayList;
import java.util.List;
2019-05-26 20:14:53 +02:00
public class PromoteTargetOfferCommand extends Command {
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
public PromoteTargetOfferCommand() {
2018-10-07 00:28:00 +02:00
super("cmd_promote_offer", Emulator.getTexts().getValue("commands.keys.cmd_promote_offer").split(";"));
}
@Override
2019-05-26 20:14:53 +02:00
public boolean handle(GameClient gameClient, String[] params) throws Exception {
if (params.length <= 1) {
2018-10-07 00:28:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_promote_offer.not_found"));
return true;
}
String offerKey = params[1];
2019-05-26 20:14:53 +02:00
if (offerKey.equalsIgnoreCase(Emulator.getTexts().getValue("commands.cmd_promote_offer.info"))) {
2018-10-07 00:28:00 +02:00
THashMap<Integer, TargetOffer> targetOffers = Emulator.getGameEnvironment().getCatalogManager().targetOffers;
String[] textConfig = Emulator.getTexts().getValue("commands.cmd_promote_offer.list").replace("%amount%", targetOffers.size() + "").split("<br>");
String entryConfig = Emulator.getTexts().getValue("commands.cmd_promote_offer.list.entry");
2019-03-18 02:22:00 +01:00
List<String> message = new ArrayList<>();
2018-10-07 00:28:00 +02:00
2019-05-26 20:14:53 +02:00
for (String pair : textConfig) {
if (pair.contains("%list%")) {
for (TargetOffer offer : targetOffers.values()) {
2018-10-07 00:28:00 +02:00
message.add(entryConfig.replace("%id%", offer.getId() + "").replace("%title%", offer.getTitle()).replace("%description%", offer.getDescription().substring(0, 25)));
}
2019-05-26 20:14:53 +02:00
} else {
2019-03-18 02:22:00 +01:00
message.add(pair);
2018-10-07 00:28:00 +02:00
}
}
gameClient.sendResponse(new MessagesForYouComposer(message));
2019-05-26 20:14:53 +02:00
} else {
2018-10-07 00:28:00 +02:00
int offerId = 0;
2019-05-26 20:14:53 +02:00
try {
2018-10-07 00:28:00 +02:00
offerId = Integer.valueOf(offerKey);
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2018-10-07 00:28:00 +02:00
}
2019-05-26 20:14:53 +02:00
if (offerId > 0) {
2018-10-07 00:28:00 +02:00
TargetOffer offer = Emulator.getGameEnvironment().getCatalogManager().getTargetOffer(offerId);
2019-05-26 20:14:53 +02:00
if (offer != null) {
2018-10-07 00:28:00 +02:00
TargetOffer.ACTIVE_TARGET_OFFER_ID = offer.getId();
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_promote_offer").replace("%id%", offerKey).replace("%title%", offer.getTitle()));
2019-05-26 20:14:53 +02:00
for (Habbo habbo : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().values()) {
2018-10-07 00:28:00 +02:00
habbo.getClient().sendResponse(new TargetedOfferComposer(habbo, offer));
}
}
2019-05-26 20:14:53 +02:00
} else {
2018-10-07 00:28:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_promote_offer.not_found"));
return true;
}
}
return true;
}
}