mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Update gifts manager
This commit is contained in:
@@ -8,9 +8,7 @@ import java.util.*;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Gift
|
||||
{
|
||||
@Getter private static final Set<Gift> gifts = new HashSet<>();
|
||||
public class Gift {
|
||||
public static final Gift UNDEFINED = new Gift(-1, "undefined", -1, "", null);
|
||||
|
||||
private final int id;
|
||||
@@ -31,6 +29,22 @@ public class Gift
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Gift(int id, String name, int diamondCost, String pictureLink) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.diamondCost = diamondCost;
|
||||
this.picture = new Picture(pictureLink);
|
||||
this.properties = new JsonObject();
|
||||
}
|
||||
|
||||
public Gift(int id, String name, int diamondCost, Picture picture) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.diamondCost = diamondCost;
|
||||
this.picture = picture;
|
||||
this.properties = new JsonObject();
|
||||
}
|
||||
|
||||
public boolean hasDiamondCostRange(int minimalCost, int maximalCost) {
|
||||
return diamondCost >= minimalCost && diamondCost <= maximalCost;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
package io.github.jwdeveloper.tiktok.data.requests;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
@@ -41,16 +42,7 @@ public class GiftsData
|
||||
public static final class Response
|
||||
{
|
||||
private String json;
|
||||
private List<GiftModel> gifts;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class GiftModel
|
||||
{
|
||||
private int id;
|
||||
private String name;
|
||||
private int diamondCost;
|
||||
private String image;
|
||||
private List<Gift> gifts;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public interface LiveHttpClient
|
||||
*/
|
||||
GiftsData.Response fetchGiftsData();
|
||||
|
||||
|
||||
/**
|
||||
* Returns information about user that is having a livestream
|
||||
* @param userName name of user
|
||||
|
||||
@@ -25,43 +25,62 @@ package io.github.jwdeveloper.tiktok.live;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface GiftManager {
|
||||
public interface GiftsManager {
|
||||
|
||||
/**
|
||||
* In case you can't find your gift in Gift enum. You can register gift
|
||||
* manually here to make it detected while TikTokGiftEvent
|
||||
* You can create and attach your own custom gift to manager
|
||||
*
|
||||
* @param id gift's id
|
||||
* @param name gift's name
|
||||
* @param diamondCost diamond cost
|
||||
* @return
|
||||
* @param gift
|
||||
*/
|
||||
default Gift registerGift(int id, String name, int diamondCost, Picture picture) {
|
||||
return registerGift(id, name, diamondCost, picture, null);
|
||||
}
|
||||
|
||||
Gift registerGift(int id, String name, int diamondCost, Picture picture, JsonObject properties);
|
||||
void attachGift(Gift gift);
|
||||
|
||||
/**
|
||||
* You can create and attach your own custom gift to manager
|
||||
*
|
||||
* @param giftId
|
||||
* @return
|
||||
* @param gifts
|
||||
*/
|
||||
Gift findById(int giftId);
|
||||
void attachGiftsList(List<Gift> gifts);
|
||||
|
||||
/**
|
||||
* finds gift by name
|
||||
* When gift not found return Gift.UNDEFINED;
|
||||
*
|
||||
* @param giftName
|
||||
* @return
|
||||
* @param name gift name
|
||||
*/
|
||||
Gift findByName(String giftName);
|
||||
Gift getByName(String name);
|
||||
|
||||
/**
|
||||
* finds gift by id
|
||||
* When gift not found return Gift.UNDEFINED;
|
||||
*
|
||||
* @return all gifts
|
||||
* @param giftId giftId
|
||||
*/
|
||||
List<Gift> getGifts();
|
||||
Gift getById(int giftId);
|
||||
|
||||
|
||||
/**
|
||||
* finds gift by filter
|
||||
* When gift not found return Gift.UNDEFINED;
|
||||
*/
|
||||
Gift getByFilter(Predicate<Gift> filter);
|
||||
|
||||
List<Gift> getManyByFilter(Predicate<Gift> filter);
|
||||
|
||||
/**
|
||||
* @return list of all gifts
|
||||
*/
|
||||
List<Gift> toList();
|
||||
|
||||
|
||||
/**
|
||||
* @return list of all map of all gifts where Integer is gift Id
|
||||
*/
|
||||
Map<Integer, Gift> toMap();
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public interface LiveClient {
|
||||
/**
|
||||
* Get information about gifts
|
||||
*/
|
||||
GiftManager getGiftManager();
|
||||
GiftsManager getGiftManager();
|
||||
|
||||
/**
|
||||
* Gets the current room info from TikTok API including streamer info, room status and statistics.
|
||||
|
||||
Reference in New Issue
Block a user