-
-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Effect Command API Enhancement & Skript Event Support #6587
Open
NotSoDelayed
wants to merge
12
commits into
SkriptLang:dev/feature
Choose a base branch
from
NotSoDelayed:enhance/effect-command-api
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+250
−46
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b471651
Adds EffectCommandEvent support to Skript
NotSoDelayed 0d5117c
Docs, and fix toString
NotSoDelayed c6fa355
Cleanup involved classes
NotSoDelayed 32f4f46
Merge branch 'dev/feature' into feature/event-effect-command
NotSoDelayed 807cbbf
Merge branch 'feature/event-effect-command' into enhance/effect-comma…
NotSoDelayed 804aa8d
Better(??) EffectCommandEvent API
NotSoDelayed 53fdc0b
Apply missing requested changes from #6575
NotSoDelayed b365f51
EffectCommandEvent Javadocs
NotSoDelayed b6d9d3d
Backwards compatibility
NotSoDelayed 85e410e
Merge branch 'dev/feature' into enhance/effect-command-api
Moderocky f236b13
Bulk requested changes
NotSoDelayed e5fd288
(pt1) lang entries for error messages
NotSoDelayed File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/ch/njol/skript/conditions/CondEffectCommandIsValid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.conditions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.command.EffectCommandEvent; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Condition; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
@Name("Effect Command Is Valid") | ||
@Description("Checks whether the parsed effect command in an 'effect command' event is valid.") | ||
@Examples({ | ||
"if the effect command is valid:", | ||
"\tsend \"%sender% has executed an invalid effect command!\" to console" | ||
}) | ||
@Since("INSERT VERSION") | ||
public class CondEffectCommandIsValid extends Condition { | ||
|
||
static { | ||
Skript.registerCondition(CondEffectCommandIsValid.class, "[the] effect command is [not:(not |in)]valid"); | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
if (!getParser().isCurrentEvent(EffectCommandEvent.class)) { | ||
Skript.error("The 'effect command is valid' condition can only be used in an 'effect command' event"); | ||
return false; | ||
} | ||
setNegated(parseResult.hasTag("not")); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
if (!(event instanceof EffectCommandEvent)) | ||
return false; | ||
return ((EffectCommandEvent) event).getEffect() != null ^ isNegated(); | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "effect command is " + (isNegated() ? "in" : "") + "valid"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.events; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.command.EffectCommandEvent; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptEvent; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.ConsoleCommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
public class EvtEffectCommand extends SkriptEvent { | ||
|
||
static { | ||
Skript.registerEvent("Effect Command Event", EvtEffectCommand.class, EffectCommandEvent.class, | ||
"[executor:(1:console|2:player)] effect command") | ||
.description("Called when a player or console executes a skript effect command.") | ||
.examples( | ||
"on effect command:", | ||
"\tlog \"%sender%: %command%\" to file \"effectcommands.log\"") | ||
.since("INSERT VERSION"); | ||
} | ||
|
||
private enum Executor { | ||
|
||
ANY("any"), | ||
CONSOLE("console"), | ||
PLAYER("player"); | ||
|
||
final String toString; | ||
|
||
Executor(String toString) { | ||
this.toString = toString; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toString; | ||
} | ||
|
||
} | ||
|
||
@SuppressWarnings("NotNullFieldNotInitialized") | ||
private Executor executor; | ||
|
||
@Override | ||
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) { | ||
executor = parseResult.hasTag("executor") ? Executor.values()[parseResult.mark] : Executor.ANY; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
if (!(event instanceof EffectCommandEvent)) | ||
return false; | ||
CommandSender sender = ((EffectCommandEvent) event).getSender(); | ||
switch (executor) { | ||
case ANY: | ||
return true; | ||
case PLAYER: | ||
return sender instanceof Player; | ||
case CONSOLE: | ||
return sender instanceof ConsoleCommandSender; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
if (executor != Executor.ANY) | ||
return executor + " effect command"; | ||
return "effect command"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These error messages probably ought to be lang entries, but it's okay if you feel that's out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeking for extended support of this in the skriptlang channel.