44import cc .polyfrost .oneconfig .libs .universal .wrappers .message .UTextComponent ;
55import cc .polyfrost .oneconfig .utils .Multithreading ;
66import cc .polyfrost .oneconfig .utils .NetworkUtils ;
7+ import com .google .gson .JsonArray ;
78import llc .redstone .hysentials .Hysentials ;
89import llc .redstone .hysentials .HysentialsUtilsKt ;
910import llc .redstone .hysentials .config .HysentialsConfig ;
@@ -147,6 +148,17 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
147148 break ;
148149 }
149150
151+ case "leaderboard" : {
152+ //Types levels, quests, emeralds, settings
153+ if (args .length > 1 ) {
154+ String [] newArgs = Arrays .copyOfRange (args , 2 , args .length );
155+ handleLeaderboard (args [1 ], newArgs );
156+ } else {
157+ UChat .chat (HysentialsConfig .chatPrefix + " §cYou must specify a type! Use /hysentials leaderboard <type> for a list of types." );
158+ }
159+ break ;
160+ }
161+
150162 case "phone" :
151163 case "menu" : {
152164 UChat .chat (HysentialsConfig .chatPrefix + " §cComing soon!" );
@@ -193,6 +205,94 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
193205 }
194206 }
195207
208+ public static void handleLeaderboard (String command , String [] args ) {
209+ switch (command ) {
210+ case "levels" : {
211+ Socket .user .sendWithAuth (
212+ "leaderboardLookup" ,
213+ "type" , "levels"
214+ );
215+ Socket .awaiting .add (new DuoVariable <>("leaderboardLookup" , HysentialsCommand ::handleLeaderboardJson ));
216+ break ;
217+ }
218+ // case "quests": { Coming at some point
219+ // break;
220+ // }
221+ case "emeralds" : {
222+ Socket .user .sendWithAuth (
223+ "leaderboardLookup" ,
224+ "type" , "emeralds"
225+ );
226+ Socket .awaiting .add (new DuoVariable <>("leaderboardLookup" , HysentialsCommand ::handleLeaderboardJson ));
227+ break ;
228+ }
229+ case "settings" : {
230+ if (args .length < 2 ) {
231+ UChat .chat (HysentialsConfig .chatPrefix + " §cYou must specify a setting to set! Use /hysentials leaderboard settings <setting> <value>" );
232+ UChat .chat ("§c - hide <true/false> (Hides you from the leaderboard)" );
233+ return ;
234+ }
235+ switch (args [1 ]) {
236+ case "hide" : {
237+ if (args .length < 3 ) {
238+ UChat .chat (HysentialsConfig .chatPrefix + " §cYou must specify a value to set! Use /hysentials leaderboard settings hide <true/false>" );
239+ return ;
240+ }
241+ boolean hide = Boolean .parseBoolean (args [2 ]);
242+ Socket .user .sendWithAuth (
243+ "leaderboardSettings" ,
244+ new JSONObject ().put ("hide" , hide )
245+ );
246+ UChat .chat (HysentialsConfig .chatPrefix + " §aSuccessfully set leaderboard setting!" );
247+ break ;
248+ }
249+ default : {
250+ UChat .chat (HysentialsConfig .chatPrefix + " §cUnknown setting! Use /hysentials leaderboard settings <setting> <value>" );
251+ UChat .chat ("§c - hide <true/false> (Hides you from the leaderboard)" );
252+ break ;
253+ }
254+ }
255+ break ;
256+ }
257+ default : {
258+ UChat .chat (HysentialsConfig .chatPrefix + " §cUnknown leaderboard type! Use /hysentials leaderboard <level/emeralds/settings> for a list of types." );
259+ break ;
260+
261+ }
262+ }
263+ }
264+
265+ public static void handleLeaderboardJson (JsonObject json ) {
266+ UTextComponent text = new UTextComponent ("" );
267+ text .appendText ("§9&m \n " );
268+ text .appendText (ChatLib .getCenteredText ("&6Leaderboard\n " ));
269+ int page = 1 ; //Eventually this will be a variable
270+ if (json .has ("levels" )) {
271+ JsonArray levels = json .get ("levels" ).getAsJsonArray ();
272+ //10 elements per page
273+ int start = (page - 1 ) * 10 ;
274+ int end = Math .min (start + 10 , levels .size ());
275+ for (int i = start ; i < end ; i ++) {
276+ JsonObject obj = levels .get (i ).getAsJsonObject ();
277+ text .appendText ("&e" + (i + 1 ) + ". &7" + obj .get ("username" ).getAsString () + " &8- &aLevel " + obj .get ("level" ).getAsInt () + " &7(" + obj .get ("xp" ).getAsInt () + " HEXP)\n " );
278+ }
279+ } else if (json .has ("emeralds" )) {
280+ JsonArray emeralds = json .get ("emeralds" ).getAsJsonArray ();
281+ //10 elements per page
282+ int start = (page - 1 ) * 10 ;
283+ int end = Math .min (start + 10 , emeralds .size ());
284+ for (int i = start ; i < end ; i ++) {
285+ JsonObject obj = emeralds .get (i ).getAsJsonObject ();
286+ text .appendText ("&e" + (i + 1 ) + ". &7" + obj .get ("username" ).getAsString () + " &8- &a" + obj .get ("emeralds" ).getAsInt () + " &7Emeralds\n " );
287+ }
288+ }
289+ if (json .get ("count" ).getAsInt () - (page * 10 ) > 0 ) {
290+ text .appendText ("&eAnd " + (json .get ("count" ).getAsInt () - (page * 10 )) + " more...\n " );
291+ }
292+ text .appendText ("§9&m " );
293+ text .chat ();
294+ }
295+
196296 public static void handleImport (String id ) {
197297 try {
198298 String codeToBeCompiled = null ;
@@ -222,6 +322,13 @@ public static void handleImport(String id) {
222322 public void helpPage (int page ) {
223323 UTextComponent text = new UTextComponent ("" );
224324 int maxPage = 3 ;
325+ if (page > maxPage ) {
326+ UChat .chat (HysentialsConfig .chatPrefix + " §cInvalid page number max page number is " + maxPage + "! Use /hysentials help <page>" );
327+ return ;
328+ } else if (page < 1 ) {
329+ UChat .chat (HysentialsConfig .chatPrefix + " §cInvalid page number min page number is 1! Use /hysentials help <page>" );
330+ return ;
331+ }
225332 text .appendText ("§9&m \n " );
226333 switch (page ) {
227334 case 1 : {
@@ -237,7 +344,7 @@ public void helpPage(int page) {
237344 text .appendText ("&e/hysentials online &7- &bShows the online players.\n " );
238345 text .appendText ("&e/hysentials menu &7- &bOpens the Hysentials menu.\n " );
239346 text .appendText ("&e/hysentials discord &7- &bShows the discord invite link.\n " );
240- text .appendText ("&e/hysentials editor <file > &7- &bOpens the HTSL code editor .\n " );
347+ text .appendText ("&e/hysentials leaderboard <level/emeralds/settings > &7- Leaderboard .\n " );
241348 text .appendText ("§9&m " );
242349 break ;
243350 }
@@ -270,7 +377,7 @@ public void helpPage(int page) {
270377 text .appendText ("&e/sll <line> <value> &7- &bSet lore line.\n " );
271378 text .appendText ("&e/rename <name> &7- &bSet name on held item.\n " );
272379 text .appendText ("&e/openinv <player> &7- &bView the held item and armor of a player.\n " );
273- //2 more can be added here
380+ //1 more can be added here
274381 text .appendText ("§9&m " );
275382 }
276383 }
@@ -427,29 +534,26 @@ private static void handleTest(String command, String args) {
427534 }
428535 }
429536
430- public static List <MovingObjectPosition > getMouseOverExtended (float dist )
431- {
537+ public static List <MovingObjectPosition > getMouseOverExtended (float dist ) {
432538 List <MovingObjectPosition > mopReturn = new ArrayList <>();
433539 Minecraft mc = FMLClientHandler .instance ().getClient ();
434540 Entity theRenderViewEntity = mc .getRenderViewEntity ();
435541 AxisAlignedBB theViewBoundingBox = new AxisAlignedBB (
436- theRenderViewEntity .posX - 0.5D ,
437- theRenderViewEntity .posY - 0.0D ,
438- theRenderViewEntity .posZ - 0.5D ,
439- theRenderViewEntity .posX + 0.5D ,
440- theRenderViewEntity .posY + 1.5D ,
441- theRenderViewEntity .posZ + 0.5D
542+ theRenderViewEntity .posX - 0.5D ,
543+ theRenderViewEntity .posY - 0.0D ,
544+ theRenderViewEntity .posZ - 0.5D ,
545+ theRenderViewEntity .posX + 0.5D ,
546+ theRenderViewEntity .posY + 1.5D ,
547+ theRenderViewEntity .posZ + 0.5D
442548 );
443549 MovingObjectPosition returnMOP = null ;
444- if (mc .theWorld != null )
445- {
550+ if (mc .theWorld != null ) {
446551 double var2 = dist ;
447552 returnMOP = theRenderViewEntity .rayTrace (var2 , 0 );
448553 double calcdist = var2 ;
449554 Vec3 pos = theRenderViewEntity .getPositionEyes (0 );
450555 var2 = calcdist ;
451- if (returnMOP != null )
452- {
556+ if (returnMOP != null ) {
453557 calcdist = returnMOP .hitVec .distanceTo (pos );
454558 }
455559
@@ -468,34 +572,28 @@ public static List<MovingObjectPosition> getMouseOverExtended(float dist)
468572 lookvec .zCoord * var2 ).expand (var9 , var9 , var9 ));
469573 double d = calcdist ;
470574
471- for (Entity entity : list )
472- {
473- if (entity .canBeCollidedWith ())
474- {
575+ for (Entity entity : list ) {
576+ if (entity .canBeCollidedWith ()) {
475577 float bordersize = entity .getCollisionBorderSize ();
476578 AxisAlignedBB aabb = new AxisAlignedBB (
477- entity .posX - entity .width / 2 ,
579+ entity .posX - entity .width / 2 ,
478580 entity .posY ,
479- entity .posZ - entity .width / 2 ,
480- entity .posX + entity .width / 2 ,
481- entity .posY + entity .height ,
482- entity .posZ + entity .width / 2 );
581+ entity .posZ - entity .width / 2 ,
582+ entity .posX + entity .width / 2 ,
583+ entity .posY + entity .height ,
584+ entity .posZ + entity .width / 2 );
483585 aabb .expand (bordersize , bordersize , bordersize );
484586 MovingObjectPosition mop0 = aabb .calculateIntercept (pos , var8 );
485587
486- if (aabb .isVecInside (pos ))
487- {
488- if (0.0D < d || d == 0.0D )
489- {
588+ if (aabb .isVecInside (pos )) {
589+ if (0.0D < d || d == 0.0D ) {
490590 mopReturn .add (new MovingObjectPosition (entity ));
491591 d = 0.0D ;
492592 }
493- } else if (mop0 != null )
494- {
593+ } else if (mop0 != null ) {
495594 double d1 = pos .distanceTo (mop0 .hitVec );
496595
497- if (d1 < d || d == 0.0D )
498- {
596+ if (d1 < d || d == 0.0D ) {
499597 mopReturn .add (new MovingObjectPosition (entity ));
500598 d = d1 ;
501599 }
0 commit comments