mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
broadcast punishment to admins when issued
This commit is contained in:
@@ -15,6 +15,9 @@ import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Punishment {
|
||||
|
||||
public static final NamedTextColor PRIMARY_COLOR = NamedTextColor.RED;
|
||||
public static final NamedTextColor SECONDARY_COLOR = NamedTextColor.GOLD;
|
||||
public final PunishmentType type;
|
||||
public final long time;
|
||||
public final long until;
|
||||
@@ -92,11 +95,48 @@ public class Punishment {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()){
|
||||
container.add(punishment);
|
||||
punishment.firstIssue();
|
||||
punishment.firstIssue(container);
|
||||
}
|
||||
}
|
||||
|
||||
private void firstIssue(){
|
||||
private Component broadcastMessage(){
|
||||
final String toName = PlayerUtil.offlinePlayerName(to);
|
||||
switch (type) {
|
||||
case MUTE -> {
|
||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
||||
Component.text(" has been muted by ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(" for "))
|
||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - this.time)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(".")));
|
||||
}
|
||||
case KICK -> {
|
||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
||||
Component.text(" has been kicked by ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
.color(PRIMARY_COLOR));
|
||||
}
|
||||
case BAN -> {
|
||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
||||
Component.text(" has been kicked by ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(" for "))
|
||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - this.time)).color(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
.color(PRIMARY_COLOR));
|
||||
}
|
||||
default -> throw new IllegalStateException("Unknown punishment type " + type);
|
||||
}
|
||||
}
|
||||
|
||||
private void broadcastIssue(PunishmentContainer container){
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(broadcastMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void firstIssue(PunishmentContainer container){
|
||||
switch (type) {
|
||||
case MUTE, BAN -> {
|
||||
final CommandSender sender = PlayerUtil.senderByUUID(to);
|
||||
@@ -105,13 +145,11 @@ public class Punishment {
|
||||
}
|
||||
}
|
||||
}
|
||||
broadcastIssue(container);
|
||||
}
|
||||
|
||||
public Component playerMessage(){
|
||||
|
||||
NamedTextColor PRIMARY_COLOR = NamedTextColor.RED;
|
||||
NamedTextColor SECONDARY_COLOR = NamedTextColor.GOLD;
|
||||
|
||||
switch (type) {
|
||||
case MUTE -> {
|
||||
return Component.text("You have been muted by ")
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package de.shiewk.smoderation.storage;
|
||||
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -20,8 +26,8 @@ public class PunishmentContainer {
|
||||
return punishments.remove(index);
|
||||
}
|
||||
|
||||
public boolean remove(Punishment punishment){
|
||||
return punishments.remove(punishment);
|
||||
public void remove(Punishment punishment){
|
||||
punishments.remove(punishment);
|
||||
}
|
||||
|
||||
public @Nullable Punishment find(Predicate<Punishment> predicate){
|
||||
@@ -33,6 +39,17 @@ public class PunishmentContainer {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<CommandSender> collectBroadcastTargets(){
|
||||
ArrayList<CommandSender> senders = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.notifications")){
|
||||
senders.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
senders.add(Bukkit.getConsoleSender());
|
||||
return Collections.unmodifiableList(senders);
|
||||
}
|
||||
|
||||
public @Nullable Punishment findByTimestamp(long timestamp){
|
||||
return find(punishment -> punishment.time == timestamp);
|
||||
}
|
||||
|
||||
@@ -45,3 +45,6 @@ permissions:
|
||||
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.
|
||||
Reference in New Issue
Block a user