From 4542e9511b3445472852fcd936ab0787c72fbdc1 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Fri, 23 Aug 2019 22:13:37 +0200 Subject: [PATCH] Set some object fields to finals, use lambdas --- .../us/myles/ViaVersion/ViaVersionPlugin.java | 12 ++--- .../bukkit/commands/BukkitCommandSender.java | 2 +- .../multiversion/PlayerSneakListener.java | 5 ++- .../protocol1_9to1_8/HandItemCache.java | 11 +++-- .../bukkit/platform/BukkitTaskId.java | 2 +- .../bukkit/platform/BukkitViaAPI.java | 2 +- .../bukkit/platform/BukkitViaInjector.java | 4 +- .../bukkit/platform/BukkitViaLoader.java | 16 ++++--- .../BukkitInventoryQuickMoveProvider.java | 12 ++--- .../BukkitInventoryUpdateTask.java | 2 +- .../myles/ViaVersion/bukkit/util/NMSUtil.java | 4 +- .../myles/ViaVersion/AbstractViaConfig.java | 2 +- .../java/us/myles/ViaVersion/ViaManager.java | 31 ++++++------- .../ViaVersion/api/data/StoredObject.java | 2 +- .../api/rewriters/MetadataRewriter.java | 1 - .../commands/ViaCommandHandler.java | 2 +- .../exception/InformativeException.java | 6 +-- .../ChannelHandlerContextWrapper.java | 4 +- .../myles/ViaVersion/packets/PacketType.java | 8 ++-- .../myles/ViaVersion/update/UpdateUtil.java | 44 +++++-------------- .../java/us/myles/ViaVersion/util/Config.java | 19 ++++---- 21 files changed, 82 insertions(+), 109 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index ada518e35..5f7cf42af 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -28,17 +28,17 @@ import java.util.UUID; public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { - private BukkitCommandHandler commandHandler; + private final BukkitCommandHandler commandHandler; private boolean compatSpigotBuild = false; private boolean spigot = true; private boolean lateBind = false; private boolean protocolSupport = false; @Getter - private BukkitViaConfig conf; + private final BukkitViaConfig conf; @Getter - private ViaAPI api = new BukkitViaAPI(this); - private List queuedTasks = new ArrayList<>(); - private List asyncQueuedTasks = new ArrayList<>(); + private final ViaAPI api = new BukkitViaAPI(this); + private final List queuedTasks = new ArrayList<>(); + private final List asyncQueuedTasks = new ArrayList<>(); public ViaVersionPlugin() { // Command handler @@ -238,7 +238,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) { getLogger().severe("ViaVersion is already loaded, we're going to kick all the players... because otherwise we'll crash because of ProtocolLib."); for (Player player : Bukkit.getOnlinePlayers()) { - player.kickPlayer(ChatColor.translateAlternateColorCodes('&', getConf().getReloadDisconnectMsg())); + player.kickPlayer(ChatColor.translateAlternateColorCodes('&', conf.getReloadDisconnectMsg())); } } else { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/commands/BukkitCommandSender.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/commands/BukkitCommandSender.java index e1288ca29..9e08186ca 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/commands/BukkitCommandSender.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/commands/BukkitCommandSender.java @@ -9,7 +9,7 @@ import java.util.UUID; @AllArgsConstructor public class BukkitCommandSender implements ViaCommandSender { - private CommandSender sender; + private final CommandSender sender; @Override public boolean hasPermission(String permission) { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java index a44dc1e74..760839394 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java @@ -23,12 +23,13 @@ public class PlayerSneakListener extends ViaBukkitListener { private static final float HEIGHT_1_9 = 1.6F; private static final float DEFAULT_WIDTH = 0.6F; + private final boolean is1_9Fix; + private final boolean is1_14Fix; private Map sneaking; // true = 1.14+, else false private Set sneakingUuids; private Method getHandle; private Method setSize; - private boolean is1_9Fix; - private boolean is1_14Fix; + private boolean useCache; public PlayerSneakListener(ViaVersionPlugin plugin, boolean is1_9Fix, boolean is1_14Fix) { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/HandItemCache.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/HandItemCache.java index 4cf432898..4154ad0c1 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/HandItemCache.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/protocol1_9to1_8/HandItemCache.java @@ -13,12 +13,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; public class HandItemCache extends BukkitRunnable { - public static boolean CACHE = false; - private static Map handCache = new ConcurrentHashMap<>(); - - public static Item getHandItem(UUID player) { - return handCache.get(player); - } + private final Map handCache = new ConcurrentHashMap<>(); @Override public void run() { @@ -34,6 +29,10 @@ public class HandItemCache extends BukkitRunnable { } } + public Item getHandItem(UUID player) { + return handCache.get(player); + } + public static Item convert(ItemStack itemInHand) { if (itemInHand == null) return new Item((short) 0, (byte) 0, (short) 0, null); return new Item((short) itemInHand.getTypeId(), (byte) itemInHand.getAmount(), itemInHand.getDurability(), null); diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitTaskId.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitTaskId.java index 50685a297..462aa0848 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitTaskId.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitTaskId.java @@ -7,5 +7,5 @@ import us.myles.ViaVersion.api.platform.TaskId; @Getter @AllArgsConstructor public class BukkitTaskId implements TaskId { - private Integer object; + private final Integer object; } diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java index d76cece62..a2ca54db9 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java @@ -26,7 +26,7 @@ import java.util.UUID; @AllArgsConstructor public class BukkitViaAPI implements ViaAPI, ViaVersionAPI { - private ViaVersionPlugin plugin; + private final ViaVersionPlugin plugin; @Override public int getPlayerVersion(@NonNull Player player) { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java index 004cb07ea..965098e06 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaInjector.java @@ -21,8 +21,8 @@ import java.lang.reflect.Method; import java.util.List; public class BukkitViaInjector implements ViaInjector { - private List injectedFutures = new ConcurrentList<>(); - private List> injectedLists = new ConcurrentList<>(); + private final List injectedFutures = new ConcurrentList<>(); + private final List> injectedLists = new ConcurrentList<>(); @Override public void inject() throws Exception { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java index b2e3e82e8..e1ca3ed94 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaLoader.java @@ -37,10 +37,12 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; public class BukkitViaLoader implements ViaPlatformLoader { - private ViaVersionPlugin plugin; + private final ViaVersionPlugin plugin; - private Set listeners = new HashSet<>(); - private Set tasks = new HashSet<>(); + private final Set listeners = new HashSet<>(); + private final Set tasks = new HashSet<>(); + + private HandItemCache handItemCache; public BukkitViaLoader(ViaVersionPlugin plugin) { this.plugin = plugin; @@ -94,8 +96,8 @@ public class BukkitViaLoader implements ViaPlatformLoader { storeListener(new PaperPatch(plugin)).register(); } if (plugin.getConf().isItemCache()) { - tasks.add(new HandItemCache().runTaskTimerAsynchronously(plugin, 2L, 2L)); // Updates player's items :) - HandItemCache.CACHE = true; + handItemCache = new HandItemCache(); + tasks.add(handItemCache.runTaskTimerAsynchronously(plugin, 2L, 2L)); // Updates player's items :) } /* Providers */ @@ -110,8 +112,8 @@ public class BukkitViaLoader implements ViaPlatformLoader { Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() { @Override public Item getHandItem(final UserConnection info) { - if (HandItemCache.CACHE) { - return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid()); + if (handItemCache != null) { + return handItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid()); } else { try { return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable() { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java index f2586442c..dc9f72de6 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitInventoryQuickMoveProvider.java @@ -26,8 +26,8 @@ import java.util.logging.Level; public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider { - private static Map updateTasks = new ConcurrentHashMap(); - private boolean supported; + private static final Map UPDATE_TASK = new ConcurrentHashMap<>(); + private final boolean supported; // packet class private Class windowClickPacketClass; private Object clickTypeEnum; @@ -65,11 +65,11 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider } ProtocolInfo info = userConnection.get(ProtocolInfo.class); UUID uuid = info.getUuid(); - BukkitInventoryUpdateTask updateTask = updateTasks.get(uuid); + BukkitInventoryUpdateTask updateTask = UPDATE_TASK.get(uuid); final boolean registered = updateTask != null; if (!registered) { updateTask = new BukkitInventoryUpdateTask(this, uuid); - updateTasks.put(uuid, updateTask); + UPDATE_TASK.put(uuid, updateTask); } // http://wiki.vg/index.php?title=Protocol&oldid=13223#Click_Window updateTask.addItem(windowId, slotId, actionId); @@ -93,7 +93,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider if (tinvtype == InventoryType.BREWING) { // 1.9 added the blaze powder slot to brewing stand fix for 1.8 servers if (slotId >= 5 && slotId <= 40) { - slotId = (short) (slotId - 1); + slotId -= 1; } } } @@ -147,7 +147,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider } public void onTaskExecuted(UUID uuid) { - updateTasks.remove(uuid); + UPDATE_TASK.remove(uuid); } private void setupReflection() { diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java index 529363b8c..58eb01430 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java @@ -12,7 +12,7 @@ import java.util.UUID; public class BukkitInventoryUpdateTask implements Runnable { - private BukkitInventoryQuickMoveProvider provider; + private final BukkitInventoryQuickMoveProvider provider; private final UUID uuid; private final List items; diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/util/NMSUtil.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/util/NMSUtil.java index d01884ecb..b3f6186d7 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/util/NMSUtil.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/util/NMSUtil.java @@ -3,8 +3,8 @@ package us.myles.ViaVersion.bukkit.util; import org.bukkit.Bukkit; public class NMSUtil { - private static String BASE = Bukkit.getServer().getClass().getPackage().getName(); - private static String NMS = BASE.replace("org.bukkit.craftbukkit", "net.minecraft.server"); + private static final String BASE = Bukkit.getServer().getClass().getPackage().getName(); + private static final String NMS = BASE.replace("org.bukkit.craftbukkit", "net.minecraft.server"); public static Class nms(String className) throws ClassNotFoundException { return Class.forName(NMS + "." + className); diff --git a/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java b/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java index 94a69c280..5213002b5 100644 --- a/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/AbstractViaConfig.java @@ -8,7 +8,7 @@ import java.util.List; public abstract class AbstractViaConfig extends Config implements ViaVersionConfig { - public AbstractViaConfig(File configFile) { + protected AbstractViaConfig(File configFile) { super(configFile); } diff --git a/common/src/main/java/us/myles/ViaVersion/ViaManager.java b/common/src/main/java/us/myles/ViaVersion/ViaManager.java index a733cbb94..25563b050 100644 --- a/common/src/main/java/us/myles/ViaVersion/ViaManager.java +++ b/common/src/main/java/us/myles/ViaVersion/ViaManager.java @@ -21,14 +21,14 @@ import java.util.concurrent.ConcurrentHashMap; @Getter public class ViaManager { private final Map portedPlayers = new ConcurrentHashMap<>(); - private ViaPlatform platform; - private ViaProviders providers = new ViaProviders(); + private final ViaPlatform platform; + private final ViaProviders providers = new ViaProviders(); @Setter private boolean debug = false; // Internals - private ViaInjector injector; - private ViaCommandHandler commandHandler; - private ViaPlatformLoader loader; + private final ViaInjector injector; + private final ViaCommandHandler commandHandler; + private final ViaPlatformLoader loader; @Builder public ViaManager(ViaPlatform platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) { @@ -52,19 +52,14 @@ public class ViaManager { try { injector.inject(); } catch (Exception e) { - getPlatform().getLogger().severe("ViaVersion failed to inject:"); + platform.getLogger().severe("ViaVersion failed to inject:"); e.printStackTrace(); return; } // Mark as injected - System.setProperty("ViaVersion", getPlatform().getPluginVersion()); + System.setProperty("ViaVersion", platform.getPluginVersion()); // If successful - platform.runSync(new Runnable() { - @Override - public void run() { - onServerLoaded(); - } - }); + platform.runSync(this::onServerLoaded); } @@ -73,14 +68,14 @@ public class ViaManager { try { ProtocolRegistry.SERVER_PROTOCOL = injector.getServerProtocolVersion(); } catch (Exception e) { - getPlatform().getLogger().severe("ViaVersion failed to get the server protocol!"); + platform.getLogger().severe("ViaVersion failed to get the server protocol!"); e.printStackTrace(); } // Check if there are any pipes to this version if (ProtocolRegistry.SERVER_PROTOCOL != -1) { - getPlatform().getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL)); + platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL)); if (!ProtocolRegistry.isWorkingPipe()) { - getPlatform().getLogger().warning("ViaVersion does not have any compatible versions for this server version, please read our resource page carefully."); + platform.getLogger().warning("ViaVersion does not have any compatible versions for this server version, please read our resource page carefully."); } } // Load Listeners / Tasks @@ -95,11 +90,11 @@ public class ViaManager { public void destroy() { // Uninject - getPlatform().getLogger().info("ViaVersion is disabling, if this is a reload and you experience issues consider rebooting."); + platform.getLogger().info("ViaVersion is disabling, if this is a reload and you experience issues consider rebooting."); try { injector.uninject(); } catch (Exception e) { - getPlatform().getLogger().severe("ViaVersion failed to uninject:"); + platform.getLogger().severe("ViaVersion failed to uninject:"); e.printStackTrace(); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java b/common/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java index 80d7e2a85..3b9f8c3a9 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java +++ b/common/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java @@ -6,5 +6,5 @@ import lombok.Getter; @Getter @AllArgsConstructor public class StoredObject { - private UserConnection user; + private final UserConnection user; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index a0a5e2e88..cb0413cdf 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -23,7 +23,6 @@ public abstract class MetadataRewriter { metadataMap = Collections.unmodifiableMap(metadataMap); for (Metadata metadata : new ArrayList<>(metadatas)) { - int oldId = metadata.getId(); try { handleMetadata(entityId, type, metadata, metadatas, metadataMap, connection); } catch (Exception e) { diff --git a/common/src/main/java/us/myles/ViaVersion/commands/ViaCommandHandler.java b/common/src/main/java/us/myles/ViaVersion/commands/ViaCommandHandler.java index a406835bb..9935fc48c 100644 --- a/common/src/main/java/us/myles/ViaVersion/commands/ViaCommandHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/commands/ViaCommandHandler.java @@ -107,7 +107,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand { */ public void showHelp(ViaCommandSender sender) { Set allowed = calculateAllowedCommands(sender); - if (allowed.size() == 0) { + if (allowed.isEmpty()) { sender.sendMessage(color("&cYou are not allowed to use these commands!")); return; } diff --git a/common/src/main/java/us/myles/ViaVersion/exception/InformativeException.java b/common/src/main/java/us/myles/ViaVersion/exception/InformativeException.java index 969d5acab..433c45e65 100644 --- a/common/src/main/java/us/myles/ViaVersion/exception/InformativeException.java +++ b/common/src/main/java/us/myles/ViaVersion/exception/InformativeException.java @@ -4,8 +4,8 @@ import java.util.HashMap; import java.util.Map; public class InformativeException extends Exception { - final Map info = new HashMap<>(); - int sources = 0; + private final Map info = new HashMap<>(); + private int sources = 0; public InformativeException(Throwable cause) { super(cause); @@ -34,7 +34,7 @@ public class InformativeException extends Exception { builder.append("Please post this error to http://github.com/ViaVersion/ViaVersion/issues\n{"); int i = 0; for (Map.Entry entry : info.entrySet()) { - builder.append((i == 0 ? "" : ", ") + entry.getKey() + ": " + entry.getValue().toString()); + builder.append(i == 0 ? "" : ", ").append(entry.getKey()).append(": ").append(entry.getValue().toString()); i++; } builder.append("}\nActual Error: "); diff --git a/common/src/main/java/us/myles/ViaVersion/handlers/ChannelHandlerContextWrapper.java b/common/src/main/java/us/myles/ViaVersion/handlers/ChannelHandlerContextWrapper.java index 717eaac7d..7a57d4269 100644 --- a/common/src/main/java/us/myles/ViaVersion/handlers/ChannelHandlerContextWrapper.java +++ b/common/src/main/java/us/myles/ViaVersion/handlers/ChannelHandlerContextWrapper.java @@ -10,8 +10,8 @@ import io.netty.util.concurrent.EventExecutor; import java.net.SocketAddress; public class ChannelHandlerContextWrapper implements ChannelHandlerContext { - private ChannelHandlerContext base; - private ViaHandler handler; + private final ChannelHandlerContext base; + private final ViaHandler handler; public ChannelHandlerContextWrapper(ChannelHandlerContext base, ViaHandler handler) { this.base = base; diff --git a/common/src/main/java/us/myles/ViaVersion/packets/PacketType.java b/common/src/main/java/us/myles/ViaVersion/packets/PacketType.java index b3077806b..e468f24b4 100644 --- a/common/src/main/java/us/myles/ViaVersion/packets/PacketType.java +++ b/common/src/main/java/us/myles/ViaVersion/packets/PacketType.java @@ -150,10 +150,10 @@ public enum PacketType { } } - private State state; - private Direction direction; - private int packetID; - private int newPacketID = -1; + private final State state; + private final Direction direction; + private final int packetID; + private final int newPacketID; PacketType(State state, Direction direction, int packetID) { this.state = state; diff --git a/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java b/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java index e4b8f4ad0..5e9047d52 100644 --- a/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java +++ b/common/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java @@ -17,45 +17,25 @@ import java.util.UUID; public class UpdateUtil { - public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN; - private final static String URL = "https://api.spiget.org/v2/resources/"; - private final static int PLUGIN = 19254; - private final static String LATEST_VERSION = "/versions/latest"; + public static final String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN; + private static final String URL = "https://api.spiget.org/v2/resources/"; + private static final int PLUGIN = 19254; + private static final String LATEST_VERSION = "/versions/latest"; public static void sendUpdateMessage(final UUID uuid) { - Via.getPlatform().runAsync(new Runnable() { - @Override - public void run() { - final String message = getUpdateMessage(false); - if (message != null) { - Via.getPlatform().runSync( - new Runnable() { - @Override - public void run() { - Via.getPlatform().sendMessage(uuid, PREFIX + message); - } - } - ); - } + Via.getPlatform().runAsync(() -> { + final String message = getUpdateMessage(false); + if (message != null) { + Via.getPlatform().runSync(() -> Via.getPlatform().sendMessage(uuid, PREFIX + message)); } }); } public static void sendUpdateMessage() { - Via.getPlatform().runAsync(new Runnable() { - @Override - public void run() { - final String message = getUpdateMessage(true); - if (message != null) { - Via.getPlatform().runSync( - new Runnable() { - @Override - public void run() { - Via.getPlatform().getLogger().warning(message); - } - } - ); - } + Via.getPlatform().runAsync(() -> { + final String message = getUpdateMessage(true); + if (message != null) { + Via.getPlatform().runSync(() -> Via.getPlatform().getLogger().warning(message)); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/util/Config.java b/common/src/main/java/us/myles/ViaVersion/util/Config.java index 0ebfc1605..0ad123812 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/Config.java +++ b/common/src/main/java/us/myles/ViaVersion/util/Config.java @@ -14,18 +14,15 @@ import java.util.Map; import java.util.concurrent.ConcurrentSkipListMap; public abstract class Config implements ConfigurationProvider { - private static final ThreadLocal YAML = new ThreadLocal() { - @Override - protected Yaml initialValue() { - DumperOptions options = new DumperOptions(); - options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - options.setPrettyFlow(false); - options.setIndent(2); - return new Yaml(new YamlConstructor(), new Representer(), options); - } - }; + private static final ThreadLocal YAML = ThreadLocal.withInitial(() -> { + DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + options.setPrettyFlow(false); + options.setIndent(2); + return new Yaml(new YamlConstructor(), new Representer(), options); + }); - private CommentStore commentStore = new CommentStore('.', 2); + private final CommentStore commentStore = new CommentStore('.', 2); private final File configFile; private ConcurrentSkipListMap config;