11package org .matrixnetwork .stats2 ;
22
3- import com .fasterxml .jackson .databind .ObjectMapper ;
43import com .sun .net .httpserver .HttpServer ;
54import net .milkbowl .vault .economy .Economy ;
6- import net .skinsrestorer .api .SkinsRestorerAPI ;
7- import org .bukkit .Bukkit ;
8- import org .bukkit .entity .Player ;
95import org .bukkit .plugin .RegisteredServiceProvider ;
106import org .bukkit .plugin .java .JavaPlugin ;
11- import org .bukkit .scheduler .BukkitRunnable ;
12- import org .bukkit .scheduler .BukkitTask ;
137import org .glassfish .jersey .jdkhttp .JdkHttpServerFactory ;
148import org .glassfish .jersey .message .GZipEncoder ;
159import org .glassfish .jersey .server .ResourceConfig ;
2317import org .matrixnetwork .stats2 .util .JacksonFeature ;
2418
2519import java .net .URI ;
26- import java .util .List ;
27-
28- public class MatrixStats extends JavaPlugin {
29-
30- private static MatrixStats plugin ;
31- private HttpServer server ;
32- private static Economy econ ;
33-
34- public static Economy getEcon () {
35- return econ ;
36- }
37-
38- @ Override
39- public void onLoad () {
40- plugin = this ;
41- }
42-
43- @ Override
44- public void onEnable () {
45- if (!setupEconomy () ) {
46- getLogger ().severe (String .format ("[%s] - Disabled due to no Vault dependency found!" ,
47- getDescription ().getName ()));
48- getServer ().getPluginManager ().disablePlugin (this );
49- return ;
50- }
51-
52- getServer ().getPluginManager ().registerEvents (new StatsListener (), this );
53-
54- StatsHandler .init ();
55-
56- ResourceConfig rc = new ResourceConfig ();
57- rc .packages ("org.matrixnetwork.stats.rest" );
58- rc .register (StatsResource .class );
59- rc .register (SkinResource .class );
60- rc .register (AuthResource .class );
61- rc .register (CorsFilter .class );
62- rc .register (new GZipEncoder ());
63- rc .register (JacksonFeature .class );
64-
65- rc .property (ServerProperties .WADL_FEATURE_DISABLE , true );
66-
67- server = JdkHttpServerFactory .createHttpServer (
68- URI .create ( "http://localhost:8081/api" ), rc );
69-
70- getLogger ().info ("Listening on http://localhost:8081/api !" );
71- }
72-
73- private boolean setupEconomy () {
74- if (getServer ().getPluginManager ().getPlugin ("Vault" ) == null ) {
75- return false ;
76- }
77-
78- RegisteredServiceProvider <Economy > rsp = getServer ()
79- .getServicesManager ()
80- .getRegistration (Economy .class );
81-
82- if (rsp == null ) {
83- return false ;
84- }
85- econ = rsp .getProvider ();
86- return econ != null ;
87- }
88-
89- @ Override
90- public void onDisable () {
91- if (server != null )
92- server .stop ( 0 );
93- getLogger ().info ("Disabled" );
94- }
95-
96- public static org .bukkit .plugin .Plugin getPlugin () {
97- return plugin ;
98- }
20+
21+ public class MatrixStats extends JavaPlugin {
22+
23+ private static MatrixStats plugin ;
24+ private static Economy econ ;
25+ private HttpServer server ;
26+
27+ public static Economy getEcon () {
28+ return econ ;
29+ }
30+
31+ public static org .bukkit .plugin .Plugin getPlugin () {
32+ return plugin ;
33+ }
34+
35+ @ Override
36+ public void onLoad () {
37+ plugin = this ;
38+ }
39+
40+ @ Override
41+ public void onEnable () {
42+ if (!setupEconomy ()) {
43+ getLogger ().severe (String .format ("[%s] - Disabled due to no Vault dependency found!" ,
44+ getDescription ().getName ()));
45+ getServer ().getPluginManager ().disablePlugin (this );
46+ return ;
47+ }
48+
49+ getServer ().getPluginManager ().registerEvents (new StatsListener (), this );
50+
51+ StatsHandler .init ();
52+
53+ ResourceConfig rc = new ResourceConfig ();
54+ rc .packages ("org.matrixnetwork.stats.rest" );
55+ rc .register (StatsResource .class );
56+ rc .register (SkinResource .class );
57+ rc .register (AuthResource .class );
58+ rc .register (CorsFilter .class );
59+ rc .register (new GZipEncoder ());
60+ rc .register (JacksonFeature .class );
61+
62+ rc .property (ServerProperties .WADL_FEATURE_DISABLE , true );
63+
64+ server = JdkHttpServerFactory .createHttpServer (
65+ URI .create ("http://localhost:8081/api" ), rc );
66+
67+ getLogger ().info ("Listening on http://localhost:8081/api !" );
68+ }
69+
70+ private boolean setupEconomy () {
71+ if (getServer ().getPluginManager ().getPlugin ("Vault" ) == null ) {
72+ return false ;
73+ }
74+
75+ RegisteredServiceProvider <Economy > rsp = getServer ()
76+ .getServicesManager ()
77+ .getRegistration (Economy .class );
78+
79+ if (rsp == null ) {
80+ return false ;
81+ }
82+ econ = rsp .getProvider ();
83+ return econ != null ;
84+ }
85+
86+ @ Override
87+ public void onDisable () {
88+ if (server != null )
89+ server .stop (0 );
90+ getLogger ().info ("Disabled" );
91+ }
9992
10093}
0 commit comments