Skip to content

Commit cf9bc97

Browse files
authored
Merge pull request #486 from UnicacityAddon/hotfix/3-0-1
hotfix/3-0-1
2 parents b71ed28 + fb01e0c commit cf9bc97

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/main/java/de/rettichlp/ucutils/common/models/StockMarketEntry.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static java.awt.Color.BLUE;
1515
import static java.lang.Double.parseDouble;
1616
import static java.lang.Integer.parseInt;
17+
import static java.util.regex.Pattern.compile;
1718
import static net.minecraft.ChatFormatting.DARK_GREEN;
1819
import static net.minecraft.ChatFormatting.DARK_RED;
1920
import static net.minecraft.ChatFormatting.GOLD;
@@ -25,19 +26,34 @@
2526

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

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

3334
public @Nullable Color getColor() {
34-
double diff = this.price - this.buyPrice;
35-
35+
// check if price is below or equal to min value
3636
if (this.price <= this.company.getMinValue()) {
3737
return BLUE;
3838
}
3939

40+
// check if user has bought any stock
41+
if (this.ownership == 0) {
42+
return null;
43+
}
44+
45+
// get color value
46+
Integer colorValue = getColorValue();
47+
if (colorValue == null) {
48+
return null;
49+
}
50+
51+
return new Color(colorValue);
52+
}
53+
54+
private @Nullable Integer getColorValue() {
4055
Integer colorValue;
56+
double diff = this.price - this.buyPrice;
4157

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

56-
if (colorValue == null) {
57-
return null;
58-
}
59-
60-
return new Color(colorValue);
72+
return colorValue;
6173
}
6274

6375
public static @Nullable StockMarketEntry fromItemStack(@NotNull ItemStack itemStack) {
@@ -116,10 +128,6 @@ public record StockMarketEntry(Company company, double price, double changeMoney
116128
}
117129
}
118130

119-
if (price == 0 || buyPrice == 0) {
120-
return null;
121-
}
122-
123131
return new StockMarketEntry(company, price, changeMoney, changePercentage, ownership, buyPrice);
124132
}
125133
}

src/main/java/de/rettichlp/ucutils/listener/impl/PlayerListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class PlayerListener implements IMessageReceiveListener {
4141

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

0 commit comments

Comments
 (0)