2222import lol .hyper .anarchystats .tools .AbstractCommand ;
2323import lol .hyper .anarchystats .tools .MessageParser ;
2424import lol .hyper .anarchystats .tools .WorldSize ;
25- import lol .hyper .githubreleaseapi .GitHubRelease ;
26- import lol .hyper .githubreleaseapi .GitHubReleaseAPI ;
27- import org .bstats .bukkit .Metrics ;
25+ import lol .hyper .hyperlib .HyperLib ;
26+ import lol .hyper .hyperlib .bstats .HyperStats ;
27+ import lol .hyper .hyperlib .releases .HyperUpdater ;
28+ import lol .hyper .hyperlib .utils .TextUtils ;
29+ import net .kyori .adventure .text .logger .slf4j .ComponentLogger ;
2830import org .bukkit .Bukkit ;
2931import org .bukkit .configuration .file .FileConfiguration ;
3032import org .bukkit .configuration .file .YamlConfiguration ;
3133import org .bukkit .plugin .java .JavaPlugin ;
3234
3335import java .io .File ;
34- import java .io .IOException ;
3536import java .nio .file .Path ;
3637import java .nio .file .Paths ;
3738import java .util .ArrayList ;
3839import java .util .List ;
39- import java .util .logging .Logger ;
4040
4141public final class AnarchyStats extends JavaPlugin {
4242
4343 public String worldSize ;
4444 public final File configFile = new File (this .getDataFolder (), "config.yml" );
45- public final Logger logger = this .getLogger ();
45+ public final ComponentLogger logger = this .getComponentLogger ();
4646 public final List <Path > worldPaths = new ArrayList <>();
4747 public final int CONFIG_VERSION = 2 ;
4848 public FileConfiguration config ;
4949 public CommandReload commandReload ;
5050 public MessageParser messageParser ;
51+ public HyperLib hyperLib ;
52+ public TextUtils textUtils ;
5153
5254 @ Override
5355 public void onEnable () {
56+ hyperLib = new HyperLib (this );
57+ hyperLib .setup ();
58+
59+ textUtils = new TextUtils (hyperLib );
60+
61+ HyperStats stats = new HyperStats (hyperLib , 6877 );
62+ stats .setup ();
63+
5464 messageParser = new MessageParser (this );
5565 commandReload = new CommandReload (this );
5666 if (!configFile .exists ()) {
@@ -65,13 +75,15 @@ public void onEnable() {
6575 this .getCommand ("anarchystats" ).setExecutor (commandReload );
6676 Bukkit .getAsyncScheduler ().runNow (this , scheduledTask -> updateWorldSize ());
6777
68- new Metrics (this , 6877 );
69-
70- Bukkit .getAsyncScheduler ().runNow (this , scheduledTask -> checkForUpdates ());
78+ HyperUpdater updater = new HyperUpdater (hyperLib );
79+ updater .setGitHub ("hyperdefined" , "AnarchyStats" );
80+ updater .setModrinth ("Z04RmeT7" );
81+ updater .setHangar ("AnarchyStats" , "paper" );
82+ updater .check ();
7183 }
7284
7385 public void updateWorldSize () {
74- worldSize = WorldSize .readableFileSize (WorldSize .getWorldSize (worldPaths ));
86+ worldSize = WorldSize .readableFileSize (WorldSize .getWorldSize (worldPaths , logger ));
7587 }
7688
7789 public void loadConfig () {
@@ -82,38 +94,15 @@ public void loadConfig() {
8294 for (String worldFolder : config .getStringList ("worlds-to-use" )) {
8395 Path currentPath = Paths .get (Paths .get ("." ).toAbsolutePath ().normalize () + File .separator + worldFolder );
8496 if (!currentPath .toFile ().exists ()) {
85- logger .warning ("World folder \" " + worldFolder + " \" does not exist! Excluding from size calculation." );
97+ logger .warn ("World folder \" {} \" does not exist! Excluding from size calculation." , worldFolder );
8698 } else {
87- logger .info ("Adding " + worldFolder );
99+ logger .info ("Adding {}" , worldFolder );
88100 worldPaths .add (currentPath );
89101 }
90102 }
91103
92104 if (config .getInt ("config-version" ) != CONFIG_VERSION ) {
93- logger .warning ("You configuration is out of date! Some features may not work!" );
94- }
95- }
96-
97- public void checkForUpdates () {
98- GitHubReleaseAPI api ;
99- try {
100- api = new GitHubReleaseAPI ("AnarchyStats" , "hyperdefined" );
101- } catch (IOException e ) {
102- logger .warning ("Unable to check updates!" );
103- e .printStackTrace ();
104- return ;
105- }
106- GitHubRelease current = api .getReleaseByTag (this .getPluginMeta ().getVersion ());
107- GitHubRelease latest = api .getLatestVersion ();
108- if (current == null ) {
109- logger .warning ("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!" );
110- return ;
111- }
112- int buildsBehind = api .getBuildsBehind (current );
113- if (buildsBehind == 0 ) {
114- logger .info ("You are running the latest version." );
115- } else {
116- logger .warning ("A new version is available (" + latest .getTagVersion () + ")! You are running version " + current .getTagVersion () + ". You are " + buildsBehind + " version(s) behind." );
105+ logger .warn ("You configuration is out of date! Some features may not work!" );
117106 }
118107 }
119108}
0 commit comments