-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
TwitchGlobalPack.java
82 lines (75 loc) · 3.15 KB
/
TwitchGlobalPack.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2015, Christopher "blay09" Baker
// Some rights reserved.
package net.blay09.mods.eiramoticons.addon.pack;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import net.blay09.mods.eiramoticons.addon.TwitchEmotesAPI;
import net.blay09.mods.eiramoticons.api.EiraMoticonsAPI;
import net.blay09.mods.eiramoticons.api.IEmoticon;
import net.blay09.mods.eiramoticons.api.IEmoticonLoader;
import net.minecraft.client.resources.I18n;
import net.minecraft.event.ClickEvent;
import net.minecraft.event.HoverEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
public class TwitchGlobalPack implements IEmoticonLoader {
public TwitchGlobalPack() {
try {
Reader reader = TwitchEmotesAPI.newGlobalEmotesReader(false);
Gson gson = new Gson();
JsonObject emoteList = null;
try {
emoteList = gson.fromJson(reader, JsonObject.class);
} catch (JsonParseException e) {
reader = TwitchEmotesAPI.newGlobalEmotesReader(true);
try {
emoteList = gson.fromJson(reader, JsonObject.class);
} catch (JsonParseException e2) {
System.out.println("Failed to load global emoticon pack: " + e2.getMessage());
e2.printStackTrace();
}
}
if(emoteList != null) {
for(Map.Entry<String, JsonElement> entry : emoteList.entrySet()) {
IEmoticon emoticon = EiraMoticonsAPI.registerEmoticon(entry.getKey(), this);
emoticon.setLoadData(entry.getValue().getAsJsonObject().get("id").getAsInt());
emoticon.setTooltip(I18n.format("eiramoticons:group.twitch"));
}
}
reader.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
IChatComponent linkComponent = new ChatComponentTranslation("eiramoticons:command.list.clickHere");
linkComponent.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://twitchemotes.com/"));
linkComponent.getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText("https://twitchemotes.com/")));
linkComponent.getChatStyle().setColor(EnumChatFormatting.GOLD);
linkComponent.getChatStyle().setBold(true);
linkComponent.getChatStyle().setUnderlined(true);
EiraMoticonsAPI.registerEmoticonGroup("Twitch Global", new ChatComponentTranslation("eiramoticons:command.list.twitch.global", linkComponent));
}
@Override
public void loadEmoticonImage(IEmoticon emoticon) {
BufferedImage image = TwitchEmotesAPI.readTwitchEmoteImage(TwitchEmotesAPI.URL_SMALL, (Integer) emoticon.getLoadData(), "global");
if (image != null) {
emoticon.setImage(image);
if(image.getWidth() <= TwitchEmotesAPI.TWITCH_BASE_SIZE || image.getHeight() <= TwitchEmotesAPI.TWITCH_BASE_SIZE) {
emoticon.setScale(0.5f, 0.5f);
}
}
}
}