Archiviert
13
0

Clean up some less-than-conventional code

Dieser Commit ist enthalten in:
Dan Mulloy 2015-11-24 15:35:23 -05:00
Ursprung 3e69dd69ed
Commit b17af68716
23 geänderte Dateien mit 41 neuen und 61 gelöschten Zeilen

Datei anzeigen

@ -75,7 +75,7 @@ class CommandProtocol extends CommandBase {
} else if (subCommand.equalsIgnoreCase("timings")) {
toggleTimings(sender, args);
} else if (subCommand.equalsIgnoreCase("listeners")) {
printListeners(sender, args);
printListeners(sender);
} else if (subCommand.equalsIgnoreCase("version")) {
printVersion(sender);
} else if (subCommand.equalsIgnoreCase("dump")) {
@ -96,7 +96,7 @@ class CommandProtocol extends CommandBase {
}
// Display every listener on the server
private void printListeners(final CommandSender sender, String[] args) {
private void printListeners(final CommandSender sender) {
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
sender.sendMessage(ChatColor.GOLD + "Packet listeners:");

Datei anzeigen

@ -77,10 +77,6 @@ public class ProtocolConfig {
private int modCount;
public ProtocolConfig(Plugin plugin) {
this(plugin, plugin.getConfig());
}
public ProtocolConfig(Plugin plugin, Configuration config) {
this.plugin = plugin;
reloadConfig();
}

Datei anzeigen

@ -388,7 +388,7 @@ public class NettyChannelInjector extends ByteToMessageDecoder implements Channe
* @return TRUE if it is, FALSE if not or unknown.
*/
private boolean guessCompression(ChannelHandler handler) {
String className = handler != null ? handler.getClass().getCanonicalName() : null;
String className = handler != null ? handler.getClass().getCanonicalName() : "";
return className.contains("Compressor") || className.contains("Decompressor");
}

Datei anzeigen

@ -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;

Datei anzeigen

@ -346,13 +346,11 @@ public abstract class PacketAdapter implements PacketListener {
* @return Name of the given plugin.
*/
public static String getPluginName(Plugin plugin) {
// Try to get the plugin name
try {
if (plugin == null)
return "UNKNOWN";
else
return plugin.getName();
if (plugin == null)
return "UNKNOWN";
try {
return plugin.getName();
} catch (NoSuchMethodError e) {
return plugin.toString();
}

Datei anzeigen

@ -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;
@ -43,7 +42,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_SEND_QUEUED_WIRE_PACKET = new ReportType("Cannot send queued wire packet %s.");

Datei anzeigen

@ -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.compat.netty.Netty;
@ -91,7 +90,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");

Datei anzeigen

@ -54,7 +54,7 @@ public class InterceptWritePacket {
}
// TODO: PacketId should probably do something...
private Class<?> createProxyClass(int packetId) {
private Class<?> createProxyClass() {
// Construct the proxy object
Enhancer ex = EnhancerFactory.getInstance().createEnhancer();
@ -102,7 +102,7 @@ public class InterceptWritePacket {
// Concurrent pattern
if (stored == null) {
final Class<?> created = createProxyClass(packetId);
final Class<?> created = createProxyClass();
stored = proxyClasses.putIfAbsent(packetId, created);
// We won!

Datei anzeigen

@ -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;

Datei anzeigen

@ -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();

Datei anzeigen

@ -31,21 +31,17 @@ 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 {
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);
}
}
}

Datei anzeigen

@ -79,7 +79,7 @@ public abstract class CompiledStructureModifier extends StructureModifier<Object
continue;
}
write(index, (Object) generator.getDefault(field.getType()));
write(index, generator.getDefault(field.getType()));
}
return this;

Datei anzeigen

@ -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 {

Datei anzeigen

@ -84,12 +84,7 @@ public abstract class AbstractFuzzyMatcher<T> implements Comparable<AbstractFuzz
@Override
public int compareTo(AbstractFuzzyMatcher<T> obj) {
if (obj instanceof AbstractFuzzyMatcher) {
AbstractFuzzyMatcher<?> matcher = (AbstractFuzzyMatcher<?>) obj;
return Ints.compare(getRoundNumber(), matcher.getRoundNumber());
}
// No match
return -1;
return Ints.compare(getRoundNumber(), obj.getRoundNumber());
}
/**

Datei anzeigen

@ -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) {

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -165,8 +165,10 @@ public class WrappedGameProfile extends AbstractWrapper {
* @throws IllegalArgumentException If we cannot parse the text.
*/
private static UUID parseUUID(String id) {
if (id == null) return null;
try {
return id != null ? UUID.fromString(id) : null;
return UUID.fromString(id);
} catch (IllegalArgumentException e) {
// Warn once every hour (per plugin)
ProtocolLibrary.getErrorReporter()

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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;

Datei anzeigen

@ -103,7 +103,6 @@ public class SimpleCraftBukkitITCase {
* Copy ProtocolLib into the plugins folder.
* @throws IOException If anything went wrong.
*/
@SuppressWarnings("deprecation")
private static void setupPlugins() throws IOException {
File pluginDirectory = new File("plugins/");
File srcDirectory = new File("../");

Datei anzeigen

@ -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)
@ -214,6 +209,7 @@ public class SimpleMinecraftClient {
serializer.serializeVarInt(output, type.getCurrentId());
}
@SuppressWarnings("unused")
public void read(PacketType type, DataInputStream input) throws IOException {
// Note - we don't read the packet id
if (this.type != type) {

Datei anzeigen

@ -33,7 +33,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
public class PlayerInfoDataTest {
@BeforeClass
public static void initializeBukkit() throws IllegalAccessException {
public static void initializeBukkit() {
BukkitInitialization.initializePackage();
}

Datei anzeigen

@ -257,6 +257,7 @@ public abstract class TinyProtocol {
* Note that this is not executed on the main thread.
*
* @param reciever - the receiving player, NULL for early login/status packets.
* @param channel - the channel that received the packet. Never NULL.
* @param remoteAddress - remote address of the sending client. Never NULL.
* @param packet - the packet being sent.
* @return The packet to send instead, or NULL to cancel the transmission.