Skip to content

Commit d523194

Browse files
committed
Fix some code style issues
1 parent f042087 commit d523194

19 files changed

+61
-70
lines changed

ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/SortedCopyOnWriteArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* An implicitly sorted array list that preserves insertion order and maintains duplicates.
3131
* @param <T> - type of the elements in the list.
3232
*/
33-
public class SortedCopyOnWriteArray<T extends Comparable<T>> implements Iterable<T>, Collection<T> {
33+
public class SortedCopyOnWriteArray<T extends Comparable<T>> implements Collection<T> {
3434
// Prevent reordering
3535
private volatile List<T> list;
3636

ProtocolLib/src/main/java/com/comphenix/protocol/injector/DelayedPacketManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.comphenix.protocol.AsynchronousManager;
1919
import com.comphenix.protocol.PacketType;
2020
import com.comphenix.protocol.PacketType.Sender;
21-
import com.comphenix.protocol.ProtocolManager;
2221
import com.comphenix.protocol.error.ErrorReporter;
2322
import com.comphenix.protocol.error.Report;
2423
import com.comphenix.protocol.error.ReportType;
@@ -42,7 +41,7 @@
4241
*
4342
* @author Kristian
4443
*/
45-
public class DelayedPacketManager implements ProtocolManager, InternalManager {
44+
public class DelayedPacketManager implements InternalManager {
4645
// Registering packet IDs that are not supported
4746
public static final ReportType REPORT_CANNOT_SEND_QUEUED_PACKET = new ReportType("Cannot send queued packet %s.");
4847
public static final ReportType REPORT_CANNOT_REGISTER_QUEUED_LISTENER = new ReportType("Cannot register queued listener %s.");

ProtocolLib/src/main/java/com/comphenix/protocol/injector/PacketFilterManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.comphenix.protocol.AsynchronousManager;
5252
import com.comphenix.protocol.PacketType;
5353
import com.comphenix.protocol.PacketType.Sender;
54-
import com.comphenix.protocol.ProtocolManager;
5554
import com.comphenix.protocol.async.AsyncFilterManager;
5655
import com.comphenix.protocol.async.AsyncMarker;
5756
import com.comphenix.protocol.error.ErrorReporter;
@@ -88,7 +87,7 @@
8887
import com.google.common.collect.ImmutableSet;
8988
import com.google.common.collect.Sets;
9089

91-
public final class PacketFilterManager implements ProtocolManager, ListenerInvoker, InternalManager {
90+
public final class PacketFilterManager implements ListenerInvoker, InternalManager {
9291

9392
public static final ReportType REPORT_CANNOT_LOAD_PACKET_LIST = new ReportType("Cannot load server and client packet list.");
9493
public static final ReportType REPORT_CANNOT_INITIALIZE_PACKET_INJECTOR = new ReportType("Unable to initialize packet injector");

ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/LegacyNetworkMarker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ protected ByteBuffer addHeader(ByteBuffer buffer, PacketType type) {
3939
return ByteBuffer.wrap(Bytes.concat(new byte[] { (byte) type.getLegacyId() }, buffer.array()));
4040
}
4141

42-
@SuppressWarnings({"unchecked", "rawtypes"})
4342
@Override
43+
@SuppressWarnings("unchecked")
4444
protected DataInputStream addHeader(final DataInputStream input, final PacketType type) {
4545
InputSupplier<InputStream> header = new InputSupplier<InputStream>() {
4646
@Override
@@ -59,7 +59,7 @@ public InputStream getInput() throws IOException {
5959

6060
// Combine them into a single stream
6161
try {
62-
return new DataInputStream(ByteStreams.join((InputSupplier) header, (InputSupplier) data).getInput());
62+
return new DataInputStream(ByteStreams.join(header, data).getInput());
6363
} catch (IOException e) {
6464
throw new RuntimeException("Cannot add header.", e);
6565
}

ProtocolLib/src/main/java/com/comphenix/protocol/injector/packet/ProxyPacketInjector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public PacketEvent packetRecieved(PacketContainer packet, InputStream input, byt
348348
@Override
349349
public PacketEvent packetRecieved(PacketContainer packet, Player client, byte[] buffered) {
350350
NetworkMarker marker = buffered != null ? new LegacyNetworkMarker(ConnectionSide.CLIENT_SIDE, buffered, packet.getType()) : null;
351-
PacketEvent event = PacketEvent.fromClient((Object) manager, packet, marker, client);
351+
PacketEvent event = PacketEvent.fromClient(manager, packet, marker, client);
352352

353353
manager.invokePacketRecieving(event);
354354
return event;

ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/PlayerInjector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ else if (MinecraftReflection.isLoginHandler(injectionSource))
176176
* @param player - the player to hook.
177177
*/
178178
public void initializePlayer(Player player) {
179-
Object notchEntity = getEntityPlayer((Player) player);
179+
Object notchEntity = getEntityPlayer(player);
180180

181181
// Save the player too
182182
this.player = player;
@@ -587,7 +587,7 @@ public boolean isClean() {
587587
* @param packet - packet to sent.
588588
* @return The given packet, or the packet replaced by the listeners.
589589
*/
590-
@SuppressWarnings("deprecation")
590+
@SuppressWarnings({ "deprecation", "null" })
591591
public Object handlePacketSending(Object packet) {
592592
try {
593593
// Get the packet ID too

ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/DummyPacketInjector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
import com.comphenix.protocol.concurrency.PacketTypeSet;
99
import com.comphenix.protocol.events.PacketContainer;
1010
import com.comphenix.protocol.events.PacketEvent;
11-
import com.comphenix.protocol.injector.packet.PacketInjector;
1211
import com.google.common.collect.Sets;
1312

1413
/**
1514
* Dummy packet injector that simply delegates to its parent Spigot packet injector or receiving filters.
1615
*
1716
* @author Kristian
1817
*/
19-
class DummyPacketInjector extends AbstractPacketInjector implements PacketInjector {
18+
class DummyPacketInjector extends AbstractPacketInjector {
2019
private SpigotPacketInjector injector;
2120
private PacketTypeSet lastBufferedPackets = new PacketTypeSet();
2221

ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/SerializableCloner.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.ObjectOutputStream;
77
import java.io.Serializable;
88

9+
import org.apache.commons.lang.Validate;
10+
911
/**
1012
* Represents a cloner that can clone any class that implements Serializable.
1113
* @author Kristian Stangeland
@@ -30,21 +32,18 @@ public Object clone(Object source) {
3032
* @return The cloned object.
3133
* @throws RuntimeException If we were unable to clone the object.
3234
*/
33-
@SuppressWarnings("unchecked")
34-
public static <T extends Serializable> T clone(final T obj) {
35-
try {
36-
if (obj instanceof Serializable) {
37-
ByteArrayOutputStream out = new ByteArrayOutputStream();
38-
ObjectOutputStream oout = new ObjectOutputStream(out);
35+
@SuppressWarnings("unchecked")
36+
public static <T extends Serializable> T clone(final T obj) {
37+
try {
38+
Validate.notNull(obj, "Object cannot be null!");
39+
ByteArrayOutputStream out = new ByteArrayOutputStream();
40+
ObjectOutputStream oout = new ObjectOutputStream(out);
3941

40-
oout.writeObject(obj);
41-
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
42-
return (T) in.readObject();
43-
} else {
44-
throw new RuntimeException("Object " + obj + " is not serializable!");
45-
}
46-
} catch (Exception e) {
47-
throw new RuntimeException("Unable to clone object " + obj + " (" + obj.getClass().getName() + ")", e);
48-
}
49-
}
42+
oout.writeObject(obj);
43+
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
44+
return (T) in.readObject();
45+
} catch (Exception e) {
46+
throw new RuntimeException("Unable to clone object " + obj + " (" + obj.getClass().getName() + ")", e);
47+
}
48+
}
5049
}

ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public StructureModifier<Object> writeDefaults() throws FieldAccessException {
7373
Integer index = entry.getValue();
7474
Field field = entry.getKey();
7575

76-
write(index, (Object) generator.getDefault(field.getType()));
76+
write(index, generator.getDefault(field.getType()));
7777
}
7878

7979
return this;

ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/MethodDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private static String map(final String type, final boolean defaultPackage) {
165165
}
166166

167167
String t = type.substring(0, type.length() - sb.length() * 2);
168-
String desc = (String) DESCRIPTORS.get(t);
168+
String desc = DESCRIPTORS.get(t);
169169
if (desc != null) {
170170
sb.append(desc);
171171
} else {

0 commit comments

Comments
 (0)