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 @@ -14,6 +14,7 @@
import static java.awt.Color.BLUE;
import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.util.regex.Pattern.compile;
import static net.minecraft.ChatFormatting.DARK_GREEN;
import static net.minecraft.ChatFormatting.DARK_RED;
import static net.minecraft.ChatFormatting.GOLD;
Expand All @@ -25,19 +26,34 @@

public record StockMarketEntry(Company company, double price, double changeMoney, double changePercentage, int ownership, double buyPrice) {

private static final Pattern PRICE_PATTERN = Pattern.compile("Kurs: (?<price>\\d+\\.\\d+)\\$");
private static final Pattern CHANGE_PATTERN = Pattern.compile("Änderung: (?<money>-?\\d+\\.\\d+)\\$ \\((?<percentage>-?\\d+\\.\\d+)%\\) [▼▲]");
private static final Pattern OWNERSHIP_PATTERN = Pattern.compile("Besitz: (?<ownership>\\d+)/\\d+");
private static final Pattern BUY_PRICE_PATTERN = Pattern.compile("EK-Preis: (?<price>-?\\d+\\.\\d+)\\$");
private static final Pattern PRICE_PATTERN = compile("Kurs: (?<price>\\d+\\.\\d+)\\$");
private static final Pattern CHANGE_PATTERN = compile("Änderung: (?<money>-?\\d+\\.\\d+)\\$ \\((?<percentage>-?\\d+\\.\\d+)%\\) [▼▲]");
private static final Pattern OWNERSHIP_PATTERN = compile("Besitz: (?<ownership>\\d+)/\\d+");
private static final Pattern BUY_PRICE_PATTERN = compile("EK-Preis: (?<price>-?\\d+\\.\\d+)\\$");

public @Nullable Color getColor() {
double diff = this.price - this.buyPrice;

// check if price is below or equal to min value
if (this.price <= this.company.getMinValue()) {
return BLUE;
}

// check if user has bought any stock
if (this.ownership == 0) {
return null;
}

// get color value
Integer colorValue = getColorValue();
if (colorValue == null) {
return null;
}

return new Color(colorValue);
}

private @Nullable Integer getColorValue() {
Integer colorValue;
double diff = this.price - this.buyPrice;

if (diff >= 75) {
colorValue = DARK_GREEN.getColor();
Expand All @@ -53,11 +69,7 @@ public record StockMarketEntry(Company company, double price, double changeMoney
colorValue = DARK_RED.getColor();
}

if (colorValue == null) {
return null;
}

return new Color(colorValue);
return colorValue;
}

public static @Nullable StockMarketEntry fromItemStack(@NotNull ItemStack itemStack) {
Expand Down Expand Up @@ -116,10 +128,6 @@ public record StockMarketEntry(Company company, double price, double changeMoney
}
}

if (price == 0 || buyPrice == 0) {
return null;
}

return new StockMarketEntry(company, price, changeMoney, changePercentage, ownership, buyPrice);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class PlayerListener implements IMessageReceiveListener {

// health
private static final Pattern HEALTH_HEADER_PATTERN = compile("^=== Zustand von (?:\\[UC])?(?<playerName>[a-zA-Z0-9_]+) ===$");
private static final Pattern HEALTH_ENTRY_PATTERN = compile("^§.» (?<type>Gesundheit|Blut §.\\[§..+§.]|Hunger|Durst|Fett|Muskeln)§.: §.((§.)?#)+$");
private static final Pattern HEALTH_ENTRY_PATTERN = compile("^§.» (?<type>Gesundheit|Blut §.\\[§..+§.]|Hunger|Durst|Fett|Muskeln|Sucht)§.: §.((§.)?#)+$");
private static final Pattern HEALTH_ENTRY_HOVER_PATTERN = compile("^§.(?<value>\\d+(\\.\\d+)?)§./§.20\\.0$");
private static final Pattern HOUSE_DRINK_PATTERN = compile("^\\[Küche] Du hast etwas getrunken\\.$");

Expand Down