4141 */
4242public class PromptContext {
4343 private final Cancellable cancellable ;
44- private final CommandSender sender ;
44+ private final CommandSender sender ; // Command sender that initiated the prompt (usually a player or console).
45+ private final Player promptedPlayer ; // Player that we're going to send the prompt to.
4546 private String content ;
4647 private String promptKey ;
4748 private boolean isConsoleDelegate ;
4849
4950 private final String paKey ;
5051
5152 public PromptContext (PlayerCommandPreprocessEvent e ) {
52- this (e , e .getPlayer (), e .getMessage (), null , null , false );
53+ this (e , e .getPlayer (), e .getPlayer (), e . getMessage (), null , null , false );
5354 }
5455
5556 public PromptContext (@ Nullable Cancellable callable ,
56- Player sender ,
57+ CommandSender sender ,
58+ Player promptedPlayer ,
5759 String content ,
5860 @ Nullable String promptKey ,
5961 @ Nullable String paKey ,
6062 boolean isConsoleDelegate ) {
6163 this .cancellable = callable ;
6264 this .sender = sender ;
65+ this .promptedPlayer = promptedPlayer ;
6366 this .content = content ;
6467 this .promptKey = promptKey ;
6568 this .paKey = paKey ;
6669 this .isConsoleDelegate = isConsoleDelegate ;
6770 }
6871
69- public CommandSender getSender () {
72+ public CommandSender getCommandSender () {
7073 return sender ;
7174 }
7275
76+ public Player getPromptedPlayer () {
77+ return promptedPlayer ;
78+ }
79+
7380 public Cancellable getCancellable () {
7481 return cancellable ;
7582 }
@@ -118,6 +125,7 @@ public String toString() {
118125 public static class Builder {
119126 private Cancellable cancellable ;
120127 private CommandSender sender ;
128+ private Player promptedPlayer ;
121129 private String content ;
122130
123131 private String promptKey ;
@@ -139,11 +147,16 @@ public Builder setCancellable(Cancellable cancellable) {
139147 return this ;
140148 }
141149
142- public Builder setSender (CommandSender sender ) {
150+ public Builder setCommandSender (CommandSender sender ) {
143151 this .sender = sender ;
144152 return this ;
145153 }
146154
155+ public Builder setPromptedPlayer (Player promptedPlayer ) {
156+ this .promptedPlayer = promptedPlayer ;
157+ return this ;
158+ }
159+
147160 public Builder setContent (String content ) {
148161 this .content = content ;
149162 return this ;
@@ -165,11 +178,9 @@ public Builder setPaKey(String paKey) {
165178 }
166179
167180 public PromptContext build () {
168- // check if sender and content is null.
169181 if (sender == null || content == null )
170- throw new IllegalStateException ("Sender and content must not be null!" );
171- return new PromptContext (cancellable , (Player ) sender ,
172- content , promptKey , paKey , isConsoleDelegate );
182+ throw new IllegalStateException ("Must provide non-null CommandSender, Player, and String!" );
183+ return new PromptContext (cancellable , sender , promptedPlayer , content , promptKey , paKey , isConsoleDelegate );
173184 }
174185 }
175186}
0 commit comments