mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-29 06:34:17 +02:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
f3ea35fd93
|
|||
|
a947a303e1
|
|||
|
2bccf45439
|
|||
|
24da79642a
|
|||
|
ea54f83909
|
|||
|
6c76066d8b
|
|||
|
823093be35
|
|||
|
fecd21bf19
|
|||
|
fc8c1c9f26
|
|||
|
f7f541c8a4
|
|||
|
a8f836d94c
|
|||
|
fcd2a513aa
|
|||
|
5c4feea042
|
|||
|
c4e1aedeca
|
|||
|
7907ee87f6
|
@@ -1,34 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report bugs to help us make the plugin better and more reliable.
|
||||
title: "[BUG]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Server**
|
||||
Please provide information about the plugin version and the server.
|
||||
This section should include:
|
||||
1. Server Software
|
||||
2. Server version
|
||||
3. Plugin Version you are using
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this plugin
|
||||
title: "[REQUEST]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||
id("xyz.jpenilla.run-paper") version "${runPaperVersion}"
|
||||
}
|
||||
|
||||
group = 'de.shiewk'
|
||||
@@ -30,17 +30,17 @@ runPaper {
|
||||
}
|
||||
|
||||
runServer {
|
||||
minecraftVersion("1.21.10")
|
||||
minecraftVersion("1.21.11")
|
||||
downloadPlugins {
|
||||
// for testing from other client versions
|
||||
modrinth("ViaVersion", "5.5.1")
|
||||
modrinth("ViaBackwards", "5.5.1")
|
||||
modrinth("ViaVersion", viaVersionVersion)
|
||||
modrinth("ViaBackwards", viaVersionVersion)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//compileOnly "io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT"
|
||||
compileOnly 'dev.folia:folia-api:1.21.4-R0.1-SNAPSHOT'
|
||||
//compileOnly "io.papermc.paper:paper-api:${apiVersion}"
|
||||
compileOnly "dev.folia:folia-api:${apiVersion}"
|
||||
}
|
||||
|
||||
jar {
|
||||
|
||||
+4
-1
@@ -1 +1,4 @@
|
||||
pluginVersion = 1.8.2
|
||||
pluginVersion = 1.8.2
|
||||
apiVersion = 1.21.4-R0.1-SNAPSHOT
|
||||
runPaperVersion = 3.0.2
|
||||
viaVersionVersion = 5.8.0
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -5,14 +5,17 @@ import de.shiewk.smoderation.paper.command.*;
|
||||
import de.shiewk.smoderation.paper.input.ChatInput;
|
||||
import de.shiewk.smoderation.paper.input.ChatInputListener;
|
||||
import de.shiewk.smoderation.paper.listener.*;
|
||||
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
|
||||
import de.shiewk.smoderation.paper.punishments.Ban;
|
||||
import de.shiewk.smoderation.paper.punishments.Kick;
|
||||
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.translation.TranslatorManager;
|
||||
import de.shiewk.smoderation.paper.util.ColorPalette;
|
||||
import de.shiewk.smoderation.paper.util.SModLegacy;
|
||||
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -25,51 +28,86 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import static de.shiewk.smoderation.paper.command.VanishCommand.isVanished;
|
||||
import static de.shiewk.smoderation.paper.command.VanishCommand.toggleVanish;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static org.bukkit.Bukkit.getPluginManager;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class SModerationPaper extends JavaPlugin {
|
||||
|
||||
public static final Gson gson = new Gson();
|
||||
public static final PunishmentContainer container = new PunishmentContainer();
|
||||
public static ComponentLogger LOGGER = null;
|
||||
public static SModerationPaper PLUGIN = null;
|
||||
public static File SAVE_FILE = null;
|
||||
private static SkinTextureProvider textureProvider = null;
|
||||
|
||||
public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255);
|
||||
public static final TextColor SECONDARY_COLOR = TextColor.color(52, 143, 255);
|
||||
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
|
||||
public static final TextComponent CHAT_PREFIX = text("SM \u00BB ").color(PRIMARY_COLOR);
|
||||
private ColorPalette colors;
|
||||
|
||||
private final TranslatorManager translatorManager = new TranslatorManager(
|
||||
Key.key("smoderation", "translations"),
|
||||
createMiniMessage(),
|
||||
"smoderation/translations/",
|
||||
new Locale[] {
|
||||
Locale.forLanguageTag("en-US")
|
||||
Locale.forLanguageTag("en-US"),
|
||||
Locale.forLanguageTag("de-DE")
|
||||
}
|
||||
);
|
||||
|
||||
private PunishmentManager punishmentManager;
|
||||
|
||||
public static FileConfiguration config() {
|
||||
return PLUGIN.getConfig();
|
||||
}
|
||||
|
||||
public static ColorPalette colors() {
|
||||
return PLUGIN.colors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
LOGGER = getComponentLogger();
|
||||
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
|
||||
PLUGIN = this;
|
||||
SAVE_FILE = new File(this.getDataFolder().getAbsolutePath() + "/container.gz");
|
||||
LOGGER.info("Loading translations");
|
||||
translatorManager.load();
|
||||
if (config().getBoolean("custom-messages", false)) {
|
||||
translatorManager.loadCustomMessages(getDataPath().resolve("messages.json"));
|
||||
} else {
|
||||
translatorManager.load();
|
||||
}
|
||||
updateConfig();
|
||||
|
||||
this.punishmentManager = new PunishmentManager(getDataPath().resolve("punishments.v2"));
|
||||
this.punishmentManager.registerType("mute", new Mute.Factory());
|
||||
this.punishmentManager.registerType("ban", new Ban.Factory());
|
||||
this.punishmentManager.registerType("kick", new Kick.Factory());
|
||||
|
||||
this.colors = new ColorPalette(
|
||||
parseColor(config().getString("colors.primary")),
|
||||
parseColor(config().getString("colors.secondary")),
|
||||
parseColor(config().getString("colors.detail"))
|
||||
);
|
||||
|
||||
SModLegacy.migrateV1PunishmentsFile(
|
||||
this.punishmentManager,
|
||||
getDataPath().resolve("container.gz"),
|
||||
getDataPath().resolve("v1-backup.gz")
|
||||
);
|
||||
}
|
||||
|
||||
private TextColor parseColor(String string) {
|
||||
if (string == null || string.length() != 7) {
|
||||
throw new IllegalArgumentException("Color not formatted correctly: " + string);
|
||||
}
|
||||
TextColor color = TextColor.fromHexString(string);
|
||||
if (color == null) {
|
||||
throw new IllegalArgumentException("Color not formatted correctly: " + string);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isFeatureEnabled(String feature){
|
||||
@@ -78,9 +116,8 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
|
||||
|
||||
if (isFeatureEnabled("punishments")) listen(new PunishmentListener());
|
||||
if (isFeatureEnabled("punishments")) listen(new PunishmentListener(punishmentManager));
|
||||
if (isFeatureEnabled("punishments")) listen(new CacheListener(punishmentManager));
|
||||
if (isFeatureEnabled("invsee")) listen(new InvSeeListener());
|
||||
if (isFeatureEnabled("enderchestsee")) listen(new EnderchestSeeListener());
|
||||
if (isFeatureEnabled("socialspy")) listen(new SocialSpyListener());
|
||||
@@ -93,15 +130,15 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
Commands commands = event.registrar();
|
||||
|
||||
if (isFeatureEnabled("punishments")){
|
||||
registerCommand(commands, new KickCommand());
|
||||
registerCommand(commands, new ModLogsCommand());
|
||||
registerCommand(commands, new UnmuteCommand());
|
||||
registerCommand(commands, new UnbanCommand());
|
||||
registerCommand(commands, new MuteCommand());
|
||||
registerCommand(commands, new BanCommand());
|
||||
registerCommand(commands, new KickCommand(punishmentManager));
|
||||
registerCommand(commands, new ModLogsCommand(punishmentManager));
|
||||
registerCommand(commands, new UnmuteCommand(punishmentManager));
|
||||
registerCommand(commands, new UnbanCommand(punishmentManager));
|
||||
registerCommand(commands, new MuteCommand(punishmentManager));
|
||||
registerCommand(commands, new BanCommand(punishmentManager));
|
||||
|
||||
if (isFeatureEnabled("smodmenu")){
|
||||
registerCommand(commands, new SModCommand());
|
||||
registerCommand(commands, new SModCommand(punishmentManager));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +157,6 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
}
|
||||
|
||||
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1);
|
||||
|
||||
container.load(SAVE_FILE);
|
||||
}
|
||||
|
||||
private void listen(Listener listener) {
|
||||
@@ -138,7 +173,6 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SModerationPaper.container.save(SModerationPaper.SAVE_FILE);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// in case players are still vanished when the server shuts down
|
||||
if (isVanished(player)){
|
||||
@@ -158,9 +192,9 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
private MiniMessage createMiniMessage() {
|
||||
return MiniMessage.builder()
|
||||
.tags(TagResolver.builder()
|
||||
.resolver(TagResolver.resolver("prefix", Tag.inserting(CHAT_PREFIX)))
|
||||
.resolver(TagResolver.resolver("primary", Tag.styling(style -> style.color(PRIMARY_COLOR))))
|
||||
.resolver(TagResolver.resolver("secondary", Tag.styling(style -> style.color(SECONDARY_COLOR))))
|
||||
.resolver(TagResolver.resolver("primary", Tag.styling(style -> style.color(colors().primary()))))
|
||||
.resolver(TagResolver.resolver("secondary", Tag.styling(style -> style.color(colors().secondary()))))
|
||||
.resolver(TagResolver.resolver("detail", Tag.styling(style -> style.color(colors().detail()))))
|
||||
.resolver(TagResolver.standard())
|
||||
.build()
|
||||
)
|
||||
@@ -181,14 +215,29 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
|
||||
boolean changedSomething = false;
|
||||
for (String key : defaultConfig.getKeys(true)) {
|
||||
if (!config.contains(key)) { // There's a new key in the default config
|
||||
if (!config.contains(key)) {
|
||||
// There's a new key in the default config
|
||||
config.set(key, defaultConfig.get(key));
|
||||
changedSomething = true;
|
||||
}
|
||||
|
||||
List<String> defaultComments = new ArrayList<>(defaultConfig.getComments(key));
|
||||
List<String> comments = new ArrayList<>(config.getComments(key));
|
||||
defaultComments.removeIf(Objects::isNull);
|
||||
comments.removeIf(Objects::isNull);
|
||||
|
||||
if (!defaultComments.equals(comments)) {
|
||||
// Comments changed
|
||||
config.setComments(key, defaultConfig.getComments(key));
|
||||
changedSomething = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the updated configuration file
|
||||
if (changedSomething) saveConfig();
|
||||
if (changedSomething){
|
||||
LOGGER.info("Changing config file to add new options/documentation");
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Could not update config", e);
|
||||
|
||||
@@ -8,7 +8,9 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.command.argument.DurationArgument;
|
||||
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||
import de.shiewk.smoderation.paper.punishments.Ban;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -21,8 +23,15 @@ import java.util.UUID;
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class BanCommand implements CommandProvider {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public BanCommand(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("ban")
|
||||
@@ -45,7 +54,7 @@ public final class BanCommand implements CommandProvider {
|
||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||
UUID target = context.getArgument("player", UUID.class);
|
||||
long duration = context.getArgument("duration", Long.class);
|
||||
executeBan(sender, target, duration, Punishment.DEFAULT_REASON);
|
||||
executeBan(punishmentManager, sender, target, duration, SModerationPaper.config().getString("default-reason", "No reason provided."));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -54,17 +63,17 @@ public final class BanCommand implements CommandProvider {
|
||||
UUID target = context.getArgument("player", UUID.class);
|
||||
long duration = context.getArgument("duration", Long.class);
|
||||
String reason = StringArgumentType.getString(context, "reason");
|
||||
executeBan(sender, target, duration, reason);
|
||||
executeBan(punishmentManager, sender, target, duration, reason);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static void executeBan(UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
|
||||
public static void executeBan(PunishmentManager manager, UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
|
||||
Player targetPlayer = Bukkit.getPlayer(target);
|
||||
if (duration == 0){
|
||||
if (targetPlayer == null){
|
||||
CommandUtil.errorTranslatable("smod.command.ban.fail.tooShort");
|
||||
} else {
|
||||
KickCommand.executeKick(sender, targetPlayer, reason);
|
||||
KickCommand.executeKick(manager, sender, targetPlayer, reason);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -74,14 +83,18 @@ public final class BanCommand implements CommandProvider {
|
||||
if (targetPlayer != null && targetPlayer.hasPermission("smod.preventban")){
|
||||
CommandUtil.errorTranslatable("smod.command.ban.fail.protect");
|
||||
} else {
|
||||
final Punishment punishment = Punishment.ban(
|
||||
if (!manager.byTargetUUID(target, p -> p instanceof Ban ban && ban.isActive()).isEmpty()) {
|
||||
CommandUtil.errorTranslatable("smod.command.ban.fail.alreadyBanned");
|
||||
}
|
||||
Punishment punishment = new Ban(
|
||||
Punishment.generateUUID(),
|
||||
System.currentTimeMillis(),
|
||||
System.currentTimeMillis() + duration,
|
||||
sender,
|
||||
target,
|
||||
reason
|
||||
reason,
|
||||
duration
|
||||
);
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
manager.tryIssue(punishment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public interface CommandProvider {
|
||||
|
||||
LiteralCommandNode<CommandSourceStack> getCommandNode();
|
||||
|
||||
@@ -16,6 +16,7 @@ import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class EnderchestSeeCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class InvseeCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,9 @@ import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.punishments.Kick;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
@@ -19,8 +21,15 @@ import java.util.UUID;
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class KickCommand implements CommandProvider {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public KickCommand(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("kick")
|
||||
@@ -38,7 +47,7 @@ public final class KickCommand implements CommandProvider {
|
||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||
String reason = StringArgumentType.getString(context, "reason");
|
||||
executeKick(sender, target, reason);
|
||||
executeKick(punishmentManager, sender, target, reason);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -48,24 +57,25 @@ public final class KickCommand implements CommandProvider {
|
||||
}
|
||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||
executeKick(sender, target, Punishment.DEFAULT_REASON);
|
||||
executeKick(punishmentManager, sender, target, SModerationPaper.config().getString("default-reason", "No reason provided."));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static void executeKick(UUID sender, Player target, String reason) throws CommandSyntaxException {
|
||||
public static void executeKick(PunishmentManager manager, UUID sender, Player target, String reason) throws CommandSyntaxException {
|
||||
UUID targetId = target.getUniqueId();
|
||||
if (sender.equals(targetId)) {
|
||||
CommandUtil.errorTranslatable("smod.command.kick.fail.self");
|
||||
} else if (target.hasPermission("smod.preventkick")){
|
||||
CommandUtil.errorTranslatable("smod.command.kick.fail.protect");
|
||||
}
|
||||
final Punishment punishment = Punishment.kick(
|
||||
Punishment punishment = new Kick(
|
||||
Punishment.generateUUID(),
|
||||
System.currentTimeMillis(),
|
||||
sender,
|
||||
targetId,
|
||||
reason
|
||||
);
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
manager.tryIssue(punishment);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
@@ -15,14 +17,20 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.container;
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class ModLogsCommand implements CommandProvider {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public ModLogsCommand(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("modlogs")
|
||||
@@ -38,13 +46,19 @@ public final class ModLogsCommand implements CommandProvider {
|
||||
UUID uuid = context.getArgument("player", UUID.class);
|
||||
String name = PlayerUtil.offlinePlayerName(uuid);
|
||||
sender.sendMessage(translatable("smod.command.modlogs.heading", text(name), text(uuid.toString())));
|
||||
final List<Punishment> punishments = container.findAll(p -> p.to.equals(uuid) && p.isActive());
|
||||
List<Punishment> punishments = punishmentManager.byTargetUUID(uuid);
|
||||
for (Punishment punishment : punishments) {
|
||||
sender.sendMessage(translatable("smod.command.modlogs." + punishment.type.name().toLowerCase(),
|
||||
TimeUtil.calendarTimestamp(punishment.until),
|
||||
TimeUtil.formatTimeLong(punishment.until - System.currentTimeMillis()),
|
||||
text(punishment.reason)
|
||||
));
|
||||
if (punishment instanceof TimedPunishment timed && timed.isActive()){
|
||||
if (timed.isPermanent()){
|
||||
sender.sendMessage(translatable("smod.command.modlogs." + punishment.getType() + ".permanent", text(punishment.getReason())));
|
||||
} else {
|
||||
sender.sendMessage(translatable("smod.command.modlogs." + punishment.getType(),
|
||||
TimeUtil.calendarTimestamp(timed.getExpiry()),
|
||||
TimeUtil.formatTimeLong(timed.getExpiry() - System.currentTimeMillis()),
|
||||
text(punishment.getReason())
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (punishments.isEmpty()){
|
||||
sender.sendMessage(translatable("smod.command.modlogs.none"));
|
||||
|
||||
@@ -8,7 +8,9 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.command.argument.DurationArgument;
|
||||
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -21,8 +23,15 @@ import java.util.UUID;
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class MuteCommand implements CommandProvider {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public MuteCommand(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("mute")
|
||||
@@ -45,7 +54,7 @@ public final class MuteCommand implements CommandProvider {
|
||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||
UUID target = context.getArgument("player", UUID.class);
|
||||
long duration = context.getArgument("duration", Long.class);
|
||||
executeMute(sender, target, duration, Punishment.DEFAULT_REASON);
|
||||
executeMute(punishmentManager, sender, target, duration, SModerationPaper.config().getString("default-reason", "No reason provided."));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -54,11 +63,11 @@ public final class MuteCommand implements CommandProvider {
|
||||
UUID target = context.getArgument("player", UUID.class);
|
||||
long duration = context.getArgument("duration", Long.class);
|
||||
String reason = StringArgumentType.getString(context, "reason");
|
||||
executeMute(sender, target, duration, reason);
|
||||
executeMute(punishmentManager, sender, target, duration, reason);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static void executeMute(UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
|
||||
public static void executeMute(PunishmentManager manager, UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
|
||||
if (duration == 0){
|
||||
CommandUtil.errorTranslatable("smod.command.mute.fail.tooShort");
|
||||
}
|
||||
@@ -69,14 +78,18 @@ public final class MuteCommand implements CommandProvider {
|
||||
if (targetPlayer != null && targetPlayer.hasPermission("smod.preventmute")){
|
||||
CommandUtil.errorTranslatable("smod.command.mute.fail.protect");
|
||||
} else {
|
||||
final Punishment punishment = Punishment.mute(
|
||||
if (!manager.byTargetUUID(target, p -> p instanceof Mute mute && mute.isActive()).isEmpty()) {
|
||||
CommandUtil.errorTranslatable("smod.command.mute.fail.alreadyMuted");
|
||||
}
|
||||
Punishment punishment = new Mute(
|
||||
Punishment.generateUUID(),
|
||||
System.currentTimeMillis(),
|
||||
System.currentTimeMillis() + duration,
|
||||
sender,
|
||||
target,
|
||||
reason
|
||||
reason,
|
||||
duration
|
||||
);
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
manager.tryIssue(punishment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class OfflineTPCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.inventory.SModMenu;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -15,8 +15,15 @@ import java.util.List;
|
||||
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class SModCommand implements CommandProvider {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public SModCommand(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("smod")
|
||||
@@ -27,7 +34,7 @@ public final class SModCommand implements CommandProvider {
|
||||
|
||||
private int openMenu(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
Player player = CommandUtil.getExecutingPlayer(context.getSource());
|
||||
new SModMenu(player, SModerationPaper.container).open();
|
||||
new SModMenu(player, punishmentManager).open();
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class SocialSpyCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,10 +4,11 @@ import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||
import de.shiewk.smoderation.paper.punishments.Ban;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
|
||||
@@ -18,8 +19,15 @@ import java.util.UUID;
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class UnbanCommand implements CommandProvider {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public UnbanCommand(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("unban")
|
||||
@@ -33,13 +41,14 @@ public final class UnbanCommand implements CommandProvider {
|
||||
private int unbanPlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
UUID senderUUID = CommandUtil.getSenderUUID(context.getSource());
|
||||
UUID target = context.getArgument("player", UUID.class);
|
||||
final Punishment punishment = SModerationPaper.container.find(
|
||||
p -> p.to.equals(target) && p.isActive() && p.type == PunishmentType.BAN
|
||||
final List<Punishment> punishments = punishmentManager.byTargetUUID(
|
||||
target,
|
||||
p -> p instanceof Ban ban && ban.isActive()
|
||||
);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModerationPaper.container);
|
||||
} else {
|
||||
for (Punishment punishment : punishments) {
|
||||
punishmentManager.cancel((TimedPunishment) punishment, senderUUID);
|
||||
}
|
||||
if (punishments.isEmpty()) {
|
||||
CommandUtil.errorTranslatable("smod.command.unban.fail.notBanned");
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
|
||||
@@ -4,10 +4,11 @@ import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
|
||||
@@ -18,8 +19,15 @@ import java.util.UUID;
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class UnmuteCommand implements CommandProvider {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public UnmuteCommand(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("unmute")
|
||||
@@ -33,14 +41,15 @@ public final class UnmuteCommand implements CommandProvider {
|
||||
private int unmutePlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
UUID senderUUID = CommandUtil.getSenderUUID(context.getSource());
|
||||
UUID target = context.getArgument("player", UUID.class);
|
||||
final Punishment punishment = SModerationPaper.container.find(
|
||||
p -> p.to.equals(target) && p.isActive() && p.type == PunishmentType.MUTE
|
||||
final List<Punishment> punishments = punishmentManager.byTargetUUID(
|
||||
target,
|
||||
p -> p instanceof Mute mute && mute.isActive()
|
||||
);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModerationPaper.container);
|
||||
} else {
|
||||
CommandUtil.errorTranslatable("smod.command.unmute.fail.notMuted");
|
||||
for (Punishment punishment : punishments) {
|
||||
punishmentManager.cancel((TimedPunishment) punishment, senderUUID);
|
||||
}
|
||||
if (punishments.isEmpty()) {
|
||||
CommandUtil.errorTranslatable("smod.command.unmute.fail.notBanned");
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.event.VanishToggleEvent;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
@@ -26,6 +27,7 @@ import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
import static net.kyori.adventure.text.Component.*;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class VanishCommand implements CommandProvider {
|
||||
|
||||
public static final NamespacedKey KEY_VANISHED = new NamespacedKey("smoderation", "vanished");
|
||||
@@ -91,7 +93,7 @@ public final class VanishCommand implements CommandProvider {
|
||||
}
|
||||
if (newStatus){
|
||||
vanishedPlayers.add(player);
|
||||
for (CommandSender sender : SModerationPaper.container.collectBroadcastTargets()) {
|
||||
for (CommandSender sender : Punishment.getBroadcastTargets()) {
|
||||
sender.sendMessage(translatable("smod.command.vanish.broadcast.on", player.teamDisplayName()));
|
||||
}
|
||||
player.sendMessage(translatable("smod.command.vanish.toggle.on"));
|
||||
@@ -103,7 +105,7 @@ public final class VanishCommand implements CommandProvider {
|
||||
}
|
||||
} else {
|
||||
vanishedPlayers.remove(player);
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
for (CommandSender sender : Punishment.getBroadcastTargets()) {
|
||||
sender.sendMessage(translatable("smod.command.vanish.broadcast.off", player.teamDisplayName()));
|
||||
}
|
||||
player.sendMessage(translatable("smod.command.vanish.toggle.off"));
|
||||
@@ -149,11 +151,11 @@ public final class VanishCommand implements CommandProvider {
|
||||
for (ObjectListIterator<Player> iterator = vanishedPlayers.iterator(); iterator.hasNext(); ) {
|
||||
Player vanishedPlayer = iterator.next();
|
||||
vanishList = vanishList.append(
|
||||
vanishedPlayer.teamDisplayName().colorIfAbsent(SECONDARY_COLOR)
|
||||
vanishedPlayer.teamDisplayName().colorIfAbsent(SModerationPaper.colors().secondary())
|
||||
);
|
||||
if (iterator.hasNext()){
|
||||
vanishList = vanishList.append(
|
||||
text().content(", ").color(PRIMARY_COLOR)
|
||||
text().content(", ").color(SModerationPaper.colors().primary())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,18 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.regex.MatchResult;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class DurationArgument implements CustomArgumentType.Converted<Long, String> {
|
||||
|
||||
public static final Pattern DURATION_PATTERN = Pattern.compile("([0-9]{1,9})(ms|s|min|h|d|w|mo|y)");
|
||||
public static final Pattern VALIDATION_PATTERN = Pattern.compile("(([0-9]{1,9})(ms|s|min|h|d|w|mo|y))+");
|
||||
public static final long INFINITE_DURATION = -1L;
|
||||
|
||||
@Override
|
||||
public @NotNull Long convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||
if (nativeType.startsWith("perm") || nativeType.startsWith("inf")) {
|
||||
return INFINITE_DURATION;
|
||||
}
|
||||
if (!VALIDATION_PATTERN.matcher(nativeType).matches()){
|
||||
CommandUtil.errorTranslatable("smod.argument.duration.fail.pattern");
|
||||
}
|
||||
@@ -57,6 +62,8 @@ public final class DurationArgument implements CustomArgumentType.Converted<Long
|
||||
public @NotNull <S> CompletableFuture<Suggestions> listSuggestions(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
|
||||
if (builder.getRemaining().isBlank()){
|
||||
List.of(
|
||||
"infinite", "inf",
|
||||
"permanent", "perm",
|
||||
"100ms",
|
||||
"15s",
|
||||
"2min",
|
||||
|
||||
+3
-1
@@ -11,13 +11,15 @@ import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class OfflinePlayerArgument implements CustomArgumentType.Converted<OfflinePlayer, String> {
|
||||
|
||||
@Override
|
||||
public OfflinePlayer convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||
public @NonNull OfflinePlayer convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayerIfCached(nativeType);
|
||||
if (player != null){
|
||||
return player;
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class PlayerUUIDArgument implements CustomArgumentType.Converted<UUID, String> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.shiewk.smoderation.paper.event;
|
||||
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@@ -11,20 +11,20 @@ public class PunishmentIssueEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
|
||||
private final Punishment punishment;
|
||||
private final PunishmentContainer container;
|
||||
private final PunishmentManager manager;
|
||||
private boolean cancelled;
|
||||
|
||||
public PunishmentIssueEvent(Punishment punishment, PunishmentContainer container) {
|
||||
public PunishmentIssueEvent(Punishment punishment, PunishmentManager manager) {
|
||||
this.punishment = punishment;
|
||||
this.container = container;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public Punishment getPunishment() {
|
||||
return punishment;
|
||||
}
|
||||
|
||||
public PunishmentContainer getContainer() {
|
||||
return container;
|
||||
public PunishmentManager getPunishmentManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.shiewk.smoderation.paper.input;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -10,7 +11,6 @@ import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.CHAT_PREFIX;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ChatInput {
|
||||
|
||||
public static void prompt(Player player, Consumer<Component> consumer, Component prompt, int timeSeconds){
|
||||
runningInputs.put(player, new ChatInput(player, prompt, consumer, timeSeconds));
|
||||
player.sendMessage(CHAT_PREFIX.append(prompt));
|
||||
player.sendMessage(prompt.colorIfAbsent(SModerationPaper.colors().primary()));
|
||||
}
|
||||
|
||||
public Component getPrompt() {
|
||||
|
||||
@@ -15,37 +15,35 @@ import org.jetbrains.annotations.NotNull;
|
||||
import static de.shiewk.smoderation.paper.inventory.CustomInventory.renderComponent;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public class ConfirmationInventory implements CustomInventory {
|
||||
private final Inventory inventory;
|
||||
private final Player player;
|
||||
private final Component prompt;
|
||||
private final ItemStack yesStack;
|
||||
private final ItemStack noStack;
|
||||
private final Runnable onAccept;
|
||||
private final Runnable onReject;
|
||||
private final boolean reversed;
|
||||
|
||||
public ConfirmationInventory(Player player, Component prompt, Runnable onAccept, Runnable onReject, boolean reversed) {
|
||||
public ConfirmationInventory(Player player, Component prompt, Runnable onAccept, Runnable onReject) {
|
||||
this.player = player;
|
||||
this.prompt = prompt;
|
||||
this.onAccept = onAccept;
|
||||
this.onReject = onReject;
|
||||
this.reversed = reversed;
|
||||
inventory = Bukkit.createInventory(this, InventoryType.HOPPER, this.prompt);
|
||||
yesStack = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
|
||||
noStack = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
yesStack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, applyFormatting(translatable("smod.confirm.yes"))));
|
||||
noStack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, applyFormatting(translatable("smod.confirm.no"))));
|
||||
ItemStack accept = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
|
||||
ItemStack confirmation = new ItemStack(Material.PAPER);
|
||||
confirmation.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, prompt.colorIfAbsent(NamedTextColor.GOLD)));
|
||||
ItemStack reject = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||
|
||||
inventory.setItem(reversed ? 4 : 0, noStack);
|
||||
accept.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, applyFormatting(translatable("smod.confirm.yes"))));
|
||||
confirmation.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, prompt.colorIfAbsent(NamedTextColor.GOLD)));
|
||||
reject.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, applyFormatting(translatable("smod.confirm.no"))));
|
||||
|
||||
inventory.setItem(0, accept);
|
||||
inventory.setItem(2, confirmation);
|
||||
inventory.setItem(reversed ? 0 : 4, yesStack);
|
||||
inventory.setItem(4, reject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,11 +53,11 @@ public class ConfirmationInventory implements CustomInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
if (yesStack.equals(stack)){
|
||||
public void click(InventoryClickEvent event) {
|
||||
if (event.getSlot() == 0){
|
||||
inventory.close();
|
||||
onAccept.run();
|
||||
} else if (noStack.equals(stack)) {
|
||||
} else if (event.getSlot() == 4) {
|
||||
inventory.close();
|
||||
onReject.run();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public interface CustomInventory extends InventoryHolder {
|
||||
|
||||
void refresh();
|
||||
void open();
|
||||
void click(ItemStack stack, InventoryClickEvent event);
|
||||
void click(InventoryClickEvent event);
|
||||
|
||||
default ItemStack createEmptyStack(){
|
||||
ItemStack stack = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
@@ -44,7 +43,7 @@ public class InvSeeEquipmentInventory implements AutoUpdatingCustomInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
public void click(InventoryClickEvent event) {
|
||||
if (viewer.hasPermission("smod.invsee.modify") && !subject.hasPermission("smod.invsee.preventmodify")){
|
||||
event.setCancelled(false);
|
||||
changing = true;
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
@@ -46,7 +45,7 @@ public class InvSeeInventory implements AutoUpdatingCustomInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
public void click(InventoryClickEvent event) {
|
||||
if (viewer.hasPermission("smod.invsee.modify") && !subject.hasPermission("smod.invsee.preventmodify")){
|
||||
event.setCancelled(false);
|
||||
changing = true;
|
||||
|
||||
@@ -1,31 +1,40 @@
|
||||
package de.shiewk.smoderation.paper.inventory;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Data Component API
|
||||
public abstract class PageableCustomInventory implements CustomInventory {
|
||||
public abstract int lastPage();
|
||||
public abstract void switchPage();
|
||||
private ItemStack previousStack = null;
|
||||
private ItemStack nextStack = null;
|
||||
|
||||
protected final int prevSlot, nextSlot;
|
||||
private int page = 0;
|
||||
|
||||
public PageableCustomInventory(int prevSlot, int nextSlot) {
|
||||
this.prevSlot = prevSlot;
|
||||
this.nextSlot = nextSlot;
|
||||
}
|
||||
|
||||
public int getPage(){
|
||||
return page;
|
||||
}
|
||||
|
||||
public abstract int lastPage();
|
||||
public abstract void switchPage();
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
if (stack != null){
|
||||
if (stack.equals(previousStack)){
|
||||
previousPage();
|
||||
} else if (stack.equals(nextStack)) {
|
||||
nextPage();
|
||||
}
|
||||
public void click(InventoryClickEvent event) {
|
||||
if (event.getSlot() == prevSlot) {
|
||||
previousPage();
|
||||
} else if (event.getSlot() == nextSlot) {
|
||||
nextPage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,23 +54,21 @@ public abstract class PageableCustomInventory implements CustomInventory {
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack createPreviousPageStack(){
|
||||
public ItemStack createPreviousPageStack(Player viewer){
|
||||
boolean allowed = page > 0;
|
||||
TextColor color = allowed ? NamedTextColor.GREEN : NamedTextColor.RED;
|
||||
int skip = allowed ? page : page+1;
|
||||
ItemStack stack = new ItemStack(allowed ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE);
|
||||
stack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("Previous page (%s/%s)".formatted(skip, lastPage()+1)).color(color))));
|
||||
previousStack = stack;
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, CustomInventory.renderComponent(viewer, applyFormatting(translatable("smod.inventory.previous", text(skip), text(lastPage()+1)).color(color))));
|
||||
return stack;
|
||||
}
|
||||
|
||||
public ItemStack createNextPageStack(){
|
||||
public ItemStack createNextPageStack(Player viewer){
|
||||
boolean allowed = page < lastPage();
|
||||
TextColor color = allowed ? NamedTextColor.GREEN : NamedTextColor.RED;
|
||||
int skip = allowed ? page+2 : page+1;
|
||||
ItemStack stack = new ItemStack(allowed ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE);
|
||||
stack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("Next page (%s/%s)".formatted(skip, lastPage()+1)).color(color))));
|
||||
nextStack = stack;
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, CustomInventory.renderComponent(viewer, applyFormatting(translatable("smod.inventory.next", text(skip), text(lastPage()+1)).color(color))));
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,36 +2,36 @@ package de.shiewk.smoderation.paper.inventory;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.SkinTextureProvider;
|
||||
import de.shiewk.smoderation.paper.input.ChatInput;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.SchedulerUtil;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||
import io.papermc.paper.datacomponent.item.ItemLore;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
@@ -40,11 +40,12 @@ import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
import static de.shiewk.smoderation.paper.inventory.CustomInventory.renderComponent;
|
||||
import static net.kyori.adventure.text.Component.*;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API, Paper Data Component API
|
||||
public class SModMenu extends PageableCustomInventory {
|
||||
|
||||
public enum Filter {
|
||||
ACTIVE(translatable("smod.menu.filter.active"), Punishment::isActive),
|
||||
OLD(translatable("smod.menu.filter.expired"), p -> !p.isActive()),
|
||||
ACTIVE(translatable("smod.menu.filter.active"), p -> p instanceof TimedPunishment timed && timed.isActive()),
|
||||
OLD(translatable("smod.menu.filter.expired"), p -> !(p instanceof TimedPunishment timed && timed.isActive())),
|
||||
ALL(translatable("smod.menu.filter.all"), p -> true);
|
||||
|
||||
public static final Material ICON = Material.HOPPER;
|
||||
@@ -58,10 +59,10 @@ public class SModMenu extends PageableCustomInventory {
|
||||
}
|
||||
|
||||
public enum Sort {
|
||||
EXPIRY(translatable("smod.menu.sort.expiry"), Comparator.comparingLong(p -> p.until)),
|
||||
TIME(translatable("smod.menu.sort.time"), Comparator.comparingLong(p -> p.time)),
|
||||
PLAYER_NAME(translatable("smod.menu.sort.playerName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.to), PlayerUtil.offlinePlayerName(p2.to))),
|
||||
MODERATOR_NAME(translatable("smod.menu.sort.moderatorName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.by), PlayerUtil.offlinePlayerName(p2.by)));
|
||||
EXPIRY(translatable("smod.menu.sort.expiry"), Comparator.comparingLong(p -> p instanceof TimedPunishment timed ? timed.getExpiry() : p.getTimestamp())),
|
||||
TIME(translatable("smod.menu.sort.time"), Comparator.comparingLong(Punishment::getTimestamp)),
|
||||
PLAYER_NAME(translatable("smod.menu.sort.playerName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.getTargetID()), PlayerUtil.offlinePlayerName(p2.getTargetID()))),
|
||||
MODERATOR_NAME(translatable("smod.menu.sort.moderatorName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.getIssuerID()), PlayerUtil.offlinePlayerName(p2.getIssuerID())));
|
||||
|
||||
public static final Material ICON = Material.COMPARATOR;
|
||||
|
||||
@@ -73,24 +74,22 @@ public class SModMenu extends PageableCustomInventory {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
}
|
||||
private static final NamespacedKey PUNISHMENT_STORE_KEY = new NamespacedKey("smod", "punishmentid");
|
||||
|
||||
private final Inventory inventory;
|
||||
private final Player player;
|
||||
private final PunishmentContainer container;
|
||||
private final PunishmentManager punishmentManager;
|
||||
private final Int2ObjectArrayMap<Punishment> slotMap = new Int2ObjectArrayMap<>(45);
|
||||
private List<Punishment> punishments;
|
||||
private ItemStack sortStack = null;
|
||||
private ItemStack filterStack = null;
|
||||
private ItemStack searchStack = null;
|
||||
private ItemStack typeStack = null;
|
||||
private int sort = 0;
|
||||
private int filter = 0;
|
||||
private int type = -1;
|
||||
private int rfId = 0;
|
||||
private String searchQuery = null;
|
||||
|
||||
public SModMenu(Player player, PunishmentContainer container) {
|
||||
public SModMenu(Player player, PunishmentManager punishmentManager) {
|
||||
super(45, 53);
|
||||
this.player = player;
|
||||
this.container = container;
|
||||
this.punishmentManager = punishmentManager;
|
||||
this.inventory = Bukkit.createInventory(this, 54, translatable("smod.menu"));
|
||||
reload();
|
||||
}
|
||||
@@ -103,16 +102,21 @@ public class SModMenu extends PageableCustomInventory {
|
||||
return Filter.values()[filter];
|
||||
}
|
||||
|
||||
public PunishmentType getType(){
|
||||
return type == -1 ? null : PunishmentType.values()[type];
|
||||
public String getType(){
|
||||
return type == -1 ? null : punishmentManager.getRegisteredTypes().get(type);
|
||||
}
|
||||
|
||||
private void reload(){
|
||||
this.punishments = container.copy().stream()
|
||||
.filter(getFilter().filter)
|
||||
.filter(p -> getType() == null || p.type == getType())
|
||||
.filter(p -> p.matchesSearchQuery(searchQuery))
|
||||
.sorted(getSort().comparator).toList();
|
||||
private void reload() {
|
||||
try {
|
||||
this.punishments = this.punishmentManager.getAll()
|
||||
.stream()
|
||||
.filter(getFilter().filter)
|
||||
.filter(p -> getType() == null || Objects.equals(p.getType(), getType()))
|
||||
.filter(p -> p.matchesSearchQuery(searchQuery))
|
||||
.sorted(getSort().comparator).toList();
|
||||
} catch (IOException e) {
|
||||
this.punishments = List.of();
|
||||
}
|
||||
}
|
||||
|
||||
public void promptSearchQuery(){
|
||||
@@ -123,7 +127,7 @@ public class SModMenu extends PageableCustomInventory {
|
||||
// chat event is async
|
||||
SchedulerUtil.scheduleForEntity(PLUGIN, player, this::open);
|
||||
}
|
||||
}, translatable("smod.menu.search.query").color(SECONDARY_COLOR), 30);
|
||||
}, translatable("smod.menu.search.query").color(SModerationPaper.colors().secondary()), 30);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -173,12 +177,12 @@ public class SModMenu extends PageableCustomInventory {
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
||||
if (backwards){
|
||||
if (type <= -1){
|
||||
type = PunishmentType.values().length-1;
|
||||
type = punishmentManager.getRegisteredTypes().size()-1;
|
||||
} else {
|
||||
type--;
|
||||
}
|
||||
} else {
|
||||
if (type >= PunishmentType.values().length-1){
|
||||
if (type >= punishmentManager.getRegisteredTypes().size()-1){
|
||||
type = -1;
|
||||
} else {
|
||||
type++;
|
||||
@@ -196,36 +200,36 @@ public class SModMenu extends PageableCustomInventory {
|
||||
private ItemStack createFilterItem(){
|
||||
final Filter filter = getFilter();
|
||||
final ItemStack stack = new ItemStack(Filter.ICON);
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.filter", filter.name).color(PRIMARY_COLOR)));
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.filter", filter.name).color(SModerationPaper.colors().primary())));
|
||||
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||
|
||||
loreBuilder.addLine(empty());
|
||||
for (Filter value : Filter.values()) {
|
||||
final boolean selected = filter == value;
|
||||
Component filterText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value.name)));
|
||||
Component filterText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SModerationPaper.colors().secondary() : SModerationPaper.colors().detail()).append(value.name)));
|
||||
loreBuilder.addLine(filterText);
|
||||
}
|
||||
loreBuilder.addLine(empty());
|
||||
loreBuilder.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.filter.switch", NamedTextColor.GOLD))));
|
||||
|
||||
stack.setData(DataComponentTypes.LORE, loreBuilder.build());
|
||||
return filterStack = stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
private ItemStack createTypeItem(){
|
||||
final PunishmentType type = getType();
|
||||
final String type = getType();
|
||||
final ItemStack stack = new ItemStack(Material.CHEST);
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.type", (type == null ? translatable("smod.menu.type.all") : type.name))).color(PRIMARY_COLOR));
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.type", (type == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + type)))).color(SModerationPaper.colors().primary()));
|
||||
|
||||
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||
loreBuilder.addLine(empty());
|
||||
final Consumer<PunishmentType> addToLore = value -> {
|
||||
final boolean selected = type == value;
|
||||
Component typeText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value == null ? translatable("smod.menu.type.all") : value.name)));
|
||||
final Consumer<String> addToLore = value -> {
|
||||
final boolean selected = Objects.equals(type, value);
|
||||
Component typeText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SModerationPaper.colors().secondary() : SModerationPaper.colors().detail()).append(value == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + value))));
|
||||
loreBuilder.addLine(typeText);
|
||||
};
|
||||
addToLore.accept(null);
|
||||
for (PunishmentType value : PunishmentType.values()) {
|
||||
for (String value : punishmentManager.getRegisteredTypes()) {
|
||||
addToLore.accept(value);
|
||||
}
|
||||
|
||||
@@ -233,20 +237,20 @@ public class SModMenu extends PageableCustomInventory {
|
||||
loreBuilder.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.type.switch", NamedTextColor.GOLD))));
|
||||
|
||||
stack.setData(DataComponentTypes.LORE, loreBuilder);
|
||||
return typeStack = stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
private ItemStack createSortItem(){
|
||||
final Sort sort = getSort();
|
||||
final ItemStack stack = new ItemStack(Sort.ICON);
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.sort", sort.name).color(PRIMARY_COLOR)));
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.sort", sort.name).color(SModerationPaper.colors().primary())));
|
||||
|
||||
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||
loreBuilder.addLine(empty());
|
||||
|
||||
for (Sort value : Sort.values()) {
|
||||
final boolean selected = sort == value;
|
||||
Component sortText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value.name)));
|
||||
Component sortText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SModerationPaper.colors().secondary() : SModerationPaper.colors().detail()).append(value.name)));
|
||||
loreBuilder.addLine(sortText);
|
||||
}
|
||||
|
||||
@@ -254,7 +258,7 @@ public class SModMenu extends PageableCustomInventory {
|
||||
loreBuilder.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.sort.switch", NamedTextColor.GOLD))));
|
||||
|
||||
stack.setData(DataComponentTypes.LORE, loreBuilder);
|
||||
return sortStack = stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
private ItemStack createSearchItem(){
|
||||
@@ -267,12 +271,12 @@ public class SModMenu extends PageableCustomInventory {
|
||||
// we just create the stack without it instead of throwing
|
||||
}
|
||||
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.search", PRIMARY_COLOR)));
|
||||
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.search", SModerationPaper.colors().primary())));
|
||||
|
||||
ItemLore.Builder loreBuilder = ItemLore.lore();
|
||||
loreBuilder.addLines(List.of(
|
||||
empty(),
|
||||
renderComponent(player, applyFormatting(translatable("smod.menu.search.current", searchQuery == null ? translatable("smod.menu.search.none") : text('"' + searchQuery + '"'))).color(SECONDARY_COLOR)),
|
||||
renderComponent(player, applyFormatting(translatable("smod.menu.search.current", searchQuery == null ? translatable("smod.menu.search.none") : text('"' + searchQuery + '"'))).color(SModerationPaper.colors().secondary())),
|
||||
empty(),
|
||||
renderComponent(player, applyFormatting(translatable("smod.menu.search.new", NamedTextColor.GOLD)))
|
||||
));
|
||||
@@ -280,18 +284,18 @@ public class SModMenu extends PageableCustomInventory {
|
||||
loreBuilder.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.search.remove", NamedTextColor.GOLD))));
|
||||
}
|
||||
stack.setData(DataComponentTypes.LORE, loreBuilder);
|
||||
return searchStack = stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
private CompletableFuture<ItemStack> createPunishmentItem(Punishment punishment){
|
||||
SkinTextureProvider provider = getTextureProvider();
|
||||
if (provider != null) {
|
||||
return provider.textureProperty(punishment.to)
|
||||
return provider.textureProperty(punishment.getTargetID())
|
||||
.thenApply(texture -> {
|
||||
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
||||
stack.editMeta(meta -> {
|
||||
if (meta instanceof SkullMeta skullMeta){
|
||||
PlayerProfile profile = Bukkit.createProfile(punishment.to);
|
||||
PlayerProfile profile = Bukkit.createProfile(punishment.getTargetID());
|
||||
profile.setProperty(new ProfileProperty(
|
||||
"textures",
|
||||
texture
|
||||
@@ -307,9 +311,9 @@ public class SModMenu extends PageableCustomInventory {
|
||||
stack.editMeta(meta -> {
|
||||
if (meta instanceof SkullMeta skullMeta){
|
||||
try {
|
||||
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.to));
|
||||
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.getTargetID()));
|
||||
} catch (NullPointerException e) {
|
||||
LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.to);
|
||||
LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.getTargetID());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -319,37 +323,43 @@ public class SModMenu extends PageableCustomInventory {
|
||||
}
|
||||
|
||||
private void addPunishmentInfo(Punishment punishment, ItemStack stack) {
|
||||
stack.setData(DataComponentTypes.CUSTOM_NAME, renderComponent(player, applyFormatting(punishment.type.name.color(NamedTextColor.RED).decorate(TextDecoration.BOLD))));
|
||||
stack.setData(DataComponentTypes.CUSTOM_NAME, renderComponent(player, applyFormatting(translatable("smod.punishment.name." + punishment.getType(), NamedTextColor.RED).decorate(TextDecoration.BOLD))));
|
||||
ItemLore.Builder lore = ItemLore.lore();
|
||||
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.player", text(PlayerUtil.offlinePlayerName(punishment.to))))));
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.punishedBy", text(PlayerUtil.offlinePlayerName(punishment.by))))));
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.timestamp", TimeUtil.calendarTimestamp(punishment.time)))));
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.player", text(PlayerUtil.offlinePlayerName(punishment.getTargetID()))))));
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.punishedBy", text(PlayerUtil.offlinePlayerName(punishment.getIssuerID()))))));
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.timestamp", TimeUtil.calendarTimestamp(punishment.getTimestamp())))));
|
||||
|
||||
if (punishment.type != PunishmentType.KICK){
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", TimeUtil.formatTimeLong(punishment.until - punishment.time)))));
|
||||
long remainingTime = punishment.until - System.currentTimeMillis();
|
||||
if (remainingTime > 0){
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.future", TimeUtil.formatTimeLong(remainingTime)))));
|
||||
if (punishment instanceof TimedPunishment timed){
|
||||
if (timed.isPermanent()){
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", translatable("smod.time.permanent")))));
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.never"))));
|
||||
} else {
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.past", TimeUtil.formatTimeLong(-remainingTime)))));
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", TimeUtil.formatTimeLong(timed.getExpiry() - punishment.getTimestamp())))));
|
||||
long remainingTime = timed.getExpiry() - System.currentTimeMillis();
|
||||
if (remainingTime > 0){
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.future", TimeUtil.formatTimeLong(remainingTime)))));
|
||||
} else {
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.past", TimeUtil.formatTimeLong(-remainingTime)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.reason", text(punishment.reason)))));
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.reason", text(punishment.getReason())))));
|
||||
|
||||
if (punishment.wasUndone()){
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.undone", text(PlayerUtil.offlinePlayerName(punishment.undoneBy()))))));
|
||||
} else if (punishment.isActive()) {
|
||||
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))){
|
||||
lore.addLine(empty());
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.click", NamedTextColor.GOLD))));
|
||||
if (punishment instanceof TimedPunishment timed){
|
||||
if (timed.wasCancelled()){
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.cancelled", text(PlayerUtil.offlinePlayerName(timed.getCancelledBy()))))));
|
||||
} else if (timed.isActive()) {
|
||||
if (player.hasPermission("smod.un" + punishment.getType())){
|
||||
lore.addLine(empty());
|
||||
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.click", NamedTextColor.GOLD))));
|
||||
}
|
||||
}
|
||||
}
|
||||
stack.setData(DataComponentTypes.LORE, lore);
|
||||
}
|
||||
|
||||
private int rfId = 0;
|
||||
@Override
|
||||
public void refresh() {
|
||||
int rfId = ++this.rfId;
|
||||
@@ -357,11 +367,12 @@ public class SModMenu extends PageableCustomInventory {
|
||||
previousPage();
|
||||
}
|
||||
inventory.clear();
|
||||
slotMap.clear();
|
||||
for (int i = 45; i < 54; i++) {
|
||||
inventory.setItem(i, createEmptyStack());
|
||||
}
|
||||
inventory.setItem(45, createPreviousPageStack());
|
||||
inventory.setItem(53, createNextPageStack());
|
||||
inventory.setItem(prevSlot, createPreviousPageStack(player));
|
||||
inventory.setItem(nextSlot, createNextPageStack(player));
|
||||
inventory.setItem(47, createSearchItem());
|
||||
inventory.setItem(48, createTypeItem());
|
||||
inventory.setItem(50, createFilterItem());
|
||||
@@ -372,13 +383,9 @@ public class SModMenu extends PageableCustomInventory {
|
||||
if (punishments.size() > ci){
|
||||
final Punishment punishment = punishments.get(ci);
|
||||
int slot = i;
|
||||
slotMap.put(slot, punishment);
|
||||
createPunishmentItem(punishment).thenAccept(item -> {
|
||||
if (rfId != this.rfId) return;
|
||||
if (punishment.isActive()){
|
||||
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))) {
|
||||
item.editMeta(meta -> meta.getPersistentDataContainer().set(PUNISHMENT_STORE_KEY, PersistentDataType.LONG, punishment.time));
|
||||
}
|
||||
}
|
||||
inventory.setItem(slot, item);
|
||||
}).exceptionally(x -> {
|
||||
LOGGER.warn("Error creating punishment item", x);
|
||||
@@ -391,40 +398,34 @@ public class SModMenu extends PageableCustomInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
super.click(stack, event);
|
||||
if (stack != null) {
|
||||
if (stack.equals(filterStack)){
|
||||
cycleFilter(event.isRightClick());
|
||||
} else if (stack.equals(sortStack)){
|
||||
cycleSort(event.isRightClick());
|
||||
} else if (stack.equals(searchStack)){
|
||||
if (event.isRightClick() && searchQuery != null){
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 0.8f);
|
||||
searchQuery = null;
|
||||
reload();
|
||||
refresh();
|
||||
} else {
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 2f);
|
||||
promptSearchQuery();
|
||||
}
|
||||
} else if (stack.equals(typeStack)) {
|
||||
cycleType(event.isRightClick());
|
||||
public void click(InventoryClickEvent event) {
|
||||
super.click(event);
|
||||
int slot = event.getSlot();
|
||||
if (slot == 47) {
|
||||
if (event.isRightClick() && searchQuery != null){
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 0.8f);
|
||||
searchQuery = null;
|
||||
reload();
|
||||
refresh();
|
||||
} else {
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 2f);
|
||||
promptSearchQuery();
|
||||
}
|
||||
final ItemMeta itemMeta = stack.getItemMeta();
|
||||
if (itemMeta != null) {
|
||||
final PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer();
|
||||
final Long timestamp = persistentDataContainer.get(PUNISHMENT_STORE_KEY, PersistentDataType.LONG);
|
||||
if (timestamp != null) {
|
||||
final Punishment punishment = container.findByTimestamp(timestamp);
|
||||
if (punishment != null) {
|
||||
new ConfirmationInventory(player, translatable("smod.menu.undoConfirmation"), () -> {
|
||||
punishment.undo(player.getUniqueId());
|
||||
punishment.broadcastUndo(container);
|
||||
player.playSound(player, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 2f);
|
||||
this.open();
|
||||
}, this::open, false).open();
|
||||
}
|
||||
} else if (slot == 48) {
|
||||
cycleType(event.isRightClick());
|
||||
} else if (slot == 50) {
|
||||
cycleFilter(event.isRightClick());
|
||||
} else if (slot == 51) {
|
||||
cycleSort(event.isRightClick());
|
||||
} else {
|
||||
Punishment punishment = slotMap.get(slot);
|
||||
if (punishment instanceof TimedPunishment timed && timed.isActive()){
|
||||
if (player.hasPermission("smod.un" + punishment.getType())) {
|
||||
new ConfirmationInventory(player, translatable("smod.menu.cancelConfirmation"), () -> {
|
||||
punishmentManager.cancel(timed, player.getUniqueId());
|
||||
player.playSound(player, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 2f);
|
||||
this.open();
|
||||
}, this::open).open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package de.shiewk.smoderation.paper.listener;
|
||||
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.LOGGER;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public class CacheListener implements Listener {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public CacheListener(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event){
|
||||
try {
|
||||
punishmentManager.loadToCache(event.getPlayer().getUniqueId());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Failed to load punishments", e);
|
||||
event.getPlayer().kick(translatable("mco.errorMessage.connectionFailure"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event){
|
||||
punishmentManager.removeFromCache(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class CustomInventoryListener implements Listener {
|
||||
public void onInventoryClick(InventoryClickEvent event){
|
||||
if (event.getInventory().getHolder() instanceof CustomInventory customInventory){
|
||||
event.setCancelled(true);
|
||||
customInventory.click(event.getCurrentItem(), event);
|
||||
customInventory.click(event);
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package de.shiewk.smoderation.paper.listener;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.event.PunishmentIssueEvent;
|
||||
import de.shiewk.smoderation.paper.inventory.CustomInventory;
|
||||
import de.shiewk.smoderation.paper.punishments.Ban;
|
||||
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -14,51 +13,42 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.world.WorldSaveEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.CHAT_PREFIX;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public class PunishmentListener implements Listener {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public PunishmentListener(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerLogin(AsyncPlayerPreLoginEvent event){
|
||||
// Have to use AsyncPlayerPreLoginEvent since PlayerLoginEvent is deprecated in newer versions
|
||||
// I would use the new PlayerConnectionValidateLoginEvent but there is literally no API available
|
||||
// there to get player's UUIDs
|
||||
Punishment punishment = SModerationPaper.container.find(p ->
|
||||
p.type == PunishmentType.BAN
|
||||
&& p.to.equals(event.getUniqueId())
|
||||
&& p.isActive());
|
||||
if (punishment != null){
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, CHAT_PREFIX.append(punishment.playerMessage()));
|
||||
List<Punishment> list = punishmentManager.byTargetUUID(event.getUniqueId(), p -> p instanceof Ban ban && ban.isActive());
|
||||
if (!list.isEmpty()) {
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, list.getFirst().infoMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncChatEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
final Punishment punishment = SModerationPaper.container.find(p ->
|
||||
p.type == PunishmentType.MUTE
|
||||
&& p.to.equals(player.getUniqueId())
|
||||
&& p.isActive());
|
||||
if (punishment != null) {
|
||||
List<Punishment> list = punishmentManager.byTargetUUID(player.getUniqueId(), p -> p instanceof Mute mute && mute.isActive());
|
||||
if (!list.isEmpty()) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(CHAT_PREFIX.append(punishment.playerMessage()));
|
||||
player.sendMessage(list.getFirst().infoMessage().colorIfAbsent(SModerationPaper.colors().primary()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
|
||||
Player player = event.getPlayer();
|
||||
final Punishment mute = SModerationPaper.container.find(p ->
|
||||
p.type == PunishmentType.MUTE
|
||||
&& p.to.equals(player.getUniqueId())
|
||||
&& p.isActive());
|
||||
|
||||
if (mute != null) { // Player is muted
|
||||
List<Punishment> list = punishmentManager.byTargetUUID(player.getUniqueId(), p -> p instanceof Mute mute && mute.isActive());
|
||||
if (!list.isEmpty()) { // Player is muted
|
||||
List<String> forbiddenCommands = SModerationPaper.config().getStringList("muted-forbidden-commands");
|
||||
final String message = event.getMessage();
|
||||
if (forbiddenCommands.stream().anyMatch(str ->
|
||||
@@ -66,36 +56,11 @@ public class PunishmentListener implements Listener {
|
||||
|| message.toLowerCase().startsWith(str.toLowerCase()+" ")
|
||||
)){
|
||||
Bukkit.getConsoleSender().sendMessage(player.getName() + " tried to run forbidden command while muted");
|
||||
player.sendMessage(CHAT_PREFIX.append(translatable("smod.punishment.playerMessage.mute.chat")));
|
||||
player.sendMessage(translatable("smod.punishment.playerMessage.mute.chat", SModerationPaper.colors().primary()));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPunishmentIssue(PunishmentIssueEvent event){
|
||||
final Punishment punishment = event.getPunishment();
|
||||
final PunishmentContainer container = event.getContainer();
|
||||
final Punishment duplicate = container.find(p -> p.to.equals(punishment.to) && p.type == punishment.type && p.isActive());
|
||||
if (duplicate != null){
|
||||
container.remove(duplicate);
|
||||
container.add(new Punishment(duplicate.type, duplicate.time, System.currentTimeMillis(), duplicate.by, duplicate.to, duplicate.reason));
|
||||
}
|
||||
switch (punishment.type){
|
||||
case KICK, BAN -> {
|
||||
final Player player = Bukkit.getPlayer(punishment.to);
|
||||
if (player != null) {
|
||||
player.kick(CustomInventory.renderComponent(player, CHAT_PREFIX.append(punishment.playerMessage())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldSave(WorldSaveEvent event){
|
||||
if (event.getWorld().equals(Bukkit.getServer().getWorlds().getFirst())){
|
||||
SModerationPaper.container.save(SModerationPaper.SAVE_FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,17 +14,17 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerAdvancementDoneEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.SECONDARY_COLOR;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public class VanishListener implements Listener {
|
||||
|
||||
public static final Component PREFIX = text("[VANISH] ").color(SECONDARY_COLOR);
|
||||
public static final Component PREFIX = text("[VANISH] ").color(SModerationPaper.colors().secondary());
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onPlayerQuit(PlayerQuitEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
@@ -56,7 +56,7 @@ public class VanishListener implements Listener {
|
||||
broadcast(message.color(null));
|
||||
}
|
||||
SchedulerUtil.scheduleForEntity(SModerationPaper.PLUGIN, player, () -> {
|
||||
player.sendMessage(translatable("smod.vanish.stillEnabled"));
|
||||
player.sendMessage(translatable("smod.command.vanish.stillEnabled"));
|
||||
player.playSound(Sound.sound(
|
||||
Key.key("minecraft", "block.beacon.power_select"),
|
||||
Sound.Source.MASTER,
|
||||
@@ -102,6 +102,16 @@ public class VanishListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAdvancementDone(PlayerAdvancementDoneEvent event){
|
||||
Player pl = event.getPlayer();
|
||||
Component message = event.message();
|
||||
if (VanishCommand.isVanished(pl) && message != null) {
|
||||
broadcast(message);
|
||||
event.message(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void broadcast(Component message) {
|
||||
Component result = PREFIX.append(message);
|
||||
Bukkit.getConsoleSender().sendMessage(result);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package de.shiewk.smoderation.paper.punishments;
|
||||
|
||||
import de.shiewk.smoderation.paper.inventory.CustomInventory;
|
||||
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Ban extends TimedPunishment {
|
||||
|
||||
public Ban(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
|
||||
super(id, "ban", timestamp, issuer, target, reason, duration, cancelledBy);
|
||||
}
|
||||
|
||||
public Ban(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration) {
|
||||
this(id, timestamp, issuer, target, reason, duration, null);
|
||||
}
|
||||
|
||||
public static class Factory implements PunishmentFactory<Ban> {
|
||||
|
||||
@Override
|
||||
public @NonNull Ban deserialize(SerializationHelper helper) {
|
||||
return new Ban(
|
||||
helper.getUUID("id"),
|
||||
helper.getLong("timestamp"),
|
||||
helper.getUUID("issuer"),
|
||||
helper.getUUID("target"),
|
||||
helper.getString("reason"),
|
||||
helper.getLong("duration"),
|
||||
helper.getUUID("cancelledBy", null)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processIssue() {
|
||||
super.processIssue();
|
||||
final Player player = Bukkit.getPlayer(getTargetID());
|
||||
if (player != null) {
|
||||
player.kick(CustomInventory.renderComponent(player, infoMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.shiewk.smoderation.paper.punishments;
|
||||
|
||||
import de.shiewk.smoderation.paper.inventory.CustomInventory;
|
||||
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Kick extends Punishment {
|
||||
|
||||
public Kick(UUID id, long timestamp, UUID issuer, UUID target, String reason) {
|
||||
super(id, "kick", timestamp, issuer, target, reason);
|
||||
}
|
||||
|
||||
public static class Factory implements PunishmentFactory<Kick> {
|
||||
|
||||
@Override
|
||||
public @NonNull Kick deserialize(SerializationHelper helper) {
|
||||
return new Kick(
|
||||
helper.getUUID("id"),
|
||||
helper.getLong("timestamp"),
|
||||
helper.getUUID("issuer"),
|
||||
helper.getUUID("target"),
|
||||
helper.getString("reason")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processIssue() {
|
||||
super.processIssue();
|
||||
final Player player = Bukkit.getPlayer(getTargetID());
|
||||
if (player != null) {
|
||||
player.kick(CustomInventory.renderComponent(player, infoMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package de.shiewk.smoderation.paper.punishments;
|
||||
|
||||
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Mute extends TimedPunishment {
|
||||
|
||||
public Mute(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
|
||||
super(id, "mute", timestamp, issuer, target, reason, duration, cancelledBy);
|
||||
}
|
||||
|
||||
public Mute(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration) {
|
||||
this(id, timestamp, issuer, target, reason, duration, null);
|
||||
}
|
||||
|
||||
public static class Factory implements PunishmentFactory<Mute> {
|
||||
|
||||
@Override
|
||||
public @NonNull Mute deserialize(SerializationHelper helper) {
|
||||
return new Mute(
|
||||
helper.getUUID("id"),
|
||||
helper.getLong("timestamp"),
|
||||
helper.getUUID("issuer"),
|
||||
helper.getUUID("target"),
|
||||
helper.getString("reason"),
|
||||
helper.getLong("duration"),
|
||||
helper.getUUID("cancelledBy", null)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,205 +1,121 @@
|
||||
package de.shiewk.smoderation.paper.punishments;
|
||||
|
||||
import de.shiewk.smoderation.paper.event.PunishmentIssueEvent;
|
||||
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
|
||||
import de.shiewk.smoderation.paper.util.ByteUtil;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public class Punishment {
|
||||
public static final String DEFAULT_REASON = "No reason provided.";
|
||||
public final PunishmentType type;
|
||||
public final long time;
|
||||
public final long until;
|
||||
public final UUID by;
|
||||
public final UUID to;
|
||||
public final String reason;
|
||||
private UUID undoneBy;
|
||||
public abstract class Punishment {
|
||||
|
||||
public Punishment(PunishmentType type, long time, long until, UUID by, UUID to, String reason) {
|
||||
this(type, time, until, by, to, reason, null);
|
||||
}
|
||||
protected final UUID id;
|
||||
protected final String type;
|
||||
protected final long timestamp;
|
||||
protected final UUID issuer;
|
||||
protected final UUID target;
|
||||
protected final String reason;
|
||||
|
||||
private Punishment(PunishmentType type, long time, long until, UUID by, UUID to, String reason, UUID undoneBy) {
|
||||
protected Punishment(UUID id, String type, long timestamp, UUID issuer, UUID target, String reason) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.time = time;
|
||||
this.until = until;
|
||||
this.by = by;
|
||||
this.to = to;
|
||||
this.timestamp = timestamp;
|
||||
this.issuer = issuer;
|
||||
this.target = target;
|
||||
this.reason = reason;
|
||||
this.undoneBy = undoneBy;
|
||||
}
|
||||
|
||||
private static byte[] readStreamInternal(InputStream stream, int len) throws IOException {
|
||||
final byte[] bytes = stream.readNBytes(len);
|
||||
if (bytes.length != len){
|
||||
throw new EOFException("Stream has ended before enough bytes were read");
|
||||
}
|
||||
return bytes;
|
||||
public UUID getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Punishment load(InputStream in) throws IOException {
|
||||
PunishmentType type = PunishmentType.values()[ByteUtil.bytesToInt(readStreamInternal(in, 4))];
|
||||
long time = ByteUtil.bytesToLong(readStreamInternal(in, 8));
|
||||
long until = ByteUtil.bytesToLong(readStreamInternal(in, 8));
|
||||
UUID by = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
||||
UUID to = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
||||
int reasonLen = ByteUtil.bytesToInt(readStreamInternal(in, 4));
|
||||
String reason = new String(readStreamInternal(in, reasonLen));
|
||||
UUID undoneBy = null;
|
||||
boolean undone = in.read() == 1;
|
||||
if (undone){
|
||||
undoneBy = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
||||
}
|
||||
return new Punishment(type, time, until, by, to, reason, undoneBy);
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean wasUndone(){
|
||||
return undoneBy != null;
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public UUID undoneBy() {
|
||||
return undoneBy;
|
||||
public UUID getIssuerID() {
|
||||
return issuer;
|
||||
}
|
||||
|
||||
public void undo(UUID undoneBy){
|
||||
if (this.undoneBy != null){
|
||||
throw new IllegalArgumentException("This punishment was already undone.");
|
||||
}
|
||||
this.undoneBy = undoneBy;
|
||||
public UUID getTargetID() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public boolean isActive(){
|
||||
return until > System.currentTimeMillis() && !wasUndone();
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public static Punishment mute(long time, long until, UUID by, UUID to, String reason){
|
||||
return new Punishment(PunishmentType.MUTE, time, until, by, to, reason);
|
||||
public void addSerializableProperties(SerializationHelper helper){
|
||||
helper.putUUID("id", id);
|
||||
helper.putString("type", type);
|
||||
helper.putLong("timestamp", timestamp);
|
||||
helper.putUUID("issuer", issuer);
|
||||
helper.putUUID("target", target);
|
||||
helper.putString("reason", reason);
|
||||
}
|
||||
|
||||
public static Punishment ban(long time, long until, UUID by, UUID to, String reason){
|
||||
return new Punishment(PunishmentType.BAN, time, until, by, to, reason);
|
||||
public boolean matchesSearchQuery(String query){
|
||||
if (query == null) return true;
|
||||
query = query.toLowerCase();
|
||||
return reason.toLowerCase().contains(query)
|
||||
|| issuer.toString().equalsIgnoreCase(query)
|
||||
|| target.toString().equalsIgnoreCase(query)
|
||||
|| PlayerUtil.offlinePlayerName(issuer).toLowerCase().contains(query)
|
||||
|| PlayerUtil.offlinePlayerName(target).toLowerCase().contains(query);
|
||||
}
|
||||
|
||||
public static Punishment kick(long time, UUID by, UUID to, String reason){
|
||||
return new Punishment(PunishmentType.KICK, time, time, by, to, reason);
|
||||
}
|
||||
|
||||
public void writeBytes(OutputStream stream) throws IOException {
|
||||
stream.write(ByteUtil.intToBytes(type.ordinal()));
|
||||
stream.write(ByteUtil.longToBytes(time));
|
||||
stream.write(ByteUtil.longToBytes(until));
|
||||
stream.write(ByteUtil.uuidToBytes(by));
|
||||
stream.write(ByteUtil.uuidToBytes(to));
|
||||
final byte[] reasonBytes = reason.getBytes();
|
||||
stream.write(ByteUtil.intToBytes(reasonBytes.length));
|
||||
stream.write(reasonBytes);
|
||||
stream.write(wasUndone() ? 1 : 0);
|
||||
if (wasUndone()){
|
||||
stream.write(ByteUtil.uuidToBytes(undoneBy));
|
||||
}
|
||||
}
|
||||
|
||||
private Component undoMessage(){
|
||||
String key = "smod.punishment.undo." + type.name().toLowerCase();
|
||||
return translatable(key, text(PlayerUtil.offlinePlayerName(to)), text(PlayerUtil.offlinePlayerName(undoneBy)));
|
||||
}
|
||||
|
||||
public void broadcastUndo(PunishmentContainer container){
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(undoMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Punishment{" +
|
||||
"type=" + type +
|
||||
", time=" + time +
|
||||
", until=" + until +
|
||||
", by=" + by +
|
||||
", to=" + to +
|
||||
", reason=" + reason +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static void issue(Punishment punishment, PunishmentContainer container){
|
||||
final PunishmentIssueEvent event = new PunishmentIssueEvent(punishment, container);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()){
|
||||
container.add(punishment);
|
||||
punishment.firstIssue(container);
|
||||
}
|
||||
}
|
||||
|
||||
private Component broadcastMessage(){
|
||||
String key = "smod.punishment.broadcast." + type.name().toLowerCase();
|
||||
public Component infoMessage(){
|
||||
return translatable(
|
||||
key,
|
||||
text(PlayerUtil.offlinePlayerName(to)),
|
||||
text(PlayerUtil.offlinePlayerName(by)),
|
||||
TimeUtil.formatTimeLong(this.until - this.time),
|
||||
"smod.punishment.playerMessage." + type,
|
||||
text(PlayerUtil.offlinePlayerName(this.issuer)),
|
||||
text(reason)
|
||||
);
|
||||
}
|
||||
|
||||
private void broadcastIssue(PunishmentContainer container){
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(broadcastMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void firstIssue(PunishmentContainer container){
|
||||
switch (type) {
|
||||
case MUTE, BAN -> {
|
||||
final CommandSender sender = PlayerUtil.senderByUUID(to);
|
||||
if (sender != null) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(playerMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
broadcastIssue(container);
|
||||
}
|
||||
|
||||
public Component playerMessage(){
|
||||
String key = "smod.punishment.playerMessage." + type.name().toLowerCase();
|
||||
public Component adminMessage(){
|
||||
return translatable(
|
||||
key,
|
||||
text(PlayerUtil.offlinePlayerName(this.by)),
|
||||
text(reason),
|
||||
TimeUtil.formatTimeLong(this.until - System.currentTimeMillis())
|
||||
"smod.punishment.broadcast." + type,
|
||||
text(PlayerUtil.offlinePlayerName(target)),
|
||||
text(PlayerUtil.offlinePlayerName(issuer)),
|
||||
text(reason)
|
||||
);
|
||||
}
|
||||
|
||||
public boolean matchesSearchQuery(String searchQuery) {
|
||||
if (searchQuery == null) return true;
|
||||
searchQuery = searchQuery.toLowerCase();
|
||||
return reason.toLowerCase().contains(searchQuery)
|
||||
|| by.toString().equalsIgnoreCase(searchQuery)
|
||||
|| to.toString().equalsIgnoreCase(searchQuery)
|
||||
|| getPlayerName().toLowerCase().contains(searchQuery)
|
||||
|| getModeratorName().toLowerCase().contains(searchQuery);
|
||||
|
||||
public void processIssue() {
|
||||
CommandSender sender = PlayerUtil.senderByUUID(target);
|
||||
if (sender != null) {
|
||||
sender.sendMessage(infoMessage());
|
||||
}
|
||||
for (CommandSender target : getBroadcastTargets()) {
|
||||
target.sendMessage(adminMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getPlayerName() {
|
||||
return PlayerUtil.offlinePlayerName(to);
|
||||
public static List<CommandSender> getBroadcastTargets() {
|
||||
ObjectArrayList<CommandSender> senders = new ObjectArrayList<>();
|
||||
senders.add(Bukkit.getConsoleSender());
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.notifications")){
|
||||
senders.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
return List.copyOf(senders);
|
||||
}
|
||||
|
||||
private String getModeratorName() {
|
||||
return PlayerUtil.offlinePlayerName(by);
|
||||
public static UUID generateUUID() {
|
||||
Random random = new Random();
|
||||
return new UUID(System.currentTimeMillis(), random.nextLong());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package de.shiewk.smoderation.paper.punishments;
|
||||
|
||||
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PunishmentFactory<T extends Punishment> {
|
||||
|
||||
@NotNull T deserialize(SerializationHelper helper);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package de.shiewk.smoderation.paper.punishments;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.Strictness;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.event.PunishmentIssueEvent;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.LOGGER;
|
||||
|
||||
public final class PunishmentManager {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PunishmentManager.class);
|
||||
private final Object2ObjectArrayMap<String, PunishmentFactory<?>> typeRegistry = new Object2ObjectArrayMap<>(1);
|
||||
private final ConcurrentHashMap<UUID, List<Punishment>> cache = new ConcurrentHashMap<>(1);
|
||||
private final Object ioLock = new Object();
|
||||
private final Path dataDir;
|
||||
|
||||
public PunishmentManager(Path dataDir) {
|
||||
this.dataDir = dataDir;
|
||||
}
|
||||
|
||||
private Path getTargetFile(UUID targetUUID){
|
||||
return dataDir.resolve(targetUUID.toString().replace("-", ""));
|
||||
}
|
||||
|
||||
public boolean tryIssue(Punishment punishment) {
|
||||
try {
|
||||
PunishmentIssueEvent event = new PunishmentIssueEvent(punishment, this);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()){
|
||||
this.appendToSave(punishment);
|
||||
punishment.processIssue();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Punishment> byTargetUUID(UUID target) {
|
||||
List<Punishment> cached = cache.get(target);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
synchronized (ioLock) {
|
||||
Path file = getTargetFile(target);
|
||||
|
||||
if (!Files.exists(file)) {
|
||||
return List.of();
|
||||
}
|
||||
try (
|
||||
BufferedReader reader = Files.newBufferedReader(file);
|
||||
JsonReader json = new JsonReader(reader)
|
||||
) {
|
||||
json.setStrictness(Strictness.LENIENT);
|
||||
Object2ObjectArrayMap<UUID, Punishment> punishments = new Object2ObjectArrayMap<>(0);
|
||||
while (json.hasNext()){
|
||||
JsonObject obj = SModerationPaper.gson.fromJson(json, JsonObject.class);
|
||||
try {
|
||||
SerializationHelper helper = new SerializationHelper(obj);
|
||||
String type = helper.getString("type");
|
||||
PunishmentFactory<?> factory = typeRegistry.get(type);
|
||||
if (factory != null){
|
||||
Punishment punishment = factory.deserialize(helper);
|
||||
if (!punishment.getTargetID().equals(target)){
|
||||
LOGGER.warn("Punishment saved in file for {} has incorrect target UUID {}", target, punishment.getTargetID());
|
||||
} else {
|
||||
punishments.put(punishment.getID(), punishment);
|
||||
}
|
||||
} else {
|
||||
LOGGER.warn("Unknown punishment type '{}'! Can not load.", type);
|
||||
LOGGER.warn("Please check your configuration, or see file {} to remove corrupted data.", file);
|
||||
LOGGER.warn(obj.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Could not deserialize punishment!", e);
|
||||
LOGGER.warn("Please check file {} for corrupted data, or remove the corresponding line.", file);
|
||||
LOGGER.warn(obj.toString());
|
||||
}
|
||||
}
|
||||
return List.copyOf(punishments.values());
|
||||
} catch (IOException e){
|
||||
throw new RuntimeException("Error while reading punishment file " + file, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Punishment> byTargetUUID(UUID target, Predicate<Punishment> filter) {
|
||||
return byTargetUUID(target).stream().filter(filter).toList();
|
||||
}
|
||||
|
||||
public <T extends Punishment> void registerType(String type, PunishmentFactory<T> factory){
|
||||
if (typeRegistry.containsKey(type)) {
|
||||
throw new IllegalStateException("Punishment type already registered: " + type);
|
||||
}
|
||||
typeRegistry.put(type, factory);
|
||||
}
|
||||
|
||||
public List<String> getRegisteredTypes(){
|
||||
return List.copyOf(typeRegistry.keySet());
|
||||
}
|
||||
|
||||
public void appendToSave(Punishment punishment) throws IOException {
|
||||
synchronized (ioLock) {
|
||||
Path file = getTargetFile(punishment.getTargetID());
|
||||
if (!Files.exists(file)) {
|
||||
Files.createDirectories(dataDir);
|
||||
Files.createFile(file);
|
||||
}
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardOpenOption.APPEND)) {
|
||||
JsonObject json = new JsonObject();
|
||||
punishment.addSerializableProperties(new SerializationHelper(json));
|
||||
SModerationPaper.gson.toJson(json, writer);
|
||||
writer.append('\n');
|
||||
}
|
||||
}
|
||||
addToCachedList(punishment);
|
||||
}
|
||||
|
||||
public @NotNull List<Punishment> getAll() throws IOException {
|
||||
ObjectArrayList<Punishment> punishments = new ObjectArrayList<>();
|
||||
synchronized (ioLock) {
|
||||
try (Stream<Path> stream = Files.list(dataDir)) {
|
||||
stream.forEach(file -> {
|
||||
try {
|
||||
String name = file.getFileName().toString();
|
||||
UUID targetUUID = PlayerUtil.uuidFromString(name);
|
||||
punishments.addAll(byTargetUUID(targetUUID));
|
||||
} catch (Exception e) {
|
||||
log.warn("Could not read punishment file {}", file, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return List.copyOf(punishments);
|
||||
}
|
||||
|
||||
public List<Punishment> getAll(Predicate<Punishment> filter) throws IOException {
|
||||
return getAll().stream().filter(filter).toList();
|
||||
}
|
||||
|
||||
public void cancel(TimedPunishment punishment, UUID canceller) {
|
||||
if (!punishment.isActive()){
|
||||
throw new IllegalStateException("This punishment is not active");
|
||||
}
|
||||
punishment.cancel(canceller);
|
||||
try {
|
||||
appendToSave(punishment);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadToCache(UUID uuid) {
|
||||
removeFromCache(uuid);
|
||||
cache.put(uuid, byTargetUUID(uuid));
|
||||
}
|
||||
|
||||
public void removeFromCache(UUID uuid) {
|
||||
cache.remove(uuid);
|
||||
}
|
||||
|
||||
private void addToCachedList(Punishment punishment) {
|
||||
cache.computeIfPresent(punishment.getTargetID(), (k, v) -> {
|
||||
ObjectArrayList<Punishment> newList = new ObjectArrayList<>(v);
|
||||
newList.add(punishment);
|
||||
return List.copyOf(newList);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.punishments;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public enum PunishmentType {
|
||||
MUTE(translatable("smod.punishment.name.mute")),
|
||||
KICK(translatable("smod.punishment.name.kick")),
|
||||
BAN(translatable("smod.punishment.name.ban"));
|
||||
|
||||
public final Component name;
|
||||
|
||||
PunishmentType(Component name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package de.shiewk.smoderation.paper.punishments;
|
||||
|
||||
import de.shiewk.smoderation.paper.command.argument.DurationArgument;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.SerializationHelper;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public abstract class TimedPunishment extends Punishment {
|
||||
|
||||
protected final long duration;
|
||||
protected UUID cancelledBy;
|
||||
|
||||
protected TimedPunishment(UUID id, String type, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
|
||||
super(id, type, timestamp, issuer, target, reason);
|
||||
this.duration = duration;
|
||||
this.cancelledBy = cancelledBy;
|
||||
}
|
||||
|
||||
public long getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public UUID getCancelledBy() {
|
||||
return cancelledBy;
|
||||
}
|
||||
|
||||
public boolean wasCancelled(){
|
||||
return cancelledBy != null;
|
||||
}
|
||||
|
||||
public boolean isActive(){
|
||||
return !wasCancelled() && (isPermanent() || System.currentTimeMillis() < getExpiry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSerializableProperties(SerializationHelper helper) {
|
||||
super.addSerializableProperties(helper);
|
||||
helper.putLong("duration", duration);
|
||||
helper.putUUID("cancelledBy", cancelledBy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesSearchQuery(String query) {
|
||||
if (super.matchesSearchQuery(query)) return true;
|
||||
query = query.toLowerCase();
|
||||
return cancelledBy.toString().equalsIgnoreCase(query)
|
||||
|| PlayerUtil.offlinePlayerName(cancelledBy).toLowerCase().contains(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component infoMessage(){
|
||||
if (isPermanent()){
|
||||
return translatable(
|
||||
"smod.punishment.playerMessage." + type + ".permanent",
|
||||
text(PlayerUtil.offlinePlayerName(this.issuer)),
|
||||
text(reason)
|
||||
);
|
||||
} else {
|
||||
return translatable(
|
||||
"smod.punishment.playerMessage." + type,
|
||||
text(PlayerUtil.offlinePlayerName(this.issuer)),
|
||||
text(reason),
|
||||
TimeUtil.formatTimeLong(this.timestamp + this.duration - System.currentTimeMillis())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component adminMessage(){
|
||||
if (isPermanent()){
|
||||
return translatable(
|
||||
"smod.punishment.broadcast." + type + ".permanent",
|
||||
text(PlayerUtil.offlinePlayerName(target)),
|
||||
text(PlayerUtil.offlinePlayerName(issuer)),
|
||||
text(reason)
|
||||
);
|
||||
} else {
|
||||
return translatable(
|
||||
"smod.punishment.broadcast." + type,
|
||||
text(PlayerUtil.offlinePlayerName(target)),
|
||||
text(PlayerUtil.offlinePlayerName(issuer)),
|
||||
text(reason),
|
||||
TimeUtil.formatTimeLong(this.duration)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public Component cancelMessage(){
|
||||
return translatable(
|
||||
"smod.punishment.cancel." + type,
|
||||
text(PlayerUtil.offlinePlayerName(target)),
|
||||
text(PlayerUtil.offlinePlayerName(cancelledBy))
|
||||
);
|
||||
}
|
||||
|
||||
public long getExpiry() {
|
||||
return isPermanent() ? Long.MAX_VALUE : getTimestamp() + getDuration();
|
||||
}
|
||||
|
||||
public boolean isPermanent() {
|
||||
return getDuration() == DurationArgument.INFINITE_DURATION;
|
||||
}
|
||||
|
||||
protected void cancel(UUID canceller) {
|
||||
if (this.cancelledBy != null){
|
||||
throw new IllegalArgumentException("This punishment was already cancelled.");
|
||||
}
|
||||
this.cancelledBy = canceller;
|
||||
for (CommandSender sender : getBroadcastTargets()) {
|
||||
sender.sendMessage(cancelMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.storage;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class PunishmentContainer {
|
||||
|
||||
private final CopyOnWriteArrayList<Punishment> punishments = new CopyOnWriteArrayList<>();
|
||||
|
||||
public PunishmentContainer(){}
|
||||
|
||||
public void add(Punishment punishment){
|
||||
punishments.add(punishment);
|
||||
}
|
||||
|
||||
public @Nullable Punishment remove(int index){
|
||||
return punishments.remove(index);
|
||||
}
|
||||
|
||||
public void remove(Punishment punishment){
|
||||
punishments.remove(punishment);
|
||||
}
|
||||
|
||||
public @Nullable Punishment find(Predicate<Punishment> predicate){
|
||||
for (Punishment punishment : punishments) {
|
||||
if (predicate.test(punishment)){
|
||||
return punishment;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public @NotNull List<Punishment> findAll(Predicate<Punishment> predicate){
|
||||
List<Punishment> found = new ArrayList<>();
|
||||
for (Punishment punishment : punishments) {
|
||||
if (predicate.test(punishment)){
|
||||
found.add(punishment);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
public List<CommandSender> collectBroadcastTargets(){
|
||||
ArrayList<CommandSender> senders = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.notifications")){
|
||||
senders.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
senders.add(Bukkit.getConsoleSender());
|
||||
return Collections.unmodifiableList(senders);
|
||||
}
|
||||
|
||||
public @Nullable Punishment findByTimestamp(long timestamp){
|
||||
return find(punishment -> punishment.time == timestamp);
|
||||
}
|
||||
|
||||
public ArrayList<Punishment> copy() {
|
||||
return new ArrayList<>(punishments);
|
||||
}
|
||||
|
||||
public synchronized void load(File file){
|
||||
final ComponentLogger logger = SModerationPaper.LOGGER;
|
||||
try {
|
||||
logger.info("Loading from {}", file.getPath());
|
||||
if (!file.isFile()){
|
||||
logger.warn("The file does not exist.");
|
||||
} else {
|
||||
try (FileInputStream fin = new FileInputStream(file)){
|
||||
GZIPInputStream gzin = new GZIPInputStream(fin);
|
||||
while (gzin.available() > 0){
|
||||
add(Punishment.load(gzin));
|
||||
}
|
||||
}
|
||||
logger.info("Successfully loaded {} items.", punishments.size());
|
||||
}
|
||||
} catch (EOFException e) {
|
||||
logger.error("The file was not correctly saved, {} items could be recovered!", this.punishments.size());
|
||||
} catch (IOException e){
|
||||
logger.error("An error occurred while loading: {}", e.toString());
|
||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
||||
logger.error(stackTraceElement.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void save(File file) {
|
||||
final ComponentLogger logger = SModerationPaper.LOGGER;
|
||||
try {
|
||||
if (!file.isFile()){
|
||||
file.mkdirs();
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
}
|
||||
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
||||
GZIPOutputStream gzout = new GZIPOutputStream(outputStream);
|
||||
for (Punishment punishment : copy()) {
|
||||
punishment.writeBytes(gzout);
|
||||
}
|
||||
gzout.close();
|
||||
}
|
||||
} catch (IOException e){
|
||||
logger.error("An error occurred while saving: {}", e.toString());
|
||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
||||
logger.error(stackTraceElement.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,20 @@
|
||||
package de.shiewk.smoderation.paper.translation;
|
||||
|
||||
import com.google.gson.FormattingStyle;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.translation.MiniMessageTranslationStore;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -45,4 +48,54 @@ public class TranslatorManager {
|
||||
}
|
||||
GlobalTranslator.translator().addSource(translationStore);
|
||||
}
|
||||
|
||||
public void loadCustomMessages(Path customPath) {
|
||||
try {
|
||||
if (Files.notExists(customPath)) {
|
||||
Files.createDirectories(customPath.getParent());
|
||||
Files.write(customPath, "{}".getBytes(), StandardOpenOption.CREATE);
|
||||
}
|
||||
|
||||
Map<String, String> predefinedMap;
|
||||
try (InputStream stream = SModerationPaper.class.getClassLoader().getResourceAsStream(resourcePath + "en_us.json")) {
|
||||
if (stream == null) {
|
||||
SModerationPaper.LOGGER.warn("English (US) predefined translations not found or not accessible");
|
||||
predefinedMap = Map.of();
|
||||
} else {
|
||||
predefinedMap = SModerationPaper.gson.fromJson(new InputStreamReader(stream), new TypeToken<>(){});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> translationMap;
|
||||
try (InputStream stream = Files.newInputStream(customPath)) {
|
||||
translationMap = SModerationPaper.gson.fromJson(new InputStreamReader(stream), new TypeToken<>(){});
|
||||
}
|
||||
|
||||
boolean updated = false;
|
||||
for (Map.Entry<String, String> entry : predefinedMap.entrySet()) {
|
||||
if (!translationMap.containsKey(entry.getKey())) {
|
||||
translationMap.put(entry.getKey(), entry.getValue());
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
SModerationPaper.LOGGER.warn("Updating {} custom translations", translationMap.size());
|
||||
try (OutputStream stream = Files.newOutputStream(customPath, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
OutputStreamWriter writer = new OutputStreamWriter(stream);
|
||||
JsonWriter jsonWriter = new JsonWriter(writer)) {
|
||||
jsonWriter.setFormattingStyle(FormattingStyle.PRETTY);
|
||||
SModerationPaper.gson.toJson(translationMap, translationMap.getClass(), jsonWriter);
|
||||
}
|
||||
SModerationPaper.LOGGER.info("Update successful");
|
||||
}
|
||||
|
||||
translationStore.registerAll(Locale.forLanguageTag("en-US"), translationMap);
|
||||
SModerationPaper.LOGGER.info("Registered {} custom translations", translationMap.size());
|
||||
|
||||
} catch (IOException e) {
|
||||
SModerationPaper.LOGGER.warn("Failed to load custom translations", e);
|
||||
}
|
||||
GlobalTranslator.translator().addSource(translationStore);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.util;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for byte-based saving of integers, longs and UUIDs
|
||||
*/
|
||||
public final class ByteUtil {
|
||||
private ByteUtil(){}
|
||||
|
||||
public static byte[] longToBytes(long v){
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
buffer.putLong(v);
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
public static long bytesToLong(byte[] i){
|
||||
if (i.length != 8){
|
||||
throw new IllegalArgumentException("length must be 8");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
buffer.put(0, i);
|
||||
return buffer.getLong(0);
|
||||
}
|
||||
|
||||
public static byte[] uuidToBytes(UUID uuid){
|
||||
byte[] l = longToBytes(uuid.getLeastSignificantBits());
|
||||
byte[] m = longToBytes(uuid.getMostSignificantBits());
|
||||
return new byte[]{
|
||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7],
|
||||
l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]
|
||||
};
|
||||
}
|
||||
|
||||
public static UUID bytesToUuid(byte[] i){
|
||||
if (i.length != 16){
|
||||
throw new IllegalArgumentException("length must be 16, was " + i.length);
|
||||
}
|
||||
long l = bytesToLong(new byte[]{ i[8], i[9], i[10], i[11], i[12], i[13], i[14], i[15] });
|
||||
long m = bytesToLong(new byte[]{ i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7] });
|
||||
return new UUID(m, l);
|
||||
}
|
||||
|
||||
public static int bytesToInt(byte[] bytes) {
|
||||
if (bytes.length != 4){
|
||||
throw new IllegalArgumentException("length must be 4");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.put(0, bytes);
|
||||
return buffer.getInt(0);
|
||||
}
|
||||
|
||||
public static byte[] intToBytes(int value) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.putInt(value);
|
||||
return buffer.array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.shiewk.smoderation.paper.util;
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public record ColorPalette(TextColor primary, TextColor secondary, TextColor detail) {
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.util.function.Predicate;
|
||||
import static de.shiewk.smoderation.paper.util.PlayerUtil.UUID_CONSOLE;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class CommandUtil {
|
||||
private CommandUtil(){}
|
||||
|
||||
|
||||
@@ -28,4 +28,12 @@ public final class PlayerUtil {
|
||||
return Bukkit.getPlayer(uid);
|
||||
}
|
||||
}
|
||||
|
||||
public static UUID uuidFromString(String string) {
|
||||
if (string.length() == 36) {
|
||||
return UUID.fromString(string);
|
||||
} else {
|
||||
return UUID.fromString(string.replaceFirst("(.{8})(.{4})(.{4})(.{4})(.{12})", "$1-$2-$3-$4-$5"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package de.shiewk.smoderation.paper.util;
|
||||
|
||||
import de.shiewk.smoderation.paper.punishments.*;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.LOGGER;
|
||||
|
||||
public final class SModLegacy {
|
||||
private SModLegacy() {}
|
||||
|
||||
private static byte[] longToBytes(long v){
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
buffer.putLong(v);
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
private static long bytesToLong(byte[] i){
|
||||
if (i.length != 8){
|
||||
throw new IllegalArgumentException("length must be 8");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
buffer.put(0, i);
|
||||
return buffer.getLong(0);
|
||||
}
|
||||
|
||||
private static byte[] uuidToBytes(UUID uuid){
|
||||
byte[] l = longToBytes(uuid.getLeastSignificantBits());
|
||||
byte[] m = longToBytes(uuid.getMostSignificantBits());
|
||||
return new byte[]{
|
||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7],
|
||||
l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]
|
||||
};
|
||||
}
|
||||
|
||||
private static UUID bytesToUuid(byte[] i){
|
||||
if (i.length != 16){
|
||||
throw new IllegalArgumentException("length must be 16, was " + i.length);
|
||||
}
|
||||
long l = bytesToLong(new byte[]{ i[8], i[9], i[10], i[11], i[12], i[13], i[14], i[15] });
|
||||
long m = bytesToLong(new byte[]{ i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7] });
|
||||
return new UUID(m, l);
|
||||
}
|
||||
|
||||
private static int bytesToInt(byte[] bytes) {
|
||||
if (bytes.length != 4){
|
||||
throw new IllegalArgumentException("length must be 4");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.put(0, bytes);
|
||||
return buffer.getInt(0);
|
||||
}
|
||||
|
||||
private static byte[] intToBytes(int value) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.putInt(value);
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
private static byte[] readStreamInternal(InputStream stream, int len) throws IOException {
|
||||
final byte[] bytes = stream.readNBytes(len);
|
||||
if (bytes.length != len){
|
||||
throw new EOFException("Stream has ended before enough bytes were read");
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static void migrateV1PunishmentsFile(PunishmentManager manager, Path path, Path copy) {
|
||||
int count = 0;
|
||||
try {
|
||||
if (Files.isRegularFile(path)) {
|
||||
LOGGER.info("Migrating V1 punishment file: {}", path);
|
||||
try (InputStream in = new FileInputStream(path.toFile());
|
||||
GZIPInputStream gzin = new GZIPInputStream(in)){
|
||||
while (gzin.available() > 0){
|
||||
int type = bytesToInt(readStreamInternal(gzin, 4));
|
||||
long time = bytesToLong(readStreamInternal(gzin, 8));
|
||||
long until = bytesToLong(readStreamInternal(gzin, 8));
|
||||
UUID by = bytesToUuid(readStreamInternal(gzin, 16));
|
||||
UUID to = bytesToUuid(readStreamInternal(gzin, 16));
|
||||
int reasonLen = bytesToInt(readStreamInternal(gzin, 4));
|
||||
String reason = new String(readStreamInternal(gzin, reasonLen));
|
||||
UUID canceller = null;
|
||||
boolean cancelled = gzin.read() == 1;
|
||||
if (cancelled){
|
||||
canceller = bytesToUuid(readStreamInternal(gzin, 16));
|
||||
}
|
||||
// Type 0: mute; 1: kick; 2: ban
|
||||
Punishment p = switch (type){
|
||||
case 0 -> new Mute(
|
||||
Punishment.generateUUID(),
|
||||
time,
|
||||
by,
|
||||
to,
|
||||
reason,
|
||||
until - time,
|
||||
canceller
|
||||
);
|
||||
case 1 -> new Kick(
|
||||
Punishment.generateUUID(),
|
||||
time,
|
||||
by,
|
||||
to,
|
||||
reason
|
||||
);
|
||||
case 2 -> new Ban(
|
||||
Punishment.generateUUID(),
|
||||
time,
|
||||
by,
|
||||
to,
|
||||
reason,
|
||||
until - time,
|
||||
canceller
|
||||
);
|
||||
default -> throw new IllegalArgumentException("Invalid legacy type for punishment: " + type);
|
||||
};
|
||||
count++;
|
||||
manager.appendToSave(p);
|
||||
LOGGER.info("Migrated: {}", p);
|
||||
}
|
||||
}
|
||||
LOGGER.info("Successfully loaded {} items.", count);
|
||||
Files.move(path, copy);
|
||||
}
|
||||
} catch (EOFException e) {
|
||||
LOGGER.error("The file was not correctly saved, {} items could be recovered!", count);
|
||||
} catch (IOException e){
|
||||
LOGGER.error("An error occurred while loading", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package de.shiewk.smoderation.paper.util;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class SerializationHelper {
|
||||
|
||||
private final JsonObject json;
|
||||
|
||||
public SerializationHelper(JsonObject json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
try {
|
||||
return json.get(key).getAsString();
|
||||
} catch (NullPointerException e) {
|
||||
throw new IllegalStateException("Key " + key + " does not exist on this object");
|
||||
} catch (UnsupportedOperationException | IllegalStateException e) {
|
||||
throw new IllegalStateException("Tried to get string " + key + ", but is " + json.get(key).getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
public void putString(String key, String value) {
|
||||
json.addProperty(key, value);
|
||||
}
|
||||
|
||||
public long getLong(String key) {
|
||||
try {
|
||||
return json.get(key).getAsLong();
|
||||
} catch (NullPointerException e) {
|
||||
throw new IllegalStateException("Key " + key + " does not exist on this object");
|
||||
} catch (UnsupportedOperationException | IllegalStateException e) {
|
||||
throw new IllegalStateException("Tried to get long " + key + ", but is " + json.get(key).getClass().getSimpleName());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalStateException("Tried to get long " + key + ", but is malformed: " + json.get(key).getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
public void putLong(String key, long value) {
|
||||
json.addProperty(key, value);
|
||||
}
|
||||
|
||||
public UUID getUUID(String key) {
|
||||
try {
|
||||
return PlayerUtil.uuidFromString(getString(key));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalStateException("UUID " + key + " malformed: " + getString(key));
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getUUID(String key, UUID defaultValue) {
|
||||
try {
|
||||
return getUUID(key);
|
||||
} catch (Exception ignored) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void putUUID(String key, UUID value) {
|
||||
if (value == null) return;
|
||||
json.addProperty(key, value.toString().replace("-", ""));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,46 @@
|
||||
# If enabled, punishments can no longer be issued without providing a reason.
|
||||
force-reason: false
|
||||
|
||||
# The string that should be used when no reason is provided.
|
||||
# This has no effect if 'force-reason' is set to true.
|
||||
default-reason: No reason provided.
|
||||
|
||||
# Allows you to toggle specific plugin features.
|
||||
features:
|
||||
# Should punishments be tracked and executed?
|
||||
# Note that disabling this will also disable the SMod menu and
|
||||
# /modlogs command since their only use is viewing punishments.
|
||||
punishments: true
|
||||
# Should commands for opening the SMod menu be registered?
|
||||
smodmenu: true
|
||||
# Should commands for viewing player inventories be registered?
|
||||
invsee: true
|
||||
# Should commands for viewing player ender chests be registered?
|
||||
enderchestsee: true
|
||||
# Should commands for teleporting to offline players be registered?
|
||||
offlinetp: true
|
||||
# Should commands for viewing other players' messaging commands be registered?
|
||||
socialspy: true
|
||||
# Should players be able to enable vanish mode?
|
||||
vanish: true
|
||||
|
||||
# Allows you to customize plugin colors.
|
||||
# Colors have to be formatted #rrggbb.
|
||||
colors:
|
||||
primary: '#e26c04'
|
||||
secondary: '#fc9e07'
|
||||
detail: '#ababab'
|
||||
|
||||
# Allows you to customize translation files.
|
||||
# - At 'false', the plugin's predefined localization is used
|
||||
# and available for multiple languages:
|
||||
# https://github.com/Shiewk/SModeration/tree/main/src/main/resources/smoderation/translations
|
||||
# - At 'true', a JSON localization file will be created in the plugin directory.
|
||||
# Only the contained strings will be used and localization will be disabled.
|
||||
custom-messages: false
|
||||
|
||||
# A list of commands which will be captured and broadcast
|
||||
# to players which have SocialSpy enabled (/socialspy).
|
||||
socialspy-commands:
|
||||
- w
|
||||
- tell
|
||||
@@ -9,7 +52,8 @@ socialspy-commands:
|
||||
- minecraft:msg
|
||||
- minecraft:teammsg
|
||||
- minecraft:tm
|
||||
force-reason: false
|
||||
|
||||
# A list of commands which muted players will not be able to run.
|
||||
muted-forbidden-commands:
|
||||
- w
|
||||
- tell
|
||||
@@ -22,12 +66,4 @@ muted-forbidden-commands:
|
||||
- minecraft:msg
|
||||
- minecraft:teammsg
|
||||
- minecraft:tm
|
||||
- minecraft:me
|
||||
features:
|
||||
punishments: true
|
||||
smodmenu: true
|
||||
invsee: true
|
||||
enderchestsee: true
|
||||
offlinetp: true
|
||||
socialspy: true
|
||||
vanish: true
|
||||
- minecraft:me
|
||||
@@ -0,0 +1,122 @@
|
||||
{
|
||||
"smod.argument.duration.fail.invalid": "Ungültige Zeit '<arg:0>'",
|
||||
"smod.argument.duration.fail.pattern": "Bitte gib eine gültige Zeit an, z.B. '1d6h30min'",
|
||||
"smod.argument.offlinePlayer.fail.notCached": "Die Daten des Spielers sind nicht gespeichert.",
|
||||
"smod.argument.uuid.fail.notCached": "Die Daten des Spielers sind nicht gespeichert. Versuche, stattdessen seine UUID anzugeben.",
|
||||
"smod.chatInput.remainingTime": "<detail><arg:0> Sekunden",
|
||||
"smod.command.ban.fail.alreadyBanned": "Dieser Spieler ist schon gebannt.",
|
||||
"smod.command.ban.fail.forceReason": "Bitte gib einen Grund an.",
|
||||
"smod.command.ban.fail.protect": "Dieser Spieler kann nicht gebannt werden.",
|
||||
"smod.command.ban.fail.self": "Du kannst dich nicht selbst bannen.",
|
||||
"smod.command.ban.fail.tooShort": "Du kannst Spieler, die nicht online sind, nicht so kurz bannen.",
|
||||
"smod.command.ecsee.opening": "<primary>Enderkiste von <secondary><arg:0></secondary> wird geöffnet.",
|
||||
"smod.command.fail.invalidPlayer": "Bitte gib einen gültigen Spieler an.",
|
||||
"smod.command.fail.players": "Nur Spieler können diesen Befehl ausführen.",
|
||||
"smod.command.fail.playersConsole": "Nur Spieler und die Konsole können diesen Befehl ausführen.",
|
||||
"smod.command.invsee.fail.self": "Du kannst dein eigenes Inventar nicht öffnen.",
|
||||
"smod.command.invsee.opening": "<primary>Inventar von <secondary><arg:0></secondary> wird geöffnet.",
|
||||
"smod.command.kick.fail.forceReason": "Bitte gib einen Grund an.",
|
||||
"smod.command.kick.fail.protect": "Dieser Spieler kann nicht gekickt werden.",
|
||||
"smod.command.kick.fail.self": "Du kannst dich nicht selbst kicken.",
|
||||
"smod.command.modlogs.ban": "<primary>- ist bis <secondary><arg:0></secondary> <detail>(in <arg:1>)</detail> gebannt. Grund: <secondary><arg:2>",
|
||||
"smod.command.modlogs.ban.permanent": "<primary>- ist <secondary>permanent</secondary> gebannt. Grund: <secondary><arg:0>",
|
||||
"smod.command.modlogs.heading": "<primary>Spieler <secondary><arg:0> <detail>(<arg:1>)",
|
||||
"smod.command.modlogs.mute": "<primary>- ist bis <secondary><arg:0></secondary> <detail>(in <arg:1>)</detail> stummgeschaltet. Grund: <secondary><arg:2>",
|
||||
"smod.command.modlogs.mute.permanent": "<primary>- ist <secondary>permanent</secondary> stummgeschaltet. Grund: <secondary><arg:0>",
|
||||
"smod.command.modlogs.none": "<primary>- ist momentan nicht gebannt oder stummgeschaltet.",
|
||||
"smod.command.mute.fail.alreadyMuted": "Dieser Spieler ist schon stummgeschaltet.",
|
||||
"smod.command.mute.fail.forceReason": "Bitte gib einen Grund an.",
|
||||
"smod.command.mute.fail.protect": "Dieser Spieler kann nicht stummgeschaltet werden.",
|
||||
"smod.command.mute.fail.self": "Du kannst dich nicht selbst stummschalten.",
|
||||
"smod.command.mute.fail.tooShort": "Du kannst Spieler nicht so kurz stummschalten.",
|
||||
"smod.command.offlinetp.fail.unknown": "Die Position des Spielers ist nicht bekannt.",
|
||||
"smod.command.offlinetp.teleporting": "<primary>Du wirst zu <secondary><arg:0></secondary> teleportiert.",
|
||||
"smod.command.socialspy.disabled": "<primary>SocialSpy <red>deaktiviert</red>.",
|
||||
"smod.command.socialspy.enabled": "<primary>SocialSpy <green>aktiviert</green>.",
|
||||
"smod.command.unban.fail.notBanned": "Dieser Spieler ist nicht gebannt.",
|
||||
"smod.command.unmute.fail.notMuted": "Dieser Spieler ist nicht stummgeschaltet.",
|
||||
"smod.command.vanish.broadcast.off": "<primary><secondary><arg:0></secondary> ist wieder erschienen.",
|
||||
"smod.command.vanish.broadcast.on": "<primary><secondary><arg:0></secondary> ist verschwunden.",
|
||||
"smod.command.vanish.fail.noPlayersFound": "Kein Spieler wurde gefunden.",
|
||||
"smod.command.vanish.list": "<primary>Diese Spieler sind momentan versteckt: <arg:0>",
|
||||
"smod.command.vanish.list.none": "<primary>Keine Spieler sind gerade versteckt.",
|
||||
"smod.command.vanish.stillEnabled": "<bold><primary>Du bist noch unsichtbar!",
|
||||
"smod.command.vanish.toggle.off": "<primary>Du bist nicht mehr versteckt.",
|
||||
"smod.command.vanish.toggle.on": "<primary>Du bist jetzt unsichtbar.",
|
||||
"smod.confirm.no": "<red>Nein",
|
||||
"smod.confirm.yes": "<green>Ja",
|
||||
"smod.inventory.next": "Nächste Seite (<arg:0>/<arg:1>)",
|
||||
"smod.inventory.previous": "Vorherige Seite (<arg:0>/<arg:1>)",
|
||||
"smod.menu": "SMod Menü",
|
||||
"smod.menu.cancelConfirmation": "Bist du sicher, dass du die Strafe aufheben willst?",
|
||||
"smod.menu.filter": "Filter: <arg:0>",
|
||||
"smod.menu.filter.active": "Aktive Strafen",
|
||||
"smod.menu.filter.all": "Alle Strafen",
|
||||
"smod.menu.filter.expired": "Abgelaufene Strafen",
|
||||
"smod.menu.filter.switch": "\u00BB Klicke, um den Filter zu ändern",
|
||||
"smod.menu.info.cancelled": "<red>Aufgehoben von: <gold><arg:0>",
|
||||
"smod.menu.info.click": "\u00BB Klicke, um die Strafe aufzuheben",
|
||||
"smod.menu.info.duration": "<secondary>Dauer: <primary><arg:0>",
|
||||
"smod.menu.info.expiry.future": "<secondary>Läuft ab: <primary>In <arg:0>",
|
||||
"smod.menu.info.expiry.never": "<secondary>Läuft ab: <primary>Nie",
|
||||
"smod.menu.info.expiry.past": "<secondary>Ist abgelaufen: <primary><arg:0> ago",
|
||||
"smod.menu.info.player": "<secondary>Spieler: <primary><arg:0>",
|
||||
"smod.menu.info.punishedBy": "<secondary>Bestraft von: <primary><arg:0>",
|
||||
"smod.menu.info.reason": "<secondary>Grund: <primary><arg:0>",
|
||||
"smod.menu.info.timestamp": "<secondary>Zeitpunkt: <primary><arg:0>",
|
||||
"smod.menu.search": "Suchen",
|
||||
"smod.menu.search.current": "Aktueller Suchbegriff: <arg:0>",
|
||||
"smod.menu.search.new": "\u00BB Klicke, um einen neuen Suchbegriff einzugeben",
|
||||
"smod.menu.search.none": "Keiner",
|
||||
"smod.menu.search.query": "Gib deinen Suchbegriff in den Chat ein",
|
||||
"smod.menu.search.remove": "\u00BB Rechtsklick, um die Suche aufzuheben",
|
||||
"smod.menu.sort": "Sortieren nach: <arg:0>",
|
||||
"smod.menu.sort.expiry": "Ablaufzeitpunkt",
|
||||
"smod.menu.sort.moderatorName": "Moderatorname",
|
||||
"smod.menu.sort.playerName": "Spielername",
|
||||
"smod.menu.sort.switch": "\u00BB Klicke, um die Sortierung zu ändern",
|
||||
"smod.menu.sort.time": "Ausstellungszeitpunkt",
|
||||
"smod.menu.type": "Typ: <arg:0>",
|
||||
"smod.menu.type.all": "Alle",
|
||||
"smod.menu.type.switch": "\u00BB Klicke, um den Typ zu ändern",
|
||||
"smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> für <secondary><arg:3></secondary> gebannt.<newline>Grund: <secondary><arg:2>",
|
||||
"smod.punishment.broadcast.ban.permanent": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> <secondary>permanent</secondary> gebannt.<newline>Grund: <secondary><arg:2>",
|
||||
"smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> gekickt.<newline>Grund: <secondary><arg:2>",
|
||||
"smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> für <secondary><arg:3></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:2>",
|
||||
"smod.punishment.broadcast.mute.permanent": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> <secondary>permanent</secondary> stummgeschaltet.<newline>Grund: <secondary><arg:2>",
|
||||
"smod.punishment.cancel.ban": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> entbannt.",
|
||||
"smod.punishment.cancel.mute": "<primary><secondary><arg:0></secondary>s Stummschaltung wurde von <secondary><arg:1></secondary> aufgehoben.",
|
||||
"smod.punishment.name.ban": "Bann",
|
||||
"smod.punishment.name.kick": "Kick",
|
||||
"smod.punishment.name.mute": "Stummschaltung",
|
||||
"smod.punishment.playerMessage.ban": "<primary>Du wurdest von <secondary><arg:0></secondary> vom Server gebannt.<newline>Grund: <secondary><arg:1></secondary><newline>Dein Bann läuft in <secondary><arg:2></secondary> ab.",
|
||||
"smod.punishment.playerMessage.ban.permanent": "<primary>Du wurdest von <secondary><arg:0></secondary> vom Server gebannt.<newline>Grund: <secondary><arg:1></secondary><newline>Dein Bann läuft <secondary>nicht</secondary> ab.",
|
||||
"smod.punishment.playerMessage.kick": "<primary>Du wurdest von <secondary><arg:0></secondary> vom Server gekickt.<newline>Grund: <secondary><arg:1>",
|
||||
"smod.punishment.playerMessage.mute": "<primary>Du wurdest von <secondary><arg:0></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:1></secondary><newline>Du kannst in <secondary><arg:2></secondary> wieder schreiben.",
|
||||
"smod.punishment.playerMessage.mute.permanent": "<primary>Du wurdest von <secondary><arg:0></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:1></secondary><newline>Du kannst <secondary>nie</secondary> wieder schreiben.",
|
||||
"smod.punishment.playerMessage.mute.chat": "<primary>Du kannst diesen Befehl nicht ausführen, während du stummgeschaltet bist.",
|
||||
"smod.socialspy.command": "<primary>[<secondary>SocialSpy</secondary>] <arg:0>: <secondary><arg:1>",
|
||||
"smod.time.days": "<arg:0> Tage",
|
||||
"smod.time.hours": "<arg:0> Stunden",
|
||||
"smod.time.milliseconds": "<arg:0> Millisekunden",
|
||||
"smod.time.minutes": "<arg:0> Minuten",
|
||||
"smod.time.month.0": "Januar",
|
||||
"smod.time.month.1": "Februar",
|
||||
"smod.time.month.10": "November",
|
||||
"smod.time.month.11": "Dezember",
|
||||
"smod.time.month.2": "März",
|
||||
"smod.time.month.3": "April",
|
||||
"smod.time.month.4": "Mai",
|
||||
"smod.time.month.5": "Juni",
|
||||
"smod.time.month.6": "Juli",
|
||||
"smod.time.month.7": "August",
|
||||
"smod.time.month.8": "September",
|
||||
"smod.time.month.9": "Oktober",
|
||||
"smod.time.months": "<arg:0> Monate",
|
||||
"smod.time.never": "Nie",
|
||||
"smod.time.permanent": "Permanent",
|
||||
"smod.time.seconds": "<arg:0> Sekunden",
|
||||
"smod.time.timestamp": "<arg:2>. <arg:1> <arg:0> <arg:3>:<arg:4>:<arg:5> <arg:6>",
|
||||
"smod.time.weeks": "<arg:0> Wochen",
|
||||
"smod.time.years": "<arg:0> Jahre"
|
||||
}
|
||||
@@ -1,60 +1,69 @@
|
||||
{
|
||||
"smod.argument.duration.fail.invalid": "Invalid duration '<arg:0>'",
|
||||
"smod.argument.duration.fail.pattern": "Please provide a valid duration, e.g. '1d6h30min'",
|
||||
"smod.argument.offlinePlayer.fail.notCached": "That player is not cached.",
|
||||
"smod.argument.uuid.fail.notCached": "That player is not cached. Try providing an UUID instead.",
|
||||
"smod.chatInput.remainingTime": "<gray><arg:0> seconds",
|
||||
"smod.argument.offlinePlayer.fail.notCached": "That player's data is not saved.",
|
||||
"smod.argument.uuid.fail.notCached": "That player's data is not saved. Try providing an UUID instead.",
|
||||
"smod.chatInput.remainingTime": "<detail><arg:0> seconds",
|
||||
"smod.command.ban.fail.alreadyBanned": "This player is already banned.",
|
||||
"smod.command.ban.fail.forceReason": "Please provide a reason.",
|
||||
"smod.command.ban.fail.protect": "This player can't be banned.",
|
||||
"smod.command.ban.fail.self": "You can't ban yourself.",
|
||||
"smod.command.ban.fail.tooShort": "You can't ban an offline player for less than 1ms.",
|
||||
"smod.command.ecsee.opening": "<prefix>Opening ender chest of <secondary><arg:0></secondary>.",
|
||||
"smod.command.ecsee.opening": "<primary>Opening ender chest of <secondary><arg:0></secondary>.",
|
||||
"smod.command.fail.invalidPlayer": "Please provide a valid player.",
|
||||
"smod.command.fail.players": "Only players can execute this command.",
|
||||
"smod.command.fail.playersConsole": "Only players and the console can execute this command.",
|
||||
"smod.command.invsee.fail.self": "You can't open your own inventory.",
|
||||
"smod.command.invsee.opening": "<prefix>Opening inventory of <secondary><arg:0></secondary>.",
|
||||
"smod.command.invsee.opening": "<primary>Opening inventory of <secondary><arg:0></secondary>.",
|
||||
"smod.command.kick.fail.forceReason": "Please provide a reason.",
|
||||
"smod.command.kick.fail.protect": "This player can't be kicked.",
|
||||
"smod.command.kick.fail.self": "You can't kick yourself.",
|
||||
"smod.command.modlogs.ban": "<primary>- is banned until <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray>. Reason: <secondary><arg:2>",
|
||||
"smod.command.modlogs.heading": "<prefix>Player <secondary><arg:0> <gray>(<arg:1>)",
|
||||
"smod.command.modlogs.mute": "<primary>- is muted until <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray>. Reason: <secondary><arg:2>",
|
||||
"smod.command.modlogs.ban": "<primary>- is banned until <secondary><arg:0></secondary> <detail>(in <arg:1>)</detail>. Reason: <secondary><arg:2>",
|
||||
"smod.command.modlogs.ban.permanent": "<primary>- is banned <secondary>permanently</secondary>. Reason: <secondary><arg:0>",
|
||||
"smod.command.modlogs.heading": "<primary>Player <secondary><arg:0> <detail>(<arg:1>)",
|
||||
"smod.command.modlogs.mute": "<primary>- is muted until <secondary><arg:0></secondary> <detail>(in <arg:1>)</detail>. Reason: <secondary><arg:2>",
|
||||
"smod.command.modlogs.mute.permanent": "<primary>- is muted <secondary>permanently</secondary>. Reason: <secondary><arg:0>",
|
||||
"smod.command.modlogs.none": "<primary>- is not currently muted or banned.",
|
||||
"smod.command.mute.fail.alreadyMuted": "This player is already muted.",
|
||||
"smod.command.mute.fail.forceReason": "Please provide a reason.",
|
||||
"smod.command.mute.fail.protect": "This player can't be muted.",
|
||||
"smod.command.mute.fail.self": "You can't mute yourself.",
|
||||
"smod.command.mute.fail.tooShort": "You can't mute a player for less than 1ms.",
|
||||
"smod.command.offlinetp.fail.unknown": "This player's location is unknown.",
|
||||
"smod.command.offlinetp.teleporting": "<prefix>Teleporting you to <secondary><arg:0></secondary>.",
|
||||
"smod.command.socialspy.disabled": "<prefix>SocialSpy <red>disabled</red>.",
|
||||
"smod.command.socialspy.enabled": "<prefix>SocialSpy <green>enabled</green>.",
|
||||
"smod.command.offlinetp.teleporting": "<primary>Teleporting you to <secondary><arg:0></secondary>.",
|
||||
"smod.command.socialspy.disabled": "<primary>SocialSpy <red>disabled</red>.",
|
||||
"smod.command.socialspy.enabled": "<primary>SocialSpy <green>enabled</green>.",
|
||||
"smod.command.unban.fail.notBanned": "That player is not banned.",
|
||||
"smod.command.unmute.fail.notMuted": "That player is not muted.",
|
||||
"smod.command.vanish.broadcast.off": "<prefix><secondary><arg:0></secondary> re-appeared.",
|
||||
"smod.command.vanish.broadcast.on": "<prefix><secondary><arg:0></secondary> vanished.",
|
||||
"smod.command.vanish.broadcast.off": "<primary><secondary><arg:0></secondary> re-appeared.",
|
||||
"smod.command.vanish.broadcast.on": "<primary><secondary><arg:0></secondary> vanished.",
|
||||
"smod.command.vanish.fail.noPlayersFound": "No player was found.",
|
||||
"smod.command.vanish.list": "<prefix>The following players are currently vanished: <arg:0>",
|
||||
"smod.command.vanish.list.none": "<prefix>No players are currently vanished.",
|
||||
"smod.command.vanish.toggle.off": "<prefix>You are no longer vanished.",
|
||||
"smod.command.vanish.toggle.on": "<prefix>You are now vanished.",
|
||||
"smod.command.vanish.list": "<primary>The following players are currently vanished: <arg:0>",
|
||||
"smod.command.vanish.list.none": "<primary>No players are currently vanished.",
|
||||
"smod.command.vanish.stillEnabled": "<bold><primary>You are still vanished!",
|
||||
"smod.command.vanish.toggle.off": "<primary>You are no longer vanished.",
|
||||
"smod.command.vanish.toggle.on": "<primary>You are now vanished.",
|
||||
"smod.confirm.no": "<red>No",
|
||||
"smod.confirm.yes": "<green>Yes",
|
||||
"smod.inventory.next": "Next page (<arg:0>/<arg:1>)",
|
||||
"smod.inventory.previous": "Previous page (<arg:0>/<arg:1>)",
|
||||
"smod.menu": "SMod Menu",
|
||||
"smod.menu.cancelConfirmation": "Are you sure that you want to cancel this punishment?",
|
||||
"smod.menu.filter": "Filter: <arg:0>",
|
||||
"smod.menu.filter.active": "Active punishments",
|
||||
"smod.menu.filter.all": "All punishments",
|
||||
"smod.menu.filter.expired": "Expired punishments",
|
||||
"smod.menu.filter.switch": "\u00BB Click to switch filter",
|
||||
"smod.menu.info.click": "\u00BB Click to undo punishment",
|
||||
"smod.menu.info.cancelled": "<red>Cancelled by: <gold><arg:0>",
|
||||
"smod.menu.info.click": "\u00BB Click to cancel punishment",
|
||||
"smod.menu.info.duration": "<secondary>Duration: <primary><arg:0>",
|
||||
"smod.menu.info.expiry.future": "<secondary>Expires: <primary>In <arg:0>",
|
||||
"smod.menu.info.expiry.never": "<secondary>Expires: <primary>Never",
|
||||
"smod.menu.info.expiry.past": "<secondary>Expired: <primary><arg:0> ago",
|
||||
"smod.menu.info.player": "<secondary>Player: <primary><arg:0>",
|
||||
"smod.menu.info.punishedBy": "<secondary>Punished by: <primary><arg:0>",
|
||||
"smod.menu.info.reason": "<secondary>Reason: <primary><arg:0>",
|
||||
"smod.menu.info.timestamp": "<secondary>Timestamp: <primary><arg:0>",
|
||||
"smod.menu.info.undone": "<red>Undone by: <gold><arg:0>",
|
||||
"smod.menu.search": "Search",
|
||||
"smod.menu.search.current": "Current search query: <arg:0>",
|
||||
"smod.menu.search.new": "\u00BB Click to enter new search query",
|
||||
@@ -70,19 +79,22 @@
|
||||
"smod.menu.type": "Type: <arg:0>",
|
||||
"smod.menu.type.all": "All",
|
||||
"smod.menu.type.switch": "» Click to switch type",
|
||||
"smod.menu.undoConfirmation": "Are you sure that you want to undo this punishment?",
|
||||
"smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> was banned by <secondary><arg:1></secondary> for <secondary><arg:2></secondary>.<newline>Reason: <secondary><arg:3>",
|
||||
"smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> was kicked by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:3>",
|
||||
"smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> was muted by <secondary><arg:1></secondary> for <secondary><arg:2></secondary>.<newline>Reason: <secondary><arg:3>",
|
||||
"smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> was banned by <secondary><arg:1></secondary> for <secondary><arg:3></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||
"smod.punishment.broadcast.ban.permanent": "<primary><secondary><arg:0></secondary> was banned <secondary>permanently</secondary> by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||
"smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> was kicked by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||
"smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> was muted by <secondary><arg:1></secondary> for <secondary><arg:3></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||
"smod.punishment.broadcast.mute.permanent": "<primary><secondary><arg:0></secondary> was muted <secondary>permanently</secondary> by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:2>",
|
||||
"smod.punishment.cancel.ban": "<primary><secondary><arg:0></secondary> was unbanned by <secondary><arg:1></secondary>.",
|
||||
"smod.punishment.cancel.mute": "<primary><secondary><arg:0></secondary> was unmuted by <secondary><arg:1></secondary>.",
|
||||
"smod.punishment.name.ban": "Ban",
|
||||
"smod.punishment.name.kick": "Kick",
|
||||
"smod.punishment.name.mute": "Mute",
|
||||
"smod.punishment.playerMessage.ban": "<primary>You have been banned from this server by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your ban expires in <secondary><arg:2></secondary>.",
|
||||
"smod.punishment.playerMessage.ban.permanent": "<primary>You have been banned from this server by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your ban <secondary>does not</secondary> expire.",
|
||||
"smod.punishment.playerMessage.kick": "<primary>You have been kicked by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1>",
|
||||
"smod.punishment.playerMessage.mute": "<primary>You have been muted by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your mute expires in <secondary><arg:2></secondary>.",
|
||||
"smod.punishment.playerMessage.mute.permanent": "<primary>You have been muted by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your mute <secondary>does not</secondary> expire.",
|
||||
"smod.punishment.playerMessage.mute.chat": "<primary>You can't run this command while you are muted.",
|
||||
"smod.punishment.undo.ban": "<primary><secondary><arg:0></secondary> was unbanned by <secondary><arg:1></secondary>.",
|
||||
"smod.punishment.undo.mute": "<primary><secondary><arg:0></secondary> was unmuted by <secondary><arg:1></secondary>.",
|
||||
"smod.socialspy.command": "<primary>[<secondary>SocialSpy</secondary>] <arg:0>: <secondary><arg:1>",
|
||||
"smod.time.days": "<arg:0> days",
|
||||
"smod.time.hours": "<arg:0> hours",
|
||||
@@ -101,9 +113,10 @@
|
||||
"smod.time.month.8": "September",
|
||||
"smod.time.month.9": "October",
|
||||
"smod.time.months": "<arg:0> months",
|
||||
"smod.time.never": "Never",
|
||||
"smod.time.permanent": "Permanent",
|
||||
"smod.time.seconds": "<arg:0> seconds",
|
||||
"smod.time.timestamp": "<arg:2> <arg:1> <arg:0> <arg:3>:<arg:4>:<arg:5> <arg:6>",
|
||||
"smod.time.weeks": "<arg:0> weeks",
|
||||
"smod.time.years": "<arg:0> years",
|
||||
"smod.vanish.stillEnabled": "<bold><prefix>You are still vanished!"
|
||||
"smod.time.years": "<arg:0> years"
|
||||
}
|
||||
Reference in New Issue
Block a user