2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.commands;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
|
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
2019-03-18 02:22:00 +01:00
|
|
|
import com.eu.habbo.messages.outgoing.wired.WiredRewardAlertComposer;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
|
|
|
|
|
|
|
|
public class RoomGiftCommand extends Command
|
|
|
|
{
|
|
|
|
public RoomGiftCommand()
|
|
|
|
{
|
|
|
|
super("cmd_roomgift", Emulator.getTexts().getValue("commands.keys.cmd_roomgift").split(";"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean handle(final GameClient gameClient, String[] params) throws Exception
|
|
|
|
{
|
|
|
|
if(params.length >= 2)
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
int itemId;
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
try
|
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
itemId = Integer.valueOf(params[1]);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_gift.not_a_number"), RoomChatMessageBubbles.ALERT);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
if(itemId <= 0)
|
|
|
|
{
|
|
|
|
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_gift.not_a_number"), RoomChatMessageBubbles.ALERT);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
final Item baseItem = Emulator.getGameEnvironment().getItemManager().getItem(itemId);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
if(baseItem == null)
|
|
|
|
{
|
|
|
|
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_gift.not_found").replace("%itemid%", itemId + ""), RoomChatMessageBubbles.ALERT);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
StringBuilder message = new StringBuilder();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
if(params.length > 2)
|
|
|
|
{
|
|
|
|
for (int i = 2; i < params.length; i++)
|
2018-07-06 15:30:00 +02:00
|
|
|
{
|
2019-03-18 02:22:00 +01:00
|
|
|
message.append(params[i]).append(" ");
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2019-03-18 02:22:00 +01:00
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
final String finalMessage = message.toString();
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
for (Habbo habbo : gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbos())
|
|
|
|
{
|
|
|
|
HabboItem item = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, 0, 0, "");
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
Item giftItem = Emulator.getGameEnvironment().getItemManager().getItem((Integer) Emulator.getGameEnvironment().getCatalogManager().giftFurnis.values().toArray()[Emulator.getRandom().nextInt(Emulator.getGameEnvironment().getCatalogManager().giftFurnis.size())]);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
String extraData = "1\t" + item.getId();
|
|
|
|
extraData += "\t0\t0\t0\t"+ finalMessage +"\t0\t0";
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
Emulator.getGameEnvironment().getItemManager().createGift(habbo.getHabboInfo().getUsername(), giftItem, extraData, 0, 0);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
habbo.getClient().sendResponse(new InventoryRefreshComposer());
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-03-18 02:22:00 +01:00
|
|
|
habbo.getClient().sendResponse(new WiredRewardAlertComposer(WiredRewardAlertComposer.REWARD_RECEIVED_ITEM));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
2019-03-18 02:22:00 +01:00
|
|
|
|
|
|
|
return true;
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|