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" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="50f184fa-7bed-4956-baf5-7586ff26ea08" name="Changes" comment="fix mabe mabe untested">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<list default="true" id="50f184fa-7bed-4956-baf5-7586ff26ea08" name="Changes" comment="add bot.profile() mabe" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
|
@ -57,19 +55,19 @@
|
|||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"jdk.selected.JAVA_MODULE": "17",
|
||||
"last_opened_file_path": "/home/chayapak1/projects/chipmunkmod",
|
||||
"project.structure.last.edited": "Modules",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.0",
|
||||
"settings.editor.selected.configurable": "reference.settings.ide.settings.new.ui"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"jdk.selected.JAVA_MODULE": "17",
|
||||
"last_opened_file_path": "/home/chayapak1/projects/chipmunkmod",
|
||||
"project.structure.last.edited": "Modules",
|
||||
"project.structure.proportion": "0.0",
|
||||
"project.structure.side.proportion": "0.0",
|
||||
"settings.editor.selected.configurable": "reference.settings.ide.settings.new.ui"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/.idea" />
|
||||
|
@ -111,20 +109,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680245437032</updated>
|
||||
</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">
|
||||
<created>1682169054135</created>
|
||||
<option name="number" value="00101" />
|
||||
|
@ -454,7 +438,21 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1682854469605</updated>
|
||||
</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 />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -469,8 +467,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="change stuff a bit" />
|
||||
<MESSAGE value="fix fallback name?" />
|
||||
<MESSAGE value="make time output shorter? mabe" />
|
||||
<MESSAGE value="chat queue delay in config" />
|
||||
<MESSAGE value="new 1.19.4 update i guess" />
|
||||
|
@ -494,7 +490,9 @@
|
|||
<MESSAGE value="packet queue farded it" />
|
||||
<MESSAGE value="i forgor" />
|
||||
<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 name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
|
|
|
@ -46,6 +46,7 @@ public class Bot {
|
|||
@Getter @Setter private LoggerPlugin logger; // in ConsolePlugin
|
||||
@Getter @Setter private DiscordPlugin discord; // same for this one too
|
||||
|
||||
@Getter private TickPlugin tick;
|
||||
@Getter private ChatPlugin chat;
|
||||
@Getter private PositionPlugin position;
|
||||
@Getter private SelfCarePlugin selfCare;
|
||||
|
@ -89,6 +90,7 @@ public class Bot {
|
|||
}
|
||||
|
||||
public void ready () {
|
||||
this.tick = new TickPlugin(this);
|
||||
this.chat = new ChatPlugin(this);
|
||||
this.position = new PositionPlugin(this);
|
||||
this.selfCare = new SelfCarePlugin(this);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
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.data.BossBar;
|
||||
import lombok.Getter;
|
||||
|
@ -9,14 +8,10 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BossbarManagerPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> tickTask;
|
||||
|
||||
private final Map<String, BossBar> bossBars = new HashMap<>();
|
||||
|
||||
@Getter @Setter private boolean enabled = true;
|
||||
|
@ -28,25 +23,16 @@ public class BossbarManagerPlugin extends Bot.Listener {
|
|||
public BossbarManagerPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.core().addListener(new CorePlugin.Listener() {
|
||||
bot.tick().addListener(new TickPlugin.Listener() {
|
||||
@Override
|
||||
public void ready() {
|
||||
BossbarManagerPlugin.this.ready();
|
||||
public void onTick() {
|
||||
tick();
|
||||
}
|
||||
});
|
||||
|
||||
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 () {
|
||||
if (!enabled) return;
|
||||
for (Map.Entry<String, BossBar> _bossBar : bossBars.entrySet()) {
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
// please ignore my shitcode
|
||||
public class DiscordPlugin {
|
||||
|
@ -71,7 +70,12 @@ public class DiscordPlugin {
|
|||
|
||||
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() {
|
||||
@Override
|
||||
|
|
|
@ -10,7 +10,6 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FilterPlugin extends PlayersPlugin.PlayerListener {
|
||||
|
@ -23,7 +22,12 @@ public class FilterPlugin extends PlayersPlugin.PlayerListener {
|
|||
|
||||
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) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import land.chipmunk.chayapak.chomens_bot.Bot;
|
|||
import lombok.Getter;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class HashingPlugin {
|
||||
private final Bot bot;
|
||||
|
@ -16,7 +15,12 @@ public class HashingPlugin {
|
|||
public HashingPlugin (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 () {
|
||||
|
|
|
@ -17,14 +17,10 @@ import java.net.URL;
|
|||
import java.nio.file.Path;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MusicPlayerPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> playTask;
|
||||
|
||||
public static final String SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic]";
|
||||
public static File SONG_DIR = new File("songs");
|
||||
static {
|
||||
|
@ -90,76 +86,77 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
}
|
||||
|
||||
public void coreReady () {
|
||||
final Runnable task = () -> {
|
||||
if (loaderThread != null && !loaderThread.isAlive()) {
|
||||
if (loaderThread.exception != null) {
|
||||
bot.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
||||
} else {
|
||||
songQueue.add(loaderThread.song);
|
||||
bot.chat().tellraw(Component.translatable("Added %s to the song queue", Component.empty().append(loaderThread.song.name).color(NamedTextColor.GOLD)));
|
||||
}
|
||||
loaderThread = null;
|
||||
}
|
||||
|
||||
if (currentSong == null) {
|
||||
if (songQueue.size() == 0) return;
|
||||
|
||||
addBossBar();
|
||||
|
||||
currentSong = songQueue.get(0); // songQueue.poll();
|
||||
bot.chat().tellraw(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.GOLD)));
|
||||
currentSong.play();
|
||||
}
|
||||
|
||||
if (currentSong.paused && ticksUntilPausedBossbar-- < 0) return;
|
||||
else ticksUntilPausedBossbar = 20;
|
||||
|
||||
BossBar bossBar = bot.bossbar().get(bossbarName);
|
||||
|
||||
if (bossBar == null) bossBar = addBossBar();
|
||||
|
||||
bossBar.players(SELECTOR);
|
||||
bossBar.name(generateBossbar());
|
||||
bossBar.color(pitch > 0 ? BossBarColor.PURPLE : BossBarColor.YELLOW);
|
||||
bossBar.visible(true);
|
||||
bossBar.style(BossBarStyle.PROGRESS);
|
||||
bossBar.value((int) Math.floor(currentSong.time * speed));
|
||||
bossBar.max(currentSong.length);
|
||||
|
||||
if (currentSong.paused) return;
|
||||
|
||||
handlePlaying();
|
||||
|
||||
if (currentSong.finished()) {
|
||||
if (loop == Loop.CURRENT) {
|
||||
currentSong.setTime(0);
|
||||
return;
|
||||
bot.tick().addListener(new TickPlugin.Listener() {
|
||||
@Override
|
||||
public void onTick() {
|
||||
if (loaderThread != null && !loaderThread.isAlive()) {
|
||||
if (loaderThread.exception != null) {
|
||||
bot.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
||||
} else {
|
||||
songQueue.add(loaderThread.song);
|
||||
bot.chat().tellraw(Component.translatable("Added %s to the song queue", Component.empty().append(loaderThread.song.name).color(NamedTextColor.GOLD)));
|
||||
}
|
||||
loaderThread = null;
|
||||
}
|
||||
|
||||
bot.chat().tellraw(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.GOLD)));
|
||||
if (currentSong == null) {
|
||||
if (songQueue.size() == 0) return;
|
||||
|
||||
if (loop == Loop.ALL) {
|
||||
skip();
|
||||
return;
|
||||
}
|
||||
addBossBar();
|
||||
|
||||
songQueue.remove();
|
||||
|
||||
if (songQueue.size() == 0) {
|
||||
stopPlaying();
|
||||
removeBossBar();
|
||||
bot.chat().tellraw(Component.text("Finished playing every song in the queue"));
|
||||
return;
|
||||
}
|
||||
if (currentSong.size() > 0) {
|
||||
currentSong = songQueue.get(0);
|
||||
currentSong.setTime(0);
|
||||
currentSong = songQueue.get(0); // songQueue.poll();
|
||||
bot.chat().tellraw(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.GOLD)));
|
||||
currentSong.play();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
playTask = bot.executor().scheduleAtFixedRate(task, 50, 50, TimeUnit.MILLISECONDS);
|
||||
if (currentSong.paused && ticksUntilPausedBossbar-- < 0) return;
|
||||
else ticksUntilPausedBossbar = 20;
|
||||
|
||||
BossBar bossBar = bot.bossbar().get(bossbarName);
|
||||
|
||||
if (bossBar == null) bossBar = addBossBar();
|
||||
|
||||
bossBar.players(SELECTOR);
|
||||
bossBar.name(generateBossbar());
|
||||
bossBar.color(pitch > 0 ? BossBarColor.PURPLE : BossBarColor.YELLOW);
|
||||
bossBar.visible(true);
|
||||
bossBar.style(BossBarStyle.PROGRESS);
|
||||
bossBar.value((int) Math.floor(currentSong.time * speed));
|
||||
bossBar.max(currentSong.length);
|
||||
|
||||
if (currentSong.paused) return;
|
||||
|
||||
handlePlaying();
|
||||
|
||||
if (currentSong.finished()) {
|
||||
if (loop == Loop.CURRENT) {
|
||||
currentSong.setTime(0);
|
||||
return;
|
||||
}
|
||||
|
||||
bot.chat().tellraw(Component.translatable("Finished playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.GOLD)));
|
||||
|
||||
if (loop == Loop.ALL) {
|
||||
skip();
|
||||
return;
|
||||
}
|
||||
|
||||
songQueue.remove();
|
||||
|
||||
if (songQueue.size() == 0) {
|
||||
stopPlaying();
|
||||
removeBossBar();
|
||||
bot.chat().tellraw(Component.text("Finished playing every song in the queue"));
|
||||
return;
|
||||
}
|
||||
if (currentSong.size() > 0) {
|
||||
currentSong = songQueue.get(0);
|
||||
currentSong.setTime(0);
|
||||
currentSong.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (currentSong != null) currentSong.play();
|
||||
}
|
||||
|
@ -248,8 +245,6 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
playTask.cancel(true);
|
||||
|
||||
if (currentSong != null) currentSong.pause(); // nice.
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TPSPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
@ -35,7 +34,12 @@ public class TPSPlugin extends Bot.Listener {
|
|||
bot.core().addListener(new CorePlugin.Listener() {
|
||||
@Override
|
||||
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