mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 11:49:12 +00:00
Improve MuteStatusChangeEvent (#3068)
Co-Authored-By: md678685 <1917406+md678685@users.noreply.github.com> Adds getTimestamp and getReason methods to MuteStatusChangeEvent with the apropriate JavaDocs explaining them. Closes #2459.
This commit is contained in:
parent
12c8623666
commit
6bbdbc89a6
3 changed files with 26 additions and 5 deletions
|
@ -590,7 +590,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||
//Returns true if status expired during this check
|
||||
public boolean checkMuteTimeout(final long currentTime) {
|
||||
if (getMuteTimeout() > 0 && getMuteTimeout() < currentTime && isMuted()) {
|
||||
final MuteStatusChangeEvent event = new MuteStatusChangeEvent(this, null, false);
|
||||
final MuteStatusChangeEvent event = new MuteStatusChangeEvent(this, null, false, getMuteTimeout(), getMuteReason());
|
||||
ess.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
|
|
|
@ -44,7 +44,7 @@ public class Commandmute extends EssentialsCommand {
|
|||
|
||||
long muteTimestamp = 0;
|
||||
String time;
|
||||
String muteReason = "";
|
||||
String muteReason = null;
|
||||
|
||||
if (args.length > 1) {
|
||||
time = args[1];
|
||||
|
@ -63,11 +63,11 @@ public class Commandmute extends EssentialsCommand {
|
|||
|
||||
final boolean willMute = (args.length > 1) || !user.getMuted();
|
||||
final User controller = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null;
|
||||
final MuteStatusChangeEvent event = new MuteStatusChangeEvent(user, controller, willMute);
|
||||
final MuteStatusChangeEvent event = new MuteStatusChangeEvent(user, controller, willMute, muteTimestamp, muteReason);
|
||||
ess.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
if (args.length > 1) {
|
||||
if (muteReason != null) {
|
||||
user.setMuteReason(muteReason.isEmpty() ? null : muteReason);
|
||||
user.setMuted(true);
|
||||
} else {
|
||||
|
|
|
@ -2,9 +2,30 @@ package net.ess3.api.events;
|
|||
|
||||
import net.ess3.api.IUser;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MuteStatusChangeEvent extends StatusChangeEvent {
|
||||
public MuteStatusChangeEvent(IUser affected, IUser controller, boolean value) {
|
||||
private Long timestamp;
|
||||
private String reason;
|
||||
|
||||
public MuteStatusChangeEvent(IUser affected, IUser controller, boolean value, Long timestamp, String reason) {
|
||||
super(affected, controller, value);
|
||||
this.timestamp = timestamp;
|
||||
this.reason = reason == null ? null : (reason.isEmpty() ? null : reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If the mute is temporary, returns a present optional with the timestamp; if permanent or unknown, returns an empty optional.
|
||||
*/
|
||||
public Optional<Long> getTimestamp() {
|
||||
return Optional.ofNullable(timestamp <= 0 ? null : timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the reason if provided, otherwise null.
|
||||
*/
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue