Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ loader_version=0.17.3
loom_version=1.14.1

# Mod Properties
mod_version=2.0.0
mod_version=2.0.1
maven_group=de.rettichlp
archives_base_name=ucutils

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/rettichlp/ucutils/UCUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void onInitialize() {
client.execute(() -> {
this.registry.registerListeners();
renderService.initializeWidgets();
syncService.sync(true);
syncService.checkForUpdates();
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/rettichlp/ucutils/command/MiCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull Litera
.map(Faction::getDisplayName), builder))
.executes(context -> {
String input = getString(context, "faction");
fromDisplayName(input).ifPresentOrElse(faction -> commandService.sendCommand("memberinfo " + faction.getMemberInfoCommandName()),
fromDisplayName(input).ifPresentOrElse(faction -> commandService.sendCommand("memberinfo " + faction.getDisplayName()),
() -> messageService.sendModMessage("Die Fraktion " + input + " konnte nicht gefunden werden.", false));

return 1;
Expand All @@ -38,7 +38,7 @@ public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull Litera
.executes(context -> {
String playerName = player.getGameProfile().name();
Faction faction = storage.getFaction(playerName);
commandService.sendCommand("memberinfo " + faction.getMemberInfoCommandName());
commandService.sendCommand("memberinfo " + faction.getDisplayName());
return 1;
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/rettichlp/ucutils/command/MiaCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull Litera
.map(Faction::getDisplayName), builder))
.executes(context -> {
String input = getString(context, "faction");
fromDisplayName(input).ifPresentOrElse(faction -> commandService.sendCommand("memberinfoall " + faction.getMemberInfoCommandName()),
fromDisplayName(input).ifPresentOrElse(faction -> commandService.sendCommand("memberinfoall " + faction.getDisplayName()),
() -> messageService.sendModMessage("Die Fraktion " + input + " konnte nicht gefunden werden.", false));

return 1;
Expand All @@ -38,7 +38,7 @@ public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull Litera
.executes(context -> {
String playerName = player.getGameProfile().name();
Faction faction = storage.getFaction(playerName);
commandService.sendCommand("memberinfoall " + faction.getMemberInfoCommandName());
commandService.sendCommand("memberinfoall " + faction.getDisplayName());
return 1;
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/rettichlp/ucutils/command/ModCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull Litera
.then(literal("sync")
.then(literal("faction")
.executes(context -> {
syncService.syncFactionMembersWithCommandResponse();
syncService.syncFactionMembersWithCommand(() -> {});
return 1;
}))
.executes(context -> {
syncService.sync(true);
syncService.checkForUpdates();
syncService.syncFactionSpecificData();
return 1;
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static de.rettichlp.ucutils.UCUtils.commandService;
import static de.rettichlp.ucutils.UCUtils.messageService;
import static de.rettichlp.ucutils.UCUtils.utilService;
import static de.rettichlp.ucutils.common.services.CommandService.COMMAND_COOLDOWN_MILLIS;
import static java.lang.Integer.parseInt;
import static java.util.regex.Pattern.compile;

Expand All @@ -38,7 +39,7 @@ public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull Litera
} else {
commandService.sendCommand("bank einzahlen " + amount);
}
}, 1000);
}, COMMAND_COOLDOWN_MILLIS);

return 1;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static de.rettichlp.ucutils.UCUtils.messageService;
import static de.rettichlp.ucutils.UCUtils.storage;
import static de.rettichlp.ucutils.UCUtils.utilService;
import static de.rettichlp.ucutils.common.services.CommandService.COMMAND_COOLDOWN_MILLIS;

@UCUtilsCommand(label = "reichensteuer")
public class RichTaxesCommand extends CommandBase {
Expand All @@ -25,7 +26,7 @@ public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull Litera
commandService.sendCommand("bank info");

// execute command to check money in atm
utilService.delayedAction(() -> commandService.sendCommand("atminfo"), 1000);
utilService.delayedAction(() -> commandService.sendCommand("atminfo"), COMMAND_COOLDOWN_MILLIS);

// handle money withdraw
utilService.delayedAction(() -> {
Expand All @@ -52,7 +53,7 @@ public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull Litera
commandService.sendCommand("bank abbuchen " + moneyAtmAmount);
messageService.sendModMessage("Du musst noch " + (moneyThatNeedsToBeWithdrawn - moneyAtmAmount) + "$ abbuchen.", false);
}
}, 2000);
}, COMMAND_COOLDOWN_MILLIS * 2);

return 1;
});
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/de/rettichlp/ucutils/common/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import de.rettichlp.ucutils.common.models.BlackMarket;
import de.rettichlp.ucutils.common.models.BlacklistEntry;
import de.rettichlp.ucutils.common.models.BlacklistReason;
import de.rettichlp.ucutils.common.models.CommandResponseRetriever;
import de.rettichlp.ucutils.common.models.ContractEntry;
import de.rettichlp.ucutils.common.models.Countdown;
import de.rettichlp.ucutils.common.models.Faction;
Expand Down Expand Up @@ -48,9 +47,6 @@ public class Storage {
@Getter
private final List<BlackMarket> blackMarkets = new ArrayList<>();

@Getter
private final List<CommandResponseRetriever> commandResponseRetrievers = new ArrayList<>();

@Getter
private final List<ContractEntry> contractEntries = new ArrayList<>();

Expand Down Expand Up @@ -130,8 +126,6 @@ public void print() {
this.blacklistReasons.forEach((faction, blacklistReasons) -> LOGGER.info("blacklistReasons[{}:{}]: {}", faction, blacklistReasons.size(), blacklistReasons));
// blackMarkets
LOGGER.info("blackMarkets[{}]: {}", this.blackMarkets.size(), this.blackMarkets);
// commandResponseRetrievers
LOGGER.info("commandResponseRetrievers[{}]: {}", this.commandResponseRetrievers.size(), this.commandResponseRetrievers);
// contractEntries
LOGGER.info("contractEntries[{}]: {}", this.contractEntries.size(), this.contractEntries);
// countdowns
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/de/rettichlp/ucutils/common/api/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.function.Consumer;

import static de.rettichlp.ucutils.UCUtils.LOGGER;
import static de.rettichlp.ucutils.UCUtils.syncService;
import static de.rettichlp.ucutils.UCUtils.utilService;
import static java.lang.String.valueOf;
import static java.net.URI.create;
Expand Down Expand Up @@ -80,11 +79,6 @@ private <T> void get(@NotNull String uri, TypeToken<T> typeToken, Consumer<T> ca
}

private <T> void sendRequest(HttpRequest httpRequest, TypeToken<T> typeToken, Consumer<T> callback) {
if (!syncService.dataUsageConfirmed()) {
LOGGER.warn("Data usage not confirmed, skipping API request: [{}] {}", httpRequest.method(), httpRequest.uri().toString());
return;
}

this.httpClient.sendAsync(httpRequest, ofString())
.thenApply(this::catchDefaultApiError)
.thenApply(response -> ofNullable(typeToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class Configuration {
private int predictedPayDayExp = 0;
@Nullable
private LocalDateTime firstAidLicenseExpireDateTime = null;
private int dataUsageConfirmationUID = 0;
private Set<EventListener.HalloweenDoor> halloweenClickedDoors = new HashSet<>();

public void addMinutesSinceLastPayDay(int minutes) {
Expand Down

This file was deleted.

47 changes: 22 additions & 25 deletions src/main/java/de/rettichlp/ucutils/common/models/Faction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static de.rettichlp.ucutils.UCUtils.storage;
import static java.util.Arrays.stream;
import static java.util.Collections.emptySet;
import static net.minecraft.text.Text.empty;
import static net.minecraft.util.Formatting.AQUA;
import static net.minecraft.util.Formatting.BLUE;
Expand All @@ -23,33 +23,34 @@
import static net.minecraft.util.Formatting.DARK_RED;
import static net.minecraft.util.Formatting.GOLD;
import static net.minecraft.util.Formatting.GRAY;
import static net.minecraft.util.Formatting.GREEN;
import static net.minecraft.util.Formatting.LIGHT_PURPLE;
import static net.minecraft.util.Formatting.RED;
import static net.minecraft.util.Formatting.WHITE;
import static net.minecraft.util.Formatting.YELLOW;

@Getter
@AllArgsConstructor
public enum Faction {

NULL("", "Keine Fraktion", false, GRAY, ""),
FBI("fbi", "F.B.I.", false, DARK_BLUE, "✯"),
POLIZEI("polizei", "Polizei", false, BLUE, "✯"),
RETTUNGSDIENST("rettungsdienst", "Rettungsdienst", false, DARK_RED, "✚"),
NULL("", false, GRAY, ""),
POLIZEI("Polizei", false, BLUE, "✯"),
FBI("FBI", false, DARK_BLUE, "✯"),
RETTUNGSDIENST("Rettungsdienst", false, DARK_RED, "✚"),

CALDERON("kartell", "Calderón Kartell", true, GOLD, ""),
KERZAKOV("kerzakov", "Kerzakov Familie", true, RED, ""),
LACOSANOSTRA("lcn", "La Cosa Nostra", true, DARK_AQUA, ""),
LEMILIEU("le_milieu", "Le Milieu", true, DARK_AQUA, ""),
OBRIEN("obrien", "O'Brien Familie", true, DARK_GREEN, ""),
TRIADEN("triaden", "Triaden", true, RED, "☯"),
WESTSIDEBALLAS("ballas", "Westside Ballas", true, DARK_PURPLE, ""),
LA_COSA_NOSTRA("La Cosa Nostra", true, DARK_AQUA, ""),
WESTSIDE_BALLAS("Westside Ballas", true, DARK_PURPLE, ""),
CALDERON_KARTELL("Calderón Kartell", true, GOLD, ""),
KERZAKOV_FAMILIE("Kerzakov Familie", true, RED, ""),
HAYAT_KARTELL("Hayat Kartell", true, DARK_GREEN, "Ħ"),
YAKUZA("Yakuza", true, GREEN, "☯"),
VELENTZAS("Velentzas", true, WHITE, "δ"),

HITMAN("hitman", "Hitman", false, AQUA, "➹"),
KIRCHE("kirche", "Kirche", false, LIGHT_PURPLE, ""),
NEWS("news", "News", false, YELLOW, ""),
TERRORISTEN("terroristen", "Terroristen", false, GRAY, "");
HITMAN("Hitman", false, AQUA, "➹"),
TERRORISTEN("Terroristen", false, GRAY, ""),
KIRCHE("Kirche", false, LIGHT_PURPLE, ""),
NEWS("News", false, YELLOW, "");

private final String apiName;
private final String displayName;
private final boolean isBadFaction;
private final Formatting color;
Expand All @@ -68,21 +69,17 @@ public Text getNameTagSuffix() {
.formatted(DARK_GRAY));
}

public String getMemberInfoCommandName() {
return this == OBRIEN ? "Obrien" : this.displayName;
}

public Set<FactionMember> getMembers() {
public List<FactionMember> getMembers() {
return storage.getFactionEntries().stream()
.filter(factionEntry -> factionEntry.faction() == this)
.findFirst()
.map(FactionEntry::members)
.orElse(emptySet());
.orElse(new ArrayList<>());
}

public static @NotNull Optional<Faction> fromDisplayName(String displayName) {
return stream(values())
.filter(faction -> displayName.contains(faction.getDisplayName()))
.filter(faction -> faction.getDisplayName().equals(displayName))
.findFirst();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.rettichlp.ucutils.common.models;

import java.util.Set;
import java.util.List;

public record FactionEntry(Faction faction, Set<FactionMember> members) {
public record FactionEntry(Faction faction, List<FactionMember> members) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

public class CommandService {

public static long COMMAND_COOLDOWN_MILLIS = 500;

private static final String UUID_RETTICHLP = "25855f4d-3874-4a7f-a6ad-e9e4f3042e19";

public void sendCommand(String command) {
Expand All @@ -37,6 +39,10 @@ public boolean sendCommandWithAfkCheck(String command) {
}

public void sendCommands(List<String> commandStrings) {
sendCommands(commandStrings, COMMAND_COOLDOWN_MILLIS);
}

public void sendCommands(List<String> commandStrings, long cooldownMillis) {
// to modifiable list
List<String> commands = new ArrayList<>(commandStrings);

Expand All @@ -50,7 +56,7 @@ public void run() {

sendCommand(commands.removeFirst());
}
}, 0, 1000);
}, 0, cooldownMillis);
}

public boolean isSuperUser() {
Expand All @@ -61,6 +67,6 @@ public void retrieveNumberAndRun(String playerName, Consumer<Integer> runWithNum
sendCommand("nummer " + playerName);

utilService.delayedAction(() -> ofNullable(storage.getRetrievedNumbers().get(playerName))
.ifPresentOrElse(runWithNumber, () -> messageService.sendModMessage("Die Nummer von " + playerName + " konnte nicht abgerufen werden.", false)), 1000);
.ifPresentOrElse(runWithNumber, () -> messageService.sendModMessage("Die Nummer von " + playerName + " konnte nicht abgerufen werden.", false)), COMMAND_COOLDOWN_MILLIS);
}
}
Loading