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

68 lines
2.9 KiB
Java
Raw Normal View History

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.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboBadge;
2022-04-15 02:19:50 +02:00
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.habbohotel.users.HabboManager;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.users.inventory.BadgesComponent;
import com.eu.habbo.messages.outgoing.inventory.InventoryBadgesComposer;
2018-12-22 11:39:00 +01:00
import com.eu.habbo.messages.outgoing.users.UserBadgesComposer;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class TakeBadgeCommand extends Command {
public TakeBadgeCommand() {
2018-07-06 15:30:00 +02:00
super("cmd_take_badge", Emulator.getTexts().getValue("commands.keys.cmd_take_badge").split(";"));
}
@Override
2019-05-26 20:14:53 +02:00
public boolean handle(GameClient gameClient, String[] params) throws Exception {
if (params.length == 2) {
2018-07-06 15:30:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_take_badge.forgot_badge"), RoomChatMessageBubbles.ALERT);
return true;
2019-05-26 20:14:53 +02:00
} else if (params.length == 1) {
2018-07-06 15:30:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_take_badge.forgot_username"), RoomChatMessageBubbles.ALERT);
return true;
}
2019-05-26 20:14:53 +02:00
if (params.length == 3) {
2018-07-06 15:30:00 +02:00
String username = params[1];
String badge = params[2];
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(username);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
2018-07-06 15:30:00 +02:00
HabboBadge b = habbo.getInventory().getBadgesComponent().removeBadge(badge);
2019-05-26 20:14:53 +02:00
if (b == null) {
2018-07-06 15:30:00 +02:00
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_take_badge.no_badge").replace("%username%", username).replace("%badge%", badge), RoomChatMessageBubbles.ALERT);
return true;
}
habbo.getClient().sendResponse(new InventoryBadgesComposer(habbo));
2019-05-26 20:14:53 +02:00
if (habbo.getHabboInfo().getCurrentRoom() != null) {
2018-12-22 11:39:00 +01:00
habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserBadgesComposer(habbo.getInventory().getBadgesComponent().getWearingBadges(), habbo.getHabboInfo().getId()).compose());
}
2018-07-06 15:30:00 +02:00
}
2022-04-15 02:29:06 +02:00
int userId = 0;
2018-07-06 15:30:00 +02:00
2022-04-15 02:29:06 +02:00
if (habbo != null)
userId = habbo.getHabboInfo().getId();
else {
HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(username);
if (habboInfo != null)
userId = habboInfo.getId();
}
if (userId > 0) {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_take_badge"), RoomChatMessageBubbles.ALERT);
BadgesComponent.deleteBadge(userId, badge);
}
2018-07-06 15:30:00 +02:00
}
return true;
}
}