From 7b8a9d60d7da4cba5013671920b1064f711b4538 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 2 Mar 2012 21:48:03 +1100 Subject: I honestly have no idea if this works, but on paper it does. Will be great, now to figure out how to test. --- EssentialsProtect/build.xml | 4 +- EssentialsProtect/nbproject/project.properties | 2 - .../essentials/protect/EssentialsConnect.java | 16 ++-- .../essentials/protect/EssentialsProtect.java | 84 +++++---------------- .../essentials/protect/data/IProtectedBlock.java | 2 - .../protect/data/ProtectedBlockJDBC.java | 42 ++++------- .../protect/data/ProtectedBlockMemory.java | 5 -- .../protect/data/ProtectedBlockMySQL.java | 3 +- .../protect/data/ProtectedBlockSQLite.java | 3 +- lib/c3p0-0.9.1.2.jar | Bin 610790 -> 0 bytes 10 files changed, 42 insertions(+), 119 deletions(-) delete mode 100644 lib/c3p0-0.9.1.2.jar diff --git a/EssentialsProtect/build.xml b/EssentialsProtect/build.xml index 1f88786d0..62dc3d935 100644 --- a/EssentialsProtect/build.xml +++ b/EssentialsProtect/build.xml @@ -72,7 +72,7 @@ nbproject/build-impl.xml file. --> - + diff --git a/EssentialsProtect/nbproject/project.properties b/EssentialsProtect/nbproject/project.properties index 77c12c248..af6412bde 100644 --- a/EssentialsProtect/nbproject/project.properties +++ b/EssentialsProtect/nbproject/project.properties @@ -64,14 +64,12 @@ dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= file.reference.bukkit.jar=../lib/bukkit.jar -file.reference.c3p0-0.9.1.2.jar=..\\lib\\c3p0-0.9.1.2.jar includes=** jar.archive.disabled=${jnlp.enabled} jar.compress=true jar.index=${jnlp.enabled} javac.classpath=\ ${reference.Essentials.jar}:\ - ${file.reference.c3p0-0.9.1.2.jar}:\ ${file.reference.bukkit.jar} # Space-separated list of extra javac options javac.compilerargs= diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java index 539ff208b..9f1cc122a 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java @@ -66,10 +66,6 @@ public class EssentialsConnect @Override public void onReload() { - if (protect.getStorage() != null) - { - protect.getStorage().onPluginDeactivation(); - } /* * for (ProtectConfig protectConfig : ProtectConfig.values()) { if (protectConfig.isList()) { @@ -97,7 +93,7 @@ public class EssentialsConnect settings.getData().getDbuser(), settings.getData().getDbpassword())); } - catch (PropertyVetoException ex) + catch (ClassNotFoundException ex) { LOGGER.log(Level.SEVERE, null, ex); } @@ -108,15 +104,15 @@ public class EssentialsConnect { protect.setStorage(new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db")); } - catch (PropertyVetoException ex) + catch (ClassNotFoundException ex) { LOGGER.log(Level.SEVERE, null, ex); } } - /*if (protect.getSettingBool(ProtectConfig.memstore)) - { - protect.setStorage(new ProtectedBlockMemory(protect.getStorage(), protect)); - }*/ + /* + * if (protect.getSettingBool(ProtectConfig.memstore)) { protect.setStorage(new + * ProtectedBlockMemory(protect.getStorage(), protect)); } + */ } finally diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index 72000eeba..5c3e3eab7 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -1,9 +1,7 @@ package com.earth2me.essentials.protect; import com.earth2me.essentials.protect.data.IProtectedBlock; -import java.util.logging.Filter; import java.util.logging.Level; -import java.util.logging.LogRecord; import java.util.logging.Logger; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -14,7 +12,6 @@ import org.bukkit.plugin.java.JavaPlugin; public class EssentialsProtect extends JavaPlugin implements IProtect { private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private static com.mchange.v2.log.MLogger C3P0logger; //private final transient Map settingsBoolean = new EnumMap(ProtectConfig.class); //private final transient Map settingsString = new EnumMap(ProtectConfig.class); //private final transient Map> settingsList = new EnumMap>(ProtectConfig.class); @@ -23,18 +20,6 @@ public class EssentialsProtect extends JavaPlugin implements IProtect private transient ProtectHolder settings = null; @Override - public void onLoad() - { - C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class); - C3P0logger.setFilter(new Filter() - { - public boolean isLoggable(LogRecord lr) - { - return lr.getLevel() != Level.INFO; - } - }); - } - public void onEnable() { final PluginManager pm = this.getServer().getPluginManager(); @@ -71,13 +56,10 @@ public class EssentialsProtect extends JavaPlugin implements IProtect LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now."); } - /*@Override - public boolean checkProtectionItems(final ProtectConfig list, final int id) - { - final List itemList = settingsList.get(list); - return itemList != null && !itemList.isEmpty() && itemList.contains(id); - }*/ - + /* + * @Override public boolean checkProtectionItems(final ProtectConfig list, final int id) { final List + * itemList = settingsList.get(list); return itemList != null && !itemList.isEmpty() && itemList.contains(id); } + */ @Override public IProtectedBlock getStorage() { @@ -94,52 +76,20 @@ public class EssentialsProtect extends JavaPlugin implements IProtect { return ess; } - - /*public Map getSettingsBoolean() - { - return settingsBoolean; - } - - public Map getSettingsString() - { - return settingsString; - } - - public Map> getSettingsList() - { - return settingsList; - } - - @Override - public boolean getSettingBool(final ProtectConfig protectConfig) - { - final Boolean bool = settingsBoolean.get(protectConfig); - return bool == null ? protectConfig.getDefaultValueBoolean() : bool; - } - - @Override - public String getSettingString(final ProtectConfig protectConfig) - { - final String str = settingsString.get(protectConfig); - return str == null ? protectConfig.getDefaultValueString() : str; - }*/ - - public void onDisable() - { - if (storage != null) - { - storage.onPluginDeactivation(); - } - // Sleep for a second to allow the database to close. - try - { - Thread.sleep(1000); - } - catch (InterruptedException ex) - { - } - } + /* + * public Map getSettingsBoolean() { return settingsBoolean; } + * + * public Map getSettingsString() { return settingsString; } + * + * public Map> getSettingsList() { return settingsList; } + * + * @Override public boolean getSettingBool(final ProtectConfig protectConfig) { final Boolean bool = + * settingsBoolean.get(protectConfig); return bool == null ? protectConfig.getDefaultValueBoolean() : bool; } + * + * @Override public String getSettingString(final ProtectConfig protectConfig) { final String str = + * settingsString.get(protectConfig); return str == null ? protectConfig.getDefaultValueString() : str; } + */ public ProtectHolder getSettings() { return settings; diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java index 755baface..d8267429f 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java @@ -19,6 +19,4 @@ public interface IProtectedBlock public List getOwners(Block block); public int unprotectBlock(Block block); - - public void onPluginDeactivation(); } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java index e24a71b80..30ac5ae8e 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java @@ -1,11 +1,6 @@ package com.earth2me.essentials.protect.data; -import com.mchange.v2.c3p0.ComboPooledDataSource; -import java.beans.PropertyVetoException; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -16,7 +11,7 @@ import org.bukkit.block.Block; public abstract class ProtectedBlockJDBC implements IProtectedBlock { protected static final Logger LOGGER = Logger.getLogger("Minecraft"); - protected final transient ComboPooledDataSource cpds; + protected String url; protected abstract PreparedStatement getStatementCreateTable(Connection conn) throws SQLException; @@ -34,22 +29,20 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock protected abstract PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException; - public ProtectedBlockJDBC(String driver, String url) throws PropertyVetoException + public ProtectedBlockJDBC(String driver, String url) throws ClassNotFoundException { this(driver, url, null, null); } - public ProtectedBlockJDBC(String driver, String url, String username, String password) throws PropertyVetoException + public ProtectedBlockJDBC(String driver, String url, String username, String password) throws ClassNotFoundException { - cpds = new ComboPooledDataSource(); - cpds.setDriverClass(driver); - cpds.setJdbcUrl(url); + Class.forName(driver); + this.url = url; if (username != null) { - cpds.setUser(username); - cpds.setPassword(password); + url += "?user=" + username; + url += "&password=" + password; } - cpds.setMaxStatements(20); createAndConvertTable(); } @@ -59,7 +52,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock PreparedStatement ps = null; try { - conn = cpds.getConnection(); + conn = DriverManager.getConnection(url); ps = getStatementCreateTable(conn); ps.execute(); ps.close(); @@ -103,7 +96,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock PreparedStatement ps = null; try { - conn = cpds.getConnection(); + conn = DriverManager.getConnection(url); ps = getStatementDeleteAll(conn); ps.executeUpdate(); } @@ -158,7 +151,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock List blocks = new ArrayList(); try { - conn = cpds.getConnection(); + conn = DriverManager.getConnection(url); ps = getStatementAllBlocks(conn); rs = ps.executeQuery(); while (rs.next()) @@ -227,7 +220,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock PreparedStatement ps = null; try { - conn = cpds.getConnection(); + conn = DriverManager.getConnection(url); ps = getStatementInsert(conn, world, x, y, z, playerName); ps.executeUpdate(); } @@ -269,7 +262,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock ResultSet rs = null; try { - conn = cpds.getConnection(); + conn = DriverManager.getConnection(url); ps = getStatementPlayerCountByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName); rs = ps.executeQuery(); return rs.next() && rs.getInt(1) > 0 && rs.getInt(2) == 0; @@ -325,7 +318,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock List owners = new ArrayList(); try { - conn = cpds.getConnection(); + conn = DriverManager.getConnection(url); ps = getStatementPlayersByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ()); rs = ps.executeQuery(); while (rs.next()) @@ -383,7 +376,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock PreparedStatement ps = null; try { - conn = cpds.getConnection(); + conn = DriverManager.getConnection(url); ps = getStatementDeleteByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ()); return ps.executeUpdate(); } @@ -418,9 +411,4 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } } - - public void onPluginDeactivation() - { - cpds.close(); - } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java index 876c8a575..61e38a848 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java @@ -240,9 +240,4 @@ public class ProtectedBlockMemory implements IProtectedBlock } return id; } - - public void onPluginDeactivation() - { - storage.onPluginDeactivation(); - } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java index 2a0077698..96f399d27 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.protect.data; -import java.beans.PropertyVetoException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -11,7 +10,7 @@ import java.util.logging.Logger; public class ProtectedBlockMySQL extends ProtectedBlockJDBC { - public ProtectedBlockMySQL(String url, String username, String password) throws PropertyVetoException + public ProtectedBlockMySQL(String url, String username, String password) throws ClassNotFoundException { super("com.mysql.jdbc.Driver", url, username, password); } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java index cf256f1ec..84aff3823 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.protect.data; -import java.beans.PropertyVetoException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -8,7 +7,7 @@ import java.sql.SQLException; public class ProtectedBlockSQLite extends ProtectedBlockJDBC { - public ProtectedBlockSQLite(String url) throws PropertyVetoException + public ProtectedBlockSQLite(String url) throws ClassNotFoundException { super("org.sqlite.JDBC", url); } diff --git a/lib/c3p0-0.9.1.2.jar b/lib/c3p0-0.9.1.2.jar deleted file mode 100644 index 0f42d60e3..000000000 Binary files a/lib/c3p0-0.9.1.2.jar and /dev/null differ -- cgit v1.2.3