Skip to content
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

Added Unknown command event #6534

Open
wants to merge 36 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
276100a
Added uknown cmd
7othifaPS Apr 3, 2024
b6a93f3
Adds Unknown command event
7othifaPS Apr 4, 2024
31b8bc4
Merge branch 'dev/feature' into ilikeskript
7othifaPS Apr 4, 2024
0359c0c
Merge branch 'dev/feature' into ilikeskript
7othifaPS Apr 4, 2024
29291f4
Merge branch 'dev/feature' into ilikeskript
7othifaPS Apr 4, 2024
36b0add
Merge branch 'ilikeskript' of https://github.com/7othifaPS/Skript int…
7othifaPS Apr 4, 2024
41614bc
eeee
7othifaPS Apr 4, 2024
2ef88ae
Added class checker
7othifaPS Apr 4, 2024
e80deff
Added requested Changes
7othifaPS Apr 5, 2024
ebe3626
Added all the requested changes
7othifaPS Apr 5, 2024
8e6f6cb
Added sender event-value
7othifaPS Apr 5, 2024
5f1f038
Fully done
7othifaPS Apr 5, 2024
640ce00
i think fixed that
7othifaPS Apr 5, 2024
d10eeb8
Fixed all
7othifaPS Apr 5, 2024
cd9b3d8
removed them
7othifaPS Apr 5, 2024
a17bba7
Did all requested changes
7othifaPS Apr 6, 2024
9a7c512
added info to ExprMessage class
7othifaPS Apr 6, 2024
b22e388
Removed player from event name
7othifaPS Apr 6, 2024
2b47e79
Did requested changes
7othifaPS Apr 13, 2024
cf30aeb
Did requested changes
7othifaPS Apr 13, 2024
d0ee1a3
added "" back :D
7othifaPS Apr 13, 2024
14165b3
Merge remote-tracking branch 'upstream/dev/feature' into pr/6534
sovdeeth Apr 14, 2024
0893b40
Merge branch 'dev/feature' into ilikeskript
sovdeeth Apr 14, 2024
ca7a0d6
i hate git sometimes
sovdeeth Apr 14, 2024
0cb815e
Merge branch 'ilikeskript' of https://github.com/7othifaPS/Skript int…
sovdeeth Apr 14, 2024
df431ac
Merge branch 'dev/feature' into ilikeskript
7othifaPS Apr 14, 2024
00e3cd1
Added requested changes
7othifaPS Apr 18, 2024
2ff09ee
Merge branch 'dev/feature' into ilikeskript
sovdeeth Apr 18, 2024
a9bad77
Added requested changes
7othifaPS Apr 18, 2024
491a7b2
Merge branch 'ilikeskript' of https://github.com/7othifaPS/Skript int…
7othifaPS Apr 18, 2024
3a7c688
Merge branch 'dev/feature' into ilikeskript
Moderocky Apr 24, 2024
ae0c4be
Merge branch 'dev/feature' into ilikeskript
Moderocky May 10, 2024
5a414fc
Added test
7othifaPS Sep 18, 2024
3a7588e
Merge remote-tracking branch 'origin/ilikeskript' into ilikeskript
7othifaPS Sep 18, 2024
6a9ced1
Added requests, no more pls im crying
7othifaPS Sep 18, 2024
147bcad
Update src/test/skript/junit/EvtUnknownCommand.sk
Moderocky Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.command.UnknownCommandEvent;
import org.bukkit.event.block.BellRingEvent;
import org.bukkit.event.block.BellResonateEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
Expand Down Expand Up @@ -1904,5 +1905,14 @@ public ItemStack get(InventoryMoveItemEvent event) {
return event.getItem();
}
}, EventValues.TIME_NOW);

if (Skript.classExists("org.bukkit.event.command.UnknownCommandEvent")) {
EventValues.registerEventValue(UnknownCommandEvent.class, CommandSender.class, new Getter<CommandSender, UnknownCommandEvent>() {
@Override
public CommandSender get(UnknownCommandEvent event) {
return event.getSender();
}
}, EventValues.TIME_NOW);
}
}
}
14 changes: 13 additions & 1 deletion src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.command.UnknownCommandEvent;
import org.bukkit.event.block.SpongeAbsorbEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
Expand Down Expand Up @@ -758,6 +759,18 @@ public class SimpleEvents {
)
.since("2.7");

if (Skript.classExists("org.bukkit.event.command.UnknownCommandEvent")) {
Skript.registerEvent("Unknown Command", SimpleEvent.class, UnknownCommandEvent.class, "unknown command")
.description("Called when an unknown command is used.")
.examples(
"on unknown command:",
"\tset unknown command message to \"Hey, this command does not exist.\""
)

.since("INSERT VERSION")
.requiredPlugins("Paper");
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
}

{
final Class<? extends Event> eventClass;
if (Skript.classExists("org.bukkit.event.block.BellRingEvent")) {
Expand Down Expand Up @@ -798,5 +811,4 @@ public class SimpleEvents {
.requiredPlugins("Spigot 1.19.4+");
}
}

7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
}
27 changes: 16 additions & 11 deletions src/main/java/ch/njol/skript/expressions/ExprArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.regex.MatchResult;

import org.bukkit.event.Event;
import org.bukkit.event.command.UnknownCommandEvent;
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -60,7 +61,7 @@
"add argument 1 to argument 2",
"heal the last argument"
})
@Since("1.0, 2.7 (support for command events)")
@Since("1.0, 2.7 (support for command events), INSERT VERSION (unknown command)")
public class ExprArgument extends SimpleExpression<Object> {

static {
Expand All @@ -81,13 +82,15 @@ public class ExprArgument extends SimpleExpression<Object> {
private Argument<?> argument;

private int ordinal = -1; // Available in ORDINAL and sometimes CLASSINFO
private boolean SUPPORTS_UNKNOWN_COMMAND_EVENT = Skript.classExists("org.bukkit.event.command.UnknownCommandEvent");

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
public boolean init(Expression<?>[] expressions, int matchedPattern,
Kleenean isDelayed, ParseResult parseResult) {
boolean scriptCommand = getParser().isCurrentEvent(ScriptCommandEvent.class);
if (!scriptCommand && !getParser().isCurrentEvent(PlayerCommandPreprocessEvent.class, ServerCommandEvent.class)) {
Skript.error("The 'argument' expression can only be used in a script command or command event");
if (!scriptCommand && !getParser().isCurrentEvent(PlayerCommandPreprocessEvent.class, ServerCommandEvent.class, org.bukkit.event.command.UnknownCommandEvent.class)) {
Skript.error("The 'argument' expression can only be used in a script command, command event or unknown command event");
return false;
}

Expand Down Expand Up @@ -159,7 +162,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
Skript.error("'arguments' cannot be used for script commands. Use 'argument 1', 'argument 2', etc. instead", ErrorQuality.SEMANTIC_ERROR);
return false;
case CLASSINFO:
ClassInfo<?> c = ((Literal<ClassInfo<?>>) exprs[0]).getSingle();
ClassInfo<?> c = ((Literal<ClassInfo<?>>) expressions[0]).getSingle();
if (parseResult.regexes.size() > 0) {
ordinal = Utils.parseInt(parseResult.regexes.get(0).group());
if (ordinal > currentArguments.size()) {
Expand Down Expand Up @@ -213,16 +216,18 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

@Override
@Nullable
protected Object[] get(final Event e) {
protected Object[] get(Event event) {
if (argument != null) {
return argument.getCurrent(e);
return argument.getCurrent(event);
}

String fullCommand;
if (e instanceof PlayerCommandPreprocessEvent) {
fullCommand = ((PlayerCommandPreprocessEvent) e).getMessage().substring(1).trim();
} else if (e instanceof ServerCommandEvent) { // It's a ServerCommandEvent then
fullCommand = ((ServerCommandEvent) e).getCommand().trim();
if (SUPPORTS_UNKNOWN_COMMAND_EVENT && event instanceof UnknownCommandEvent) {
fullCommand = ((UnknownCommandEvent) event).getCommandLine().trim();
} else if (event instanceof PlayerCommandPreprocessEvent) {
fullCommand = ((PlayerCommandPreprocessEvent) event).getMessage().substring(1).trim();
} else if (event instanceof ServerCommandEvent) { // It's a ServerCommandEvent then
fullCommand = ((ServerCommandEvent) event).getCommand().trim();
} else {
return new Object[0];
}
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/ch/njol/skript/expressions/ExprCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import ch.njol.skript.command.ScriptCommandEvent;
import org.bukkit.event.Event;
import org.bukkit.event.command.UnknownCommandEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -59,11 +60,12 @@ public class ExprCommand extends SimpleExpression<String> {
}

private boolean fullCommand;
private boolean SUPPORTS_UNKNOWN_COMMAND_EVENT = Skript.classExists("org.bukkit.event.command.UnknownCommandEvent");

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (!getParser().isCurrentEvent(PlayerCommandPreprocessEvent.class, ServerCommandEvent.class, ScriptCommandEvent.class)) {
Skript.error("The 'command' expression can only be used in a script command or command event");
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (!getParser().isCurrentEvent(PlayerCommandPreprocessEvent.class, ServerCommandEvent.class, org.bukkit.event.command.UnknownCommandEvent.class, ScriptCommandEvent.class)) {
Skript.error("The 'command' expression can only be used in a script command, command event or unknown command event");
return false;
}
fullCommand = matchedPattern == 0;
Expand All @@ -72,16 +74,18 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

@Override
@Nullable
protected String[] get(final Event e) {
protected String[] get(Event event) {
final String s;

if (e instanceof PlayerCommandPreprocessEvent) {
s = ((PlayerCommandPreprocessEvent) e).getMessage().substring(1).trim();
} else if (e instanceof ServerCommandEvent) {
s = ((ServerCommandEvent) e).getCommand().trim();
if (event instanceof PlayerCommandPreprocessEvent) {
s = ((PlayerCommandPreprocessEvent) event).getMessage().substring(1).trim();
} else if (event instanceof ServerCommandEvent) {
s = ((ServerCommandEvent) event).getCommand().trim();
} else if (SUPPORTS_UNKNOWN_COMMAND_EVENT && event instanceof UnknownCommandEvent) {
s = ((UnknownCommandEvent) event).getCommandLine().trim();
} else { // It's a script command event
ScriptCommandEvent event = (ScriptCommandEvent) e;
s = event.getCommandLabel() + " " + event.getArgsString();
ScriptCommandEvent scriptCmdEvent = (ScriptCommandEvent) event;
s = scriptCmdEvent.getCommandLabel() + " " + scriptCmdEvent.getArgsString();
}

if (fullCommand) {
Expand Down
76 changes: 47 additions & 29 deletions src/main/java/ch/njol/skript/expressions/ExprMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package ch.njol.skript.expressions;

import org.bukkit.event.Event;
import org.bukkit.event.command.UnknownCommandEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
Expand Down Expand Up @@ -47,25 +48,30 @@
*/
@SuppressWarnings("deprecation")
@Name("Message")
@Description("The (chat) message of a chat event, the join message of a join event, the quit message of a quit event, or the death message on a death event. This expression is mostly useful for being changed.")
@Examples({"on chat:",
" player has permission \"admin\"",
" set message to \"&c%message%\"",
@Description("The (chat) message of a chat event, the join message of a join event, the quit message of a quit event, or the death message of a death event, or the unknown command message of an unknown command event. This expression is mostly useful for being changed.")
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
@Examples({
"on chat:",
"\tplayer has permission \"admin\"",
"\tset message to \"&c%message%\"",
"",
"on first join:",
" set join message to \"Welcome %player% to our awesome server!\"",
"\tset join message to \"Welcome %player% to our awesome server!\"",
"",
"on join:",
" player has played before",
" set join message to \"Welcome back, %player%!\"",
"\tplayer has played before",
"\tset join message to \"Welcome back, %player%!\"",
"",
"on quit:",
" set quit message to \"%player% left this awesome server!\"",
"\tset quit message to \"%player% left this awesome server!\"",
"",
"on death:",
" set the death message to \"%player% died!\""})
@Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message)")
@Events({"chat", "join", "quit", "death"})
"\tset the death message to \"%player% died!\"",
"",
"on unknown command:",
"\tset unknown command message to \"This command does not exist.\""
})
@Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message), INSERT VERSION (unknown command message)")
@Events({"chat", "join", "quit", "death", "unknown command"})
public class ExprMessage extends SimpleExpression<String> {

@SuppressWarnings("unchecked")
Expand All @@ -84,46 +90,58 @@ void set(Event event, String message) {
JOIN("join", "(join|log[ ]in)( |-)message", PlayerJoinEvent.class) {
@Override
@Nullable
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
String get(final Event e) {
return ((PlayerJoinEvent) e).getJoinMessage();
String get(Event event) {
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
return ((PlayerJoinEvent) event).getJoinMessage();
}

@Override
void set(final Event e, final String message) {
((PlayerJoinEvent) e).setJoinMessage(message);
void set(Event event, final String message) {
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
((PlayerJoinEvent) event).setJoinMessage(message);
}
},
QUIT("quit", "(quit|leave|log[ ]out|kick)( |-)message", PlayerQuitEvent.class, PlayerKickEvent.class) {
@Override
@Nullable
String get(final Event e) {
if (e instanceof PlayerKickEvent)
return ((PlayerKickEvent) e).getLeaveMessage();
String get(Event event) {
if (event instanceof PlayerKickEvent)
return ((PlayerKickEvent) event).getLeaveMessage();
else
return ((PlayerQuitEvent) e).getQuitMessage();
return ((PlayerQuitEvent) event).getQuitMessage();
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
void set(final Event e, final String message) {
if (e instanceof PlayerKickEvent)
((PlayerKickEvent) e).setLeaveMessage(message);
void set(Event event, final String message) {
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
if (event instanceof PlayerKickEvent)
((PlayerKickEvent) event).setLeaveMessage(message);
else
((PlayerQuitEvent) e).setQuitMessage(message);
((PlayerQuitEvent) event).setQuitMessage(message);
}
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
},
UNKNOWN("unknown command", "unknown command( |-)message", UnknownCommandEvent.class) {
@Override
@Nullable
String get(Event event) {
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
return ((UnknownCommandEvent) event).getMessage();
}

@Override
void set(Event event, final String message) {
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
((UnknownCommandEvent) event).setMessage(message);
}
},
DEATH("death", "death( |-)message", EntityDeathEvent.class) {
@Override
@Nullable
String get(final Event e) {
if (e instanceof PlayerDeathEvent)
return ((PlayerDeathEvent) e).getDeathMessage();
String get(Event event) {
if (event instanceof PlayerDeathEvent)
return ((PlayerDeathEvent) event).getDeathMessage();
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

@Override
void set(final Event e, final String message) {
if (e instanceof PlayerDeathEvent)
((PlayerDeathEvent) e).setDeathMessage(message);
void set(Event event, String message) {
if (event instanceof PlayerDeathEvent)
((PlayerDeathEvent) event).setDeathMessage(message);
7othifaPS marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/test/skript/junit/EvtUnknownCommand.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
on unknown command:
set unknown command message to "Hey, this command does not exist."
Comment on lines +1 to +2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a test.