Skip to content

Commit 024db63

Browse files
committed
Fix NullPointer on TeleportTransition
1 parent ae72bd5 commit 024db63

1 file changed

Lines changed: 10 additions & 21 deletions

File tree

common/src/main/java/com/gmail/picono435/randomtp/api/RandomTPAPI.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import net.minecraft.core.BlockPos;
1010
import net.minecraft.core.Holder;
1111
import net.minecraft.core.registries.Registries;
12-
import net.minecraft.network.chat.*;
12+
import net.minecraft.network.chat.Component;
1313
import net.minecraft.resources.ResourceKey;
1414
import net.minecraft.resources.ResourceLocation;
1515
import net.minecraft.server.MinecraftServer;
@@ -24,14 +24,16 @@
2424
import net.minecraft.world.level.portal.TeleportTransition;
2525
import net.minecraft.world.phys.Vec3;
2626

27-
import java.util.*;
27+
import java.util.Map;
28+
import java.util.Random;
29+
import java.util.Set;
2830
import java.util.concurrent.ExecutorService;
2931
import java.util.concurrent.Executors;
3032
import java.util.concurrent.Future;
3133

3234
public class RandomTPAPI {
3335

34-
private static ExecutorService executorService = Executors.newFixedThreadPool(10);
36+
private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
3537

3638
public static Future<Boolean> randomTeleport(ServerPlayer player, ServerLevel world) {
3739
return randomTeleport(player, world, null);
@@ -109,7 +111,7 @@ public static Future<Boolean> randomTeleport(ServerPlayer player, ServerLevel wo
109111
}
110112

111113
player.getServer().submit(() -> {
112-
TeleportTransition teleportTransition = new TeleportTransition(world, mutableBlockPos.getCenter(), Vec3.ZERO, player.getYRot(), player.getXRot(), false, false, Set.of(), null);
114+
TeleportTransition teleportTransition = new TeleportTransition(world, mutableBlockPos.getCenter(), Vec3.ZERO, player.getYRot(), player.getXRot(), false, false, Set.of(), TeleportTransition.DO_NOTHING);
113115
player.teleport(teleportTransition);
114116
Component successful = Component.literal(Messages.getSuccessful().replaceAll("\\{playerName\\}", player.getName().getString()).replaceAll("\\{blockX\\}", "" + (int)player.position().x).replaceAll("\\{blockY\\}", "" + (int)player.position().y).replaceAll("\\{blockZ\\}", "" + (int)player.position().z).replaceAll("&", "§"));
115117
player.sendSystemMessage(successful, false);
@@ -184,11 +186,7 @@ public static boolean checkCooldown(ServerPlayer player, Map<String, Long> coold
184186
int cooldownTime = Config.getCooldown();
185187
if(cooldowns.containsKey(player.getName().getString())) {
186188
long secondsLeft = ((cooldowns.get(player.getName().getString())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
187-
if(secondsLeft > 0) {
188-
return false;
189-
} else {
190-
return true;
191-
}
189+
return secondsLeft <= 0;
192190
} else {
193191
return true;
194192
}
@@ -211,28 +209,19 @@ public static boolean hasPermission(CommandSourceStack source, String permission
211209
}
212210

213211
public static boolean isSafe(ServerLevel world, BlockPos.MutableBlockPos mutableBlockPos) {
214-
if (isEmpty(world, mutableBlockPos) && !isDangerBlocks(world, mutableBlockPos) && world.getWorldBorder().isWithinBounds(mutableBlockPos)) {
215-
return true;
216-
}
217-
return false;
212+
return isEmpty(world, mutableBlockPos) && !isDangerBlocks(world, mutableBlockPos) && world.getWorldBorder().isWithinBounds(mutableBlockPos);
218213
}
219214

220215
public static boolean isEmpty(ServerLevel world, BlockPos.MutableBlockPos mutableBlockPos) {
221-
if (world.isEmptyBlock(mutableBlockPos.offset(0, 1, 0)) && world.isEmptyBlock(mutableBlockPos)) {
222-
return true;
223-
}
224-
return false;
216+
return world.isEmptyBlock(mutableBlockPos.offset(0, 1, 0)) && world.isEmptyBlock(mutableBlockPos);
225217
}
226218

227219
public static boolean isDangerBlocks(ServerLevel world, BlockPos.MutableBlockPos mutableBlockPos) {
228220
if(isDangerBlock(world, mutableBlockPos) && isDangerBlock(world, mutableBlockPos.offset(0, 1, 0)) &&
229221
isDangerBlock(world, mutableBlockPos.offset(0, -1, 0))) {
230222
return true;
231223
}
232-
if(world.getBlockState(mutableBlockPos.offset(0, -1, 0)).getBlock() != Blocks.AIR) {
233-
return false;
234-
}
235-
return true;
224+
return world.getBlockState(mutableBlockPos.offset(0, -1, 0)).getBlock() == Blocks.AIR;
236225
}
237226

238227
public static boolean isDangerBlock(ServerLevel world, BlockPos mutableBlockPos) {

0 commit comments

Comments
 (0)