2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
|
|
|
|
|
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
|
|
|
|
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
|
2020-10-12 11:18:52 +02:00
|
|
|
import com.eu.habbo.habbohotel.permissions.Permission;
|
2020-11-16 12:12:24 +01:00
|
|
|
import com.eu.habbo.habbohotel.rooms.*;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
2020-11-16 12:12:24 +01:00
|
|
|
import com.eu.habbo.habbohotel.wired.WiredChangeDirectionSetting;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.wired.WiredEffectType;
|
2020-10-12 11:18:52 +02:00
|
|
|
import com.eu.habbo.habbohotel.wired.WiredHandler;
|
|
|
|
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.messages.ClientMessage;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
2020-10-12 11:18:52 +02:00
|
|
|
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
|
|
|
|
import gnu.trove.procedure.TObjectProcedure;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class WiredEffectWhisper extends InteractionWiredEffect {
|
2018-07-06 15:30:00 +02:00
|
|
|
public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE;
|
|
|
|
|
|
|
|
protected String message = "";
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectWhisper(ResultSet set, Item baseItem) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set, baseItem);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectWhisper(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void serializeWiredData(ServerMessage message, Room room) {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendBoolean(false);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(this.getBaseItem().getSpriteId());
|
|
|
|
message.appendInt(this.getId());
|
|
|
|
message.appendString(this.message);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(0);
|
|
|
|
message.appendInt(type.code);
|
|
|
|
message.appendInt(this.getDelay());
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.requiresTriggeringUser()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
List<Integer> invalidTriggers = new ArrayList<>();
|
2019-05-26 20:14:53 +02:00
|
|
|
room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(new TObjectProcedure<InteractionWiredTrigger>() {
|
2018-07-06 15:30:00 +02:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean execute(InteractionWiredTrigger object) {
|
|
|
|
if (!object.isTriggeredByRoomUnit()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
invalidTriggers.add(object.getBaseItem().getSpriteId());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
message.appendInt(invalidTriggers.size());
|
2019-05-26 20:14:53 +02:00
|
|
|
for (Integer i : invalidTriggers) {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(i);
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
2018-07-06 15:30:00 +02:00
|
|
|
message.appendInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-12 11:18:52 +02:00
|
|
|
public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
|
2018-07-06 15:30:00 +02:00
|
|
|
packet.readInt();
|
|
|
|
|
2020-10-12 11:18:52 +02:00
|
|
|
String message = packet.readString();
|
|
|
|
|
|
|
|
if(gameClient.getHabbo() == null || !gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) {
|
|
|
|
message = Emulator.getGameEnvironment().getWordFilter().filter(message, null);
|
|
|
|
message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
|
2018-12-22 11:39:00 +01:00
|
|
|
}
|
2020-10-12 11:18:52 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
packet.readInt();
|
2020-10-12 11:18:52 +02:00
|
|
|
|
|
|
|
int delay = packet.readInt();
|
|
|
|
|
|
|
|
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
|
|
|
|
throw new WiredSaveException("Delay too long");
|
|
|
|
|
|
|
|
this.message = message;
|
|
|
|
this.setDelay(delay);
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
|
|
|
|
if (this.message.length() > 0) {
|
|
|
|
if (roomUnit != null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
Habbo habbo = room.getHabbo(roomUnit);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (habbo != null) {
|
2020-10-12 11:18:52 +02:00
|
|
|
String msg = this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + "");
|
|
|
|
habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(msg, habbo, habbo, RoomChatMessageBubbles.WIRED)));
|
|
|
|
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, roomUnit, room, new Object[]{ msg }));
|
2019-05-26 20:34:40 +02:00
|
|
|
|
|
|
|
if (habbo.getRoomUnit().isIdle()) {
|
|
|
|
habbo.getRoomUnit().getRoom().unIdle(habbo);
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
} else {
|
|
|
|
for (Habbo h : room.getHabbos()) {
|
2019-03-18 02:22:00 +01:00
|
|
|
h.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(this.message.replace("%user%", h.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), h, h, RoomChatMessageBubbles.WIRED)));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getWiredData() {
|
2020-11-16 12:12:24 +01:00
|
|
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay()));
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
2020-11-16 12:12:24 +01:00
|
|
|
String wiredData = set.getString("wired_data");
|
|
|
|
|
|
|
|
if(wiredData.startsWith("{")) {
|
|
|
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
|
|
|
this.setDelay(data.delay);
|
|
|
|
this.message = data.message;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.message = "";
|
|
|
|
|
|
|
|
if (wiredData.split("\t").length >= 2) {
|
|
|
|
super.setDelay(Integer.valueOf(wiredData.split("\t")[0]));
|
|
|
|
this.message = wiredData.split("\t")[1];
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2020-11-16 12:12:24 +01:00
|
|
|
this.needsUpdate(true);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onPickUp() {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.message = "";
|
|
|
|
this.setDelay(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public WiredEffectType getType() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean requiresTriggeringUser() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-11-16 12:12:24 +01:00
|
|
|
|
|
|
|
static class JsonData {
|
|
|
|
String message;
|
|
|
|
int delay;
|
|
|
|
|
|
|
|
public JsonData(String message, int delay) {
|
|
|
|
this.message = message;
|
|
|
|
this.delay = delay;
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|