diff options
author | md_5 <md_5@bigpond.com> | 2012-06-27 20:23:06 +1000 |
---|---|---|
committer | md_5 <md_5@bigpond.com> | 2012-06-27 20:23:06 +1000 |
commit | 4561a7f0106adb7bd62e2d42114cb80a3a30b570 (patch) | |
tree | e7e57e5ab8832bb1fbd0fafeacc9bcd9ee1fc48c /EssentialsProtect/src/com/earth2me/essentials/protect/data | |
parent | 7bef2d3817634a4c396e61930460126dde3606ba (diff) | |
download | Essentials-4561a7f0106adb7bd62e2d42114cb80a3a30b570.tar Essentials-4561a7f0106adb7bd62e2d42114cb80a3a30b570.tar.gz Essentials-4561a7f0106adb7bd62e2d42114cb80a3a30b570.tar.lz Essentials-4561a7f0106adb7bd62e2d42114cb80a3a30b570.tar.xz Essentials-4561a7f0106adb7bd62e2d42114cb80a3a30b570.zip |
Fairly expansive cleanup of ess protect.
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials/protect/data')
4 files changed, 75 insertions, 49 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java index e24a71b80..53d5de945 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java @@ -34,12 +34,12 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock protected abstract PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException; - public ProtectedBlockJDBC(String driver, String url) throws PropertyVetoException + public ProtectedBlockJDBC(final String driver, final String url) throws PropertyVetoException { this(driver, url, null, null); } - public ProtectedBlockJDBC(String driver, String url, String username, String password) throws PropertyVetoException + public ProtectedBlockJDBC(final String driver, final String url, final String username, final String password) throws PropertyVetoException { cpds = new ComboPooledDataSource(); cpds.setDriverClass(driver); @@ -97,6 +97,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } + @Override public void clearProtections() { Connection conn = null; @@ -138,7 +139,8 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } - public void importProtections(List<OwnedBlock> blocks) + @Override + public void importProtections(final List<OwnedBlock> blocks) { for (OwnedBlock ownedBlock : blocks) { @@ -150,6 +152,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } + @Override public List<OwnedBlock> exportProtections() { Connection conn = null; @@ -216,12 +219,13 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } - public void protectBlock(Block block, String playerName) + @Override + public void protectBlock(final Block block, final String playerName) { protectBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName); } - private void protectBlock(String world, int x, int y, int z, String playerName) + private void protectBlock(final String world, final int x, final int y, final int z, final String playerName) { Connection conn = null; PreparedStatement ps = null; @@ -262,7 +266,8 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } - public boolean isProtected(Block block, String playerName) + @Override + public boolean isProtected(final Block block, final String playerName) { Connection conn = null; PreparedStatement ps = null; @@ -317,7 +322,8 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } - public List<String> getOwners(Block block) + @Override + public List<String> getOwners(final Block block) { Connection conn = null; PreparedStatement ps = null; @@ -377,7 +383,8 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } - public int unprotectBlock(Block block) + @Override + public int unprotectBlock(final Block block) { Connection conn = null; PreparedStatement ps = null; @@ -419,6 +426,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock } } + @Override 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..7b38d54eb 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java @@ -1,13 +1,13 @@ package com.earth2me.essentials.protect.data; -import java.util.Map.Entry; import java.util.*; +import java.util.Map.Entry; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.plugin.Plugin; -public class ProtectedBlockMemory implements IProtectedBlock +public final class ProtectedBlockMemory implements IProtectedBlock { private final transient List<String> worlds = new ArrayList<String>(); private final transient List<String> playerNames = new ArrayList<String>(); @@ -123,12 +123,14 @@ public class ProtectedBlockMemory implements IProtectedBlock importProtections(storage.exportProtections()); } + @Override public void clearProtections() { blocks.clear(); } - public final void importProtections(final List<OwnedBlock> blocks) + @Override + public void importProtections(final List<OwnedBlock> blocks) { for (OwnedBlock ownedBlock : blocks) { @@ -141,6 +143,7 @@ public class ProtectedBlockMemory implements IProtectedBlock } } + @Override public List<OwnedBlock> exportProtections() { final List<OwnedBlock> blockList = new ArrayList<OwnedBlock>(blocks.size()); @@ -160,12 +163,14 @@ public class ProtectedBlockMemory implements IProtectedBlock return blockList; } + @Override public void protectBlock(final Block block, final String playerName) { final ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld())); protectBlock(pl, playerName); plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() { + @Override public void run() { storage.protectBlock(block, playerName); @@ -173,9 +178,9 @@ public class ProtectedBlockMemory implements IProtectedBlock }); } - private final void protectBlock(ProtectedLocation pl, String playerName) + private void protectBlock(final ProtectedLocation pl, final String playerName) { - int playerId = getPlayerId(playerName); + final int playerId = getPlayerId(playerName); ProtectedBy pb = blocks.get(pl); if (pb == null) { @@ -185,27 +190,31 @@ public class ProtectedBlockMemory implements IProtectedBlock pb.add(playerId); } - public boolean isProtected(Block block, String playerName) + @Override + public boolean isProtected(final Block block, final String playerName) { - int playerId = getPlayerId(playerName); - ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld())); - ProtectedBy pb = blocks.get(pl); + final int playerId = getPlayerId(playerName); + final ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld())); + final ProtectedBy pb = blocks.get(pl); return !pb.contains(playerId); } - public List<String> getOwners(Block block) + @Override + public List<String> getOwners(final Block block) { ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld())); ProtectedBy pb = blocks.get(pl); return pb.getPlayers(playerNames); } + @Override public int unprotectBlock(final Block block) { - ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld())); - ProtectedBy pb = blocks.remove(pl); + final ProtectedLocation pl = new ProtectedLocation(block, getWorldId(block.getWorld())); + final ProtectedBy pb = blocks.remove(pl); plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() { + @Override public void run() { storage.unprotectBlock(block); @@ -214,7 +223,7 @@ public class ProtectedBlockMemory implements IProtectedBlock return pb.size(); } - private int getPlayerId(String playername) + private int getPlayerId(final String playername) { int id = playerNames.indexOf(playername); if (id < 0) @@ -225,12 +234,12 @@ public class ProtectedBlockMemory implements IProtectedBlock return id; } - private int getWorldId(World world) + private int getWorldId(final World world) { return getWorldId(world.getName()); } - private int getWorldId(String name) + private int getWorldId(final String name) { int id = worlds.indexOf(name); if (id < 0) @@ -241,6 +250,7 @@ public class ProtectedBlockMemory implements IProtectedBlock return id; } + @Override 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..39070c30c 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java @@ -11,7 +11,7 @@ import java.util.logging.Logger; public class ProtectedBlockMySQL extends ProtectedBlockJDBC { - public ProtectedBlockMySQL(String url, String username, String password) throws PropertyVetoException + public ProtectedBlockMySQL(final String url, final String username, final String password) throws PropertyVetoException { super("com.mysql.jdbc.Driver", url, username, password); } @@ -24,7 +24,7 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC + ") ENGINE=MyISAM DEFAULT CHARSET=utf8"; @Override - protected PreparedStatement getStatementCreateTable(Connection conn) throws SQLException + protected PreparedStatement getStatementCreateTable(final Connection conn) throws SQLException { return conn.prepareStatement(QueryCreateTable); } @@ -40,7 +40,7 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC + "DROP PRIMARY KEY ;"; @Override - protected PreparedStatement getStatementUpdateFrom2_0Table(Connection conn) throws SQLException + protected PreparedStatement getStatementUpdateFrom2_0Table(final Connection conn) throws SQLException { PreparedStatement testPS = null; ResultSet testRS = null; @@ -86,7 +86,7 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC private static final String QueryDeleteAll = "DELETE FROM EssentialsProtect;"; @Override - protected PreparedStatement getStatementDeleteAll(Connection conn) throws SQLException + protected PreparedStatement getStatementDeleteAll(final Connection conn) throws SQLException { return conn.prepareStatement(QueryDeleteAll); } @@ -94,9 +94,10 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC "INSERT INTO EssentialsProtect (worldName, x, y, z, playerName) VALUES (?, ?, ?, ?, ?);"; @Override - protected PreparedStatement getStatementInsert(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException + protected PreparedStatement getStatementInsert(final Connection conn, final String world, final int x, final int y, final int z, + final String playerName) throws SQLException { - PreparedStatement ps = conn.prepareStatement(QueryInsert); + final PreparedStatement ps = conn.prepareStatement(QueryInsert); ps.setString(1, world); ps.setInt(2, x); ps.setInt(3, y); @@ -109,9 +110,10 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC + "WHERE worldName = ? AND x = ? AND y = ? AND z = ? GROUP BY x;"; @Override - protected PreparedStatement getStatementPlayerCountByLocation(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException + protected PreparedStatement getStatementPlayerCountByLocation(final Connection conn, final String world, final int x, final int y, final int z, + final String playerName) throws SQLException { - PreparedStatement ps = conn.prepareStatement(QueryCountByPlayer); + final PreparedStatement ps = conn.prepareStatement(QueryCountByPlayer); ps.setString(1, playerName); ps.setString(2, world); ps.setInt(3, x); @@ -123,9 +125,10 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC "SELECT playerName FROM EssentialsProtect WHERE worldname = ? AND x = ? AND y = ? AND z = ?;"; @Override - protected PreparedStatement getStatementPlayersByLocation(Connection conn, String world, int x, int y, int z) throws SQLException + protected PreparedStatement getStatementPlayersByLocation(final Connection conn, final String world, + final int x, final int y, final int z) throws SQLException { - PreparedStatement ps = conn.prepareStatement(QueryPlayersByLocation); + final PreparedStatement ps = conn.prepareStatement(QueryPlayersByLocation); ps.setString(1, world); ps.setInt(2, x); ps.setInt(3, y); @@ -136,9 +139,10 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC "DELETE FROM EssentialsProtect WHERE worldName = ? AND x = ? AND y = ? AND z = ?;"; @Override - protected PreparedStatement getStatementDeleteByLocation(Connection conn, String world, int x, int y, int z) throws SQLException + protected PreparedStatement getStatementDeleteByLocation(final Connection conn, final String world, + final int x, final int y, final int z) throws SQLException { - PreparedStatement ps = conn.prepareStatement(QueryDeleteByLocation); + final PreparedStatement ps = conn.prepareStatement(QueryDeleteByLocation); ps.setString(1, world); ps.setInt(2, x); ps.setInt(3, y); @@ -149,7 +153,7 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC "SELECT worldName, x, y, z, playerName FROM EssentialsProtect;"; @Override - protected PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException + protected PreparedStatement getStatementAllBlocks(final Connection conn) throws SQLException { return conn.prepareStatement(QueryAllBlocks); } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java index cf256f1ec..464c620fe 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java @@ -8,7 +8,7 @@ import java.sql.SQLException; public class ProtectedBlockSQLite extends ProtectedBlockJDBC { - public ProtectedBlockSQLite(String url) throws PropertyVetoException + public ProtectedBlockSQLite(final String url) throws PropertyVetoException { super("org.sqlite.JDBC", url); } @@ -18,7 +18,7 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC + "x NUMERIC, y NUMERIC, z NUMERIC)"; @Override - protected PreparedStatement getStatementCreateTable(Connection conn) throws SQLException + protected PreparedStatement getStatementCreateTable(final Connection conn) throws SQLException { return conn.prepareStatement(QueryCreateTable); } @@ -27,14 +27,14 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC + "worldName, x, z, y)"; @Override - protected PreparedStatement getStatementUpdateFrom2_0Table(Connection conn) throws SQLException + protected PreparedStatement getStatementUpdateFrom2_0Table(final Connection conn) throws SQLException { return conn.prepareStatement(QueryUpdateFrom2_0Table); } private static final String QueryDeleteAll = "DELETE FROM EssentialsProtect;"; @Override - protected PreparedStatement getStatementDeleteAll(Connection conn) throws SQLException + protected PreparedStatement getStatementDeleteAll(final Connection conn) throws SQLException { return conn.prepareStatement(QueryDeleteAll); } @@ -42,9 +42,10 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC "INSERT INTO EssentialsProtect (worldName, x, y, z, playerName) VALUES (?, ?, ?, ?, ?);"; @Override - protected PreparedStatement getStatementInsert(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException + protected PreparedStatement getStatementInsert(final Connection conn, final String world, + final int x, final int y, final int z, final String playerName) throws SQLException { - PreparedStatement ps = conn.prepareStatement(QueryInsert); + final PreparedStatement ps = conn.prepareStatement(QueryInsert); ps.setString(1, world); ps.setInt(2, x); ps.setInt(3, y); @@ -57,9 +58,10 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC + "WHERE worldName = ? AND x = ? AND y = ? AND z = ? GROUP BY x;"; @Override - protected PreparedStatement getStatementPlayerCountByLocation(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException + protected PreparedStatement getStatementPlayerCountByLocation(final Connection conn, final String world, + final int x, final int y, final int z, final String playerName) throws SQLException { - PreparedStatement ps = conn.prepareStatement(QueryPlayerCountByLocation); + final PreparedStatement ps = conn.prepareStatement(QueryPlayerCountByLocation); ps.setString(1, playerName); ps.setString(2, world); ps.setInt(3, x); @@ -71,9 +73,10 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC "SELECT playerName FROM EssentialsProtect WHERE worldname = ? AND x = ? AND y = ? AND z = ?;"; @Override - protected PreparedStatement getStatementPlayersByLocation(Connection conn, String world, int x, int y, int z) throws SQLException + protected PreparedStatement getStatementPlayersByLocation(final Connection conn, final String world, + final int x, final int y, final int z) throws SQLException { - PreparedStatement ps = conn.prepareStatement(QueryPlayersByLocation); + final PreparedStatement ps = conn.prepareStatement(QueryPlayersByLocation); ps.setString(1, world); ps.setInt(2, x); ps.setInt(3, y); @@ -84,9 +87,10 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC "DELETE FROM EssentialsProtect WHERE worldName = ? AND x = ? AND y = ? AND z = ?;"; @Override - protected PreparedStatement getStatementDeleteByLocation(Connection conn, String world, int x, int y, int z) throws SQLException + protected PreparedStatement getStatementDeleteByLocation(final Connection conn, final String world, + final int x, final int y, final int z) throws SQLException { - PreparedStatement ps = conn.prepareStatement(QueryDeleteByLocation); + final PreparedStatement ps = conn.prepareStatement(QueryDeleteByLocation); ps.setString(1, world); ps.setInt(2, x); ps.setInt(3, y); @@ -97,7 +101,7 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC "SELECT worldName, x, y, z, playerName FROM EssentialsProtect;"; @Override - protected PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException + protected PreparedStatement getStatementAllBlocks(final Connection conn) throws SQLException { return conn.prepareStatement(QueryAllBlocks); } |