diff --git a/common/build.gradle b/common/build.gradle index f8274d6..d88488c 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -6,6 +6,8 @@ dependencies { // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + compileOnly "net.luckperms:api:5.4" +} implementation 'org.spongepowered:configurate-yaml:4.1.2' } diff --git a/common/src/main/java/com/gmail/picono435/randomtp/api/RandomTPAPI.java b/common/src/main/java/com/gmail/picono435/randomtp/api/RandomTPAPI.java index 73e63df..1049b1f 100644 --- a/common/src/main/java/com/gmail/picono435/randomtp/api/RandomTPAPI.java +++ b/common/src/main/java/com/gmail/picono435/randomtp/api/RandomTPAPI.java @@ -9,7 +9,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; -import net.minecraft.network.chat.*; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; @@ -24,14 +24,16 @@ import net.minecraft.world.level.portal.TeleportTransition; import net.minecraft.world.phys.Vec3; -import java.util.*; +import java.util.Map; +import java.util.Random; +import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class RandomTPAPI { - private static ExecutorService executorService = Executors.newFixedThreadPool(10); + private static final ExecutorService executorService = Executors.newFixedThreadPool(10); public static Future randomTeleport(ServerPlayer player, ServerLevel world) { return randomTeleport(player, world, null); @@ -109,7 +111,7 @@ public static Future randomTeleport(ServerPlayer player, ServerLevel wo } player.getServer().submit(() -> { - TeleportTransition teleportTransition = new TeleportTransition(world, mutableBlockPos.getCenter(), Vec3.ZERO, player.getYRot(), player.getXRot(), false, false, Set.of(), null); + TeleportTransition teleportTransition = new TeleportTransition(world, mutableBlockPos.getCenter(), Vec3.ZERO, player.getYRot(), player.getXRot(), false, false, Set.of(), TeleportTransition.DO_NOTHING); player.teleport(teleportTransition); 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("&", "§")); player.sendSystemMessage(successful, false); @@ -184,11 +186,7 @@ public static boolean checkCooldown(ServerPlayer player, Map coold int cooldownTime = Config.getCooldown(); if(cooldowns.containsKey(player.getName().getString())) { long secondsLeft = ((cooldowns.get(player.getName().getString())/1000)+cooldownTime) - (System.currentTimeMillis()/1000); - if(secondsLeft > 0) { - return false; - } else { - return true; - } + return secondsLeft <= 0; } else { return true; } @@ -211,17 +209,11 @@ public static boolean hasPermission(CommandSourceStack source, String permission } public static boolean isSafe(ServerLevel world, BlockPos.MutableBlockPos mutableBlockPos) { - if (isEmpty(world, mutableBlockPos) && !isDangerBlocks(world, mutableBlockPos) && world.getWorldBorder().isWithinBounds(mutableBlockPos)) { - return true; - } - return false; + return isEmpty(world, mutableBlockPos) && !isDangerBlocks(world, mutableBlockPos) && world.getWorldBorder().isWithinBounds(mutableBlockPos); } public static boolean isEmpty(ServerLevel world, BlockPos.MutableBlockPos mutableBlockPos) { - if (world.isEmptyBlock(mutableBlockPos.offset(0, 1, 0)) && world.isEmptyBlock(mutableBlockPos)) { - return true; - } - return false; + return world.isEmptyBlock(mutableBlockPos.offset(0, 1, 0)) && world.isEmptyBlock(mutableBlockPos); } public static boolean isDangerBlocks(ServerLevel world, BlockPos.MutableBlockPos mutableBlockPos) { @@ -229,10 +221,7 @@ public static boolean isDangerBlocks(ServerLevel world, BlockPos.MutableBlockPos isDangerBlock(world, mutableBlockPos.offset(0, -1, 0))) { return true; } - if(world.getBlockState(mutableBlockPos.offset(0, -1, 0)).getBlock() != Blocks.AIR) { - return false; - } - return true; + return world.getBlockState(mutableBlockPos.offset(0, -1, 0)).getBlock() == Blocks.AIR; } public static boolean isDangerBlock(ServerLevel world, BlockPos mutableBlockPos) { diff --git a/common/src/main/java/com/gmail/picono435/randomtp/commands/RTPBCommand.java b/common/src/main/java/com/gmail/picono435/randomtp/commands/RTPBCommand.java index 118834a..1378d06 100644 --- a/common/src/main/java/com/gmail/picono435/randomtp/commands/RTPBCommand.java +++ b/common/src/main/java/com/gmail/picono435/randomtp/commands/RTPBCommand.java @@ -1,6 +1,5 @@ package com.gmail.picono435.randomtp.commands; -import com.gmail.picono435.randomtp.api.RandomTPAPI; import com.gmail.picono435.randomtp.config.Config; import com.gmail.picono435.randomtp.config.Messages; import com.mojang.brigadier.CommandDispatcher; @@ -18,19 +17,21 @@ import java.util.HashMap; import java.util.Map; +import static com.gmail.picono435.randomtp.api.RandomTPAPI.*; + public class RTPBCommand { - private static Map cooldowns = new HashMap(); + private static final Map cooldowns = new HashMap(); public static void register(CommandDispatcher dispatcher, CommandBuildContext commandBuildContext) { - dispatcher.register(Commands.literal("rtpb").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.interbiome")) + dispatcher.register(Commands.literal("rtpb").requires(source -> hasPermission(source, "randomtp.command.interbiome")) .then( Commands.argument("biome", ResourceOrTagArgument.resourceOrTag(commandBuildContext, Registries.BIOME)) .executes(context -> runCommand(context.getSource().getPlayerOrException(), ResourceOrTagArgument.getResourceOrTag(context, "biome", Registries.BIOME)) ) )); - dispatcher.register(Commands.literal("biomertp").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.interbiome")) + dispatcher.register(Commands.literal("biomertp").requires(source -> hasPermission(source, "randomtp.command.interbiome")) .then( Commands.argument("biome", ResourceOrTagArgument.resourceOrTag(commandBuildContext, Registries.BIOME)) .executes(context -> @@ -39,10 +40,10 @@ public static void register(CommandDispatcher dispatcher, Co )); } - private static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result biome) { + public static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result biome) { try { - if(!RandomTPAPI.checkCooldown(p, cooldowns) && !RandomTPAPI.hasPermission(p, "randomtp.cooldown.exempt")) { - long secondsLeft = RandomTPAPI.getCooldownLeft(p, cooldowns); + if(!checkCooldown(p, cooldowns) && !hasPermission(p, "randomtp.cooldown.exempt")) { + long secondsLeft = getCooldownLeft(p, cooldowns); Component cooldownmes = Component.literal(Messages.getCooldown().replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§")); p.sendSystemMessage(cooldownmes, false); return 1; @@ -57,7 +58,7 @@ private static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result cooldowns = new HashMap(); + private static final Map cooldowns = new HashMap(); public static void register(CommandDispatcher dispatcher) { - dispatcher.register(Commands.literal("rtp").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.basic")) + dispatcher.register(Commands.literal("rtp").requires(source -> hasPermission(source, "randomtp.command.basic")) .executes(context -> runCommand(context.getSource().getPlayerOrException()) )); - dispatcher.register(Commands.literal("randomtp").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.basic")) + dispatcher.register(Commands.literal("randomtp").requires(source -> hasPermission(source, "randomtp.command.basic")) .executes(context -> runCommand(context.getSource().getPlayerOrException()) )); } - private static int runCommand(ServerPlayer p) { + public static int runCommand(ServerPlayer p) { try { - if(!RandomTPAPI.checkCooldown(p, cooldowns) && !RandomTPAPI.hasPermission(p, "randomtp.cooldown.exempt")) { - long secondsLeft = RandomTPAPI.getCooldownLeft(p, cooldowns); + if(!checkCooldown(p, cooldowns) && !hasPermission(p, "randomtp.cooldown.exempt")) { + long secondsLeft = getCooldownLeft(p, cooldowns); Component cooldownmes = Component.literal(Messages.getCooldown().replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§")); p.sendSystemMessage(cooldownmes, false); return 1; @@ -40,9 +40,9 @@ private static int runCommand(ServerPlayer p) { 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("&", "§")); p.sendSystemMessage(finding, false); if(!Config.getDefaultWorld().equals("playerworld")) { - RandomTPAPI.randomTeleport(p, RandomTPAPI.getWorld(Config.getDefaultWorld(), p.getServer())); + randomTeleport(p, getWorld(Config.getDefaultWorld(), p.getServer())); } else { - RandomTPAPI.randomTeleport(p, p.serverLevel()); + randomTeleport(p, p.serverLevel()); } cooldowns.put(p.getName().getString(), System.currentTimeMillis()); return 1; diff --git a/common/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java b/common/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java index 91f2950..e931d3c 100644 --- a/common/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java +++ b/common/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java @@ -1,14 +1,8 @@ package com.gmail.picono435.randomtp.commands; -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Map; - -import com.gmail.picono435.randomtp.api.RandomTPAPI; import com.gmail.picono435.randomtp.config.Config; import com.gmail.picono435.randomtp.config.Messages; import com.mojang.brigadier.CommandDispatcher; - import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.DimensionArgument; @@ -17,19 +11,25 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.portal.TeleportTransition; +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; + +import static com.gmail.picono435.randomtp.api.RandomTPAPI.*; + public class RTPDCommand { - private static Map cooldowns = new HashMap(); + private static final Map cooldowns = new HashMap(); public static void register(CommandDispatcher dispatcher) { - dispatcher.register(Commands.literal("rtpd").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.interdim")) + dispatcher.register(Commands.literal("rtpd").requires(source -> hasPermission(source, "randomtp.command.interdim")) .then( Commands.argument("dimension", DimensionArgument.dimension()) .executes(context -> runCommand(context.getSource().getPlayerOrException(), DimensionArgument.getDimension(context, "dimension")) ) )); - dispatcher.register(Commands.literal("dimensionrtp").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.interdim")) + dispatcher.register(Commands.literal("dimensionrtp").requires(source -> hasPermission(source, "randomtp.command.interdim")) .then( Commands.argument("dimension", DimensionArgument.dimension()) .executes(context -> @@ -38,10 +38,10 @@ public static void register(CommandDispatcher dispatcher) { )); } - private static int runCommand(ServerPlayer p, ServerLevel dim) { + public static int runCommand(ServerPlayer p, ServerLevel dim) { try { - if(!RandomTPAPI.checkCooldown(p, cooldowns) && !RandomTPAPI.hasPermission(p, "randomtp.cooldown.exempt")) { - long secondsLeft = RandomTPAPI.getCooldownLeft(p, cooldowns); + if(!checkCooldown(p, cooldowns) && !hasPermission(p, "randomtp.cooldown.exempt")) { + long secondsLeft = getCooldownLeft(p, cooldowns); Component cooldownmes = Component.literal(Messages.getCooldown().replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§")); p.sendSystemMessage(cooldownmes, false); return 1; @@ -49,13 +49,13 @@ private static int runCommand(ServerPlayer p, ServerLevel dim) { cooldowns.remove(p.getName().getString()); String dimensionId = dim.dimension().location().getNamespace() + ":" + dim.dimension().location().getPath(); if(!inWhitelist(dimensionId)) { - p.sendSystemMessage(Component.literal(Messages.getDimensionNotAllowed().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{dimensionId\\}", dimensionId.toString()).replace('&', '§')), false); + p.sendSystemMessage(Component.literal(Messages.getDimensionNotAllowed().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{dimensionId\\}", dimensionId).replace('&', '§')), false); return 1; } if(Config.useOriginal()) { 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("&", "§")); p.sendSystemMessage(finding, false); - RandomTPAPI.randomTeleport(p, dim); + randomTeleport(p, dim); cooldowns.put(p.getName().getString(), System.currentTimeMillis()); return 1; } diff --git a/common/src/main/java/com/gmail/picono435/randomtp/data/ServerState.java b/common/src/main/java/com/gmail/picono435/randomtp/data/ServerState.java index c111cef..98f21f9 100644 --- a/common/src/main/java/com/gmail/picono435/randomtp/data/ServerState.java +++ b/common/src/main/java/com/gmail/picono435/randomtp/data/ServerState.java @@ -4,13 +4,9 @@ import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.datafix.DataFixTypes; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.level.ForcedChunksSavedData; -import net.minecraft.world.level.Level; import net.minecraft.world.level.saveddata.SavedData; import net.minecraft.world.level.storage.DimensionDataStorage; -import org.apache.logging.log4j.core.jmx.Server; import java.util.HashMap; import java.util.UUID; @@ -51,7 +47,7 @@ public static ServerState createFromNbt(CompoundTag compoundTag, HolderLookup.Pr public static ServerState getServerState(MinecraftServer server) { DimensionDataStorage persistentStateManager = server - .getLevel(Level.OVERWORLD).getDataStorage(); + .overworld().getDataStorage(); ServerState serverState = persistentStateManager.computeIfAbsent( new SavedData.Factory<>(ServerState::new, ServerState::createFromNbt, null), diff --git a/gradle.properties b/gradle.properties index d1883f2..b688d25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.daemon=false enabled_platforms=fabric,neoforge,forge archives_name=randomtp -mod_version=9.0.1 +mod_version=9.1.0 maven_group=com.gmail.picono435 minecraft_version=1.21.4 @@ -13,5 +13,4 @@ fabric_loader_version=0.16.9 fabric_api_version=0.114.0 forge_version=54.0.16 - -neoforge_version=21.4.49-beta +neoforge_version=21.4.136