HTTPS
https://git.nageyqma.icu/nageyqma/blade-addons-next.git
SSH
git@git.nageyqma.icu:nageyqma/blade-addons-next.git
HTTPS 链接可直接 git clone;推送代码请使用 SSH。
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
package blade.addon.features.notifications;
import blade.addon.utils.Misc;
import blade.addon.utils.debug.Debug;
import config.practical.data.SoundData;
import java.util.regex.PatternSyntaxException;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
public class Notification {
private String matchString, notificationString, command;
private boolean useRegex, sendCommand, enabled;
private int ticks;
private final SoundData sound;
public Notification() {
this.matchString = "";
this.notificationString = "";
this.command = "";
this.useRegex = false;
this.sendCommand = false;
this.enabled = true;
this.ticks = 20;
this.sound = new SoundData(SoundEvents.NOTE_BLOCK_PLING.value(), 1, 1);
}
public Notification(String matchString, String notificationString, String command, boolean useRegex, boolean sendCommand, boolean enabled, int ticks, SoundData sound) {
this.matchString = matchString;
this.notificationString = notificationString;
this.command = command;
this.useRegex = useRegex;
this.sendCommand = sendCommand;
this.enabled = enabled;
this.ticks = ticks;
this.sound = sound;
}
public String getMatchString() {
return matchString;
}
public String getNotificationString() {
return notificationString;
}
public int getTicks() {
return ticks;
}
public String getCommand() {
return command;
}
public boolean sendCommand() {
return sendCommand;
}
public SoundData getSound() {
return sound;
}
public boolean useRegex() {
return useRegex;
}
public boolean isEnabled() {
return enabled;
}
public void setMatchString(String matchString) {
this.matchString = matchString;
}
public void setNotificationString(String notificationString) {
this.notificationString = notificationString;
}
public void setCommand(String command) {
this.command = command;
}
public void setTicks(int ticks) {
this.ticks = ticks;
}
public void setSendCommand(boolean sendCommand) {
this.sendCommand = sendCommand;
}
public void setUseRegex(boolean useRegex) {
this.useRegex = useRegex;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public void testMessage(String message) {
if (!enabled) return;
if (useRegex) {
try {
if (!message.matches(matchString)) return;
} catch (PatternSyntaxException e) {
return;
}
} else if (!message.equals(matchString)) return;
Debug.sendDebugMessage(Component.literal("Debug: " + notificationString));
Notifications.setNotification(this);
Misc.sendSound(sound);
if (sendCommand) {
Misc.executeCommand(command);
}
}
@Override
public String toString() {
return "Notification{" +
"matchString='" + matchString + '\'' +
", notificationString='" + notificationString + '\'' +
", command='" + command + '\'' +
", useRegex=" + useRegex +
", sendCommand=" + sendCommand +
", enabled=" + enabled +
", ticks=" + ticks +
", sound=" + sound +
'}';
}
}