2
2
3
3
import com .mojang .authlib .GameProfile ;
4
4
import com .mojang .brigadier .arguments .IntegerArgumentType ;
5
+ import com .mojang .brigadier .exceptions .CommandSyntaxException ;
5
6
import dev .architectury .event .EventResult ;
6
7
import dev .ftb .mods .ftbessentials .FTBEssentials ;
7
8
import dev .ftb .mods .ftbessentials .FTBEssentialsEvents ;
8
9
import dev .ftb .mods .ftbessentials .commands .CommandUtils ;
9
10
import dev .ftb .mods .ftbessentials .commands .FTBCommand ;
10
11
import dev .ftb .mods .ftbessentials .commands .SimpleConfigurableCommand ;
12
+ import dev .ftb .mods .ftbessentials .commands .impl .kit .KitCommand ;
11
13
import dev .ftb .mods .ftbessentials .commands .impl .teleporting .HomeCommand ;
12
14
import dev .ftb .mods .ftbessentials .commands .impl .teleporting .OfflineTeleportCommand ;
13
15
import dev .ftb .mods .ftbessentials .commands .impl .teleporting .TPACommand ;
@@ -89,7 +91,7 @@ public class TeleportingCommands {
89
91
90
92
// Jump to command, allows you to jump to the top of the block you're looking at
91
93
new SimpleConfigurableCommand (FTBEConfig .JUMP , Commands .literal ("jump" )
92
- .requires (CommandUtils .isGamemaster ())
94
+ .requires (CommandUtils .isGamemaster ())
93
95
.executes (ctx -> jump (ctx .getSource ())))
94
96
);
95
97
@@ -99,7 +101,7 @@ public static void register() {
99
101
private static int back (ServerPlayer player ) {
100
102
return FTBEPlayerData .getOrCreate (player ).map (data -> {
101
103
if (data .teleportHistory .isEmpty ()) {
102
- player .displayClientMessage (Component .literal ( "Teleportation history is empty! " ).withStyle (ChatFormatting .RED ), false );
104
+ player .displayClientMessage (Component .translatable ( "ftbessentials.teleport.history_empty " ).withStyle (ChatFormatting .RED ), false );
103
105
return 0 ;
104
106
}
105
107
@@ -122,15 +124,16 @@ private static int spawn(ServerPlayer player) {
122
124
//#region RTP
123
125
private static int rtp (ServerPlayer player , int minDistance , int maxDistance ) {
124
126
if (maxDistance < minDistance ) {
125
- player .displayClientMessage (Component .literal ( "Maximum teleport distance cannot be less than minimum! " ), false );
127
+ player .displayClientMessage (Component .translatable ( "ftbessentials. teleport.max_less_than_min " ), false );
126
128
return 0 ;
127
129
}
128
- if (!player .hasPermissions (2 ) && !DimensionFilter .isRtpDimensionOK (player .level ().dimension ())) {
129
- player .displayClientMessage (Component .literal ("You may not use /rtp in this dimension!" ).withStyle (ChatFormatting .RED ), false );
130
+ if ((!player .hasPermissions (Commands .LEVEL_GAMEMASTERS ) || !FTBEConfig .ADMINS_EXEMPT_DIMENSION_BLACKLISTS .get ())
131
+ && !DimensionFilter .isRtpDimensionOK (player .level ().dimension ())) {
132
+ player .displayClientMessage (Component .translatable ("ftbessentials.rtp.not_here" ).withStyle (ChatFormatting .RED ), false );
130
133
return 0 ;
131
134
}
132
135
return FTBEPlayerData .getOrCreate (player ).map (data -> data .rtpTeleporter .teleport (player , p -> {
133
- p .displayClientMessage (Component .literal ( "Looking for random location... " ), false );
136
+ p .displayClientMessage (Component .translatable ( "ftbessentials.rtp.looking " ), false );
134
137
return findBlockPos ((ServerLevel ) player .level (), p , minDistance , maxDistance );
135
138
}).runCommand (player ))
136
139
.orElse (0 );
@@ -152,7 +155,7 @@ private static TeleportPos findBlockPos(ServerLevel world, ServerPlayer player,
152
155
if (world .getBiome (currentPos ).is (IGNORE_RTP_BIOMES )) {
153
156
continue ;
154
157
}
155
- // TODO: FTB Chunks will listen to RTPEvent and cancel it if position is inside a claimed chunk
158
+ // FTB Chunks (via FTB XMod Compat) listens to this. Other mods can too.
156
159
EventResult res = FTBEssentialsEvents .RTP_EVENT .invoker ().teleport (world , player , currentPos , attempt );
157
160
if (res .isFalse ()) {
158
161
continue ;
@@ -177,12 +180,13 @@ private static TeleportPos findBlockPos(ServerLevel world, ServerPlayer player,
177
180
}
178
181
}
179
182
if (goodPos != null ) {
180
- player .displayClientMessage (Component .literal (String .format ("Found good location after %d " + (attempt == 1 ? "attempt" : "attempts" ) + " @ [x %d, y %d, z %d]" , attempt , goodPos .getX (), goodPos .getY (), goodPos .getZ ())), false );
183
+ String pos = String .format (" @ [x %d, y %d, z %d]" , goodPos .getX (), goodPos .getY (), goodPos .getZ ());
184
+ player .displayClientMessage (Component .translatable ("ftbessentials.rtp.found" , attempt + 1 , pos ), false );
181
185
return new TeleportPos (world .dimension (), goodPos .above ());
182
186
}
183
187
}
184
188
}
185
- player .displayClientMessage (Component .literal ( "Could not find a valid location to teleport to! " ).withStyle (ChatFormatting .RED ), false );
189
+ player .displayClientMessage (Component .translatable ( "ftbessentials.rtp.failed " ).withStyle (ChatFormatting .RED ), false );
186
190
return new TeleportPos (player );
187
191
}
188
192
//#endregion
@@ -210,25 +214,21 @@ private static int tpx(ServerPlayer player, ServerLevel to) {
210
214
return 1 ;
211
215
}
212
216
213
- private static int jump (CommandSourceStack source ) {
214
- try {
215
- ServerPlayer player = source .getPlayerOrException ();
216
-
217
- BlockHitResult res = BlockUtil .getFocusedBlock (player , player .getServer ().getPlayerList ().getViewDistance () * 16 )
218
- .orElseThrow (() -> new IllegalArgumentException ("Not looking at a block" ));
219
- // want to land the player on top of the focused block, so scan up as far as needed
220
- BlockPos .MutableBlockPos mPos = res .getBlockPos ().above ().mutable ();
221
- while (true ) {
222
- Level level = player .level ();
223
- if (isEmptyShape (level , mPos .above ()) && isEmptyShape (level , mPos .above (2 )) || mPos .getY () >= level .getMaxBuildHeight ())
224
- break ;
225
- mPos .move (Direction .UP , 2 );
226
- }
227
- Vec3 vec = Vec3 .atBottomCenterOf (mPos );
228
- player .teleportTo (vec .x (), vec .y (), vec .z ());
229
- } catch (Exception e ) {
230
- source .sendFailure (Component .literal ("Can't jump: " + e .getMessage ()));
217
+ private static int jump (CommandSourceStack source ) throws CommandSyntaxException {
218
+ ServerPlayer player = source .getPlayerOrException ();
219
+
220
+ BlockHitResult res = BlockUtil .getFocusedBlock (player , player .getServer ().getPlayerList ().getViewDistance () * 16 )
221
+ .orElseThrow (KitCommand .NOT_LOOKING_AT_BLOCK ::create );
222
+ // want to land the player on top of the focused block, so scan up as far as needed
223
+ BlockPos .MutableBlockPos mPos = res .getBlockPos ().above ().mutable ();
224
+ while (true ) {
225
+ Level level = player .level ();
226
+ if (isEmptyShape (level , mPos .above ()) && isEmptyShape (level , mPos .above (2 )) || mPos .getY () >= level .getMaxBuildHeight ())
227
+ break ;
228
+ mPos .move (Direction .UP , 2 );
231
229
}
230
+ Vec3 vec = Vec3 .atBottomCenterOf (mPos );
231
+ player .teleportTo (vec .x (), vec .y (), vec .z ());
232
232
return 0 ;
233
233
}
234
234
0 commit comments