mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-09-28 23:27:30 +02:00
Fix some code style issues
This commit is contained in:
parent
f042087356
commit
d5231944b6
@ -30,7 +30,7 @@ import com.google.common.collect.Iterables;
|
||||
* An implicitly sorted array list that preserves insertion order and maintains duplicates.
|
||||
* @param <T> - type of the elements in the list.
|
||||
*/
|
||||
public class SortedCopyOnWriteArray<T extends Comparable<T>> implements Iterable<T>, Collection<T> {
|
||||
public class SortedCopyOnWriteArray<T extends Comparable<T>> implements Collection<T> {
|
||||
// Prevent reordering
|
||||
private volatile List<T> list;
|
||||
|
||||
|
@ -18,7 +18,6 @@ import org.bukkit.plugin.PluginManager;
|
||||
import com.comphenix.protocol.AsynchronousManager;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Sender;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.error.ReportType;
|
||||
@ -42,7 +41,7 @@ import com.google.common.collect.Sets;
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public class DelayedPacketManager implements ProtocolManager, InternalManager {
|
||||
public class DelayedPacketManager implements InternalManager {
|
||||
// Registering packet IDs that are not supported
|
||||
public static final ReportType REPORT_CANNOT_SEND_QUEUED_PACKET = new ReportType("Cannot send queued packet %s.");
|
||||
public static final ReportType REPORT_CANNOT_REGISTER_QUEUED_LISTENER = new ReportType("Cannot register queued listener %s.");
|
||||
|
@ -51,7 +51,6 @@ import org.bukkit.plugin.PluginManager;
|
||||
import com.comphenix.protocol.AsynchronousManager;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Sender;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.async.AsyncFilterManager;
|
||||
import com.comphenix.protocol.async.AsyncMarker;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
@ -88,7 +87,7 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public final class PacketFilterManager implements ProtocolManager, ListenerInvoker, InternalManager {
|
||||
public final class PacketFilterManager implements ListenerInvoker, InternalManager {
|
||||
|
||||
public static final ReportType REPORT_CANNOT_LOAD_PACKET_LIST = new ReportType("Cannot load server and client packet list.");
|
||||
public static final ReportType REPORT_CANNOT_INITIALIZE_PACKET_INJECTOR = new ReportType("Unable to initialize packet injector");
|
||||
|
@ -39,8 +39,8 @@ public class LegacyNetworkMarker extends NetworkMarker {
|
||||
return ByteBuffer.wrap(Bytes.concat(new byte[] { (byte) type.getLegacyId() }, buffer.array()));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected DataInputStream addHeader(final DataInputStream input, final PacketType type) {
|
||||
InputSupplier<InputStream> header = new InputSupplier<InputStream>() {
|
||||
@Override
|
||||
@ -59,7 +59,7 @@ public class LegacyNetworkMarker extends NetworkMarker {
|
||||
|
||||
// Combine them into a single stream
|
||||
try {
|
||||
return new DataInputStream(ByteStreams.join((InputSupplier) header, (InputSupplier) data).getInput());
|
||||
return new DataInputStream(ByteStreams.join(header, data).getInput());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Cannot add header.", e);
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ class ProxyPacketInjector implements PacketInjector {
|
||||
@Override
|
||||
public PacketEvent packetRecieved(PacketContainer packet, Player client, byte[] buffered) {
|
||||
NetworkMarker marker = buffered != null ? new LegacyNetworkMarker(ConnectionSide.CLIENT_SIDE, buffered, packet.getType()) : null;
|
||||
PacketEvent event = PacketEvent.fromClient((Object) manager, packet, marker, client);
|
||||
PacketEvent event = PacketEvent.fromClient(manager, packet, marker, client);
|
||||
|
||||
manager.invokePacketRecieving(event);
|
||||
return event;
|
||||
|
@ -176,7 +176,7 @@ public abstract class PlayerInjector implements SocketInjector {
|
||||
* @param player - the player to hook.
|
||||
*/
|
||||
public void initializePlayer(Player player) {
|
||||
Object notchEntity = getEntityPlayer((Player) player);
|
||||
Object notchEntity = getEntityPlayer(player);
|
||||
|
||||
// Save the player too
|
||||
this.player = player;
|
||||
@ -587,7 +587,7 @@ public abstract class PlayerInjector implements SocketInjector {
|
||||
* @param packet - packet to sent.
|
||||
* @return The given packet, or the packet replaced by the listeners.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({ "deprecation", "null" })
|
||||
public Object handlePacketSending(Object packet) {
|
||||
try {
|
||||
// Get the packet ID too
|
||||
|
@ -8,7 +8,6 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.concurrency.PacketTypeSet;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.injector.packet.PacketInjector;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
@ -16,7 +15,7 @@ import com.google.common.collect.Sets;
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
class DummyPacketInjector extends AbstractPacketInjector implements PacketInjector {
|
||||
class DummyPacketInjector extends AbstractPacketInjector {
|
||||
private SpigotPacketInjector injector;
|
||||
private PacketTypeSet lastBufferedPackets = new PacketTypeSet();
|
||||
|
||||
|
@ -6,6 +6,8 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
/**
|
||||
* Represents a cloner that can clone any class that implements Serializable.
|
||||
* @author Kristian Stangeland
|
||||
@ -30,21 +32,18 @@ public class SerializableCloner implements Cloner {
|
||||
* @return The cloned object.
|
||||
* @throws RuntimeException If we were unable to clone the object.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Serializable> T clone(final T obj) {
|
||||
try {
|
||||
if (obj instanceof Serializable) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oout = new ObjectOutputStream(out);
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Serializable> T clone(final T obj) {
|
||||
try {
|
||||
Validate.notNull(obj, "Object cannot be null!");
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oout = new ObjectOutputStream(out);
|
||||
|
||||
oout.writeObject(obj);
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
|
||||
return (T) in.readObject();
|
||||
} else {
|
||||
throw new RuntimeException("Object " + obj + " is not serializable!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to clone object " + obj + " (" + obj.getClass().getName() + ")", e);
|
||||
}
|
||||
}
|
||||
oout.writeObject(obj);
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
|
||||
return (T) in.readObject();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to clone object " + obj + " (" + obj.getClass().getName() + ")", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public abstract class CompiledStructureModifier extends StructureModifier<Object
|
||||
Integer index = entry.getValue();
|
||||
Field field = entry.getKey();
|
||||
|
||||
write(index, (Object) generator.getDefault(field.getType()));
|
||||
write(index, generator.getDefault(field.getType()));
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -165,7 +165,7 @@ class MethodDescriptor {
|
||||
}
|
||||
|
||||
String t = type.substring(0, type.length() - sb.length() * 2);
|
||||
String desc = (String) DESCRIPTORS.get(t);
|
||||
String desc = DESCRIPTORS.get(t);
|
||||
if (desc != null) {
|
||||
sb.append(desc);
|
||||
} else {
|
||||
|
@ -84,8 +84,8 @@ public abstract class AbstractFuzzyMatcher<T> implements Comparable<AbstractFuzz
|
||||
|
||||
@Override
|
||||
public int compareTo(AbstractFuzzyMatcher<T> obj) {
|
||||
if (obj instanceof AbstractFuzzyMatcher) {
|
||||
AbstractFuzzyMatcher<?> matcher = (AbstractFuzzyMatcher<?>) obj;
|
||||
if (obj != null) {
|
||||
AbstractFuzzyMatcher<?> matcher = obj;
|
||||
return Ints.compare(getRoundNumber(), matcher.getRoundNumber());
|
||||
}
|
||||
// No match
|
||||
|
@ -251,7 +251,7 @@ public class FuzzyClassContract extends AbstractFuzzyMatcher<Class<?>> {
|
||||
(baseclassContracts.size() == 0 ||
|
||||
processValue(value.getSuperclass(), parent, baseclassContracts)) &&
|
||||
(interfaceContracts.size() == 0 ||
|
||||
processContracts(Arrays.asList(value.getInterfaces()), (Class<?>) parent, interfaceContracts));
|
||||
processContracts(Arrays.asList(value.getInterfaces()), parent, interfaceContracts));
|
||||
}
|
||||
|
||||
private <T> boolean processContracts(Collection<T> values, Object parent, List<AbstractFuzzyMatcher<T>> matchers) {
|
||||
|
@ -326,7 +326,7 @@ public class DefaultInstances implements InstanceProvider {
|
||||
*/
|
||||
protected <T> T createInstance(Class<T> type, Constructor<T> constructor, Class<?>[] types, Object[] params) {
|
||||
try {
|
||||
return (T) constructor.newInstance(params);
|
||||
return constructor.newInstance(params);
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
// Cannot create it
|
||||
|
@ -33,7 +33,7 @@ public class SnapshotVersion implements Comparable<SnapshotVersion>, Serializabl
|
||||
if (matcher.matches()) {
|
||||
try {
|
||||
this.snapshotDate = getDateFormat().parse(matcher.group(1));
|
||||
this.snapshotWeekVersion = (int)matcher.group(2).charAt(0) - (int)'a';
|
||||
this.snapshotWeekVersion = matcher.group(2).charAt(0) - 'a';
|
||||
this.rawString = version;
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("Date implied by snapshot version is invalid.", e);
|
||||
@ -83,7 +83,7 @@ public class SnapshotVersion implements Comparable<SnapshotVersion>, Serializabl
|
||||
rawString = String.format("%02dw%02d%s",
|
||||
current.get(Calendar.YEAR) % 100,
|
||||
current.get(Calendar.WEEK_OF_YEAR),
|
||||
(char) ((int)'a' + snapshotWeekVersion));
|
||||
(char) ('a' + snapshotWeekVersion));
|
||||
}
|
||||
return rawString;
|
||||
}
|
||||
|
@ -120,7 +120,8 @@ public class BukkitConverters {
|
||||
* @author Kristian
|
||||
* @param <T> - type that can be converted.
|
||||
*/
|
||||
private static abstract class IgnoreNullConverter<TType> implements EquivalentConverter<TType> {
|
||||
public static abstract class IgnoreNullConverter<TType> implements EquivalentConverter<TType> {
|
||||
@Override
|
||||
public final Object getGeneric(Class<?> genericType, TType specific) {
|
||||
if (specific != null)
|
||||
return getGenericValue(genericType, specific);
|
||||
@ -153,20 +154,20 @@ public class BukkitConverters {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
// Very short
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (this == obj) return true;
|
||||
|
||||
// See if they're equivalent
|
||||
if (obj instanceof EquivalentConverter) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
EquivalentConverter other = (EquivalentConverter) obj;
|
||||
return Objects.equal(this.getSpecificType(), other.getSpecificType());
|
||||
EquivalentConverter<?> that = (EquivalentConverter<?>) obj;
|
||||
return Objects.equal(this.getSpecificType(), that.getSpecificType());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.getSpecificType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,21 +190,21 @@ public class BukkitConverters {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
// More shortcuts
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (obj == this) return true;
|
||||
|
||||
// Add another constraint
|
||||
if (obj instanceof WorldSpecificConverter && super.equals(obj)) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
WorldSpecificConverter other = (WorldSpecificConverter) obj;
|
||||
|
||||
return Objects.equal(world, other.world);
|
||||
WorldSpecificConverter<?> that = (WorldSpecificConverter<?>) obj;
|
||||
return Objects.equal(this.world, that.world);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.getSpecificType(), this.world);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -832,7 +833,6 @@ public class BukkitConverters {
|
||||
*/
|
||||
public static Unwrapper asUnwrapper(final Class<?> nativeType, final EquivalentConverter<Object> converter) {
|
||||
return new Unwrapper() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Object unwrapItem(Object wrappedObject) {
|
||||
Class<?> type = PacketConstructor.getClass(wrappedObject);
|
||||
@ -842,7 +842,7 @@ public class BukkitConverters {
|
||||
if (wrappedObject instanceof Class)
|
||||
return nativeType;
|
||||
else
|
||||
return converter.getGeneric((Class) nativeType, wrappedObject);
|
||||
return converter.getGeneric(nativeType, wrappedObject);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -519,7 +519,7 @@ public class NbtFactory {
|
||||
if (type == NbtType.TAG_COMPOUND)
|
||||
return (NbtWrapper<T>) new WrappedCompound(handle);
|
||||
else if (type == NbtType.TAG_LIST)
|
||||
return (NbtWrapper<T>) new WrappedList(handle);
|
||||
return new WrappedList(handle);
|
||||
else
|
||||
return new WrappedElement<T>(handle);
|
||||
}
|
||||
@ -532,7 +532,7 @@ public class NbtFactory {
|
||||
if (type == NbtType.TAG_COMPOUND)
|
||||
return (NbtWrapper<T>) new WrappedCompound(handle, name);
|
||||
else if (type == NbtType.TAG_LIST)
|
||||
return (NbtWrapper<T>) new WrappedList(handle, name);
|
||||
return new WrappedList(handle, name);
|
||||
else
|
||||
return new WrappedElement<T>(handle, name);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import com.comphenix.protocol.wrappers.nbt.io.NbtBinarySerializer;
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<NbtBase<?>>, NbtCompound {
|
||||
class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, NbtCompound {
|
||||
// A list container
|
||||
private WrappedElement<Map<String, Object>> container;
|
||||
|
||||
@ -636,7 +636,7 @@ class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<N
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> NbtBase<?> remove(String key) {
|
||||
public NbtBase<?> remove(String key) {
|
||||
return getValue().remove(key);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ import com.google.common.collect.Iterables;
|
||||
*
|
||||
* @param <TType> - the type of the value in each NBT sub element.
|
||||
*/
|
||||
class WrappedList<TType> implements NbtWrapper<List<NbtBase<TType>>>, Iterable<TType>, NbtList<TType> {
|
||||
class WrappedList<TType> implements NbtWrapper<List<NbtBase<TType>>>, NbtList<TType> {
|
||||
// A list container
|
||||
private WrappedElement<List<Object>> container;
|
||||
|
||||
|
@ -6,7 +6,6 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
@ -50,7 +49,6 @@ public class SimpleMinecraftClient {
|
||||
Socket socket = null;
|
||||
OutputStream output = null;
|
||||
InputStream input = null;
|
||||
InputStreamReader reader = null;
|
||||
|
||||
try {
|
||||
socket = new Socket();
|
||||
@ -76,10 +74,7 @@ public class SimpleMinecraftClient {
|
||||
|
||||
socket.close();
|
||||
return ((ResponsePacket) packet).getPingJson();
|
||||
|
||||
} finally {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
if (input != null)
|
||||
input.close();
|
||||
if (output != null)
|
||||
|
Loading…
Reference in New Issue
Block a user