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
8 changed files with 111 additions and 48 deletions

View file

@ -7,8 +7,6 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
@ -52,28 +50,6 @@ public final class CommandServerInfo implements CommandExecutor {
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
);
try {
final String[] shCommand = {
"/bin/sh",
"-c",
"cat /proc/cpuinfo | grep 'model name' | cut -f 2 -d ':' | awk '{$1=$1}1' | head -1"
};
final Process process = Runtime.getRuntime().exec(shCommand);
final InputStreamReader isr = new InputStreamReader(process.getInputStream());
final BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
sendInfoMessage(sender, "CPU model",
line
);
}
br.close();
} catch (Exception ignored) {
}
sendInfoMessage(sender, "CPU cores",
String.valueOf(Runtime.getRuntime().availableProcessors())
);

View file

@ -23,7 +23,7 @@ import java.util.regex.Pattern;
public final class PlayerChat implements Listener {
private static final PlayerChatRenderer CHAT_RENDERER = new PlayerChatRenderer();
@EventHandler(priority = EventPriority.HIGHEST)
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
void onAsyncChatEventProcess(final AsyncChatEvent event) {
final UUID playerUuid = event.getPlayer().getUniqueId();
@ -33,6 +33,7 @@ public final class PlayerChat implements Listener {
if (millisDifference < 50) {
event.setCancelled(true);
return;
}
}
@ -83,11 +84,24 @@ public final class PlayerChat implements Listener {
LegacyComponentSerializer
.legacyAmpersand();
private Component renderVanilla(@Nonnull Component displayName,
@Nonnull Component component) {
return Component.translatable(
"chat.type.text",
displayName,
component.replaceText(URL_REPLACEMENT_CONFIG)
);
}
@Override
public @Nonnull Component render(@Nonnull Player player,
@Nonnull Component displayName,
@Nonnull Component component,
@Nonnull Audience audience) {
if (PlayerPrefix.isUsingVanillaFormat(player)) {
return renderVanilla(displayName, component);
}
Component newComponent = Component.empty();
final Component prefix;
Component prefix1;

View file

@ -6,6 +6,7 @@ import java.util.UUID;
import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
@ -14,7 +15,7 @@ import pw.kaboom.extras.modules.server.ServerCommand;
public final class PlayerCommand implements Listener {
private static HashMap<UUID, Long> commandMillisList = new HashMap<UUID, Long>();
@EventHandler
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final UUID playerUuid = event.getPlayer().getUniqueId();
@ -24,15 +25,12 @@ public final class PlayerCommand implements Listener {
if (millisDifference < 75) {
event.setCancelled(true);
return;
}
}
getCommandMillisList().put(playerUuid, System.currentTimeMillis());
if (event.isCancelled()) {
return;
}
final CommandSender sender = event.getPlayer();
final String command = event.getMessage();
final boolean isConsoleCommand = false;

View file

@ -4,6 +4,7 @@ import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
import com.destroystokyo.paper.profile.ProfileProperty;
import com.google.common.base.Charsets;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -29,8 +30,22 @@ import java.util.concurrent.ThreadLocalRandom;
public final class PlayerConnection implements Listener {
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
private static final String TITLE = CONFIG.getString("playerJoinTitle");
private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle");
private static final Component TITLE =
LegacyComponentSerializer.legacySection()
.deserialize(
CONFIG.getString(
"playerJoinTitle",
""
)
);
private static final Component SUBTITLE =
LegacyComponentSerializer.legacySection()
.deserialize(
CONFIG.getString(
"playerJoinSubtitle",
""
)
);
private static final Duration FADE_IN = Duration.ofMillis(50);
private static final Duration STAY = Duration.ofMillis(8000);
private static final Duration FADE_OUT = Duration.ofMillis(250);
@ -70,13 +85,11 @@ public final class PlayerConnection implements Listener {
void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
if (TITLE != null || SUBTITLE != null) {
player.showTitle(Title.title(
Component.text(TITLE),
Component.text(SUBTITLE),
Title.Times.times(FADE_IN, STAY, FADE_OUT)
));
}
player.showTitle(Title.title(
TITLE,
SUBTITLE,
Title.Times.times(FADE_IN, STAY, FADE_OUT)
));
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
}

View file

@ -1,6 +1,9 @@
package pw.kaboom.extras.modules.player;
import io.papermc.paper.event.world.WorldGameRuleChangeEvent;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
@ -9,6 +12,7 @@ import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -19,7 +23,13 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import pw.kaboom.extras.util.Utility;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Objects;
public final class PlayerDamage implements Listener {
private final Map<World, Boolean> deathMessageToggles = new IdentityHashMap<>();
@EventHandler
void onEntityDamage(final EntityDamageEvent event) {
if (EntityType.PLAYER.equals(event.getEntityType())) {
@ -48,12 +58,28 @@ public final class PlayerDamage implements Listener {
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
void onGameRuleChange(final WorldGameRuleChangeEvent event) {
if (event.getGameRule() != GameRule.SHOW_DEATH_MESSAGES) {
return;
}
this.deathMessageToggles.put(event.getWorld(), Boolean.parseBoolean(event.getValue()));
}
@EventHandler
void onPlayerDeath(final PlayerDeathEvent event) {
final Player player = event.getEntity();
final Component deathMessage = event.deathMessage();
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
onlinePlayer.sendMessage(event.deathMessage());
if (deathMessage != null && this.deathMessageToggles.computeIfAbsent(
player.getWorld(),
(key) -> Objects.requireNonNullElse(
key.getGameRuleValue(GameRule.SHOW_DEATH_MESSAGES),
key.getGameRuleDefault(GameRule.SHOW_DEATH_MESSAGES)
)
)) {
Bukkit.broadcast(deathMessage);
}
try {

View file

@ -74,6 +74,14 @@ public final class PlayerPrefix implements Listener {
return prefix;
}
public static boolean isUsingVanillaFormat(Player player) {
final UUID playerUUID = player.getUniqueId();
final String stringifiedUUID = playerUUID.toString();
final String legacyPrefix = PREFIX_CONFIG.getString(stringifiedUUID);
return legacyPrefix != null && legacyPrefix.equals("%");
}
public static Component getPrefix(Player player) throws IOException {
final UUID playerUUID = player.getUniqueId();
final String stringifiedUUID = playerUUID.toString();
@ -94,7 +102,10 @@ public final class PlayerPrefix implements Listener {
private static void onUpdate(Player player) throws IOException {
final Component component = Component.empty()
.append(getPrefix(player))
.append(
isUsingVanillaFormat(player) ?
Component.empty() : getPrefix(player)
)
.append(player.displayName());
player.playerListName(component);

View file

@ -1,6 +1,7 @@
package pw.kaboom.extras.modules.player.skin;
import com.google.gson.Gson;
import java.lang.InterruptedException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
@ -10,8 +11,12 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -58,8 +63,22 @@ public final class SkinManager {
final SkinData skinData;
try {
skinData = getSkinData(name).get();
} catch (Exception e) {
skinData = getSkinData(name).get(15, TimeUnit.SECONDS);
} catch (InterruptedException e) {
if (!shouldSendMessage) {
return;
}
player.sendMessage(Component.text("Skin fetching was interrupted"));
return;
} catch (TimeoutException e) {
if (!shouldSendMessage) {
return;
}
player.sendMessage(Component.text("Took too long to fetch skin"));
return;
} catch (ExecutionException | CompletionException e) {
if(!shouldSendMessage) {
return;
}

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 Logger LOGGER = JavaPlugin.getPlugin(Main.class).getLogger();
private static final String[] COMMANDS = { "execute", "clone", "fill", "forceload", "kick",
"locate", "locatebiome", "me", "msg", "reload", "save-all", "say", "spreadplayers",
"stop", "summon", "teammsg", "teleport", "tell", "tellraw", "tm", "tp", "w", "place",
"fillbiome", "ride" , "tick", "jfr"};
private static final String[] COMMANDS = { "execute", "clone", "datapack", "fill",
"forceload", "give", "kick", "locate", "locatebiome", "me", "msg", "reload",
"save-all", "say", "spawnpoint", "spreadplayers", "stop", "summon", "teammsg",
"teleport", "tell", "tellraw", "tm", "tp", "w", "place", "fillbiome", "ride" ,
"tick", "jfr"};
public static boolean checkExecuteCommand(final String cmd) {
for (String command : COMMANDS) {
@ -62,6 +63,11 @@ public final class ServerCommand implements Listener {
}
final String[] arr = command.split(" ");
if (arr.length == 0) {
return command;
}
String commandName = arr[0].toLowerCase();
if (isConsoleCommand) {