mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-29 06:34:17 +02:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 27a1fd8244 | |||
| 66c113bad2 | |||
| d863622168 | |||
| 361f66f645 | |||
| fbaaa6ec89 | |||
| 955ab8791a | |||
| 8128628b12 | |||
| 02570993a7 |
+18
-2
@@ -5,7 +5,6 @@ plugins {
|
||||
group = 'de.shiewk'
|
||||
version = pluginVersion
|
||||
|
||||
subprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
@@ -17,10 +16,27 @@ subprojects {
|
||||
url = "https://oss.sonatype.org/content/groups/public/"
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
def props = [version: version]
|
||||
inputs.properties props
|
||||
filteringCharset 'UTF-8'
|
||||
filesMatching('plugin.yml') {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveBaseName.set('SModeration-Paper')
|
||||
archiveVersion.set(pluginVersion)
|
||||
}
|
||||
|
||||
|
||||
def targetJavaVersion = 17
|
||||
def targetJavaVersion = 21
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
sourceCompatibility = javaVersion
|
||||
|
||||
+1
-1
@@ -13,6 +13,6 @@
|
||||
| /invsee \<player> equipment | Views another player's equipment (armor and offhand). | smod.invsee |
|
||||
| /enderchestsee <player> | Views another player's ender chest. | smod.enderchestsee |
|
||||
| /vanish | Toggles vanish mode so that other players can't see you're online. | smod.vanish |
|
||||
| /vanish toggle \<player> | Toggles vanish mode for another player. | smod.vanish |
|
||||
| /vanish toggle \<players> | Toggles vanish mode for other players. | smod.vanish |
|
||||
| /vanish list | Lists all vanished players. | smod.vanish.see |
|
||||
| /socialspy | Enables SocialSpy mode where you can see other player's private messages. | smod.socialspy |
|
||||
+1
-1
@@ -1 +1 @@
|
||||
pluginVersion = 1.4.2
|
||||
pluginVersion = 1.5.0
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
rootProject.name = 'SModeration'
|
||||
include 'smoderation-paper'
|
||||
@@ -1,19 +0,0 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compileOnly "io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveBaseName.set('SModeration-Paper')
|
||||
archiveVersion.set(pluginVersion)
|
||||
}
|
||||
|
||||
processResources {
|
||||
def props = [version: version]
|
||||
inputs.properties props
|
||||
filteringCharset 'UTF-8'
|
||||
filesMatching('plugin.yml') {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class BanCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
return false;
|
||||
} else {
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
String playerName = args[0];
|
||||
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
|
||||
if (senderUUID.equals(uuid)) {
|
||||
sender.sendMessage(Component.text("You can't ban yourself.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(Component.text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
final Player toPlayer = Bukkit.getPlayer(uuid);
|
||||
if (toPlayer != null && toPlayer.hasPermission("smod.preventban")){
|
||||
sender.sendMessage(text().content("This player can't be banned.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
long duration = 0;
|
||||
int p = 1;
|
||||
for (int i = 1 /* start with index 1 to avoid player name */; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
long parsedDuration = TimeUtil.parseDurationMillisSafely(arg);
|
||||
if (parsedDuration == -1){
|
||||
p = i;
|
||||
break;
|
||||
} else {
|
||||
duration += parsedDuration;
|
||||
}
|
||||
if (i == args.length - 1){ p = args.length; }
|
||||
}
|
||||
if (duration == 0){
|
||||
sender.sendMessage(Component.text("Please provide a valid duration.").color(NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
if (duration < 0){
|
||||
sender.sendMessage(Component.text("Please provide a duration that's longer than 0ms.").color(NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
StringBuilder reason = new StringBuilder();
|
||||
for (int i = p; i < args.length; i++) {
|
||||
if (!reason.isEmpty()){
|
||||
reason.append(" ");
|
||||
}
|
||||
reason.append(args[i]);
|
||||
}
|
||||
final Punishment punishment = Punishment.ban(System.currentTimeMillis(), System.currentTimeMillis() + duration, senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
String toComplete = args.length > 0 ? args[0] : "";
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
names.add(onlinePlayer.getName());
|
||||
}
|
||||
ArrayList<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
||||
return completions;
|
||||
} else {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (TimeUtil.parseDurationMillisSafely(args[i]) == -1){
|
||||
try {
|
||||
Long.parseLong(args[i]);
|
||||
} catch (NumberFormatException ignored){
|
||||
if (i != 1){
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return List.of(
|
||||
"100ms",
|
||||
"15s", // some sample completions for duration
|
||||
"30min", // you can input your own ones as well
|
||||
"6h",
|
||||
"1d",
|
||||
"2w",
|
||||
"3mo",
|
||||
"1y"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
|
||||
public class EnderchestSeeCommand implements TabExecutor {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
if (sender instanceof HumanEntity human){
|
||||
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
|
||||
if (player != null) {
|
||||
human.sendMessage(CHAT_PREFIX.append(
|
||||
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
));
|
||||
human.openInventory(player.getEnderChest());
|
||||
} else {
|
||||
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Only an entity that can open inventories can execute this command!").color(FAIL_COLOR));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length > 1){
|
||||
return List.of();
|
||||
}
|
||||
List<String> available = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
available.add(onlinePlayer.getName());
|
||||
}
|
||||
List<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(args.length > 0 ? args[0] : "", available, completions);
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.inventory.InvSeeEquipmentInventory;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
|
||||
public class InvseeCommand implements TabExecutor {
|
||||
|
||||
private enum InvseeType {
|
||||
INVENTORY,
|
||||
EQUIPMENT
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
final InvseeType type;
|
||||
if (args.length > 1){
|
||||
switch (args[1].toLowerCase()){
|
||||
case "armor", "equipment" -> type = InvseeType.EQUIPMENT;
|
||||
default -> type = InvseeType.INVENTORY;
|
||||
}
|
||||
} else {
|
||||
type = InvseeType.INVENTORY;
|
||||
}
|
||||
if (sender instanceof HumanEntity human){
|
||||
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
|
||||
if (player != null) {
|
||||
if (human.getUniqueId().equals(player.getUniqueId()) && type != InvseeType.EQUIPMENT){
|
||||
human.sendMessage(Component.text("You can't open your own inventory.").color(FAIL_COLOR));
|
||||
} else {
|
||||
human.sendMessage(CHAT_PREFIX.append(
|
||||
Component.text("Opening inventory of ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
));
|
||||
switch (type){
|
||||
case INVENTORY -> human.openInventory(player.getInventory());
|
||||
case EQUIPMENT -> new InvSeeEquipmentInventory(human, player).open();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Only an entity that can open inventories can execute this command!").color(FAIL_COLOR));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length > 2){
|
||||
return List.of();
|
||||
} else if (args.length > 1){
|
||||
return List.of("armor", "equipment", "inventory");
|
||||
}
|
||||
List<String> available = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
available.add(onlinePlayer.getName());
|
||||
}
|
||||
List<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(args.length > 0 ? args[0] : "", available, completions);
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class KickCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1){
|
||||
return false;
|
||||
} else {
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
String playerName = args[0];
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
if (player == null) {
|
||||
sender.sendMessage(Component.text("This player is not online.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (senderUUID.equals(uuid)) {
|
||||
sender.sendMessage(Component.text("You can't kick yourself.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (player.hasPermission("smod.preventkick")){
|
||||
sender.sendMessage(text().content("This player can't be kicked.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
StringBuilder reason = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (!reason.isEmpty()){
|
||||
reason.append(" ");
|
||||
}
|
||||
reason.append(args[i]);
|
||||
}
|
||||
final Punishment punishment = Punishment.kick(System.currentTimeMillis(), senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
String toComplete = args.length > 0 ? args[0] : "";
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
names.add(onlinePlayer.getName());
|
||||
}
|
||||
ArrayList<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
||||
return completions;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
|
||||
public class ModLogsCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1){
|
||||
return false;
|
||||
} else {
|
||||
String playername = args[0];
|
||||
String name;
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(playername);
|
||||
} catch (IllegalArgumentException ignored){
|
||||
uuid = PlayerUtil.offlinePlayerUUIDByName(playername);
|
||||
}
|
||||
if (uuid == null){
|
||||
sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label)).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
name = PlayerUtil.offlinePlayerName(uuid);
|
||||
sender.sendMessage(CHAT_PREFIX.append(Component.text("Player ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(name).color(SECONDARY_COLOR))
|
||||
.append(Component.text(" (%s)".formatted(uuid)).color(INACTIVE_COLOR))));
|
||||
UUID finalUuid = uuid;
|
||||
final List<Punishment> punishments = SModerationPaper.container.findAll(p -> p.to.equals(finalUuid) && p.isActive());
|
||||
for (Punishment punishment : punishments) {
|
||||
sender.sendMessage(Component.text("- is currently ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(punishment.type == PunishmentType.BAN ? "banned" : "muted").color(SECONDARY_COLOR))
|
||||
.append(Component.text(" until ").color(PRIMARY_COLOR))
|
||||
.append(Component.text(TimeUtil.calendarTimestamp(punishment.until)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(" (in %s)".formatted(TimeUtil.formatTimeLong(punishment.until - System.currentTimeMillis()))).color(INACTIVE_COLOR))
|
||||
.append(Component.text(". Reason: ").color(PRIMARY_COLOR))
|
||||
.append(Component.text(punishment.reason).color(SECONDARY_COLOR)));
|
||||
}
|
||||
if (punishments.isEmpty()){
|
||||
sender.sendMessage(Component.text("- has no punishments.").color(PRIMARY_COLOR));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length > 1){
|
||||
return List.of();
|
||||
}
|
||||
String search = args.length > 0 ? args[0] : "";
|
||||
List<String> playernames = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
playernames.add(onlinePlayer.getName());
|
||||
}
|
||||
List<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(search, playernames, completions);
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class MuteCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
return false;
|
||||
} else {
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
String playerName = args[0];
|
||||
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
|
||||
if (senderUUID.equals(uuid)) {
|
||||
sender.sendMessage(text("You can't mute yourself.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
final Player toPlayer = Bukkit.getPlayer(uuid);
|
||||
if (toPlayer != null && toPlayer.hasPermission("smod.preventmute")){
|
||||
sender.sendMessage(text().content("This player can't be muted.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
long duration = 0;
|
||||
int p = 1;
|
||||
for (int i = 1 /* start with index 1 to avoid player name */; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
long parsedDuration = TimeUtil.parseDurationMillisSafely(arg);
|
||||
if (parsedDuration == -1){
|
||||
p = i;
|
||||
break;
|
||||
} else {
|
||||
duration += parsedDuration;
|
||||
}
|
||||
if (i == args.length - 1){ p = args.length; }
|
||||
}
|
||||
if (duration == 0){
|
||||
sender.sendMessage(text("Please provide a valid duration.").color(NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
if (duration < 0){
|
||||
sender.sendMessage(text("Please provide a duration that's longer than 0ms.").color(NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
StringBuilder reason = new StringBuilder();
|
||||
for (int i = p; i < args.length; i++) {
|
||||
if (!reason.isEmpty()){
|
||||
reason.append(" ");
|
||||
}
|
||||
reason.append(args[i]);
|
||||
}
|
||||
final Punishment punishment = Punishment.mute(System.currentTimeMillis(), System.currentTimeMillis() + duration, senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
String toComplete = args.length > 0 ? args[0] : "";
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
names.add(onlinePlayer.getName());
|
||||
}
|
||||
ArrayList<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
||||
return completions;
|
||||
} else {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (TimeUtil.parseDurationMillisSafely(args[i]) == -1){
|
||||
try {
|
||||
Long.parseLong(args[i]);
|
||||
} catch (NumberFormatException ignored){
|
||||
if (i != 1){
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return List.of(
|
||||
"100ms",
|
||||
"15s", // some sample completions for duration
|
||||
"30min", // you can input your own ones as well
|
||||
"6h",
|
||||
"1d",
|
||||
"2w",
|
||||
"3mo",
|
||||
"1y"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.inventory.SModMenu;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SModCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
if (commandSender instanceof Player player){
|
||||
new SModMenu(player, SModerationPaper.container).open();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.listener.SocialSpyListener;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.CHAT_PREFIX;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class SocialSpyCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
final boolean enabled = SocialSpyListener.toggle(sender);
|
||||
sender.sendMessage(CHAT_PREFIX.append(text("SocialSpy ").append(
|
||||
enabled ?
|
||||
text("enabled").color(NamedTextColor.GREEN) :
|
||||
text("disabled").color(NamedTextColor.RED)
|
||||
).append(text("."))));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UnbanCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1){
|
||||
return false;
|
||||
} else {
|
||||
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
String nameArg = args[0];
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(nameArg);
|
||||
} catch (IllegalArgumentException ignored){
|
||||
uuid = PlayerUtil.offlinePlayerUUIDByName(nameArg);
|
||||
}
|
||||
if (uuid == null){
|
||||
sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label)).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
UUID finalUuid = uuid;
|
||||
final Punishment punishment = SModerationPaper.container.find(p -> p.to.equals(finalUuid) && p.isActive() && p.type == PunishmentType.BAN);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModerationPaper.container);
|
||||
} else {
|
||||
sender.sendMessage(Component.text("This player is not banned.").color(NamedTextColor.RED));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UnmuteCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1){
|
||||
return false;
|
||||
} else {
|
||||
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
String nameArg = args[0];
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(nameArg);
|
||||
} catch (IllegalArgumentException ignored){
|
||||
uuid = PlayerUtil.offlinePlayerUUIDByName(nameArg);
|
||||
}
|
||||
if (uuid == null){
|
||||
sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label)).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
UUID finalUuid = uuid;
|
||||
final Punishment punishment = SModerationPaper.container.find(p -> p.to.equals(finalUuid) && p.isActive() && p.type == PunishmentType.MUTE);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModerationPaper.container);
|
||||
} else {
|
||||
sender.sendMessage(Component.text("This player is not muted.").color(NamedTextColor.RED));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.event.VanishToggleEvent;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class VanishCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("toggle")){
|
||||
Player player = null;
|
||||
if (args.length > 1){
|
||||
player = PlayerUtil.findOnlinePlayer(args[1]);
|
||||
} else if (sender instanceof Player){
|
||||
player = (Player) sender;
|
||||
}
|
||||
if (player != null){
|
||||
toggleVanish(player);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("list")) {
|
||||
if (sender.hasPermission("smod.vanish.see")){
|
||||
listVanishedPlayersTo(sender);
|
||||
} else {
|
||||
sender.sendMessage(text().color(NamedTextColor.RED).content("You do not have permission to list all vanished players."));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
return List.of("list", "toggle");
|
||||
}
|
||||
if (args.length < 3 && args[0].equalsIgnoreCase("toggle")){
|
||||
return PlayerUtil.listPlayerNames(args[1]);
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private static final ObjectArrayList<Player> vanishedPlayers = new ObjectArrayList<>();
|
||||
|
||||
public static void toggleVanish(Player player){
|
||||
final boolean newStatus = !isVanished(player);
|
||||
VanishToggleEvent event = new VanishToggleEvent(player, newStatus);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()){
|
||||
return;
|
||||
}
|
||||
if (newStatus){
|
||||
vanishedPlayers.add(player);
|
||||
for (CommandSender sender : SModerationPaper.container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName()
|
||||
.colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(
|
||||
text()
|
||||
.content(" vanished.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are now vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(false);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.showEntity(PLUGIN, player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vanishedPlayers.remove(player);
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName()
|
||||
.colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(
|
||||
text()
|
||||
.content(" re-appeared.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are no longer vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isVanished(Player player){
|
||||
return vanishedPlayers.contains(player);
|
||||
}
|
||||
|
||||
public static ObjectArrayList<Player> getVanishedPlayers() {
|
||||
return vanishedPlayers.clone();
|
||||
}
|
||||
|
||||
public static void listVanishedPlayersTo(CommandSender receiver){
|
||||
if (vanishedPlayers.isEmpty()){
|
||||
receiver.sendMessage(CHAT_PREFIX.append(
|
||||
text().content("No players are currently vanished.").color(PRIMARY_COLOR)
|
||||
));
|
||||
} else {
|
||||
Component vanishList = CHAT_PREFIX.append(
|
||||
text().content("The following players are currently vanished: ").color(PRIMARY_COLOR)
|
||||
);
|
||||
for (ObjectListIterator<Player> iterator = vanishedPlayers.iterator(); iterator.hasNext(); ) {
|
||||
Player vanishedPlayer = iterator.next();
|
||||
vanishList = vanishList.append(
|
||||
vanishedPlayer.displayName().colorIfAbsent(SECONDARY_COLOR)
|
||||
);
|
||||
if (iterator.hasNext()){
|
||||
vanishList = vanishList.append(
|
||||
text().content(", ").color(PRIMARY_COLOR)
|
||||
);
|
||||
}
|
||||
}
|
||||
receiver.sendMessage(vanishList);
|
||||
}
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.config;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SModerationConfig {
|
||||
|
||||
private final FileConfiguration config;
|
||||
private final SModerationPaper plugin;
|
||||
|
||||
public SModerationConfig(FileConfiguration config, SModerationPaper plugin) {
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public List<String> getSocialSpyCommands(List<String> default_){
|
||||
final String path = "socialspy-commands";
|
||||
if (!config.contains(path)){
|
||||
config.set(path, default_);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
package de.shiewk.smoderation.paper.listener;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.command.VanishCommand;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.SECONDARY_COLOR;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class VanishListener implements Listener {
|
||||
|
||||
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
if (VanishCommand.isVanished(player)){
|
||||
VanishCommand.toggleVanish(player);
|
||||
}
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to clean up visibility status
|
||||
player.hideEntity(SModerationPaper.PLUGIN, vanishedPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event){
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModerationPaper.PLUGIN, () -> {
|
||||
final Player player = event.getPlayer().getPlayer();
|
||||
assert player != null;
|
||||
if (player.hasPermission("smod.vanish.see")){
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to show visible vanished players
|
||||
player.showEntity(SModerationPaper.PLUGIN, vanishedPlayer);
|
||||
}
|
||||
VanishCommand.listVanishedPlayersTo(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerDeath(PlayerDeathEvent event){
|
||||
final Component message = event.deathMessage();
|
||||
if (VanishCommand.isVanished(event.getPlayer()) && message != null){
|
||||
event.deathMessage(null);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.sendMessage(text("[VANISH] ").color(SECONDARY_COLOR).append(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
name: SModeration
|
||||
version: '1.4.2'
|
||||
main: de.shiewk.smoderation.paper.SModerationPaper
|
||||
api-version: '1.20'
|
||||
load: STARTUP
|
||||
authors:
|
||||
- Shiewk
|
||||
description: "SModeration is an easy-to-use minecraft plugin for moderating your server."
|
||||
commands:
|
||||
modlogs:
|
||||
usage: "§cUsage: /modlogs <player|uuid>"
|
||||
aliases:
|
||||
- logs
|
||||
- seen
|
||||
- smodlogs
|
||||
permission: smod.logs
|
||||
mute:
|
||||
usage: "§cUsage: /mute <player> <duration> <reason>"
|
||||
aliases:
|
||||
- smodmute
|
||||
permission: smod.mute
|
||||
description: Mutes a player, either temporarily or permanently.
|
||||
ban:
|
||||
usage: "§cUsage: /ban <player> <duration> <reason>"
|
||||
aliases:
|
||||
- smodban
|
||||
- tempban
|
||||
permission: smod.ban
|
||||
description: Bans a player, either temporarily or permanently.
|
||||
kick:
|
||||
usage: "§cUsage: /kick <player> <reason>"
|
||||
aliases:
|
||||
- smodkick
|
||||
permission: smod.kick
|
||||
description: Kicks a player
|
||||
smod:
|
||||
usage: "§cUsage: /smod"
|
||||
aliases:
|
||||
- smodmenu
|
||||
- smoderation
|
||||
permission: smod.menu
|
||||
description: Shows the SModeration menu.
|
||||
unmute:
|
||||
usage: "§cUsage: /unmute <player|uuid>"
|
||||
aliases:
|
||||
- sunmute
|
||||
permission: smod.unmute
|
||||
description: Unmutes a muted player.
|
||||
unban:
|
||||
usage: "§cUsage: /unban <player|uuid>"
|
||||
aliases:
|
||||
- sunban
|
||||
- pardon
|
||||
- spardon
|
||||
permission: smod.unban
|
||||
description: Unbans a banned player.
|
||||
invsee:
|
||||
usage: "§cUsage: /invsee <player>"
|
||||
aliases:
|
||||
- sinvsee
|
||||
- smodinvsee
|
||||
- invs
|
||||
permission: smod.invsee
|
||||
description: Views the inventory of another player.
|
||||
enderchestsee:
|
||||
usage: "§cUsage: /enderchestsee <player>"
|
||||
aliases:
|
||||
- secsee
|
||||
- senderchestsee
|
||||
- ecsee
|
||||
- ecs
|
||||
permission: smod.enderchestsee
|
||||
description: Views the ender chest of another player.
|
||||
vanish:
|
||||
usage: "§cUsage: /vanish list or /vanish toggle <player>"
|
||||
aliases:
|
||||
- smvanish
|
||||
- smodvanish
|
||||
- v
|
||||
- smv
|
||||
permission: smod.vanish
|
||||
description: Toggles vanish mode which prevents other players from seeing you're online
|
||||
socialspy:
|
||||
usage: "§cUsage: /socialspy"
|
||||
description: Enables socialspy mode (you can see private messages of other players)
|
||||
permission: smod.socialspy
|
||||
aliases:
|
||||
- smodsocialspy
|
||||
- smsocialspy
|
||||
- smss
|
||||
- ss
|
||||
permissions:
|
||||
smod.mute:
|
||||
default: op
|
||||
description: Allows the player to mute other players.
|
||||
smod.ban:
|
||||
default: op
|
||||
description: Allows the player to ban and kick other players.
|
||||
children:
|
||||
- smod.kick
|
||||
smod.kick:
|
||||
default: op
|
||||
description: Allows the player to kick other players.
|
||||
smod.menu:
|
||||
default: op
|
||||
description: Allows the player to use the SModeration menu.
|
||||
smod.notifications:
|
||||
default: op
|
||||
description: Allows the player to be notified when a punishment is issued.
|
||||
smod.unmute:
|
||||
default: op
|
||||
description: Allows the player to unmute other players.
|
||||
smod.unban:
|
||||
default: op
|
||||
description: Allows the player to unban other players.
|
||||
smod.logs:
|
||||
default: op
|
||||
description: Allows the player to view mod logs.
|
||||
smod.invsee:
|
||||
default: op
|
||||
description: Allows the player to view other players inventories.
|
||||
smod.invsee.modify:
|
||||
default: op
|
||||
description: Allows the player to view and modify other players inventories.
|
||||
children:
|
||||
- smod.invsee
|
||||
smod.invsee.preventmodify:
|
||||
default: op
|
||||
description: When giving this permission to a player, prevents their inventory from being modified.
|
||||
smod.enderchestsee:
|
||||
default: op
|
||||
description: Allows the player to view other players ender chests.
|
||||
smod.enderchestsee.modify:
|
||||
default: op
|
||||
description: Allows the player to view and modify other players ender chests.
|
||||
children:
|
||||
- smod.enderchestsee
|
||||
smod.preventmute:
|
||||
default: op
|
||||
description: Prevents the player from being muted (if online)
|
||||
smod.preventkick:
|
||||
default: op
|
||||
description: Prevents the player from being muted (if online)
|
||||
smod.preventban:
|
||||
default: op
|
||||
description: Prevents the player from being muted (if online)
|
||||
smod.vanish:
|
||||
default: op
|
||||
description: Allows the player to use /vanish
|
||||
smod.vanish.see:
|
||||
default: op
|
||||
description: Allows the player to see vanished players
|
||||
smod.socialspy:
|
||||
default: op
|
||||
description: Allows the player to enable SocialSpy
|
||||
+34
-22
@@ -5,13 +5,13 @@ import de.shiewk.smoderation.paper.config.SModerationConfig;
|
||||
import de.shiewk.smoderation.paper.input.ChatInputListener;
|
||||
import de.shiewk.smoderation.paper.listener.*;
|
||||
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -29,11 +29,11 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
public static SModerationPaper PLUGIN = null;
|
||||
public static SModerationConfig CONFIG = 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 TextColor FAIL_COLOR = NamedTextColor.RED;
|
||||
public static final TextComponent CHAT_PREFIX = text("SM \u00BB ").color(PRIMARY_COLOR);
|
||||
|
||||
@Override
|
||||
@@ -46,6 +46,8 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
CONFIG.reload();
|
||||
|
||||
getPluginManager().registerEvents(new PunishmentListener(), this);
|
||||
getPluginManager().registerEvents(new CustomInventoryListener(), this);
|
||||
getPluginManager().registerEvents(new InvSeeListener(), this);
|
||||
@@ -54,29 +56,31 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
getPluginManager().registerEvents(new ChatInputListener(), this);
|
||||
getPluginManager().registerEvents(new SocialSpyListener(), this);
|
||||
|
||||
registerCommand("mute", new MuteCommand());
|
||||
registerCommand("ban", new BanCommand());
|
||||
registerCommand("kick", new KickCommand());
|
||||
registerCommand("smod", new SModCommand());
|
||||
registerCommand("modlogs", new ModLogsCommand());
|
||||
registerCommand("unmute", new UnmuteCommand());
|
||||
registerCommand("unban", new UnbanCommand());
|
||||
registerCommand("invsee", new InvseeCommand());
|
||||
registerCommand("enderchestsee", new EnderchestSeeCommand());
|
||||
registerCommand("vanish", new VanishCommand());
|
||||
registerCommand("socialspy", new SocialSpyCommand());
|
||||
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
|
||||
Commands commands = event.registrar();
|
||||
|
||||
registerCommand(commands, new KickCommand());
|
||||
registerCommand(commands, new ModLogsCommand());
|
||||
registerCommand(commands, new SModCommand());
|
||||
registerCommand(commands, new InvseeCommand());
|
||||
registerCommand(commands, new EnderchestSeeCommand());
|
||||
registerCommand(commands, new SocialSpyCommand());
|
||||
registerCommand(commands, new VanishCommand());
|
||||
registerCommand(commands, new UnmuteCommand());
|
||||
registerCommand(commands, new UnbanCommand());
|
||||
registerCommand(commands, new MuteCommand());
|
||||
registerCommand(commands, new BanCommand());
|
||||
});
|
||||
|
||||
container.load(SAVE_FILE);
|
||||
}
|
||||
|
||||
private void registerCommand(String label, TabExecutor executor){
|
||||
final PluginCommand command = getCommand(label);
|
||||
if (command != null) {
|
||||
command.setExecutor(executor);
|
||||
command.setTabCompleter(executor);
|
||||
} else {
|
||||
LOGGER.warn("Command %s failed to register: This command does not exist".formatted(label));
|
||||
}
|
||||
private void registerCommand(Commands commands, CommandProvider provider){
|
||||
commands.register(
|
||||
provider.getCommandNode(),
|
||||
provider.getCommandDescription(),
|
||||
provider.getAliases()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,4 +93,12 @@ public final class SModerationPaper extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static SkinTextureProvider getTextureProvider() {
|
||||
return textureProvider;
|
||||
}
|
||||
|
||||
public static void setTextureProvider(SkinTextureProvider textureProvider) {
|
||||
SModerationPaper.textureProvider = textureProvider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package de.shiewk.smoderation.paper;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface SkinTextureProvider {
|
||||
|
||||
CompletableFuture<String> textureProperty(UUID player);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
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.DurationArgument;
|
||||
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class BanCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("ban")
|
||||
.requires(CommandUtil.requirePermission("smod.ban"))
|
||||
.then(argument("player", new PlayerUUIDArgument())
|
||||
.then(argument("duration", new DurationArgument())
|
||||
.executes(this::banWithoutReason)
|
||||
.then(argument("reason", StringArgumentType.greedyString())
|
||||
.executes(this::banWithReason)
|
||||
)
|
||||
)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int banWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
if (SModerationPaper.CONFIG.shouldForceReason()){
|
||||
CommandUtil.error("Please provide a reason.");
|
||||
}
|
||||
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);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private int banWithReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||
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);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static void executeBan(UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
|
||||
Player targetPlayer = Bukkit.getPlayer(target);
|
||||
if (duration == 0){
|
||||
if (targetPlayer == null){
|
||||
CommandUtil.error("You can't ban an offline player for less than 1ms.");
|
||||
} else {
|
||||
KickCommand.executeKick(sender, targetPlayer, reason);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sender.equals(target)) {
|
||||
CommandUtil.error("You can't ban yourself.");
|
||||
} else {
|
||||
if (targetPlayer != null && targetPlayer.hasPermission("smod.preventban")){
|
||||
CommandUtil.error("This player can't be banned.");
|
||||
} else {
|
||||
final Punishment punishment = Punishment.ban(
|
||||
System.currentTimeMillis(),
|
||||
System.currentTimeMillis() + duration,
|
||||
sender,
|
||||
target,
|
||||
reason
|
||||
);
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Bans a player for a customizable duration.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodban");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface CommandProvider {
|
||||
|
||||
LiteralCommandNode<CommandSourceStack> getCommandNode();
|
||||
|
||||
String getCommandDescription();
|
||||
|
||||
default Collection<String> getAliases(){
|
||||
return List.of();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
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.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class EnderchestSeeCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("enderchestsee")
|
||||
.requires(CommandUtil.requirePermission("smod.enderchestsee"))
|
||||
.then(argument("player", ArgumentTypes.player())
|
||||
.executes(this::openEnderChest)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int openEnderChest(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
|
||||
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
|
||||
.append(target.teamDisplayName().colorIfAbsent(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
));
|
||||
sender.openInventory(target.getEnderChest());
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Views the ender chest of a player.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("ecsee");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
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.inventory.InvSeeEquipmentInventory;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
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;
|
||||
|
||||
public final class InvseeCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("invsee")
|
||||
.requires(CommandUtil.requirePermission("smod.invsee"))
|
||||
.then(argument("player", ArgumentTypes.player())
|
||||
.executes(this::invseeInventory)
|
||||
.then(literal("inventory")
|
||||
.executes(this::invseeInventory)
|
||||
)
|
||||
.then(literal("armor")
|
||||
.executes(this::invseeEquipment)
|
||||
)
|
||||
.then(literal("equipment")
|
||||
.executes(this::invseeEquipment)
|
||||
)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int invseeInventory(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
|
||||
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||
if (sender.equals(target)){
|
||||
CommandUtil.error("You can't open your own inventory.");
|
||||
}
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
text("Opening inventory of ").color(PRIMARY_COLOR)
|
||||
.append(target.teamDisplayName().colorIfAbsent(SECONDARY_COLOR))
|
||||
.append(text("."))
|
||||
));
|
||||
sender.openInventory(target.getInventory());
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private int invseeEquipment(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
|
||||
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||
if (sender.equals(target)){
|
||||
CommandUtil.error("You can't open your own inventory.");
|
||||
}
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
text("Opening inventory of ").color(PRIMARY_COLOR)
|
||||
.append(target.teamDisplayName().colorIfAbsent(SECONDARY_COLOR))
|
||||
.append(text("."))
|
||||
));
|
||||
new InvSeeEquipmentInventory(sender, target).open();
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Views the inventory of another player.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("sinvsee", "smodinvsee", "invs");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
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.Punishment;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class KickCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("kick")
|
||||
.requires(CommandUtil.requirePermission("smod.kick"))
|
||||
.then(argument("player", ArgumentTypes.player())
|
||||
.executes(this::kickWithoutReason)
|
||||
.then(argument("reason", StringArgumentType.greedyString())
|
||||
.executes(this::kickWithReason)
|
||||
)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int kickWithReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||
String reason = StringArgumentType.getString(context, "reason");
|
||||
executeKick(sender, target, reason);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private int kickWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
if (SModerationPaper.CONFIG.shouldForceReason()){
|
||||
CommandUtil.error("Please provide a reason.");
|
||||
}
|
||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||
Player target = CommandUtil.getPlayerSingle(context, "player");
|
||||
executeKick(sender, target, Punishment.DEFAULT_REASON);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static void executeKick(UUID sender, Player target, String reason) throws CommandSyntaxException {
|
||||
UUID targetId = target.getUniqueId();
|
||||
if (sender.equals(targetId)) {
|
||||
CommandUtil.error("You can't kick yourself.");
|
||||
} else if (target.hasPermission("smod.preventkick")){
|
||||
CommandUtil.error("This player can't be kicked.");
|
||||
}
|
||||
final Punishment punishment = Punishment.kick(
|
||||
System.currentTimeMillis(),
|
||||
sender,
|
||||
targetId,
|
||||
reason
|
||||
);
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Kicks a player";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodkick");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
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.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import de.shiewk.smoderation.paper.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.paper.util.TimeUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class ModLogsCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("modlogs")
|
||||
.requires(CommandUtil.requirePermission("smod.logs"))
|
||||
.then(argument("player", new PlayerUUIDArgument())
|
||||
.executes(this::showModLogs)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int showModLogs(CommandContext<CommandSourceStack> context) {
|
||||
CommandSender sender = context.getSource().getSender();
|
||||
UUID uuid = context.getArgument("player", UUID.class);
|
||||
String name = PlayerUtil.offlinePlayerName(uuid);
|
||||
sender.sendMessage(CHAT_PREFIX.append(Component.text("Player ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(name).color(SECONDARY_COLOR))
|
||||
.append(Component.text(" (%s)".formatted(uuid)).color(INACTIVE_COLOR))));
|
||||
final List<Punishment> punishments = SModerationPaper.container.findAll(p -> p.to.equals(uuid) && p.isActive());
|
||||
for (Punishment punishment : punishments) {
|
||||
sender.sendMessage(Component.text("- is currently ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(punishment.type == PunishmentType.BAN ? "banned" : "muted").color(SECONDARY_COLOR))
|
||||
.append(Component.text(" until ").color(PRIMARY_COLOR))
|
||||
.append(Component.text(TimeUtil.calendarTimestamp(punishment.until)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(" (in %s)".formatted(TimeUtil.formatTimeLong(punishment.until - System.currentTimeMillis()))).color(INACTIVE_COLOR))
|
||||
.append(Component.text(". Reason: ").color(PRIMARY_COLOR))
|
||||
.append(Component.text(punishment.reason).color(SECONDARY_COLOR)));
|
||||
}
|
||||
if (punishments.isEmpty()){
|
||||
sender.sendMessage(Component.text("- has no punishments.").color(PRIMARY_COLOR));
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Views all current punishments of a player.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("logs", "seen", "smodlogs");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
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.DurationArgument;
|
||||
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
|
||||
import de.shiewk.smoderation.paper.punishments.Punishment;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class MuteCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("mute")
|
||||
.requires(CommandUtil.requirePermission("smod.mute"))
|
||||
.then(argument("player", new PlayerUUIDArgument())
|
||||
.then(argument("duration", new DurationArgument())
|
||||
.executes(this::muteWithoutReason)
|
||||
.then(argument("reason", StringArgumentType.greedyString())
|
||||
.executes(this::muteWithReason)
|
||||
)
|
||||
)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int muteWithoutReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
if (SModerationPaper.CONFIG.shouldForceReason()){
|
||||
CommandUtil.error("Please provide a reason.");
|
||||
}
|
||||
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);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private int muteWithReason(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
UUID sender = CommandUtil.getSenderUUID(context.getSource());
|
||||
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);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static void executeMute(UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
|
||||
if (sender.equals(target)) {
|
||||
CommandUtil.error("You can't mute yourself.");
|
||||
} else {
|
||||
Player targetPlayer = Bukkit.getPlayer(target);
|
||||
if (targetPlayer != null && targetPlayer.hasPermission("smod.preventmute")){
|
||||
CommandUtil.error("This player can't be muted.");
|
||||
} else {
|
||||
final Punishment punishment = Punishment.mute(
|
||||
System.currentTimeMillis(),
|
||||
System.currentTimeMillis() + duration,
|
||||
sender,
|
||||
target,
|
||||
reason
|
||||
);
|
||||
Punishment.issue(punishment, SModerationPaper.container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Mutes a player for a customizable duration.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodmute");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
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.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class SModCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("smod")
|
||||
.requires(CommandUtil.requirePermission("smod.menu"))
|
||||
.executes(this::openMenu)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int openMenu(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
Player player = CommandUtil.getExecutingPlayer(context.getSource());
|
||||
new SModMenu(player, SModerationPaper.container).open();
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Shows the SModeration menu.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodmenu", "smoderation");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.listener.SocialSpyListener;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.CHAT_PREFIX;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public final class SocialSpyCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("socialspy")
|
||||
.requires(CommandUtil.requirePermission("smod.socialspy"))
|
||||
.executes(this::toggleSocialSpy)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int toggleSocialSpy(CommandContext<CommandSourceStack> context) {
|
||||
CommandSender sender = context.getSource().getSender();
|
||||
final boolean enabled = SocialSpyListener.toggle(sender);
|
||||
sender.sendMessage(CHAT_PREFIX.append(text("SocialSpy ").append(
|
||||
enabled ?
|
||||
text("enabled").color(NamedTextColor.GREEN) :
|
||||
text("disabled").color(NamedTextColor.RED)
|
||||
).append(text("."))));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Enables socialspy mode (you can see private messages of other players)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodsocialspy");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.shiewk.smoderation.paper.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.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class UnbanCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("unban")
|
||||
.requires(CommandUtil.requirePermission("smod.unban"))
|
||||
.then(argument("player", new PlayerUUIDArgument())
|
||||
.executes(this::unbanPlayer)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModerationPaper.container);
|
||||
} else {
|
||||
CommandUtil.error("This player is not banned.");
|
||||
}
|
||||
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Unbans a banned player.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodunban");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
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.Punishment;
|
||||
import de.shiewk.smoderation.paper.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.papermc.paper.command.brigadier.Commands.argument;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class UnmuteCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("unmute")
|
||||
.requires(CommandUtil.requirePermission("smod.unmute"))
|
||||
.then(argument("player", new PlayerUUIDArgument())
|
||||
.executes(this::unmutePlayer)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModerationPaper.container);
|
||||
} else {
|
||||
CommandUtil.error("This player is not muted.");
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Unmutes a muted player.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodunmute");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
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.event.VanishToggleEvent;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.*;
|
||||
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;
|
||||
|
||||
public final class VanishCommand implements CommandProvider {
|
||||
|
||||
public static final NamespacedKey KEY_VANISHED = new NamespacedKey("smoderation", "vanished");
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("vanish")
|
||||
.requires(CommandUtil.requirePermission("smod.vanish"))
|
||||
.executes(this::toggleVanishSelf)
|
||||
.then(literal("toggle")
|
||||
.executes(this::toggleVanishSelf)
|
||||
.then(argument("targets", ArgumentTypes.players())
|
||||
.executes(this::toggleVanishForTargets)
|
||||
)
|
||||
)
|
||||
.then(literal("list")
|
||||
.requires(CommandUtil.requirePermission("smod.vanish.see"))
|
||||
.executes(this::listVanishedPlayers)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int toggleVanishForTargets(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
List<Player> targets = context.getArgument("targets", PlayerSelectorArgumentResolver.class).resolve(context.getSource());
|
||||
if (targets.isEmpty()){
|
||||
CommandUtil.error("No player was found.");
|
||||
} else {
|
||||
for (Player target : targets) {
|
||||
toggleVanish(target);
|
||||
}
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private int toggleVanishSelf(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
toggleVanish(CommandUtil.getExecutingPlayer(context.getSource()));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private int listVanishedPlayers(CommandContext<CommandSourceStack> context) {
|
||||
listVanishedPlayersTo(context.getSource().getSender());
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandDescription() {
|
||||
return "Toggles vanish mode which prevents other players from seeing you're online";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smvanish", "smodvanish", "v", "smv");
|
||||
}
|
||||
|
||||
private static final ObjectArrayList<Player> vanishedPlayers = new ObjectArrayList<>(1);
|
||||
|
||||
public static void toggleVanish(Player player){
|
||||
final boolean newStatus = !isVanished(player);
|
||||
VanishToggleEvent event = new VanishToggleEvent(player, newStatus);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()){
|
||||
return;
|
||||
}
|
||||
if (newStatus){
|
||||
vanishedPlayers.add(player);
|
||||
for (CommandSender sender : SModerationPaper.container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName().colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(text()
|
||||
.content(" vanished.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are now vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(false);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.showEntity(PLUGIN, player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vanishedPlayers.remove(player);
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName().colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(text()
|
||||
.content(" re-appeared.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are no longer vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean toggleVanishSilent(Player player, boolean force){
|
||||
final boolean newStatus = !isVanished(player);
|
||||
VanishToggleEvent event = new VanishToggleEvent(player, newStatus);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled() && !force){
|
||||
return false;
|
||||
}
|
||||
if (newStatus){
|
||||
vanishedPlayers.add(player);
|
||||
player.setVisibleByDefault(false);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.showEntity(PLUGIN, player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vanishedPlayers.remove(player);
|
||||
player.setVisibleByDefault(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isVanished(Player player){
|
||||
return vanishedPlayers.contains(player);
|
||||
}
|
||||
|
||||
public static ObjectArrayList<Player> getVanishedPlayers() {
|
||||
return vanishedPlayers.clone();
|
||||
}
|
||||
|
||||
public static void listVanishedPlayersTo(CommandSender receiver){
|
||||
if (vanishedPlayers.isEmpty()){
|
||||
receiver.sendMessage(CHAT_PREFIX.append(
|
||||
text().content("No players are currently vanished.").color(PRIMARY_COLOR)
|
||||
));
|
||||
} else {
|
||||
Component vanishList = CHAT_PREFIX.append(
|
||||
text().content("The following players are currently vanished: ").color(PRIMARY_COLOR)
|
||||
);
|
||||
for (ObjectListIterator<Player> iterator = vanishedPlayers.iterator(); iterator.hasNext(); ) {
|
||||
Player vanishedPlayer = iterator.next();
|
||||
vanishList = vanishList.append(
|
||||
vanishedPlayer.displayName().colorIfAbsent(SECONDARY_COLOR)
|
||||
);
|
||||
if (iterator.hasNext()){
|
||||
vanishList = vanishList.append(
|
||||
text().content(", ").color(PRIMARY_COLOR)
|
||||
);
|
||||
}
|
||||
}
|
||||
receiver.sendMessage(vanishList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package de.shiewk.smoderation.paper.command.argument;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.regex.MatchResult;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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))+");
|
||||
|
||||
@Override
|
||||
public @NotNull Long convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||
if (!VALIDATION_PATTERN.matcher(nativeType).matches()){
|
||||
CommandUtil.error("Please provide a valid duration, e.g. '1d6h30min'");
|
||||
}
|
||||
AtomicLong totalDuration = new AtomicLong();
|
||||
for (MatchResult result : DURATION_PATTERN.matcher(nativeType).results().toList()) {
|
||||
long amount = Long.parseLong(result.group(1));
|
||||
long timeSpan = switch (result.group(2)) {
|
||||
case "ms" -> 1;
|
||||
case "s" -> 1000;
|
||||
case "min" -> 60_000;
|
||||
case "h" -> 3600_000;
|
||||
case "d" -> 86400_000;
|
||||
case "w" -> 604800_000;
|
||||
case "mo" -> 2_592_000_000L;
|
||||
case "y" -> 31_536_000_000L;
|
||||
default -> {
|
||||
CommandUtil.error("Invalid time span '%s'".formatted(result.group(2)));
|
||||
throw new UnknownError(); // can't happen
|
||||
}
|
||||
};
|
||||
totalDuration.addAndGet(amount*timeSpan);
|
||||
}
|
||||
return totalDuration.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArgumentType<String> getNativeType() {
|
||||
return StringArgumentType.word();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <S> CompletableFuture<Suggestions> listSuggestions(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
|
||||
if (builder.getRemaining().isBlank()){
|
||||
List.of(
|
||||
"100ms",
|
||||
"15s",
|
||||
"2min",
|
||||
"3h",
|
||||
"7d",
|
||||
"1w",
|
||||
"3mo",
|
||||
"1y",
|
||||
"1mo15d",
|
||||
"2h30min"
|
||||
).forEach(builder::suggest);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package de.shiewk.smoderation.paper.command.argument;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class PlayerUUIDArgument implements CustomArgumentType.Converted<UUID, String> {
|
||||
|
||||
@Override
|
||||
public @NotNull UUID convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||
try {
|
||||
return UUID.fromString(nativeType);
|
||||
} catch (IllegalArgumentException e) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayerIfCached(nativeType);
|
||||
if (player != null){
|
||||
return player.getUniqueId();
|
||||
} else {
|
||||
CommandUtil.error("This player is not cached. Try providing an UUID instead.");
|
||||
throw new UnknownError(); // can't happen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ArgumentType<String> getNativeType() {
|
||||
return StringArgumentType.word();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <S> CompletableFuture<Suggestions> listSuggestions(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.map(Player::getName)
|
||||
.filter(name -> name.toLowerCase().startsWith(builder.getRemainingLowerCase()))
|
||||
.forEach(builder::suggest);
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package de.shiewk.smoderation.paper.config;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SModerationConfig {
|
||||
|
||||
private final FileConfiguration config;
|
||||
private final SModerationPaper plugin;
|
||||
|
||||
public SModerationConfig(FileConfiguration config, SModerationPaper plugin) {
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private List<String> socialSpyCommands = List.of(
|
||||
"w",
|
||||
"tell",
|
||||
"msg",
|
||||
"teammsg",
|
||||
"tm",
|
||||
"minecraft:w",
|
||||
"minecraft:tell",
|
||||
"minecraft:msg",
|
||||
"minecraft:teammsg",
|
||||
"minecraft:tm"
|
||||
);
|
||||
private boolean forceReason = false;
|
||||
|
||||
public void reload(){
|
||||
socialSpyCommands = loadOrSetStringList("socialspy-commands", socialSpyCommands);
|
||||
forceReason = loadOrSetBoolean("force-reason", forceReason);
|
||||
}
|
||||
|
||||
private List<String> loadOrSetStringList(String path, List<String> defaultValue) {
|
||||
if (!config.contains(path)){
|
||||
config.set(path, defaultValue);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
private boolean loadOrSetBoolean(String path, boolean defaultValue) {
|
||||
if (!config.contains(path)){
|
||||
config.set(path, defaultValue);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
public List<String> getSocialSpyCommands(){
|
||||
return socialSpyCommands;
|
||||
}
|
||||
|
||||
public boolean shouldForceReason(){
|
||||
return forceReason;
|
||||
}
|
||||
}
|
||||
+45
-5
@@ -1,5 +1,8 @@
|
||||
package de.shiewk.smoderation.paper.inventory;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||
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;
|
||||
@@ -28,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -269,7 +273,26 @@ public class SModMenu extends PageableCustomInventory {
|
||||
return searchStack = stack;
|
||||
}
|
||||
|
||||
private ItemStack createPunishmentItem(Punishment punishment){
|
||||
private CompletableFuture<ItemStack> createPunishmentItem(Punishment punishment){
|
||||
SkinTextureProvider provider = getTextureProvider();
|
||||
if (provider != null) {
|
||||
return provider.textureProperty(punishment.to)
|
||||
.thenApply(texture -> {
|
||||
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
||||
stack.editMeta(meta -> {
|
||||
if (meta instanceof SkullMeta skullMeta){
|
||||
PlayerProfile profile = Bukkit.createProfile(punishment.to);
|
||||
profile.setProperty(new ProfileProperty(
|
||||
"textures",
|
||||
texture
|
||||
));
|
||||
skullMeta.setPlayerProfile(profile);
|
||||
}
|
||||
addPunishmentInfo(punishment, meta);
|
||||
});
|
||||
return stack;
|
||||
});
|
||||
} else {
|
||||
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
||||
stack.editMeta(meta -> {
|
||||
if (meta instanceof SkullMeta skullMeta){
|
||||
@@ -279,6 +302,13 @@ public class SModMenu extends PageableCustomInventory {
|
||||
LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.to);
|
||||
}
|
||||
}
|
||||
addPunishmentInfo(punishment, meta);
|
||||
});
|
||||
return CompletableFuture.completedFuture(stack);
|
||||
}
|
||||
}
|
||||
|
||||
private void addPunishmentInfo(Punishment punishment, ItemMeta meta) {
|
||||
meta.displayName(applyFormatting(text(punishment.type.name).color(NamedTextColor.RED).decorate(TextDecoration.BOLD)));
|
||||
ArrayList<Component> lore = new ArrayList<>();
|
||||
lore.add(applyFormatting(text("Player: ").color(SECONDARY_COLOR).append(text(PlayerUtil.offlinePlayerName(punishment.to)).color(PRIMARY_COLOR))));
|
||||
@@ -306,12 +336,16 @@ public class SModMenu extends PageableCustomInventory {
|
||||
}
|
||||
}
|
||||
meta.lore(lore);
|
||||
});
|
||||
return stack;
|
||||
}
|
||||
|
||||
private int rfId = 0;
|
||||
@Override
|
||||
public void refresh() {
|
||||
int rfId = ++this.rfId;
|
||||
while (getPage() > lastPage()){
|
||||
previousPage();
|
||||
}
|
||||
inventory.clear();
|
||||
for (int i = 45; i < 54; i++) {
|
||||
inventory.setItem(i, createEmptyStack());
|
||||
}
|
||||
@@ -326,13 +360,19 @@ public class SModMenu extends PageableCustomInventory {
|
||||
int ci = i + (getPage() * 45);
|
||||
if (punishments.size() > ci){
|
||||
final Punishment punishment = punishments.get(ci);
|
||||
final ItemStack item = createPunishmentItem(punishment);
|
||||
int slot = i;
|
||||
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(i, item);
|
||||
inventory.setItem(slot, item);
|
||||
}).exceptionally(x -> {
|
||||
LOGGER.warn("Error creating punishment item", x);
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
inventory.setItem(i, new ItemStack(Material.AIR));
|
||||
}
|
||||
+2
-15
@@ -22,19 +22,6 @@ import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class SocialSpyListener implements Listener {
|
||||
|
||||
private static final List<String> defaultCommands = List.of(
|
||||
"w",
|
||||
"tell",
|
||||
"msg",
|
||||
"teammsg",
|
||||
"tm",
|
||||
"minecraft:w",
|
||||
"minecraft:tell",
|
||||
"minecraft:msg",
|
||||
"minecraft:teammsg",
|
||||
"minecraft:tm"
|
||||
);
|
||||
|
||||
private static final NamespacedKey SAVE_KEY = new NamespacedKey("smoderation", "socialspy");
|
||||
private static final ObjectArrayList<CommandSender> targets = new ObjectArrayList<>();
|
||||
|
||||
@@ -72,9 +59,9 @@ public class SocialSpyListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
public void onPlayerSendCommand(PlayerCommandPreprocessEvent event){
|
||||
List<String> ssCommands = SModerationPaper.CONFIG.getSocialSpyCommands(defaultCommands);
|
||||
List<String> socialSpyCommands = SModerationPaper.CONFIG.getSocialSpyCommands();
|
||||
final String message = event.getMessage();
|
||||
if (ssCommands.stream().anyMatch(str ->
|
||||
if (socialSpyCommands.stream().anyMatch(str ->
|
||||
message.startsWith("/"+str+" ")
|
||||
|| message.startsWith(str+" ")
|
||||
)){
|
||||
@@ -0,0 +1,102 @@
|
||||
package de.shiewk.smoderation.paper.listener;
|
||||
|
||||
import de.shiewk.smoderation.paper.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.command.VanishCommand;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
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;
|
||||
|
||||
public class VanishListener implements Listener {
|
||||
|
||||
public static final Component PREFIX = text("[VANISH] ").color(SECONDARY_COLOR);
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onPlayerQuit(PlayerQuitEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
if (VanishCommand.isVanished(player)){
|
||||
player.getPersistentDataContainer().set(VanishCommand.KEY_VANISHED, PersistentDataType.BOOLEAN, true);
|
||||
VanishCommand.toggleVanishSilent(player, true);
|
||||
Component message = event.quitMessage();
|
||||
event.quitMessage(null);
|
||||
if (message != null){
|
||||
broadcast(message.color(null));
|
||||
}
|
||||
} else {
|
||||
player.getPersistentDataContainer().remove(VanishCommand.KEY_VANISHED);
|
||||
}
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to clean up visibility status
|
||||
player.hideEntity(SModerationPaper.PLUGIN, vanishedPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
if (player.getPersistentDataContainer().has(VanishCommand.KEY_VANISHED)){
|
||||
boolean state = VanishCommand.toggleVanishSilent(player, false);
|
||||
if (state){
|
||||
Component message = event.joinMessage();
|
||||
event.joinMessage(null);
|
||||
if (message != null){
|
||||
broadcast(message.color(null));
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModerationPaper.PLUGIN, () -> {
|
||||
player.sendMessage(SModerationPaper.CHAT_PREFIX
|
||||
.decorate(TextDecoration.BOLD)
|
||||
.append(
|
||||
text("You are still vanished!")
|
||||
));
|
||||
player.playSound(Sound.sound(
|
||||
Key.key("minecraft", "block.beacon.power_select"),
|
||||
Sound.Source.MASTER,
|
||||
1f,
|
||||
1f
|
||||
), player);
|
||||
}, 20);
|
||||
} else {
|
||||
player.getPersistentDataContainer().remove(VanishCommand.KEY_VANISHED);
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModerationPaper.PLUGIN, () -> {
|
||||
if (player.hasPermission("smod.vanish.see")){
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to show visible vanished players
|
||||
player.showEntity(SModerationPaper.PLUGIN, vanishedPlayer);
|
||||
}
|
||||
VanishCommand.listVanishedPlayersTo(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerDeath(PlayerDeathEvent event){
|
||||
final Component message = event.deathMessage();
|
||||
if (VanishCommand.isVanished(event.getPlayer()) && message != null){
|
||||
event.deathMessage(null);
|
||||
broadcast(message);
|
||||
}
|
||||
}
|
||||
|
||||
private static void broadcast(Component message) {
|
||||
Component result = PREFIX.append(message);
|
||||
SModerationPaper.LOGGER.info(result);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.sendMessage(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package de.shiewk.smoderation.paper.util;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static de.shiewk.smoderation.paper.util.PlayerUtil.UUID_CONSOLE;
|
||||
|
||||
public abstract class CommandUtil {
|
||||
private CommandUtil(){}
|
||||
|
||||
public static Predicate<CommandSourceStack> requirePermission(String permission) {
|
||||
return stack -> stack.getSender().hasPermission(permission);
|
||||
}
|
||||
|
||||
public static Player getExecutingPlayer(CommandSourceStack stack) throws CommandSyntaxException {
|
||||
CommandSender sender = stack.getSender();
|
||||
if (sender instanceof Player player) {
|
||||
return player;
|
||||
} else {
|
||||
error("Only players can execute this command.");
|
||||
throw new UnknownError(); // can't happen
|
||||
}
|
||||
}
|
||||
|
||||
public static UUID getSenderUUID(CommandSourceStack stack) throws CommandSyntaxException {
|
||||
CommandSender sender = stack.getSender();
|
||||
if (sender instanceof Player player) {
|
||||
return player.getUniqueId();
|
||||
} else if (sender instanceof ConsoleCommandSender){
|
||||
return UUID_CONSOLE;
|
||||
} else {
|
||||
error("Only players and the console can execute this command.");
|
||||
throw new UnknownError(); // can't happen
|
||||
}
|
||||
}
|
||||
|
||||
public static Player getPlayerSingle(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
|
||||
@NotNull List<Player> players = context.getArgument(name, PlayerSelectorArgumentResolver.class).resolve(context.getSource());
|
||||
if (players.isEmpty()){
|
||||
CommandUtil.error("Please provide a valid player.");
|
||||
}
|
||||
return players.getFirst();
|
||||
}
|
||||
|
||||
public static void error(String message) throws CommandSyntaxException {
|
||||
throw new CommandSyntaxException(
|
||||
new SimpleCommandExceptionType(null),
|
||||
MessageComponentSerializer.message().serialize(
|
||||
Component.text(message)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
name: SModeration
|
||||
version: '${version}'
|
||||
main: de.shiewk.smoderation.paper.SModerationPaper
|
||||
api-version: '1.21'
|
||||
load: STARTUP
|
||||
authors:
|
||||
- Shiewk
|
||||
description: "SModeration is an easy-to-use minecraft plugin for moderating your server."
|
||||
permissions:
|
||||
smod.mute:
|
||||
default: op
|
||||
description: Allows the player to mute other players.
|
||||
smod.ban:
|
||||
default: op
|
||||
description: Allows the player to ban and kick other players.
|
||||
children:
|
||||
- smod.kick
|
||||
smod.kick:
|
||||
default: op
|
||||
description: Allows the player to kick other players.
|
||||
smod.menu:
|
||||
default: op
|
||||
description: Allows the player to use the SModeration menu.
|
||||
smod.notifications:
|
||||
default: op
|
||||
description: Allows the player to be notified when a punishment is issued.
|
||||
smod.unmute:
|
||||
default: op
|
||||
description: Allows the player to unmute other players.
|
||||
smod.unban:
|
||||
default: op
|
||||
description: Allows the player to unban other players.
|
||||
smod.logs:
|
||||
default: op
|
||||
description: Allows the player to view mod logs.
|
||||
smod.invsee:
|
||||
default: op
|
||||
description: Allows the player to view other players inventories.
|
||||
smod.invsee.modify:
|
||||
default: op
|
||||
description: Allows the player to view and modify other players inventories.
|
||||
children:
|
||||
- smod.invsee
|
||||
smod.invsee.preventmodify:
|
||||
default: op
|
||||
description: When giving this permission to a player, prevents their inventory from being modified.
|
||||
smod.enderchestsee:
|
||||
default: op
|
||||
description: Allows the player to view other players ender chests.
|
||||
smod.enderchestsee.modify:
|
||||
default: op
|
||||
description: Allows the player to view and modify other players ender chests.
|
||||
children:
|
||||
- smod.enderchestsee
|
||||
smod.preventmute:
|
||||
default: op
|
||||
description: Prevents the player from being muted (if online)
|
||||
smod.preventkick:
|
||||
default: op
|
||||
description: Prevents the player from being kicked (if online)
|
||||
smod.preventban:
|
||||
default: op
|
||||
description: Prevents the player from being banned (if online)
|
||||
smod.vanish:
|
||||
default: op
|
||||
description: Allows the player to use /vanish
|
||||
smod.vanish.see:
|
||||
default: op
|
||||
description: Allows the player to see vanished players
|
||||
smod.socialspy:
|
||||
default: op
|
||||
description: Allows the player to enable SocialSpy
|
||||
Reference in New Issue
Block a user