Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java

70 lines
2.2 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.pets;
import com.eu.habbo.Emulator;
2020-05-04 22:24:09 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2018-07-06 15:30:00 +02:00
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-05-26 20:14:53 +02:00
public class HorsePet extends RideablePet {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory.getLogger(HorsePet.class);
2018-07-06 15:30:00 +02:00
private int hairColor;
private int hairStyle;
2019-05-26 20:14:53 +02:00
public HorsePet(ResultSet set) throws SQLException {
2018-07-06 15:30:00 +02:00
super(set);
this.hairColor = set.getInt("hair_color");
this.hairStyle = set.getInt("hair_style");
this.hasSaddle(set.getString("saddle").equalsIgnoreCase("1"));
this.setAnyoneCanRide(set.getString("ride").equalsIgnoreCase("1"));
2020-02-04 22:04:41 +01:00
this.setSaddleItemId(set.getInt("saddle_item_id"));
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public HorsePet(int type, int race, String color, String name, int userId) {
2018-07-06 15:30:00 +02:00
super(type, race, color, name, userId);
this.hairColor = 0;
this.hairStyle = -1;
this.hasSaddle(false);
this.setAnyoneCanRide(false);
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void run() {
if (this.needsUpdate) {
2020-02-04 22:04:41 +01:00
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET hair_style = ?, hair_color = ?, saddle = ?, ride = ?, saddle_item_id = ? WHERE id = ?")) {
2018-07-06 15:30:00 +02:00
statement.setInt(1, this.hairStyle);
statement.setInt(2, this.hairColor);
statement.setString(3, this.hasSaddle() ? "1" : "0");
statement.setString(4, this.anyoneCanRide() ? "1" : "0");
2020-02-04 22:04:41 +01:00
statement.setInt(5, this.getSaddleItemId());
statement.setInt(6, super.getId());
2018-07-06 15:30:00 +02:00
statement.execute();
2019-05-26 20:14:53 +02:00
} catch (SQLException e) {
2020-05-04 22:24:09 +02:00
LOGGER.error("Caught SQL exception", e);
2018-07-06 15:30:00 +02:00
}
super.run();
}
}
2019-05-26 20:14:53 +02:00
public int getHairColor() {
2018-07-06 15:30:00 +02:00
return this.hairColor;
}
2019-05-26 20:14:53 +02:00
public void setHairColor(int hairColor) {
2018-07-06 15:30:00 +02:00
this.hairColor = hairColor;
}
2019-05-26 20:14:53 +02:00
public int getHairStyle() {
2018-07-06 15:30:00 +02:00
return this.hairStyle;
}
2019-05-26 20:14:53 +02:00
public void setHairStyle(int hairStyle) {
2018-07-06 15:30:00 +02:00
this.hairStyle = hairStyle;
}
}