-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multiple pages trait (proof of concept)
- Loading branch information
1 parent
1a5d4ff
commit 5be4e95
Showing
4 changed files
with
89 additions
and
5 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
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
63 changes: 63 additions & 0 deletions
63
src/main/java/de/oliver/fancyholograms/trait/builtin/MultiplePagesTrait.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,63 @@ | ||
package de.oliver.fancyholograms.trait.builtin; | ||
|
||
import de.oliver.fancyholograms.api.data.TextHologramData; | ||
import de.oliver.fancyholograms.api.trait.HologramTrait; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@ApiStatus.Experimental | ||
public class MultiplePagesTrait extends HologramTrait { | ||
|
||
private static final int NEXT_PAGE_DELAY_SECONDS = 5; | ||
|
||
private final List<Page> pages; | ||
private int currentPageIdx; | ||
|
||
public MultiplePagesTrait() { | ||
super("multiple_pages"); | ||
this.pages = new ArrayList<>(); | ||
this.currentPageIdx = 0; | ||
|
||
this.pages.add(new Page(List.of("Page 1", "Line 1", "Line 2"))); | ||
this.pages.add(new Page(List.of("Page 2", "Line 1", "Line 2"))); | ||
this.pages.add(new Page(List.of("Page 3", "Line 1", "Line 2"))); | ||
} | ||
|
||
@Override | ||
public void onAttach() { | ||
if (!(hologram.getData() instanceof TextHologramData td)) { | ||
throw new IllegalStateException("Hologram must be text hologram to use MultiplePagesTrait"); | ||
} | ||
|
||
hologramThread.scheduleWithFixedDelay(() -> { | ||
Page currentPage = pages.get(currentPageIdx); | ||
td.setText(new ArrayList<>(currentPage.lines())); | ||
|
||
currentPageIdx = (currentPageIdx + 1) % pages.size(); // cycle through pages | ||
}, 0, NEXT_PAGE_DELAY_SECONDS, TimeUnit.SECONDS); | ||
} | ||
|
||
@Override | ||
public void save() { | ||
//TODO save pages to data | ||
} | ||
|
||
@Override | ||
public void load() { | ||
//TODO load pages from data | ||
} | ||
|
||
record Page(List<String> lines) { | ||
|
||
public void addLine(String line) { | ||
lines.add(line); | ||
} | ||
|
||
public void removeLine(int index) { | ||
lines.remove(index); | ||
} | ||
} | ||
} |