Removed reference to IOUtils & no config warn

I use IOUtils suprisingly often
Made the config name warning test only
This commit is contained in:
Norbi Peti 2019-08-07 18:26:45 +02:00
parent 773277cb27
commit fa6c453a8d
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
7 changed files with 39 additions and 35 deletions

View file

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: commons-io:commons-io:1.3.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/1.3.2/commons-io-1.3.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/1.3.2/commons-io-1.3.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View file

@ -31,6 +31,7 @@
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
<encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -68,6 +69,7 @@
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
</resource> </resource>
</resources> </resources>
<encoding>UTF-8</encoding>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
@ -131,13 +133,6 @@
<version>1.12.2-R0.1-SNAPSHOT</version> <version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>provided</scope>
</dependency>
<!-- Change jitpack.yml to set location of Towny JAR --> <!-- Change jitpack.yml to set location of Towny JAR -->
<dependency> <dependency>
<groupId>com.github.TBMCPlugins.ButtonCore</groupId> <groupId>com.github.TBMCPlugins.ButtonCore</groupId>

View file

@ -5,16 +5,13 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -66,7 +63,7 @@ public class PluginUpdater {
private static boolean updatePluginJitPack(CommandSender sender, String correctname, private static boolean updatePluginJitPack(CommandSender sender, String correctname,
String correctbranch) { String correctbranch) {
URL url; /*URL url;
File result = new File(updatedir, correctname + ".jar"); File result = new File(updatedir, correctname + ".jar");
try { try {
url = new URL("https://jitpack.io/com/github/TBMCPlugins/" url = new URL("https://jitpack.io/com/github/TBMCPlugins/"
@ -93,8 +90,9 @@ public class PluginUpdater {
error(sender, "IO error while updating " + correctname + "\n" + e.getMessage()); error(sender, "IO error while updating " + correctname + "\n" + e.getMessage());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
error(sender, "Unknown error while updating " + correctname + ": " + e); error(sender, "Unknown error while updating " + correctname + ": " + e); - TODO: Either add Commons or don't use FileUtils
} }*/
info(sender, "Plugin updating is currently not supported");
return false; return false;
} }

View file

@ -4,7 +4,6 @@ import buttondevteam.core.MainPlugin;
import buttondevteam.core.component.updater.PluginUpdater; import buttondevteam.core.component.updater.PluginUpdater;
import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.potato.DebugPotato; import buttondevteam.lib.potato.DebugPotato;
import org.apache.commons.io.IOUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -15,10 +14,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
public class TBMCCoreAPI { public class TBMCCoreAPI {
@ -63,7 +59,8 @@ public class TBMCCoreAPI {
InputStream in = con.getInputStream(); InputStream in = con.getInputStream();
String encoding = con.getContentEncoding(); String encoding = con.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding; encoding = encoding == null ? "UTF-8" : encoding;
String body = IOUtils.toString(in, encoding); Scanner s = new Scanner(in).useDelimiter("\\A");
String body = s.hasNext() ? s.next() : "";
in.close(); in.close();
return body; return body;
} }

View file

@ -166,6 +166,7 @@ public final class IHaveConfig {
} }
}).filter(Objects::nonNull).collect(Collectors.toList()); }).filter(Objects::nonNull).collect(Collectors.toList());
} else { } else {
if (TBMCCoreAPI.IsTestServer())
MainPlugin.Instance.getLogger().warning("Method " + m.getName() + " returns a config but its parameters are unknown: " + Arrays.toString(m.getParameterTypes())); MainPlugin.Instance.getLogger().warning("Method " + m.getName() + " returns a config but its parameters are unknown: " + Arrays.toString(m.getParameterTypes()));
continue; continue;
} }

View file

@ -1,6 +1,7 @@
package buttondevteam.lib.chat; package buttondevteam.lib.chat;
import buttondevteam.core.MainPlugin; import buttondevteam.core.MainPlugin;
import lombok.experimental.var;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;

View file

@ -6,9 +6,14 @@ import buttondevteam.lib.player.TBMCPlayerBase;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.UUID; import java.util.UUID;
public class PlayerDataTest extends TestCase { public class PlayerDataTest extends TestCase {
@ -25,7 +30,27 @@ public class PlayerDataTest extends TestCase {
public void testConfig() throws Exception { public void testConfig() throws Exception {
TestPrepare.PrepareServer(); TestPrepare.PrepareServer();
FileUtils.deleteDirectory(new File(ChromaGamerBase.TBMC_PLAYERS_DIR)); //FileUtils.deleteDirectory(new File(ChromaGamerBase.TBMC_PLAYERS_DIR));
Files.walkFileTree(new File(ChromaGamerBase.TBMC_PLAYERS_DIR).toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e)
throws IOException {
if (e == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
// directory iteration failed
throw e;
}
}
});
UUID uuid = new UUID(0L, 0L); UUID uuid = new UUID(0L, 0L);
try (TestPlayerClass p = TBMCPlayerBase.getPlayer(uuid, TestPlayerClass.class)) { try (TestPlayerClass p = TBMCPlayerBase.getPlayer(uuid, TestPlayerClass.class)) {
p.PlayerName().set("Test"); p.PlayerName().set("Test");