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
63 changes: 63 additions & 0 deletions src/main/java/de/rettichlp/ucutils/command/RichTaxesCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package de.rettichlp.ucutils.command;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import de.rettichlp.ucutils.common.registry.CommandBase;
import de.rettichlp.ucutils.common.registry.UCUtilsCommand;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import org.jetbrains.annotations.NotNull;

import static de.rettichlp.ucutils.UCUtils.commandService;
import static de.rettichlp.ucutils.UCUtils.configuration;
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 {

private static final int RICH_TAXES_THRESHOLD = 100000;

@Override
public LiteralArgumentBuilder<FabricClientCommandSource> execute(@NotNull LiteralArgumentBuilder<FabricClientCommandSource> node) {
return node
.executes(context -> {
if (storage.isPremium()) {
commandService.sendCommand("reichensteuern");
return 1;
}

// execute command to check money on the bank of player
commandService.sendCommand("atminfo");

// handle money withdraw
utilService.delayedAction(() -> {
int moneyAtmAmount = storage.getMoneyAtmAmount();
int moneyBankAmount = configuration.getMoneyBankAmount();

// check atm has money
if (moneyAtmAmount <= 0) {
messageService.sendModMessage("Der ATM hat kein Geld.", false);
return;
}

// check player has rich taxes
if (moneyBankAmount <= RICH_TAXES_THRESHOLD) {
messageService.sendModMessage("Du hast nicht ausreichend Geld auf der Bank.", false);
return;
}

int moneyThatNeedsToBeWithdrawn = moneyBankAmount - RICH_TAXES_THRESHOLD;

if (moneyAtmAmount >= moneyThatNeedsToBeWithdrawn) {
commandService.sendCommand("bank abbuchen " + moneyThatNeedsToBeWithdrawn);
} else {
commandService.sendCommand("bank abbuchen " + moneyAtmAmount);
messageService.sendModMessage("Du musst noch " + (moneyThatNeedsToBeWithdrawn - moneyAtmAmount) + "$ abbuchen.", false);
}
}, COMMAND_COOLDOWN_MILLIS);

return 1;
});
}
}
6 changes: 6 additions & 0 deletions src/main/java/de/rettichlp/ucutils/common/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public class Storage {
@Setter
private Minecart minecartEntityToHighlight;

@Getter
@Setter
private int moneyAtmAmount = 0;

@Getter
@Setter
private boolean premium = false;
Expand Down Expand Up @@ -171,6 +175,8 @@ public void print() {
LOGGER.info("joinTimestamp: {}", this.joinTimestamp);
// minecartEntityToHighlight
LOGGER.info("minecartEntityToHighlight: {}", this.minecartEntityToHighlight);
// moneyAtmAmount
LOGGER.info("moneyAtmAmount: {}", this.moneyAtmAmount);
// premium
LOGGER.info("premium: {}", this.premium);
// stockMarketCommandRunning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class EconomyListener implements IMessageReceiveListener {
private static final Pattern STOCK_MARKET_SELL_PATTERN = compile("^\\[Aktien] (?<amount>\\d+)x (?<company>.+) verkauft für (?<price>\\d+)\\$\\. \\(Gebühr: (?<fee>\\d+)\\$, Steuer: (?<tax>\\d+)\\$\\) (?<brutto>[+-]\\d+)\\$ Brutto / (?<netto>[+-]\\d+)\\$ Netto$");

// other
private static final Pattern ATM_MONEY_AMOUNT_PATTERN = compile("ATM \\d+: (?<moneyAtmAmount>\\d+)\\$/100000\\$");
private static final Pattern BUSINESS_CASH_PATTERN = compile("^Kasse: (\\d+)\\$$");
private static final Pattern EXP_PATTERN = compile("(?<amount>[+-]\\d+) Exp!( \\(x(?<multiplier>\\d)\\))?$");
private static final Pattern MAX_EXP_REACHED_PATTERN = compile("^Du hast die maximale Exp erreicht! Benutze /buylevel um ein Level aufzusteigen\\.$");
Expand Down Expand Up @@ -306,6 +307,13 @@ public boolean onMessageReceive(Component text, String message) {
return true;
}

Matcher moneyAtmAmountMatcher = ATM_MONEY_AMOUNT_PATTERN.matcher(message);
if (moneyAtmAmountMatcher.find()) {
int moneyAtmAmount = parseInt(moneyAtmAmountMatcher.group("moneyAtmAmount"));
storage.setMoneyAtmAmount(moneyAtmAmount);
return true;
}

Matcher businessCashMatcher = BUSINESS_CASH_PATTERN.matcher(message);
if (businessCashMatcher.find()) {
String amountString = businessCashMatcher.group(1);
Expand Down