Skip to content

Commit

Permalink
Update javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderscoreTud committed Sep 10, 2024
1 parent 666f94c commit 79fcc25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/effects/EffContinue.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
return false;
}

// Section.getSections counts from the innermost section, so we need to invert the level
int levels = level == -1 ? 1 : loops - level + 1;
if (levels <= 0) {
Skript.error("Can't continue the " + StringUtils.fancyOrderNumber(level) + " loop as there " +
Expand Down
35 changes: 30 additions & 5 deletions src/main/java/ch/njol/skript/lang/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,14 @@ protected void loadOptionalCode(SectionNode sectionNode) {

/**
* Returns the sections from the current section (inclusive) until the specified section (exclusive).
*
* <p>
* If we have the following sections:
* <pre>{@code
* Section1
* └ Section2
* └ Section3} (we are here)</pre>
* And we call {@code getSectionsUntil(Section1)}, the result will be {@code [Section2, Section3]}.
*
* @param section The section to stop at. (exclusive)
* @return A list of sections from the current section (inclusive) until the specified section (exclusive).
*/
Expand All @@ -184,10 +191,18 @@ public static List<TriggerSection> getSectionsUntil(TriggerSection section) {
}

/**
* Returns a list of sections up to the specified number of levels.
* Returns a list of sections up to the specified number of levels from the current section.
* <p>
* If we have the following sections:
* <pre>{@code
* Section1
* └ Section2
* └ Section3} (we are here)</pre>
* And we call {@code getSections(2)}, the result will be {@code [Section2, Section3]}.
*
* @param levels The number of levels to retrieve.
* @param levels The number of levels to retrieve from the current section upwards. Must be greater than 0.
* @return A list of sections up to the specified number of levels.
* @throws IllegalArgumentException if the levels is less than 1.
*/
public static List<TriggerSection> getSections(int levels) {
Preconditions.checkArgument(levels > 0, "Depth must be at least 1");
Expand All @@ -196,11 +211,21 @@ public static List<TriggerSection> getSections(int levels) {
}

/**
* Returns a list of sections to the specified number of levels. Only counting sections of the specified type.
* Returns a list of sections to the specified number of levels from the current section.
* Only counting sections of the specified type.
* <p>
* If we have the following sections:
* <pre>{@code
* Section1
* └ LoopSection2
* └ Section3
* └ LoopSection4} (we are here)</pre>
* And we call {@code getSections(2, LoopSection.class)}, the result will be {@code [LoopSection2, Section3, LoopSection4]}.
*
* @param levels The number of levels to retrieve.
* @param levels The number of levels to retrieve from the current section upwards. Must be greater than 0.
* @param type The class type of the sections to count.
* @return A list of sections of the specified type up to the specified number of levels.
* @throws IllegalArgumentException if the levels is less than 1.
*/
public static List<TriggerSection> getSections(int levels, Class<? extends TriggerSection> type) {
Preconditions.checkArgument(levels > 0, "Depth must be at least 1");
Expand Down

0 comments on commit 79fcc25

Please sign in to comment.