@@ -69,73 +69,71 @@ public boolean persist() {
6969 public String onPlaceholderRequest (Player player , @ NotNull String input ) {
7070 String [] elements = input .split ("_" );
7171
72- switch (elements [0 ]) {
73- case "balancetop" -> {
74- int place ;
75- try {
76- int index ;
77- if (elements .length == 2 && elements [1 ].startsWith ("#" ))
78- index = 1 ;
79- else if (elements .length == 3 && elements [2 ].startsWith ("#" ))
80- index = 2 ;
81- else
72+ try {
73+ switch (elements [0 ]) {
74+ case "balancetop" -> {
75+ int place ;
76+ try {
77+ int index ;
78+ if (elements .length == 2 && elements [1 ].startsWith ("#" ))
79+ index = 1 ;
80+ else if (elements .length == 3 && elements [2 ].startsWith ("#" ))
81+ index = 2 ;
82+ else
83+ return null ;
84+ place = Integer .parseInt (elements [index ].substring (1 )) - 1 ;
85+ } catch (NumberFormatException exception ) {
86+ new Debug .QualityError ("Invalid input for \" balancetop_#<integer>\" : " + input , exception ).log ();
8287 return null ;
83- place = Integer .parseInt (elements [index ].substring (1 )) - 1 ;
84- } catch (NumberFormatException exception ) {
85- new Debug .QualityError ("Invalid input for \" balancetop_#<integer>\" : " + input , exception ).log ();
86- return null ;
88+ }
89+ if (place == -1 || BalanceTopCommand .orderedPlayerList .size () < place + 1 )
90+ return "N/A" ;
91+ if (elements [1 ].equals ("balance" ))
92+ return Number .format (BalanceTopCommand .orderedPlayerList .get (place ).getBalance (), Number .FormatType .NORMAL );
93+ else
94+ return BalanceTopCommand .orderedPlayerList .get (place ).getUsername ();
95+ }
96+ case "balance" -> {
97+ UUID uuid = grabUUID (elements , player , 1 );
98+ return Number .format (QualityEconomyAPI .getBalance (uuid ), Number .FormatType .NORMAL );
99+ }
100+ case "cbalance" -> {
101+ if (!Configuration .isCustomCurrenciesEnabled ())
102+ return "Feature is disabled" ;
103+ if (!QualityEconomyAPI .doesCustomCurrencyExist (elements [1 ]))
104+ return "Currency does not exist" ;
105+ UUID uuid = grabUUID (elements , player , 2 );
106+ return Number .format (QualityEconomyAPI .getCustomBalance (uuid , elements [1 ]), Number .FormatType .NORMAL );
107+ }
108+ case "isPayable" -> {
109+ UUID uuid = grabUUID (elements , player , 1 );
110+ return String .valueOf (QualityEconomyAPI .isPayable (uuid ));
111+ }
112+ case "isRequestable" -> {
113+ UUID uuid = grabUUID (elements , player , 1 );
114+ return String .valueOf (QualityEconomyAPI .isRequestable (uuid ));
87115 }
88- if (place == -1 || BalanceTopCommand .orderedPlayerList .size () < place + 1 )
89- return "N/A" ;
90- if (elements [1 ].equals ("balance" ))
91- return Number .format (BalanceTopCommand .orderedPlayerList .get (place ).getBalance (), Number .FormatType .NORMAL );
92- else
93- return BalanceTopCommand .orderedPlayerList .get (place ).getUsername ();
94- }
95- case "balance" -> {
96- UUID uuid = grabUUID (elements , player , 1 );
97- if (uuid == null )
98- return null ;
99- return Number .format (QualityEconomyAPI .getBalance (uuid ), Number .FormatType .NORMAL );
100- }
101- case "cbalance" -> {
102- if (!Configuration .isCustomCurrenciesEnabled ())
103- return "Feature is disabled" ;
104- if (!QualityEconomyAPI .doesCustomCurrencyExist (elements [1 ]))
105- return "Currency does not exist" ;
106- UUID uuid = grabUUID (elements , player , 2 );
107- if (uuid == null )
108- return null ;
109- return Number .format (QualityEconomyAPI .getCustomBalance (uuid , elements [1 ]), Number .FormatType .NORMAL );
110- }
111- case "isPayable" -> {
112- UUID uuid = grabUUID (elements , player , 1 );
113- if (uuid == null )
114- return null ;
115- return String .valueOf (QualityEconomyAPI .isPayable (uuid ));
116- }
117- case "isRequestable" -> {
118- UUID uuid = grabUUID (elements , player , 1 );
119- if (uuid == null )
120- return null ;
121- return String .valueOf (QualityEconomyAPI .isRequestable (uuid ));
122116 }
117+ } catch (Exception ignored ) {
118+ return null ;
123119 }
124120
125121 return null ;
126122 }
127123
128- private UUID grabUUID (String [] elements , Player player , int index ) {
124+ private @ NotNull UUID grabUUID (String [] elements , Player player , int index ) throws Exception {
129125 UUID uuid = null ;
130126 if (elements .length == index + 1 ) {
131127 if (Misc .isUUID (elements [index ])) {
132128 uuid = UUID .fromString (elements [index ]);
133129 } else {
134- uuid = Bukkit .getOfflinePlayer (elements [index + 1 ]).getUniqueId ();
130+ uuid = Bukkit .getOfflinePlayer (elements [index ]).getUniqueId ();
135131 }
136132 } else if (elements .length == index ) {
137133 uuid = player .getUniqueId ();
138134 }
135+ if (uuid == null )
136+ throw new Exception ();
139137 return uuid ;
140138 }
141139
0 commit comments