-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
180 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/codes/cookies/mod/commands/dev/debug/FiestaDebugCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package codes.cookies.mod.commands.dev.debug; | ||
|
||
import codes.cookies.mod.commands.system.ClientCommand; | ||
import codes.cookies.mod.features.mining.fiesta.MiningFiesta; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
|
||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class FiestaDebugCommand extends ClientCommand { | ||
|
||
@Override | ||
public @NotNull LiteralArgumentBuilder<FabricClientCommandSource> getCommand() { | ||
return literal("fiesta") | ||
.then(literal("start").executes(run(MiningFiesta::start))) | ||
.then(literal("stop").executes(run(MiningFiesta::stop))); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/codes/cookies/mod/events/MiningFiestaEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package codes.cookies.mod.events; | ||
|
||
import codes.cookies.mod.utils.cookies.CookiesEventUtils; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
|
||
public interface MiningFiestaEvents { | ||
|
||
Event<Runnable> START = CookiesEventUtils.runnable(); | ||
Event<Runnable> STOP = CookiesEventUtils.runnable(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/codes/cookies/mod/features/mining/fiesta/MiningFiesta.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package codes.cookies.mod.features.mining.fiesta; | ||
|
||
import codes.cookies.mod.events.ChatMessageEvents; | ||
import codes.cookies.mod.events.MiningFiestaEvents; | ||
import lombok.Getter; | ||
|
||
public class MiningFiesta { | ||
|
||
private static boolean active; | ||
@Getter | ||
private static long timeStarted; | ||
private static final long FIESTA_TIME =( 60 * 60 * 1000 * 2) + (20 * 60 * 1000); | ||
|
||
public static void register() { | ||
active = false; | ||
timeStarted = -1; | ||
ChatMessageEvents.EVENT.register(MiningFiesta::handleMessage); | ||
} | ||
|
||
private static void handleMessage(String content) { | ||
if ("MINING FIESTA is now underway! Equip your pickaxe and head to the mines!".equalsIgnoreCase(content.trim())) { | ||
start(); | ||
} else if ("MINING FIESTA has concluded! Put your pickaxe down and haul your ores home!".equalsIgnoreCase(content.trim())) { | ||
stop(); | ||
} | ||
} | ||
|
||
public static boolean isActive() { | ||
if (timeStarted + FIESTA_TIME < System.currentTimeMillis()) { | ||
active = false; | ||
} | ||
|
||
return active; | ||
} | ||
|
||
public static void startIfNotActive() { | ||
if (isActive()) { | ||
return; | ||
} | ||
|
||
start(); | ||
} | ||
|
||
public static void start() { | ||
timeStarted = System.currentTimeMillis(); | ||
active = true; | ||
MiningFiestaEvents.START.invoker().run(); | ||
} | ||
|
||
public static void stop() { | ||
active = false; | ||
MiningFiestaEvents.STOP.invoker().run(); | ||
timeStarted = -1; | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/codes/cookies/mod/features/mining/fiesta/MiningFiestaTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package codes.cookies.mod.features.mining.fiesta; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import codes.cookies.mod.events.ChatMessageEvents; | ||
import codes.cookies.mod.events.MiningFiestaEvents; | ||
import codes.cookies.mod.utils.cookies.Constants; | ||
import codes.cookies.mod.utils.cookies.CookiesUtils; | ||
|
||
import net.minecraft.text.Text; | ||
|
||
public class MiningFiestaTracker { | ||
|
||
private static final List<Integer> pristineDrops = new ArrayList<>(); | ||
private static int glossyGemstone; | ||
|
||
public static void register() { | ||
ChatMessageEvents.register(MiningFiestaTracker::trackPristine, "cookies-regex:PRISTINE! You found .*? x\\d+!"); | ||
MiningFiestaEvents.START.register(MiningFiestaTracker::reset); | ||
MiningFiestaEvents.STOP.register(MiningFiestaTracker::finishFiesta); | ||
} | ||
|
||
private static void reset() { | ||
pristineDrops.clear(); | ||
glossyGemstone = 0; | ||
} | ||
|
||
private static void finishFiesta() { | ||
CookiesUtils.sendMessage(Text.literal("§m §r{ Cookies Mod }§m §r") | ||
.withColor(Constants.MAIN_COLOR)); | ||
CookiesUtils.sendRawMessage(""); | ||
CookiesUtils.sendRawMessage("Total Pristine Drops: " + pristineDrops.size()); | ||
CookiesUtils.sendRawMessage("Flawed Through Pristine: " + pristineDrops.stream() | ||
.mapToInt(Integer::intValue) | ||
.sum()); | ||
CookiesUtils.sendRawMessage("Glossy Gemstones Obtained: " + glossyGemstone); | ||
CookiesUtils.sendRawMessage("Active for: " + CookiesUtils.formattedMs((System.currentTimeMillis() - MiningFiesta.getTimeStarted()))); | ||
CookiesUtils.sendRawMessage(""); | ||
CookiesUtils.sendMessage(Text.literal("§m §r").withColor(Constants.MAIN_COLOR)); | ||
} | ||
|
||
private static void trackPristine(String message) { | ||
if (!MiningFiesta.isActive()) { | ||
return; | ||
} | ||
|
||
final String literalAmount = message.replaceAll("\\D", ""); | ||
if (literalAmount.isEmpty()) { | ||
return; | ||
} | ||
|
||
final int amount; | ||
try { | ||
amount = Integer.parseInt(literalAmount); | ||
} catch (NumberFormatException e) { | ||
return; | ||
} | ||
|
||
pristineDrops.add(amount); | ||
} | ||
|
||
public static void trackGlossyGemstone(int amount) { | ||
MiningFiesta.startIfNotActive(); | ||
if (!MiningFiesta.isActive()) { | ||
return; | ||
} | ||
|
||
glossyGemstone += amount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters