Code Patterns
Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.
All
225
Command
60
Damage
2
Ecs
27
Entity
5
Gui
75
Interaction
2
Inventory
4
Moderation
3
Permission
2
Player
9
Plugin
4
Storage
2
Teleport
3
Ui
22
Util
5
← Back to Patterns
java
moderation
Mute System
Timed mute system with JSON persistence. Automatically cleans up expired mutes.
Example Code
public class MuteTracker extends BlockingDiskFile {
private List<Mute> muteTracker = new ArrayList<>();
public MuteTracker() {
super(Path.of("MyPlugin/Mute.json"));
}
public void addMute(Mute mute) {
this.fileLock.writeLock().lock();
this.muteTracker.removeIf(m -> m.target().equals(mute.target()));
this.muteTracker.add(mute);
this.fileLock.writeLock().unlock();
this.syncSave();
}
public List<Mute> getMutes() {
// Auto-cleanup expired mutes
if (this.muteTracker.removeIf(m -> m.until().isBefore(Instant.now()))) {
this.syncSave();
}
return muteTracker;
}
public boolean isMuted(UUID uuid) {
var playerMute = getMutes().stream()
.filter(m -> m.target().equals(uuid))
.findFirst().orElse(null);
return playerMute != null && playerMute.until().isAfter(Instant.now());
}
public record Mute(UUID target, UUID mutedBy, Instant until, String reason) {}
}