Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java

180 lines
6.0 KiB
Java
Raw Normal View History

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;
2022-11-16 16:56:06 +01:00
import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings;
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.rooms.RoomChatMessage;
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
2020-11-16 12:12:24 +01:00
import com.eu.habbo.habbohotel.wired.WiredHandler;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
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 com.eu.habbo.threading.runnables.RoomUnitKick;
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 WiredEffectKickHabbo extends InteractionWiredEffect {
2018-07-06 15:30:00 +02:00
public static final WiredEffectType type = WiredEffectType.KICK_USER;
private String message = "";
2019-05-26 20:14:53 +02:00
public WiredEffectKickHabbo(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 WiredEffectKickHabbo(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 boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (room == null)
2018-07-06 15:30:00 +02:00
return false;
Habbo habbo = room.getHabbo(roomUnit);
2019-05-26 20:14:53 +02:00
if (habbo != null) {
if (habbo.hasPermission(Permission.ACC_UNKICKABLE)) {
2018-09-12 18:45:00 +02:00
habbo.whisper(Emulator.getTexts().getValue("hotel.wired.kickexception.unkickable"));
return true;
}
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if (habbo.getHabboInfo().getId() == room.getOwnerId()) {
2018-09-12 18:45:00 +02:00
habbo.whisper(Emulator.getTexts().getValue("hotel.wired.kickexception.owner"));
2018-07-06 15:30:00 +02:00
return true;
}
2018-09-12 18:45:00 +02:00
2019-03-18 02:22:00 +01:00
room.giveEffect(habbo, 4, 2);
2018-09-12 18:45:00 +02:00
2019-05-26 20:14:53 +02:00
if (!this.message.isEmpty())
2018-09-12 18:45:00 +02:00
habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(this.message, habbo, habbo, RoomChatMessageBubbles.ALERT)));
Emulator.getThreading().run(new RoomUnitKick(habbo, room, true), 2000);
return true;
2018-07-06 15:30:00 +02:00
}
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");
2018-07-06 15:30:00 +02:00
2020-11-16 12:12:24 +01:00
if(wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.message = data.message;
}
else {
try {
String[] data = set.getString("wired_data").split("\t");
if (data.length >= 1) {
this.setDelay(Integer.valueOf(data[0]));
2018-07-06 15:30:00 +02:00
2020-11-16 12:12:24 +01:00
if (data.length >= 2) {
this.message = data[1];
}
2018-07-06 15:30:00 +02:00
}
2020-11-16 12:12:24 +01:00
} catch (Exception e) {
this.message = "";
this.setDelay(0);
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 void serializeWiredData(ServerMessage message, Room room) {
2018-07-06 15:30:00 +02:00
message.appendBoolean(false);
message.appendInt(5);
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString(this.message);
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getType().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
2022-11-16 16:56:06 +01:00
public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException {
String message = settings.getStringParam();
int delay = settings.getDelay();
if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
throw new WiredSaveException("Delay too long");
this.message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
this.setDelay(delay);
2018-07-06 15:30:00 +02:00
return true;
}
@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
}