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;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Punishment {
|
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 PunishmentType type;
|
||||||
public final long time;
|
public final long time;
|
||||||
public final long until;
|
public final long until;
|
||||||
@@ -92,11 +95,48 @@ public class Punishment {
|
|||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()){
|
if (!event.isCancelled()){
|
||||||
container.add(punishment);
|
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) {
|
switch (type) {
|
||||||
case MUTE, BAN -> {
|
case MUTE, BAN -> {
|
||||||
final CommandSender sender = PlayerUtil.senderByUUID(to);
|
final CommandSender sender = PlayerUtil.senderByUUID(to);
|
||||||
@@ -105,13 +145,11 @@ public class Punishment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
broadcastIssue(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component playerMessage(){
|
public Component playerMessage(){
|
||||||
|
|
||||||
NamedTextColor PRIMARY_COLOR = NamedTextColor.RED;
|
|
||||||
NamedTextColor SECONDARY_COLOR = NamedTextColor.GOLD;
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MUTE -> {
|
case MUTE -> {
|
||||||
return Component.text("You have been muted by ")
|
return Component.text("You have been muted by ")
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
package de.shiewk.smoderation.storage;
|
package de.shiewk.smoderation.storage;
|
||||||
|
|
||||||
import de.shiewk.smoderation.punishments.Punishment;
|
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 org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@@ -20,8 +26,8 @@ public class PunishmentContainer {
|
|||||||
return punishments.remove(index);
|
return punishments.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean remove(Punishment punishment){
|
public void remove(Punishment punishment){
|
||||||
return punishments.remove(punishment);
|
punishments.remove(punishment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Punishment find(Predicate<Punishment> predicate){
|
public @Nullable Punishment find(Predicate<Punishment> predicate){
|
||||||
@@ -33,6 +39,17 @@ public class PunishmentContainer {
|
|||||||
return null;
|
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){
|
public @Nullable Punishment findByTimestamp(long timestamp){
|
||||||
return find(punishment -> punishment.time == timestamp);
|
return find(punishment -> punishment.time == timestamp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,7 @@ permissions:
|
|||||||
description: Allows the player to kick other players.
|
description: Allows the player to kick other players.
|
||||||
smod.menu:
|
smod.menu:
|
||||||
default: op
|
default: op
|
||||||
description: Allows the player to use the SModeration menu.
|
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