Innovation:
Commands can now be provided with delays (in ticks)

Example:
/say hi !delay:20
This command is now executed with a delay of one second
20 ticks are one second
This commit is contained in:
JaTiTV 2023-07-31 21:09:46 +02:00
parent de6ecdf7a8
commit f40c47e6ab
3 changed files with 63 additions and 18 deletions

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<list size="2"> <list size="2">

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId> <artifactId>T2CodeLib</artifactId>
<version>15.8_dev</version> <version>15.8</version>
<!--version>VERSION_snapshot-0</version--> <!--version>VERSION_snapshot-0</version-->
<!--version>VERSION_beta-0</version--> <!--version>VERSION_beta-0</version-->
<!--version>VERSION_dev-0</version--> <!--version>VERSION_dev-0</version-->
@ -27,8 +27,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>${java.version}</source> <source>9</source>
<target>${java.version}</target> <target>9</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -1,17 +1,38 @@
package net.t2code.t2codelib.SPIGOT.api.commands; package net.t2code.t2codelib.SPIGOT.api.commands;
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
import net.t2code.t2codelib.SPIGOT.system.T2CbungeeCommandSenderReciver; import net.t2code.t2codelib.SPIGOT.system.T2CbungeeCommandSenderReciver;
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import java.rmi.MarshalledObject;
import java.util.Map;
public class T2Ccmd { public class T2Ccmd {
public static void console(String cmd) { public static void console(String cmdInput) {
if (cmd.contains("!onBungee")){ Map.Entry<String,Integer> map = delay(cmdInput);
int delay = map.getValue();
String cmd = map.getKey();
Bukkit.getScheduler().runTaskLater(T2CodeLibMain.getPlugin(), new Runnable() {
@Override
public void run() {
if (cmd.contains("!onBungee")) {
T2CbungeeCommandSenderReciver.sendToBungee(null, cmd.replace("!onBungee", ""), true); T2CbungeeCommandSenderReciver.sendToBungee(null, cmd.replace("!onBungee", ""), true);
}else Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd); } else Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd);
}
}, delay);
} }
public static void player(Player player, String cmd) { public static void player(Player player, String cmdInput) {
Map.Entry<String,Integer> map = delay(cmdInput);
int delay = map.getValue();
String cmd = map.getKey();
Bukkit.getScheduler().runTaskLater(T2CodeLibMain.getPlugin(), new Runnable() {
@Override
public void run() {
if (cmd.contains("!asConsole")) { if (cmd.contains("!asConsole")) {
if (cmd.contains("!onBungee")) { if (cmd.contains("!onBungee")) {
T2CbungeeCommandSenderReciver.sendToBungee(player, cmd.replace("!asConsole", "").replace("!onBungee", ""), true); T2CbungeeCommandSenderReciver.sendToBungee(player, cmd.replace("!asConsole", "").replace("!onBungee", ""), true);
@ -22,4 +43,29 @@ public class T2Ccmd {
} else player.chat("/" + cmd); } else player.chat("/" + cmd);
} }
} }
}, delay);
}
private static Map.Entry<String, Integer> delay(@NotNull String cmdInput) {
T2Cdebug.debugmsg(T2CodeLibMain.getPlugin(), "Input: " + cmdInput);
int delay = 0;
String cmd;
if (cmdInput.contains("!delay:")) {
int i = cmdInput.indexOf("!delay:") + 7;
String s2 = cmdInput.substring(i);
int i2 = 1;
if(s2.contains(" ")) {
i2 = s2.indexOf(" ");
}else{
i2 = s2.length();
}
delay = Integer.parseInt(cmdInput.substring(i, i + i2));
cmd = cmdInput.replace("!delay:" + delay, "");
} else cmd = cmdInput;
return Map.entry(cmd, delay);
}
} }