1818package lol .hyper .velocityblockversion ;
1919
2020import com .google .inject .Inject ;
21+ import com .google .inject .Injector ;
2122import com .velocitypowered .api .command .CommandManager ;
2223import com .velocitypowered .api .command .CommandMeta ;
23- import com .velocitypowered .api .event .proxy . ProxyInitializeEvent ;
24+ import com .velocitypowered .api .event .EventManager ;
2425import com .velocitypowered .api .event .Subscribe ;
26+ import com .velocitypowered .api .event .proxy .ProxyInitializeEvent ;
2527import com .velocitypowered .api .plugin .Plugin ;
2628import com .velocitypowered .api .proxy .ProxyServer ;
2729import lol .hyper .githubreleaseapi .GitHubRelease ;
2830import lol .hyper .githubreleaseapi .GitHubReleaseAPI ;
2931import lol .hyper .velocityblockversion .commands .CommandReload ;
3032import lol .hyper .velocityblockversion .events .JoinEvent ;
3133import lol .hyper .velocityblockversion .tools .ConfigHandler ;
32- import net .kyori .adventure .text .minimessage .MiniMessage ;
3334import org .bstats .velocity .Metrics ;
3435import org .slf4j .Logger ;
3536
4445 url = "https://github.com/hyperdefined/VelocityBlockVersion"
4546)
4647public class VelocityBlockVersion {
47-
48- public ConfigHandler configHandler ;
49- public JoinEvent joinEvent ;
50- public CommandReload commandReload ;
51- public final String VERSION = "1.0.7" ;
52-
53- public final Logger logger ;
54- private final Metrics .Factory metricsFactory ;
55- private final ProxyServer server ;
56- private final CommandManager commandManager ;
57- public final MiniMessage miniMessage = MiniMessage .miniMessage ();
48+ public static final String VERSION = "1.0.7" ;
5849
5950 @ Inject
60- public VelocityBlockVersion (ProxyServer server , Logger logger , Metrics .Factory metricsFactory , CommandManager commandManager ) {
61- this .server = server ;
62- this .logger = logger ;
63- this .metricsFactory = metricsFactory ;
64- this .commandManager = commandManager ;
65- }
51+ private Logger logger ;
52+ @ Inject
53+ private Metrics .Factory metricsFactory ;
54+ @ Inject
55+ private ProxyServer server ;
56+ @ Inject
57+ private CommandManager commandManager ;
58+ @ Inject
59+ private EventManager eventManager ;
60+ @ Inject
61+ private Injector injector ;
6662
6763 @ Subscribe
68- public void onProxyInitialization (ProxyInitializeEvent event ) {
69- configHandler = new ConfigHandler (this );
70- joinEvent = new JoinEvent (this );
71- commandReload = new CommandReload (this );
72- configHandler .loadConfig ();
64+ public void onProxyInitialization (final ProxyInitializeEvent event ) {
65+ final ConfigHandler configHandler = injector .getInstance (ConfigHandler .class );
66+ if (!configHandler .loadConfig ()) {
67+ return ;
68+ }
69+
7370 metricsFactory .make (this , 13308 );
71+
7472 server .getScheduler ().buildTask (this , this ::checkForUpdates ).schedule ();
75- server .getEventManager ().register (this , joinEvent );
7673
77- CommandMeta meta = commandManager .metaBuilder ("vbvreload" ).build ();
74+ final JoinEvent joinEvent = injector .getInstance (JoinEvent .class );
75+ eventManager .register (this , joinEvent );
76+
77+ final CommandReload commandReload = injector .getInstance (CommandReload .class );
78+ final CommandMeta meta = commandManager .metaBuilder ("vbvreload" ).plugin (this ).build ();
7879 commandManager .register (meta , commandReload );
7980 }
8081
@@ -83,12 +84,11 @@ public void checkForUpdates() {
8384 try {
8485 api = new GitHubReleaseAPI ("velocityblockversion" , "hyperdefined" );
8586 } catch (IOException e ) {
86- logger .warn ("Unable to check updates!" );
87- e .printStackTrace ();
87+ logger .warn ("Unable to check updates!" , e );
8888 return ;
8989 }
90- GitHubRelease current = api .getReleaseByTag (VERSION );
91- GitHubRelease latest = api .getLatestVersion ();
90+ final GitHubRelease current = api .getReleaseByTag (VERSION );
91+ final GitHubRelease latest = api .getLatestVersion ();
9292 if (current == null ) {
9393 logger .warn ("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!" );
9494 return ;
@@ -97,7 +97,7 @@ public void checkForUpdates() {
9797 if (buildsBehind == 0 ) {
9898 logger .info ("You are running the latest version." );
9999 } else {
100- logger .warn ("A new version is available (" + latest . getTagVersion () + ") ! You are running version " + current . getTagVersion () + ". You are " + buildsBehind + " version(s) behind." );
100+ logger .warn ("A new version is available ({}) ! You are running version {}. You are " + buildsBehind + " version(s) behind." , latest . getTagVersion (), current . getTagVersion () );
101101 }
102102 }
103103}
0 commit comments