code improvement !1
This commit is contained in:
parent
09c1357e1c
commit
8beaa3d290
2 changed files with 8 additions and 11 deletions
|
@ -6,6 +6,8 @@ import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
import com.github.steveice10.packetlib.event.session.*;
|
import com.github.steveice10.packetlib.event.session.*;
|
||||||
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
|
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundGameProfilePacket;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -16,6 +18,7 @@ import lombok.Setter;
|
||||||
public class Client {
|
public class Client {
|
||||||
@Getter private Session session;
|
@Getter private Session session;
|
||||||
@Getter private final List<SessionListener> listeners = new ArrayList<>();
|
@Getter private final List<SessionListener> listeners = new ArrayList<>();
|
||||||
|
@Getter private GameProfile profile;
|
||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
private int port;
|
private int port;
|
||||||
|
@ -44,14 +47,15 @@ public class Client {
|
||||||
session.addListener(new SessionAdapter () {
|
session.addListener(new SessionAdapter () {
|
||||||
@Override public void packetReceived(Session session, Packet packet) { for (SessionListener listener : listeners) listener.packetReceived(session, packet); }
|
@Override public void packetReceived(Session session, Packet packet) { for (SessionListener listener : listeners) listener.packetReceived(session, packet); }
|
||||||
@Override public void packetSending (PacketSendingEvent event) { for (SessionListener listener : listeners) listener.packetSending(event); }
|
@Override public void packetSending (PacketSendingEvent event) { for (SessionListener listener : listeners) listener.packetSending(event); }
|
||||||
@Override public void packetSent (Session session, Packet packet) { for (SessionListener listener : listeners) listener.packetSent(session, packet); }
|
@Override public void packetSent (Session session, Packet packet) {
|
||||||
|
if (packet instanceof ClientboundGameProfilePacket) profile = ((ClientboundGameProfilePacket) packet).getProfile();
|
||||||
|
for (SessionListener listener : listeners) listener.packetSent(session, packet);
|
||||||
|
}
|
||||||
@Override public void packetError (PacketErrorEvent event) {
|
@Override public void packetError (PacketErrorEvent event) {
|
||||||
event.getCause().printStackTrace();
|
event.getCause().printStackTrace();
|
||||||
event.setSuppress(true);
|
event.setSuppress(true);
|
||||||
for (SessionListener listener : listeners) listener.packetError(event);
|
for (SessionListener listener : listeners) listener.packetError(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void connected (ConnectedEvent event) { for (SessionListener listener : listeners) listener.connected(event); }
|
@Override public void connected (ConnectedEvent event) { for (SessionListener listener : listeners) listener.connected(event); }
|
||||||
@Override public void disconnecting (DisconnectingEvent event) { for (SessionListener listener : listeners) listener.disconnecting(event); }
|
@Override public void disconnecting (DisconnectingEvent event) { for (SessionListener listener : listeners) listener.disconnecting(event); }
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import land.chipmunk.chipmunkbot.util.UUIDUtilities;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDisguisedChatPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDisguisedChatPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundGameProfilePacket; // TODO: Move uuid detection elsewhere
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
|
||||||
|
@ -38,7 +37,6 @@ import land.chipmunk.chipmunkbot.systemChat.*;
|
||||||
public class ChatPlugin extends SessionAdapter {
|
public class ChatPlugin extends SessionAdapter {
|
||||||
private final ChipmunkBot client;
|
private final ChipmunkBot client;
|
||||||
@Getter private List<Listener> listeners = new ArrayList<>();
|
@Getter private List<Listener> listeners = new ArrayList<>();
|
||||||
private UUID uuid; // TODO: Move uuid detection elsewhere
|
|
||||||
|
|
||||||
private List<SystemChatParser> systemChatParsers;
|
private List<SystemChatParser> systemChatParsers;
|
||||||
|
|
||||||
|
@ -66,7 +64,6 @@ public class ChatPlugin extends SessionAdapter {
|
||||||
if (packet instanceof ClientboundSystemChatPacket) packetReceived(session, (ClientboundSystemChatPacket) packet);
|
if (packet instanceof ClientboundSystemChatPacket) packetReceived(session, (ClientboundSystemChatPacket) packet);
|
||||||
else if (packet instanceof ClientboundPlayerChatPacket) packetReceived(session, (ClientboundPlayerChatPacket) packet);
|
else if (packet instanceof ClientboundPlayerChatPacket) packetReceived(session, (ClientboundPlayerChatPacket) packet);
|
||||||
else if (packet instanceof ClientboundDisguisedChatPacket) packetReceived(session, (ClientboundDisguisedChatPacket) packet);
|
else if (packet instanceof ClientboundDisguisedChatPacket) packetReceived(session, (ClientboundDisguisedChatPacket) packet);
|
||||||
else if (packet instanceof ClientboundGameProfilePacket) packetReceived(session, (ClientboundGameProfilePacket) packet); // TODO: Move uuid detection elsewhere
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void packetReceived (Session session, ClientboundSystemChatPacket packet) {
|
public void packetReceived (Session session, ClientboundSystemChatPacket packet) {
|
||||||
|
@ -114,10 +111,6 @@ public class ChatPlugin extends SessionAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void packetReceived (Session session, ClientboundGameProfilePacket packet) {
|
|
||||||
uuid = packet.getProfile().getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ? Should this be here?
|
// ? Should this be here?
|
||||||
// TODO: Break up the method to make it less messy
|
// TODO: Break up the method to make it less messy
|
||||||
public void tellraw (Component message, String targets) {
|
public void tellraw (Component message, String targets) {
|
||||||
|
@ -146,7 +139,7 @@ public class ChatPlugin extends SessionAdapter {
|
||||||
final Session session = client.session();
|
final Session session = client.session();
|
||||||
|
|
||||||
session.send(new ServerboundSetCreativeModeSlotPacket(26, new ItemStack(1 /* stone */, 1, itemTag)));
|
session.send(new ServerboundSetCreativeModeSlotPacket(26, new ItemStack(1 /* stone */, 1, itemTag)));
|
||||||
client.core().run("minecraft:tellraw " + targets + " {\"nbt\":\"Inventory[0].tag.m\",\"entity\":\"" + uuid.toString() + "\",\"interpret\":" + interpret + "}"); // TODO: Use GSON instead of concatenating strings, and hardcode less of this (it shouldn't matter here but yes)
|
client.core().run("minecraft:tellraw " + targets + " {\"nbt\":\"Inventory[0].tag.m\",\"entity\":\"" + client.profile().getIdAsString() + "\",\"interpret\":" + interpret + "}"); // TODO: Use GSON instead of concatenating strings, and hardcode less of this (it shouldn't matter here but yes)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue