forked from kaboomserver/extras
Compare commits
11 commits
853e5ec60a
...
39feb26c93
Author | SHA1 | Date | |
---|---|---|---|
39feb26c93 | |||
|
d36503ed3f | ||
60b20ab4bf | |||
|
8cca595937 | ||
|
d882118c96 | ||
|
3278ddaddc | ||
|
7450b8bcc9 | ||
8fe96bcc2b | |||
2e79421d49 | |||
e20467b7af | |||
6fc8d1117c |
8 changed files with 111 additions and 48 deletions
|
@ -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())
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue