11package com .azuredoom .levelingcore ;
22
3+ import com .azuredoom .levelingcore .events .GainXPEventSystem ;
4+ import com .hypixel .hytale .logger .HytaleLogger ;
5+ import com .hypixel .hytale .server .core .plugin .JavaPlugin ;
6+ import com .hypixel .hytale .server .core .plugin .JavaPluginInit ;
7+ import com .hypixel .hytale .server .core .universe .world .storage .EntityStore ;
8+ import com .hypixel .hytale .server .core .util .Config ;
9+
310import java .nio .file .Path ;
411import java .nio .file .Paths ;
5- import java .util .UUID ;
612import java .util .logging .*;
13+ import javax .annotation .Nonnull ;
714
8- import com .azuredoom .levelingcore .api .LevelingCoreApi ;
9- import com .azuredoom .levelingcore .config .ConfigBootstrap ;
15+ import com .azuredoom .levelingcore .commands .*;
16+ import com .azuredoom .levelingcore .config .GUIConfig ;
17+ import com .azuredoom .levelingcore .config .internal .ConfigBootstrap ;
1018import com .azuredoom .levelingcore .exceptions .LevelingCoreException ;
1119import com .azuredoom .levelingcore .level .LevelServiceImpl ;
12- import com .azuredoom .levelingcore .logging .LogConfig ;
1320
14- public class LevelingCore {
21+ public class LevelingCore extends JavaPlugin {
1522
16- public static final Logger LOGGER = LogConfig . setup ( LevelingCore . class );
23+ public static final HytaleLogger LOGGER = HytaleLogger . forEnclosingClass ( );
1724
18- public static final Path configPath = Paths .get ("./data/plugins/levelingcore /" );
25+ public static final Path configPath = Paths .get ("./mods/levelingcore_LevelingCore/data/config /" );
1926
2027 private static final ConfigBootstrap .Bootstrap bootstrap = ConfigBootstrap .bootstrap (configPath );
2128
2229 private static LevelServiceImpl levelingService ;
2330
24- public LevelingCore () {}
31+ private static LevelingCore INSTANCE ;
32+
33+ private final Config <GUIConfig > config ;
34+
35+ /**
36+ * Constructs a new {@code LevelingCore} instance and initializes the core components of the leveling system. This
37+ * constructor takes a non-null {@link JavaPluginInit} object to set up the necessary dependencies and
38+ * configurations required for the leveling system to function.
39+ *
40+ * @param init a {@link JavaPluginInit} instance used to initialize the plugin environment and dependencies. Must
41+ * not be {@code null}.
42+ */
43+ public LevelingCore (@ Nonnull JavaPluginInit init ) {
44+ super (init );
45+ INSTANCE = this ;
46+ config = this .withConfig ("levelingcore" , GUIConfig .CODEC );
47+ }
2548
26- // TODO: Call this from the server startup hook
27- public static void init () {
28- LOGGER .log (Level .INFO , "Leveling Core initialized" );
49+ @ Override
50+ protected void setup () {
51+ super .setup ();
52+ this .config .save ();
53+ LOGGER .at (Level .INFO ).log ("Leveling Core initializing" );
2954 levelingService = bootstrap .service ();
55+ getCommandRegistry ().registerCommand (new AddLevelCommand ());
56+ getCommandRegistry ().registerCommand (new CheckLevelCommand ());
57+ getCommandRegistry ().registerCommand (new AddXpCommand ());
58+ getCommandRegistry ().registerCommand (new SetLevelCommand ());
59+ getCommandRegistry ().registerCommand (new RemoveLevelCommand ());
60+ getCommandRegistry ().registerCommand (new RemoveXpCommand ());
61+ getEntityStoreRegistry ().registerSystem (new GainXPEventSystem ());
3062 }
3163
32- // TODO: Call this from the server shutdown hook
33- public static void shutdown () {
34- LOGGER .log (Level .INFO , "Leveling Core shutting down" );
64+ @ Override
65+ protected void shutdown () {
66+ super .shutdown ();
67+ LOGGER .at (Level .INFO ).log ("Leveling Core shutting down" );
3568 try {
3669 LevelingCore .bootstrap .closeable ().close ();
3770 } catch (Exception e ) {
3871 throw new LevelingCoreException ("Failed to close resources" , e );
3972 }
4073 }
4174
42- static void main () {
43- LevelingCore .init ();
44- // TODO: Remove once hooks into the player/mob kill events are found and integrable.
45- var testId = UUID .fromString ("d3804858-4bb8-4026-ae21-386255ed467d" );
46- if (LevelingCoreApi .getLevelServiceIfPresent ().isPresent ()) {
47- var levelingService = LevelingCoreApi .getLevelServiceIfPresent ().get ();
48- levelingService .addXp (testId , 500 );
49- // TODO: Move to chat based logging instead of System loggers
50- LevelingCore .LOGGER .log (Level .INFO , String .format ("XP: %d" , levelingService .getXp (testId )));
51- LevelingCore .LOGGER .log (
52- Level .INFO ,
53- String .format ("Level: %d" , levelingService .getLevel (testId ))
54- );
55- }
56- LevelingCore .shutdown ();
57- }
75+ // static void main() {
76+ // TODO: Remove once hooks into the player/mob kill events are found and integrable.
77+ // var testId = UUID.fromString("d3804858-4bb8-4026-ae21-386255ed467d");
78+ // if (LevelingCoreApi.getLevelServiceIfPresent().isPresent()) {
79+ // var levelingService = LevelingCoreApi.getLevelServiceIfPresent().get();
80+ // levelingService.addXp(testId, 500);
81+ // TODO: Move to chat or display based logging instead of loggers for gaining or lossing Levels/XP.
82+ // LOGGER.at(Level.INFO).log("Added 500 XP to player");
83+ // LOGGER.at(Level.INFO).log("Player level: " + levelingService.getLevel(testId));
84+ // }
85+ // }
5886
5987 /**
6088 * Retrieves the {@link LevelServiceImpl} instance managed by the {@code LevelingCore} class. The
@@ -65,4 +93,15 @@ static void main() {
6593 public static LevelServiceImpl getLevelService () {
6694 return levelingService ;
6795 }
96+
97+ /**
98+ * Provides access to the singleton instance of the {@code LevelingCore} class. This instance serves as the primary
99+ * entry point for managing the core functionality of the leveling system, including initialization, configuration,
100+ * and lifecycle management.
101+ *
102+ * @return the singleton instance of {@code LevelingCore}.
103+ */
104+ public static LevelingCore getInstance () {
105+ return INSTANCE ;
106+ }
68107}
0 commit comments