@@ -53,14 +53,15 @@ public String getCommand() {
5353 }
5454
5555 public CommandSender [] getSender () {
56- return new CommandSender []{sender };
56+ return new CommandSender []{this . sender };
5757 }
5858
5959 public World [] getWorld () {
60- return new World []{world };
60+ return new World []{this . world };
6161 }
6262
6363 public Player [] getPlayer () {
64+ if (this .player == null && this .sender instanceof Player p ) return new Player []{p };
6465 return new Player []{this .player };
6566 }
6667
@@ -137,6 +138,13 @@ public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, P
137138 if (this .command .startsWith ("/" )) {
138139 this .command = this .command .substring (1 );
139140 }
141+ if (this .command .contains (" " )) {
142+ this .command = this .command .substring (0 , this .command .indexOf (" " ));
143+ }
144+ if (this .command .isEmpty ()) {
145+ parseContext .getLogger ().error ("Command cannot be empty" , ErrorType .SEMANTIC_ERROR );
146+ return false ;
147+ }
140148 this .commandType = matchedPattern ;
141149 return true ;
142150 }
@@ -145,16 +153,28 @@ public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, P
145153 public List <Statement > loadSection (@ NotNull FileSection section , @ NotNull ParserState parserState , @ NotNull SkriptLogger logger ) {
146154 this .sec .loadConfiguration (null , section , parserState , logger );
147155 Optional <CodeSection > triggerSec = this .sec .getSection ("trigger" );
148- if (triggerSec .isEmpty ()) return List .of ();
156+ if (triggerSec .isEmpty ()) {
157+ logger .error ("Trigger section is missing" , ErrorType .SEMANTIC_ERROR );
158+ return List .of ();
159+ }
149160
150161 CodeSection trigger = triggerSec .get ();
162+ if (trigger .getItems ().isEmpty ()) {
163+ logger .warn ("Trigger section should not be empty." );
164+ return List .of ();
165+ }
151166
152167 Optional <String > descOption = this .sec .getValue ("description" , String .class );
153168 if (descOption .isEmpty ()) {
154169 logger .error ("Description cannot be empty" , ErrorType .SEMANTIC_ERROR );
155170 return List .of ();
156171 }
157- String description = descOption .get ();
172+
173+ String description = trim (descOption .get ());
174+ if (description .isEmpty ()) {
175+ logger .error ("Description cannot be empty" , ErrorType .SEMANTIC_ERROR );
176+ return List .of ();
177+ }
158178
159179 AbstractCommand hyCommand = switch (this .commandType ) {
160180 case 1 -> new AbstractPlayerCommand (this .command , description ) {
@@ -191,13 +211,31 @@ protected void execute(@NotNull CommandContext commandContext, @NotNull World wo
191211 }
192212 };
193213 };
194- Optional <String > perm = sec .getValue ("permission" , String .class );
195- perm .ifPresent (hyCommand ::requirePermission );
214+ Optional <String > permValue = sec .getValue ("permission" , String .class );
215+ if (permValue .isPresent ()) {
216+ String perm = trim (permValue .get ());
217+ if (!perm .isEmpty ()) {
218+ hyCommand .requirePermission (perm );
219+ } else {
220+ logger .warn ("Permission is empty, will fallback to default permission." );
221+ }
222+ }
196223 HySk .getInstance ().getCommandRegistry ().registerCommand (hyCommand );
197224
198225 return List .of (trigger );
199226 }
200227
228+ private String trim (String s ) {
229+ // In case someone puts quotes, let's remove them
230+ if (s .startsWith ("\" " )) {
231+ s = s .substring (1 );
232+ }
233+ if (s .endsWith ("\" " )) {
234+ s = s .substring (0 , s .length () - 1 );
235+ }
236+ return s .trim ();
237+ }
238+
201239 @ Override
202240 public boolean check (@ NotNull TriggerContext ctx ) {
203241 return ctx instanceof ScriptCommandContext sctx && sctx .getCommand ().equals (this .command );
0 commit comments