Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Defective4 committed Sep 3, 2022
1 parent ac4f529 commit 838244d
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 99 deletions.
35 changes: 3 additions & 32 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
AMCC Change Log
v1.8.1
v1.8.2

Here's a huge update, adding tons of new stuff!
A minor maintenance update

[+] Added:
- New Entity Radar tool.
It allows you to see and interact with nearby entities
including players.

- Ability to simulate right click on an entity.
You can now interact with NPCs!

- Entity tracking and auto-tracking.
Allows you to look at nearby entities, or
at entities you manually target.

- Entity attacking and auto-attacking!
You can now select an entity, or automatically
attack anything that comes near your player.
This option also includes ranged/item attacks!
Your weapon doesn't auto-switch though.

- SOCKS Proxy Support

[+] Fixed:
- Number spinners under Player tab randomly disappearing

[+] Added (from v1.8.0-pre):
- New Protocol Manager Tool
A new, poweful utility to debug traffic between client and server!
- TheAltening authentication support

[+] Fixed (from v1.8.0-pre):
- Updated Gradle build system
- Completely remade chat messages JSON parser
- Minor code improvements
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ public void packetReceived(final Packet packet, final PacketRegistry registry) {
} else if (packet instanceof ServerLoginEncryptionPacket) {
final ServerLoginEncryptionPacket sPacket = (ServerLoginEncryptionPacket) packet;
switch (cl.getAuthType()) {
default:
case Offline: {
for (final ClientListener ls : cl.getClientListeners()) {
ls.disconnected(Messages.getString("MinecraftClient.clientErrorDisconnectedNoAuth"));
Expand Down Expand Up @@ -268,12 +267,20 @@ public void packetReceived(final Packet packet, final PacketRegistry registry) {
break;
}
} catch (final Exception ex) {
ex.printStackTrace();
}

cl.sendPacket(new ClientLoginEncryptionPacket(registry, encryptedSecret, encryptedToken));
cl.enableEncryption(clientSecret);
break;
}
default: {
for (final ClientListener ls : cl.getClientListeners()) {
ls.disconnected(Messages.getString("MinecraftClient.clientErrorDisconnectedNoAuth"));
}
cl.close();
break;
}
}
} else if (packet instanceof ServerLoginResponsePacket) {
for (final ClientListener ls : cl.getClientListeners()) {
Expand Down Expand Up @@ -513,8 +520,9 @@ public void run() {

for (final ClientListener ls : cl.getClientListeners())
if (dsIgnore) {
ls.messageReceived("\u00A7cPacket " + Integer.toHexString(packet.getID()) + ": "
+ ChatMessages.parse(json), Position.CHAT);
ls.messageReceived(
"§cPacket " + Integer.toHexString(packet.getID()) + ": " + ChatMessages.parse(json),
Position.CHAT);
} else {
ls.disconnected(ChatMessages.parse(json));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,6 @@ protected void setCurrentState(final State state) {
this.state = state;
}

/**
* Connect to server specified in constructor
*
* @param username username of connecting client
* @throws IOException thrown when client was unable to connect to target server
*/
public void connect(final String username) throws IOException {
connect(AuthType.Offline, username, null);
}

private Cipher eCipher = null;
private Cipher dCipher = null;
private boolean isEncrypted = false;
Expand Down Expand Up @@ -260,6 +250,16 @@ protected void enableEncryption(final byte[] secret) throws InvalidKeyException,
private String authToken = null;
private AuthType authType = AuthType.Offline;

/**
* Connect to server specified in constructor
*
* @param username username of connecting client
* @throws IOException thrown when client was unable to connect to target server
*/
public void connect(final String username) throws IOException {
connect(AuthType.Offline, username, null);
}

/**
* Connect this client to the server
*
Expand All @@ -271,11 +271,6 @@ protected void enableEncryption(final byte[] secret) throws InvalidKeyException,
public void connect(final AuthType auth, final String token, final String password) throws IOException {
this.authType = auth;
switch (auth) {
default:
case Offline: {
this.username = token;
break;
}
case TheAltening:
case Mojang: {
final MojangUser user = MojangAPI.authenticateUser(token, auth == AuthType.Mojang ? password : "none",
Expand All @@ -285,6 +280,14 @@ public void connect(final AuthType auth, final String token, final String passwo
this.authToken = user.getAccessToken();
break;
}
case Offline: {
this.username = token;
break;
}
default: {
this.username = token;
break;
}
}

try {
Expand Down Expand Up @@ -415,6 +418,7 @@ public void run() {
}
}
} catch (final InterruptedException e) {
e.printStackTrace();
}
}
});
Expand Down Expand Up @@ -607,15 +611,6 @@ public void sendChatMessage(final String message) throws IOException {
sendPacket(PacketFactory.constructPacket(reg, "ClientChatMessagePacket", message));
}

/**
* Get entity ID of this client on server
*
* @return client's entity ID
*/
public int getEntityID() {
return entityID;
}

/**
* Used internally by {@link ClientPacketListener} to set client's entity ID
*
Expand Down Expand Up @@ -795,6 +790,15 @@ public int getEntityID(final Entity entity) {
return -1;
}

/**
* Get entity ID of this client on server
*
* @return client's entity ID
*/
public int getEntityID() {
return entityID;
}

/**
* Set client's pitch and yaw to face provided entity
*
Expand Down Expand Up @@ -956,7 +960,7 @@ public void run() {
sendPacket(PacketFactory.constructPacket(reg, "ClientPlayerPositionAndLookPacket", tx,
MinecraftClient.this.y, tz, MinecraftClient.this.yaw, 0f, true));
} catch (final Exception e) {

e.printStackTrace();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,21 @@ public static StatusInfo legacyServerListPing(final String host, final int port)
String data = new String(stringBytes, "UTF-16LE");
data = data.substring(1, data.length() - 1);

final int paraCount = data.length() - data.replace("\u00a7", "").length();
final int paraCount = data.length() - data.replace("§", "").length();
String playersString = data;
for (int x = 0; x < paraCount - 1; x++) {
playersString = playersString.substring(playersString.indexOf("\u00a7") + 1);
playersString = playersString.substring(playersString.indexOf("§") + 1);
}

final String motd = data.substring(0, data.lastIndexOf(playersString) - 1);

int online = 0;
int max = 0;

final String[] players = playersString.split("\u00a7");
final String[] players = playersString.split("§");
online = Integer.parseInt(players[0]);
max = Integer.parseInt(players[1]);
return new StatusInfo(motd, online, max, "\u00a7cLegacy", -1, null, null, new ArrayList<ModInfo>());
return new StatusInfo(motd, online, max, "§cLegacy", -1, null, null, new ArrayList<ModInfo>());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static Color translateColorCode(final String code) {
public static String translateColorName(String name) {
name = name.toLowerCase();

if (name.contains("#") && name.length() > 1) return "\u00A7" + name;
if (name.contains("#") && name.length() > 1) return "§" + name;

return colorCodes.containsKey(name) ? colorCodes.get(name) : colorCodes.get("white");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class ChatMessages {

private static final String pChar = "\u00A7";
private static final String pChar = "§";

private ChatMessages() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,18 @@ public void putItem(final int index, final ItemStack item) {
btn.removeMouseListener(ml);
}
if (item.getId() == 0) return;
String label = "\u00A7f" + itemInfo.getName();
String label = "§f" + itemInfo.getName();
try {
if (item.getNbt() != null) {
CompoundMap map = (CompoundMap) item.getNbt().getValue();
if (map.containsKey("display")) {
map = (CompoundMap) map.get("display").getValue();
if (map.containsKey("Name")) {
label = "\u00A7f" + ChatMessages.parse((String) map.get("Name").getValue());
label = "§f" + ChatMessages.parse((String) map.get("Name").getValue());
}
if (map.containsKey("Lore")) {
for (final StringTag lore : (List<StringTag>) map.get("Lore").getValue()) {
label += "\r\n\u00A75" + ChatMessages.parse(lore.getValue());
label += "\r\n§5" + ChatMessages.parse(lore.getValue());
}
}
}
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/net/defekt/mc/chatclient/ui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public void actionPerformed(final ActionEvent ev2) {
labels.get(srvLabel).add(cl);
}

final MenuItem options = new MenuItem(Messages.getString("Main.optionsMenu") + "Info");
final MenuItem options = new MenuItem(Messages.getString("Main.optionsMenu"));
options.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ev2) {
Expand Down Expand Up @@ -916,7 +916,6 @@ public void actionPerformed(final ActionEvent e) {
savedProxies.addItem(sett);
}

// TODO Lang
final JButton pxLoad = new JButton(Messages.getString("Main.load"));
pxLoad.setEnabled(false);
final JButton pxSave = new JButton(Messages.getString("Main.save"));
Expand Down Expand Up @@ -964,6 +963,7 @@ public void actionPerformed(final ActionEvent e) {
pxDelete.setEnabled(sel);
pxLoad.setEnabled(sel);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
});
Expand All @@ -979,6 +979,7 @@ public void actionPerformed(final ActionEvent e) {
pxSave.setEnabled(false);
}
} catch (final Exception ex) {
ex.printStackTrace();
}
}
});
Expand All @@ -998,6 +999,7 @@ public void actionPerformed(final ActionEvent e) {
}
}
} catch (final Exception ex) {
ex.printStackTrace();
}
}
});
Expand Down Expand Up @@ -1026,10 +1028,11 @@ public void actionPerformed(final ActionEvent e) {
}
}
} catch (final Exception ex) {
ex.printStackTrace();
}
}
});
userTabs.addTab(Messages.getString("Main.logInTab"), box); // TODO Lang
userTabs.addTab(Messages.getString("Main.logInTab"), box);
userTabs.addTab(Messages.getString("Main.proxyTab"), proxyBox);
Proxy proxyObj = null;

Expand All @@ -1052,6 +1055,7 @@ public void actionPerformed(final ActionEvent e) {
final int pport = Integer.parseInt(pxAddr[1]);
proxyObj = new Proxy(Type.SOCKS, new InetSocketAddress(phost, pport));
} catch (final Exception ex) {
ex.printStackTrace();
}
}
if (!up.isUsernameAlertSeen() && !uname.replaceAll("[^a-zA-Z0-9]", "").equals(uname)
Expand Down Expand Up @@ -1406,8 +1410,7 @@ public void run() {
pingField.setValue(up.getAdditionalPing());
SwingUtils.alignSpinner(pingField);

final JSpinner maxPacketsOnListField = new JSpinner(new SpinnerNumberModel(1, 1, 50000, 1)); // TODO Lang
maxPacketsOnListField.setToolTipText("TODO");
final JSpinner maxPacketsOnListField = new JSpinner(new SpinnerNumberModel(1, 1, 50000, 1));
maxPacketsOnListField.setValue(up.getMaxPacketsOnList());
SwingUtils.alignSpinner(maxPacketsOnListField);

Expand Down Expand Up @@ -1871,7 +1874,7 @@ public void actionPerformed(final ActionEvent e) {
up.setDisablePacketAnalyzer(disablePacketAnalyzer.isSelected());
up.setResourcePackBehavior(rsBehavior);
up.setShowResourcePackMessages(showResourcePackMessages);
up.setResourcePackMessage(resourcePackMessage.replace("&", "\u00A7"));
up.setResourcePackMessage(resourcePackMessage.replace("&", "§"));
up.setResourcePackMessagePosition(resourcePackMessagePosition);

up.setSkinFetchRule(skinFetchRule);
Expand Down Expand Up @@ -2721,7 +2724,6 @@ public void actionPerformed(final ActionEvent e) {
}
});

// TODO Lang
trackingBox.add(new JLabel(Messages.getString("Main.trackingCurrent") + ": "));
trackingBox.add(trackingField);

Expand Down Expand Up @@ -3713,8 +3715,7 @@ public void run() {
}
} catch (final Exception e) {
SwingUtils.appendColoredText(
"\u00a7c" + Messages.getString("Main.connectionFailedChatMessage") + e.toString(),
pane);
"§c" + Messages.getString("Main.connectionFailedChatMessage") + e.toString(), pane);
e.printStackTrace();
}
break;
Expand Down Expand Up @@ -3843,7 +3844,7 @@ public void run() {
}
}
} catch (final Exception e2) {
// e2.printStackTrace();
e2.printStackTrace();
}
}
}
Expand Down Expand Up @@ -3978,10 +3979,8 @@ public void run() {
@Override
public void disconnected(final String reason) {
autoMessagesThread.interrupt();
SwingUtils.appendColoredText(
"\u00a7c" + Messages.getString("Main.connectionLostChatMessage") + ": \r\n"
+ reason + "\r\n",
jtp);
SwingUtils.appendColoredText("§c" + Messages.getString("Main.connectionLostChatMessage")
+ ": \r\n" + reason + "\r\n", jtp);

if (trayIcon != null && up.isTrayShowDisconnectMessages()
&& !reason.equals(Messages.getString("Main.trayClosedReason"))) {
Expand Down Expand Up @@ -4276,8 +4275,8 @@ public void actionPerformed(final ActionEvent e) {
cl.sendChatMessage(message);
} catch (final IOException e1) {
SwingUtils.appendColoredText(
"\u00a7c" + Messages.getString("Main.connectionLostChatMessage2")
+ ": \r\n" + e1.toString(),
"§c" + Messages.getString("Main.connectionLostChatMessage2") + ": \r\n"
+ e1.toString(),
pane);
e1.printStackTrace();
for (final Component ct : chatControls.getComponents()) {
Expand All @@ -4296,7 +4295,7 @@ public void actionPerformed(final ActionEvent e) {
} catch (

final IOException e) {
SwingUtils.appendColoredText("\u00a7c" + Messages.getString("Main.connectionFailedChatMessage2")
SwingUtils.appendColoredText("§c" + Messages.getString("Main.connectionFailedChatMessage2")
+ "\r\n\r\n" + e.toString(), pane);
e.printStackTrace();
}
Expand Down
Loading

0 comments on commit 838244d

Please sign in to comment.