diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/server/commands/TeleportCommand.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/server/commands/TeleportCommand.java.patch | 408 |
1 files changed, 408 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/server/commands/TeleportCommand.java.patch b/patch-remap/mache-vineflower/net/minecraft/server/commands/TeleportCommand.java.patch new file mode 100644 index 0000000000..cd02501708 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/server/commands/TeleportCommand.java.patch @@ -0,0 +1,408 @@ +--- a/net/minecraft/server/commands/TeleportCommand.java ++++ b/net/minecraft/server/commands/TeleportCommand.java +@@ -1,18 +1,19 @@ + package net.minecraft.server.commands; + + import com.mojang.brigadier.CommandDispatcher; +-import com.mojang.brigadier.context.CommandContext; ++import com.mojang.brigadier.builder.LiteralArgumentBuilder; ++import com.mojang.brigadier.builder.RequiredArgumentBuilder; + import com.mojang.brigadier.exceptions.CommandSyntaxException; + import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; + import com.mojang.brigadier.tree.LiteralCommandNode; + import java.util.Collection; + import java.util.Collections; + import java.util.EnumSet; ++import java.util.Iterator; + import java.util.Locale; + import java.util.Set; + import javax.annotation.Nullable; + import net.minecraft.commands.CommandSourceStack; +-import net.minecraft.commands.Commands; + import net.minecraft.commands.arguments.EntityAnchorArgument; + import net.minecraft.commands.arguments.EntityArgument; + import net.minecraft.commands.arguments.coordinates.Coordinates; +@@ -31,173 +32,72 @@ + import net.minecraft.world.level.Level; + import net.minecraft.world.phys.Vec2; + import net.minecraft.world.phys.Vec3; ++// CraftBukkit start ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.CraftWorld; ++import org.bukkit.event.entity.EntityTeleportEvent; ++import org.bukkit.event.player.PlayerTeleportEvent; ++// CraftBukkit end + + public class TeleportCommand { +- private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType( +- Component.translatable("commands.teleport.invalidPosition") +- ); + ++ private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(Component.translatable("commands.teleport.invalidPosition")); ++ ++ public TeleportCommand() {} ++ + public static void register(CommandDispatcher<CommandSourceStack> dispatcher) { +- LiteralCommandNode<CommandSourceStack> literalCommandNode = dispatcher.register( +- Commands.literal("teleport") +- .requires(source -> source.hasPermission(2)) +- .then( +- Commands.argument("location", Vec3Argument.vec3()) +- .executes( +- context -> teleportToPos( +- context.getSource(), +- Collections.singleton(context.getSource().getEntityOrException()), +- context.getSource().getLevel(), +- Vec3Argument.getCoordinates(context, "location"), +- WorldCoordinates.current(), +- null +- ) +- ) +- ) +- .then( +- Commands.argument("destination", EntityArgument.entity()) +- .executes( +- context -> teleportToEntity( +- context.getSource(), +- Collections.singleton(context.getSource().getEntityOrException()), +- EntityArgument.getEntity(context, "destination") +- ) +- ) +- ) +- .then( +- Commands.argument("targets", EntityArgument.entities()) +- .then( +- Commands.argument("location", Vec3Argument.vec3()) +- .executes( +- context -> teleportToPos( +- context.getSource(), +- EntityArgument.getEntities(context, "targets"), +- context.getSource().getLevel(), +- Vec3Argument.getCoordinates(context, "location"), +- null, +- null +- ) +- ) +- .then( +- Commands.argument("rotation", RotationArgument.rotation()) +- .executes( +- context -> teleportToPos( +- context.getSource(), +- EntityArgument.getEntities(context, "targets"), +- context.getSource().getLevel(), +- Vec3Argument.getCoordinates(context, "location"), +- RotationArgument.getRotation(context, "rotation"), +- null +- ) +- ) +- ) +- .then( +- Commands.literal("facing") +- .then( +- Commands.literal("entity") +- .then( +- Commands.argument("facingEntity", EntityArgument.entity()) +- .executes( +- context -> teleportToPos( +- context.getSource(), +- EntityArgument.getEntities(context, "targets"), +- context.getSource().getLevel(), +- Vec3Argument.getCoordinates(context, "location"), +- null, +- new TeleportCommand.LookAt( +- EntityArgument.getEntity(context, "facingEntity"), EntityAnchorArgument.Anchor.FEET +- ) +- ) +- ) +- .then( +- Commands.argument("facingAnchor", EntityAnchorArgument.anchor()) +- .executes( +- context -> teleportToPos( +- context.getSource(), +- EntityArgument.getEntities(context, "targets"), +- context.getSource().getLevel(), +- Vec3Argument.getCoordinates(context, "location"), +- null, +- new TeleportCommand.LookAt( +- EntityArgument.getEntity(context, "facingEntity"), +- EntityAnchorArgument.getAnchor(context, "facingAnchor") +- ) +- ) +- ) +- ) +- ) +- ) +- .then( +- Commands.argument("facingLocation", Vec3Argument.vec3()) +- .executes( +- context -> teleportToPos( +- context.getSource(), +- EntityArgument.getEntities(context, "targets"), +- context.getSource().getLevel(), +- Vec3Argument.getCoordinates(context, "location"), +- null, +- new TeleportCommand.LookAt(Vec3Argument.getVec3(context, "facingLocation")) +- ) +- ) +- ) +- ) +- ) +- .then( +- Commands.argument("destination", EntityArgument.entity()) +- .executes( +- context -> teleportToEntity( +- context.getSource(), +- EntityArgument.getEntities(context, "targets"), +- EntityArgument.getEntity(context, "destination") +- ) +- ) +- ) +- ) +- ); +- dispatcher.register(Commands.literal("tp").requires(source -> source.hasPermission(2)).redirect(literalCommandNode)); ++ LiteralCommandNode<CommandSourceStack> literalcommandnode = dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("teleport").requires((commandlistenerwrapper) -> { ++ return commandlistenerwrapper.hasPermission(2); ++ })).then(net.minecraft.commands.Commands.argument("location", Vec3Argument.vec3()).executes((commandcontext) -> { ++ return teleportToPos((CommandSourceStack) commandcontext.getSource(), Collections.singleton(((CommandSourceStack) commandcontext.getSource()).getEntityOrException()), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), WorldCoordinates.current(), (TeleportCommand.LookAt) null); ++ }))).then(net.minecraft.commands.Commands.argument("destination", EntityArgument.entity()).executes((commandcontext) -> { ++ return teleportToEntity((CommandSourceStack) commandcontext.getSource(), Collections.singleton(((CommandSourceStack) commandcontext.getSource()).getEntityOrException()), EntityArgument.getEntity(commandcontext, "destination")); ++ }))).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("targets", EntityArgument.entities()).then(((RequiredArgumentBuilder) ((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("location", Vec3Argument.vec3()).executes((commandcontext) -> { ++ return teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), (Coordinates) null, (TeleportCommand.LookAt) null); ++ })).then(net.minecraft.commands.Commands.argument("rotation", RotationArgument.rotation()).executes((commandcontext) -> { ++ return teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), RotationArgument.getRotation(commandcontext, "rotation"), (TeleportCommand.LookAt) null); ++ }))).then(((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("facing").then(net.minecraft.commands.Commands.literal("entity").then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("facingEntity", EntityArgument.entity()).executes((commandcontext) -> { ++ return teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), (Coordinates) null, new TeleportCommand.LookAt(EntityArgument.getEntity(commandcontext, "facingEntity"), EntityAnchorArgument.Anchor.FEET)); ++ })).then(net.minecraft.commands.Commands.argument("facingAnchor", EntityAnchorArgument.anchor()).executes((commandcontext) -> { ++ return teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), (Coordinates) null, new TeleportCommand.LookAt(EntityArgument.getEntity(commandcontext, "facingEntity"), EntityAnchorArgument.getAnchor(commandcontext, "facingAnchor"))); ++ }))))).then(net.minecraft.commands.Commands.argument("facingLocation", Vec3Argument.vec3()).executes((commandcontext) -> { ++ return teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), (Coordinates) null, new TeleportCommand.LookAt(Vec3Argument.getVec3(commandcontext, "facingLocation"))); ++ }))))).then(net.minecraft.commands.Commands.argument("destination", EntityArgument.entity()).executes((commandcontext) -> { ++ return teleportToEntity((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), EntityArgument.getEntity(commandcontext, "destination")); ++ })))); ++ ++ dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("tp").requires((commandlistenerwrapper) -> { ++ return commandlistenerwrapper.hasPermission(2); ++ })).redirect(literalcommandnode)); + } + + private static int teleportToEntity(CommandSourceStack source, Collection<? extends Entity> targets, Entity destination) throws CommandSyntaxException { +- for (Entity entity : targets) { +- performTeleport( +- source, +- entity, +- (ServerLevel)destination.level(), +- destination.getX(), +- destination.getY(), +- destination.getZ(), +- EnumSet.noneOf(RelativeMovement.class), +- destination.getYRot(), +- destination.getXRot(), +- null +- ); ++ Iterator iterator = targets.iterator(); ++ ++ while (iterator.hasNext()) { ++ Entity entity1 = (Entity) iterator.next(); ++ ++ performTeleport(source, entity1, (ServerLevel) destination.level(), destination.getX(), destination.getY(), destination.getZ(), EnumSet.noneOf(RelativeMovement.class), destination.getYRot(), destination.getXRot(), (TeleportCommand.LookAt) null); + } + + if (targets.size() == 1) { +- source.sendSuccess( +- () -> Component.translatable( +- "commands.teleport.success.entity.single", targets.iterator().next().getDisplayName(), destination.getDisplayName() +- ), +- true +- ); ++ source.sendSuccess(() -> { ++ return Component.translatable("commands.teleport.success.entity.single", ((Entity) targets.iterator().next()).getDisplayName(), destination.getDisplayName()); ++ }, true); + } else { +- source.sendSuccess(() -> Component.translatable("commands.teleport.success.entity.multiple", targets.size(), destination.getDisplayName()), true); ++ source.sendSuccess(() -> { ++ return Component.translatable("commands.teleport.success.entity.multiple", targets.size(), destination.getDisplayName()); ++ }, true); + } + + return targets.size(); + } + +- private static int teleportToPos( +- CommandSourceStack source, +- Collection<? extends Entity> targets, +- ServerLevel level, +- Coordinates position, +- @Nullable Coordinates rotation, +- @Nullable TeleportCommand.LookAt facing +- ) throws CommandSyntaxException { +- Vec3 position1 = position.getPosition(source); +- Vec2 vec2 = rotation == null ? null : rotation.getRotation(source); ++ private static int teleportToPos(CommandSourceStack source, Collection<? extends Entity> targets, ServerLevel level, Coordinates position, @Nullable Coordinates rotation, @Nullable TeleportCommand.LookAt facing) throws CommandSyntaxException { ++ Vec3 vec3d = position.getPosition(source); ++ Vec2 vec2f = rotation == null ? null : rotation.getRotation(source); + Set<RelativeMovement> set = EnumSet.noneOf(RelativeMovement.class); ++ + if (position.isXRelative()) { + set.add(RelativeMovement.X); + } +@@ -223,36 +123,26 @@ + } + } + +- for (Entity entity : targets) { ++ Iterator iterator = targets.iterator(); ++ ++ while (iterator.hasNext()) { ++ Entity entity = (Entity) iterator.next(); ++ + if (rotation == null) { +- performTeleport(source, entity, level, position1.x, position1.y, position1.z, set, entity.getYRot(), entity.getXRot(), facing); ++ performTeleport(source, entity, level, vec3d.x, vec3d.y, vec3d.z, set, entity.getYRot(), entity.getXRot(), facing); + } else { +- performTeleport(source, entity, level, position1.x, position1.y, position1.z, set, vec2.y, vec2.x, facing); ++ performTeleport(source, entity, level, vec3d.x, vec3d.y, vec3d.z, set, vec2f.y, vec2f.x, facing); + } + } + + if (targets.size() == 1) { +- source.sendSuccess( +- () -> Component.translatable( +- "commands.teleport.success.location.single", +- targets.iterator().next().getDisplayName(), +- formatDouble(position1.x), +- formatDouble(position1.y), +- formatDouble(position1.z) +- ), +- true +- ); ++ source.sendSuccess(() -> { ++ return Component.translatable("commands.teleport.success.location.single", ((Entity) targets.iterator().next()).getDisplayName(), formatDouble(vec3d.x), formatDouble(vec3d.y), formatDouble(vec3d.z)); ++ }, true); + } else { +- source.sendSuccess( +- () -> Component.translatable( +- "commands.teleport.success.location.multiple", +- targets.size(), +- formatDouble(position1.x), +- formatDouble(position1.y), +- formatDouble(position1.z) +- ), +- true +- ); ++ source.sendSuccess(() -> { ++ return Component.translatable("commands.teleport.success.location.multiple", targets.size(), formatDouble(vec3d.x), formatDouble(vec3d.y), formatDouble(vec3d.z)); ++ }, true); + } + + return targets.size(); +@@ -262,42 +152,69 @@ + return String.format(Locale.ROOT, "%f", value); + } + +- private static void performTeleport( +- CommandSourceStack source, +- Entity entity, +- ServerLevel level, +- double x, +- double y, +- double z, +- Set<RelativeMovement> relativeList, +- float yaw, +- float pitch, +- @Nullable TeleportCommand.LookAt facing +- ) throws CommandSyntaxException { +- BlockPos blockPos = BlockPos.containing(x, y, z); +- if (!Level.isInSpawnableBounds(blockPos)) { +- throw INVALID_POSITION.create(); ++ private static void performTeleport(CommandSourceStack source, Entity entity, ServerLevel level, double x, double d1, double y, Set<RelativeMovement> set, float z, float f1, @Nullable TeleportCommand.LookAt relativeList) throws CommandSyntaxException { ++ BlockPos blockposition = BlockPos.containing(x, d1, y); ++ ++ if (!Level.isInSpawnableBounds(blockposition)) { ++ throw TeleportCommand.INVALID_POSITION.create(); + } else { +- float f = Mth.wrapDegrees(yaw); +- float f1 = Mth.wrapDegrees(pitch); +- if (entity.teleportTo(level, x, y, z, relativeList, f, f1)) { +- if (facing != null) { +- facing.perform(source, entity); ++ float f2 = Mth.wrapDegrees(z); ++ float f3 = Mth.wrapDegrees(f1); ++ ++ // CraftBukkit start - Teleport event ++ boolean result; ++ if (entity instanceof ServerPlayer player) { ++ result = player.teleportTo(level, x, d1, y, set, f2, f3, PlayerTeleportEvent.TeleportCause.COMMAND); ++ } else { ++ Location to = new Location(level.getWorld(), x, d1, y, f2, f3); ++ EntityTeleportEvent event = new EntityTeleportEvent(entity.getBukkitEntity(), entity.getBukkitEntity().getLocation(), to); ++ level.getCraftServer().getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ return; + } + +- if (!(entity instanceof LivingEntity livingEntity) || !livingEntity.isFallFlying()) { +- entity.setDeltaMovement(entity.getDeltaMovement().multiply(1.0, 0.0, 1.0)); ++ x = to.getX(); ++ d1 = to.getY(); ++ y = to.getZ(); ++ f2 = to.getYaw(); ++ f3 = to.getPitch(); ++ level = ((CraftWorld) to.getWorld()).getHandle(); ++ ++ result = entity.teleportTo(level, x, d1, y, set, f2, f3); ++ } ++ ++ if (result) { ++ // CraftBukkit end ++ if (relativeList != null) { ++ relativeList.perform(source, entity); ++ } ++ ++ label23: ++ { ++ if (entity instanceof LivingEntity) { ++ LivingEntity entityliving = (LivingEntity) entity; ++ ++ if (entityliving.isFallFlying()) { ++ break label23; ++ } ++ } ++ ++ entity.setDeltaMovement(entity.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D)); + entity.setOnGround(true); + } + +- if (entity instanceof PathfinderMob pathfinderMob) { +- pathfinderMob.getNavigation().stop(); ++ if (entity instanceof PathfinderMob) { ++ PathfinderMob entitycreature = (PathfinderMob) entity; ++ ++ entitycreature.getNavigation().stop(); + } ++ + } + } + } + +- static class LookAt { ++ private static class LookAt { ++ + private final Vec3 position; + private final Entity entity; + private final EntityAnchorArgument.Anchor anchor; +@@ -317,13 +234,14 @@ + public void perform(CommandSourceStack source, Entity entity) { + if (this.entity != null) { + if (entity instanceof ServerPlayer) { +- ((ServerPlayer)entity).lookAt(source.getAnchor(), this.entity, this.anchor); ++ ((ServerPlayer) entity).lookAt(source.getAnchor(), this.entity, this.anchor); + } else { + entity.lookAt(source.getAnchor(), this.position); + } + } else { + entity.lookAt(source.getAnchor(), this.position); + } ++ + } + } + } |