Skip to content

Commit

Permalink
Merge pull request #7 from KingsMMA/auction-alerts
Browse files Browse the repository at this point in the history
Added Auction Alerts
  • Loading branch information
KingsMMA committed Jul 10, 2023
2 parents 4f32ac3 + a890140 commit e207645
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ public class AuctionTimerCategory extends ConfigCategory {
@ConfigBoolean(id = "enabled", display = "Enable Timer", description = "Enables the Auction Timer, appearing on your HUD.")
public boolean enabled = true;

@ConfigBoolean(id = "alert", display = "Always Send Alert", description = "Always send an alert when auctions start, even if disabled on Melon King.")
public boolean alert = true;


@ConfigBoolean(id = "warning", display = "Always Send Warning", description = "Always send a warning 60 seconds before auctions start, even if disabled on Melon King.")
public boolean warning = true;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ public class AuctionTimerElement extends HudElement {
public List<Object> render(float tickDelta) {
if (!FruitfulUtilities.getInstance().configManager.getCategory(AuctionTimerCategory.class).enabled) return Collections.emptyList();

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
int[] timeUntilAuctions = getTimeUntilAuctions();
int minutesRemaining = timeUntilAuctions[0], secondsRemaining = timeUntilAuctions[1];

return Collections.singletonList("§6Auction Timer: §e" + (minutesRemaining < 10 ? "0" : "") + minutesRemaining + ":" + (secondsRemaining < 10 ? "0" : "") + secondsRemaining);
}

public static int[] getTimeUntilAuctions() {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
int currentMinute = calendar.get(Calendar.MINUTE);
int currentSecond = calendar.get(Calendar.SECOND);

Expand All @@ -37,7 +43,7 @@ public List<Object> render(float tickDelta) {
secondsRemaining = 0;
}

return Collections.singletonList("§6Auction Timer: §e" + (minutesRemaining < 10 ? "0" : "") + minutesRemaining + ":" + (secondsRemaining < 10 ? "0" : "") + secondsRemaining);
return new int[]{minutesRemaining, secondsRemaining};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import dev.kingrabbit.fruitfulutilities.Keybinds;
import dev.kingrabbit.fruitfulutilities.config.ConfigManager;
import dev.kingrabbit.fruitfulutilities.config.ConfigScreen;
import dev.kingrabbit.fruitfulutilities.config.categories.AuctionTimerCategory;
import dev.kingrabbit.fruitfulutilities.config.categories.SearchingTrackerCategory;
import dev.kingrabbit.fruitfulutilities.hud.elements.AuctionTimerElement;
import dev.kingrabbit.fruitfulutilities.pathviewer.PathManager;
import dev.kingrabbit.fruitfulutilities.pathviewer.PathScreen;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
Expand All @@ -24,6 +27,10 @@ public class TickListener implements ClientTickEvents.EndTick {
public static int searchingUntil = 0;
public static int testUndergroundAt = -1;

public static boolean auctionWarningReceived = false;
public static boolean auctionAlertReceived = false;
public static int sendAuctionAlertAt = -1;

@Override
public void onEndTick(MinecraftClient client) {
FruitfulUtilities fruitfulUtilities = FruitfulUtilities.getInstance();
Expand Down Expand Up @@ -63,6 +70,33 @@ public void onEndTick(MinecraftClient client) {
}
}

if (client.player != null) {
AuctionTimerCategory auctionTimerCategory = configManager.getCategory(AuctionTimerCategory.class);

if (tick >= sendAuctionAlertAt && sendAuctionAlertAt != -1) {
if (auctionTimerCategory.alert && !auctionAlertReceived) {
auctionAlertReceived = true;
client.player.sendMessage(Text.of("§8» §7A set of auctions is starting!"));
client.player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 2.0f, 1.0f);
}
sendAuctionAlertAt = -1;
}

int[] timeUntilAuctions = AuctionTimerElement.getTimeUntilAuctions();
int minutesRemaining = timeUntilAuctions[0], secondsRemaining = timeUntilAuctions[1] + 1;
if (minutesRemaining == 0 && secondsRemaining <= 59) {
if (auctionTimerCategory.warning && !auctionWarningReceived) {
auctionWarningReceived = true;
client.player.sendMessage(Text.of("§8» §7A set of auctions is starting in 60 seconds!"));
client.player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 2.0f, 1.0f);
}
sendAuctionAlertAt = tick + secondsRemaining * 20;
} else if (auctionWarningReceived || auctionAlertReceived) {
auctionWarningReceived = false;
auctionAlertReceived = false;
}
}

SearchingTrackerCategory searchingCategory = fruitfulUtilities.configManager.getCategory(SearchingTrackerCategory.class);
if (searchingCategory.enabled) {
if (searchingCategory.mode == 1 && (searchingUntil == 0 || searchingUntil - 10 < tick) && client.player != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public void onGameMessage(GameMessageS2CPacket packet, CallbackInfo ci) {
}
}

if (message.equals("» A set of auctions is starting!"))
TickListener.auctionAlertReceived = true;
else if (message.equals("» A set of auctions is starting in 60 seconds!"))
TickListener.auctionWarningReceived = true;

if (message.matches("^> The (king|queen|monarch|city) has purchased the (.*) (major upgrade|upgrade|renovation)( for [0-9]{1,16} .*)?\\.$")) {
Matcher matcher = UPGRADE_PURCHASED_PATTERN.matcher(message);
while (matcher.find()) {
Expand Down

0 comments on commit e207645

Please sign in to comment.