Push Comments for WiredConditionDateRangeActive.java for Wired Documentation.

This commit is contained in:
Harmonic 2023-01-08 10:55:34 -08:00
parent 60bf49df74
commit 8310e9f7df

View File

@ -14,25 +14,53 @@ import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
/**
* This class represents a wired condition item in the game "Habbo Hotel". It checks if the current date is within
* a given range.
*/
public class WiredConditionDateRangeActive extends InteractionWiredCondition { public class WiredConditionDateRangeActive extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.DATE_RANGE; public static final WiredConditionType type = WiredConditionType.DATE_RANGE;
private int startDate; private int startDate; // the start of the date range
private int endDate; private int endDate; // the end of the date range
/**
* Creates a new instance of this class.
* @param set the ResultSet object to get data from
* @param baseItem the base item for this wired condition
* @throws SQLException if an error occurs while getting data from the ResultSet object
*/
public WiredConditionDateRangeActive(ResultSet set, Item baseItem) throws SQLException { public WiredConditionDateRangeActive(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
} }
/**
* Creates a new instance of this class.
* @param id The ID of this item.
* @param userId The ID of the user that owns this item.
* @param item The item this instance is associated with.
* @param extradata Additional data associated with this item.
* @param limitedStack The amount of items in this stack (if this item is stackable).
* @param limitedSells The amount of items that can be sold from this stack (if this item is sellable).
*/
public WiredConditionDateRangeActive(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { public WiredConditionDateRangeActive(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells); super(id, userId, item, extradata, limitedStack, limitedSells);
} }
/**
* Returns the {@link WiredConditionType} of this object.
* @return the type of this wired condition
*/
@Override @Override
public WiredConditionType getType() { public WiredConditionType getType() {
return type; return type;
} }
/**
* Sends information about this wired condition to the client.
* @param message the message to send data with
* @param room the room this wired condition is in
*/
@Override @Override
public void serializeWiredData(ServerMessage message, Room room) { public void serializeWiredData(ServerMessage message, Room room) {
message.appendBoolean(false); message.appendBoolean(false);
@ -50,6 +78,11 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
message.appendInt(this.endDate); message.appendInt(this.endDate);
} }
/**
* Saves the given {@link WiredSettings} object to this wired condition.
* @param settings the settings to save
* @return {@code true} if the settings were saved successfully, {@code false} otherwise
* */
@Override @Override
public boolean saveData(WiredSettings settings) { public boolean saveData(WiredSettings settings) {
if(settings.getIntParams().length < 2) return false; if(settings.getIntParams().length < 2) return false;
@ -58,12 +91,24 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
return true; return true;
} }
/**
* Determines if the wired condition is met.
* @param roomUnit the room unit that triggered the condition
* @param room the room that the condition is in
* @param stuff additional data for the condition
* @return true if the current time is within the given date range (startDate is less than the current time and
* endDate is greater than or equal to the current time)
*/
@Override @Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
int time = Emulator.getIntUnixTimestamp(); int time = Emulator.getIntUnixTimestamp();
return this.startDate < time && this.endDate >= time; return this.startDate < time && this.endDate >= time;
} }
/**
* Gets the wired data for this wired condition in JSON format.
* @return the wired data in JSON format
*/
@Override @Override
public String getWiredData() { public String getWiredData() {
return WiredHandler.getGsonBuilder().create().toJson(new JsonData( return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
@ -72,6 +117,12 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
)); ));
} }
/**
* Loads the wired data for this wired condition from a database.
* @param set the ResultSet object to get data from
* @param room the room that this wired condition is in
* @throws SQLException if an error occurs while getting data from the ResultSet object
*/
@Override @Override
public void loadWiredData(ResultSet set, Room room) throws SQLException { public void loadWiredData(ResultSet set, Room room) throws SQLException {
String wiredData = set.getString("wired_data"); String wiredData = set.getString("wired_data");
@ -93,16 +144,27 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
} }
} }
/**
* Called when this item is picked up. Resets the startDate and endDate member variables to 0.
*/
@Override @Override
public void onPickUp() { public void onPickUp() {
this.startDate = 0; this.startDate = 0;
this.endDate = 0; this.endDate = 0;
} }
/**
* A nested class for storing the wired data for this wired condition in JSON format.
*/
static class JsonData { static class JsonData {
int startDate; int startDate;
int endDate; int endDate;
/**
* Creates a new instance of this class.
* @param startDate the start of the date range
* @param endDate the end of the date range
*/
public JsonData(int startDate, int endDate) { public JsonData(int startDate, int endDate) {
this.startDate = startDate; this.startDate = startDate;
this.endDate = endDate; this.endDate = endDate;