2018-07-06 13:30:00 +00:00
|
|
|
package com.eu.habbo.habbohotel.commands;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.core.CommandLog;
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
2018-09-12 16:45:00 +00:00
|
|
|
import com.eu.habbo.habbohotel.permissions.Permission;
|
|
|
|
import com.eu.habbo.habbohotel.permissions.PermissionSetting;
|
|
|
|
import com.eu.habbo.habbohotel.pets.Pet;
|
2018-07-06 13:30:00 +00:00
|
|
|
import com.eu.habbo.habbohotel.pets.PetCommand;
|
|
|
|
import com.eu.habbo.habbohotel.pets.PetVocalsType;
|
2019-05-04 07:40:24 +01:00
|
|
|
import com.eu.habbo.habbohotel.pets.RideablePet;
|
2018-07-06 13:30:00 +00:00
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTypingComposer;
|
|
|
|
import com.eu.habbo.plugin.events.users.UserCommandEvent;
|
|
|
|
import com.eu.habbo.plugin.events.users.UserExecuteCommandEvent;
|
|
|
|
import gnu.trove.iterator.TIntObjectIterator;
|
|
|
|
import gnu.trove.map.hash.THashMap;
|
2020-05-03 01:46:07 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.NoSuchElementException;
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public class CommandHandler {
|
2020-05-03 01:46:07 +02:00
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(CommandHandler.class);
|
|
|
|
|
2018-09-28 19:25:00 +00:00
|
|
|
private final static THashMap<String, Command> commands = new THashMap<>(5);
|
2019-05-26 21:14:53 +03:00
|
|
|
private static final Comparator<Command> ALPHABETICAL_ORDER = new Comparator<Command>() {
|
|
|
|
public int compare(Command c1, Command c2) {
|
|
|
|
int res = String.CASE_INSENSITIVE_ORDER.compare(c1.permission, c2.permission);
|
|
|
|
return (res != 0) ? res : c1.permission.compareTo(c2.permission);
|
|
|
|
}
|
|
|
|
};
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public CommandHandler() {
|
2018-07-06 13:30:00 +00:00
|
|
|
long millis = System.currentTimeMillis();
|
2019-03-18 01:22:00 +00:00
|
|
|
this.reloadCommands();
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.info("Command Handler -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)");
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public static void addCommand(Command command) {
|
|
|
|
if (command == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
commands.put(command.getClass().getName(), command);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void addCommand(Class<? extends Command> command) {
|
|
|
|
try {
|
|
|
|
//command.getConstructor().setAccessible(true);
|
|
|
|
addCommand(command.newInstance());
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.debug("Added command: {}", command.getName());
|
2019-05-26 21:14:53 +03:00
|
|
|
} catch (Exception e) {
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2019-05-26 21:14:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean handleCommand(GameClient gameClient, String commandLine) {
|
|
|
|
if (gameClient != null) {
|
|
|
|
if (commandLine.startsWith(":")) {
|
|
|
|
commandLine = commandLine.replaceFirst(":", "");
|
|
|
|
|
|
|
|
String[] parts = commandLine.split(" ");
|
|
|
|
|
|
|
|
if (parts.length >= 1) {
|
|
|
|
for (Command command : commands.values()) {
|
|
|
|
for (String s : command.keys) {
|
|
|
|
if (s.toLowerCase().equals(parts[0].toLowerCase())) {
|
|
|
|
boolean succes = false;
|
2020-06-05 04:12:49 -04:00
|
|
|
if (command.permission == null || gameClient.getHabbo().hasPermission(command.permission, gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && (gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasRights(gameClient.getHabbo())) || gameClient.getHabbo().hasPermission(Permission.ACC_PLACEFURNI) || (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboInfo().getCurrentRoom().getGuildId() > 0 && gameClient.getHabbo().getHabboInfo().getCurrentRoom().guildRightLevel(gameClient.getHabbo()) >= 2))) {
|
2019-05-26 21:14:53 +03:00
|
|
|
try {
|
|
|
|
Emulator.getPluginManager().fireEvent(new UserExecuteCommandEvent(gameClient.getHabbo(), command, parts));
|
|
|
|
|
|
|
|
if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null)
|
|
|
|
gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserTypingComposer(gameClient.getHabbo().getRoomUnit(), false).compose());
|
|
|
|
|
|
|
|
UserCommandEvent event = new UserCommandEvent(gameClient.getHabbo(), parts, command.handle(gameClient, parts));
|
|
|
|
Emulator.getPluginManager().fireEvent(event);
|
|
|
|
|
|
|
|
succes = event.succes;
|
|
|
|
} catch (Exception e) {
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.error("Caught exception", e);
|
2019-05-26 21:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gameClient.getHabbo().getHabboInfo().getRank().isLogCommands()) {
|
2020-05-03 01:46:07 +02:00
|
|
|
Emulator.getDatabaseLogger().store(new CommandLog(gameClient.getHabbo().getHabboInfo().getId(), command, commandLine, succes));
|
2019-05-26 21:14:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return succes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String[] args = commandLine.split(" ");
|
|
|
|
|
|
|
|
if (args.length <= 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) {
|
|
|
|
Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom();
|
|
|
|
|
|
|
|
if (room.getCurrentPets().isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TIntObjectIterator<Pet> petIterator = room.getCurrentPets().iterator();
|
|
|
|
|
|
|
|
for (int j = room.getCurrentPets().size(); j-- > 0; ) {
|
|
|
|
try {
|
|
|
|
petIterator.advance();
|
|
|
|
} catch (NoSuchElementException e) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Pet pet = petIterator.value();
|
|
|
|
|
|
|
|
if (pet != null) {
|
|
|
|
if (pet.getName().equalsIgnoreCase(args[0])) {
|
|
|
|
StringBuilder s = new StringBuilder();
|
|
|
|
|
|
|
|
for (int i = 1; i < args.length; i++) {
|
|
|
|
s.append(args[i]).append(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
s = new StringBuilder(s.substring(0, s.length() - 1));
|
|
|
|
|
|
|
|
for (PetCommand command : pet.getPetData().getPetCommands()) {
|
|
|
|
if (command.key.equalsIgnoreCase(s.toString())) {
|
|
|
|
if (pet instanceof RideablePet && ((RideablePet) pet).getRider() != null) {
|
|
|
|
if (((RideablePet) pet).getRider().getHabboInfo().getId() == gameClient.getHabbo().getHabboInfo().getId()) {
|
|
|
|
((RideablePet) pet).getRider().getHabboInfo().dismountPet();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command.level <= pet.getLevel())
|
|
|
|
pet.handleCommand(command, gameClient.getHabbo(), args);
|
|
|
|
else
|
|
|
|
pet.say(pet.getPetData().randomVocal(PetVocalsType.UNKNOWN_COMMAND));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Command getCommand(String key) {
|
|
|
|
for (Command command : commands.values()) {
|
|
|
|
for (String k : command.keys) {
|
|
|
|
if (key.equalsIgnoreCase(k)) {
|
|
|
|
return command;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reloadCommands() {
|
2018-07-06 13:30:00 +00:00
|
|
|
addCommand(new AboutCommand());
|
|
|
|
addCommand(new AlertCommand());
|
|
|
|
addCommand(new AllowTradingCommand());
|
|
|
|
addCommand(new ArcturusCommand());
|
|
|
|
addCommand(new BadgeCommand());
|
|
|
|
addCommand(new BanCommand());
|
|
|
|
addCommand(new BlockAlertCommand());
|
|
|
|
addCommand(new BotsCommand());
|
2018-09-12 16:45:00 +00:00
|
|
|
addCommand(new CalendarCommand());
|
2018-07-06 13:30:00 +00:00
|
|
|
addCommand(new ChangeNameCommand());
|
|
|
|
addCommand(new ChatTypeCommand());
|
|
|
|
addCommand(new CommandsCommand());
|
|
|
|
addCommand(new ConnectCameraCommand());
|
|
|
|
addCommand(new ControlCommand());
|
|
|
|
addCommand(new CoordsCommand());
|
|
|
|
addCommand(new CreditsCommand());
|
|
|
|
addCommand(new DiagonalCommand());
|
|
|
|
addCommand(new DisconnectCommand());
|
|
|
|
addCommand(new EjectAllCommand());
|
|
|
|
addCommand(new EmptyInventoryCommand());
|
|
|
|
addCommand(new EmptyBotsInventoryCommand());
|
|
|
|
addCommand(new EmptyPetsInventoryCommand());
|
|
|
|
addCommand(new EnableCommand());
|
|
|
|
addCommand(new EventCommand());
|
|
|
|
addCommand(new FacelessCommand());
|
|
|
|
addCommand(new FastwalkCommand());
|
2018-10-06 22:28:00 +00:00
|
|
|
addCommand(new FilterWordCommand());
|
2018-07-06 13:30:00 +00:00
|
|
|
addCommand(new FreezeBotsCommand());
|
|
|
|
addCommand(new FreezeCommand());
|
|
|
|
addCommand(new GiftCommand());
|
|
|
|
addCommand(new GiveRankCommand());
|
|
|
|
addCommand(new HabnamCommand());
|
|
|
|
addCommand(new HandItemCommand());
|
|
|
|
addCommand(new HappyHourCommand());
|
2018-09-28 19:25:00 +00:00
|
|
|
addCommand(new HideWiredCommand());
|
2018-07-06 13:30:00 +00:00
|
|
|
addCommand(new HotelAlertCommand());
|
|
|
|
addCommand(new HotelAlertLinkCommand());
|
2018-09-28 19:25:00 +00:00
|
|
|
addCommand(new InvisibleCommand());
|
2018-07-06 13:30:00 +00:00
|
|
|
addCommand(new IPBanCommand());
|
|
|
|
addCommand(new LayCommand());
|
|
|
|
addCommand(new MachineBanCommand());
|
|
|
|
addCommand(new MassBadgeCommand());
|
|
|
|
addCommand(new MassCreditsCommand());
|
|
|
|
addCommand(new MassGiftCommand());
|
|
|
|
addCommand(new MassPixelsCommand());
|
|
|
|
addCommand(new MassPointsCommand());
|
|
|
|
addCommand(new MimicCommand());
|
|
|
|
addCommand(new MoonwalkCommand());
|
|
|
|
addCommand(new MultiCommand());
|
|
|
|
addCommand(new MuteBotsCommand());
|
|
|
|
addCommand(new MuteCommand());
|
|
|
|
addCommand(new MutePetsCommand());
|
|
|
|
addCommand(new PetInfoCommand());
|
|
|
|
addCommand(new PickallCommand());
|
|
|
|
addCommand(new PixelCommand());
|
|
|
|
addCommand(new PluginsCommand());
|
|
|
|
addCommand(new PointsCommand());
|
2018-10-06 22:28:00 +00:00
|
|
|
addCommand(new PromoteTargetOfferCommand());
|
2018-07-06 13:30:00 +00:00
|
|
|
addCommand(new PullCommand());
|
|
|
|
addCommand(new PushCommand());
|
|
|
|
addCommand(new RedeemCommand());
|
|
|
|
addCommand(new ReloadRoomCommand());
|
|
|
|
addCommand(new RoomAlertCommand());
|
|
|
|
addCommand(new RoomBundleCommand());
|
|
|
|
addCommand(new RoomCreditsCommand());
|
|
|
|
addCommand(new RoomDanceCommand());
|
|
|
|
addCommand(new RoomEffectCommand());
|
|
|
|
addCommand(new RoomItemCommand());
|
|
|
|
addCommand(new RoomKickCommand());
|
|
|
|
addCommand(new RoomMuteCommand());
|
|
|
|
addCommand(new RoomPixelsCommand());
|
|
|
|
addCommand(new RoomPointsCommand());
|
|
|
|
addCommand(new SayAllCommand());
|
|
|
|
addCommand(new SayCommand());
|
|
|
|
addCommand(new SetMaxCommand());
|
|
|
|
addCommand(new SetPollCommand());
|
|
|
|
addCommand(new SetSpeedCommand());
|
|
|
|
addCommand(new ShoutAllCommand());
|
|
|
|
addCommand(new ShoutCommand());
|
|
|
|
addCommand(new ShutdownCommand());
|
|
|
|
addCommand(new SitCommand());
|
2020-03-13 17:00:48 +00:00
|
|
|
addCommand(new StandCommand());
|
2018-07-06 13:30:00 +00:00
|
|
|
addCommand(new SitDownCommand());
|
|
|
|
addCommand(new StaffAlertCommand());
|
|
|
|
addCommand(new StaffOnlineCommand());
|
|
|
|
addCommand(new StalkCommand());
|
|
|
|
addCommand(new SummonCommand());
|
|
|
|
addCommand(new SummonRankCommand());
|
|
|
|
addCommand(new SuperbanCommand());
|
|
|
|
addCommand(new SuperPullCommand());
|
|
|
|
addCommand(new TakeBadgeCommand());
|
|
|
|
addCommand(new TeleportCommand());
|
|
|
|
addCommand(new TransformCommand());
|
|
|
|
addCommand(new TrashCommand());
|
|
|
|
addCommand(new UnbanCommand());
|
|
|
|
addCommand(new UnloadRoomCommand());
|
|
|
|
addCommand(new UnmuteCommand());
|
2019-04-21 23:42:00 +00:00
|
|
|
addCommand(new UpdateAchievements());
|
2018-07-06 13:30:00 +00:00
|
|
|
addCommand(new UpdateBotsCommand());
|
|
|
|
addCommand(new UpdateCatalogCommand());
|
|
|
|
addCommand(new UpdateConfigCommand());
|
|
|
|
addCommand(new UpdateGuildPartsCommand());
|
|
|
|
addCommand(new UpdateHotelViewCommand());
|
|
|
|
addCommand(new UpdateItemsCommand());
|
|
|
|
addCommand(new UpdateNavigatorCommand());
|
|
|
|
addCommand(new UpdatePermissionsCommand());
|
|
|
|
addCommand(new UpdatePetDataCommand());
|
|
|
|
addCommand(new UpdatePluginsCommand());
|
|
|
|
addCommand(new UpdatePollsCommand());
|
|
|
|
addCommand(new UpdateTextsCommand());
|
|
|
|
addCommand(new UpdateWordFilterCommand());
|
|
|
|
addCommand(new UserInfoCommand());
|
|
|
|
addCommand(new WordQuizCommand());
|
2019-06-16 14:44:20 +03:00
|
|
|
addCommand(new UpdateYoutubePlaylistsCommand());
|
|
|
|
addCommand(new AddYoutubePlaylistCommand());
|
2020-05-16 15:35:20 +02:00
|
|
|
addCommand(new SoftKickCommand());
|
2020-10-04 00:25:55 +02:00
|
|
|
addCommand(new SubscriptionCommand());
|
2018-07-06 13:30:00 +00:00
|
|
|
|
|
|
|
addCommand(new TestCommand());
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public List<Command> getCommandsForRank(int rankId) {
|
2018-09-28 19:25:00 +00:00
|
|
|
List<Command> allowedCommands = new ArrayList<>();
|
2019-05-26 21:14:53 +03:00
|
|
|
if (Emulator.getGameEnvironment().getPermissionsManager().rankExists(rankId)) {
|
2018-09-12 16:45:00 +00:00
|
|
|
THashMap<String, Permission> permissions = Emulator.getGameEnvironment().getPermissionsManager().getRank(rankId).getPermissions();
|
2018-07-06 13:30:00 +00:00
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
for (Command command : commands.values()) {
|
2018-07-06 13:30:00 +00:00
|
|
|
if (allowedCommands.contains(command))
|
|
|
|
continue;
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
if (permissions.contains(command.permission) && permissions.get(command.permission).setting != PermissionSetting.DISALLOWED) {
|
2018-07-06 13:30:00 +00:00
|
|
|
allowedCommands.add(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 01:22:00 +00:00
|
|
|
allowedCommands.sort(CommandHandler.ALPHABETICAL_ORDER);
|
2018-07-06 13:30:00 +00:00
|
|
|
|
|
|
|
return allowedCommands;
|
|
|
|
}
|
|
|
|
|
2019-05-26 21:14:53 +03:00
|
|
|
public void dispose() {
|
2018-07-06 13:30:00 +00:00
|
|
|
commands.clear();
|
2020-05-03 01:46:07 +02:00
|
|
|
LOGGER.info("Command Handler -> Disposed!");
|
2018-07-06 13:30:00 +00:00
|
|
|
}
|
|
|
|
}
|