### BIGAL Achievement Definition Example Source: https://github.com/mcparks/achievables/blob/main/README.md An example of a complete achievement definition using BIGAL version 0, including state, activators, deactivators, and event handling. ```Groovy achievement { syntaxVersion 0 name "Magic Kingdom Mountaineer" description "Ride the three mountains of Magic Kingdom without warping or teleporting" icon "IRON_SPADE:20" reward "MONEY:500" state { rodeSpaceMountain = false rodeBigThunderMountain = false rodeSplashMountain = false warpedOrTeleported = false } activators { (state.rodeSpaceMountain == true) && (state.rodeSplashMountain == true) && (state.rodeBigThunderMountain == true) } deactivators { state.warpedOrTeleported == true } events { on("CompleteRideEvent") { if (event.rideId == 32) { state.rodeSpaceMountain = true } if (event.rideId == 7) { state.rodeBigThunderMountain = true } if (event.rideId == 9) { state.rodeSplashMountain = true } } on("TeleportPlayerToPlayerEvent") { state.warpedOrTeleported = true } on("PlayerWarpEvent") { state.warpedOrTeleported = true } } } ``` -------------------------------- ### Activator Logic Example Source: https://github.com/mcparks/achievables/blob/main/README.md Defines the conditions under which an achievement is considered complete. It uses boolean logic to evaluate the game state. ```groovy activators { (state.rodeSpaceMountain == true) && (state.rodeSplashMountain == true) && (state.rodeBigThunderMountain == true) } ``` -------------------------------- ### AchievableManager Process Trigger Implementation Source: https://github.com/mcparks/achievables/blob/main/README.md Provides an example implementation of the `processTrigger` method within the AchievableManager. This method iterates through registered achievables matching the trigger type and attempts to process the trigger against each achievable. ```java // In your AchievableManager implementation @Override public void processTrigger(AchievableTrigger trigger) { // Check if the trigger matches any registered achievements for (Achievable achievable : registeredAchievables.get(trigger.getType())) { try { achievable.process(trigger); } catch (Exception e) { // do whatever you want with caught exceptions } } } ``` -------------------------------- ### Deactivator Logic Example Source: https://github.com/mcparks/achievables/blob/main/README.md Defines the conditions under which an achievement's progress should be reset. It uses boolean logic to evaluate the game state. ```groovy deactivators { state.warpedOrTeleported == true } ``` -------------------------------- ### Initialize Achievables System Source: https://github.com/mcparks/achievables/blob/main/README.md Demonstrates how to initialize the Achievables system with a custom `AchievableManager`, set logging, configure metadata, and customize JSON serialization for player data. ```java Achievables.initialize(yourAchievableManager); Achievables.getInstance().setLogger(yourLogger); Achievables.getInstance().setAchievableMetaBuilderSupplier(() -> YourAchievementMeta.builder()); Achievables.customizeGson(gsonBuilder -> gsonBuilder.registerTypeAdapter(AchievablePlayer.class, new YourPlayerDeserializer())); Achievables.customizeGson(gsonBuilder -> gsonBuilder.registerTypeAdapter(AchievablePlayer.class, new YourPlayerSerializer())); ``` -------------------------------- ### Gradle Dependency Configuration Source: https://github.com/mcparks/achievables/blob/main/README.md Shows how to add the Achievables library as a dependency in a Gradle build file. ```groovy dependencies { implementation 'us.mcparks:achievables:1.0.0' // Replace with the actual version } ``` -------------------------------- ### Maven Dependency Configuration Source: https://github.com/mcparks/achievables/blob/main/README.md Shows how to add the Achievables library as a dependency in a Maven project's pom.xml. ```xml us.mcparks achievables 1.0.0 ``` -------------------------------- ### Load and Register BIGAL Achievements Source: https://github.com/mcparks/achievables/blob/main/README.md Shows how to load achievement definitions from BIGAL files, parse them, and register the parsed achievables with the AchievableManager. It also mentions the utility of metadata associated with achievables. ```java import java.util.List; List bigAlFileContents = // Load your BIGAL files; for (String fileContent : bigAlFileContents) { // Parse the BIGAL file content AchievableWithMeta parsedAchievable = BigalsIntegratedGroovyAchievementLanguage.interpret(fileContent); // // Register the achievable with your manager yourAchievableManager.registerAchievable(parsedAchievable.getAchievable()); // you might want to use the metadata for other purposes! We use it to display the achievement in the GUI, keep track of the rewards, determine whether or not the file should be activated, etc. } ``` -------------------------------- ### Player Representation and Serialization Source: https://github.com/mcparks/achievables/blob/main/README.md Shows how to create a `YourPlayer` class implementing `AchievablePlayer` and provide custom `JsonSerializer` and `JsonDeserializer` for `AchievablePlayer`. ```java public class YourPlayer implements AchievablePlayer { // Player implementation } ``` ```java public class YourPlayerSerializer implements JsonSerializer { @Override public JsonElement serialize(AchievablePlayer player, Type type, JsonSerializationContext context) { // Convert YourPlayer to JSON } } ``` ```java public class YourPlayerDeserializer implements JsonDeserializer { @Override public AchievablePlayer deserialize(JsonElement json, Type type, JsonDeserializationContext context) { // Convert JSON to YourPlayer } } ``` -------------------------------- ### State Persistence Implementation Source: https://github.com/mcparks/achievables/blob/main/README.md Provides the methods `setPlayerState` and `getPlayerState` for implementing the storage and retrieval of achievement states for players. ```java @Override public void setPlayerState(AchievablePlayer player, StatefulAchievable achievable, Map state, boolean persist) { // Store the player's state for the achievable // If persist is true, save to your persistent storage (database, etc) } ``` ```java @Override public Map getPlayerState(AchievablePlayer player, StatefulAchievable achievable) { // Retrieve the player's state for the achievable from your storage } ``` -------------------------------- ### Event System Implementation Source: https://github.com/mcparks/achievables/blob/main/README.md Illustrates defining custom game events that extend `us.mcparks.achievables.events.Event` and mapping event class names to these custom events within the `AchievableManager`. ```java public class YourGameEvent implements us.mcparks.achievables.events.Event { // Event implementation } ``` ```java public class YourPlayerJumpEvent extends YourGameEvent { // Player jump event implementation } ``` ```java public class YourItemCollectEvent extends YourGameEvent { // Item collect event implementation } ``` ```java @Override public Class getEventClass(String eventClassName) { // Map event class names to your game's event classes switch(eventClassName) { case "PlayerJumpEvent": return YourPlayerJumpEvent.class; case "ItemCollectEvent": return YourItemCollectEvent.class; // Add more mappings as needed (more likely: do this dynamically with reflection) default: return null; } } ``` -------------------------------- ### Register and Unregister Achievables Source: https://github.com/mcparks/achievables/blob/main/README.md Demonstrates how to register and unregister achievables with the AchievableManager, using a Multimap to index them by trigger type. This is crucial for efficient event handling. ```java import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; // in your AchievableManager Multimap achievables = Multimaps.synchronizedSetMultimap(HashMultimap.create()); public void registerAchievable(Achievable achievable) { for (AchievableTrigger.Type triggerType : achievable.getTriggers()) { //System.out.println("Registering achievable " + achievable.getUUID().toString() + "with trigger " + triggerType.toString()); achievables.put(triggerType, achievable); } } public void unregisterAchievable(Achievable achievable) { for (AchievableTrigger.Type triggerType : achievable.getTriggers()) { achievables.remove(triggerType, achievable); } } ``` -------------------------------- ### BIGAL Achievement Metadata Source: https://github.com/mcparks/achievables/blob/main/README.md Defines the metadata for an achievement, including syntax version, name, description, icon, and reward. ```Groovy syntaxVersion 0 name "Magic Kingdom Mountaineer" description "Ride the three mountains of Magic Kingdom without warping or teleporting" icon "IRON_SPADE:20" reward "MONEY:500" ``` -------------------------------- ### BIGAL Achievement State Variables Source: https://github.com/mcparks/achievables/blob/main/README.md Defines the initial state variables for an achievement, which track player progress and disqualifying conditions. ```Groovy state { rodeSpaceMountain = false rodeBigThunderMountain = false rodeSplashMountain = false warpedOrTeleported = false } ``` -------------------------------- ### Java Implementation of AchievableManager Source: https://github.com/mcparks/achievables/blob/main/README.md Provides a basic structure for a Java class that implements the AchievableManager interface, required for managing achievements. ```java public class YourAchievableManager implements us.mcparks.achievables.AchievableManager { // Implementation of required methods // ... } ``` -------------------------------- ### Achievement Completion Tracking Source: https://github.com/mcparks/achievables/blob/main/README.md Details the implementation of `completeAchievable` to mark an achievement as completed and `isCompleted` to check the completion status for a player. ```java @Override public void completeAchievable(Achievable achievable, AchievablePlayer player) { // Mark the achievable as completed for the player // Store this information in your persistent storage (database, etc) // Trigger any rewards or notifications } ``` ```java @Override public boolean isCompleted(Achievable achievable, AchievablePlayer player) { // Check if the player has completed the achievable } ``` -------------------------------- ### Process Game Events to Triggers Source: https://github.com/mcparks/achievables/blob/main/README.md Illustrates how to convert a game event into an AchievableTrigger and then process this trigger using the AchievableManager. This is the core mechanism for triggering achievements based on game occurrences. ```java // In your event handling system public void onYourGameEvent(YourGameEvent event) { // Convert to an Achievable Trigger AchievableTrigger trigger = new AchievableTrigger( AchievableTrigger.Type.EVENT, event, (YourPlayer) event.getPlayer() ); // Process the trigger yourAchievableManager.processTrigger(trigger); } ``` -------------------------------- ### Event Handling for State Changes Source: https://github.com/mcparks/achievables/blob/main/README.md Responds to game events to update the achievement's state. It checks event-specific fields like 'rideId' and modifies the 'state' object accordingly. ```groovy events { on("CompleteRideEvent") { if (event.rideId == 32) { state.rodeSpaceMountain = true } if (event.rideId == 7) { state.rodeBigThunderMountain = true } if (event.rideId == 9) { state.rodeSplashMountain = true } } on("TeleportPlayerToPlayerEvent") { state.warpedOrTeleported = true } on("PlayerWarpEvent") { state.warpedOrTeleported = true } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.