Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java

87 lines
2.5 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions;
2020-10-13 03:42:30 +02:00
import com.eu.habbo.habbohotel.gameclients.GameClient;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.map.hash.THashMap;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
2019-05-26 20:14:53 +02:00
public abstract class InteractionCustomValues extends HabboItem {
2018-09-28 21:25:00 +02:00
public final THashMap<String, String> values = new THashMap<>();
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public InteractionCustomValues(ResultSet set, Item baseItem, THashMap<String, String> defaultValues) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set, baseItem);
this.values.putAll(defaultValues);
2019-05-26 20:14:53 +02:00
for (String s : set.getString("extra_data").split(";")) {
2018-07-06 15:30:00 +02:00
String[] data = s.split("=");
2019-05-26 20:14:53 +02:00
if (data.length == 2) {
2018-07-06 15:30:00 +02:00
this.values.put(data[0], data[1]);
}
}
}
2019-05-26 20:14:53 +02:00
public InteractionCustomValues(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, THashMap<String, String> defaultValues) {
2018-07-06 15:30:00 +02:00
super(id, userId, item, extradata, limitedStack, limitedSells);
this.values.putAll(defaultValues);
}
@Override
2019-05-26 20:14:53 +02:00
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
2018-07-06 15:30:00 +02:00
return false;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean isWalkable() {
2018-07-06 15:30:00 +02:00
return false;
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void run() {
2018-07-06 15:30:00 +02:00
this.setExtradata(this.toExtraData());
super.run();
}
2019-05-26 20:14:53 +02:00
public String toExtraData() {
2019-03-18 02:22:00 +01:00
StringBuilder data = new StringBuilder();
2019-05-26 20:14:53 +02:00
synchronized (this.values) {
for (Map.Entry<String, String> set : this.values.entrySet()) {
2019-03-18 02:22:00 +01:00
data.append(set.getKey()).append("=").append(set.getValue()).append(";");
2018-07-06 15:30:00 +02:00
}
}
2019-03-18 02:22:00 +01:00
return data.toString();
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void serializeExtradata(ServerMessage serverMessage) {
2018-07-06 15:30:00 +02:00
serverMessage.appendInt(1 + (this.isLimited() ? 256 : 0));
serverMessage.appendInt(this.values.size());
2019-05-26 20:14:53 +02:00
for (Map.Entry<String, String> set : this.values.entrySet()) {
2018-07-06 15:30:00 +02:00
serverMessage.appendString(set.getKey());
serverMessage.appendString(set.getValue());
}
super.serializeExtradata(serverMessage);
}
2020-10-13 03:42:30 +02:00
public void onCustomValuesSaved(Room room, GameClient client) {
}
2018-07-06 15:30:00 +02:00
}