Make some JavaPlugin methods final. Fixes BUKKIT-2916

These methods were never intended to be overwritten, and bukkit relies
on their internal functionality. Additionally, the methods were inlined
in JavaPlugin, but the finality maintains intention.
This commit is contained in:
Wesley Wolfe 2012-11-13 15:38:46 -06:00 committed by Travis Watkins
parent 39b3aa8e0d
commit 6ebc1cd7ce

View File

@ -57,7 +57,7 @@ public abstract class JavaPlugin extends PluginBase {
* *
* @return The folder. * @return The folder.
*/ */
public File getDataFolder() { public final File getDataFolder() {
return dataFolder; return dataFolder;
} }
@ -102,7 +102,7 @@ public abstract class JavaPlugin extends PluginBase {
* *
* @return Contents of the plugin.yaml file * @return Contents of the plugin.yaml file
*/ */
public PluginDescriptionFile getDescription() { public final PluginDescriptionFile getDescription() {
return description; return description;
} }
@ -128,12 +128,12 @@ public abstract class JavaPlugin extends PluginBase {
try { try {
getConfig().save(configFile); getConfig().save(configFile);
} catch (IOException ex) { } catch (IOException ex) {
getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex); logger.log(Level.SEVERE, "Could not save config to " + configFile, ex);
} }
} }
public void saveDefaultConfig() { public void saveDefaultConfig() {
if (!new File(getDataFolder(), "config.yml").exists()) { if (!configFile.exists()) {
saveResource("config.yml", false); saveResource("config.yml", false);
} }
} }
@ -146,12 +146,12 @@ public abstract class JavaPlugin extends PluginBase {
resourcePath = resourcePath.replace('\\', '/'); resourcePath = resourcePath.replace('\\', '/');
InputStream in = getResource(resourcePath); InputStream in = getResource(resourcePath);
if (in == null) { if (in == null) {
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + getFile()); throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + file);
} }
File outFile = new File(getDataFolder(), resourcePath); File outFile = new File(dataFolder, resourcePath);
int lastIndex = resourcePath.lastIndexOf('/'); int lastIndex = resourcePath.lastIndexOf('/');
File outDir = new File(getDataFolder(), resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0)); File outDir = new File(dataFolder, resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));
if (!outDir.exists()) { if (!outDir.exists()) {
outDir.mkdirs(); outDir.mkdirs();
@ -168,10 +168,10 @@ public abstract class JavaPlugin extends PluginBase {
out.close(); out.close();
in.close(); in.close();
} else { } else {
getLogger().log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists."); logger.log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
} }
} catch (IOException ex) { } catch (IOException ex) {
getLogger().log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, ex); logger.log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, ex);
} }
} }
@ -200,7 +200,7 @@ public abstract class JavaPlugin extends PluginBase {
* *
* @return ClassLoader holding this plugin * @return ClassLoader holding this plugin
*/ */
protected ClassLoader getClassLoader() { protected final ClassLoader getClassLoader() {
return classLoader; return classLoader;
} }
@ -209,7 +209,7 @@ public abstract class JavaPlugin extends PluginBase {
* *
* @param enabled true if enabled, otherwise false * @param enabled true if enabled, otherwise false
*/ */
protected void setEnabled(final boolean enabled) { protected final void setEnabled(final boolean enabled) {
if (isEnabled != enabled) { if (isEnabled != enabled) {
isEnabled = enabled; isEnabled = enabled;
@ -243,6 +243,7 @@ public abstract class JavaPlugin extends PluginBase {
this.dataFolder = dataFolder; this.dataFolder = dataFolder;
this.classLoader = classLoader; this.classLoader = classLoader;
this.configFile = new File(dataFolder, "config.yml"); this.configFile = new File(dataFolder, "config.yml");
this.logger = new PluginLogger(this);
if (description.isDatabaseEnabled()) { if (description.isDatabaseEnabled()) {
ServerConfig db = new ServerConfig(); ServerConfig db = new ServerConfig();
@ -256,7 +257,7 @@ public abstract class JavaPlugin extends PluginBase {
DataSourceConfig ds = db.getDataSourceConfig(); DataSourceConfig ds = db.getDataSourceConfig();
ds.setUrl(replaceDatabaseString(ds.getUrl())); ds.setUrl(replaceDatabaseString(ds.getUrl()));
getDataFolder().mkdirs(); dataFolder.mkdirs();
ClassLoader previous = Thread.currentThread().getContextClassLoader(); ClassLoader previous = Thread.currentThread().getContextClassLoader();
@ -277,8 +278,8 @@ public abstract class JavaPlugin extends PluginBase {
} }
private String replaceDatabaseString(String input) { private String replaceDatabaseString(String input) {
input = input.replaceAll("\\{DIR\\}", getDataFolder().getPath().replaceAll("\\\\", "/") + "/"); input = input.replaceAll("\\{DIR\\}", dataFolder.getPath().replaceAll("\\\\", "/") + "/");
input = input.replaceAll("\\{NAME\\}", getDescription().getName().replaceAll("[^\\w_-]", "")); input = input.replaceAll("\\{NAME\\}", description.getName().replaceAll("[^\\w_-]", ""));
return input; return input;
} }
@ -287,7 +288,7 @@ public abstract class JavaPlugin extends PluginBase {
* *
* @return true if this plugin is initialized, otherwise false * @return true if this plugin is initialized, otherwise false
*/ */
public boolean isInitialized() { public final boolean isInitialized() {
return initialized; return initialized;
} }
@ -316,7 +317,7 @@ public abstract class JavaPlugin extends PluginBase {
PluginCommand command = getServer().getPluginCommand(alias); PluginCommand command = getServer().getPluginCommand(alias);
if ((command != null) && (command.getPlugin() != this)) { if ((command != null) && (command.getPlugin() != this)) {
command = getServer().getPluginCommand(getDescription().getName().toLowerCase() + ":" + alias); command = getServer().getPluginCommand(description.getName().toLowerCase() + ":" + alias);
} }
if ((command != null) && (command.getPlugin() == this)) { if ((command != null) && (command.getPlugin() == this)) {
@ -333,7 +334,7 @@ public abstract class JavaPlugin extends PluginBase {
public void onEnable() {} public void onEnable() {}
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
getServer().getLogger().severe("Plugin " + getDescription().getFullName() + " does not contain any generators that may be used in the default world!"); getServer().getLogger().severe("Plugin " + description.getFullName() + " does not contain any generators that may be used in the default world!");
return null; return null;
} }
@ -363,15 +364,12 @@ public abstract class JavaPlugin extends PluginBase {
gen.runScript(true, gen.generateDropDdl()); gen.runScript(true, gen.generateDropDdl());
} }
public Logger getLogger() { public final Logger getLogger() {
if (logger == null) {
logger = new PluginLogger(this);
}
return logger; return logger;
} }
@Override @Override
public String toString() { public String toString() {
return getDescription().getFullName(); return description.getFullName();
} }
} }