Skip to content

Add "minecraft.spectatetp".#1729

Open
Mickey42302 wants to merge 22 commits into
PurpurMC:ver/26.2from
Mickey42302:spectatetp
Open

Add "minecraft.spectatetp".#1729
Mickey42302 wants to merge 22 commits into
PurpurMC:ver/26.2from
Mickey42302:spectatetp

Conversation

@Mickey42302

Copy link
Copy Markdown
Contributor

I would like to suggest the addition of a "minecraft.spectatetp" permission node. It would allow for control over whether or not people can teleport to others in Spectator mode.

This idea originates from BasicLandMC: https://github.com/Basic-Land/BasicLandMC/blob/6936acca0bd195f762e9c09e8899d382eacd0c12/basiclandmc-server/minecraft-patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch

@bobhenl

This comment was marked as spam.

@LuanBertozzi7 LuanBertozzi7 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good code🚀

@katekerllenevich

Copy link
Copy Markdown
Member

Please add a configuration option that would enable the requirement of this permission. We avoid making any changes that would automatically change any behavior from Paper.

@Mickey42302

Copy link
Copy Markdown
Contributor Author

I'll update the code. Does "spectator-teleport-permission" sound like an appropriate name for the configuration setting?

@ghost

ghost commented Feb 22, 2026

Copy link
Copy Markdown

"require-spectator-teleport-permission" sounds better to understand in my opinion

@katekerllenevich

Copy link
Copy Markdown
Member

"require-spectator-teleport-permission" sounds better to understand in my opinion

This is what I would go with as well.

@Mickey42302

Copy link
Copy Markdown
Contributor Author

I've added a configuration entry for the permission node. It is set to "false" by default.

Are any other changes needed? I apologise for the delay as well. I have a lot going on in real life.

@Mickey42302

Copy link
Copy Markdown
Contributor Author

I'm going to update the patches to make them work with Java Edition 26.2. This might take a bit.

@Mickey42302
Mickey42302 changed the base branch from ver/1.21.10 to ver/26.2 July 1, 2026 16:11

@granny granny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea, just some requested changes.

If you register the permission in the PurpurPermissions class in the registerPermissions() method as default true, you can avoid needing to specify a config option for this permission.

Please include a PR to PurpurDocs in the permissions page, and for the config option if we decide to keep it.

Comment on lines +27 to +50
- if (this.player.isSpectator()) {
- for (ServerLevel level : this.server.getAllLevels()) {
- Entity entity = packet.getEntity(level);
- if (entity != null) {
- this.player.teleportTo(level, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
- return;
+ if (org.purpurmc.purpur.PurpurConfig.requireSpectatorTeleportPermission) {
+ if (this.player.isSpectator() && this.player.getBukkitEntity().hasPermission("minecraft.spectatetp")) {
+ for (ServerLevel level : this.server.getAllLevels()) {
+ Entity entity = packet.getEntity(level);
+ if (entity != null) {
+ this.player.teleportTo(level, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
+ return;
+ }
+ }
+ }
+ } else {
+ if (this.player.isSpectator()) {
+ for (ServerLevel level : this.server.getAllLevels()) {
+ Entity entity = packet.getEntity(level);
+ if (entity != null) {
+ this.player.teleportTo(level, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
+ return;
+ }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty noisy diff for what it adds. Please reduce it to a maintainable level.

- this.player.teleportTo(level, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
- return;
+ if (org.purpurmc.purpur.PurpurConfig.requireSpectatorTeleportPermission) {
+ if (this.player.isSpectator() && this.player.getBukkitEntity().hasPermission("minecraft.spectatetp")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the permission name and i'm not sure about putting it under the "minecraft" perm root. Maybe purpur.spectator-can-teleport-to-players? Open to suggestions other than minecraft.spectatetp.

org.purpurmc.purpur.PurpurConfig.clampEnchantLevels = purpurConfiguration.getBoolean("settings.enchantment.clamp-levels", true);
org.purpurmc.purpur.PurpurConfig.registerMinecraftDebugCommands = purpurConfiguration.getBoolean("settings.register-minecraft-debug-commands"); // Purpur - register minecraft debug commands
org.purpurmc.purpur.PurpurConfig.registerMinecraftDisabledCommands = purpurConfiguration.getBoolean("settings.register-minecraft-disabled-commands"); // Purpur - register disabled minecraft commands
+ org.purpurmc.purpur.PurpurConfig.requireSpectatorTeleportPermission = purpurConfiguration.getBoolean("settings.require-spectator-teleport-permission"); // Purpur - require spectator teleport permission

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings.require-permission-spectator-teleport-to-players? 🤷

@Mickey42302

Copy link
Copy Markdown
Contributor Author

I updated the code. Before I submit a pull request to the PurpurDocs repository, I'd like to ask if this is what you're looking for?

@djohts

djohts commented Jul 20, 2026

Copy link
Copy Markdown

I updated the code. Before I submit a pull request to the PurpurDocs repository, I'd like to ask if this is what you're looking for?

pretty sure granny meant to modify the existing patch instead of adding another one on top of it that "makes code less noisy"

@kacimiamine

Copy link
Copy Markdown
Contributor

Yeah those patches are really wrong. You should update the current patch you did, the 0022- patch and make it less noisy (simpler and shorter)

@Mickey42302

Copy link
Copy Markdown
Contributor Author

Is this better?

+ // Purpur end - Add settings for enabling commands that are unavailable by default.
+
+ // Purpur start - Add setting which can be used to enable a permission node that controls the ability for spectators to teleport to other players.
+ org.purpurmc.purpur.PurpurConfig.requirePermissionSpectatorTeleportToPlayers = purpurConfiguration.getBoolean("settings.require-permission-spectator-teleport-to-players"); // Purpur - require permission spectator teleport to players

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should comment here with // Purpur instead of having // Purpur start and // Purpur end

- if (entity != null) {
- this.player.teleportTo(level, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
- return;
+ if (!org.purpurmc.purpur.PurpurConfig.requirePermissionSpectatorTeleportToPlayers || this.player.getBukkitEntity().hasPermission("purpur.spectator-can-teleport-to-players")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a // Purpur comment

@Mickey42302

Copy link
Copy Markdown
Contributor Author

The comments are updated now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants