22
33import com .mojang .authlib .GameProfile ;
44import eu .pb4 .placeholders .impl .placeholder .ViewObjectImpl ;
5- import net .minecraft .entity .Entity ;
5+ import net .minecraft .commands .CommandSource ;
6+ import net .minecraft .commands .CommandSourceStack ;
7+ import net .minecraft .network .chat .Component ;
8+ import net .minecraft .resources .Identifier ;
69import net .minecraft .server .MinecraftServer ;
7- import net .minecraft .server .PlayerConfigEntry ;
8- import net .minecraft .server .command .CommandOutput ;
9- import net .minecraft .server .command .ServerCommandSource ;
10- import net .minecraft .server .network .ServerPlayerEntity ;
11- import net .minecraft .server .world .ServerWorld ;
12- import net .minecraft .text .Text ;
13- import net .minecraft .util .Identifier ;
14- import net .minecraft .util .math .Vec2f ;
15- import net .minecraft .util .math .Vec3d ;
10+ import net .minecraft .server .level .ServerLevel ;
11+ import net .minecraft .server .level .ServerPlayer ;
12+ import net .minecraft .server .players .NameAndId ;
13+ import net .minecraft .world .entity .Entity ;
14+ import net .minecraft .world .phys .Vec2 ;
15+ import net .minecraft .world .phys .Vec3 ;
1616import org .jetbrains .annotations .Contract ;
1717import org .jetbrains .annotations .Nullable ;
1818
1919import java .util .function .Supplier ;
2020
2121
2222public record PlaceholderContext (MinecraftServer server ,
23- Supplier <ServerCommandSource > lazySource ,
24- @ Nullable ServerWorld world ,
25- @ Nullable ServerPlayerEntity player ,
23+ Supplier <CommandSourceStack > lazySource ,
24+ @ Nullable ServerLevel world ,
25+ @ Nullable ServerPlayer player ,
2626 @ Nullable Entity entity ,
2727 @ Nullable GameProfile gameProfile ,
2828 ViewObject view
2929) {
3030
3131 public PlaceholderContext (MinecraftServer server ,
32- ServerCommandSource source ,
33- @ Nullable ServerWorld world ,
34- @ Nullable ServerPlayerEntity player ,
32+ CommandSourceStack source ,
33+ @ Nullable ServerLevel world ,
34+ @ Nullable ServerPlayer player ,
3535 @ Nullable Entity entity ,
3636 @ Nullable GameProfile gameProfile ,
3737 ViewObject view
3838 ) {
3939 this (server , () -> source , world , player , entity , gameProfile , view );
4040 }
4141
42- public ServerCommandSource source () {
42+ public CommandSourceStack source () {
4343 return this .lazySource .get ();
4444 }
4545
4646 public PlaceholderContext (MinecraftServer server ,
47- ServerCommandSource source ,
48- @ Nullable ServerWorld world ,
49- @ Nullable ServerPlayerEntity player ,
47+ CommandSourceStack source ,
48+ @ Nullable ServerLevel world ,
49+ @ Nullable ServerPlayer player ,
5050 @ Nullable Entity entity ,
5151 @ Nullable GameProfile gameProfile ) {
5252 this (server , source , world , player , entity , gameProfile , ViewObject .DEFAULT );
@@ -72,7 +72,7 @@ public boolean hasEntity() {
7272 }
7373
7474 public ParserContext asParserContext () {
75- return ParserContext .of (KEY , this ).with (ParserContext .Key .WRAPPER_LOOKUP , this .server .getRegistryManager ());
75+ return ParserContext .of (KEY , this ).with (ParserContext .Key .WRAPPER_LOOKUP , this .server .registryAccess ());
7676 }
7777
7878 public PlaceholderContext withView (ViewObject view ) {
@@ -81,7 +81,7 @@ public PlaceholderContext withView(ViewObject view) {
8181
8282 public void addToContext (ParserContext context ) {
8383 context .with (KEY , this );
84- context .with (ParserContext .Key .WRAPPER_LOOKUP , this .server .getRegistryManager ());
84+ context .with (ParserContext .Key .WRAPPER_LOOKUP , this .server .registryAccess ());
8585 }
8686
8787
@@ -90,7 +90,7 @@ public static PlaceholderContext of(MinecraftServer server) {
9090 }
9191
9292 public static PlaceholderContext of (MinecraftServer server , ViewObject view ) {
93- return new PlaceholderContext (server , server ::getCommandSource , null , null , null , null , view );
93+ return new PlaceholderContext (server , server ::createCommandSourceStack , null , null , null , null , view );
9494 }
9595
9696 public static PlaceholderContext of (GameProfile profile , MinecraftServer server ) {
@@ -99,41 +99,41 @@ public static PlaceholderContext of(GameProfile profile, MinecraftServer server)
9999
100100 public static PlaceholderContext of (GameProfile profile , MinecraftServer server , ViewObject view ) {
101101 var name = profile .name () != null ? profile .name () : profile .id ().toString ();
102- return new PlaceholderContext (server , () -> new ServerCommandSource ( CommandOutput . DUMMY , Vec3d .ZERO , Vec2f .ZERO , server .getOverworld (), server .getPermissionLevel (new PlayerConfigEntry (profile )), name , Text .literal (name ), server , null ), null , null , null , profile , view );
102+ return new PlaceholderContext (server , () -> new CommandSourceStack ( CommandSource . NULL , Vec3 .ZERO , Vec2 .ZERO , server .overworld (), server .getProfilePermissions (new NameAndId (profile )), name , Component .literal (name ), server , null ), null , null , null , profile , view );
103103 }
104104
105- public static PlaceholderContext of (ServerPlayerEntity player ) {
105+ public static PlaceholderContext of (ServerPlayer player ) {
106106 return of (player , ViewObject .DEFAULT );
107107 }
108108
109- public static PlaceholderContext of (ServerPlayerEntity player , ViewObject view ) {
110- return new PlaceholderContext (player .getEntityWorld ().getServer (), player ::getCommandSource , player .getEntityWorld (), player , player , player .getGameProfile (), view );
109+ public static PlaceholderContext of (ServerPlayer player , ViewObject view ) {
110+ return new PlaceholderContext (player .level ().getServer (), player ::createCommandSourceStack , player .level (), player , player , player .getGameProfile (), view );
111111 }
112112
113- public static PlaceholderContext of (ServerCommandSource source ) {
113+ public static PlaceholderContext of (CommandSourceStack source ) {
114114 return of (source , ViewObject .DEFAULT );
115115 }
116116
117- public static PlaceholderContext of (ServerCommandSource source , ViewObject view ) {
118- return new PlaceholderContext (source .getServer (), source , source .getWorld (), source .getPlayer (), source .getEntity (), source .getPlayer () != null ? source .getPlayer ().getGameProfile () : null , view );
117+ public static PlaceholderContext of (CommandSourceStack source , ViewObject view ) {
118+ return new PlaceholderContext (source .getServer (), source , source .getLevel (), source .getPlayer (), source .getEntity (), source .getPlayer () != null ? source .getPlayer ().getGameProfile () : null , view );
119119 }
120120
121121 public static PlaceholderContext of (Entity entity ) {
122122 return of (entity , ViewObject .DEFAULT );
123123 }
124124
125125 public static PlaceholderContext of (Entity entity , ViewObject view ) {
126- if (entity instanceof ServerPlayerEntity player ) {
126+ if (entity instanceof ServerPlayer player ) {
127127 return of (player , view );
128128 } else {
129- var world = (ServerWorld ) entity .getEntityWorld ();
130- return new PlaceholderContext (world .getServer (), () -> entity .getCommandSource (world ), world , null , entity , null , view );
129+ var world = (ServerLevel ) entity .level ();
130+ return new PlaceholderContext (world .getServer (), () -> entity .createCommandSourceStackForNameResolution (world ), world , null , entity , null , view );
131131 }
132132 }
133133
134134
135135 public interface ViewObject {
136- ViewObject DEFAULT = of (Identifier .of ("placeholder_api" , "default" ));
136+ ViewObject DEFAULT = of (Identifier .fromNamespaceAndPath ("placeholder_api" , "default" ));
137137
138138 static ViewObject of (Identifier identifier ) {
139139 return new ViewObjectImpl (identifier );
0 commit comments