[trunk] Adding dependancy checker, need to fix timings as Protect tries to use it before the file system finishes

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1579 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
ementalo 2011-06-03 14:23:55 +00:00
parent 1a572bca2e
commit e94a01b149
12 changed files with 193 additions and 111 deletions

View File

@ -50,6 +50,7 @@ public class Essentials extends JavaPlugin implements IEssentials
private EssentialsEntityListener entityListener; private EssentialsEntityListener entityListener;
private JailPlayerListener jailPlayerListener; private JailPlayerListener jailPlayerListener;
private TNTExplodeListener tntListener; private TNTExplodeListener tntListener;
private EssentialsDependancyChecker essDep;
private static Essentials instance = null; private static Essentials instance = null;
private Spawn spawn; private Spawn spawn;
private Jail jail; private Jail jail;
@ -116,6 +117,7 @@ public class Essentials extends JavaPlugin implements IEssentials
confList.add(worth); confList.add(worth);
reload(); reload();
backup = new Backup(this); backup = new Backup(this);
essDep = new EssentialsDependancyChecker(this);
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
for (Plugin plugin : pm.getPlugins()) for (Plugin plugin : pm.getPlugins())
@ -183,7 +185,6 @@ public class Essentials extends JavaPlugin implements IEssentials
if (settings.isNetherEnabled() && getServer().getWorlds().size() < 2) if (settings.isNetherEnabled() && getServer().getWorlds().size() < 2)
{ {
logger.log(Level.WARNING, "Old nether is disabled until multiworld support in bukkit is fixed.");
getServer().createWorld(settings.getNetherName(), World.Environment.NETHER); getServer().createWorld(settings.getNetherName(), World.Environment.NETHER);
} }
@ -757,4 +758,10 @@ public class Essentials extends JavaPlugin implements IEssentials
{ {
return tntListener; return tntListener;
} }
public EssentialsDependancyChecker getDependancyChecker()
{
return essDep;
}
} }

View File

@ -0,0 +1,68 @@
package com.earth2me.essentials;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
public class EssentialsDependancyChecker
{
private static final Logger logger = Logger.getLogger("Minecraft");
final Essentials ess;
public EssentialsDependancyChecker(Essentials ess)
{
this.ess = ess;
}
public void checkProtectDependancies()
{
final String dependancyLocation = "http://mirrors.ibiblio.org/pub/mirrors/maven2/c3p0/c3p0/0.9.1.2/c3p0-0.9.1.2.jar";
File dependancyFile = new File("lib/c3p0-0.9.1.2.jar");
if (!dependancyFile.exists())
{
logger.log(Level.INFO, Util.i18n("dependancyNotFound"));
try
{
URL url = new URL(dependancyLocation);
BufferedInputStream inStream = new BufferedInputStream(url.openStream());
FileOutputStream fos = new FileOutputStream(dependancyFile);
BufferedOutputStream outStream = new BufferedOutputStream(fos, 1024);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) > 0)
{
outStream.write(buffer, 0, len);
}
outStream.close();
fos.close();
inStream.close();
logger.log(Level.INFO, Util.format("dependancyDownloaded", dependancyFile.getName()));
}
catch (MalformedURLException ex)
{
logger.log(Level.SEVERE, Util.i18n("urlMalformed"), ex);
}
catch (FileNotFoundException ex)
{
logger.log(Level.SEVERE, Util.i18n("dependancyException"), ex);
}
catch (IOException ex)
{
logger.log(Level.SEVERE, Util.i18n("dependancyException"), ex);
}
}
}
}

View File

@ -69,4 +69,6 @@ public interface IEssentials
List<String> getBannedIps(); List<String> getBannedIps();
TNTExplodeListener getTNTListener(); TNTExplodeListener getTNTListener();
EssentialsDependancyChecker getDependancyChecker();
} }

View File

@ -305,4 +305,7 @@ timePattern = (?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:
msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2} msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2}
kits = \u00a77Kits: {0} kits = \u00a77Kits: {0}
loadWarpError = Failed to load warp {0} loadWarpError = Failed to load warp {0}
invalidSignLine = Line {0} on sign is invalid. invalidSignLine = Line {0} on sign is invalid.
dependancyNotFound = [Essentials] A required dependancy was not found, downloading now.
dependancyDownloaded = [Essentials] Dependancy {0} downloaded successfully.
dependancyException = [Essentials] An error occured when trying to download a dependacy

View File

@ -307,4 +307,7 @@ timePattern = (?:([0-9]+)\\s*[a\u00e5y][a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\
msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2} msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2}
kits = \u00a77Pakker: {0} kits = \u00a77Pakker: {0}
loadWarpError = Kunne ikke indl\u00e6se warp {0} loadWarpError = Kunne ikke indl\u00e6se warp {0}
invalidSignLine = Linje {0} p\u00e5 skilt er ugyldig. invalidSignLine = Linje {0} p\u00e5 skilt er ugyldig.
dependancyNotFound = [Essentials] A required dependancy was not found, downloading now.
dependancyDownloaded = [Essentials] Dependancy {0} downloaded successfully.
dependancyException = [Essentials] An error occured when trying to download a dependacy

View File

@ -305,4 +305,7 @@ timePattern = (?:([0-9]+)\\s*[yj][a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?
msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2} msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2}
kits = \u00a77Ausr\u00fcstungen: {0} kits = \u00a77Ausr\u00fcstungen: {0}
loadWarpError = Fehler beim Laden von Warp-Punkt {0} loadWarpError = Fehler beim Laden von Warp-Punkt {0}
invalidSignLine = Die Zeile {0} auf dem Schild ist falsch. invalidSignLine = Die Zeile {0} auf dem Schild ist falsch.
dependancyNotFound = [Essentials] A required dependancy was not found, downloading now.
dependancyDownloaded = [Essentials] Dependancy {0} downloaded successfully.
dependancyException = [Essentials] An error occured when trying to download a dependacy

View File

@ -305,4 +305,7 @@ timePattern = (?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:
msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2} msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2}
kits = \u00a77Kits: {0} kits = \u00a77Kits: {0}
loadWarpError = Failed to load warp {0} loadWarpError = Failed to load warp {0}
invalidSignLine = Line {0} on sign is invalid. invalidSignLine = Line {0} on sign is invalid.
dependancyNotFound = [Essentials] A required dependancy was not found, downloading now.
dependancyDownloaded = [Essentials] Dependancy {0} downloaded successfully.
dependancyException = [Essentials] An error occured when trying to download a dependacy

View File

@ -302,4 +302,7 @@ timePattern = (?:([0-9]+)\\s*[ya][a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?
msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2} msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2}
kits = \u00a77Kits:{0} kits = \u00a77Kits:{0}
loadWarpError = Echec du chargement du warp {0} loadWarpError = Echec du chargement du warp {0}
invalidSignLine = Ligne {0} du panneau est invalide. invalidSignLine = Ligne {0} du panneau est invalide.
dependancyNotFound = [Essentials] A required dependancy was not found, downloading now.
dependancyDownloaded = [Essentials] Dependancy {0} downloaded successfully.
dependancyException = [Essentials] An error occured when trying to download a dependacy

View File

@ -306,4 +306,7 @@ timePattern = (?:([0-9]+)\\s*[yj][a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[oa][a-z]*[,\\s]
msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2} msgFormat = \u00a77[{0}\u00a77 -> {1}\u00a77] \u00a7f{2}
kits = \u00a77Kits: {0} kits = \u00a77Kits: {0}
loadWarpError = Fout bij het laden van warp {0} loadWarpError = Fout bij het laden van warp {0}
invalidSignLine = Regel {0} op het bordje is ongeldig. invalidSignLine = Regel {0} op het bordje is ongeldig.
dependancyNotFound = [Essentials] A required dependancy was not found, downloading now.
dependancyDownloaded = [Essentials] Dependancy {0} downloaded successfully.
dependancyException = [Essentials] An error occured when trying to download a dependacy

View File

@ -73,13 +73,4 @@
--> -->
<target name="-post-jar">
<jar jarfile="${dist.dir}/EssentialsProtect.jar">
<zipfileset src="${dist.jar}" excludes="META-INF/*" />
<zipfileset src="../lib/c3p0-0.9.1.2.jar" excludes="META-INF/*" />
<manifest>
<attribute name="Classpath" value="Essentials.jar"/>
</manifest>
</jar>
</target>
</project> </project>

View File

@ -1,87 +1,87 @@
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.run.all.processors=true annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=EssentialsProtect application.title=EssentialsProtect
application.vendor=devhome application.vendor=devhome
build.classes.dir=${build.dir}/classes build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned: # This directory is removed when the project is cleaned:
build.dir=build build.dir=build
build.generated.dir=${build.dir}/generated build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here: # Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport: # Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket #debug.transport=dt_socket
debug.classpath=\ debug.classpath=\
${run.classpath} ${run.classpath}
debug.test.classpath=\ debug.test.classpath=\
${run.test.classpath} ${run.test.classpath}
# This directory is removed when the project is cleaned: # This directory is removed when the project is cleaned:
dist.dir=dist dist.dir=dist
dist.jar=${dist.dir}/original-EssentialsProtect.jar dist.jar=${dist.dir}/EssentialsProtect.jar
dist.javadoc.dir=${dist.dir}/javadoc dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath= endorsed.classpath=
excludes= excludes=
file.reference.c3p0-0.9.1.2.jar=..\\lib\\c3p0-0.9.1.2.jar file.reference.c3p0-0.9.1.2.jar=..\\lib\\c3p0-0.9.1.2.jar
file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar
includes=** includes=**
jar.archive.disabled=${jnlp.enabled} jar.archive.disabled=${jnlp.enabled}
jar.compress=false jar.compress=false
jar.index=${jnlp.enabled} jar.index=${jnlp.enabled}
javac.classpath=\ javac.classpath=\
${reference.Essentials.jar}:\ ${reference.Essentials.jar}:\
${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\ ${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\
${file.reference.c3p0-0.9.1.2.jar} ${file.reference.c3p0-0.9.1.2.jar}
# Space-separated list of extra javac options # Space-separated list of extra javac options
javac.compilerargs= javac.compilerargs=
javac.deprecation=false javac.deprecation=false
javac.processorpath=\ javac.processorpath=\
${javac.classpath} ${javac.classpath}
javac.source=1.5 javac.source=1.5
javac.target=1.5 javac.target=1.5
javac.test.classpath=\ javac.test.classpath=\
${javac.classpath}:\ ${javac.classpath}:\
${build.classes.dir}:\ ${build.classes.dir}:\
${libs.junit.classpath}:\ ${libs.junit.classpath}:\
${libs.junit_4.classpath} ${libs.junit_4.classpath}
javac.test.processorpath=\ javac.test.processorpath=\
${javac.test.classpath} ${javac.test.classpath}
javadoc.additionalparam= javadoc.additionalparam=
javadoc.author=false javadoc.author=false
javadoc.encoding=${source.encoding} javadoc.encoding=${source.encoding}
javadoc.noindex=false javadoc.noindex=false
javadoc.nonavbar=false javadoc.nonavbar=false
javadoc.notree=false javadoc.notree=false
javadoc.private=false javadoc.private=false
javadoc.splitindex=true javadoc.splitindex=true
javadoc.use=true javadoc.use=true
javadoc.version=false javadoc.version=false
javadoc.windowtitle= javadoc.windowtitle=
jnlp.codebase.type=no.codebase jnlp.codebase.type=no.codebase
jnlp.descriptor=application jnlp.descriptor=application
jnlp.enabled=false jnlp.enabled=false
jnlp.mixed.code=defaut jnlp.mixed.code=defaut
jnlp.offline-allowed=false jnlp.offline-allowed=false
jnlp.signed=false jnlp.signed=false
manifest.file=manifest.mf manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform platform.active=default_platform
project.Essentials=../Essentials project.Essentials=../Essentials
reference.Essentials.jar=${project.Essentials}/dist/Essentials.jar reference.Essentials.jar=${project.Essentials}/dist/Essentials.jar
run.classpath=\ run.classpath=\
${javac.classpath}:\ ${javac.classpath}:\
${build.classes.dir} ${build.classes.dir}
# Space-separated list of JVM arguments used when running the project # Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests): # or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs= run.jvmargs=
run.test.classpath=\ run.test.classpath=\
${javac.test.classpath}:\ ${javac.test.classpath}:\
${build.test.classes.dir} ${build.test.classes.dir}
source.encoding=UTF-8 source.encoding=UTF-8
src.dir=src src.dir=src
test.src.dir=test test.src.dir=test

View File

@ -50,14 +50,10 @@ public class EssentialsProtect extends JavaPlugin implements IConf
public void onEnable() public void onEnable()
{ {
ess = Essentials.getStatic();
PluginManager pm = this.getServer().getPluginManager();
Essentials ess = (Essentials)pm.getPlugin("Essentials");
if (!ess.isEnabled())
{
pm.enablePlugin(ess);
}
PluginManager pm = this.getServer().getPluginManager();
ess = Essentials.getStatic();
ess.getDependancyChecker().checkProtectDependancies();
instance = this; instance = this;
reloadConfig(); reloadConfig();
@ -77,7 +73,7 @@ public class EssentialsProtect extends JavaPlugin implements IConf
pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this); pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this);
pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this); pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this);
pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this); pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this);
if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion()))
{ {
logger.log(Level.WARNING, "Version mismatch! Please update all Essentials jars to the same version."); logger.log(Level.WARNING, "Version mismatch! Please update all Essentials jars to the same version.");