forked from ChomeNS/chomens-bot-java
finally a team plugin !!!
This commit is contained in:
parent
85c779062a
commit
572dfbc9f7
3 changed files with 113 additions and 0 deletions
|
@ -52,6 +52,7 @@ public class Bot {
|
|||
@Getter private PositionPlugin position;
|
||||
@Getter private SelfCarePlugin selfCare;
|
||||
@Getter private CorePlugin core;
|
||||
@Getter private TeamPlugin team;
|
||||
@Getter private PlayersPlugin players;
|
||||
@Getter private TabCompletePlugin tabComplete;
|
||||
@Getter private CommandHandlerPlugin commandHandler;
|
||||
|
@ -97,6 +98,7 @@ public class Bot {
|
|||
this.position = new PositionPlugin(this);
|
||||
this.selfCare = new SelfCarePlugin(this);
|
||||
this.core = new CorePlugin(this);
|
||||
this.team = new TeamPlugin(this);
|
||||
this.players = new PlayersPlugin(this);
|
||||
this.tabComplete = new TabCompletePlugin(this);
|
||||
this.commandHandler = new CommandHandlerPlugin(this);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.data;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility;
|
||||
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Team {
|
||||
@Getter @Setter private String teamName;
|
||||
@Getter private List<String> players;
|
||||
@Getter @Setter private Component displayName;
|
||||
@Getter @Setter private boolean friendlyFire;
|
||||
@Getter @Setter private boolean seeFriendlyInvisibles;
|
||||
@Getter @Setter private NameTagVisibility nametagVisibility;
|
||||
@Getter @Setter private CollisionRule collisionRule;
|
||||
@Getter @Setter private TeamColor color;
|
||||
@Getter @Setter private Component prefix;
|
||||
@Getter @Setter private Component suffix;
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.scoreboard.ClientboundSetPlayerTeamPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.Team;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TeamPlugin extends Bot.Listener {
|
||||
@Getter private final List<Team> teams = new ArrayList<>();
|
||||
|
||||
public TeamPlugin (Bot bot) {
|
||||
bot.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundSetPlayerTeamPacket) packetReceived((ClientboundSetPlayerTeamPacket) packet);
|
||||
}
|
||||
|
||||
public void packetReceived(ClientboundSetPlayerTeamPacket packet) {
|
||||
switch (packet.getAction()) {
|
||||
case CREATE -> {
|
||||
final Team team = new Team(
|
||||
packet.getTeamName(),
|
||||
List.of(packet.getPlayers()),
|
||||
packet.getDisplayName(),
|
||||
packet.isFriendlyFire(),
|
||||
packet.isSeeFriendlyInvisibles(),
|
||||
packet.getNameTagVisibility(),
|
||||
packet.getCollisionRule(),
|
||||
packet.getColor(),
|
||||
packet.getPrefix(),
|
||||
packet.getSuffix()
|
||||
);
|
||||
|
||||
teams.add(team);
|
||||
}
|
||||
case REMOVE -> teams.removeIf(team -> team.teamName().equals(packet.getTeamName()));
|
||||
case UPDATE -> {
|
||||
final Team team = teams
|
||||
.stream()
|
||||
.filter(eachTeam -> eachTeam.teamName().equals(packet.getTeamName()))
|
||||
.toArray(Team[]::new)[0];
|
||||
|
||||
if (team == null) return;
|
||||
|
||||
team.teamName(packet.getTeamName());
|
||||
team.displayName(packet.getDisplayName());
|
||||
team.friendlyFire(packet.isFriendlyFire());
|
||||
team.seeFriendlyInvisibles(packet.isSeeFriendlyInvisibles());
|
||||
team.nametagVisibility(packet.getNameTagVisibility());
|
||||
team.collisionRule(packet.getCollisionRule());
|
||||
team.color(packet.getColor());
|
||||
team.prefix(packet.getPrefix());
|
||||
team.suffix(packet.getSuffix());
|
||||
}
|
||||
case ADD_PLAYER -> {
|
||||
final Team team = teams
|
||||
.stream()
|
||||
.filter(eachTeam -> eachTeam.teamName().equals(packet.getTeamName()))
|
||||
.toArray(Team[]::new)[0];
|
||||
|
||||
if (team == null) return;
|
||||
|
||||
team.players().addAll(List.of(packet.getPlayers()));
|
||||
}
|
||||
case REMOVE_PLAYER -> {
|
||||
final Team team = teams
|
||||
.stream()
|
||||
.filter(eachTeam -> eachTeam.teamName().equals(packet.getTeamName()))
|
||||
.toArray(Team[]::new)[0];
|
||||
|
||||
if (team == null) return;
|
||||
|
||||
team.players().removeAll(List.of(packet.getPlayers()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue