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

139 lines
3.5 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 com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.items.ItemStateComposer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public abstract class InteractionWired extends HabboItem
{
2018-07-08 23:32:00 +02:00
private long cooldown;
2018-07-06 15:30:00 +02:00
InteractionWired(ResultSet set, Item baseItem) throws SQLException
{
super(set, baseItem);
this.setExtradata("0");
2018-07-06 15:30:00 +02:00
}
InteractionWired(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells)
{
super(id, userId, item, extradata, limitedStack, limitedSells);
this.setExtradata("0");
2018-07-06 15:30:00 +02:00
}
public abstract boolean execute(RoomUnit roomUnit, Room room, Object[] stuff);
2019-03-18 02:22:00 +01:00
public abstract String getWiredData();
2018-07-06 15:30:00 +02:00
public abstract void serializeWiredData(ServerMessage message, Room room);
public abstract void loadWiredData(ResultSet set, Room room) throws SQLException;
@Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception
{
super.onWalkOn(roomUnit, room, objects);
}
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception
{
super.onWalkOff(roomUnit, room, objects);
}
@Override
public void serializeExtradata(ServerMessage serverMessage)
{
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage);
}
@Override
public void run()
{
if(this.needsUpdate())
{
String wiredData = this.getWiredData();
if (wiredData == null)
{
wiredData = "";
}
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE items SET wired_data = ? WHERE id = ?"))
{
if(this.getRoomId() != 0)
{
statement.setString(1, wiredData);
}
else
{
statement.setString(1, "");
}
statement.setInt(2, this.getId());
statement.execute();
}
catch (SQLException e)
{
Emulator.getLogging().logSQLException(e);
}
}
super.run();
}
@Override
public void onPickUp(Room room)
{
2019-03-18 02:22:00 +01:00
this.onPickUp();
2018-07-06 15:30:00 +02:00
}
public abstract void onPickUp();
public void activateBox(Room room)
{
this.setExtradata(this.getExtradata().equals("1") ? "0" : "1");
room.sendComposer(new ItemStateComposer(this).compose());
}
2018-07-08 23:32:00 +02:00
protected long requiredCooldown()
{
2019-05-16 11:15:33 +02:00
return 50L;
2018-07-08 23:32:00 +02:00
}
public boolean canExecute(long newMillis)
{
2019-03-18 02:22:00 +01:00
return newMillis - this.cooldown >= this.requiredCooldown();
2018-07-08 23:32:00 +02:00
}
2018-10-07 00:28:00 +02:00
2018-12-22 11:39:00 +01:00
public void setCooldown(long newMillis)
{
this.cooldown = newMillis;
}
2019-03-18 02:22:00 +01:00
2018-11-17 14:28:00 +01:00
@Override
public boolean allowWiredResetState()
{
return false;
}
2018-10-07 00:28:00 +02:00
@Override
public boolean isUsable()
{
return true;
}
2018-07-06 15:30:00 +02:00
}