Skip to content

Commit

Permalink
Return a copy of the sections list rather than a view in the section …
Browse files Browse the repository at this point in the history
…helper methods
  • Loading branch information
UnderscoreTud committed Sep 5, 2024
1 parent 3afdbb6 commit b6e7f01
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/ch/njol/skript/lang/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected void loadOptionalCode(SectionNode sectionNode) {
*/
public static List<TriggerSection> getSectionsUntil(TriggerSection section) {
List<TriggerSection> sections = ParserInstance.get().getCurrentSections();
return sections.subList(sections.indexOf(section) + 1, sections.size());
return new ArrayList<>(sections.subList(sections.indexOf(section) + 1, sections.size()));
}

/**
Expand All @@ -192,7 +192,7 @@ public static List<TriggerSection> getSectionsUntil(TriggerSection section) {
public static List<TriggerSection> getSections(int levels) {
Preconditions.checkArgument(levels > 0, "Depth must be at least 1");
List<TriggerSection> sections = ParserInstance.get().getCurrentSections();
return sections.subList(Math.max(sections.size() - levels, 0), sections.size());
return new ArrayList<>(sections.subList(Math.max(sections.size() - levels, 0), sections.size()));
}

/**
Expand All @@ -208,7 +208,7 @@ public static List<TriggerSection> getSections(int levels, Class<? extends Trigg
List<? extends TriggerSection> sections = parser.getCurrentSections(type);
TriggerSection section = sections.get(Math.max(sections.size() - levels, 0));
List<TriggerSection> allSections = parser.getCurrentSections();
return allSections.subList(allSections.indexOf(section), allSections.size());
return new ArrayList<>(allSections.subList(allSections.indexOf(section), allSections.size()));
}

@Nullable
Expand Down

0 comments on commit b6e7f01

Please sign in to comment.