add global ticker
the performance is the same its still using like 100 - 300 heap usage doesn't really do anyhting.,.,,. real
This commit is contained in:
parent
7232defa7f
commit
8155ada338
9 changed files with 172 additions and 127 deletions
|
@ -4,9 +4,7 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="50f184fa-7bed-4956-baf5-7586ff26ea08" name="Changes" comment="fix mabe mabe untested">
|
<list default="true" id="50f184fa-7bed-4956-baf5-7586ff26ea08" name="Changes" comment="add bot.profile() mabe" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
@ -57,19 +55,19 @@
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "master",
|
"git-widget-placeholder": "master",
|
||||||
"jdk.selected.JAVA_MODULE": "17",
|
"jdk.selected.JAVA_MODULE": "17",
|
||||||
"last_opened_file_path": "/home/chayapak1/projects/chipmunkmod",
|
"last_opened_file_path": "/home/chayapak1/projects/chipmunkmod",
|
||||||
"project.structure.last.edited": "Modules",
|
"project.structure.last.edited": "Modules",
|
||||||
"project.structure.proportion": "0.0",
|
"project.structure.proportion": "0.0",
|
||||||
"project.structure.side.proportion": "0.0",
|
"project.structure.side.proportion": "0.0",
|
||||||
"settings.editor.selected.configurable": "reference.settings.ide.settings.new.ui"
|
"settings.editor.selected.configurable": "reference.settings.ide.settings.new.ui"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="MoveFile.RECENT_KEYS">
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
<recent name="$PROJECT_DIR$/.idea" />
|
<recent name="$PROJECT_DIR$/.idea" />
|
||||||
|
@ -111,20 +109,6 @@
|
||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1680245437032</updated>
|
<updated>1680245437032</updated>
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00099" summary="sex">
|
|
||||||
<created>1682167370618</created>
|
|
||||||
<option name="number" value="00099" />
|
|
||||||
<option name="presentableId" value="LOCAL-00099" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1682167370618</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00100" summary="probably improve logquery?">
|
|
||||||
<created>1682168732774</created>
|
|
||||||
<option name="number" value="00100" />
|
|
||||||
<option name="presentableId" value="LOCAL-00100" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1682168732774</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00101" summary="forgor to set the thread to null">
|
<task id="LOCAL-00101" summary="forgor to set the thread to null">
|
||||||
<created>1682169054135</created>
|
<created>1682169054135</created>
|
||||||
<option name="number" value="00101" />
|
<option name="number" value="00101" />
|
||||||
|
@ -454,7 +438,21 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1682854469605</updated>
|
<updated>1682854469605</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="148" />
|
<task id="LOCAL-00148" summary="patch skiddie exploit">
|
||||||
|
<created>1682901042864</created>
|
||||||
|
<option name="number" value="00148" />
|
||||||
|
<option name="presentableId" value="LOCAL-00148" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1682901042865</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00149" summary="add bot.profile() mabe">
|
||||||
|
<created>1682905214835</created>
|
||||||
|
<option name="number" value="00149" />
|
||||||
|
<option name="presentableId" value="LOCAL-00149" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1682905214836</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="150" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
@ -469,8 +467,6 @@
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="change stuff a bit" />
|
|
||||||
<MESSAGE value="fix fallback name?" />
|
|
||||||
<MESSAGE value="make time output shorter? mabe" />
|
<MESSAGE value="make time output shorter? mabe" />
|
||||||
<MESSAGE value="chat queue delay in config" />
|
<MESSAGE value="chat queue delay in config" />
|
||||||
<MESSAGE value="new 1.19.4 update i guess" />
|
<MESSAGE value="new 1.19.4 update i guess" />
|
||||||
|
@ -494,7 +490,9 @@
|
||||||
<MESSAGE value="packet queue farded it" />
|
<MESSAGE value="packet queue farded it" />
|
||||||
<MESSAGE value="i forgor" />
|
<MESSAGE value="i forgor" />
|
||||||
<MESSAGE value="fix mabe mabe untested" />
|
<MESSAGE value="fix mabe mabe untested" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="fix mabe mabe untested" />
|
<MESSAGE value="patch skiddie exploit" />
|
||||||
|
<MESSAGE value="add bot.profile() mabe" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="add bot.profile() mabe" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class Bot {
|
||||||
@Getter @Setter private LoggerPlugin logger; // in ConsolePlugin
|
@Getter @Setter private LoggerPlugin logger; // in ConsolePlugin
|
||||||
@Getter @Setter private DiscordPlugin discord; // same for this one too
|
@Getter @Setter private DiscordPlugin discord; // same for this one too
|
||||||
|
|
||||||
|
@Getter private TickPlugin tick;
|
||||||
@Getter private ChatPlugin chat;
|
@Getter private ChatPlugin chat;
|
||||||
@Getter private PositionPlugin position;
|
@Getter private PositionPlugin position;
|
||||||
@Getter private SelfCarePlugin selfCare;
|
@Getter private SelfCarePlugin selfCare;
|
||||||
|
@ -89,6 +90,7 @@ public class Bot {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ready () {
|
public void ready () {
|
||||||
|
this.tick = new TickPlugin(this);
|
||||||
this.chat = new ChatPlugin(this);
|
this.chat = new ChatPlugin(this);
|
||||||
this.position = new PositionPlugin(this);
|
this.position = new PositionPlugin(this);
|
||||||
this.selfCare = new SelfCarePlugin(this);
|
this.selfCare = new SelfCarePlugin(this);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
|
||||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
import land.chipmunk.chayapak.chomens_bot.data.BossBar;
|
import land.chipmunk.chayapak.chomens_bot.data.BossBar;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -9,14 +8,10 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class BossbarManagerPlugin extends Bot.Listener {
|
public class BossbarManagerPlugin extends Bot.Listener {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
private ScheduledFuture<?> tickTask;
|
|
||||||
|
|
||||||
private final Map<String, BossBar> bossBars = new HashMap<>();
|
private final Map<String, BossBar> bossBars = new HashMap<>();
|
||||||
|
|
||||||
@Getter @Setter private boolean enabled = true;
|
@Getter @Setter private boolean enabled = true;
|
||||||
|
@ -28,25 +23,16 @@ public class BossbarManagerPlugin extends Bot.Listener {
|
||||||
public BossbarManagerPlugin (Bot bot) {
|
public BossbarManagerPlugin (Bot bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
|
|
||||||
bot.core().addListener(new CorePlugin.Listener() {
|
bot.tick().addListener(new TickPlugin.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void ready() {
|
public void onTick() {
|
||||||
BossbarManagerPlugin.this.ready();
|
tick();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.addListener(this);
|
bot.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ready () {
|
|
||||||
tickTask = bot.executor().scheduleAtFixedRate(this::tick, 0, 50, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disconnected(DisconnectedEvent event) {
|
|
||||||
tickTask.cancel(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick () {
|
public void tick () {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
for (Map.Entry<String, BossBar> _bossBar : bossBars.entrySet()) {
|
for (Map.Entry<String, BossBar> _bossBar : bossBars.entrySet()) {
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
// please ignore my shitcode
|
// please ignore my shitcode
|
||||||
public class DiscordPlugin {
|
public class DiscordPlugin {
|
||||||
|
@ -71,7 +70,12 @@ public class DiscordPlugin {
|
||||||
|
|
||||||
if (channelAlreadyAddedListeners) return;
|
if (channelAlreadyAddedListeners) return;
|
||||||
|
|
||||||
bot.executor().scheduleAtFixedRate(() -> onDiscordTick(channelId), 0, 50, TimeUnit.MILLISECONDS);
|
bot.tick().addListener(new TickPlugin.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTick() {
|
||||||
|
onDiscordTick(channelId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
bot.chat().addListener(new ChatPlugin.ChatListener() {
|
bot.chat().addListener(new ChatPlugin.ChatListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,7 +10,6 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class FilterPlugin extends PlayersPlugin.PlayerListener {
|
public class FilterPlugin extends PlayersPlugin.PlayerListener {
|
||||||
|
@ -23,7 +22,12 @@ public class FilterPlugin extends PlayersPlugin.PlayerListener {
|
||||||
|
|
||||||
bot.players().addListener(this);
|
bot.players().addListener(this);
|
||||||
|
|
||||||
bot.executor().scheduleAtFixedRate(this::tick, 0, 50, TimeUnit.MILLISECONDS);
|
bot.tick().addListener(new TickPlugin.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTick() {
|
||||||
|
tick();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private FilteredPlayer getPlayer (String name) {
|
private FilteredPlayer getPlayer (String name) {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class HashingPlugin {
|
public class HashingPlugin {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
@ -16,7 +15,12 @@ public class HashingPlugin {
|
||||||
public HashingPlugin (Bot bot) {
|
public HashingPlugin (Bot bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
|
|
||||||
bot.executor().scheduleAtFixedRate(this::update, 0, 1, TimeUnit.SECONDS);
|
bot.tick().addListener(new TickPlugin.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTick() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update () {
|
public void update () {
|
||||||
|
|
|
@ -17,14 +17,10 @@ import java.net.URL;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class MusicPlayerPlugin extends Bot.Listener {
|
public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
private ScheduledFuture<?> playTask;
|
|
||||||
|
|
||||||
public static final String SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic]";
|
public static final String SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic]";
|
||||||
public static File SONG_DIR = new File("songs");
|
public static File SONG_DIR = new File("songs");
|
||||||
static {
|
static {
|
||||||
|
@ -90,7 +86,9 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void coreReady () {
|
public void coreReady () {
|
||||||
final Runnable task = () -> {
|
bot.tick().addListener(new TickPlugin.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTick() {
|
||||||
if (loaderThread != null && !loaderThread.isAlive()) {
|
if (loaderThread != null && !loaderThread.isAlive()) {
|
||||||
if (loaderThread.exception != null) {
|
if (loaderThread.exception != null) {
|
||||||
bot.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
bot.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
||||||
|
@ -157,9 +155,8 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
currentSong.play();
|
currentSong.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
});
|
||||||
playTask = bot.executor().scheduleAtFixedRate(task, 50, 50, TimeUnit.MILLISECONDS);
|
|
||||||
|
|
||||||
if (currentSong != null) currentSong.play();
|
if (currentSong != null) currentSong.play();
|
||||||
}
|
}
|
||||||
|
@ -248,8 +245,6 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnected (DisconnectedEvent event) {
|
public void disconnected (DisconnectedEvent event) {
|
||||||
playTask.cancel(true);
|
|
||||||
|
|
||||||
if (currentSong != null) currentSong.pause(); // nice.
|
if (currentSong != null) currentSong.pause(); // nice.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class TPSPlugin extends Bot.Listener {
|
public class TPSPlugin extends Bot.Listener {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
@ -35,7 +34,12 @@ public class TPSPlugin extends Bot.Listener {
|
||||||
bot.core().addListener(new CorePlugin.Listener() {
|
bot.core().addListener(new CorePlugin.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void ready() {
|
public void ready() {
|
||||||
bot.executor().scheduleAtFixedRate(() -> updateTPSBar(), 0, 50, TimeUnit.MILLISECONDS);
|
bot.tick().addListener(new TickPlugin.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onTick() {
|
||||||
|
updateTPSBar();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||||
|
|
||||||
|
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
||||||
|
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||||
|
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class TickPlugin extends Bot.Listener {
|
||||||
|
private final Bot bot;
|
||||||
|
|
||||||
|
private ScheduledFuture<?> tickTask;
|
||||||
|
|
||||||
|
private final List<Listener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public TickPlugin (Bot bot) {
|
||||||
|
this.bot = bot;
|
||||||
|
|
||||||
|
bot.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connected(ConnectedEvent event) {
|
||||||
|
tickTask = bot.executor().scheduleAtFixedRate(this::tick, 0, 50, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tick () {
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
listener.onTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnected (DisconnectedEvent event) {
|
||||||
|
tickTask.cancel(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListener (Listener listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Listener {
|
||||||
|
public void onTick () {}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue