6565import org .bukkit .craftbukkit .v1_21_R3 .CraftParticle ;
6666import org .bukkit .craftbukkit .v1_21_R3 .CraftServer ;
6767import org .bukkit .craftbukkit .v1_21_R3 .CraftSound ;
68+ import org .bukkit .craftbukkit .v1_21_R3 .CraftWorld ;
6869import org .bukkit .craftbukkit .v1_21_R3 .block .data .CraftBlockData ;
6970import org .bukkit .craftbukkit .v1_21_R3 .command .BukkitCommandWrapper ;
7071import org .bukkit .craftbukkit .v1_21_R3 .command .VanillaCommandWrapper ;
@@ -838,8 +839,7 @@ public String getScoreHolderSingle(CommandContext<CommandSourceStack> cmdCtx, St
838839 }
839840
840841 @ Override
841- public BukkitCommandSender <? extends CommandSender > getSenderForCommand (CommandContext <CommandSourceStack > cmdCtx ,
842- boolean isNative ) {
842+ public BukkitCommandSender <? extends CommandSender > getSenderForCommand (CommandContext <CommandSourceStack > cmdCtx , boolean isNative ) {
843843 CommandSourceStack css = cmdCtx .getSource ();
844844
845845 CommandSender sender = css .getBukkitSender ();
@@ -851,10 +851,6 @@ public BukkitCommandSender<? extends CommandSender> getSenderForCommand(CommandC
851851 // sender.
852852 sender = Bukkit .getConsoleSender ();
853853 }
854- Vec3 pos = css .getPosition ();
855- Vec2 rot = css .getRotation ();
856- World world = getWorldForCSS (css );
857- Location location = new Location (world , pos .x (), pos .y (), pos .z (), rot .y , rot .x );
858854
859855 Entity proxyEntity = css .getEntity ();
860856 CommandSender proxy = proxyEntity == null ? null : proxyEntity .getBukkitEntity ();
@@ -863,12 +859,42 @@ public BukkitCommandSender<? extends CommandSender> getSenderForCommand(CommandC
863859 proxy = sender ;
864860 }
865861
866- return new BukkitNativeProxyCommandSender (new NativeProxyCommandSender ( sender , proxy , location , world ));
862+ return new BukkitNativeProxyCommandSender (new NativeProxyCommandSender_1_21_R3 ( css , sender , proxy ));
867863 } else {
868864 return wrapCommandSender (sender );
869865 }
870866 }
871867
868+ @ Override
869+ public NativeProxyCommandSender createNativeProxyCommandSender (CommandSender caller , CommandSender callee , Location location , World world ) {
870+ if (callee == null ) callee = caller ;
871+
872+ // Most parameters default to what is defined by the caller
873+ CommandSourceStack css = getBrigadierSourceFromCommandSender (wrapCommandSender (caller ));
874+
875+ // Position and rotation may be overridden by the Location
876+ if (location != null ) {
877+ css = css
878+ .withPosition (new Vec3 (location .getX (), location .getY (), location .getZ ()))
879+ .withRotation (new Vec2 (location .getPitch (), location .getYaw ()));
880+ }
881+
882+ // ServerLevel may be overridden by the World
883+ if (world == null && location != null ) {
884+ world = location .getWorld ();
885+ }
886+ if (world != null ) {
887+ css = css .withLevel (((CraftWorld ) world ).getHandle ());
888+ }
889+
890+ // The proxied sender can only be an Entity in the CommandSourceStack
891+ if (callee instanceof org .bukkit .entity .Entity e ) {
892+ css = css .withEntity (((CraftEntity ) e ).getHandle ());
893+ }
894+
895+ return new NativeProxyCommandSender_1_21_R3 (css , caller , callee );
896+ }
897+
872898 @ Override
873899 public final SimpleCommandMap getSimpleCommandMap () {
874900 return ((CraftServer ) Bukkit .getServer ()).getCommandMap ();
0 commit comments