-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔥 Remove debug, API is now working and probably finished.
- Loading branch information
Showing
6 changed files
with
63 additions
and
49 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
44 changes: 0 additions & 44 deletions
44
src/main/java/com/mattmx/nametags/entity/TestImplTrait.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
src/main/java/com/mattmx/nametags/entity/trait/RefreshTrait.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,52 @@ | ||
package com.mattmx.nametags.entity.trait; | ||
|
||
import com.mattmx.nametags.entity.NameTagEntity; | ||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Consumer; | ||
|
||
public class RefreshTrait extends Trait { | ||
private final @NotNull ScheduledTask task; | ||
private boolean paused = false; | ||
|
||
public RefreshTrait(@NotNull JavaPlugin plugin, long period, TimeUnit unit, Consumer<NameTagEntity> update) { | ||
this.task = Bukkit.getAsyncScheduler() | ||
.runAtFixedRate(plugin, (task) -> { | ||
|
||
if (!this.isPaused()) { | ||
update.accept(getTag()); | ||
} | ||
|
||
}, 0L, period, unit); | ||
} | ||
|
||
public void setPaused(boolean paused) { | ||
this.paused = paused; | ||
} | ||
|
||
public boolean isPaused() { | ||
return this.paused; | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
task.cancel(); | ||
} | ||
|
||
public static @NotNull RefreshTrait ofMinutes(@NotNull JavaPlugin plugin, long minutes, Consumer<NameTagEntity> update) { | ||
return new RefreshTrait(plugin, minutes, TimeUnit.MINUTES, update); | ||
} | ||
|
||
public static @NotNull RefreshTrait ofSeconds(@NotNull JavaPlugin plugin, long seconds, Consumer<NameTagEntity> update) { | ||
return new RefreshTrait(plugin, seconds, TimeUnit.SECONDS, update); | ||
} | ||
|
||
public static @NotNull RefreshTrait ofTicks(@NotNull JavaPlugin plugin, long ticks, Consumer<NameTagEntity> update) { | ||
return new RefreshTrait(plugin, ticks * 50, TimeUnit.MILLISECONDS, update); | ||
} | ||
|
||
} |
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