Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Paper tag base and tick_times tag (#2192)
* Add Paper tag base and tick_times tag * Return durations for paper tick_times * Add missing paper key to docs
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 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
46 changes: 46 additions & 0 deletions
46
paper/src/main/java/com/denizenscript/denizen/paper/tags/PaperTagBase.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,46 @@ | ||
package com.denizenscript.denizen.paper.tags; | ||
|
||
import com.denizenscript.denizencore.objects.core.DurationTag; | ||
import com.denizenscript.denizencore.objects.core.ListTag; | ||
import com.denizenscript.denizencore.tags.TagRunnable; | ||
import com.denizenscript.denizencore.tags.Attribute; | ||
import com.denizenscript.denizencore.tags.ReplaceableTagEvent; | ||
import com.denizenscript.denizencore.tags.TagManager; | ||
import org.bukkit.Bukkit; | ||
|
||
public class PaperTagBase { | ||
|
||
public PaperTagBase() { | ||
TagManager.registerTagHandler(new TagRunnable.RootForm() { | ||
@Override | ||
public void run(ReplaceableTagEvent event) { | ||
paperTag(event); | ||
} | ||
}, "paper"); | ||
} | ||
|
||
public void paperTag(ReplaceableTagEvent event) { | ||
if (!event.matches("paper") || event.replaced()) { | ||
return; | ||
} | ||
|
||
Attribute attribute = event.getAttributes().fulfill(1); | ||
|
||
// <--[tag] | ||
// @attribute <paper.tick_times> | ||
// @returns ListTag(DurationTag) | ||
// @Plugin Paper | ||
// @description | ||
// Returns a sample of the server's last 5s of tick times as a list of durations. | ||
// On average, a tick should take 50ms or less for a stable 20tps. | ||
// --> | ||
if (attribute.startsWith("tick_times")) { | ||
ListTag list = new ListTag(); | ||
for (long time : Bukkit.getServer().getTickTimes()) { | ||
list.addObject(new DurationTag(time / 1000000000D)); | ||
} | ||
event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1))); | ||
return; | ||
} | ||
} | ||
} |