Skip to content

Commit fba8623

Browse files
Start deprecating legacy code
1 parent 2c19ef6 commit fba8623

10 files changed

Lines changed: 27 additions & 418 deletions

File tree

src/main/java/ch/njol/skript/bukkitutil/CommandReloader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
/**
1212
* Utilizes CraftServer with reflection to re-send commands to clients.
13+
* @deprecated This behavior should not be relied upon. There is no replacement.
1314
*/
15+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
1416
public class CommandReloader {
1517

1618
@Nullable

src/main/java/ch/njol/skript/command/Argument.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
* Represents an argument of a command
2323
*
2424
* @author Peter Güttinger
25+
* @deprecated There is no direct replacement for this class.
26+
* The closest alternative is {@link org.skriptlang.skript.bukkit.command.custom.ArgumentData}.
2527
*/
28+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
2629
public class Argument<T> {
2730

2831
@Nullable

src/main/java/ch/njol/skript/command/CommandUsage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
/**
1111
* Holds info about the usage of a command.
1212
* TODO: replace with record when java 17
13+
* @deprecated There is no direct replacement for this class.
1314
*/
15+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
1416
public class CommandUsage {
1517

1618
/**

src/main/java/ch/njol/skript/command/Commands.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import org.bukkit.event.EventPriority;
2323
import org.bukkit.event.Listener;
2424
import org.bukkit.event.player.AsyncPlayerChatEvent;
25-
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
26-
import org.bukkit.event.server.ServerCommandEvent;
2725
import org.bukkit.help.HelpMap;
2826
import org.bukkit.help.HelpTopic;
2927
import org.bukkit.plugin.SimplePluginManager;
@@ -125,46 +123,6 @@ public static String unescape(String string) {
125123
return "" + unescape.matcher(string).replaceAll("$0");
126124
}
127125

128-
private final static Listener commandListener = new Listener() {
129-
130-
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
131-
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
132-
// Spigot will simply report that the command doesn't exist if a player does not have permission to use it.
133-
// This is good security but, well, it's a breaking change for Skript. So we need to check for permissions
134-
// ourselves and handle those messages, for every command.
135-
136-
// parse command, see if it's a skript command
137-
String[] cmd = event.getMessage().substring(1).split("\\s+", 2);
138-
String label = cmd[0].toLowerCase(Locale.ENGLISH);
139-
String arguments = cmd.length == 1 ? "" : "" + cmd[1];
140-
ScriptCommand command = commands.get(label);
141-
142-
// is it a skript command?
143-
if (command != null) {
144-
// if so, check permissions to handle ourselves
145-
if (!command.checkPermissions(event.getPlayer(), label, arguments))
146-
event.setCancelled(true);
147-
148-
// we can also handle case sensitivity here:
149-
if (SkriptConfig.caseInsensitiveCommands.value()) {
150-
cmd[0] = event.getMessage().charAt(0) + label;
151-
event.setMessage(String.join(" ", cmd));
152-
}
153-
}
154-
}
155-
156-
@SuppressWarnings("null")
157-
@EventHandler(priority = EventPriority.HIGHEST)
158-
public void onServerCommand(ServerCommandEvent event) {
159-
if (event.getCommand().isEmpty() || event.isCancelled())
160-
return;
161-
if ((Skript.testing() || SkriptConfig.enableEffectCommands.value()) && event.getCommand().startsWith(SkriptConfig.effectCommandToken.value())) {
162-
if (handleEffectCommand(event.getSender(), event.getCommand()))
163-
event.setCancelled(true);
164-
}
165-
}
166-
};
167-
168126
static boolean handleEffectCommand(CommandSender sender, String command) {
169127
if (!(Skript.testing() || sender instanceof ConsoleCommandSender || sender.hasPermission("skript.effectcommands") || SkriptConfig.allowOpsToUseEffectCommands.value() && sender.isOp()))
170128
return false;
@@ -279,8 +237,6 @@ public static void unregisterCommand(ScriptCommand scriptCommand) {
279237

280238
public static void registerListeners() {
281239
if (!registeredListeners) {
282-
Bukkit.getPluginManager().registerEvents(commandListener, Skript.getInstance());
283-
284240
Bukkit.getPluginManager().registerEvents(new Listener() {
285241
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
286242
public void onPlayerChat(AsyncPlayerChatEvent event) {

src/main/java/ch/njol/skript/command/ScriptCommand.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464

6565
/**
6666
* This class is used for user-defined commands.
67+
* @deprecated There is no direct replacement for this command.
68+
* The closest alternative is {@link org.skriptlang.skript.bukkit.command.custom.ScriptBrigadierCommand}.
6769
*/
70+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
6871
public class ScriptCommand implements TabExecutor {
6972

7073
public final static Message m_executable_by_players = new Message("commands.executable by players");
@@ -332,7 +335,7 @@ public boolean execute(final CommandSender sender, final String commandLabel, fi
332335
boolean execute2(final ScriptCommandEvent event, final CommandSender sender, final String commandLabel, final String rest) {
333336
final ParseLogHandler log = SkriptLogger.startParseLogHandler();
334337
try {
335-
final boolean ok = SkriptParser.parseArguments(rest, ScriptCommand.this, event);
338+
final boolean ok = false;
336339
if (!ok) {
337340
final LogEntry e = log.getError();
338341
if (e != null)

src/main/java/ch/njol/skript/command/ScriptCommandEvent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import org.bukkit.entity.Player;
77
import org.bukkit.event.HandlerList;
88

9+
/**
10+
* @deprecated There is no direct replacement for this class.
11+
* The closest alternative is {@link org.skriptlang.skript.bukkit.command.custom.ScriptCommandEvent}.
12+
*/
13+
@Deprecated(since = "INSERT VERSION", forRemoval = true)
914
public class ScriptCommandEvent extends CommandEvent {
1015

1116
private final ScriptCommand scriptCommand;
Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1 @@
1-
/**
2-
* This file is part of Skript.
3-
*
4-
* Skript is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* Skript is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
16-
*
17-
* Copyright Peter Güttinger, SkriptLang team and contributors
18-
*/
19-
/**
20-
* Code related to handling commands, either Skript commands or custom script commands.
21-
*
22-
* @author Peter Güttinger
23-
*/
241
package ch.njol.skript.command;
25-

src/main/java/ch/njol/skript/effects/EffScriptFile.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import ch.njol.skript.ScriptLoader.ScriptInfo;
55
import ch.njol.skript.Skript;
66
import ch.njol.skript.SkriptCommand;
7-
import ch.njol.skript.command.ScriptCommand;
87
import ch.njol.skript.doc.Description;
98
import ch.njol.skript.doc.Example;
109
import ch.njol.skript.doc.Name;

src/main/java/ch/njol/skript/lang/SkriptParser.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import ch.njol.skript.SkriptConfig;
66
import ch.njol.skript.classes.ClassInfo;
77
import ch.njol.skript.classes.Parser;
8-
import ch.njol.skript.command.Argument;
98
import ch.njol.skript.command.Commands;
10-
import ch.njol.skript.command.ScriptCommand;
11-
import ch.njol.skript.command.ScriptCommandEvent;
129
import ch.njol.skript.expressions.ExprParse;
1310
import ch.njol.skript.lang.DefaultExpressionUtils.DefaultExpressionError;
1411
import ch.njol.skript.lang.function.ExprFunctionCall;
@@ -1217,30 +1214,6 @@ public <T> org.skriptlang.skript.common.function.FunctionReference<T> parseFunct
12171214
return new FunctionReference<>(newReference.name(), null, newReference.namespace(), types, expressions);
12181215
}
12191216

1220-
/*
1221-
* Command parsing
1222-
*/
1223-
1224-
/**
1225-
* Prints parse errors (i.e. must start a ParseLog before calling this method)
1226-
*/
1227-
public static boolean parseArguments(String args, ScriptCommand command, ScriptCommandEvent event) {
1228-
SkriptParser parser = new SkriptParser(args, PARSE_LITERALS, ParseContext.COMMAND);
1229-
ParseResult parseResult = parser.parse_i(command.getPattern());
1230-
if (parseResult == null)
1231-
return false;
1232-
1233-
List<Argument<?>> arguments = command.getArguments();
1234-
assert arguments.size() == parseResult.exprs.length;
1235-
for (int i = 0; i < parseResult.exprs.length; i++) {
1236-
if (parseResult.exprs[i] == null)
1237-
arguments.get(i).setToDefault(event);
1238-
else
1239-
arguments.get(i).set(event, parseResult.exprs[i].getArray(event));
1240-
}
1241-
return true;
1242-
}
1243-
12441217
/*
12451218
* Utility methods
12461219
*/

0 commit comments

Comments
 (0)