Skip to content

Commit 6c57701

Browse files
committed
Config
1 parent b923b50 commit 6c57701

File tree

3 files changed

+102
-5
lines changed

3 files changed

+102
-5
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.volmit.gloss.chatbubbles;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.lang.reflect.Field;
6+
7+
import org.bukkit.configuration.file.FileConfiguration;
8+
import org.bukkit.configuration.file.YamlConfiguration;
9+
10+
import com.volmit.gloss.api.GLOSS;
11+
import com.volmit.volume.bukkit.VolumePlugin;
12+
import com.volmit.volume.bukkit.util.data.YAMLClusterPort;
13+
import com.volmit.volume.cluster.DataCluster;
14+
15+
public class Config
16+
{
17+
public static boolean followPlayers = true;
18+
public static int wordWrapThreshold = 32;
19+
public static int messageDisplayTicks = 100;
20+
public static int messageBubbleMaxTimeAlive = 5000;
21+
22+
public static void read() throws IOException, Exception
23+
{
24+
File f = GLOSS.getConfigLocation(VolumePlugin.vpi);
25+
26+
if(!f.exists())
27+
{
28+
f.getParentFile().mkdirs();
29+
new YAMLClusterPort().fromCluster(peel()).save(f);
30+
}
31+
32+
FileConfiguration fc = new YamlConfiguration();
33+
fc.load(f);
34+
stick(new YAMLClusterPort().toCluster(fc));
35+
}
36+
37+
public static void stick(DataCluster cc)
38+
{
39+
for(Field i : Config.class.getDeclaredFields())
40+
{
41+
try
42+
{
43+
if(cc.has(i.getName()))
44+
{
45+
i.set(null, cc.get(i.getName()));
46+
}
47+
}
48+
49+
catch(IllegalArgumentException | IllegalAccessException e)
50+
{
51+
e.printStackTrace();
52+
}
53+
}
54+
}
55+
56+
public static DataCluster peel()
57+
{
58+
DataCluster cc = new DataCluster();
59+
60+
for(Field i : Config.class.getDeclaredFields())
61+
{
62+
try
63+
{
64+
cc.set(i.getName(), i.get(null));
65+
}
66+
67+
catch(IllegalArgumentException | IllegalAccessException e)
68+
{
69+
e.printStackTrace();
70+
}
71+
}
72+
73+
return cc;
74+
}
75+
}

src/main/java/com/volmit/gloss/chatbubbles/GlossChatBubbles.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.UUID;
44

5+
import org.bukkit.Location;
56
import org.bukkit.entity.Player;
67
import org.bukkit.event.EventHandler;
78
import org.bukkit.event.EventPriority;
@@ -12,6 +13,7 @@
1213
import com.volmit.volume.bukkit.VolumePlugin;
1314
import com.volmit.volume.bukkit.command.CommandTag;
1415
import com.volmit.volume.bukkit.pawn.Async;
16+
import com.volmit.volume.bukkit.pawn.Start;
1517
import com.volmit.volume.bukkit.task.A;
1618
import com.volmit.volume.bukkit.util.data.Edgy;
1719
import com.volmit.volume.lang.format.F;
@@ -20,13 +22,28 @@
2022
@CommandTag("&8[&5GCB&8]:&7 ")
2123
public class GlossChatBubbles extends VolumePlugin
2224
{
25+
@Start
26+
public void loadConf()
27+
{
28+
try
29+
{
30+
Config.read();
31+
}
32+
33+
catch(Exception e)
34+
{
35+
System.out.println("Failed to read gloss chat bubbles config.");
36+
e.printStackTrace();
37+
}
38+
}
39+
2340
@Async
2441
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
2542
public void on(AsyncPlayerChatEvent e)
2643
{
2744
int m = 0;
2845

29-
for(String i : F.wrapWords(e.getMessage(), 32).split("\n"))
46+
for(String i : F.wrapWords(e.getMessage(), Config.wordWrapThreshold).split("\n"))
3047
{
3148
new A(5 * m)
3249
{
@@ -44,7 +61,8 @@ public void run()
4461
@Async
4562
private void bubble(String msg, Player p)
4663
{
47-
TemporaryDescriptor d = GLOSS.getSourceLibrary().createTemporaryDescriptor("chat-" + p.getUniqueId() + "-" + M.ms() + UUID.randomUUID().toString(), p.getEyeLocation().clone().add(0, 1, 0), 5000);
64+
Location l = p.getEyeLocation().clone().add(0, 1, 0);
65+
TemporaryDescriptor d = GLOSS.getSourceLibrary().createTemporaryDescriptor("chat-" + p.getUniqueId() + "-" + M.ms() + UUID.randomUUID().toString(), l, Config.messageBubbleMaxTimeAlive);
4866
d.addLine("&s&7" + msg);
4967
int trk = GLOSS.getContextLibrary().getView(p).getTrackedBubbles();
5068

@@ -59,14 +77,14 @@ private void bubble(String msg, Player p)
5977
double j = Math.max((m) - (((m / 2D) - ((h + g) / 2D)) + (f * 2D)), 0);
6078
double v = d.getHealth() < 2000 ? (Math.pow(1D - ((double) d.getHealth() / 2000D), 16) * 10D) : 0;
6179

62-
return p.getEyeLocation().clone().add(0, 0.86 + j + v, 0);
80+
return (Config.followPlayers ? p.getEyeLocation() : l).clone().add(0, 0.86 + j + v, 0);
6381
});
6482

6583
d.setLocation(p.getEyeLocation());
6684

6785
GLOSS.getContextLibrary().getView(p).setTrackedBubbles(GLOSS.getContextLibrary().getView(p).getTrackedBubbles() + 1);
6886

69-
new A(20 * 5)
87+
new A(Config.messageDisplayTicks)
7088
{
7189
@Override
7290
public void run()

src/main/resources/plugin.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
name: ${project.name}
22
version: ${project.version}
33
main: com.volmit.gloss.chatbubbles.GlossChatBubbles
4-
depend: [Gloss]
4+
depend: [Gloss]
5+
permissions:
6+
gloss.chatbubbles.allow:
7+
description: Gives access display chat bubbles
8+
default: op

0 commit comments

Comments
 (0)