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 ;
1711import net .minecraft .server .level .ServerPlayer ;
1812import net .minecraft .world .level .portal .TeleportTransition ;
1913
14+ import java .math .BigDecimal ;
15+ import java .util .HashMap ;
16+ import java .util .Map ;
17+
18+ import static com .gmail .picono435 .randomtp .api .RandomTPAPI .*;
19+
2020public class RTPDCommand {
2121
22- private static Map <String , Long > cooldowns = new HashMap <String , Long >();
22+ private static final Map <String , Long > cooldowns = new HashMap <String , Long >();
2323
2424 public static void register (CommandDispatcher <CommandSourceStack > dispatcher ) {
25- dispatcher .register (Commands .literal ("rtpd" ).requires (source -> RandomTPAPI . hasPermission (source , "randomtp.command.interdim" ))
25+ dispatcher .register (Commands .literal ("rtpd" ).requires (source -> hasPermission (source , "randomtp.command.interdim" ))
2626 .then (
2727 Commands .argument ("dimension" , DimensionArgument .dimension ())
2828 .executes (context ->
2929 runCommand (context .getSource ().getPlayerOrException (), DimensionArgument .getDimension (context , "dimension" ))
3030 )
3131 ));
32- dispatcher .register (Commands .literal ("dimensionrtp" ).requires (source -> RandomTPAPI . hasPermission (source , "randomtp.command.interdim" ))
32+ dispatcher .register (Commands .literal ("dimensionrtp" ).requires (source -> hasPermission (source , "randomtp.command.interdim" ))
3333 .then (
3434 Commands .argument ("dimension" , DimensionArgument .dimension ())
3535 .executes (context ->
@@ -38,24 +38,24 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
3838 ));
3939 }
4040
41- private static int runCommand (ServerPlayer p , ServerLevel dim ) {
41+ public static int runCommand (ServerPlayer p , ServerLevel dim ) {
4242 try {
43- if (!RandomTPAPI . checkCooldown (p , cooldowns ) && !RandomTPAPI . hasPermission (p , "randomtp.cooldown.exempt" )) {
44- long secondsLeft = RandomTPAPI . getCooldownLeft (p , cooldowns );
43+ if (!checkCooldown (p , cooldowns ) && !hasPermission (p , "randomtp.cooldown.exempt" )) {
44+ long secondsLeft = getCooldownLeft (p , cooldowns );
4545 Component cooldownmes = Component .literal (Messages .getCooldown ().replaceAll ("\\ {secondsLeft\\ }" , Long .toString (secondsLeft )).replaceAll ("\\ {playerName\\ }" , p .getName ().getString ()).replaceAll ("&" , "§" ));
4646 p .sendSystemMessage (cooldownmes , false );
4747 return 1 ;
4848 } else {
4949 cooldowns .remove (p .getName ().getString ());
5050 String dimensionId = dim .dimension ().location ().getNamespace () + ":" + dim .dimension ().location ().getPath ();
5151 if (!inWhitelist (dimensionId )) {
52- p .sendSystemMessage (Component .literal (Messages .getDimensionNotAllowed ().replaceAll ("\\ {playerName\\ }" , p .getName ().getString ()).replaceAll ("\\ {dimensionId\\ }" , dimensionId . toString () ).replace ('&' , '§' )), false );
52+ p .sendSystemMessage (Component .literal (Messages .getDimensionNotAllowed ().replaceAll ("\\ {playerName\\ }" , p .getName ().getString ()).replaceAll ("\\ {dimensionId\\ }" , dimensionId ).replace ('&' , '§' )), false );
5353 return 1 ;
5454 }
5555 if (Config .useOriginal ()) {
5656 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 ("&" , "§" ));
5757 p .sendSystemMessage (finding , false );
58- RandomTPAPI . randomTeleport (p , dim );
58+ randomTeleport (p , dim );
5959 cooldowns .put (p .getName ().getString (), System .currentTimeMillis ());
6060 return 1 ;
6161 }
0 commit comments