Plumbed in varp update handling

This commit is contained in:
ceikry 2022-07-10 15:31:18 -05:00 committed by Ceikry
parent d69ac42050
commit 4bbb8e0458
6 changed files with 103 additions and 2 deletions

View file

@ -1,4 +1,4 @@
AUTHOR='Me'
DESCRIPTION='Make sure to rename both the MyPlugin folder and the package statement in plugin.java!
AUTHOR='Ceikry'
DESCRIPTION='Enables visual display of component children and a log of interface-related varps.'
VERSION=-1.1

View file

@ -0,0 +1,70 @@
package VarpLogPlugin;
import plugin.Plugin;
import plugin.api.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class plugin extends Plugin {
boolean isEnabled;
int MAX_VISIBLE_UPDATES = 5;
ArrayList<String> varpUpdates = new ArrayList<>();
ArrayList<String> updateCreationTime = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
@Override
public void Init() {
if (API.IsHD()) MAX_VISIBLE_UPDATES = 10;
}
@Override
public void OnVarpUpdate(int id, int value) {
if (!isEnabled) return;
if (varpUpdates.size() == MAX_VISIBLE_UPDATES) {
varpUpdates.remove(0);
updateCreationTime.remove(0);
}
varpUpdates.add(id + " =<gt> " + value);
String formattedTime = sdf.format(new Date());
updateCreationTime.add(formattedTime);
System.out.println("[VARP Update]" + formattedTime + " " + id + "->" + value);
}
@Override
public void Draw(long timeDelta) {
if (!isEnabled) return;
int startX = 10;
int startY = 30;
API.DrawText(FontType.SMALL, FontColor.YELLOW, TextModifier.LEFT, "Varp Updates:", startX, startY);
for (int i = 0; i < varpUpdates.size(); i++){
String update = varpUpdates.get(i);
String time = updateCreationTime.get(i);
API.DrawText(
FontType.SMALL,
FontColor.YELLOW,
TextModifier.LEFT,
"[" + time + "] " + update,
startX,
startY + (i + 1) * 15
);
}
}
@Override
public void ProcessCommand(String commandStr, String[] args) {
if (!API.PlayerHasPrivilege(Privileges.JMOD)) return;
if (commandStr.equalsIgnoreCase("::varplog")) {
isEnabled = !isEnabled;
}
}
}

View file

@ -0,0 +1,4 @@
AUTHOR='Ceikry'
DESCRIPTION='Draws some info about varp changes on the screen.'
VERSION=-1.0