|
19 | 19 | package com.andre601.oneversionremake.velocity; |
20 | 20 |
|
21 | 21 | import com.andre601.oneversionremake.core.OneVersionRemake; |
| 22 | +import com.andre601.oneversionremake.core.enums.ProtocolVersion; |
22 | 23 | import com.andre601.oneversionremake.core.enums.ProxyPlatform; |
23 | 24 | import com.andre601.oneversionremake.core.files.ConfigHandler; |
24 | 25 | import com.andre601.oneversionremake.core.interfaces.PluginCore; |
|
33 | 34 | import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; |
34 | 35 | import com.velocitypowered.api.plugin.annotation.DataDirectory; |
35 | 36 | import com.velocitypowered.api.proxy.ProxyServer; |
| 37 | +import org.bstats.charts.DrilldownPie; |
| 38 | +import org.bstats.velocity.Metrics; |
36 | 39 | import org.slf4j.LoggerFactory; |
37 | 40 |
|
38 | 41 | import java.nio.file.Path; |
| 42 | +import java.util.HashMap; |
| 43 | +import java.util.List; |
| 44 | +import java.util.Map; |
39 | 45 |
|
40 | 46 | public class VelocityCore implements PluginCore{ |
41 | 47 |
|
42 | 48 | private final ProxyLogger logger; |
43 | 49 | private final ProxyServer proxy; |
44 | 50 | private final Path path; |
45 | 51 |
|
| 52 | + private final Metrics.Factory factory; |
| 53 | + |
46 | 54 | private OneVersionRemake core; |
47 | 55 |
|
48 | 56 | private ConfigHandler configHandler = null; |
49 | 57 |
|
50 | 58 | @Inject |
51 | | - public VelocityCore(ProxyServer proxy, @DataDirectory Path path){ |
| 59 | + public VelocityCore(ProxyServer proxy, @DataDirectory Path path, Metrics.Factory factory){ |
52 | 60 | this.logger = new VelocityLogger(LoggerFactory.getLogger("OneVersionRemake")); |
53 | 61 | this.proxy = proxy; |
54 | 62 | this.path = path; |
| 63 | + |
| 64 | + this.factory = factory; |
55 | 65 | } |
56 | 66 |
|
57 | 67 | @Subscribe |
@@ -81,6 +91,39 @@ public void setConfigHandler(ConfigHandler configHandler){ |
81 | 91 | this.configHandler = configHandler; |
82 | 92 | } |
83 | 93 |
|
| 94 | + @Override |
| 95 | + public void loadMetrics(){ |
| 96 | + Metrics metrics = factory.make(this, 10341); |
| 97 | + |
| 98 | + metrics.addCustomChart(new DrilldownPie("allowed_versions", () -> { |
| 99 | + Map<String, Map<String, Integer>> map = new HashMap<>(); |
| 100 | + Map<String, Integer> entry = new HashMap<>(); |
| 101 | + |
| 102 | + List<Integer> protocolVersions = getConfigHandler().getIntList("Protocol", "Versions"); |
| 103 | + if(protocolVersions.isEmpty()){ |
| 104 | + String unknown = ProtocolVersion.getFriendlyName(0); |
| 105 | + entry.put(unknown, 1); |
| 106 | + map.put("other", entry); |
| 107 | + |
| 108 | + return map; |
| 109 | + } |
| 110 | + |
| 111 | + for(int version : protocolVersions){ |
| 112 | + String major = ProtocolVersion.getMajor(version); |
| 113 | + String name = ProtocolVersion.getFriendlyName(version); |
| 114 | + |
| 115 | + entry.put(name, 1); |
| 116 | + if(major.equalsIgnoreCase("?")){ |
| 117 | + map.put("other", entry); |
| 118 | + }else{ |
| 119 | + map.put(major, entry); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + return map; |
| 124 | + })); |
| 125 | + } |
| 126 | + |
84 | 127 | @Override |
85 | 128 | public boolean reloadConfig(){ |
86 | 129 | return core.reloadConfig(); |
|
0 commit comments