Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9875c13
Remove MaximumTransferUnit.java redundancy
uramnoil Dec 5, 2020
5a503e7
Remove RakNetClient.java redundancy
uramnoil Dec 5, 2020
8d77d6d
Remove Discovery.java redundancy
uramnoil Dec 5, 2020
f40c1d2
Remove DiscoveryHandler.java redundancy
uramnoil Dec 5, 2020
8a44380
Remove DiscoveryThread.java redundancy
uramnoil Dec 5, 2020
a77c2bb
Remove MinecraftIdentifier.java redundancy
uramnoil Dec 5, 2020
eadb2a5
Remove RakNetClientPeer.java redundancy
uramnoil Dec 5, 2020
51f325b
Remove RakNetPeer.java redundancy
uramnoil Dec 5, 2020
2426c1c
Remove ConnectionRequestAccepted.java redundancy
uramnoil Dec 5, 2020
590516f
Remove NewIncomingConnection.java redundancy
uramnoil Dec 5, 2020
33cffd6
Remove AcknowledgedPacket.java redundancy
uramnoil Dec 5, 2020
ea5479f
Remove Record.java redundancy
uramnoil Dec 5, 2020
e6f8ae2
Remove CustomPacket.java redundancy
uramnoil Dec 5, 2020
fca3c60
Remove EncapsulatedPacket.java redundancy
uramnoil Dec 5, 2020
52f8ffd
Remove ConnectionType.java redundancy
uramnoil Dec 5, 2020
7a87579
Remove Reliability.java redundancy
uramnoil Dec 5, 2020
e0277ab
Remove RakNetServer.java redundancy
uramnoil Dec 5, 2020
b8d9e78
Remove RakNetServerHandler.java redundancy
uramnoil Dec 5, 2020
d90191e
Remove PacketDataInputStream.java redundancy
uramnoil Dec 5, 2020
c128529
Remove PowerShellAdministrativeClient.java redundancy
uramnoil Dec 5, 2020
e64d1bb
Remove PowerShellCommand.java redundancy
uramnoil Dec 5, 2020
53e7004
Remove UniversalWindowsProgram.java redundancy
uramnoil Dec 5, 2020
a7495e5
Remove Packet.java redundancy
uramnoil Dec 5, 2020
582190c
Remove unnecessary import
uramnoil Dec 5, 2020
dc57346
Remove RakNet.java redundancy
uramnoil Dec 5, 2020
fcad608
Remove RakNetPacket.java redundancy
uramnoil Dec 5, 2020
b67f0cc
Remove RakNetPacket.java redundancy
uramnoil Dec 5, 2020
39bd349
Remove Packet.java redundancy
uramnoil Dec 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/com/whirvis/jraknet/Packet.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public final byte[] read(int length) throws IndexOutOfBoundsException {
* the amount of <code>byte</code>s to skip.
*/
public final void skip(int length) {
buffer.skipBytes(length > this.remaining() ? this.remaining() : length);
buffer.skipBytes(Math.min(length, this.remaining()));
}

/**
Expand Down Expand Up @@ -666,8 +666,8 @@ public final Packet write(byte... data) throws NullPointerException {
if (data == null) {
throw new NullPointerException("Data cannot be null");
}
for (int i = 0; i < data.length; i++) {
buffer.writeByte(data[i]);
for (byte datum : data) {
buffer.writeByte(datum);
}
return this;
}
Expand Down Expand Up @@ -894,7 +894,7 @@ public final Packet writeUnsignedInt(long i) throws IllegalArgumentException {
if (i < 0x00000000 || i > 0xFFFFFFFFL) {
throw new IllegalArgumentException("Value must be in between 0-4294967295");
}
buffer.writeInt(((int) i) & 0xFFFFFFFF);
buffer.writeInt((int) i);
return this;
}

Expand Down Expand Up @@ -924,7 +924,7 @@ public final Packet writeUnsignedIntLE(long i) throws IllegalArgumentException {
if (i < 0x00000000 || i > 0xFFFFFFFFL) {
throw new IllegalArgumentException("Value must be in between 0-4294967295");
}
buffer.writeIntLE(((int) i) & 0xFFFFFFFF);
buffer.writeIntLE((int) i);
return this;
}

Expand Down Expand Up @@ -1234,8 +1234,8 @@ public final Packet writeAddress(InetSocketAddress address) throws NullPointerEx
int version = RakNet.getAddressVersion(address);
if (version == RakNet.IPV4) {
this.writeUnsignedByte(RakNet.IPV4);
for (int i = 0; i < ipAddress.length; i++) {
this.writeByte(~ipAddress[i] & 0xFF);
for (byte b : ipAddress) {
this.writeByte(~b & 0xFF);
}
this.writeUnsignedShort(address.getPort());
} else if (version == RakNet.IPV6) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/whirvis/jraknet/PacketBufferException.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
*/
package com.whirvis.jraknet;

import com.whirvis.jraknet.RakNetPacket;

/**
* Signals that a packet critical to the current task at hand failed to encode
* or decode correctly.
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/com/whirvis/jraknet/RakNet.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void onFinish(Runnable runnable) {
* if the UPnP code is still being executed.
*/
public boolean wasSuccessful() throws IllegalStateException {
if (finished == false) {
if (!finished) {
throw new IllegalStateException("UPnP code is still being executed");
}
return this.success;
Expand Down Expand Up @@ -242,7 +242,7 @@ public void channelReadComplete(ChannelHandlerContext ctx) {
*/
public static final int MINECRAFT_SYSTEM_ADDRESS_COUNT = 20;

private static final HashMap<InetAddress, Integer> MAXIMUM_TRANSFER_UNIT_SIZES = new HashMap<InetAddress, Integer>();
private static final HashMap<InetAddress, Integer> MAXIMUM_TRANSFER_UNIT_SIZES = new HashMap<>();
private static int _lowestMaximumTransferUnitSize = -1;
private static long _maxPacketsPerSecond = 500;
private static int _systemAddressCount = RAKNET_SYSTEM_ADDRESS_COUNT;
Expand Down Expand Up @@ -611,8 +611,7 @@ private static RakNetPacket createBootstrapAndSend(InetSocketAddress address, Pa
while (retries > 0 && received == null && !Thread.currentThread().isInterrupted()) {
long sendTime = System.currentTimeMillis();
channel.writeAndFlush(new DatagramPacket(packet.buffer(), address));
while (System.currentTimeMillis() - sendTime < timeout && handler.packet == null)
; // Wait for either a timeout or a response
while (System.currentTimeMillis() - sendTime < timeout && handler.packet == null); // Wait for either a timeout or a response
received = handler.packet;
retries--;
}
Expand Down Expand Up @@ -649,7 +648,7 @@ public static boolean isServerOnline(InetSocketAddress address) throws NullPoint
if (packet.getId() == RakNetPacket.ID_OPEN_CONNECTION_REPLY_1) {
OpenConnectionResponseOne connectionResponseOne = new OpenConnectionResponseOne(packet);
connectionResponseOne.decode();
if (connectionResponseOne.magic == true) {
if (connectionResponseOne.magic) {
return true;
}
}
Expand Down Expand Up @@ -726,7 +725,7 @@ public static boolean isServerCompatible(InetSocketAddress address) throws NullP
if (packet.getId() == RakNetPacket.ID_OPEN_CONNECTION_REPLY_1) {
OpenConnectionResponseOne connectionResponseOne = new OpenConnectionResponseOne(packet);
connectionResponseOne.decode();
if (connectionResponseOne.magic == true) {
if (connectionResponseOne.magic) {
return true;
}
} else if (packet.getId() == RakNetPacket.ID_INCOMPATIBLE_PROTOCOL_VERSION) {
Expand Down Expand Up @@ -811,7 +810,7 @@ public static Identifier getServerIdentifier(InetSocketAddress address) throws N
if (packet.getId() == RakNetPacket.ID_UNCONNECTED_PONG) {
UnconnectedPong pong = new UnconnectedPong(packet);
pong.decode();
if (!pong.failed() && pong.magic == true) {
if (!pong.failed() && pong.magic) {
return pong.identifier;
}
}
Expand Down Expand Up @@ -908,7 +907,7 @@ public static int getMaximumTransferUnit(InetAddress address) throws RuntimeExce
MAXIMUM_TRANSFER_UNIT_SIZES.put(address, _lowestMaximumTransferUnitSize);
}
}
return MAXIMUM_TRANSFER_UNIT_SIZES.get(address).intValue();
return MAXIMUM_TRANSFER_UNIT_SIZES.get(address);
}

/**
Expand Down Expand Up @@ -978,7 +977,7 @@ public static void setMaxPacketsPerSecond(long maxPacketsPerSecond) throws Illeg
}
boolean updated = _maxPacketsPerSecond != maxPacketsPerSecond;
_maxPacketsPerSecond = maxPacketsPerSecond;
if (updated == true) {
if (updated) {
LOGGER.info("Set max packets per second to " + maxPacketsPerSecond);
}
}
Expand Down Expand Up @@ -1017,7 +1016,7 @@ public static void setSystemAddressCount(int systemAddressCount) throws IllegalA
}
boolean updated = _systemAddressCount != systemAddressCount;
_systemAddressCount = systemAddressCount;
if (updated == true) {
if (updated) {
LOGGER.info("Set system address count to " + systemAddressCount);
}
}
Expand Down Expand Up @@ -1122,7 +1121,7 @@ public static InetSocketAddress parseAddress(String address, int defaultPort) th
String[] addressSplit = address.split(":");
if (addressSplit.length == 1 || addressSplit.length == 2) {
InetAddress inetAddress = InetAddress.getByName(!addressSplit[0].startsWith("/") ? addressSplit[0]
: addressSplit[0].substring(1, addressSplit[0].length()));
: addressSplit[0].substring(1));
int port = (addressSplit.length == 2 ? parseIntPassive(addressSplit[1]) : defaultPort);
if (port >= 0x0000 && port <= 0xFFFF) {
return new InetSocketAddress(inetAddress, port);
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/whirvis/jraknet/RakNetPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public class RakNetPacket extends Packet {
/**
* The cached packet names, mapped by their ID.
*/
private static final ShortMap<String> PACKET_NAMES = new ShortMap<String>();
private static final ShortMap<String> PACKET_NAMES = new ShortMap<>();

/**
* The cached packet IDs, mapped by their name.
*/
private static final HashMap<String, Short> PACKET_IDS = new HashMap<String, Short>();
private static final HashMap<String, Short> PACKET_IDS = new HashMap<>();

/**
* The magic identifier.
Expand Down Expand Up @@ -916,7 +916,7 @@ public class RakNetPacket extends Packet {
* they also override other packets with the same ID.
*/
private static void mapNameIds() {
if (mappedNameIds == false) {
if (!mappedNameIds) {
Logger log = LogManager.getLogger(RakNetPacket.class);
for (Field field : RakNetPacket.class.getFields()) {
if (field.getType().equals(short.class)) {
Expand Down Expand Up @@ -957,7 +957,7 @@ private static void mapNameIds() {
* packet, <code>false</code>.
*/
public static boolean hasPacket(int id) {
if (mappedNameIds == false) {
if (!mappedNameIds) {
mapNameIds();
}
return PACKET_NAMES.containsKey((short) id);
Expand Down Expand Up @@ -988,7 +988,7 @@ public static boolean hasPacket(RakNetPacket packet) {
* packet, <code>false</code>.
*/
public static boolean hasPacket(String name) {
if (mappedNameIds == false) {
if (!mappedNameIds) {
mapNameIds();
}
return PACKET_IDS.containsKey(name);
Expand Down Expand Up @@ -1055,7 +1055,7 @@ public static String getName(RakNetPacket packet) {
* it does not exist.
*/
public static short getId(String name) {
if (mappedNameIds == false) {
if (!mappedNameIds) {
mapNameIds();
}
return PACKET_IDS.containsKey(name) ? PACKET_IDS.get(name) : -1;
Expand Down Expand Up @@ -1228,7 +1228,7 @@ public final ConnectionType readConnectionType() throws RakNetException {
String name = this.readString();
String language = this.readString();
String version = this.readString();
HashMap<String, String> metadata = new HashMap<String, String>();
HashMap<String, String> metadata = new HashMap<>();
int metadataLength = this.readUnsignedByte();
for (int i = 0; i < metadataLength; i++) {
String key = this.readString();
Expand Down Expand Up @@ -1362,7 +1362,7 @@ public void decode() throws UnsupportedOperationException {
*/
public final RakNetPacket setBuffer(ByteBuf buffer, boolean updateId) throws IndexOutOfBoundsException {
super.setBuffer(buffer);
if (updateId == true) {
if (updateId) {
this.id = this.readUnsignedByte();
}
return this;
Expand Down Expand Up @@ -1450,7 +1450,7 @@ public final RakNetPacket setBuffer(Packet packet, boolean updateId)
*/
public final RakNetPacket flip(boolean updateId) throws IndexOutOfBoundsException {
super.flip();
if (updateId == true) {
if (updateId) {
this.id = this.readUnsignedByte();
}
return this;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/whirvis/jraknet/VarInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ public static void write(long l, OutputStream out, int max)
}
boolean more = true;
int shift = 0;
while (more == true) {
while (more) {
if (max != VARLONG_MAX_SIZE && shift >= max) {
throw new IndexOutOfBoundsException("VarInt overflow");
}
long bits = (long) (l >>> shift) & 0x7F;
long bits = (l >>> shift) & 0x7F;
shift += 7;
if (shift >= VARLONG_MAX_SIZE || (l >>> shift == 0)) {
more = false;
}
out.write((int) (bits | (more == true ? 0x80 : 0x00)));
out.write((int) (bits | (more ? 0x80 : 0x00)));
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ public static void write(int i, OutputStream out, int max)
}
boolean more = true;
int shift = 0;
while (more == true) {
while (more) {
if (max != VARINT_MAX_SIZE && shift >= max) {
throw new IndexOutOfBoundsException("VarInt overflow");
}
Expand All @@ -185,7 +185,7 @@ public static void write(int i, OutputStream out, int max)
if (shift >= VARINT_MAX_SIZE || (i >>> shift == 0)) {
more = false;
}
out.write(bits | (more == true ? 0x80 : 0x00));
out.write(bits | (more ? 0x80 : 0x00));
}
}

Expand Down Expand Up @@ -349,7 +349,7 @@ public static void writeUnsigned(long l, OutputStream out, int max)
if (shift >= max) {
throw new IndexOutOfBoundsException("VarInt overflow");
}
long bits = (long) (l >>> shift) & 0x7F;
long bits = (l >>> shift) & 0x7F;
moreBits = ((l >>> (shift + 7)) & 0x7F) != 0;
out.write((int) (bits | (moreBits ? 0x80 : 0x00)));
shift += 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,18 @@ public static MaximumTransferUnit[] sort(MaximumTransferUnit... units) throws Nu
} else if (units.length <= 0) {
return new MaximumTransferUnit[0]; // Nothing to sort
}
IntMap<MaximumTransferUnit> unitMap = new IntMap<MaximumTransferUnit>();
IntMap<MaximumTransferUnit> unitMap = new IntMap<>();
for (MaximumTransferUnit unit : units) {
if (unit == null) {
throw new NullPointerException("Maximum transfer unit cannot be null");
}
unitMap.put(unit.getSize(), unit);
}
ArrayList<MaximumTransferUnit> unitList = new ArrayList<MaximumTransferUnit>();
NavigableMap<Integer, MaximumTransferUnit> unitTreeMap = new TreeMap<Integer, MaximumTransferUnit>(unitMap)
ArrayList<MaximumTransferUnit> unitList = new ArrayList<>();
NavigableMap<Integer, MaximumTransferUnit> unitTreeMap = new TreeMap<>(unitMap)
.descendingMap();
Set<Entry<Integer, MaximumTransferUnit>> unitSet = unitTreeMap.entrySet();
Iterator<Entry<Integer, MaximumTransferUnit>> unitI = unitSet.iterator();
while (unitI.hasNext()) {
Entry<Integer, MaximumTransferUnit> unitEntry = unitI.next();
for (Entry<Integer, MaximumTransferUnit> unitEntry : unitSet) {
unitList.add(unitEntry.getValue());
}
return unitList.toArray(new MaximumTransferUnit[unitList.size()]);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/whirvis/jraknet/client/RakNetClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public final void setMaximumTransferUnitSizes(int... maximumTransferUnitSizes)
}
}
this.highestMaximumTransferUnitSize = highestMaximumTransferUnit;
if (foundTransferUnit == false) {
if (!foundTransferUnit) {
throw new RuntimeException("No compatible maximum transfer unit found for machine network cards");
}
int[] registeredMaximumTransferUnitSizes = new int[maximumTransferUnits.size()];
Expand Down
Loading