2018-07-06 13:30:00 +00: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.HabboInfo;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboManager;
|
|
|
|
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
|
|
|
|
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
|
|
|
|
import gnu.trove.map.hash.THashMap;
|
|
|
|
|
|
|
|
public class GiftCommand extends Command
|
|
|
|
{
|
|
|
|
public GiftCommand()
|
|
|
|
{
|
|
|
|
super("cmd_gift", Emulator.getTexts().getValue("commands.keys.cmd_gift").split(";"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean handle(GameClient gameClient, String[] params) throws Exception
|
|
|
|
{
|
|
|
|
if(params.length >= 3)
|
|
|
|
{
|
2019-03-18 01:22:00 +00:00
|
|
|
String username = params[1];
|
|
|
|
int itemId;
|
|
|
|
|
2018-07-06 13:30:00 +00:00
|
|
|
try
|
|
|
|
{
|
2019-03-18 01:22:00 +00:00
|
|
|
itemId = Integer.valueOf(params[2]);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_gift.not_a_number"), RoomChatMessageBubbles.ALERT);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
if(itemId <= 0)
|
|
|
|
{
|
|
|
|
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_gift.not_a_number"), RoomChatMessageBubbles.ALERT);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
Item baseItem = Emulator.getGameEnvironment().getItemManager().getItem(itemId);
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00: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 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(username);
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
if(habboInfo == null)
|
|
|
|
{
|
|
|
|
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_gift.user_not_found").replace("%username%", username), RoomChatMessageBubbles.ALERT);
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
StringBuilder message = new StringBuilder();
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
if(params.length > 3)
|
|
|
|
{
|
|
|
|
for (int i = 3; i < params.length; i++)
|
2018-07-06 13:30:00 +00:00
|
|
|
{
|
2019-03-18 01:22:00 +00:00
|
|
|
message.append(params[i]).append(" ");
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
2019-03-18 01:22:00 +00:00
|
|
|
}
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
final String finalMessage = message.toString();
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
HabboItem item = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, 0, 0, "");
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00: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 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
String extraData = "1\t" + item.getId();
|
|
|
|
extraData += "\t0\t0\t0\t"+ finalMessage +"\t0\t0";
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
Emulator.getGameEnvironment().getItemManager().createGift(username, giftItem, extraData, 0, 0);
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_gift").replace("%username%", username).replace("%itemname%", item.getBaseItem().getName()), RoomChatMessageBubbles.ALERT);
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(habboInfo.getId());
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
if (habbo != null)
|
2018-07-06 13:30:00 +00:00
|
|
|
{
|
2019-03-18 01:22:00 +00:00
|
|
|
habbo.getClient().sendResponse(new InventoryRefreshComposer());
|
|
|
|
|
|
|
|
THashMap<String, String> keys = new THashMap<>();
|
|
|
|
keys.put("display", "BUBBLE");
|
|
|
|
keys.put("image", "${image.library.url}notifications/gift.gif");
|
|
|
|
keys.put("message", Emulator.getTexts().getValue("generic.gift.received.anonymous"));
|
|
|
|
habbo.getClient().sendResponse(new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys));
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
2019-03-18 01:22:00 +00:00
|
|
|
return true;
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|