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

98 lines
2.5 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;
public class NewUserGift implements ISerialize
{
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
public NewUserGift(ResultSet set) throws SQLException
{
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
}
public NewUserGift(int id, Type type, String imageUrl, Map<String, String> items)
{
this.id = id;
this.imageUrl = imageUrl;
this.type = type;
this.items = items;
}
@Override
public void serialize(ServerMessage message)
{
message.appendString(this.imageUrl);
message.appendInt(this.items.size());
for (Map.Entry<String, String> entry : this.items.entrySet())
{
message.appendString(entry.getKey()); //Item Name
message.appendString(entry.getValue()); //Extra Info
}
}
public void give(Habbo habbo)
{
if (this.type == Type.ITEM)
{
for (Map.Entry<String, String> set : this.items.entrySet())
{
Item item = Emulator.getGameEnvironment().getItemManager().getItem(set.getKey());
if (item != null)
{
HabboItem createdItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), item, 0, 0, "");
if (createdItem != null)
{
habbo.addFurniture(createdItem);
}
}
}
}
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
}
}
public int getId()
{
return this.id;
}
public Type getType()
{
return this.type;
}
public String getImageUrl()
{
return this.imageUrl;
}
public Map<String, String> getItems()
{
return this.items;
}
2019-03-18 02:22:00 +01:00
public enum Type
2018-07-06 15:30:00 +02:00
{
ITEM,
ROOM
}
}