From f8bd688fa58c81a7e6c81c1967e5fb4a8178fe2e Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 17 Apr 2022 23:09:53 -0400 Subject: [PATCH] uhhhh uhhhhhh :flushed: --- .../dev/plex/request/AbstractServlet.java | 1 - .../plex/request/SchematicUploadServlet.java | 26 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/plex/request/AbstractServlet.java b/src/main/java/dev/plex/request/AbstractServlet.java index 9a430e6..a1554ee 100644 --- a/src/main/java/dev/plex/request/AbstractServlet.java +++ b/src/main/java/dev/plex/request/AbstractServlet.java @@ -15,7 +15,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.CharacterIterator; import java.text.StringCharacterIterator; -import java.util.Arrays; import java.util.List; import java.util.Objects; import lombok.Data; diff --git a/src/main/java/dev/plex/request/SchematicUploadServlet.java b/src/main/java/dev/plex/request/SchematicUploadServlet.java index 6bda658..e0f38ec 100644 --- a/src/main/java/dev/plex/request/SchematicUploadServlet.java +++ b/src/main/java/dev/plex/request/SchematicUploadServlet.java @@ -28,7 +28,7 @@ public class SchematicUploadServlet extends HttpServlet return; } File[] schematics = worldeditFolder.listFiles(); - Part uploadPart = null; + Part uploadPart; try { uploadPart = req.getPart("file"); @@ -39,19 +39,21 @@ public class SchematicUploadServlet extends HttpServlet return; } String filename = uploadPart.getSubmittedFileName().replaceAll("[^a-zA-Z0-9'!,_ .-]", "_"); - if (schemNameMatcher.matcher(filename).matches()) + if (!schemNameMatcher.matcher(filename).matches()) { - boolean alreadyExists = schematics != null && Arrays.stream(schematics).anyMatch(file -> HTTPDModule.fileNameEquals(file.getName(), filename)); - if (alreadyExists) - { - resp.getWriter().println(schematicUploadBadHTML("A schematic with the name " + filename + " already exists!")); - return; - } - InputStream inputStream = uploadPart.getInputStream(); - Files.copy(inputStream, new File(worldeditFolder, filename).toPath(), StandardCopyOption.REPLACE_EXISTING); - inputStream.close(); - resp.getWriter().println(schematicUploadGoodHTML("Successfully uploaded " + filename + ".")); + resp.getWriter().println(schematicUploadBadHTML("That is not a valid schematic filename!")); + return; } + boolean alreadyExists = schematics != null && Arrays.stream(schematics).anyMatch(file -> HTTPDModule.fileNameEquals(file.getName(), filename)); + if (alreadyExists) + { + resp.getWriter().println(schematicUploadBadHTML("A schematic with the name " + filename + " already exists!")); + return; + } + InputStream inputStream = uploadPart.getInputStream(); + Files.copy(inputStream, new File(worldeditFolder, filename).toPath(), StandardCopyOption.REPLACE_EXISTING); + inputStream.close(); + resp.getWriter().println(schematicUploadGoodHTML("Successfully uploaded " + filename + ".")); } private String schematicUploadBadHTML(String message)