Arcturus-Community/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/BotSaveSettingsEvent.java

181 lines
7.4 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.messages.incoming.rooms.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.bots.BotManager;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.habbohotel.permissions.Permission;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.messages.incoming.MessageHandler;
2018-09-28 21:25:00 +02:00
import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.outgoing.rooms.users.RoomUnitUpdateUsernameComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDanceComposer;
2018-09-28 21:25:00 +02:00
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.plugin.events.bots.BotSavedChatEvent;
import com.eu.habbo.plugin.events.bots.BotSavedLookEvent;
import com.eu.habbo.plugin.events.bots.BotSavedNameEvent;
import org.jsoup.Jsoup;
import java.util.ArrayList;
public class BotSaveSettingsEvent extends MessageHandler
{
@Override
public void handle() throws Exception
{
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
if(room == null)
return;
2018-09-12 18:45:00 +02:00
if(room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER))
2018-07-06 15:30:00 +02:00
{
int botId = this.packet.readInt();
Bot bot = room.getBot(Math.abs(botId));
if(bot == null)
return;
int settingId = this.packet.readInt();
switch(settingId)
{
case 1:
BotSavedLookEvent lookEvent = new BotSavedLookEvent(bot,
this.client.getHabbo().getHabboInfo().getGender(),
this.client.getHabbo().getHabboInfo().getLook(),
this.client.getHabbo().getRoomUnit().getEffectId());
Emulator.getPluginManager().fireEvent(lookEvent);
if(lookEvent.isCancelled())
break;
bot.setFigure(lookEvent.newLook);
bot.setGender(lookEvent.gender);
bot.setEffect(lookEvent.effect);
bot.needsUpdate(true);
break;
case 2:
String messageString = this.packet.readString();
if(messageString.length() > 5112)
break;
String[] data = messageString.split(";#;");
2018-09-28 21:25:00 +02:00
ArrayList<String> chat = new ArrayList<>();
int totalChatLength = 0;
for(int i = 0; i < data.length - 3 && totalChatLength <= 120; i++)
2018-07-06 15:30:00 +02:00
{
for(String s : data[i].split("\r"))
{
2018-09-28 21:25:00 +02:00
String filtered = Jsoup.parse(s).text();
int count = 0;
while (!filtered.equalsIgnoreCase(s))
{
if (count >=5){ bot.clearChat(); return; }
s = filtered;
filtered = Jsoup.parse(s).text();
count++;
}
String result = Emulator.getGameEnvironment().getWordFilter().filter(s, null);
2018-09-12 18:45:00 +02:00
2018-09-28 21:25:00 +02:00
if (!result.isEmpty())
2018-09-12 18:45:00 +02:00
{
2018-09-28 21:25:00 +02:00
if (!this.client.getHabbo().hasPermission("acc_chat_no_filter"))
{
result = Emulator.getGameEnvironment().getWordFilter().filter(result, this.client.getHabbo());
}
result = result.substring(0, Math.min(BotManager.MAXIMUM_CHAT_LENGTH - totalChatLength, result.length()));
chat.add(result);
totalChatLength += result.length();
2018-09-12 18:45:00 +02:00
}
2018-07-06 15:30:00 +02:00
}
}
2018-09-28 21:25:00 +02:00
int chatSpeed = 7;
try
2018-07-06 15:30:00 +02:00
{
2018-09-28 21:25:00 +02:00
chatSpeed = Integer.valueOf(data[data.length - 2]);
if (chatSpeed < BotManager.MINIMUM_CHAT_SPEED)
{
chatSpeed = BotManager.MINIMUM_CHAT_SPEED;
}
}
catch (Exception e)
{
//Invalid chatspeed. Use 7.
2018-07-06 15:30:00 +02:00
}
BotSavedChatEvent chatEvent = new BotSavedChatEvent(bot, Boolean.valueOf(data[data.length - 3]), Boolean.valueOf(data[data.length - 1]), chatSpeed, chat);
Emulator.getPluginManager().fireEvent(chatEvent);
if(chatEvent.isCancelled())
break;
bot.setChatAuto(chatEvent.autoChat);
bot.setChatRandom(chatEvent.randomChat);
bot.setChatDelay((short) chatEvent.chatDelay);
bot.clearChat();
bot.addChatLines(chat);
bot.needsUpdate(true);
break;
case 3:
bot.getRoomUnit().setCanWalk(!bot.getRoomUnit().canWalk());
bot.needsUpdate(true);
break;
case 4:
bot.getRoomUnit().setDanceType(DanceType.values()[(bot.getRoomUnit().getDanceType().getType() + 1) %DanceType.values().length]);
room.sendComposer(new RoomUserDanceComposer(bot.getRoomUnit()).compose());
bot.needsUpdate(true);
break;
case 5:
2018-09-28 21:25:00 +02:00
String name = this.packet.readString();
boolean invalidName = name.length() > BotManager.MAXIMUM_NAME_LENGTH;
if (!invalidName)
2018-07-06 15:30:00 +02:00
{
2018-09-28 21:25:00 +02:00
String filteredName = Emulator.getGameEnvironment().getWordFilter().filter(Jsoup.parse(name).text(), null);
invalidName = !name.equalsIgnoreCase(filteredName);
if (!invalidName)
{
BotSavedNameEvent nameEvent = new BotSavedNameEvent(bot, name);
Emulator.getPluginManager().fireEvent(nameEvent);
2018-07-06 15:30:00 +02:00
2018-09-28 21:25:00 +02:00
if (nameEvent.isCancelled())
break;
bot.setName(nameEvent.name);
bot.needsUpdate(true);
room.sendComposer(new RoomUnitUpdateUsernameComposer(bot.getRoomUnit(), nameEvent.name).compose());
}
}
2018-07-06 15:30:00 +02:00
2018-09-28 21:25:00 +02:00
if (invalidName)
{
this.client.sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_NAME_NOT_ACCEPT));
2018-07-06 15:30:00 +02:00
}
break;
2018-09-28 21:25:00 +02:00
case 9:
bot.setMotto(this.packet.readString());
bot.needsUpdate(true);
room.sendComposer(new RoomUsersComposer(bot).compose());
break;
2018-07-06 15:30:00 +02:00
}
if(bot.needsUpdate())
{
Emulator.getThreading().run(bot);
}
}
}
}