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

82 lines
2.4 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
2019-05-26 20:14:53 +02:00
public class NewUserGift implements ISerialize {
2018-07-06 15:30:00 +02:00
private final int id;
private final Type type;
private final String imageUrl;
2018-09-28 21:25:00 +02:00
private Map<String, String> items = new HashMap<>();
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public NewUserGift(ResultSet set) throws SQLException {
2018-07-06 15:30:00 +02:00
this.id = set.getInt("id");
this.type = Type.valueOf(set.getString("type").toUpperCase());
this.imageUrl = set.getString("image");
2019-03-18 02:22:00 +01:00
this.items.put(this.type == Type.ROOM ? "" : set.getString("value"), this.type == Type.ROOM ? set.getString("value") : "");
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public NewUserGift(int id, Type type, String imageUrl, Map<String, String> items) {
2018-07-06 15:30:00 +02:00
this.id = id;
this.imageUrl = imageUrl;
this.type = type;
this.items = items;
}
@Override
2019-05-26 20:14:53 +02:00
public void serialize(ServerMessage message) {
2018-07-06 15:30:00 +02:00
message.appendString(this.imageUrl);
message.appendInt(this.items.size());
2019-05-26 20:14:53 +02:00
for (Map.Entry<String, String> entry : this.items.entrySet()) {
2018-07-06 15:30:00 +02:00
message.appendString(entry.getKey()); //Item Name
message.appendString(entry.getValue()); //Extra Info
}
}
2019-05-26 20:14:53 +02:00
public void give(Habbo habbo) {
if (this.type == Type.ITEM) {
for (Map.Entry<String, String> set : this.items.entrySet()) {
2018-07-06 15:30:00 +02:00
Item item = Emulator.getGameEnvironment().getItemManager().getItem(set.getKey());
2019-05-26 20:14:53 +02:00
if (item != null) {
2018-07-06 15:30:00 +02:00
HabboItem createdItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), item, 0, 0, "");
2019-05-26 20:14:53 +02:00
if (createdItem != null) {
2018-07-06 15:30:00 +02:00
habbo.addFurniture(createdItem);
}
}
}
2019-05-26 20:14:53 +02:00
} else if (this.type == Type.ROOM) {
2019-03-18 02:22:00 +01:00
//TODO Give room
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
public int getId() {
2018-07-06 15:30:00 +02:00
return this.id;
}
2019-05-26 20:14:53 +02:00
public Type getType() {
2018-07-06 15:30:00 +02:00
return this.type;
}
2019-05-26 20:14:53 +02:00
public String getImageUrl() {
2018-07-06 15:30:00 +02:00
return this.imageUrl;
}
2019-05-26 20:14:53 +02:00
public Map<String, String> getItems() {
2018-07-06 15:30:00 +02:00
return this.items;
}
2019-05-26 20:14:53 +02:00
public enum Type {
2018-07-06 15:30:00 +02:00
ITEM,
ROOM
}
}