Compare commits

...

29 commits

Author SHA1 Message Date
853e5ec60a fix the fix 2024-06-24 23:34:47 -04:00
b830c55f7c Re-block chat commands 2024-06-24 23:29:22 -04:00
6bcc4ad5ae Merge branch 'vanilla-format' of https://github.com/OptimisticDeving/extras 2024-06-24 23:28:09 -04:00
fb209a44c3
Fix URL replacement in vanilla format 2024-06-25 03:23:12 +00:00
04570df0ea Merge branch 'vanilla-format' of https://github.com/OptimisticDeving/extras 2024-06-24 22:02:57 -04:00
86e6f8b57e Merge branch 'respect-death-messages-gamerule' of https://github.com/OptimisticDeving/extras 2024-06-24 22:02:49 -04:00
7c71a2a3ce Merge branch 'make-join-title-use-adventure' of https://github.com/OptimisticDeving/extras 2024-06-24 22:02:38 -04:00
6aa5ef344c Merge branch 'improved-skin' of https://github.com/OptimisticDeving/extras 2024-06-24 22:02:26 -04:00
eabdebb3ec Merge branch 'fix-server-command-oob-exception' of https://github.com/OptimisticDeving/extras 2024-06-24 22:02:17 -04:00
a1c0c5d48c Merge branch 'cached-spec' of https://github.com/OptimisticDeving/extras 2024-06-24 22:01:54 -04:00
b0339fcd29
Don't broadcast death messages from worlds with showDeathMessages disabled 2024-06-24 21:11:50 +00:00
aaf135365e
Check if the death message is null before broadcasting it 2024-06-24 20:29:27 +00:00
f75be147c1
Use Bukkit.broadcast instead of looping through getOnlinePlayers 2024-06-24 20:28:11 +00:00
8bd65b82b2
Fix Adventure usage for join title & subtitle 2024-06-23 18:50:07 +00:00
901b136fa8
Add more detailed error messages to /skin and a timeout of 15 seconds 2024-06-23 15:56:41 +00:00
90ef97a6c0
Allow players to select the vanilla chat format 2024-06-23 15:46:44 +00:00
42171a943f
Fix OOB exception in ServerCommand when the command is just a space 2024-06-23 15:15:24 +00:00
190a40e864
Cache output of CPU model grabbing command 2024-06-23 14:54:36 +00:00
5a7c8fad92 update the thing 2024-06-21 10:30:18 -04:00
a558a5dc8a among 2024-02-11 17:52:52 -05:00
1334e758e2 update extras 2023-12-12 12:00:40 -05:00
f31c62f40e Merge branch 'master' of https://code.chipmunk.land/kaboomserver/extras 2023-07-25 23:48:02 -04:00
86ffc9920f amogus 2023-04-24 22:24:21 -04:00
03327f85e9 Merge remote-tracking branch 'upstream/master' 2023-03-23 11:57:22 -04:00
6d9323d50d Make the taken username check more accurate (#336)
Instead of using `Bukkit.getPlayer(name)`, now each player is manually iterated over to check if a username is taken. This fixes multiple problems, such as a player not being able to set their name to `a` because a player named `ab` is online, and a player not being able to set their username back to the one they joined with.
2023-02-06 21:45:58 -05:00
696463e663 Fix the usage of the skin command (#335) 2023-02-06 21:45:58 -05:00
79b4803bd2 Append to an empty component instead of the prefix (#334) 2023-01-09 21:49:47 -05:00
978fad1c83 Unblock say too 2022-12-31 17:53:48 -05:00
9d5c0232aa Unblock some commands in execute
Commands for sending chat messages, teleportation, and summoning entities are unblocked for now.
2022-12-31 14:27:14 -05:00
8 changed files with 158 additions and 37 deletions

View file

@ -1,18 +1,47 @@
package pw.kaboom.extras.commands;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import pw.kaboom.extras.util.Lazy;
import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.util.Collections;
import java.util.List;
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,
final String value) {
target.sendMessage(
@ -52,26 +81,8 @@ 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) {
for (final String modelLine: CPU_MODEL_SUPPLIER.get()) {
sendInfoMessage(sender, "CPU model", modelLine);
}
sendInfoMessage(sender, "CPU cores",

View file

@ -83,11 +83,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

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

@ -24,9 +24,9 @@ public final class ServerCommand implements Listener {
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"};
"locate", "locatebiome", "me", "msg", "reload", "save-all", /* "say", */ "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 +62,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) {

View file

@ -0,0 +1,23 @@
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;
}
}