From 386668d2212d247c406aae90bc45ff3b31d68dc6 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Wed, 26 Dec 2018 16:50:24 -0800 Subject: [PATCH] Clean up other compiler warnings --- .../worldedit/bukkit/WorldEditPlugin.java | 43 +++++++------------ .../java/com/sk89q/jnbt/ListTagBuilder.java | 2 +- .../sk89q/worldedit/util/FileDialogUtil.java | 2 +- .../worldedit/world/snapshot/Snapshot.java | 7 +-- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 4e74d4814..3899db50f 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -37,6 +37,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extent.inventory.BlockBag; + import org.bstats.bukkit.Metrics; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -181,41 +182,27 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { protected void createDefaultConfiguration(String name) { File actual = new File(getDataFolder(), name); if (!actual.exists()) { - InputStream input = null; - try { - JarFile file = new JarFile(getFile()); + try (JarFile file = new JarFile(getFile())) { ZipEntry copy = file.getEntry("defaults/" + name); if (copy == null) throw new FileNotFoundException(); - input = file.getInputStream(copy); + copyDefaultConfig(file.getInputStream(copy), actual, name); } catch (IOException e) { getLogger().severe("Unable to read default configuration: " + name); } - if (input != null) { - FileOutputStream output = null; + } + } - try { - output = new FileOutputStream(actual); - byte[] buf = new byte[8192]; - int length; - while ((length = input.read(buf)) > 0) { - output.write(buf, 0, length); - } - - getLogger().info("Default configuration file written: " + name); - } catch (IOException e) { - getLogger().log(Level.WARNING, "Failed to write default config file", e); - } finally { - try { - input.close(); - } catch (IOException ignored) {} - - try { - if (output != null) { - output.close(); - } - } catch (IOException ignored) {} - } + private void copyDefaultConfig(InputStream input, File actual, String name) { + try (FileOutputStream output = new FileOutputStream(actual)) { + byte[] buf = new byte[8192]; + int length; + while ((length = input.read(buf)) > 0) { + output.write(buf, 0, length); } + + getLogger().info("Default configuration file written: " + name); + } catch (IOException e) { + getLogger().log(Level.WARNING, "Failed to write default config file", e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java index c410ec3ae..ab2b41399 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java @@ -97,7 +97,7 @@ public class ListTagBuilder { * * @return a new builder */ - public static ListTagBuilder createWith(T ... entries) { + public static ListTagBuilder createWith(Tag... entries) { checkNotNull(entries); if (entries.length == 0) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java index b44850ca7..ff3924558 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java @@ -85,7 +85,7 @@ public final class FileDialogUtil { if (index == -1 || index == path.length() - 1) { return false; } else { - return exts.contains(path.indexOf(index + 1)); + return exts.contains(path.substring(index + 1)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java index d3ca0c251..58525a7d2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java @@ -133,9 +133,10 @@ public class Snapshot implements Comparable { public boolean containsWorld(String worldname) { try { if (file.getName().toLowerCase().endsWith(".zip")) { - ZipFile entry = new ZipFile(file); - return (entry.getEntry(worldname) != null - || entry.getEntry(worldname + "/level.dat") != null); + try (ZipFile entry = new ZipFile(file)) { + return (entry.getEntry(worldname) != null + || entry.getEntry(worldname + "/level.dat") != null); + } } else if (file.getName().toLowerCase().endsWith(".tar.bz2") || file.getName().toLowerCase().endsWith(".tar.gz") || file.getName().toLowerCase().endsWith(".tar")) {