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
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,34 +1,34 @@
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;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
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 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 @@ -37,24 +37,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
2 changes: 1 addition & 1 deletion 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=8.1.0
mod_version=8.2.0
maven_group=com.gmail.picono435

minecraft_version=1.20.6
Expand Down