Compare commits

..

11 commits

Author SHA1 Message Date
39feb26c93
Block spawnpoint in execute (#365) 2024-09-24 00:51:25 +03:00
Kaboom
d36503ed3f
CommandServerInfo.java: remove CPU info
This can be re-added if we find a way to do it without using shell commands.

Closes #354
2024-09-11 02:32:54 +03:00
60b20ab4bf
Respect death messages gamerule (#359)
* Use Bukkit.broadcast instead of looping through getOnlinePlayers

* Check if the death message is null before broadcasting it

* Don't broadcast death messages from worlds with showDeathMessages disabled
2024-09-11 02:29:22 +03:00
7cc5c4f330d47060
8cca595937
Block give in execute (#363)
Co-authored-by: Kaboom <58372747+kaboombot@users.noreply.github.com>
2024-09-11 02:23:09 +03:00
Kaboom
d882118c96
ServerCommand.java: Fix checkstyle violation 2024-09-11 02:21:19 +03:00
GEOEGII555
3278ddaddc
Block the /execute ... run datapack command (#361)
* Block the /execute ... run datapack command

The /datapack list command is useless, and the other 2 subcommands (/datapack enable and /datapack disable) can be used to cause huge lag on the server.

* Update ServerCommand.java (partial revert)
2024-09-11 02:19:56 +03:00
amy
7450b8bcc9
Don't re-apply command rate-limit when command is ratelimited (#364)
* fix: don't re-apply ratelimit when user is already ratelimited

* fix: lower command ratelimit event priority

Makes command spam not show up in CommandSpy
2024-09-11 02:15:45 +03:00
8fe96bcc2b
Allow players to select the vanilla chat format (#356)
* Allow players to select the vanilla chat format

* Fix URL replacement in vanilla format
2024-08-19 18:35:37 +03:00
2e79421d49
Fix Adventure usage for join title & subtitle (#358) 2024-08-01 11:38:47 +03:00
e20467b7af
Add more detailed error messages to /skin and a timeout of 15 seconds (#357) 2024-08-01 11:37:13 +03:00
6fc8d1117c
Fix OOB exception in ServerCommand when the command is just a space (#355) 2024-08-01 11:36:15 +03:00
5 changed files with 10 additions and 68 deletions

View file

@ -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())
); );

View file

@ -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;
} }
} }

View file

@ -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;

View file

@ -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) {

View file

@ -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;
}
}