Fix FileAlreadyExistsException for sym linked folders

This commit is contained in:
games647 2018-01-27 21:53:34 +01:00
parent 8e73eecd51
commit c7e431e6fc
No known key found for this signature in database
GPG Key ID: BFC68C8708713A88
8 changed files with 22 additions and 23 deletions

View File

@ -4,7 +4,9 @@
## Description
This lightweight plugin to make your console more colorful. It colorize the message depending on the log level. This means that important error messages will be printed in a red color. This gives you and your administrators a better overview about what's happening on your server.
This lightweight plugin to make your console more colorful. It colorize the message depending on the log level. This
means that important error messages will be printed in a red color. This gives you and your administrators a better
overview about what's happening on your server.
## Features

View File

@ -1,13 +1,12 @@
package com.github.games647.colorconsole.bukkit;
import com.github.games647.colorconsole.common.CommonLogInstaller;
import com.google.common.collect.Maps;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Layout;
@ -23,7 +22,7 @@ public class ColorConsoleBukkit extends JavaPlugin {
@Override
public void onLoad() {
Map<String, String> levelColors = Maps.newHashMap();
Map<String, String> levelColors = new HashMap<>();
levelColors.put("FATAL", getConfig().getString("FATAL"));
levelColors.put("ERROR", getConfig().getString("ERROR"));
levelColors.put("WARN", getConfig().getString("WARN"));
@ -95,7 +94,7 @@ public class ColorConsoleBukkit extends JavaPlugin {
}
ColorPluginAppender pluginAppender = new ColorPluginAppender(terminalAppender, getConfig(), levelColors);
Map<String, String> colors = Maps.newHashMap();
Map<String, String> colors = new HashMap<>();
for (Map.Entry<String, Object> entry : getConfig().getValues(false).entrySet()) {
if (!entry.getKey().startsWith("P-")) {
continue;

View File

@ -15,7 +15,7 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.SimpleMessage;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.Plugin;
public class ColorPluginAppender extends ColorAppender {
@ -23,7 +23,7 @@ public class ColorPluginAppender extends ColorAppender {
private static final Set<String> disabledPrefix = Sets.newHashSet("net.minecraft", "Minecraft"
, "com.mojang", "com.sk89q", "ru.tehkode", "Minecraft.AWE");
public ColorPluginAppender(Appender oldAppender, FileConfiguration config, Map<String, String> levelColors) {
public ColorPluginAppender(Appender oldAppender, ConfigurationSection config, Map<String, String> levelColors) {
super(oldAppender
, config.getStringList("hide-messages")
, config.getBoolean("colorPluginTag")
@ -34,9 +34,9 @@ public class ColorPluginAppender extends ColorAppender {
@Override
public LogEvent onAppend(LogEvent logEvent) {
String oldMessage = logEvent.getMessage().getFormattedMessage();
String prefix = "[" + logEvent.getLoggerName() + "] ";
String prefix = '[' + logEvent.getLoggerName() + "] ";
if (!oldMessage.contains(prefix)
&& !disabledPrefix.stream().anyMatch(disabled -> logEvent.getLoggerName().startsWith(disabled))) {
&& disabledPrefix.stream().noneMatch(disabled -> logEvent.getLoggerName().startsWith(disabled))) {
oldMessage = prefix + oldMessage;
}

View File

@ -64,16 +64,19 @@ public class ColorConsoleBungee extends Plugin {
Formatter oldFormatter = handler.getFormatter();
ColorLogFormatter newFormatter = new ColorLogFormatter(this, oldFormatter);
newFormatter.initPluginColors(getConfiguration().getString("PLUGIN"));
newFormatter.initPluginColors(configuration.getString("PLUGIN"));
handler.setFormatter(newFormatter);
}
}
private void saveDefaultConfig() {
try {
Files.createDirectories(getDataFolder().toPath());
Path dataFolder = getDataFolder().toPath();
if (Files.notExists(dataFolder)) {
Files.createDirectories(dataFolder);
}
Path configFile = getDataFolder().toPath().resolve("config.yml");
Path configFile = dataFolder.resolve("config.yml");
if (Files.notExists(configFile)) {
try (InputStream in = getResourceAsStream("config.yml")) {
Files.copy(in, configFile);

View File

@ -1,7 +1,6 @@
package com.github.games647.colorconsole.bungee;
import com.github.games647.colorconsole.common.CommonFormatter;
import com.google.common.collect.Maps;
import java.io.PrintWriter;
import java.io.StringWriter;
@ -35,7 +34,7 @@ public class ColorLogFormatter extends Formatter {
boolean colorizeTag = plugin.getConfiguration().getBoolean("colorPluginTag");
boolean truncateColor = plugin.getConfiguration().getBoolean("truncateColor", false);
Map<String, String> levelColors = Maps.newHashMap();
Map<String, String> levelColors = new HashMap<>();
if (plugin.getConfiguration().getBoolean("colorMessage", false)) {
levelColors.put("FATAL", plugin.getConfiguration().getString("FATAL"));
levelColors.put("ERROR", plugin.getConfiguration().getString("ERROR"));

View File

@ -9,7 +9,6 @@ import io.netty.util.internal.ThreadLocalRandom;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.fusesource.jansi.Ansi;

View File

@ -1,23 +1,22 @@
package com.github.games647.colorconsole.sponge;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import ninja.leaping.configurate.objectmapping.Setting;
public class ColorConsoleConfig {
public ColorConsoleConfig() {
this.pluginColors = Maps.newHashMap();
this.pluginColors = new HashMap<>();
this.pluginColors.put("ColorConsole", "yellow");
this.levelColors = Maps.newHashMap();
this.levelColors = new HashMap<>();
this.levelColors.put("FATAL", "red blink");
this.levelColors.put("ERROR", "red");
this.levelColors.put("WARN", "yellow bold");
@ -67,7 +66,7 @@ public class ColorConsoleConfig {
@Setting(comment = "Hides the log message if it contains one or more of the following texts\n"
+ "The texts are case-sensitive")
private final List<String> hideMessages = Lists.newArrayList();
private final List<String> hideMessages = new ArrayList<>();
@Setting(comment = "Removes color formatting if the complete message has color formatting")
private boolean truncateColor;

View File

@ -5,10 +5,8 @@ import com.google.inject.Inject;
import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Path;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.objectmapping.ObjectMapper;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;