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

60 lines
1.7 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class InteractionColorPlate extends InteractionDefault {
public InteractionColorPlate(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 InteractionColorPlate(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 onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
super.onWalkOn(roomUnit, room, objects);
this.change(room, 1);
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
2018-07-06 15:30:00 +02:00
super.onWalkOff(roomUnit, room, objects);
2019-03-18 02:22:00 +01:00
this.change(room, -1);
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
private void change(Room room, int amount) {
2018-07-06 15:30:00 +02:00
int state = 0;
2019-05-26 20:14:53 +02:00
if (this.getExtradata() == null || this.getExtradata().isEmpty()) {
2018-07-06 15:30:00 +02:00
this.setExtradata("0");
}
2019-05-26 20:14:53 +02:00
try {
2018-07-06 15:30:00 +02:00
state = Integer.valueOf(this.getExtradata());
2019-05-26 20:14:53 +02:00
} catch (Exception e) {
2018-07-06 15:30:00 +02:00
Emulator.getLogging().logErrorLine(e);
}
state += amount;
2019-05-26 20:14:53 +02:00
if (state > this.getBaseItem().getStateCount()) {
2018-07-06 15:30:00 +02:00
state = this.getBaseItem().getStateCount();
}
2019-05-26 20:14:53 +02:00
if (state < 0) {
2018-07-06 15:30:00 +02:00
state = 0;
}
this.setExtradata(state + "");
this.needsUpdate(true);
room.updateItemState(this);
}
}