-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advancements API #1554
Merged
gabizou
merged 15 commits into
SpongePowered:bleeding
from
Cybermaxke:feature/advancements
Dec 31, 2017
Merged
Advancements API #1554
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3202756
Added the advancements API
Cybermaxke 365f794
Moved operator criteria to separate interfaces. Remove dataview metho…
Cybermaxke 157e0fe
Changes for compatibility with vanilla mc. Simplify for impl.
Cybermaxke 4631081
More work.
Cybermaxke 6488efc
Updated the events, some improvements
Cybermaxke b78c567
Fixed the SpongeEventFactoryTest for the added events.
Cybermaxke 8080288
Progress. Added a game registry event.
Cybermaxke d57a9e9
Added generic events.
Cybermaxke 556be61
Fixed the SpongeEventFactoryTest.
Cybermaxke 652287b
Make a Advancement extend TextRepresentable, moved the toast text met…
Cybermaxke 1111bb7
Added a getTextFormat method to the advancement type.
Cybermaxke cdae096
Work on custom triggers.
Cybermaxke 3fc7cb4
Derp
Cybermaxke f5635e0
Only one trigger per criterion.
Cybermaxke 4124309
Moved the arguments out of the build methods to be consistent in the …
Cybermaxke File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
167 changes: 167 additions & 0 deletions
167
src/main/java/org/spongepowered/api/advancement/Advancement.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,167 @@ | ||
/* | ||
* This file is part of SpongeAPI, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.spongepowered.api.advancement; | ||
|
||
import org.spongepowered.api.CatalogType; | ||
import org.spongepowered.api.Sponge; | ||
import org.spongepowered.api.advancement.criteria.AdvancementCriterion; | ||
import org.spongepowered.api.text.Text; | ||
import org.spongepowered.api.text.TextRepresentable; | ||
import org.spongepowered.api.util.ResettableBuilder; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* An advancement. | ||
*/ | ||
public interface Advancement extends CatalogType, TextRepresentable { | ||
|
||
/** | ||
* Creates a new {@link Builder} to create {@link Advancement}s. | ||
* | ||
* @return The new builder | ||
*/ | ||
static Builder builder() { | ||
return Sponge.getRegistry().createBuilder(Builder.class); | ||
} | ||
|
||
/** | ||
* Gets the {@link AdvancementTree} this advancement is located in, | ||
* will only be present if the root advancement was used to create | ||
* a {@link AdvancementTree}. | ||
* | ||
* @return The advancement tree | ||
*/ | ||
Optional<AdvancementTree> getTree(); | ||
|
||
/** | ||
* Gets all the children {@link Advancement}s. | ||
* | ||
* @return The children advancements | ||
*/ | ||
Collection<Advancement> getChildren(); | ||
|
||
/** | ||
* Gets all the {@link AdvancementCriterion} that should be achieved | ||
* before this advancement is unlocked. {@link AdvancementCriterion#EMPTY} | ||
* will be returned if no criterion was assigned. | ||
* <p> | ||
* This {@link AdvancementCriterion} can be a AND or OR operation that | ||
* contains multiple possible {@link AdvancementCriterion}s. | ||
* | ||
* @return The criterion | ||
*/ | ||
AdvancementCriterion getCriterion(); | ||
|
||
/** | ||
* Gets the parent {@link Advancement}, if present. | ||
* | ||
* @return The parent advancement, if present | ||
*/ | ||
Optional<Advancement> getParent(); | ||
|
||
/** | ||
* Gets the {@link DisplayInfo} of this advancement, if present. | ||
* | ||
* @return The display info, if present | ||
*/ | ||
Optional<DisplayInfo> getDisplayInfo(); | ||
|
||
/** | ||
* Gets the {@link Text} lines that would be used to | ||
* display a toast notification. | ||
* | ||
* @return The text lines | ||
*/ | ||
List<Text> toToastText(); | ||
|
||
/** | ||
* A builder to create {@link Advancement}s. | ||
*/ | ||
interface Builder extends ResettableBuilder<Advancement, Builder> { | ||
|
||
/** | ||
* Sets the parent {@link Advancement}. Defaults to {code null}. | ||
* | ||
* @param parent The parent advancement | ||
* @return This builder, for chaining | ||
*/ | ||
Builder parent(@Nullable Advancement parent); | ||
|
||
/** | ||
* Sets the {@link AdvancementCriterion} that should be used | ||
* for the advancement. Defaults to {@link AdvancementCriterion#EMPTY}. | ||
* | ||
* @param criterion The criterion | ||
* @return This builder, for chaining | ||
*/ | ||
Builder criterion(AdvancementCriterion criterion); | ||
|
||
/** | ||
* Sets the {@link DisplayInfo}. Defaults to {code null}. | ||
* | ||
* @param displayInfo The display info | ||
* @return This builder, for chaining | ||
*/ | ||
Builder displayInfo(@Nullable DisplayInfo displayInfo); | ||
|
||
/** | ||
* Sets the identifier of the {@link Advancement} | ||
* (without the namespace). | ||
* | ||
* @param id The identifier | ||
* @return This builder, for chaining | ||
*/ | ||
Builder id(String id); | ||
|
||
/** | ||
* Sets the name of the {@link Advancement}. Defaults to | ||
* the plain {@link DisplayInfo#getTitle()} if the | ||
* {@link DisplayInfo} is present. Otherwise will it default | ||
* to the identifier ({@link #id(String)}). | ||
* | ||
* @param name The name | ||
* @return This builder, for chaining | ||
*/ | ||
Builder name(String name); | ||
|
||
/** | ||
* Builds the {@link Advancement}. | ||
* | ||
* @return The advancement | ||
*/ | ||
Advancement build(); | ||
|
||
@Override | ||
@Deprecated | ||
default Builder from(Advancement value) throws UnsupportedOperationException { | ||
throw new UnsupportedOperationException("Cannot create duplicate advancements!"); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/org/spongepowered/api/advancement/AdvancementProgress.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,91 @@ | ||
/* | ||
* This file is part of SpongeAPI, licensed under the MIT License (MIT). | ||
* | ||
* Copyright (c) SpongePowered <https://www.spongepowered.org> | ||
* Copyright (c) contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.spongepowered.api.advancement; | ||
|
||
import org.spongepowered.api.advancement.criteria.AdvancementCriterion; | ||
import org.spongepowered.api.advancement.criteria.CriterionProgress; | ||
import org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion; | ||
import org.spongepowered.api.advancement.criteria.ScoreCriterionProgress; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Represents the progress of a {@link Advancement}. | ||
*/ | ||
public interface AdvancementProgress extends Progressable { | ||
|
||
/** | ||
* Gets the {@link Advancement}. | ||
* | ||
* @return The advancement | ||
*/ | ||
Advancement getAdvancement(); | ||
|
||
/** | ||
* Gets the {@link ScoreCriterionProgress} for the given {@link ScoreAdvancementCriterion}. | ||
* | ||
* @param criterion The score criterion | ||
* @return The score criterion progress | ||
*/ | ||
default ScoreCriterionProgress require(ScoreAdvancementCriterion criterion) { | ||
return get(criterion).orElseThrow(() -> new IllegalStateException("The score criterion " + criterion.getName() + | ||
" isn't present on the advancement " + getAdvancement().getName())); | ||
} | ||
|
||
/** | ||
* Gets the {@link ScoreCriterionProgress} for the given {@link ScoreAdvancementCriterion}, | ||
* this will only be returned of the criterion is present on the {@link Advancement}. | ||
* | ||
* @param criterion The score criterion | ||
* @return The score criterion progress | ||
*/ | ||
Optional<ScoreCriterionProgress> get(ScoreAdvancementCriterion criterion); | ||
|
||
/** | ||
* Gets the {@link CriterionProgress} for the given {@link AdvancementCriterion}. | ||
* <p> | ||
* For AND and OR criteria will wrapped {@link CriterionProgress} be provided that will | ||
* interact with the {@link CriterionProgress}s for every child {@link AdvancementCriterion}s. | ||
* | ||
* @param criterion The criterion | ||
* @return The criterion progress | ||
*/ | ||
default CriterionProgress require(AdvancementCriterion criterion) { | ||
return get(criterion).orElseThrow(() -> new IllegalStateException("The criterion " + criterion.getName() + | ||
" isn't present on the advancement " + getAdvancement().getName())); | ||
} | ||
|
||
/** | ||
* Gets the {@link CriterionProgress} for the given {@link AdvancementCriterion}, | ||
* this will only be returned of the criterion is present on the {@link Advancement}. | ||
* <p> | ||
* For AND and OR criteria will wrapped {@link CriterionProgress} be provided that will | ||
* interact with the {@link CriterionProgress}s for every child {@link AdvancementCriterion}s. | ||
* | ||
* @param criterion The criterion | ||
* @return The criterion progress | ||
*/ | ||
Optional<CriterionProgress> get(AdvancementCriterion criterion); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested classes will not link properly in Java 8's javadoc generator. They need to be fully qualified to work.