-
Notifications
You must be signed in to change notification settings - Fork 0
/
HoloHandler.java
88 lines (75 loc) · 2.53 KB
/
HoloHandler.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
83
84
85
86
87
88
package com.IntenseArmadillo.armadilloholohead;
import com.IntenseArmadillo.armadilloholohead.imgmessage.ImageChar;
import com.IntenseArmadillo.armadilloholohead.imgmessage.ImageMessage;
import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import com.gmail.filoghost.holographicdisplays.api.VisibilityManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class HoloHandler {
public static void handleMotd(final Player p) {
final Hologram hologram = HologramsAPI.createHologram(Main.instance, p.getLocation());
VisibilityManager visibilityManager = hologram.getVisibilityManager();
visibilityManager.showTo(p);
visibilityManager.setVisibleByDefault(false);
new Thread(new Runnable() {
@Override
public void run() {
final List<String> face = new ArrayList<String>();
try {
face.addAll(Arrays.asList(new ImageMessage(ImageIO.read(new URL("https://minotar.net/avatar/" + p.getName() + "/8.png")), 8, ImageChar.BLOCK
.getChar()).getLines()));
} catch (MalformedURLException e) {
} catch (IOException e) {
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.instance, new Runnable() {
@Override
public void run() {
if (p.isOnline()) {
if (face.size() == 0) {
p.sendMessage(getLine("before", p));
String s = "";
s = s + getLine("1", p).trim();
s = s + getLine("2", p).trim();
;
s = s + getLine("3", p).trim();
;
s = s + getLine("4", p).trim();
;
s = s + getLine("5", p).trim();
;
p.sendMessage(s);
p.sendMessage(getLine("after", p));
} else {
for (String s : face) {
hologram.appendTextLine(s);
}
hologram.appendTextLine(p.getName());
}
}
}
});
}
}).start();
}
public static String getLine(String n, Player p) {
String line = Main.instance.getConfig().getString("line-" + n);
line = line.replace("%name", p.getName());
line = line.replace("%display", p.getDisplayName());
line = line.replace("%total", p.getServer().getOnlinePlayers().size() + "");
line = ChatColor.translateAlternateColorCodes('&', line);
return line;
}
}