Skip to content

Commit 4fb5cd3

Browse files
committed
Make commands public to ease reuse in other mod
1 parent 024db63 commit 4fb5cd3

File tree

6 files changed

+42
-44
lines changed

6 files changed

+42
-44
lines changed

common/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ dependencies {
66
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
77
// Do NOT use other classes from fabric loader
88
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
9+
compileOnly "net.luckperms:api:5.4"
10+
}
911

1012
implementation 'org.spongepowered:configurate-yaml:4.1.2'
1113
}

common/src/main/java/com/gmail/picono435/randomtp/commands/RTPBCommand.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.gmail.picono435.randomtp.commands;
22

3-
import com.gmail.picono435.randomtp.api.RandomTPAPI;
43
import com.gmail.picono435.randomtp.config.Config;
54
import com.gmail.picono435.randomtp.config.Messages;
65
import com.mojang.brigadier.CommandDispatcher;
@@ -18,19 +17,21 @@
1817
import java.util.HashMap;
1918
import java.util.Map;
2019

20+
import static com.gmail.picono435.randomtp.api.RandomTPAPI.*;
21+
2122
public class RTPBCommand {
2223

23-
private static Map<String, Long> cooldowns = new HashMap<String, Long>();
24+
private static final Map<String, Long> cooldowns = new HashMap<String, Long>();
2425

2526
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext) {
26-
dispatcher.register(Commands.literal("rtpb").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.interbiome"))
27+
dispatcher.register(Commands.literal("rtpb").requires(source -> hasPermission(source, "randomtp.command.interbiome"))
2728
.then(
2829
Commands.argument("biome", ResourceOrTagArgument.resourceOrTag(commandBuildContext, Registries.BIOME))
2930
.executes(context ->
3031
runCommand(context.getSource().getPlayerOrException(), ResourceOrTagArgument.getResourceOrTag(context, "biome", Registries.BIOME))
3132
)
3233
));
33-
dispatcher.register(Commands.literal("biomertp").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.interbiome"))
34+
dispatcher.register(Commands.literal("biomertp").requires(source -> hasPermission(source, "randomtp.command.interbiome"))
3435
.then(
3536
Commands.argument("biome", ResourceOrTagArgument.resourceOrTag(commandBuildContext, Registries.BIOME))
3637
.executes(context ->
@@ -39,10 +40,10 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
3940
));
4041
}
4142

42-
private static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result<Biome> biome) {
43+
public static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result<Biome> biome) {
4344
try {
44-
if(!RandomTPAPI.checkCooldown(p, cooldowns) && !RandomTPAPI.hasPermission(p, "randomtp.cooldown.exempt")) {
45-
long secondsLeft = RandomTPAPI.getCooldownLeft(p, cooldowns);
45+
if(!checkCooldown(p, cooldowns) && !hasPermission(p, "randomtp.cooldown.exempt")) {
46+
long secondsLeft = getCooldownLeft(p, cooldowns);
4647
Component cooldownmes = Component.literal(Messages.getCooldown().replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§"));
4748
p.sendSystemMessage(cooldownmes, false);
4849
return 1;
@@ -57,7 +58,7 @@ private static int runCommand(ServerPlayer p, ResourceOrTagArgument.Result<Biome
5758
if(Config.useOriginal()) {
5859
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("&", "§"));
5960
p.sendSystemMessage(finding, false);
60-
RandomTPAPI.randomTeleport(p, p.serverLevel(), biomeKey);
61+
randomTeleport(p, p.serverLevel(), biomeKey);
6162
cooldowns.put(p.getName().getString(), System.currentTimeMillis());
6263
return 1;
6364
}

common/src/main/java/com/gmail/picono435/randomtp/commands/RTPCommand.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
package com.gmail.picono435.randomtp.commands;
22

3-
import java.math.BigDecimal;
4-
import java.util.HashMap;
5-
import java.util.Map;
6-
7-
import com.gmail.picono435.randomtp.api.RandomTPAPI;
83
import com.gmail.picono435.randomtp.config.Config;
94
import com.gmail.picono435.randomtp.config.Messages;
105
import com.mojang.brigadier.CommandDispatcher;
11-
126
import net.minecraft.commands.CommandSourceStack;
137
import net.minecraft.commands.Commands;
148
import net.minecraft.network.chat.Component;
159
import net.minecraft.server.level.ServerPlayer;
1610

11+
import java.math.BigDecimal;
12+
import java.util.HashMap;
13+
import java.util.Map;
14+
15+
import static com.gmail.picono435.randomtp.api.RandomTPAPI.*;
16+
1717
public class RTPCommand {
1818

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

2121
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
22-
dispatcher.register(Commands.literal("rtp").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.basic"))
22+
dispatcher.register(Commands.literal("rtp").requires(source -> hasPermission(source, "randomtp.command.basic"))
2323
.executes(context -> runCommand(context.getSource().getPlayerOrException())
2424
));
25-
dispatcher.register(Commands.literal("randomtp").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.basic"))
25+
dispatcher.register(Commands.literal("randomtp").requires(source -> hasPermission(source, "randomtp.command.basic"))
2626
.executes(context -> runCommand(context.getSource().getPlayerOrException())
2727
));
2828
}
2929

30-
private static int runCommand(ServerPlayer p) {
30+
public static int runCommand(ServerPlayer p) {
3131
try {
32-
if(!RandomTPAPI.checkCooldown(p, cooldowns) && !RandomTPAPI.hasPermission(p, "randomtp.cooldown.exempt")) {
33-
long secondsLeft = RandomTPAPI.getCooldownLeft(p, cooldowns);
32+
if(!checkCooldown(p, cooldowns) && !hasPermission(p, "randomtp.cooldown.exempt")) {
33+
long secondsLeft = getCooldownLeft(p, cooldowns);
3434
Component cooldownmes = Component.literal(Messages.getCooldown().replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§"));
3535
p.sendSystemMessage(cooldownmes, false);
3636
return 1;
@@ -40,9 +40,9 @@ private static int runCommand(ServerPlayer p) {
4040
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("&", "§"));
4141
p.sendSystemMessage(finding, false);
4242
if(!Config.getDefaultWorld().equals("playerworld")) {
43-
RandomTPAPI.randomTeleport(p, RandomTPAPI.getWorld(Config.getDefaultWorld(), p.getServer()));
43+
randomTeleport(p, getWorld(Config.getDefaultWorld(), p.getServer()));
4444
} else {
45-
RandomTPAPI.randomTeleport(p, p.serverLevel());
45+
randomTeleport(p, p.serverLevel());
4646
}
4747
cooldowns.put(p.getName().getString(), System.currentTimeMillis());
4848
return 1;

common/src/main/java/com/gmail/picono435/randomtp/commands/RTPDCommand.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package com.gmail.picono435.randomtp.commands;
22

3-
import java.math.BigDecimal;
4-
import java.util.HashMap;
5-
import java.util.Map;
6-
7-
import com.gmail.picono435.randomtp.api.RandomTPAPI;
83
import com.gmail.picono435.randomtp.config.Config;
94
import com.gmail.picono435.randomtp.config.Messages;
105
import com.mojang.brigadier.CommandDispatcher;
11-
126
import net.minecraft.commands.CommandSourceStack;
137
import net.minecraft.commands.Commands;
148
import net.minecraft.commands.arguments.DimensionArgument;
@@ -17,19 +11,25 @@
1711
import net.minecraft.server.level.ServerPlayer;
1812
import net.minecraft.world.level.portal.TeleportTransition;
1913

14+
import java.math.BigDecimal;
15+
import java.util.HashMap;
16+
import java.util.Map;
17+
18+
import static com.gmail.picono435.randomtp.api.RandomTPAPI.*;
19+
2020
public class RTPDCommand {
2121

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

2424
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
25-
dispatcher.register(Commands.literal("rtpd").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.interdim"))
25+
dispatcher.register(Commands.literal("rtpd").requires(source -> hasPermission(source, "randomtp.command.interdim"))
2626
.then(
2727
Commands.argument("dimension", DimensionArgument.dimension())
2828
.executes(context ->
2929
runCommand(context.getSource().getPlayerOrException(), DimensionArgument.getDimension(context, "dimension"))
3030
)
3131
));
32-
dispatcher.register(Commands.literal("dimensionrtp").requires(source -> RandomTPAPI.hasPermission(source, "randomtp.command.interdim"))
32+
dispatcher.register(Commands.literal("dimensionrtp").requires(source -> hasPermission(source, "randomtp.command.interdim"))
3333
.then(
3434
Commands.argument("dimension", DimensionArgument.dimension())
3535
.executes(context ->
@@ -38,24 +38,24 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
3838
));
3939
}
4040

41-
private static int runCommand(ServerPlayer p, ServerLevel dim) {
41+
public static int runCommand(ServerPlayer p, ServerLevel dim) {
4242
try {
43-
if(!RandomTPAPI.checkCooldown(p, cooldowns) && !RandomTPAPI.hasPermission(p, "randomtp.cooldown.exempt")) {
44-
long secondsLeft = RandomTPAPI.getCooldownLeft(p, cooldowns);
43+
if(!checkCooldown(p, cooldowns) && !hasPermission(p, "randomtp.cooldown.exempt")) {
44+
long secondsLeft = getCooldownLeft(p, cooldowns);
4545
Component cooldownmes = Component.literal(Messages.getCooldown().replaceAll("\\{secondsLeft\\}", Long.toString(secondsLeft)).replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("&", "§"));
4646
p.sendSystemMessage(cooldownmes, false);
4747
return 1;
4848
} else {
4949
cooldowns.remove(p.getName().getString());
5050
String dimensionId = dim.dimension().location().getNamespace() + ":" + dim.dimension().location().getPath();
5151
if(!inWhitelist(dimensionId)) {
52-
p.sendSystemMessage(Component.literal(Messages.getDimensionNotAllowed().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{dimensionId\\}", dimensionId.toString()).replace('&', '§')), false);
52+
p.sendSystemMessage(Component.literal(Messages.getDimensionNotAllowed().replaceAll("\\{playerName\\}", p.getName().getString()).replaceAll("\\{dimensionId\\}", dimensionId).replace('&', '§')), false);
5353
return 1;
5454
}
5555
if(Config.useOriginal()) {
5656
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("&", "§"));
5757
p.sendSystemMessage(finding, false);
58-
RandomTPAPI.randomTeleport(p, dim);
58+
randomTeleport(p, dim);
5959
cooldowns.put(p.getName().getString(), System.currentTimeMillis());
6060
return 1;
6161
}

common/src/main/java/com/gmail/picono435/randomtp/data/ServerState.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
import net.minecraft.core.HolderLookup;
55
import net.minecraft.nbt.CompoundTag;
66
import net.minecraft.server.MinecraftServer;
7-
import net.minecraft.util.datafix.DataFixTypes;
87
import net.minecraft.world.entity.LivingEntity;
9-
import net.minecraft.world.level.ForcedChunksSavedData;
10-
import net.minecraft.world.level.Level;
118
import net.minecraft.world.level.saveddata.SavedData;
129
import net.minecraft.world.level.storage.DimensionDataStorage;
13-
import org.apache.logging.log4j.core.jmx.Server;
1410

1511
import java.util.HashMap;
1612
import java.util.UUID;
@@ -51,7 +47,7 @@ public static ServerState createFromNbt(CompoundTag compoundTag, HolderLookup.Pr
5147

5248
public static ServerState getServerState(MinecraftServer server) {
5349
DimensionDataStorage persistentStateManager = server
54-
.getLevel(Level.OVERWORLD).getDataStorage();
50+
.overworld().getDataStorage();
5551

5652
ServerState serverState = persistentStateManager.computeIfAbsent(
5753
new SavedData.Factory<>(ServerState::new, ServerState::createFromNbt, null),

gradle.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ org.gradle.daemon=false
44
enabled_platforms=fabric,neoforge,forge
55

66
archives_name=randomtp
7-
mod_version=9.0.1
7+
mod_version=9.1.0
88
maven_group=com.gmail.picono435
99

1010
minecraft_version=1.21.4
@@ -13,5 +13,4 @@ fabric_loader_version=0.16.9
1313
fabric_api_version=0.114.0
1414

1515
forge_version=54.0.16
16-
17-
neoforge_version=21.4.49-beta
16+
neoforge_version=21.4.136

0 commit comments

Comments
 (0)