forked from kaboomserver/extras
Compare commits
11 commits
853e5ec60a
...
39feb26c93
Author | SHA1 | Date | |
---|---|---|---|
39feb26c93 | |||
|
d36503ed3f | ||
60b20ab4bf | |||
|
8cca595937 | ||
|
d882118c96 | ||
|
3278ddaddc | ||
|
7450b8bcc9 | ||
8fe96bcc2b | |||
2e79421d49 | |||
e20467b7af | |||
6fc8d1117c |
5 changed files with 10 additions and 68 deletions
|
@ -1,47 +1,16 @@
|
||||||
package pw.kaboom.extras.commands;
|
package pw.kaboom.extras.commands;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import pw.kaboom.extras.util.Lazy;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class CommandServerInfo implements CommandExecutor {
|
public final class CommandServerInfo implements CommandExecutor {
|
||||||
private static final Lazy<List<String>> CPU_MODEL_SUPPLIER = new Lazy<>(() -> {
|
|
||||||
final String[] shCommand = {
|
|
||||||
"/bin/sh",
|
|
||||||
"-c",
|
|
||||||
"cat /proc/cpuinfo | grep 'model name' | cut -f 2 -d ':' | awk '{$1=$1}1' | head -1"
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
final Process process = Runtime.getRuntime().exec(shCommand);
|
|
||||||
final InputStreamReader isr = new InputStreamReader(process.getInputStream());
|
|
||||||
final BufferedReader br = new BufferedReader(isr);
|
|
||||||
final List<String> lines = new ObjectArrayList<>();
|
|
||||||
String line;
|
|
||||||
|
|
||||||
while ((line = br.readLine()) != null) {
|
|
||||||
lines.add(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
br.close();
|
|
||||||
return lines;
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
private void sendInfoMessage(final CommandSender target, final String description,
|
private void sendInfoMessage(final CommandSender target, final String description,
|
||||||
final String value) {
|
final String value) {
|
||||||
target.sendMessage(
|
target.sendMessage(
|
||||||
|
@ -81,10 +50,6 @@ public final class CommandServerInfo implements CommandExecutor {
|
||||||
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
|
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
|
||||||
);
|
);
|
||||||
|
|
||||||
for (final String modelLine: CPU_MODEL_SUPPLIER.get()) {
|
|
||||||
sendInfoMessage(sender, "CPU model", modelLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
sendInfoMessage(sender, "CPU cores",
|
sendInfoMessage(sender, "CPU cores",
|
||||||
String.valueOf(Runtime.getRuntime().availableProcessors())
|
String.valueOf(Runtime.getRuntime().availableProcessors())
|
||||||
);
|
);
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.regex.Pattern;
|
||||||
public final class PlayerChat implements Listener {
|
public final class PlayerChat implements Listener {
|
||||||
private static final PlayerChatRenderer CHAT_RENDERER = new PlayerChatRenderer();
|
private static final PlayerChatRenderer CHAT_RENDERER = new PlayerChatRenderer();
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||||
void onAsyncChatEventProcess(final AsyncChatEvent event) {
|
void onAsyncChatEventProcess(final AsyncChatEvent event) {
|
||||||
final UUID playerUuid = event.getPlayer().getUniqueId();
|
final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ public final class PlayerChat implements Listener {
|
||||||
|
|
||||||
if (millisDifference < 50) {
|
if (millisDifference < 50) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.UUID;
|
||||||
import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent;
|
import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ import pw.kaboom.extras.modules.server.ServerCommand;
|
||||||
public final class PlayerCommand implements Listener {
|
public final class PlayerCommand implements Listener {
|
||||||
private static HashMap<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
|
private static HashMap<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||||
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||||
final UUID playerUuid = event.getPlayer().getUniqueId();
|
final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||||
|
|
||||||
|
@ -24,15 +25,12 @@ public final class PlayerCommand implements Listener {
|
||||||
|
|
||||||
if (millisDifference < 75) {
|
if (millisDifference < 75) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommandMillisList().put(playerUuid, System.currentTimeMillis());
|
getCommandMillisList().put(playerUuid, System.currentTimeMillis());
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final CommandSender sender = event.getPlayer();
|
final CommandSender sender = event.getPlayer();
|
||||||
final String command = event.getMessage();
|
final String command = event.getMessage();
|
||||||
final boolean isConsoleCommand = false;
|
final boolean isConsoleCommand = false;
|
||||||
|
|
|
@ -23,10 +23,11 @@ public final class ServerCommand implements Listener {
|
||||||
private static final Pattern SELECTOR_PATTERN = Pattern.compile("(?>\\s)*@[aepsr](?>\\s)*");
|
private static final Pattern SELECTOR_PATTERN = Pattern.compile("(?>\\s)*@[aepsr](?>\\s)*");
|
||||||
private static final Logger LOGGER = JavaPlugin.getPlugin(Main.class).getLogger();
|
private static final Logger LOGGER = JavaPlugin.getPlugin(Main.class).getLogger();
|
||||||
|
|
||||||
private static final String[] COMMANDS = { "execute", "clone", "fill", "forceload", "kick",
|
private static final String[] COMMANDS = { "execute", "clone", "datapack", "fill",
|
||||||
"locate", "locatebiome", "me", "msg", "reload", "save-all", /* "say", */ "spreadplayers",
|
"forceload", "give", "kick", "locate", "locatebiome", "me", "msg", "reload",
|
||||||
"stop", "summon", "teammsg", /* "teleport", */ "tell", "tellraw", "tm", "tp", "w", "place",
|
"save-all", "say", "spawnpoint", "spreadplayers", "stop", "summon", "teammsg",
|
||||||
"fillbiome", "ride", "tick", "jfr" };
|
"teleport", "tell", "tellraw", "tm", "tp", "w", "place", "fillbiome", "ride" ,
|
||||||
|
"tick", "jfr"};
|
||||||
|
|
||||||
public static boolean checkExecuteCommand(final String cmd) {
|
public static boolean checkExecuteCommand(final String cmd) {
|
||||||
for (String command : COMMANDS) {
|
for (String command : COMMANDS) {
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
package pw.kaboom.extras.util;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public final class Lazy<T> implements Supplier<T> {
|
|
||||||
private @Nullable T value;
|
|
||||||
private final Supplier<T> supplier;
|
|
||||||
|
|
||||||
public Lazy(final Supplier<T> supplier) {
|
|
||||||
this.supplier = supplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T get() {
|
|
||||||
if (this.value == null) {
|
|
||||||
this.value = this.supplier.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue