11package com .gmail .picono435 .randomtp .commands ;
22
3- import java .math .BigDecimal ;
4- import java .util .HashMap ;
5- import java .util .Map ;
6-
7- import com .gmail .picono435 .randomtp .api .RandomTPAPI ;
83import com .gmail .picono435 .randomtp .config .Config ;
94import com .gmail .picono435 .randomtp .config .Messages ;
105import com .mojang .brigadier .CommandDispatcher ;
11-
126import net .minecraft .commands .CommandSourceStack ;
137import net .minecraft .commands .Commands ;
148import net .minecraft .commands .arguments .DimensionArgument ;
159import net .minecraft .network .chat .Component ;
1610import net .minecraft .server .level .ServerLevel ;
1711import net .minecraft .server .level .ServerPlayer ;
1812
13+ import java .math .BigDecimal ;
14+ import java .util .HashMap ;
15+ import java .util .Map ;
16+
17+ import static com .gmail .picono435 .randomtp .api .RandomTPAPI .*;
18+
1919public class RTPDCommand {
2020
21- private static Map <String , Long > cooldowns = new HashMap <String , Long >();
21+ private static final Map <String , Long > cooldowns = new HashMap <String , Long >();
2222
2323 public static void register (CommandDispatcher <CommandSourceStack > dispatcher ) {
24- dispatcher .register (Commands .literal ("rtpd" ).requires (source -> RandomTPAPI . hasPermission (source , "randomtp.command.interdim" ))
24+ dispatcher .register (Commands .literal ("rtpd" ).requires (source -> hasPermission (source , "randomtp.command.interdim" ))
2525 .then (
2626 Commands .argument ("dimension" , DimensionArgument .dimension ())
2727 .executes (context ->
2828 runCommand (context .getSource ().getPlayerOrException (), DimensionArgument .getDimension (context , "dimension" ))
2929 )
3030 ));
31- dispatcher .register (Commands .literal ("dimensionrtp" ).requires (source -> RandomTPAPI . hasPermission (source , "randomtp.command.interdim" ))
31+ dispatcher .register (Commands .literal ("dimensionrtp" ).requires (source -> hasPermission (source , "randomtp.command.interdim" ))
3232 .then (
3333 Commands .argument ("dimension" , DimensionArgument .dimension ())
3434 .executes (context ->
@@ -37,24 +37,24 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
3737 ));
3838 }
3939
40- private static int runCommand (ServerPlayer p , ServerLevel dim ) {
40+ public static int runCommand (ServerPlayer p , ServerLevel dim ) {
4141 try {
42- if (!RandomTPAPI . checkCooldown (p , cooldowns ) && !RandomTPAPI . hasPermission (p , "randomtp.cooldown.exempt" )) {
43- long secondsLeft = RandomTPAPI . getCooldownLeft (p , cooldowns );
42+ if (!checkCooldown (p , cooldowns ) && !hasPermission (p , "randomtp.cooldown.exempt" )) {
43+ long secondsLeft = getCooldownLeft (p , cooldowns );
4444 Component cooldownmes = Component .literal (Messages .getCooldown ().replaceAll ("\\ {secondsLeft\\ }" , Long .toString (secondsLeft )).replaceAll ("\\ {playerName\\ }" , p .getName ().getString ()).replaceAll ("&" , "§" ));
4545 p .sendSystemMessage (cooldownmes , false );
4646 return 1 ;
4747 } else {
4848 cooldowns .remove (p .getName ().getString ());
4949 String dimensionId = dim .dimension ().location ().getNamespace () + ":" + dim .dimension ().location ().getPath ();
5050 if (!inWhitelist (dimensionId )) {
51- p .sendSystemMessage (Component .literal (Messages .getDimensionNotAllowed ().replaceAll ("\\ {playerName\\ }" , p .getName ().getString ()).replaceAll ("\\ {dimensionId\\ }" , dimensionId . toString () ).replace ('&' , '§' )), false );
51+ p .sendSystemMessage (Component .literal (Messages .getDimensionNotAllowed ().replaceAll ("\\ {playerName\\ }" , p .getName ().getString ()).replaceAll ("\\ {dimensionId\\ }" , dimensionId ).replace ('&' , '§' )), false );
5252 return 1 ;
5353 }
5454 if (Config .useOriginal ()) {
5555 Component finding = Component .literal (Messages .getFinding ().replaceAll ("\\ {playerName\\ }" , p .getName ().getString ()).replaceAll ("\\ {blockX\\ }" , "" + (int )p .position ().x ).replaceAll ("\\ {blockY\\ }" , "" + (int )p .position ().y ).replaceAll ("\\ {blockZ\\ }" , "" + (int )p .position ().z ).replaceAll ("&" , "§" ));
5656 p .sendSystemMessage (finding , false );
57- RandomTPAPI . randomTeleport (p , dim );
57+ randomTeleport (p , dim );
5858 cooldowns .put (p .getName ().getString (), System .currentTimeMillis ());
5959 return 1 ;
6060 }
0 commit comments