Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Boolean> randomTeleport(ServerPlayer player, ServerLevel world) {
return randomTeleport(player, world, null);
Expand Down Expand Up @@ -109,7 +111,7 @@ public static Future<Boolean> 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);
Expand Down Expand Up @@ -184,11 +186,7 @@ public static boolean checkCooldown(ServerPlayer player, Map<String, Long> 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;
}
Expand All @@ -211,28 +209,19 @@ 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) {
if(isDangerBlock(world, mutableBlockPos) && isDangerBlock(world, mutableBlockPos.offset(0, 1, 0)) &&
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, Long> cooldowns = new HashMap<String, Long>();
private static final Map<String, Long> cooldowns = new HashMap<String, Long>();

public static void register(CommandDispatcher<CommandSourceStack> 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 ->
Expand All @@ -39,10 +40,10 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
));
}

private static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result<Biome> biome) {
public static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result<Biome> 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;
Expand All @@ -57,7 +58,7 @@ private static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result<Biome
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, p.serverLevel(), biomeKey);
randomTeleport(p, p.serverLevel(), biomeKey);
cooldowns.put(p.getName().getString(), System.currentTimeMillis());
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
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.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import static com.gmail.picono435.randomtp.api.RandomTPAPI.*;

public class RTPCommand {

private static Map<String, Long> cooldowns = new HashMap<String, Long>();
private static final Map<String, Long> cooldowns = new HashMap<String, Long>();

public static void register(CommandDispatcher<CommandSourceStack> 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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, Long> cooldowns = new HashMap<String, Long>();
private static final Map<String, Long> cooldowns = new HashMap<String, Long>();

public static void register(CommandDispatcher<CommandSourceStack> 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 ->
Expand All @@ -38,24 +38,24 @@ public static void register(CommandDispatcher<CommandSourceStack> 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;
} else {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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