-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerHelper.java
More file actions
76 lines (66 loc) · 2.5 KB
/
ServerHelper.java
File metadata and controls
76 lines (66 loc) · 2.5 KB
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
package cf.catworlds.dynamicspigotsetting.utils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.World;
public class ServerHelper {
static public double getTPS() {
return Bukkit.getServer().getTPS()[0];
}
static public double getItemMerge() {
try {
World world = Bukkit.getWorlds().get(0);
Object handle = getHandle(world);
Object spigotConfig = getSpigotConfig(handle);
Field itemMergeField = spigotConfig.getClass().getField("itemMerge");
return itemMergeField.getDouble(spigotConfig);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
static public void setItemMerge(double radius) {
try {
for (World world : Bukkit.getWorlds()) {
Object handle = getHandle(world);
Object spigotConfig = getSpigotConfig(handle);
Field itemMergeField = spigotConfig.getClass().getField("itemMerge");
itemMergeField.setDouble(spigotConfig, radius);
}
} catch (Exception e) {
e.printStackTrace();
}
}
static public double getExpMerge() {
try {
World world = Bukkit.getWorlds().get(0);
Object handle = getHandle(world);
Object spigotConfig = getSpigotConfig(handle);
Field expMergeField = spigotConfig.getClass().getField("expMerge");
return expMergeField.getDouble(spigotConfig);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
static public void setExpMerge(double radius) {
try {
for (World world : Bukkit.getWorlds()) {
Object handle = getHandle(world);
Object spigotConfig = getSpigotConfig(handle);
Field expMergeField = spigotConfig.getClass().getField("expMerge");
expMergeField.setDouble(spigotConfig, radius);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static Object getHandle(World world) throws Exception {
Method getHandle = world.getClass().getMethod("getHandle");
return getHandle.invoke(world);
}
private static Object getSpigotConfig(Object worldServer) throws Exception {
Field spigotConfigField = worldServer.getClass().getField("spigotConfig");
return spigotConfigField.get(worldServer);
}
}