diff --git a/src/main/java/com/comphenix/protocol/CommandFilter.java b/src/main/java/com/comphenix/protocol/CommandFilter.java index e78a5528..8b863bc6 100644 --- a/src/main/java/com/comphenix/protocol/CommandFilter.java +++ b/src/main/java/com/comphenix/protocol/CommandFilter.java @@ -2,6 +2,7 @@ package com.comphenix.protocol; import java.util.ArrayList; import java.util.Deque; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -79,7 +80,7 @@ public class CommandFilter extends CommandBase { public Filter(String name, String predicate, Set packets) { this.name = name; this.predicate = predicate; - this.packets = Sets.newHashSet(packets); + this.packets = new HashSet<>(packets); } /** @@ -103,7 +104,7 @@ public class CommandFilter extends CommandBase { * @return Set of packets this filter applies to. */ public Set getRanges() { - return Sets.newHashSet(packets); + return new HashSet<>(packets); } /** diff --git a/src/main/java/com/comphenix/protocol/CommandPacket.java b/src/main/java/com/comphenix/protocol/CommandPacket.java index c84f5001..8d3ed3d0 100644 --- a/src/main/java/com/comphenix/protocol/CommandPacket.java +++ b/src/main/java/com/comphenix/protocol/CommandPacket.java @@ -22,6 +22,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -34,25 +35,17 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import com.comphenix.protocol.utility.ByteBuddyGenerated; import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.concurrency.PacketTypeSet; import com.comphenix.protocol.error.ErrorReporter; import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.events.ListeningWhitelist; -import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketListener; -import com.comphenix.protocol.reflect.EquivalentConverter; -import com.comphenix.protocol.reflect.PrettyPrinter; -import com.comphenix.protocol.reflect.PrettyPrinter.ObjectPrinter; import com.comphenix.protocol.utility.ChatExtensions; import com.comphenix.protocol.utility.HexDumper; -import com.comphenix.protocol.utility.MinecraftReflection; -import com.comphenix.protocol.wrappers.BukkitConverters; import com.google.common.collect.MapMaker; -import com.google.common.collect.Sets; /** * Handles the "packet" debug command. @@ -306,7 +299,7 @@ class CommandPacket extends CommandBase { } private Set filterTypes(Set types, Sender sender) { - Set result = Sets.newHashSet(); + final Set result = new HashSet<>(); for (PacketType type : types) { if (type.getSender() == sender) { diff --git a/src/main/java/com/comphenix/protocol/PacketType.java b/src/main/java/com/comphenix/protocol/PacketType.java index 9d822481..32e85af2 100644 --- a/src/main/java/com/comphenix/protocol/PacketType.java +++ b/src/main/java/com/comphenix/protocol/PacketType.java @@ -17,7 +17,6 @@ import com.comphenix.protocol.utility.MinecraftVersion; import com.google.common.base.Preconditions; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; @@ -695,7 +694,8 @@ public class PacketType implements Serializable, Cloneable, Comparable values() { - List> sources = Lists.newArrayList(); + final List> sources = new ArrayList<>(); + sources.add(Handshake.Client.getInstance()); sources.add(Handshake.Server.getInstance()); sources.add(Play.Client.getInstance()); diff --git a/src/main/java/com/comphenix/protocol/PacketTypeEnum.java b/src/main/java/com/comphenix/protocol/PacketTypeEnum.java index 706e5eb1..07830616 100644 --- a/src/main/java/com/comphenix/protocol/PacketTypeEnum.java +++ b/src/main/java/com/comphenix/protocol/PacketTypeEnum.java @@ -23,11 +23,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import com.comphenix.protocol.PacketType; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.Sets; - /** * Represents a more modern object-based enum. *

@@ -37,7 +32,7 @@ import com.google.common.collect.Sets; */ public class PacketTypeEnum implements Iterable { // Used to convert between IDs and names - protected Set members = Sets.newHashSet(); + protected Set members = new HashSet<>(); /** * Registers every declared PacketType field. diff --git a/src/main/java/com/comphenix/protocol/PacketTypeLookup.java b/src/main/java/com/comphenix/protocol/PacketTypeLookup.java index 141eee51..75fe5de0 100644 --- a/src/main/java/com/comphenix/protocol/PacketTypeLookup.java +++ b/src/main/java/com/comphenix/protocol/PacketTypeLookup.java @@ -19,14 +19,14 @@ import com.google.common.collect.Multimap; class PacketTypeLookup { public static class ProtocolSenderLookup { // Unroll lookup for performance reasons - public final IntegerMap HANDSHAKE_CLIENT = IntegerMap.newMap(); - public final IntegerMap HANDSHAKE_SERVER = IntegerMap.newMap(); - public final IntegerMap GAME_CLIENT = IntegerMap.newMap(); - public final IntegerMap GAME_SERVER = IntegerMap.newMap(); - public final IntegerMap STATUS_CLIENT = IntegerMap.newMap(); - public final IntegerMap STATUS_SERVER = IntegerMap.newMap(); - public final IntegerMap LOGIN_CLIENT = IntegerMap.newMap(); - public final IntegerMap LOGIN_SERVER = IntegerMap.newMap(); + public final IntegerMap HANDSHAKE_CLIENT = new IntegerMap<>(); + public final IntegerMap HANDSHAKE_SERVER = new IntegerMap<>(); + public final IntegerMap GAME_CLIENT = new IntegerMap<>(); + public final IntegerMap GAME_SERVER = new IntegerMap<>(); + public final IntegerMap STATUS_CLIENT = new IntegerMap<>(); + public final IntegerMap STATUS_SERVER = new IntegerMap<>(); + public final IntegerMap LOGIN_CLIENT = new IntegerMap<>(); + public final IntegerMap LOGIN_SERVER = new IntegerMap<>(); /** * Retrieve the correct integer map for a specific protocol and sender. @@ -52,14 +52,14 @@ class PacketTypeLookup { public static class ClassLookup { // Unroll lookup for performance reasons - public final Map HANDSHAKE_CLIENT = new ConcurrentHashMap(); - public final Map HANDSHAKE_SERVER = new ConcurrentHashMap(); - public final Map GAME_CLIENT = new ConcurrentHashMap(); - public final Map GAME_SERVER = new ConcurrentHashMap(); - public final Map STATUS_CLIENT = new ConcurrentHashMap(); - public final Map STATUS_SERVER = new ConcurrentHashMap(); - public final Map LOGIN_CLIENT = new ConcurrentHashMap(); - public final Map LOGIN_SERVER = new ConcurrentHashMap(); + public final Map HANDSHAKE_CLIENT = new ConcurrentHashMap<>(); + public final Map HANDSHAKE_SERVER = new ConcurrentHashMap<>(); + public final Map GAME_CLIENT = new ConcurrentHashMap<>(); + public final Map GAME_SERVER = new ConcurrentHashMap<>(); + public final Map STATUS_CLIENT = new ConcurrentHashMap<>(); + public final Map STATUS_SERVER = new ConcurrentHashMap<>(); + public final Map LOGIN_CLIENT = new ConcurrentHashMap<>(); + public final Map LOGIN_SERVER = new ConcurrentHashMap<>(); /** * Retrieve the correct integer map for a specific protocol and sender. @@ -84,9 +84,9 @@ class PacketTypeLookup { } // Packet IDs from 1.6.4 and below - private final IntegerMap legacyLookup = new IntegerMap(); - private final IntegerMap serverLookup = new IntegerMap(); - private final IntegerMap clientLookup = new IntegerMap(); + private final IntegerMap legacyLookup = new IntegerMap<>(); + private final IntegerMap serverLookup = new IntegerMap<>(); + private final IntegerMap clientLookup = new IntegerMap<>(); // Packets for 1.7.2 private final ProtocolSenderLookup idLookup = new ProtocolSenderLookup(); diff --git a/src/main/java/com/comphenix/protocol/PacketTypeParser.java b/src/main/java/com/comphenix/protocol/PacketTypeParser.java index 947616ed..801d99ee 100644 --- a/src/main/java/com/comphenix/protocol/PacketTypeParser.java +++ b/src/main/java/com/comphenix/protocol/PacketTypeParser.java @@ -1,29 +1,29 @@ package com.comphenix.protocol; -import java.util.Collection; -import java.util.Deque; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Set; - import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.events.ConnectionSide; import com.google.common.collect.ContiguousSet; import com.google.common.collect.DiscreteDomain; -import com.google.common.collect.Lists; import com.google.common.collect.Range; -import com.google.common.collect.Sets; + +import java.util.Collection; +import java.util.Collections; +import java.util.Deque; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Set; class PacketTypeParser { - public final static Range DEFAULT_MAX_RANGE = Range.closed(0, 255); + public static final Range DEFAULT_MAX_RANGE = Range.closed(0, 255); private Sender side = null; private Protocol protocol = null; public Set parseTypes(Deque arguments, Range defaultRange) { - Set result = Sets.newHashSet(); + final Set result = new HashSet<>(); side = null; protocol = null; @@ -68,8 +68,7 @@ class PacketTypeParser { // Supply a default integer range if (ranges.isEmpty() && result.isEmpty()) { - ranges = Lists.newArrayList(); - ranges.add(defaultRange); + ranges = Collections.singletonList(defaultRange); } for (Range range : ranges) { @@ -130,19 +129,20 @@ class PacketTypeParser { * @return The protocol, or NULL if not found. */ public Protocol parseProtocol(String text) { - if (text == null) - return null; - String candidate = text.toLowerCase(); - - if ("handshake".equals(candidate) || "handshaking".equals(candidate)) - return Protocol.HANDSHAKING; - else if ("login".equals(candidate)) - return Protocol.LOGIN; - else if ("play".equals(candidate) || "game".equals(candidate)) - return Protocol.PLAY; - else if ("status".equals(candidate)) - return Protocol.STATUS; - else - return null; + if (text == null) return null; + + switch (text.toLowerCase()) { + case "handshake": + case "handshaking": + return Protocol.HANDSHAKING; + case "login": + return Protocol.LOGIN; + case "play": + case "game": + return Protocol.PLAY; + case "status": + return Protocol.STATUS; + default: return null; + } } } diff --git a/src/main/java/com/comphenix/protocol/ProtocolLib.java b/src/main/java/com/comphenix/protocol/ProtocolLib.java index 34c7ecbc..39909d5d 100644 --- a/src/main/java/com/comphenix/protocol/ProtocolLib.java +++ b/src/main/java/com/comphenix/protocol/ProtocolLib.java @@ -34,9 +34,9 @@ import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.utility.NettyVersion; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; import java.io.File; import java.io.IOException; +import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Handler; @@ -235,7 +235,7 @@ public class ProtocolLib extends JavaPlugin { private ErrorReporter getFilteredReporter(ErrorReporter reporter) { return new DelegatedErrorReporter(reporter) { private int lastModCount = -1; - private Set reports = Sets.newHashSet(); + private Set reports = new HashSet<>(); @Override protected Report filterReport(Object sender, Report report, boolean detailed) { @@ -245,7 +245,7 @@ public class ProtocolLib extends JavaPlugin { if (config != null && config.getModificationCount() != this.lastModCount) { // Update our cached set again - this.reports = Sets.newHashSet(config.getSuppressedReports()); + this.reports = new HashSet<>(config.getSuppressedReports()); this.lastModCount = config.getModificationCount(); } diff --git a/src/main/java/com/comphenix/protocol/RangeParser.java b/src/main/java/com/comphenix/protocol/RangeParser.java index 9253271a..cfa4c00b 100644 --- a/src/main/java/com/comphenix/protocol/RangeParser.java +++ b/src/main/java/com/comphenix/protocol/RangeParser.java @@ -17,22 +17,24 @@ package com.comphenix.protocol; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Deque; -import java.util.List; - import com.google.common.collect.ContiguousSet; import com.google.common.collect.DiscreteDomain; import com.google.common.collect.Range; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Deque; +import java.util.List; + /** * Used to parse ranges in CommandPacket. * * @author Kristian */ -class RangeParser { +final class RangeParser { + private RangeParser() {} + /** * Parse a range from a given text. * @param text - the text. @@ -40,20 +42,18 @@ class RangeParser { * @return The parsed ranges. */ public static List> getRanges(String text, Range legalRange) { - return getRanges(new ArrayDeque(Arrays.asList(text)), legalRange); + return getRanges(new ArrayDeque<>(Collections.singletonList(text)), legalRange); } /** * Parse ranges from an array of elements. - * @param args - array of elements. - * @param offset - beginning offset. - * @param lastIndex - the last index of the array to read. + * @param input the input to parse the ranges from * @param legalRange - range of legal values. * @return The parsed ranges. */ public static List> getRanges(Deque input, Range legalRange) { List tokens = tokenizeInput(input); - List> ranges = new ArrayList>(); + List> ranges = new ArrayList<>(); for (int i = 0; i < tokens.size(); i++) { Range range; @@ -96,7 +96,7 @@ class RangeParser { * @return A simplified list of ranges. */ private static List> simplify(List> ranges, int maximum) { - List> result = new ArrayList>(); + List> result = new ArrayList<>(); boolean[] set = new boolean[maximum + 1]; int start = -1; @@ -125,7 +125,7 @@ class RangeParser { } private static List tokenizeInput(Deque input) { - List tokens = new ArrayList(); + List tokens = new ArrayList<>(); // Tokenize the input while (!input.isEmpty()) { diff --git a/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java b/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java index 74cc1149..08cdc003 100644 --- a/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java +++ b/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java @@ -36,7 +36,6 @@ import com.comphenix.protocol.injector.SortedPacketListenerList; import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -87,7 +86,7 @@ public class AsyncFilterManager implements AsynchronousManager { // Initialize timeout listeners this.serverTimeoutListeners = new SortedPacketListenerList(); this.clientTimeoutListeners = new SortedPacketListenerList(); - this.timeoutListeners = Sets.newSetFromMap(new ConcurrentHashMap<>()); + this.timeoutListeners = ConcurrentHashMap.newKeySet(); this.playerSendingHandler = new PlayerSendingHandler(reporter, serverTimeoutListeners, clientTimeoutListeners); this.serverProcessingQueue = new PacketProcessingQueue(playerSendingHandler); diff --git a/src/main/java/com/comphenix/protocol/collections/IntegerMap.java b/src/main/java/com/comphenix/protocol/collections/IntegerMap.java index 4319ec7f..4ac3286e 100644 --- a/src/main/java/com/comphenix/protocol/collections/IntegerMap.java +++ b/src/main/java/com/comphenix/protocol/collections/IntegerMap.java @@ -1,10 +1,10 @@ package com.comphenix.protocol.collections; import java.util.Arrays; +import java.util.HashMap; import java.util.Map; import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; /** * Represents a very quick integer-based lookup map, with a fixed key space size. @@ -16,15 +16,6 @@ public class IntegerMap { private T[] array; private int size; - /** - * Construct a new integer map. - * @param Parameter type - * @return A new integer map. - */ - public static IntegerMap newMap() { - return new IntegerMap(); - } - /** * Construct a new integer map with a default capacity. */ @@ -128,7 +119,7 @@ public class IntegerMap { * @return The Integer map. */ public Map toMap() { - Map map = Maps.newHashMap(); + final Map map = new HashMap<>(); for (int i = 0; i < array.length; i++) { if (array[i] != null) { diff --git a/src/main/java/com/comphenix/protocol/concurrency/ConcurrentPlayerMap.java b/src/main/java/com/comphenix/protocol/concurrency/ConcurrentPlayerMap.java index 5e21f91d..dea28440 100644 --- a/src/main/java/com/comphenix/protocol/concurrency/ConcurrentPlayerMap.java +++ b/src/main/java/com/comphenix/protocol/concurrency/ConcurrentPlayerMap.java @@ -7,7 +7,6 @@ import com.google.common.base.Preconditions; import com.google.common.cache.CacheLoader; import com.google.common.cache.RemovalListener; import com.google.common.collect.AbstractIterator; -import com.google.common.collect.Maps; import com.google.common.util.concurrent.UncheckedExecutionException; import org.bukkit.entity.Player; @@ -73,7 +72,7 @@ public class ConcurrentPlayerMap extends AbstractMap imp * @return Concurrent player map. */ public static ConcurrentPlayerMap usingAddress() { - return new ConcurrentPlayerMap(PlayerKey.ADDRESS); + return new ConcurrentPlayerMap<>(PlayerKey.ADDRESS); } /** @@ -82,7 +81,7 @@ public class ConcurrentPlayerMap extends AbstractMap imp * @return Concurrent player map. */ public static ConcurrentPlayerMap usingName() { - return new ConcurrentPlayerMap(PlayerKey.NAME); + return new ConcurrentPlayerMap<>(PlayerKey.NAME); } /** @@ -108,7 +107,7 @@ public class ConcurrentPlayerMap extends AbstractMap imp * @return The value map. */ private ConcurrentMap createValueMap() { - return Maps.newConcurrentMap(); + return new ConcurrentHashMap<>(); } /** diff --git a/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java b/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java index 6923b933..194f6f13 100644 --- a/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java +++ b/src/main/java/com/comphenix/protocol/events/ListeningWhitelist.java @@ -116,7 +116,7 @@ public class ListeningWhitelist { */ private static Set safeSet(Collection set) { if (set != null) { - return Sets.newHashSet(set); + return new HashSet<>(set); } else { return Collections.emptySet(); } @@ -204,9 +204,9 @@ public class ListeningWhitelist { // Default values private ListenerPriority priority = ListenerPriority.NORMAL; - private Set types = Sets.newHashSet(); + private Set types = new HashSet<>(); private GamePhase gamePhase = GamePhase.PLAYING; - private Set options = Sets.newHashSet(); + private Set options = new HashSet<>(); /** * Construct a new listening whitelist template. diff --git a/src/main/java/com/comphenix/protocol/events/PacketAdapter.java b/src/main/java/com/comphenix/protocol/events/PacketAdapter.java index 45a4cb36..e2b51b3f 100644 --- a/src/main/java/com/comphenix/protocol/events/PacketAdapter.java +++ b/src/main/java/com/comphenix/protocol/events/PacketAdapter.java @@ -396,7 +396,7 @@ public abstract class PacketAdapter implements PacketListener { if (options == null) { return options(option); } else { - Set current = Sets.newHashSet(options); + final Set current = Sets.newHashSet(options); current.add(option); return options(current); } diff --git a/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/src/main/java/com/comphenix/protocol/events/PacketContainer.java index 9d7f9bb0..d8ef5c93 100644 --- a/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -17,61 +17,44 @@ package com.comphenix.protocol.events; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentMap; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.injector.StructureCache; -import com.comphenix.protocol.reflect.*; -import com.comphenix.protocol.reflect.cloning.*; +import com.comphenix.protocol.reflect.FuzzyReflection; +import com.comphenix.protocol.reflect.ObjectWriter; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.reflect.cloning.AggregateCloner; import com.comphenix.protocol.reflect.cloning.AggregateCloner.BuilderParameters; +import com.comphenix.protocol.reflect.cloning.BukkitCloner; +import com.comphenix.protocol.reflect.cloning.Cloner; +import com.comphenix.protocol.reflect.cloning.CollectionCloner; +import com.comphenix.protocol.reflect.cloning.FieldCloner; +import com.comphenix.protocol.reflect.cloning.GuavaOptionalCloner; +import com.comphenix.protocol.reflect.cloning.ImmutableDetector; +import com.comphenix.protocol.reflect.cloning.JavaOptionalCloner; +import com.comphenix.protocol.reflect.cloning.SerializableCloner; import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.reflect.instances.MinecraftGenerator; import com.comphenix.protocol.utility.MinecraftMethods; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; -import com.comphenix.protocol.utility.StreamSerializer; -import com.comphenix.protocol.wrappers.*; -import com.comphenix.protocol.wrappers.EnumWrappers.*; -import com.comphenix.protocol.wrappers.nbt.NbtBase; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; -import com.comphenix.protocol.wrappers.nbt.NbtFactory; - +import com.comphenix.protocol.wrappers.Converters; import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; - import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.WorldType; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.MerchantRecipe; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.Vector; +import javax.annotation.Nullable; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; /** * Represents a Minecraft packet indirectly. @@ -85,8 +68,8 @@ public class PacketContainer extends AbstractStructure implements Serializable { private PacketType type; // Support for serialization - private static ConcurrentMap, Method> writeMethods = Maps.newConcurrentMap(); - private static ConcurrentMap, Method> readMethods = Maps.newConcurrentMap(); + private static ConcurrentMap, Method> writeMethods = new ConcurrentHashMap<>(); + private static ConcurrentMap, Method> readMethods = new ConcurrentHashMap<>(); // Used to clone packets private static final AggregateCloner DEEP_CLONER = AggregateCloner diff --git a/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java b/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java index ddcf669e..754c0065 100644 --- a/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java +++ b/src/main/java/com/comphenix/protocol/injector/EntityUtilities.java @@ -28,7 +28,6 @@ import com.comphenix.protocol.utility.MinecraftFields; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.wrappers.WrappedIntHashMap; -import com.google.common.collect.Lists; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; @@ -221,7 +220,7 @@ class EntityUtilities { } private List unwrapBukkit(List players) { - List output = Lists.newArrayList(); + final List output = new ArrayList<>(); BukkitUnwrapper unwrapper = new BukkitUnwrapper(); // Get the NMS equivalent diff --git a/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java b/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java index e9a5b378..ba27a162 100644 --- a/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java +++ b/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Set; import java.util.logging.Level; +import com.google.common.collect.ImmutableSet; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginLoadOrder; @@ -55,12 +56,12 @@ class PluginVerifier { /** * Contains a list of plugins that will detect and use ProtocolLib dynamically, instead of relying on the dependency system. */ - private static final Set DYNAMIC_DEPENDENCY = Sets.newHashSet("mcore", "MassiveCore"); + private static final Set DYNAMIC_DEPENDENCY = ImmutableSet.of("mcore", "MassiveCore"); /** * Set of plugins that have been loaded after ProtocolLib. */ - private final Set loadedAfter = new HashSet(); + private final Set loadedAfter = new HashSet<>(); /** * Reference to ProtocolLib. @@ -201,7 +202,7 @@ class PluginVerifier { if (list == null) return Collections.emptySet(); else - return Sets.newHashSet(list); + return new HashSet<>(list); } // Avoid cycles. DFS. diff --git a/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java b/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java index c8af7d88..c7d9051b 100644 --- a/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java +++ b/src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java @@ -30,9 +30,6 @@ import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; /** * Static packet registry in Minecraft. @@ -51,9 +48,9 @@ public class PacketRegistry { private final Map>> typeToClass = new ConcurrentHashMap<>(); private final Map, PacketType> classToType = new ConcurrentHashMap<>(); - private volatile Set serverPackets = Sets.newHashSet(); - private volatile Set clientPackets = Sets.newHashSet(); - private final List containers = Lists.newArrayList(); + private volatile Set serverPackets = new HashSet<>(); + private volatile Set clientPackets = new HashSet<>(); + private final List containers = new ArrayList<>(); public Register() {} @@ -106,8 +103,8 @@ public class PacketRegistry { Object[] protocols = ENUM_PROTOCOL.getEnumConstants(); // ID to Packet class maps - Map>> serverMaps = Maps.newLinkedHashMap(); - Map>> clientMaps = Maps.newLinkedHashMap(); + final Map>> serverMaps = new LinkedHashMap<>(); + final Map>> clientMaps = new LinkedHashMap<>(); Register result = new Register(); StructureModifier modifier = null; @@ -157,8 +154,8 @@ public class PacketRegistry { Object[] protocols = ENUM_PROTOCOL.getEnumConstants(); // ID to Packet class maps - Map, Integer>> serverMaps = Maps.newLinkedHashMap(); - Map, Integer>> clientMaps = Maps.newLinkedHashMap(); + final Map, Integer>> serverMaps = new LinkedHashMap<>(); + final Map, Integer>> clientMaps = new LinkedHashMap<>(); Register result = new Register(); Field mainMapField = null; diff --git a/src/main/java/com/comphenix/protocol/reflect/ClassAnalyser.java b/src/main/java/com/comphenix/protocol/reflect/ClassAnalyser.java index 975f83c0..356d0658 100644 --- a/src/main/java/com/comphenix/protocol/reflect/ClassAnalyser.java +++ b/src/main/java/com/comphenix/protocol/reflect/ClassAnalyser.java @@ -2,10 +2,10 @@ package com.comphenix.protocol.reflect; import java.io.IOException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.List; import com.comphenix.protocol.reflect.ClassAnalyser.AsmMethod.AsmOpcodes; -import com.google.common.collect.Lists; import net.bytebuddy.jar.asm.ClassReader; import net.bytebuddy.jar.asm.ClassVisitor; import net.bytebuddy.jar.asm.MethodVisitor; @@ -109,7 +109,7 @@ public class ClassAnalyser { */ private List getMethodCalls(Class clazz, Method method) throws IOException { final ClassReader reader = new ClassReader(clazz.getCanonicalName()); - final List output = Lists.newArrayList(); + final List output = new ArrayList<>(); // The method we are looking for final String methodName = method.getName(); diff --git a/src/main/java/com/comphenix/protocol/reflect/FuzzyReflection.java b/src/main/java/com/comphenix/protocol/reflect/FuzzyReflection.java index bf9626ab..6d9a7aa2 100644 --- a/src/main/java/com/comphenix/protocol/reflect/FuzzyReflection.java +++ b/src/main/java/com/comphenix/protocol/reflect/FuzzyReflection.java @@ -20,6 +20,8 @@ package com.comphenix.protocol.reflect; import java.lang.reflect.*; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -31,8 +33,6 @@ import org.apache.commons.lang.Validate; import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.fuzzy.AbstractFuzzyMatcher; import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; /** @@ -211,7 +211,7 @@ public class FuzzyReflection { * @return List of found methods. */ public List getMethodList(AbstractFuzzyMatcher matcher) { - List methods = Lists.newArrayList(); + final List methods = new ArrayList<>(); // Add all matching fields to the list for (Method method : getMethods()) { @@ -349,7 +349,7 @@ public class FuzzyReflection { * @return Every method that satisfies the given constraints. */ public List getMethodListByParameters(Class returnType, Class[] args) { - List methods = new ArrayList(); + final List methods = new ArrayList<>(); // Find the correct method to call for (Method method : getMethods()) { @@ -388,7 +388,7 @@ public class FuzzyReflection { * @return The first field with a type that is an instance of the given type. */ public Field getFieldByType(String name, Class type) { - List fields = getFieldListByType(type); + final List fields = getFieldListByType(type); if (fields.size() > 0) { return fields.get(0); @@ -406,7 +406,7 @@ public class FuzzyReflection { * @return Every field with a type that is an instance of the given type. */ public List getFieldListByType(Class type) { - List fields = new ArrayList(); + final List fields = new ArrayList<>(); // Field with a compatible type for (Field field : getFields()) { @@ -468,7 +468,7 @@ public class FuzzyReflection { * @return List of found fields. */ public List getFieldList(AbstractFuzzyMatcher matcher) { - List fields = Lists.newArrayList(); + final List fields = new ArrayList<>(); // Add all matching fields to the list for (Field field : getFields()) { @@ -550,7 +550,7 @@ public class FuzzyReflection { * @throws IllegalArgumentException If the constructor cannot be found. */ public Constructor getConstructor(AbstractFuzzyMatcher matcher) { - List> result = getConstructorList(matcher); + final List> result = getConstructorList(matcher); if (result.size() > 0) return result.get(0); @@ -566,7 +566,7 @@ public class FuzzyReflection { * @return A map over every given method. */ public Map getMappedMethods(List methods) { - Map map = Maps.newHashMap(); + final Map map = new HashMap<>(); for (Method method : methods) { map.put(method.getName(), method); @@ -582,7 +582,7 @@ public class FuzzyReflection { * @return List of found constructors. */ public List> getConstructorList(AbstractFuzzyMatcher matcher) { - List> constructors = Lists.newArrayList(); + final List> constructors = new ArrayList<>(); // Add all matching fields to the list for (Constructor constructor : getConstructors()) { @@ -659,12 +659,10 @@ public class FuzzyReflection { @SafeVarargs private static Set setUnion(T[]... array) { - Set result = new LinkedHashSet(); + final Set result = new LinkedHashSet<>(); for (T[] elements : array) { - for (T element : elements) { - result.add(element); - } + Collections.addAll(result, elements); } return result; } diff --git a/src/main/java/com/comphenix/protocol/reflect/MethodInfo.java b/src/main/java/com/comphenix/protocol/reflect/MethodInfo.java index bc4872c4..c8e3bbdb 100644 --- a/src/main/java/com/comphenix/protocol/reflect/MethodInfo.java +++ b/src/main/java/com/comphenix/protocol/reflect/MethodInfo.java @@ -6,12 +6,11 @@ import java.lang.reflect.GenericDeclaration; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.TypeVariable; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import com.google.common.collect.Lists; - /** * Represents a method or a constructor. * @@ -103,11 +102,10 @@ public abstract class MethodInfo implements GenericDeclaration, Member { * @return Method info list. */ public static List fromMethods(Collection methods) { - List infos = Lists.newArrayList(); - - for (Method method : methods) - infos.add(fromMethod(method)); - return infos; + final List list = new ArrayList<>(); + + for (Method method : methods) list.add(fromMethod(method)); + return list; } /** @@ -195,7 +193,7 @@ public abstract class MethodInfo implements GenericDeclaration, Member { * @return Method info list. */ public static List fromConstructors(Collection> constructors) { - List infos = Lists.newArrayList(); + final List infos = new ArrayList<>(); for (Constructor constructor : constructors) infos.add(fromConstructor(constructor)); diff --git a/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java b/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java index 523faf02..793fcac1 100644 --- a/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java +++ b/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java @@ -36,7 +36,6 @@ import com.comphenix.protocol.utility.MinecraftReflection; import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; /** * Provides list-oriented access to the fields of a Minecraft packet. @@ -58,7 +57,7 @@ public class StructureModifier { // The fields to read in order protected Class fieldType; - protected List data = new ArrayList(); + protected List data = new ArrayList<>(); // Improved default values protected Map defaultFields; @@ -76,7 +75,7 @@ public class StructureModifier { private static DefaultInstances DEFAULT_GENERATOR = getDefaultGenerator(); private static DefaultInstances getDefaultGenerator() { - List providers = Lists.newArrayList(); + final List providers = new ArrayList<>(); // Prevent certain classes from being generated providers.add(new BannedGenerator(MinecraftReflection.getItemStackClass(), MinecraftReflection.getBlockClass())); @@ -120,10 +119,9 @@ public class StructureModifier { */ public StructureModifier(Class targetType, Class superclassExclude, boolean requireDefault, boolean useStructureCompiler) { List fields = getFields(targetType, superclassExclude); - Map defaults = requireDefault ? generateDefaultFields(fields) : new HashMap(); + Map defaults = requireDefault ? generateDefaultFields(fields) : new HashMap<>(); - initialize(targetType, Object.class, fields, defaults, null, - new ConcurrentHashMap(), useStructureCompiler); + initialize(targetType, Object.class, fields, defaults, null, new ConcurrentHashMap<>(), useStructureCompiler); } /** @@ -510,8 +508,8 @@ public class StructureModifier { // Do we need to update the cache? if (result == null) { - List filtered = new ArrayList(); - Map defaults = new HashMap(); + List filtered = new ArrayList<>(); + Map defaults = new HashMap<>(); int index = 0; for (Field field : data) { @@ -607,9 +605,9 @@ public class StructureModifier { Class fieldType, List filtered, Map defaults, EquivalentConverter converter) { - StructureModifier result = new StructureModifier(); + StructureModifier result = new StructureModifier<>(); result.initialize(targetType, fieldType, filtered, defaults, - converter, new ConcurrentHashMap(), + converter, new ConcurrentHashMap<>(), useStructureCompiler); return result; } @@ -620,7 +618,7 @@ public class StructureModifier { * @return Structure modifier with the new target. */ public StructureModifier withTarget(Object target) { - StructureModifier copy = new StructureModifier(); + final StructureModifier copy = new StructureModifier<>(); // Create a new instance copy.initialize(this); @@ -676,7 +674,7 @@ public class StructureModifier { * @throws FieldAccessException Unable to access one or all of the fields */ public List getValues() throws FieldAccessException { - List values = new ArrayList(); + final List values = new ArrayList<>(); for (int i = 0; i < size(); i++) { values.add(read(i)); @@ -687,8 +685,7 @@ public class StructureModifier { // Used to generate plausible default values private static Map generateDefaultFields(List fields) { - - Map requireDefaults = new HashMap(); + final Map requireDefaults = new HashMap<>(); DefaultInstances generator = DEFAULT_GENERATOR; int index = 0; @@ -714,7 +711,7 @@ public class StructureModifier { // Used to filter out irrelevant fields private static List getFields(Class type, Class superclassExclude) { - List result = new ArrayList(); + final List result = new ArrayList<>(); // Retrieve every private and public field for (Field field : FuzzyReflection.fromClass(type, true).getDeclaredFields(superclassExclude)) { diff --git a/src/main/java/com/comphenix/protocol/reflect/cloning/AggregateCloner.java b/src/main/java/com/comphenix/protocol/reflect/cloning/AggregateCloner.java index a80daa99..bded9f3e 100644 --- a/src/main/java/com/comphenix/protocol/reflect/cloning/AggregateCloner.java +++ b/src/main/java/com/comphenix/protocol/reflect/cloning/AggregateCloner.java @@ -18,6 +18,7 @@ package com.comphenix.protocol.reflect.cloning; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -75,8 +76,8 @@ public class AggregateCloner implements Cloner { * @author Kristian */ public static class Builder { - private List> factories = Lists.newArrayList(); - private BuilderParameters parameters; + private final List> factories = new ArrayList<>(); + private final BuilderParameters parameters; /** * Create a new aggregate builder. @@ -147,7 +148,7 @@ public class AggregateCloner implements Cloner { ); // Build every cloner in the correct order - List cloners = Lists.newArrayList(); + final List cloners = new ArrayList<>(); for (int i = 0; i < factories.size(); i++) { Cloner cloner = factories.get(i).apply(parameters); diff --git a/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java b/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java index e4c80801..55155976 100644 --- a/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java +++ b/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Supplier; @@ -39,7 +40,7 @@ import net.md_5.bungee.api.chat.BaseComponent; * @author Kristian */ public class BukkitCloner implements Cloner { - private static final Map, Function> CLONERS = Maps.newConcurrentMap(); + private static final Map, Function> CLONERS = new ConcurrentHashMap<>(); private static void fromWrapper(Supplier> getClass, Function fromHandle) { try { diff --git a/src/main/java/com/comphenix/protocol/reflect/cloning/ImmutableDetector.java b/src/main/java/com/comphenix/protocol/reflect/cloning/ImmutableDetector.java index 2cabdd82..75870e8c 100644 --- a/src/main/java/com/comphenix/protocol/reflect/cloning/ImmutableDetector.java +++ b/src/main/java/com/comphenix/protocol/reflect/cloning/ImmutableDetector.java @@ -28,6 +28,7 @@ import java.security.PublicKey; import java.util.Locale; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; import javax.crypto.SecretKey; @@ -35,7 +36,6 @@ import javax.crypto.SecretKey; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; import com.google.common.primitives.Primitives; /** @@ -55,7 +55,7 @@ public class ImmutableDetector implements Cloner { SecretKey.class, PublicKey.class ); - private static final Set> immutableNMS = Sets.newConcurrentHashSet(); + private static final Set> immutableNMS = ConcurrentHashMap.newKeySet(); static { add(MinecraftReflection::getGameProfileClass); diff --git a/src/main/java/com/comphenix/protocol/reflect/compiler/BackgroundCompiler.java b/src/main/java/com/comphenix/protocol/reflect/compiler/BackgroundCompiler.java index f8bc3fbc..9ed511df 100644 --- a/src/main/java/com/comphenix/protocol/reflect/compiler/BackgroundCompiler.java +++ b/src/main/java/com/comphenix/protocol/reflect/compiler/BackgroundCompiler.java @@ -20,6 +20,7 @@ package com.comphenix.protocol.reflect.compiler; import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryUsage; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; @@ -35,7 +36,6 @@ import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.compiler.StructureCompiler.StructureKey; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.util.concurrent.ThreadFactoryBuilder; /** @@ -66,7 +66,7 @@ public class BackgroundCompiler { private static BackgroundCompiler backgroundCompiler; // Classes we're currently compiling - private Map>> listeners = Maps.newHashMap(); + private Map>> listeners = new HashMap<>(); private Object listenerLock = new Object(); private StructureCompiler compiler; diff --git a/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java b/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java index ae02a806..ae45b519 100644 --- a/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java +++ b/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java @@ -18,13 +18,13 @@ package com.comphenix.protocol.reflect.compiler; import java.lang.reflect.Field; +import java.util.HashSet; import java.util.Map; import java.util.Set; import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.instances.DefaultInstances; -import com.google.common.collect.Sets; /** * Represents a compiled structure modifier. @@ -48,7 +48,7 @@ public abstract class CompiledStructureModifier extends StructureModifier(); exempted.add(fieldIndex); } diff --git a/src/main/java/com/comphenix/protocol/reflect/fuzzy/AbstractFuzzyMember.java b/src/main/java/com/comphenix/protocol/reflect/fuzzy/AbstractFuzzyMember.java index 4523b30a..d320b47c 100644 --- a/src/main/java/com/comphenix/protocol/reflect/fuzzy/AbstractFuzzyMember.java +++ b/src/main/java/com/comphenix/protocol/reflect/fuzzy/AbstractFuzzyMember.java @@ -2,13 +2,13 @@ package com.comphenix.protocol.reflect.fuzzy; import java.lang.reflect.Member; import java.lang.reflect.Modifier; +import java.util.LinkedHashMap; import java.util.Map; import java.util.regex.Pattern; import javax.annotation.Nonnull; import com.google.common.base.Objects; -import com.google.common.collect.Maps; /** * Represents a matcher that matches members. @@ -251,7 +251,7 @@ public abstract class AbstractFuzzyMember extends AbstractFuzz * @return A modifiable key-value view. */ protected Map getKeyValueView() { - Map map = Maps.newLinkedHashMap(); + final Map map = new LinkedHashMap<>(); // Build our representation if (modifiersRequired != Integer.MAX_VALUE || modifiersBanned != 0) { diff --git a/src/main/java/com/comphenix/protocol/reflect/fuzzy/FuzzyClassContract.java b/src/main/java/com/comphenix/protocol/reflect/fuzzy/FuzzyClassContract.java index e3f076fb..96405451 100644 --- a/src/main/java/com/comphenix/protocol/reflect/fuzzy/FuzzyClassContract.java +++ b/src/main/java/com/comphenix/protocol/reflect/fuzzy/FuzzyClassContract.java @@ -1,9 +1,11 @@ package com.comphenix.protocol.reflect.fuzzy; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -11,7 +13,6 @@ import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.MethodInfo; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; /** @@ -33,12 +34,12 @@ public class FuzzyClassContract extends AbstractFuzzyMatcher> { * */ public static class Builder { - private List> fieldContracts = Lists.newArrayList(); - private List> methodContracts = Lists.newArrayList(); - private List> constructorContracts = Lists.newArrayList(); + private final List> fieldContracts = new ArrayList<>(); + private final List> methodContracts = new ArrayList<>(); + private final List> constructorContracts = new ArrayList<>(); - private List>> baseclassContracts = Lists.newArrayList(); - private List>> interfaceContracts = Lists.newArrayList(); + private final List>> baseclassContracts = new ArrayList<>(); + private final List>> interfaceContracts = new ArrayList<>(); /** * Add a new field contract. @@ -305,7 +306,7 @@ public class FuzzyClassContract extends AbstractFuzzyMatcher> { @Override public String toString() { - Map params = Maps.newLinkedHashMap(); + final Map params = new LinkedHashMap<>(); if (fieldContracts.size() > 0) { params.put("fields", fieldContracts); diff --git a/src/main/java/com/comphenix/protocol/reflect/fuzzy/FuzzyMethodContract.java b/src/main/java/com/comphenix/protocol/reflect/fuzzy/FuzzyMethodContract.java index e08b2db0..48e57df0 100644 --- a/src/main/java/com/comphenix/protocol/reflect/fuzzy/FuzzyMethodContract.java +++ b/src/main/java/com/comphenix/protocol/reflect/fuzzy/FuzzyMethodContract.java @@ -1,5 +1,6 @@ package com.comphenix.protocol.reflect.fuzzy; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -10,8 +11,6 @@ import javax.annotation.Nonnull; import com.comphenix.protocol.reflect.MethodInfo; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - /** * Represents a contract for matching methods or constructors. * @@ -394,8 +393,8 @@ public class FuzzyMethodContract extends AbstractFuzzyMember { private FuzzyMethodContract() { // Only allow construction from the builder - paramMatchers = Lists.newArrayList(); - exceptionMatchers = Lists.newArrayList(); + paramMatchers = new ArrayList<>(); + exceptionMatchers = new ArrayList<>(); } private FuzzyMethodContract(FuzzyMethodContract other) { diff --git a/src/main/java/com/comphenix/protocol/timing/TimedListenerManager.java b/src/main/java/com/comphenix/protocol/timing/TimedListenerManager.java index a624f711..d269ddbd 100644 --- a/src/main/java/com/comphenix/protocol/timing/TimedListenerManager.java +++ b/src/main/java/com/comphenix/protocol/timing/TimedListenerManager.java @@ -3,6 +3,7 @@ package com.comphenix.protocol.timing; import java.util.Calendar; import java.util.Date; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicBoolean; @@ -10,7 +11,6 @@ import org.bukkit.plugin.Plugin; import com.comphenix.protocol.events.PacketListener; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; /** * Represents a system for recording the time spent by each packet listener. @@ -33,7 +33,7 @@ public class TimedListenerManager { private volatile Date stopped; // The map of time trackers - private ConcurrentMap> map = Maps.newConcurrentMap(); + private final ConcurrentMap> map = new ConcurrentHashMap<>(); /** * Retrieve the shared listener manager. diff --git a/src/main/java/com/comphenix/protocol/timing/TimedTracker.java b/src/main/java/com/comphenix/protocol/timing/TimedTracker.java index 6c4f3f02..0451703c 100644 --- a/src/main/java/com/comphenix/protocol/timing/TimedTracker.java +++ b/src/main/java/com/comphenix/protocol/timing/TimedTracker.java @@ -1,7 +1,6 @@ package com.comphenix.protocol.timing; import com.comphenix.protocol.PacketType; -import com.google.common.collect.Maps; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -60,7 +59,7 @@ public class TimedTracker { * @return The map of statistics. */ public synchronized Map getStatistics() { - Map clone = Maps.newHashMap(); + final Map clone = new HashMap<>(); for (Entry entry : this.packets.entrySet()) { clone.put( diff --git a/src/main/java/com/comphenix/protocol/timing/TimingReportGenerator.java b/src/main/java/com/comphenix/protocol/timing/TimingReportGenerator.java index fe071449..443d2db7 100644 --- a/src/main/java/com/comphenix/protocol/timing/TimingReportGenerator.java +++ b/src/main/java/com/comphenix/protocol/timing/TimingReportGenerator.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.Writer; import java.util.Date; import java.util.Map; +import java.util.TreeSet; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.timing.TimedListenerManager.ListenerType; @@ -75,7 +76,7 @@ public class TimingReportGenerator { destination.write(SEPERATION_LINE); // Write every packet ID that we care about - for (PacketType key : Sets.newTreeSet(streams.keySet())) { + for (PacketType key : new TreeSet<>(streams.keySet())) { final StatisticsStream stream = streams.get(key); if (stream != null && stream.getCount() > 0) { diff --git a/src/main/java/com/comphenix/protocol/utility/CachedPackage.java b/src/main/java/com/comphenix/protocol/utility/CachedPackage.java index 3f36acbb..7efed35b 100644 --- a/src/main/java/com/comphenix/protocol/utility/CachedPackage.java +++ b/src/main/java/com/comphenix/protocol/utility/CachedPackage.java @@ -18,6 +18,7 @@ package com.comphenix.protocol.utility; import java.util.Map; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -40,7 +41,7 @@ class CachedPackage { */ public CachedPackage(String packageName, ClassSource source) { this.packageName = packageName; - this.cache = Maps.newConcurrentMap(); + this.cache = new ConcurrentHashMap<>(); this.source = source; } diff --git a/src/main/java/com/comphenix/protocol/utility/MinecraftProtocolVersion.java b/src/main/java/com/comphenix/protocol/utility/MinecraftProtocolVersion.java index f52e1f2c..c4c72867 100644 --- a/src/main/java/com/comphenix/protocol/utility/MinecraftProtocolVersion.java +++ b/src/main/java/com/comphenix/protocol/utility/MinecraftProtocolVersion.java @@ -4,8 +4,6 @@ import java.util.Map.Entry; import java.util.NavigableMap; import java.util.TreeMap; -import com.google.common.collect.Maps; - /** * A lookup of the associated protocol version of a given Minecraft server. * @author Kristian @@ -14,7 +12,7 @@ public class MinecraftProtocolVersion { private static final NavigableMap lookup = createLookup(); private static NavigableMap createLookup() { - TreeMap map = Maps.newTreeMap(); + TreeMap map = new TreeMap<>(); // Source: http://wiki.vg/Protocol_version_numbers // Doesn't include pre-releases diff --git a/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java b/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java index 861c7a80..4ec8006e 100644 --- a/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java +++ b/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java @@ -31,6 +31,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.logging.Level; import java.util.regex.Matcher; @@ -69,7 +70,6 @@ import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.nbt.NbtFactory; import com.comphenix.protocol.wrappers.nbt.NbtType; import com.google.common.base.Joiner; -import com.google.common.collect.Maps; /** * Methods and constants specifically used in conjuction with reflecting Minecraft object. @@ -142,7 +142,7 @@ public class MinecraftReflection { private static Class itemStackArrayClass; // Cache of getBukkitEntity - private static ConcurrentMap, MethodAccessor> getBukkitEntityCache = Maps.newConcurrentMap(); + private static final ConcurrentMap, MethodAccessor> getBukkitEntityCache = new ConcurrentHashMap<>(); // The current class source private static ClassSource classSource; diff --git a/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java b/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java index 3b66fcb9..0f2ecb8b 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java +++ b/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java @@ -457,8 +457,8 @@ public abstract class EnumWrappers { private static Class ENTITY_POSE_CLASS = null; private static boolean INITIALIZED = false; - private static Map, EquivalentConverter> FROM_NATIVE = Maps.newHashMap(); - private static Map, EquivalentConverter> FROM_WRAPPER = Maps.newHashMap(); + private static Map, EquivalentConverter> FROM_NATIVE = new HashMap<>(); + private static Map, EquivalentConverter> FROM_WRAPPER = new HashMap<>(); static Set INVALID = new HashSet<>(); /** diff --git a/src/main/java/com/comphenix/protocol/wrappers/WrappedAttribute.java b/src/main/java/com/comphenix/protocol/wrappers/WrappedAttribute.java index a11399cd..6b4e754f 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/WrappedAttribute.java +++ b/src/main/java/com/comphenix/protocol/wrappers/WrappedAttribute.java @@ -399,7 +399,7 @@ public class WrappedAttribute extends AbstractWrapper { * @return Unwrapped modifiers. */ private Set getUnwrappedModifiers() { - Set output = Sets.newHashSet(); + final Set output = new HashSet<>(); for (WrappedAttributeModifier modifier : modifiers) { output.add(modifier.getHandle()); diff --git a/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java b/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java index 08cda829..55614765 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java +++ b/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java @@ -6,6 +6,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.List; import javax.imageio.ImageIO; @@ -29,7 +30,6 @@ import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import com.google.common.io.ByteStreams; import io.netty.buffer.ByteBuf; @@ -288,7 +288,7 @@ public class WrappedServerPing extends AbstractWrapper implements ClonableWrappe * @param players - the players to display. */ public void setBukkitPlayers(Iterable players) { - List profiles = Lists.newArrayList(); + final List profiles = new ArrayList<>(); for (Player player : players) { Object profile = ENTITY_HUMAN_PROFILE.get(BukkitUnwrapper.getInstance().unwrapItem(player)); diff --git a/src/main/java/com/comphenix/protocol/wrappers/collection/ConvertedCollection.java b/src/main/java/com/comphenix/protocol/wrappers/collection/ConvertedCollection.java index 0f226bc1..75e5c1ae 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/collection/ConvertedCollection.java +++ b/src/main/java/com/comphenix/protocol/wrappers/collection/ConvertedCollection.java @@ -18,12 +18,12 @@ package com.comphenix.protocol.wrappers.collection; import java.lang.reflect.Array; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; /** * Represents a collection that wraps another collection by transforming the elements going in and out. @@ -103,7 +103,7 @@ public abstract class ConvertedCollection extends AbstractConver @Override @SuppressWarnings("unchecked") public boolean retainAll(Collection c) { - List innerCopy = Lists.newArrayList(); + final List innerCopy = new ArrayList<>(); // Convert all the elements for (Object outer : c) diff --git a/src/main/java/com/comphenix/protocol/wrappers/nbt/NameProperty.java b/src/main/java/com/comphenix/protocol/wrappers/nbt/NameProperty.java index 9d22d4bf..c094d526 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/nbt/NameProperty.java +++ b/src/main/java/com/comphenix/protocol/wrappers/nbt/NameProperty.java @@ -1,12 +1,13 @@ package com.comphenix.protocol.wrappers.nbt; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import com.comphenix.protocol.reflect.StructureModifier; import com.google.common.collect.Maps; public abstract class NameProperty { - private static final Map, StructureModifier> MODIFIERS = Maps.newConcurrentMap(); + private static final Map, StructureModifier> MODIFIERS = new ConcurrentHashMap<>(); /** * Retrieve the name. diff --git a/src/main/java/com/comphenix/protocol/wrappers/nbt/TileEntityAccessor.java b/src/main/java/com/comphenix/protocol/wrappers/nbt/TileEntityAccessor.java index 24fb104b..76a35323 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/nbt/TileEntityAccessor.java +++ b/src/main/java/com/comphenix/protocol/wrappers/nbt/TileEntityAccessor.java @@ -5,6 +5,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import com.comphenix.protocol.injector.BukkitUnwrapper; @@ -18,8 +19,6 @@ import com.comphenix.protocol.utility.MinecraftMethods; import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftVersion; -import com.google.common.collect.Maps; - import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; import net.bytebuddy.implementation.InvocationHandlerAdapter; import net.bytebuddy.jar.asm.ClassReader; @@ -41,12 +40,12 @@ class TileEntityAccessor { /** * Token indicating that the given block state doesn't contain any tile entities. */ - private static final TileEntityAccessor EMPTY_ACCESSOR = new TileEntityAccessor(); + private static final TileEntityAccessor EMPTY_ACCESSOR = new TileEntityAccessor<>(); /** * Cached field accessors - {@link #EMPTY_ACCESSOR} represents no valid tile entity. */ - private static final ConcurrentMap, TileEntityAccessor> cachedAccessors = Maps.newConcurrentMap(); + private static final ConcurrentMap, TileEntityAccessor> cachedAccessors = new ConcurrentHashMap<>(); private static Constructor nbtCompoundParserConstructor; diff --git a/src/main/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializer.java b/src/main/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializer.java index 27f32cd1..c197d40c 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializer.java +++ b/src/main/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializer.java @@ -5,9 +5,11 @@ import java.nio.IntBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -19,8 +21,6 @@ import com.comphenix.protocol.wrappers.nbt.NbtList; import com.comphenix.protocol.wrappers.nbt.NbtType; import com.comphenix.protocol.wrappers.nbt.NbtVisitor; import com.comphenix.protocol.wrappers.nbt.NbtWrapper; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.primitives.Ints; /** @@ -81,7 +81,7 @@ public class NbtConfigurationSerializer { private List currentList; // Store the index of a configuration section that works like a list - private Map workingIndex = Maps.newHashMap(); + private Map workingIndex = new HashMap<>(); @Override public boolean visitEnter(NbtCompound compound) { @@ -99,7 +99,7 @@ public class NbtConfigurationSerializer { current = current.createSection(name); workingIndex.put(current, 0); } else { - currentList = Lists.newArrayList(); + currentList = new ArrayList<>(); current.set(name, currentList); } return true; @@ -282,17 +282,10 @@ public class NbtConfigurationSerializer { private List sortSet(Set unsorted) { // Convert to integers - List sorted = new ArrayList(unsorted); - - Collections.sort(sorted, new Comparator() { - @Override - public int compare(String o1, String o2) { - // Parse the name - int index1 = Integer.parseInt(getDecodedName(o1)[0]); - int index2 = Integer.parseInt(getDecodedName(o2)[0]); - return Ints.compare(index1, index2); - } - }); + final List sorted = new ArrayList<>(unsorted); + + // Parse the name and sort. + sorted.sort((o1, o2) -> Ints.compare(Integer.parseInt(getDecodedName(o1)[0]), Integer.parseInt(getDecodedName(o2)[0]))); return sorted; }