Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java

103 lines
2.8 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
2019-04-22 01:42:00 +02:00
import com.eu.habbo.Emulator;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionDateRangeActive extends InteractionWiredCondition
{
public static final WiredConditionType type = WiredConditionType.DATE_RANGE;
2019-04-22 01:42:00 +02:00
private int startDate;
private int endDate;
2018-07-06 15:30:00 +02:00
public WiredConditionDateRangeActive(ResultSet set, Item baseItem) throws SQLException
{
super(set, baseItem);
}
public WiredConditionDateRangeActive(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
{
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public WiredConditionType getType()
{
return type;
}
@Override
public void serializeWiredData(ServerMessage message, Room room)
{
message.appendBoolean(false);
message.appendInt(5);
message.appendInt(0);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString("");
2019-04-22 01:42:00 +02:00
message.appendInt(2);
message.appendInt(this.startDate);
message.appendInt(this.endDate);
2018-07-06 15:30:00 +02:00
message.appendInt(0);
message.appendInt(this.getType().code);
2019-04-22 01:42:00 +02:00
message.appendInt(this.startDate);
message.appendInt(this.endDate);
2018-07-06 15:30:00 +02:00
}
@Override
public boolean saveData(ClientMessage packet)
{
2019-04-22 01:42:00 +02:00
packet.readInt();
this.startDate = packet.readInt();
this.endDate = packet.readInt();
return true;
2018-07-06 15:30:00 +02:00
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff)
{
2019-04-22 01:42:00 +02:00
int time = Emulator.getIntUnixTimestamp();
return this.startDate < time && this.endDate >= time;
2018-07-06 15:30:00 +02:00
}
@Override
2019-03-18 02:22:00 +01:00
public String getWiredData()
2018-07-06 15:30:00 +02:00
{
2019-04-22 01:42:00 +02:00
return this.startDate + "\t" + this.endDate;
2018-07-06 15:30:00 +02:00
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException
{
2019-04-22 01:42:00 +02:00
String[] data = set.getString("wired_data").split("\t");
2018-07-06 15:30:00 +02:00
2019-04-22 01:42:00 +02:00
if (data.length == 2)
{
try
{
this.startDate = Integer.valueOf(data[0]);
this.endDate = Integer.valueOf(data[1]);
}
catch (Exception e)
{
}
}
2018-07-06 15:30:00 +02:00
}
@Override
public void onPickUp()
{
2019-04-22 01:42:00 +02:00
this.startDate = 0;
this.endDate = 0;
2018-07-06 15:30:00 +02:00
}
}