Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bFundamentals/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<artifactId>jNBT</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>
</dependencies>

<build>
Expand All @@ -50,7 +55,9 @@
<artifactSet>
<includes>
<include>commons-*:*</include>
<include>org.jnbt:jNBT</include>
<include>org.jnbt:jNBT</include>
<include>org.javassist:javassist</include>
<include>org.reflections:reflections</include>
<include>org.apache.httpcomponents:*</include>
</includes>
</artifactSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class BukkitConfigurationManager implements ConfigManager {
protected String m_logPrefix = null;
protected DatabaseSettings m_databaseSettings = null;
protected String m_crashPass;
protected File m_moduleDir;

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#loadConfiguration(java.io.File)
Expand All @@ -48,10 +49,14 @@ public class BukkitConfigurationManager implements ConfigManager {
public void loadConfiguration(File configFile) throws IOException {
FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);

config.options().header("bFundamentals configuration");

config.addDefault("general.language", "UK");
config.addDefault("general.debug", false);
config.addDefault("general.crash.password", "Password");

config.addDefault("module.loading.dir", "${plugindir}/modules");

config.addDefault("module.update.enabled", false);
config.addDefault("module.update.download", false);
config.addDefault("module.update.apply", false);
Expand All @@ -66,14 +71,17 @@ public void loadConfiguration(File configFile) throws IOException {
config.addDefault("database.password", "");
config.addDefault("database.port", 3306);
config.addDefault("database.updateRate", 5);


config.options().copyHeader(true);
config.options().copyDefaults(true);
config.save(configFile);

m_language = config.getString("general.language");
m_debug = config.getBoolean("general.debug");
m_crashPass = config.getString("general.crash.password", "Password");

m_moduleDir = parseDirectory(config.getString("module.loading.dir"));

m_autoUpdate = config.getBoolean("module.update.enabled");
m_autoDownload = config.getBoolean("module.update.download");
m_autoApply = config.getBoolean("module.update.apply");
Expand All @@ -92,68 +100,55 @@ public void loadConfiguration(File configFile) throws IOException {

}

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#getDatabaseSettings()
*/
private File parseDirectory(String string) {
string = string.replace("${plugindir}", bFundamentals.getInstance().getDataFolder().getAbsolutePath());
string = string.replace("${basedir}", new File(".").getAbsolutePath());
return new File(string);
}

@Override
public DatabaseSettings getDatabaseSettings() {
return m_databaseSettings;
}

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#getLanguage()
*/
@Override
public String getLanguage() {
return m_language;
}

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#isDebugEnabled()
*/
@Override
public boolean isDebugEnabled() {
return m_debug;
}

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#isAutoUpdateEnabled()
*/
@Override
public boolean isAutoUpdateEnabled() {
return m_autoUpdate;
}

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#isAutoDownloadEnabled()
*/
@Override
public boolean isAutoDownloadEnabled() {
return m_autoDownload;
}

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#isAutoInstallEnabled()
*/
@Override
public boolean isAutoInstallEnabled() {
return m_autoApply;
}

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#getLogPrefix()
*/
@Override
public String getLogPrefix() {
return m_logPrefix;
}

/* (non-Javadoc)
* @see uk.codingbadgers.bFundamentals.ConfigManager#getCrashPassword()
*/
@Override
public String getCrashPassword() {
return m_crashPass;
}

@Override
public File getModuleDirectory() {
return m_moduleDir;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@ public interface ConfigManager {
*/
public abstract String getCrashPassword();

/**
* Gets the current module directory.
*
* @return the module directory
*/
public abstract File getModuleDirectory();

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import ru.tehkode.permissions.bukkit.PermissionsEx;

import uk.codingbadgers.bFundamentals.module.Module;
import uk.codingbadgers.bFundamentals.module.ModuleLoader;
import uk.codingbadgers.bFundamentals.module.loader.ModuleLoader;
import uk.codingbadgers.bFundamentals.player.FundamentalPlayer;
import uk.codingbadgers.bFundamentals.player.FundamentalPlayerArray;
import uk.thecodingbadgers.bDatabaseManager.bDatabaseManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.logging.Level;

import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
Expand All @@ -32,6 +33,7 @@
import com.google.common.collect.ImmutableList.Builder;

import uk.codingbadgers.bFundamentals.bFundamentals;
import uk.codingbadgers.bFundamentals.error.ExceptionHandler;
import uk.codingbadgers.bFundamentals.module.Module;

/**
Expand Down Expand Up @@ -225,30 +227,36 @@ public void addChildCommand(ModuleChildCommand command) {
*/
@Override
public final boolean execute(CommandSender sender, String label, String[] args) {
if (args.length >= 1) {
for (ModuleChildCommand child : m_children) {
if (child.getLabel().equalsIgnoreCase(args[0])) {
m_module.log(Level.INFO, child.getLabel());
// cut first argument (sub command) out of command then handle as child command
args = Arrays.copyOfRange(args, 1, args.length);
return child.execute(sender, label, args);
try {
if (args.length >= 1) {
for (ModuleChildCommand child : m_children) {
if (child.getLabel().equalsIgnoreCase(args[0])) {
m_module.log(Level.INFO, child.getLabel());
// cut first argument (sub command) out of command then handle as child command
args = Arrays.copyOfRange(args, 1, args.length);
return child.execute(sender, label, args);
}
}
}

// for backwards compatibility call old method first, will pass to new if left as default
if (onCommand(sender, label, args)) {
return true;
}

// call command method in module if still not handled
if (m_module.onCommand(sender, label, args)) {
return true;
}

// if not handled for any reason, send usage
Module.sendMessage(m_module.getName(), sender, getUsage());
return false;
} catch (Exception ex) {
ExceptionHandler.handleException(ex);
sender.sendMessage(ChatColor.RED + "Sorry there was a error executing your command.");
return false;
}

// for backwards compatibility call old method first, will pass to new if left as default
if (onCommand(sender, label, args)) {
return true;
}

// call command method in module if still not handled
if (m_module.onCommand(sender, label, args)) {
return true;
}

// if not handled for any reason, send usage
Module.sendMessage(m_module.getName(), sender, getUsage());
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
package uk.codingbadgers.bFundamentals.error;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.logging.Level;

import uk.codingbadgers.bFundamentals.bFundamentals;

/**
* The Class ExceptionHandler, handles exceptions generated by bFundamentals
* and any sub modules.
*/
public class ExceptionHandler implements UncaughtExceptionHandler {

private static final ExceptionHandler instance;
Expand All @@ -28,12 +35,21 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
Thread.setDefaultUncaughtExceptionHandler(instance);
}

/**
* Handle an exception.
*
* @param e the exception caught
* @return true, if successful
*/
public static boolean handleException(Throwable e) {
e.printStackTrace();
bFundamentals.getInstance().getLogger().log(Level.WARNING, null, e);
ReportExceptionRunnable run = new ReportExceptionRunnable(e);
return run.run();
}

/* (non-Javadoc)
* @see java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread, java.lang.Throwable)
*/
@Override
public void uncaughtException(Thread t, Throwable e) {
handleException(e);
Expand Down
Loading