Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class Options {
private final NameTagOptions nameTag = new NameTagOptions();
private final List<PersonalUseEntry> personalUse = new ArrayList<>();
private final CarOptions car = new CarOptions();
private final SoundOptions sound = new SoundOptions();

private ReinforcementType reinforcementType = UNICACITYADDON;
private boolean customSounds = true;
private AtmInformationType atmInformationType = NONE;
private boolean showHydration = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package de.rettichlp.ucutils.common.configuration.options;

import de.rettichlp.ucutils.common.gui.screens.components.CyclingButtonEntry;
import de.rettichlp.ucutils.common.models.Faction;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import static de.rettichlp.ucutils.common.configuration.options.SoundOptions.MedicSelect.MEDIC;
import static de.rettichlp.ucutils.common.configuration.options.SoundOptions.StateSelect.STATE;
import static de.rettichlp.ucutils.common.models.Faction.FBI;
import static de.rettichlp.ucutils.common.models.Faction.POLIZEI;
import static de.rettichlp.ucutils.common.models.Faction.RETTUNGSDIENST;
import static net.minecraft.text.Text.translatable;

@Getter
@Setter
@Accessors(fluent = true)
public class SoundOptions {

private StateSelect bankRobbery = STATE;
private StateSelect bomb = STATE;
private boolean contractFulfilled = true;
private boolean contractSet = true;
private MedicSelect fire = MEDIC;
private boolean report = false;
private boolean service = true;

public enum StateSelect implements CyclingButtonEntry {

ALWAYS,
STATE,
NONE;

@Contract(" -> new")
@Override
public @NotNull Text getDisplayName() {
return translatable("ucutils.select_state." + name().toLowerCase() + ".name");
}

@Contract(" -> new")
@Override
public @NotNull Tooltip getTooltip() {
return Tooltip.of(translatable("ucutils.select_state." + name().toLowerCase() + ".tooltip"));
}

public boolean verify(Faction faction) {
return this == ALWAYS || (this == STATE && (faction == FBI || faction == POLIZEI || faction == RETTUNGSDIENST));
}
}

public enum MedicSelect implements CyclingButtonEntry {

ALWAYS,
MEDIC,
NONE;

@Contract(" -> new")
@Override
public @NotNull Text getDisplayName() {
return translatable("ucutils.select_medic." + name().toLowerCase() + ".name");
}

@Contract(" -> new")
@Override
public @NotNull Tooltip getTooltip() {
return Tooltip.of(translatable("ucutils.select_medic." + name().toLowerCase() + ".tooltip"));
}

public boolean verify(Faction faction) {
return this == ALWAYS || (this == MEDIC && faction == RETTUNGSDIENST);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public class MainOptionsScreen extends OptionsScreen {
private static final Text TEXT_NAMETAG = translatable("ucutils.options.text.nametag");
private static final Text TEXT_PERSONAL_USE = translatable("ucutils.options.text.personal_use");
private static final Text TEXT_WIDGETS = translatable("ucutils.options.text.widgets");
private static final Text TEXT_SOUNDS = translatable("ucutils.options.text.sounds");
private static final Text REINFORCEMENT_STYLE_NAME = translatable("ucutils.options.reinforcement_style.name");
private static final Text NOTIFICATION_SOUNDS_NAME = translatable("ucutils.options.notification_sounds.name");
private static final Text NOTIFICATION_SOUNDS_TOOLTIP = translatable("ucutils.options.notification_sounds.tooltip");
private static final Text BANK_INFORMATION_NAME = translatable("ucutils.options.atm_information.name");
private static final Text HYDRATION_NAME = translatable("ucutils.options.hydration.name");
private static final Text HYDRATION_TOOLTIP = translatable("ucutils.options.hydration.tooltip");
Expand All @@ -40,7 +39,7 @@ public void initBody() {

DirectionalLayoutWidget directionalLayoutWidget2 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addButton(directionalLayoutWidget2, TEXT_CAR, button -> this.client.setScreen(new CarOptionsScreen(this)), 150);
renderService.addToggleButton(directionalLayoutWidget2, NOTIFICATION_SOUNDS_NAME, NOTIFICATION_SOUNDS_TOOLTIP, Options::customSounds, Options::customSounds, 150);
renderService.addButton(directionalLayoutWidget2, TEXT_SOUNDS, button -> this.client.setScreen(new SoundOptionsScreen(this)), 150);

DirectionalLayoutWidget directionalLayoutWidget3 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addButton(directionalLayoutWidget3, TEXT_WIDGETS, button -> this.client.setScreen(new WidgetOptionsScreen(this)), 150);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package de.rettichlp.ucutils.common.gui.screens.options;

import de.rettichlp.ucutils.common.configuration.options.SoundOptions;
import de.rettichlp.ucutils.common.gui.screens.OptionsScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.DirectionalLayoutWidget;
import net.minecraft.text.Text;

import static de.rettichlp.ucutils.UCUtils.renderService;
import static net.minecraft.client.gui.widget.DirectionalLayoutWidget.horizontal;
import static net.minecraft.client.gui.widget.DirectionalLayoutWidget.vertical;
import static net.minecraft.text.Text.translatable;

public class SoundOptionsScreen extends OptionsScreen {

private static final Text TEXT_SOUND = translatable("ucutils.options.text.sounds");
private static final Text SOUND_BANK_ROBBERY_NAME = translatable("ucutils.sound.bank_robbery.name");
private static final Text SOUND_BOMB_NAME = translatable("ucutils.sound.bomb.name");
private static final Text SOUND_CONTRACT_SET_NAME = translatable("ucutils.sound.contract_set.name");
private static final Text SOUND_CONTRACT_SET_TOOLTIP = translatable("ucutils.sound.contract_set.tooltip");
private static final Text SOUND_CONTRACT_FULFILLED_NAME = translatable("ucutils.sound.contract_fulfilled.name");
private static final Text SOUND_CONTRACT_FULFILLED_TOOLTIP = translatable("ucutils.sound.contract_fulfilled.tooltip");
private static final Text SOUND_SERVICE_NAME = translatable("ucutils.sound.service.name");
private static final Text SOUND_SERVICE_TOOLTIP = translatable("ucutils.sound.service.tooltip");
private static final Text SOUND_FIRE_NAME = translatable("ucutils.sound.fire.name");
private static final Text TEXT_REPORT_NAME = translatable("ucutils.sound.report.name");
private static final Text TEXT_REPORT_TOOLTIP = translatable("ucutils.sound.report.tooltip");

public SoundOptionsScreen(Screen parent) {
super(parent, TEXT_SOUND);
}

@Override
public void initBody() {
DirectionalLayoutWidget directionalLayoutWidget = this.layout.addBody(vertical().spacing(4));

DirectionalLayoutWidget directionalLayoutWidget1 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addCyclingButton(directionalLayoutWidget1, SOUND_BANK_ROBBERY_NAME, SoundOptions.StateSelect.values(), SoundOptions.StateSelect::getDisplayName, (options, e) -> options.sound().bankRobbery(e), options -> options.sound().bankRobbery(), 150);
renderService.addCyclingButton(directionalLayoutWidget1, SOUND_BOMB_NAME, SoundOptions.StateSelect.values(), SoundOptions.StateSelect::getDisplayName, (options, e) -> options.sound().bomb(e), options -> options.sound().bomb(), 150);

DirectionalLayoutWidget directionalLayoutWidget2 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addToggleButton(directionalLayoutWidget2, SOUND_CONTRACT_SET_NAME, SOUND_CONTRACT_SET_TOOLTIP, (options, value) -> options.sound().contractSet(value), options -> options.sound().contractSet(), 150);
renderService.addToggleButton(directionalLayoutWidget2, SOUND_CONTRACT_FULFILLED_NAME, SOUND_CONTRACT_FULFILLED_TOOLTIP, (options, value) -> options.sound().contractFulfilled(value), options -> options.sound().contractFulfilled(), 150);

DirectionalLayoutWidget directionalLayoutWidget3 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addToggleButton(directionalLayoutWidget3, SOUND_SERVICE_NAME, SOUND_SERVICE_TOOLTIP, (options, value) -> options.sound().service(value), options -> options.sound().service(), 150);
renderService.addCyclingButton(directionalLayoutWidget3, SOUND_FIRE_NAME, SoundOptions.MedicSelect.values(), SoundOptions.MedicSelect::getDisplayName, (options, e) -> options.sound().fire(e), options -> options.sound().fire(), 150);

DirectionalLayoutWidget directionalLayoutWidget4 = directionalLayoutWidget.add(horizontal().spacing(8));
renderService.addToggleButton(directionalLayoutWidget4, TEXT_REPORT_NAME, TEXT_REPORT_TOOLTIP, (options, value) -> options.sound().report(value), options -> options.sound().report(), 150);

directionalLayoutWidget.forEachChild(this::addDrawableChild);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
public enum Faction {

NULL("", "", false, GRAY, ""),
POLIZEI("Polizei", "police", false, BLUE, "✯"),
FBI("FBI", "fbi", false, DARK_BLUE, "✯"),
POLIZEI("Polizei", "police", false, BLUE, "✯"),
RETTUNGSDIENST("Rettungsdienst", "medic", false, DARK_RED, "✚"),

LA_COSA_NOSTRA("La Cosa Nostra", "mafia", true, DARK_AQUA, "⚜"),
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/de/rettichlp/ucutils/common/models/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import static de.rettichlp.ucutils.UCUtils.configuration;
import static net.minecraft.client.sound.PositionedSoundInstance.master;

@Getter
@AllArgsConstructor
public enum Sound {

BANK_ROBBERY("bank_robbery"),
BOMB_SOUND("bomb"),
CONTRACT_FULFILLED("contract.fulfilled"),
CONTRACT_SET("contract.set"),
FIRE("fire"),
REPORT("report"), // TODO use sound
SERVICE("service");

Expand All @@ -35,16 +36,12 @@ public enum Sound {
}

public void play() {
if (configuration.getOptions().customSounds()) {
PositionedSoundInstance positionedSoundInstance = master(getSoundEvent(), 1.0F, 1.0F);
MinecraftClient.getInstance().getSoundManager().play(positionedSoundInstance);
}
PositionedSoundInstance positionedSoundInstance = master(getSoundEvent(), 1.0F, 1.0F);
MinecraftClient.getInstance().getSoundManager().play(positionedSoundInstance);
}

public void play(float pitch, float volume) {
if (configuration.getOptions().customSounds()) {
PositionedSoundInstance positionedSoundInstance = master(getSoundEvent(), pitch, volume);
MinecraftClient.getInstance().getSoundManager().play(positionedSoundInstance);
}
PositionedSoundInstance positionedSoundInstance = master(getSoundEvent(), pitch, volume);
MinecraftClient.getInstance().getSoundManager().play(positionedSoundInstance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand All @@ -19,6 +18,7 @@
import static java.awt.Color.RED;
import static java.awt.Color.WHITE;
import static java.time.LocalDateTime.now;
import static java.util.Comparator.comparing;
import static java.util.Objects.hash;
import static java.util.Objects.nonNull;
import static java.util.UUID.randomUUID;
Expand Down Expand Up @@ -54,7 +54,7 @@ public List<Notification> getActiveNotifications() {
return this.notifications.stream()
.filter(Objects::nonNull)
.filter(notification -> now().isBefore(notification.getTimestamp().plus(notification.getDurationInMillis(), MILLISECONDS.toChronoUnit())))
.sorted(Comparator.comparing(Notification::getTimestamp))
.sorted(comparing(Notification::getTimestamp))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.regex.Pattern;

import static de.rettichlp.ucutils.UCUtils.commandService;
import static de.rettichlp.ucutils.UCUtils.configuration;
import static de.rettichlp.ucutils.UCUtils.storage;
import static de.rettichlp.ucutils.UCUtils.utilService;
import static de.rettichlp.ucutils.common.models.Sound.CONTRACT_FULFILLED;
Expand Down Expand Up @@ -48,7 +49,11 @@ public boolean onMessageReceive(Text text, String message) {
if (contractAddMatcher.find()) {
// show all entries to sync
utilService.delayedAction(() -> commandService.sendCommandWithAfkCheck("contractlist"), COMMAND_COOLDOWN_MILLIS);
CONTRACT_SET.play();

if (configuration.getOptions().sound().contractSet()) {
CONTRACT_SET.play();
}

return true;
}

Expand All @@ -63,7 +68,11 @@ public boolean onMessageReceive(Text text, String message) {
if (contractKillMatcher.find()) {
String targetName = contractKillMatcher.group("targetName");
storage.getContractEntries().removeIf(contractEntry -> contractEntry.getPlayerName().equals(targetName));
CONTRACT_FULFILLED.play();

if (configuration.getOptions().sound().contractFulfilled()) {
CONTRACT_FULFILLED.play();
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.regex.Pattern;

import static de.rettichlp.ucutils.UCUtils.commandService;
import static de.rettichlp.ucutils.UCUtils.configuration;
import static de.rettichlp.ucutils.UCUtils.player;
import static de.rettichlp.ucutils.UCUtils.storage;
import static de.rettichlp.ucutils.common.models.Sound.SERVICE;
Expand All @@ -35,7 +36,11 @@ public boolean onMessageReceive(Text text, String message) {
Matcher serviceMatcher = SERVICE_PATTERN.matcher(message);
if (serviceMatcher.find()) {
storage.setActiveServices(storage.getActiveServices() + 1);
SERVICE.play();

if (configuration.getOptions().sound().service()) {
SERVICE.play();
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static de.rettichlp.ucutils.UCUtils.configuration;
import static de.rettichlp.ucutils.UCUtils.player;
import static de.rettichlp.ucutils.UCUtils.storage;
import static de.rettichlp.ucutils.common.models.Faction.FBI;
import static de.rettichlp.ucutils.common.models.Faction.POLIZEI;
import static de.rettichlp.ucutils.common.models.Faction.RETTUNGSDIENST;
import static de.rettichlp.ucutils.common.models.Sound.BANK_ROBBERY;
import static de.rettichlp.ucutils.common.models.Sound.BOMB_SOUND;
import static java.lang.String.format;
import static java.time.Duration.between;
Expand All @@ -34,8 +33,9 @@
import static net.minecraft.util.Formatting.RED;

@UCUtilsListener
public class BombListener implements IMessageReceiveListener, IHudRenderListener {
public class MajorEventListener implements IMessageReceiveListener, IHudRenderListener {

private static final Pattern BANK_ROBBERY_PATTERN = compile("^News: Es wurde ein Raub in der Staatsbank gemeldet!$");
private static final Pattern BOMB_FOUND_PATTERN = compile("^News: ACHTUNG! Es wurde eine Bombe in der Nähe von (?<location>.+) gefunden!$");
private static final Pattern BOMB_STOP_PATTERN = compile("^News: Die Bombe konnte (erfolgreich|nicht) entschärft werden!");

Expand All @@ -45,15 +45,21 @@ public class BombListener implements IMessageReceiveListener, IHudRenderListener
@Override
public boolean onMessageReceive(Text text, String message) {
Faction playerFaction = storage.getFaction(player.getGameProfile().name());
if (playerFaction != POLIZEI && playerFaction != FBI && playerFaction != RETTUNGSDIENST) {
return true;

Matcher bankRobberyMatcher = BANK_ROBBERY_PATTERN.matcher(message);
if (bankRobberyMatcher.find() && configuration.getOptions().sound().bankRobbery().verify(playerFaction)) {
BANK_ROBBERY.play();
}

Matcher bombFoundMatcher = BOMB_FOUND_PATTERN.matcher(message);
if (bombFoundMatcher.find()) {
this.bombPlantedTime = now();
this.bombLocationString = bombFoundMatcher.group("location");
BOMB_SOUND.play();

if (configuration.getOptions().sound().bomb().verify(playerFaction)) {
BOMB_SOUND.play();
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.rettichlp.ucutils.listener.impl.faction;

import de.rettichlp.ucutils.common.models.Countdown;
import de.rettichlp.ucutils.common.models.Faction;
import de.rettichlp.ucutils.common.models.HousebanEntry;
import de.rettichlp.ucutils.common.registry.UCUtilsListener;
import de.rettichlp.ucutils.listener.IMessageReceiveListener;
Expand All @@ -22,6 +23,7 @@
import static de.rettichlp.ucutils.UCUtils.utilService;
import static de.rettichlp.ucutils.common.Storage.MEDIC_BANDAGE_DURATION;
import static de.rettichlp.ucutils.common.Storage.MEDIC_PILL_DURATION;
import static de.rettichlp.ucutils.common.models.Sound.FIRE;
import static de.rettichlp.ucutils.common.services.CommandService.COMMAND_COOLDOWN_MILLIS;
import static java.lang.Integer.parseInt;
import static java.time.Duration.ofMinutes;
Expand Down Expand Up @@ -49,6 +51,7 @@ public class MedicListener implements IMessageReceiveListener {
private static final Pattern FIRST_AID_PATTERN = compile("^\\[Erste-Hilfe] (?:\\[UC])?(?<playerName>[a-zA-Z0-9_]+) hat dir ein Erste-Hilfe-Schein für 14 Tage ausgestellt\\.$");
private static final Pattern FIRST_AID_LICENCES_PATTERN = compile("^- Erste-Hilfe-Schein: Vorhanden$");
private static final Pattern LABOR_TRANSPORT_STARTED_PATTERN = compile("^\\[ʟᴀʙᴏʀ] Transport gestartet: (?<chestAmount>\\d+) ᴋɪsᴛᴇɴ mit (?<ingredientAmount>\\d+) (?<ingredient>.+)$");
private static final Pattern FIRE_START_PATTERN = compile("^News: Es wurde ein Feuer bei .+ gemeldet!$");

@Override
public boolean onMessageReceive(Text text, String message) {
Expand Down Expand Up @@ -150,6 +153,13 @@ public boolean onMessageReceive(Text text, String message) {
return true;
}

Faction playerFaction = storage.getFaction(player.getGameProfile().name());
Matcher fireStartMatcher = FIRE_START_PATTERN.matcher(message);
if (fireStartMatcher.find() && configuration.getOptions().sound().fire().verify(playerFaction)) {
FIRE.play();
return true;
}

return true;
}

Expand Down
Loading