add unused sus

This commit is contained in:
ChomeNS 2023-03-27 11:44:14 +07:00
parent 379303ba69
commit 5c3e0efef3

View file

@ -2,6 +2,7 @@ package me.chayapak1.chomens_bot.plugins;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction; import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoPacket;
import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.event.session.SessionAdapter;
@ -19,6 +20,8 @@ public class PlayersPlugin extends SessionAdapter {
private final Bot bot; private final Bot bot;
@Getter private List<MutablePlayerListEntry> list = new ArrayList<>(); @Getter private List<MutablePlayerListEntry> list = new ArrayList<>();
private final List<PlayerListener> listeners = new ArrayList<>();
public PlayersPlugin (Bot bot) { public PlayersPlugin (Bot bot) {
this.bot = bot; this.bot = bot;
bot.addListener(this); bot.addListener(this);
@ -78,28 +81,44 @@ public class PlayersPlugin extends SessionAdapter {
final MutablePlayerListEntry duplicate = getEntry(newEntry); final MutablePlayerListEntry duplicate = getEntry(newEntry);
if (duplicate != null) list.remove(duplicate); if (duplicate != null) list.remove(duplicate);
list.add(new MutablePlayerListEntry(newEntry)); final MutablePlayerListEntry target = new MutablePlayerListEntry(newEntry);
list.add(target);
for (PlayerListener listener : listeners) { listener.playerJoined(target); }
} }
private void updateGamemode (PlayerListEntry newEntry) { private void updateGamemode (PlayerListEntry newEntry) {
final MutablePlayerListEntry target = getEntry(newEntry); final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return; if (target == null) return;
target.gamemode(newEntry.getGameMode()); final GameMode gameMode = newEntry.getGameMode();
target.gamemode(gameMode);
for (PlayerListener listener : listeners) { listener.playerGameModeUpdated(target, gameMode); }
} }
private void updateLatency (PlayerListEntry newEntry) { private void updateLatency (PlayerListEntry newEntry) {
final MutablePlayerListEntry target = getEntry(newEntry); final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return; if (target == null) return;
target.latency(newEntry.getPing()); final int ping = newEntry.getPing();
target.latency(ping);
for (PlayerListener listener : listeners) { listener.playerLatencyUpdated(target, ping); }
} }
private void updateDisplayName (PlayerListEntry newEntry) { private void updateDisplayName (PlayerListEntry newEntry) {
final MutablePlayerListEntry target = getEntry(newEntry); final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return; if (target == null) return;
target.displayName(newEntry.getDisplayName()); final Component displayName = newEntry.getDisplayName();
target.displayName(displayName);
for (PlayerListener listener : listeners) { listener.playerDisplayNameUpdated(target, displayName); }
} }
private void removePlayer (PlayerListEntry newEntry) { private void removePlayer (PlayerListEntry newEntry) {
@ -117,7 +136,20 @@ public class PlayersPlugin extends SessionAdapter {
} }
list.remove(target); list.remove(target);
for (PlayerListener listener : listeners) { listener.playerLeft(target); }
return packet; return packet;
}); });
} }
public void addListener (PlayerListener listener) { listeners.add(listener); }
public static class PlayerListener {
public void playerJoined (MutablePlayerListEntry target) {}
public void playerGameModeUpdated (MutablePlayerListEntry target, GameMode gameMode) {}
public void playerLatencyUpdated (MutablePlayerListEntry target, int ping) {}
public void playerDisplayNameUpdated (MutablePlayerListEntry target, Component displayName) {}
public void playerLeft (MutablePlayerListEntry target) {}
}
} }