-
-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy pathCommandReloader.java
More file actions
53 lines (46 loc) · 1.55 KB
/
Copy pathCommandReloader.java
File metadata and controls
53 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ch.njol.skript.bukkitutil;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.Skript;
/**
* Utilizes CraftServer with reflection to re-send commands to clients.
* @deprecated This behavior should not be relied upon. There is no replacement.
*/
@Deprecated(since = "INSERT VERSION", forRemoval = true)
public class CommandReloader {
@Nullable
private static Method syncCommandsMethod;
static {
try {
syncCommandsMethod = Bukkit.getServer().getClass().getDeclaredMethod("syncCommands");
if (syncCommandsMethod != null)
syncCommandsMethod.setAccessible(true);
} catch (NoSuchMethodException e) {
// Ignore except for debugging. This is not necessary or in any way supported functionality
if (Skript.debug())
e.printStackTrace();
}
}
/**
* Attempts to register Bukkit commands to Brigadier and synchronize them
* to all clients. This <i>may</i> fail for any reason or no reason at all!
* @param server Server to use.
* @return Whether it is likely that we succeeded or not.
*/
public static boolean syncCommands(Server server) {
if (syncCommandsMethod == null)
return false; // Method not available, can't sync
try {
syncCommandsMethod.invoke(server);
return true; // Sync probably succeeded
} catch (Throwable e) {
if (Skript.debug()) {
Skript.info("syncCommands failed; stack trace for debugging below");
e.printStackTrace();
}
return false; // Something went wrong, sync probably failed
}
}
}