2121import java .util .Map ;
2222import java .util .Objects ;
2323
24+ import static io .github .optijava .opt_carpet_addition .utils .McUtils .MINECRAFT_SERVER ;
25+
2426
2527public class PlayerTpCommand {
2628
2729 /* permit 1 request per 2 seconds < == > permit 0.5 request per 1 second */
2830 public static Map <ServerPlayer , RateLimiter > rateLimiterMap = new HashMap <>();
2931
30- private PlayerTpCommand () {}
31-
3232 private static final String COMMAND_PREFIX = "player" ;
33- private static final MinecraftServer server = CarpetServer .minecraft_server ;
3433
3534 public static void registerCommands (CommandDispatcher <CommandSourceStack > dispatcher ) {
3635 LiteralArgumentBuilder <CommandSourceStack > argumentBuilder = Commands .literal (COMMAND_PREFIX )
@@ -64,17 +63,17 @@ private static int teleport(CommandContext<CommandSourceStack> context) {
6463
6564 String target = StringArgumentType .getString (context , COMMAND_PREFIX );
6665
67- if (CarpetServer . minecraft_server .getPlayerList ().getPlayerByName (target ) == null ) {
66+ if (MINECRAFT_SERVER .getPlayerList ().getPlayerByName (target ) == null ) {
6867 Messenger .m (context .getSource (), "r No such player" );
6968 return 0 ;
7069 }
7170
72- if (context .getSource ().equals (server .createCommandSourceStack ())) {
71+ if (context .getSource ().equals (MINECRAFT_SERVER .createCommandSourceStack ())) {
7372 Messenger .m (context .getSource (), "r Console can't tp to player." );
7473 OptCarpetAddition .LOGGER .warn ("Console can't tp to player" );
7574 return 0 ;
7675 }
77- if (StringArgumentType .getString (context , COMMAND_PREFIX ).isEmpty () || target == null ) {
76+ if (StringArgumentType .getString (context , COMMAND_PREFIX ).isEmpty ()) {
7877 Messenger .m (context .getSource (), "r Invalid player name." );
7978 return 0 ;
8079 }
@@ -86,18 +85,18 @@ private static int teleport(CommandContext<CommandSourceStack> context) {
8685 /*final String commandSourcePlayerName = Objects.requireNonNull(context.getSource().getPlayer()).getGameProfile().getName();
8786 */ //?}
8887
89- if (server .getPlayerList ().getPlayerByName (target ) instanceof EntityPlayerMPFake ) {
88+ if (MINECRAFT_SERVER .getPlayerList ().getPlayerByName (target ) instanceof EntityPlayerMPFake ) {
9089
9190 switch (OptCarpetSettings .commandTpToFakePlayer ) {
92- case "true" -> executeTp (commandSourcePlayerName , context );
91+ case OptCarpetSettings . TRUE -> executeTp (commandSourcePlayerName , context );
9392 case "ops" -> {
9493 if (McUtils .isOp (context .getSource ().getPlayer ().getGameProfile ())) {
9594 executeTp (commandSourcePlayerName , context );
9695 } else {
9796 if (OptCarpetSettings .allowSpectatorTpToAnyPlayer && context .getSource ().getPlayer ().gameMode .getGameModeForPlayer ().equals (GameType .SPECTATOR )){
9897 executeTp (commandSourcePlayerName , context );
9998 } else {
100- Messenger .m (context .getSource (), "r You have no permission to teleport to fake player.You aren't op." );
99+ Messenger .m (context .getSource (), "r You have no permission to teleport to fake player. You aren't op." );
101100 }
102101 }
103102 }
@@ -111,17 +110,17 @@ private static int teleport(CommandContext<CommandSourceStack> context) {
111110 }
112111
113112 } else {
114-
113+ // TODO: "true"改为OCS.TRUE
115114 switch (OptCarpetSettings .allowTpToRealPlayer ) {
116- case "true" -> tp (commandSourcePlayerName , target );
115+ case OptCarpetSettings . TRUE -> tp (commandSourcePlayerName , target );
117116 case "ops" -> {
118117 if (McUtils .isOp (context .getSource ().getPlayer ().getGameProfile ())) {
119118 tp (commandSourcePlayerName , target );
120119 } else {
121120 if (OptCarpetSettings .allowSpectatorTpToAnyPlayer && context .getSource ().getPlayer ().gameMode .getGameModeForPlayer ().equals (GameType .SPECTATOR )) {
122121 executeTp (commandSourcePlayerName , context );
123122 } else {
124- Messenger .m (context .getSource (), "r You have no permission to teleport to real player.You aren't op." );
123+ Messenger .m (context .getSource (), "r You have no permission to teleport to real player. You aren't op." );
125124 }
126125 }
127126 }
@@ -150,18 +149,18 @@ private static int teleportHere(CommandContext<CommandSourceStack> context) {
150149
151150 String target = StringArgumentType .getString (context , COMMAND_PREFIX );
152151
153- if (server .getPlayerList ().getPlayerByName (target ) == null ) {
152+ if (MINECRAFT_SERVER .getPlayerList ().getPlayerByName (target ) == null ) {
154153 Messenger .m (context .getSource (), "r No such player" );
155154 return 0 ;
156155 }
157156
158- if (context .getSource ().equals (server .createCommandSourceStack ())) {
157+ if (context .getSource ().equals (MINECRAFT_SERVER .createCommandSourceStack ())) {
159158 Messenger .m (context .getSource (), "r Console can't tp here player." );
160159 OptCarpetAddition .LOGGER .warn ("Console can't tp here player" );
161160 return 0 ;
162161 }
163162
164- if (StringArgumentType .getString (context , COMMAND_PREFIX ).isEmpty () || target == null ) {
163+ if (StringArgumentType .getString (context , COMMAND_PREFIX ).isEmpty ()) {
165164 Messenger .m (context .getSource (), "r Invalid player name." );
166165 return 0 ;
167166 }
@@ -173,32 +172,32 @@ private static int teleportHere(CommandContext<CommandSourceStack> context) {
173172 /*final String commandSourcePlayerName = Objects.requireNonNull(context.getSource().getPlayer()).getGameProfile().getName();
174173 */ //?}
175174
176- if (server .getPlayerList ().getPlayerByName (target ) instanceof EntityPlayerMPFake ) {
175+ if (MINECRAFT_SERVER .getPlayerList ().getPlayerByName (target ) instanceof EntityPlayerMPFake ) {
177176
178177 switch (OptCarpetSettings .commandTpHereFakePlayer ) {
179- case "true" -> executeTpHere (commandSourcePlayerName , context );
178+ case OptCarpetSettings . TRUE -> executeTpHere (commandSourcePlayerName , context );
180179 case "ops" -> {
181180 if (McUtils .isOp (context .getSource ().getPlayer ().getGameProfile ())) {
182181 executeTpHere (commandSourcePlayerName , context );
183182 } else {
184- Messenger .m (context .getSource (), "r You have no permission to teleport here fake player.You aren't op." );
183+ Messenger .m (context .getSource (), "r You have no permission to teleport here fake player. You aren't op." );
185184 }
186185 }
187- case "false" -> Messenger .m (context .getSource (), "r Anybody can't teleport here fake player." );
186+ case OptCarpetSettings . FALSE -> Messenger .m (context .getSource (), "r Anybody can't teleport here fake player." );
188187 }
189188
190189 } else {
191190
192191 switch (OptCarpetSettings .allowTpHereRealPlayer ) {
193- case "true" -> tp (target , commandSourcePlayerName );
192+ case OptCarpetSettings . TRUE -> tp (target , commandSourcePlayerName );
194193 case "ops" -> {
195194 if (McUtils .isOp (context .getSource ().getPlayer ().getGameProfile ())) {
196195 tp (target , commandSourcePlayerName );
197196 } else {
198- Messenger .m (context .getSource (), "r You have no permission to teleport here real player.You aren't op." );
197+ Messenger .m (context .getSource (), "r You have no permission to teleport here real player. You aren't op." );
199198 }
200199 }
201- case "false" -> Messenger .m (context .getSource (), "r Anybody can't teleport here real player." );
200+ case OptCarpetSettings . FALSE -> Messenger .m (context .getSource (), "r Anybody can't teleport here real player." );
202201 }
203202
204203 }
@@ -266,7 +265,7 @@ private static boolean checkTpHereWhitelist(String name) {
266265 }
267266
268267 private static void tp (String target , String commandSourcePlayerName ) throws CommandSyntaxException {
269- Commands commands = server .getCommands ();
270- commands .getDispatcher ().execute (commands .getDispatcher ().parse ("tp " + target + " " + commandSourcePlayerName , server .createCommandSourceStack ()));
268+ Commands commands = MINECRAFT_SERVER .getCommands ();
269+ commands .getDispatcher ().execute (commands .getDispatcher ().parse ("tp " + target + " " + commandSourcePlayerName , MINECRAFT_SERVER .createCommandSourceStack ()));
271270 }
272271}
0 commit comments