Skip to content

Commit 1b08e7c

Browse files
committed
feat: allowSpectatorTpToAnyPlayer
1 parent d881245 commit 1b08e7c

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/main/java/io/github/optijava/opt_carpet_addition/OptCarpetSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,11 @@ public class OptCarpetSettings {
237237
options = {"true", "false", "ops"}
238238
)
239239
public static String commandLoggerBroadcastToPlayer = FALSE;
240+
241+
@Rule(
242+
desc = "allow spectator tp to any player!",
243+
category = {RuleCategory.FEATURE, RuleCategory.COMMAND},
244+
options = {"true", "false"}
245+
)
246+
public static boolean allowSpectatorTpToAnyPlayer = false;
240247
}

src/main/java/io/github/optijava/opt_carpet_addition/commands/PlayerTpCommand.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.minecraft.server.MinecraftServer;
1515
import net.minecraft.server.command.ServerCommandSource;
1616
import net.minecraft.server.network.ServerPlayerEntity;
17+
import net.minecraft.world.GameMode;
1718

1819
import java.util.HashMap;
1920
import java.util.Map;
@@ -91,11 +92,20 @@ private static int teleport(CommandContext<ServerCommandSource> context) {
9192
if ((server.getPlayerManager().isOperator(context.getSource().getPlayer().getGameProfile()))) {
9293
executeTp(commandSourcePlayerName, context, server);
9394
} else {
94-
Messenger.m(context.getSource(), "r You have no permission to teleport to fake player.You aren't op.");
95+
if (OptCarpetSettings.allowSpectatorTpToAnyPlayer && context.getSource().getPlayer().interactionManager.getGameMode().equals(GameMode.SPECTATOR)){
96+
executeTp(commandSourcePlayerName, context, server);
97+
} else {
98+
Messenger.m(context.getSource(), "r You have no permission to teleport to fake player.You aren't op.");
99+
}
95100
}
96101
}
97-
case OptCarpetSettings.FALSE ->
102+
case OptCarpetSettings.FALSE -> {
103+
if (OptCarpetSettings.allowSpectatorTpToAnyPlayer && context.getSource().getPlayer().interactionManager.getGameMode().equals(GameMode.SPECTATOR)){
104+
executeTp(commandSourcePlayerName, context, server);
105+
} else {
98106
Messenger.m(context.getSource(), "r Anybody can't teleport to fake player.");
107+
}
108+
}
99109
}
100110

101111
} else {
@@ -107,11 +117,20 @@ private static int teleport(CommandContext<ServerCommandSource> context) {
107117
if ((server.getPlayerManager().isOperator(context.getSource().getPlayer().getGameProfile()))) {
108118
server.getCommandManager().getDispatcher().execute(server.getCommandManager().getDispatcher().parse("tp " + commandSourcePlayerName + " " + target, server.getCommandSource()));
109119
} else {
110-
Messenger.m(context.getSource(), "r You have no permission to teleport to real player.You aren't op.");
120+
if (OptCarpetSettings.allowSpectatorTpToAnyPlayer && context.getSource().getPlayer().interactionManager.getGameMode().equals(GameMode.SPECTATOR)){
121+
executeTp(commandSourcePlayerName, context, server);
122+
} else {
123+
Messenger.m(context.getSource(), "r You have no permission to teleport to real player.You aren't op.");
124+
}
111125
}
112126
}
113-
case OptCarpetSettings.FALSE ->
114-
Messenger.m(context.getSource(), "r Anybody can't teleport to real player.");
127+
case OptCarpetSettings.FALSE -> {
128+
if (OptCarpetSettings.allowSpectatorTpToAnyPlayer && context.getSource().getPlayer().interactionManager.getGameMode().equals(GameMode.SPECTATOR)){
129+
executeTp(commandSourcePlayerName, context, server);
130+
} else {
131+
Messenger.m(context.getSource(), "r Anybody can't teleport to real player.");
132+
}
133+
}
115134
}
116135

117136
}

0 commit comments

Comments
 (0)