This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
forked from RedRelay/ForgeCreeperHeal-Legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
123 changed files
with
4,243 additions
and
4,327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
package fr.eyzox.bsc.config; | ||
|
||
import fr.eyzox.bsc.config.option.IConfigOption; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import fr.eyzox.bsc.config.option.IConfigOption; | ||
|
||
public class ConfigOptionGroup { | ||
|
||
private final String name; | ||
private final Map<String, IConfigOption> options = new LinkedHashMap<String, IConfigOption>(); | ||
public ConfigOptionGroup(final String name) { | ||
this.name = name; | ||
} | ||
public String getName() { | ||
return name; | ||
} | ||
public void addOption(final IConfigOption option) { | ||
this.options.put(option.getName(), option); | ||
} | ||
public void removeOption(final String optionName) { | ||
this.options.remove(optionName); | ||
} | ||
public void removeOption(final IConfigOption option) { | ||
this.removeOption(option.getName()); | ||
} | ||
|
||
public IConfigOption getOption(final String name) { | ||
return options.get(name); | ||
} | ||
public Collection<IConfigOption> getOptions() { | ||
return options.values(); | ||
} | ||
private final String name; | ||
private final Map<String, IConfigOption> options = new LinkedHashMap<String, IConfigOption>(); | ||
|
||
public ConfigOptionGroup(final String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void addOption(final IConfigOption option) { | ||
this.options.put(option.getName(), option); | ||
} | ||
|
||
public void removeOption(final String optionName) { | ||
this.options.remove(optionName); | ||
} | ||
|
||
public void removeOption(final IConfigOption option) { | ||
this.removeOption(option.getName()); | ||
} | ||
|
||
public IConfigOption getOption(final String name) { | ||
return options.get(name); | ||
} | ||
|
||
public Collection<IConfigOption> getOptions() { | ||
return options.values(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package fr.eyzox.bsc.config; | ||
|
||
public interface IConfigListener { | ||
public void onChange(final Config config); | ||
public void onChange(final Config config); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package fr.eyzox.bsc.config; | ||
|
||
public interface IConfigProvider { | ||
public Config getConfig(); | ||
public void addConfigListener(final IConfigListener listener); | ||
public void removeConfigListener(final IConfigListener listener); | ||
public void fireConfigChanged(); | ||
public void loadConfig(); | ||
public void unloadConfig(); | ||
public Config getConfig(); | ||
|
||
public void addConfigListener(final IConfigListener listener); | ||
|
||
public void removeConfigListener(final IConfigListener listener); | ||
|
||
public void fireConfigChanged(); | ||
|
||
public void loadConfig(); | ||
|
||
public void unloadConfig(); | ||
} |
149 changes: 72 additions & 77 deletions
149
src/main/java/fr/eyzox/bsc/config/loader/AbstractFileConfigLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,81 @@ | ||
package fr.eyzox.bsc.config.loader; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.nio.file.AccessDeniedException; | ||
import java.nio.file.NoSuchFileException; | ||
|
||
import fr.eyzox.bsc.config.Config; | ||
import fr.eyzox.bsc.exception.InvalidValueException; | ||
|
||
import java.io.*; | ||
import java.nio.file.AccessDeniedException; | ||
import java.nio.file.NoSuchFileException; | ||
|
||
public abstract class AbstractFileConfigLoader implements IConfigLoader { | ||
|
||
private final File file; | ||
private final IErrorManager errorManager = new FileErrorManager(); | ||
public AbstractFileConfigLoader(final File file) { | ||
this.file = file; | ||
} | ||
@Override | ||
public void load(Config config) throws NoSuchFileException, FileNotFoundException, AccessDeniedException, IOException, InvalidValueException{ | ||
if(!file.exists()) { | ||
throw new NoSuchFileException(file.getAbsolutePath()); | ||
} | ||
if(!file.isFile()) { | ||
throw new FileNotFoundException(file.getAbsolutePath() + "is not a file"); | ||
} | ||
if(!file.canRead()) { | ||
throw new AccessDeniedException(file.getAbsolutePath() + "must allow reading"); | ||
} | ||
errorManager.getErrors().clear(); | ||
} | ||
@Override | ||
public void save(Config config) throws FileNotFoundException, AccessDeniedException, IOException { | ||
if(file.exists()) { | ||
if(!file.isFile()) { | ||
throw new FileNotFoundException(file.getAbsolutePath() + " is not a file"); | ||
} | ||
if(!file.canWrite()) { | ||
throw new AccessDeniedException(file.getAbsolutePath()+" must allow writing"); | ||
} | ||
}else if(!file.getParentFile().canWrite()){ | ||
throw new AccessDeniedException(file.getParentFile().getAbsolutePath()+" must allow writing"); | ||
} | ||
} | ||
public File getFile() { | ||
return file; | ||
} | ||
@Override | ||
public IErrorManager getErrorManager() { | ||
return errorManager; | ||
} | ||
protected class FileErrorManager extends ErrorManager { | ||
@Override | ||
public void output(PrintWriter out) throws IOException { | ||
super.output(out); | ||
out.println(); | ||
out.println("-------- ORIGINAL FILE --------"); | ||
out.println(); | ||
BufferedReader in = null; | ||
try { | ||
in = new BufferedReader(new FileReader(file)); | ||
String s = null; | ||
while((s=in.readLine())!=null) { | ||
out.println(s); | ||
} | ||
}finally { | ||
if(in != null) { | ||
in.close(); | ||
} | ||
} | ||
} | ||
} | ||
private final File file; | ||
private final IErrorManager errorManager = new FileErrorManager(); | ||
|
||
public AbstractFileConfigLoader(final File file) { | ||
this.file = file; | ||
} | ||
|
||
@Override | ||
public void load(Config config) throws NoSuchFileException, FileNotFoundException, AccessDeniedException, IOException, InvalidValueException { | ||
if (!file.exists()) { | ||
throw new NoSuchFileException(file.getAbsolutePath()); | ||
} | ||
|
||
if (!file.isFile()) { | ||
throw new FileNotFoundException(file.getAbsolutePath() + "is not a file"); | ||
} | ||
|
||
if (!file.canRead()) { | ||
throw new AccessDeniedException(file.getAbsolutePath() + "must allow reading"); | ||
} | ||
errorManager.getErrors().clear(); | ||
} | ||
|
||
@Override | ||
public void save(Config config) throws FileNotFoundException, AccessDeniedException, IOException { | ||
if (file.exists()) { | ||
if (!file.isFile()) { | ||
throw new FileNotFoundException(file.getAbsolutePath() + " is not a file"); | ||
} | ||
|
||
if (!file.canWrite()) { | ||
throw new AccessDeniedException(file.getAbsolutePath() + " must allow writing"); | ||
} | ||
} else if (!file.getParentFile().canWrite()) { | ||
throw new AccessDeniedException(file.getParentFile().getAbsolutePath() + " must allow writing"); | ||
} | ||
} | ||
|
||
public File getFile() { | ||
return file; | ||
} | ||
|
||
@Override | ||
public IErrorManager getErrorManager() { | ||
return errorManager; | ||
} | ||
|
||
protected class FileErrorManager extends ErrorManager { | ||
@Override | ||
public void output(PrintWriter out) throws IOException { | ||
super.output(out); | ||
out.println(); | ||
out.println("-------- ORIGINAL FILE --------"); | ||
out.println(); | ||
BufferedReader in = null; | ||
try { | ||
in = new BufferedReader(new FileReader(file)); | ||
String s = null; | ||
while ((s = in.readLine()) != null) { | ||
out.println(s); | ||
} | ||
} finally { | ||
if (in != null) { | ||
in.close(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
57 changes: 29 additions & 28 deletions
57
src/main/java/fr/eyzox/bsc/config/loader/ErrorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
package fr.eyzox.bsc.config.loader; | ||
|
||
import fr.eyzox.bsc.exception.ConfigException; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import fr.eyzox.bsc.exception.ConfigException; | ||
public class ErrorManager implements IErrorManager { | ||
|
||
private final List<ConfigException> errors = new LinkedList<ConfigException>(); | ||
|
||
public ErrorManager() { | ||
} | ||
|
||
@Override | ||
public void error(ConfigException exception) { | ||
errors.add(exception); | ||
} | ||
|
||
@Override | ||
public boolean hasErrors() { | ||
return !errors.isEmpty(); | ||
} | ||
|
||
@Override | ||
public void output(final PrintWriter out) throws IOException { | ||
for (final ConfigException e : errors) { | ||
out.println(e.getMessage()); | ||
} | ||
} | ||
|
||
public class ErrorManager implements IErrorManager{ | ||
|
||
private final List<ConfigException> errors = new LinkedList<ConfigException>(); | ||
|
||
public ErrorManager() {} | ||
|
||
@Override | ||
public void error(ConfigException exception) { | ||
errors.add(exception); | ||
} | ||
|
||
@Override | ||
public boolean hasErrors() { | ||
return !errors.isEmpty(); | ||
} | ||
|
||
@Override | ||
public void output(final PrintWriter out) throws IOException{ | ||
for(final ConfigException e : errors) { | ||
out.println(e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public Collection<ConfigException> getErrors() { | ||
return errors; | ||
} | ||
@Override | ||
public Collection<ConfigException> getErrors() { | ||
return errors; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.