summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com/earth2me/essentials
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java12
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java23
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java112
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java21
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java4
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java11
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/data/OwnedBlock.java4
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java9
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java94
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java54
10 files changed, 161 insertions, 183 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
index 98daf26cb..897112cb6 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
@@ -1,9 +1,9 @@
package com.earth2me.essentials.protect;
+import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IConf;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
-import com.earth2me.essentials.Util;
import com.earth2me.essentials.protect.data.IProtectedBlock;
import com.earth2me.essentials.protect.data.ProtectedBlockMemory;
import com.earth2me.essentials.protect.data.ProtectedBlockMySQL;
@@ -81,9 +81,9 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
ess.addReloadListener(this);
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion()))
{
- LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
+ LOGGER.log(Level.WARNING, _("versionMismatchAll"));
}
- LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
+ LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
}
@Override
@@ -97,9 +97,9 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
public void alert(final User user, final String item, final String type)
{
final Location loc = user.getLocation();
- final String warnMessage = Util.format("alertFormat", user.getName(), type, item,
- loc.getWorld().getName() + "," + loc.getBlockX() + ","
- + loc.getBlockY() + "," + loc.getBlockZ());
+ final String warnMessage = _("alertFormat", user.getName(), type, item,
+ loc.getWorld().getName() + "," + loc.getBlockX() + ","
+ + loc.getBlockY() + "," + loc.getBlockZ());
LOGGER.log(Level.WARNING, warnMessage);
for (Player p : this.getServer().getOnlinePlayers())
{
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
index 8717825b3..a14925ccd 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
@@ -1,22 +1,15 @@
package com.earth2me.essentials.protect;
+import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
-import com.earth2me.essentials.Util;
import com.earth2me.essentials.protect.data.IProtectedBlock;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
-import org.bukkit.event.block.BlockBreakEvent;
-import org.bukkit.event.block.BlockBurnEvent;
-import org.bukkit.event.block.BlockFromToEvent;
-import org.bukkit.event.block.BlockIgniteEvent;
-import org.bukkit.event.block.BlockListener;
-import org.bukkit.event.block.BlockPistonExtendEvent;
-import org.bukkit.event.block.BlockPistonRetractEvent;
-import org.bukkit.event.block.BlockPlaceEvent;
+import org.bukkit.event.block.*;
public class EssentialsProtectBlockListener extends BlockListener
@@ -57,7 +50,7 @@ public class EssentialsProtectBlockListener extends BlockListener
if (prot.checkProtectionItems(ProtectConfig.alert_on_placement, id))
{
- prot.alert(user, blockPlaced.getType().toString(), Util.i18n("alertPlaced"));
+ prot.alert(user, blockPlaced.getType().toString(), _("alertPlaced"));
}
final Block below = blockPlaced.getRelative(BlockFace.DOWN);
@@ -75,7 +68,8 @@ public class EssentialsProtectBlockListener extends BlockListener
&& user.isAuthorized("essentials.protect"))
{
protect.add(blockPlaced);
- if (prot.getSettingBool(ProtectConfig.protect_below_rails))
+ if (prot.getSettingBool(ProtectConfig.protect_below_rails)
+ && !prot.getStorage().isProtected(blockPlaced.getRelative(BlockFace.DOWN), user.getName()))
{
protect.add(blockPlaced.getRelative(BlockFace.DOWN));
}
@@ -85,7 +79,10 @@ public class EssentialsProtectBlockListener extends BlockListener
&& user.isAuthorized("essentials.protect"))
{
protect.add(blockPlaced);
- if (prot.getSettingBool(ProtectConfig.protect_against_signs))
+ if (prot.getSettingBool(ProtectConfig.protect_against_signs)
+ && event.getBlockAgainst().getType() != Material.SIGN_POST
+ && event.getBlockAgainst().getType() != Material.WALL_SIGN
+ && !prot.getStorage().isProtected(event.getBlockAgainst(), user.getName()))
{
protect.add(event.getBlockAgainst());
}
@@ -251,7 +248,7 @@ public class EssentialsProtectBlockListener extends BlockListener
if (prot.checkProtectionItems(ProtectConfig.alert_on_break, typeId))
{
- prot.alert(user, type.toString(), Util.i18n("alertBroke"));
+ prot.alert(user, type.toString(), _("alertBroke"));
}
final IProtectedBlock storage = prot.getStorage();
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
index c0e568578..2c4d1dbab 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
@@ -2,49 +2,28 @@ package com.earth2me.essentials.protect;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import net.minecraft.server.ChunkPosition;
-import net.minecraft.server.Packet60Explosion;
-import org.bukkit.Location;
+import com.earth2me.essentials.craftbukkit.FakeExplosion;
+import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
-import org.bukkit.craftbukkit.CraftServer;
-import org.bukkit.craftbukkit.CraftWorld;
-import org.bukkit.entity.Creeper;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Fireball;
-import org.bukkit.entity.LivingEntity;
-import org.bukkit.entity.Player;
-import org.bukkit.entity.Projectile;
-import org.bukkit.entity.TNTPrimed;
-import org.bukkit.event.entity.CreatureSpawnEvent;
-import org.bukkit.event.entity.EndermanPickupEvent;
-import org.bukkit.event.entity.EntityDamageByBlockEvent;
-import org.bukkit.event.entity.EntityDamageByEntityEvent;
-import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
-import org.bukkit.event.entity.EntityExplodeEvent;
-import org.bukkit.event.entity.EntityListener;
-import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
-import org.bukkit.event.entity.ExplosionPrimeEvent;
+import org.bukkit.event.entity.*;
public class EssentialsProtectEntityListener extends EntityListener
{
private final transient IProtect prot;
private final transient IEssentials ess;
-
+
public EssentialsProtectEntityListener(final IProtect prot)
{
this.prot = prot;
this.ess = prot.getEssentials();
}
-
+
@Override
public void onEntityDamage(final EntityDamageEvent event)
{
@@ -57,7 +36,7 @@ public class EssentialsProtectEntityListener extends EntityListener
if (event instanceof EntityDamageByBlockEvent)
{
final DamageCause cause = event.getCause();
-
+
if (prot.getSettingBool(ProtectConfig.disable_contactdmg)
&& cause == DamageCause.CONTACT
&& !(target instanceof Player
@@ -86,7 +65,7 @@ public class EssentialsProtectEntityListener extends EntityListener
return;
}
}
-
+
if (event instanceof EntityDamageByEntityEvent)
{
final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
@@ -111,7 +90,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
return;
}
-
+
if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)
&& !(target instanceof Player
&& user.isAuthorized("essentials.protect.damage.creeper")
@@ -120,8 +99,9 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
return;
}
-
- if (eAttack instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
+
+ if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
+ && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
&& !(target instanceof Player
&& user.isAuthorized("essentials.protect.damage.fireball")
&& !user.isAuthorized("essentials.protect.damage.disable")))
@@ -129,7 +109,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
return;
}
-
+
if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
&& !(target instanceof Player
&& user.isAuthorized("essentials.protect.damage.tnt")
@@ -138,7 +118,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
return;
}
-
+
if (edEvent.getDamager() instanceof Projectile
&& target instanceof Player
&& ((prot.getSettingBool(ProtectConfig.disable_projectiles)
@@ -153,7 +133,7 @@ public class EssentialsProtectEntityListener extends EntityListener
return;
}
}
-
+
final DamageCause cause = event.getCause();
if (target instanceof Player)
{
@@ -165,7 +145,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
return;
}
-
+
if (cause == DamageCause.SUFFOCATION
&& prot.getSettingBool(ProtectConfig.disable_suffocate)
&& !(user.isAuthorized("essentials.protect.damage.suffocation")
@@ -201,7 +181,7 @@ public class EssentialsProtectEntityListener extends EntityListener
}
}
}
-
+
@Override
public void onEntityExplode(final EntityExplodeEvent event)
{
@@ -216,40 +196,7 @@ public class EssentialsProtectEntityListener extends EntityListener
|| prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg)
|| (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight)))
{
- try
- {
- final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size());
- final Player[] players = ess.getServer().getOnlinePlayers();
- final Set<ChunkPosition> blocksUnderPlayers = new HashSet<ChunkPosition>(players.length);
- final Location loc = event.getLocation();
- for (Player player : players)
- {
- if (player.getWorld().equals(loc.getWorld()))
- {
- blocksUnderPlayers.add(
- new ChunkPosition(
- player.getLocation().getBlockX(),
- player.getLocation().getBlockY() - 1,
- player.getLocation().getBlockZ()));
- }
- }
- ChunkPosition cp;
- for (Block block : event.blockList())
- {
- cp = new ChunkPosition(block.getX(), block.getY(), block.getZ());
- if (!blocksUnderPlayers.contains(cp))
- {
- set.add(cp);
- }
- }
-
- ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0D, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension,
- new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set));
- }
- catch (Throwable ex)
- {
- Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
- }
+ FakeExplosion.createExplosion(event, ess.getServer(), ess.getServer().getOnlinePlayers());
event.setCancelled(true);
return;
}
@@ -259,7 +206,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
return;
}
- else if (event.getEntity() instanceof Fireball
+ else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& prot.getSettingBool(ProtectConfig.prevent_fireball_explosion))
{
event.setCancelled(true);
@@ -295,7 +242,7 @@ public class EssentialsProtectEntityListener extends EntityListener
}
}
}
-
+
@Override
public void onCreatureSpawn(final CreatureSpawnEvent event)
{
@@ -307,7 +254,12 @@ public class EssentialsProtectEntityListener extends EntityListener
{
return;
}
- final String creatureName = event.getCreatureType().toString().toLowerCase();
+ final CreatureType creature = event.getCreatureType();
+ if (creature == null)
+ {
+ return;
+ }
+ final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH);
if (creatureName == null || creatureName.isEmpty())
{
return;
@@ -317,7 +269,7 @@ public class EssentialsProtectEntityListener extends EntityListener
event.setCancelled(true);
}
}
-
+
@Override
public void onEntityTarget(final EntityTargetEvent event)
{
@@ -343,11 +295,11 @@ public class EssentialsProtectEntityListener extends EntityListener
return;
}
}
-
+
@Override
public void onExplosionPrime(ExplosionPrimeEvent event)
{
- if (event.getEntity() instanceof Fireball
+ if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& prot.getSettingBool(ProtectConfig.prevent_fireball_fire))
{
event.setFire(false);
@@ -357,10 +309,12 @@ public class EssentialsProtectEntityListener extends EntityListener
@Override
public void onEndermanPickup(EndermanPickupEvent event)
{
- if (event.isCancelled()) {
+ if (event.isCancelled())
+ {
return;
}
- if (prot.getSettingBool(ProtectConfig.prevent_enderman_pickup)) {
+ if (prot.getSettingBool(ProtectConfig.prevent_enderman_pickup))
+ {
event.setCancelled(true);
return;
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java
index 7543a5244..98daecb97 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java
@@ -1,14 +1,14 @@
package com.earth2me.essentials.protect;
+import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+import org.bukkit.Material;
import org.bukkit.block.Block;
+import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.inventory.ItemStack;
-import com.earth2me.essentials.User;
-import com.earth2me.essentials.Util;
-import org.bukkit.Material;
-import org.bukkit.event.block.Action;
public class EssentialsProtectPlayerListener extends PlayerListener
@@ -25,10 +25,7 @@ public class EssentialsProtectPlayerListener extends PlayerListener
@Override
public void onPlayerInteract(final PlayerInteractEvent event)
{
- if (event.isCancelled())
- {
- return;
- }
+ // Do not return if cancelled, because the interact event has 2 cancelled states.
final User user = ess.getUser(event.getPlayer());
if (event.hasItem()
@@ -38,7 +35,7 @@ public class EssentialsProtectPlayerListener extends PlayerListener
{
if (ess.getSettings().warnOnBuildDisallow())
{
- user.sendMessage(Util.i18n("buildAlert"));
+ user.sendMessage(_("buildAlert"));
}
event.setCancelled(true);
return;
@@ -48,7 +45,7 @@ public class EssentialsProtectPlayerListener extends PlayerListener
{
if (ess.getSettings().warnOnBuildDisallow())
{
- user.sendMessage(Util.i18n("buildAlert"));
+ user.sendMessage(_("buildAlert"));
}
event.setCancelled(true);
return;
@@ -80,13 +77,13 @@ public class EssentialsProtectPlayerListener extends PlayerListener
final String ownerNames = stringBuilder.toString();
if (ownerNames != null && !ownerNames.isEmpty())
{
- user.sendMessage(Util.format("protectionOwner", ownerNames));
+ user.sendMessage(_("protectionOwner", ownerNames));
}
}
if (item != null
&& prot.checkProtectionItems(ProtectConfig.alert_on_use, item.getTypeId()))
{
- prot.alert(user, item.getType().toString(), Util.i18n("alertUsed"));
+ prot.alert(user, item.getType().toString(), _("alertUsed"));
}
}
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java
index 5d93fe0ea..369e988ae 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java
@@ -62,7 +62,7 @@ public enum ProtectConfig
{
this(configName, null, false, true, false);
}
-
+
private ProtectConfig(final String configName, final String defValueString)
{
this(configName, defValueString, false, false, true);
@@ -110,7 +110,7 @@ public enum ProtectConfig
{
return isString;
}
-
+
public boolean isList()
{
return isList;
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java
index 271f1c464..755baface 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/IProtectedBlock.java
@@ -3,13 +3,22 @@ package com.earth2me.essentials.protect.data;
import java.util.List;
import org.bukkit.block.Block;
-public interface IProtectedBlock {
+
+public interface IProtectedBlock
+{
public void clearProtections();
+
public void importProtections(List<OwnedBlock> blocks);
+
public List<OwnedBlock> exportProtections();
+
public void protectBlock(Block block, String playerName);
+
public boolean isProtected(Block block, String playerName);
+
public List<String> getOwners(Block block);
+
public int unprotectBlock(Block block);
+
public void onPluginDeactivation();
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/OwnedBlock.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/OwnedBlock.java
index dea124b58..dc28feae8 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/OwnedBlock.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/OwnedBlock.java
@@ -1,6 +1,8 @@
package com.earth2me.essentials.protect.data;
-public class OwnedBlock {
+
+public class OwnedBlock
+{
final int x;
final int y;
final int z;
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java
index 1348b6bc8..876c8a575 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMemory.java
@@ -1,12 +1,7 @@
package com.earth2me.essentials.protect.data;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
+import java.util.*;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.plugin.Plugin;
@@ -249,5 +244,5 @@ public class ProtectedBlockMemory implements IProtectedBlock
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 8e50ce248..2a0077698 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockMySQL.java
@@ -8,50 +8,59 @@ import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
-public class ProtectedBlockMySQL extends ProtectedBlockJDBC {
- public ProtectedBlockMySQL(String url, String username, String password) throws PropertyVetoException {
+public class ProtectedBlockMySQL extends ProtectedBlockJDBC
+{
+ public ProtectedBlockMySQL(String url, String username, String password) throws PropertyVetoException
+ {
super("com.mysql.jdbc.Driver", url, username, password);
}
-
private static final String QueryCreateTable =
- "CREATE TABLE IF NOT EXISTS `EssentialsProtect` ("
- + "`worldName` varchar(60) NOT NULL,"
- + "`x` int(11) NOT NULL, `y` int(11) NOT NULL, `z` int(11) NOT NULL,"
- + "`playerName` varchar(150) DEFAULT NULL,"
- + "KEY `pos` (`worldName`,`x`,`z`,`y`)"
- + ") ENGINE=MyISAM DEFAULT CHARSET=utf8";
+ "CREATE TABLE IF NOT EXISTS `EssentialsProtect` ("
+ + "`worldName` varchar(60) NOT NULL,"
+ + "`x` int(11) NOT NULL, `y` int(11) NOT NULL, `z` int(11) NOT NULL,"
+ + "`playerName` varchar(150) DEFAULT NULL,"
+ + "KEY `pos` (`worldName`,`x`,`z`,`y`)"
+ + ") ENGINE=MyISAM DEFAULT CHARSET=utf8";
@Override
- protected PreparedStatement getStatementCreateTable(Connection conn) throws SQLException {
+ protected PreparedStatement getStatementCreateTable(Connection conn) throws SQLException
+ {
return conn.prepareStatement(QueryCreateTable);
}
-
private static final String QueryUpdateFrom2_0TableCheck =
- "SHOW COLUMNS FROM `EssentialsProtect` LIKE 'id';";
+ "SHOW COLUMNS FROM `EssentialsProtect` LIKE 'id';";
private static final String QueryUpdateFrom2_0Table =
- "ALTER TABLE `EssentialsProtect` "
- + "CHARACTER SET = utf8, ENGINE = MyISAM,"
- + "DROP COLUMN `id`,"
- + "CHANGE COLUMN `playerName` `playerName` VARCHAR(150) NULL AFTER `z`,"
- + "CHANGE COLUMN `worldName` `worldName` VARCHAR(60) NOT NULL,"
- + "ADD INDEX `position` (`worldName` ASC, `x` ASC, `z` ASC, `y` ASC),"
- + "DROP PRIMARY KEY ;";
+ "ALTER TABLE `EssentialsProtect` "
+ + "CHARACTER SET = utf8, ENGINE = MyISAM,"
+ + "DROP COLUMN `id`,"
+ + "CHANGE COLUMN `playerName` `playerName` VARCHAR(150) NULL AFTER `z`,"
+ + "CHANGE COLUMN `worldName` `worldName` VARCHAR(60) NOT NULL,"
+ + "ADD INDEX `position` (`worldName` ASC, `x` ASC, `z` ASC, `y` ASC),"
+ + "DROP PRIMARY KEY ;";
@Override
- protected PreparedStatement getStatementUpdateFrom2_0Table(Connection conn) throws SQLException {
+ protected PreparedStatement getStatementUpdateFrom2_0Table(Connection conn) throws SQLException
+ {
PreparedStatement testPS = null;
ResultSet testRS = null;
- try {
+ try
+ {
testPS = conn.prepareStatement(QueryUpdateFrom2_0TableCheck);
testRS = testPS.executeQuery();
- if (testRS.first()) {
+ if (testRS.first())
+ {
return conn.prepareStatement(QueryUpdateFrom2_0Table);
- } else {
+ }
+ else
+ {
return conn.prepareStatement("SELECT 1;");
}
- } finally {
- if (testRS != null) {
+ }
+ finally
+ {
+ if (testRS != null)
+ {
try
{
testRS.close();
@@ -61,7 +70,8 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC {
Logger.getLogger(ProtectedBlockMySQL.class.getName()).log(Level.SEVERE, null, ex);
}
}
- if (testPS != null) {
+ if (testPS != null)
+ {
try
{
testPS.close();
@@ -74,16 +84,18 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC {
}
}
private static final String QueryDeleteAll = "DELETE FROM EssentialsProtect;";
-
+
@Override
- protected PreparedStatement getStatementDeleteAll(Connection conn) throws SQLException {
+ protected PreparedStatement getStatementDeleteAll(Connection conn) throws SQLException
+ {
return conn.prepareStatement(QueryDeleteAll);
}
private static final String QueryInsert =
- "INSERT INTO EssentialsProtect (worldName, x, y, z, playerName) VALUES (?, ?, ?, ?, ?);";
+ "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(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException
+ {
PreparedStatement ps = conn.prepareStatement(QueryInsert);
ps.setString(1, world);
ps.setInt(2, x);
@@ -93,11 +105,12 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC {
return ps;
}
private static final String QueryCountByPlayer =
- "SELECT COUNT(playerName), SUM(playerName = ?) FROM EssentialsProtect "
- + "WHERE worldName = ? AND x = ? AND y = ? AND z = ? GROUP BY x;";
+ "SELECT COUNT(playerName), SUM(playerName = ?) FROM EssentialsProtect "
+ + "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(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException
+ {
PreparedStatement ps = conn.prepareStatement(QueryCountByPlayer);
ps.setString(1, playerName);
ps.setString(2, world);
@@ -107,10 +120,11 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC {
return ps;
}
private static final String QueryPlayersByLocation =
- "SELECT playerName FROM EssentialsProtect WHERE worldname = ? AND x = ? AND y = ? AND z = ?;";
+ "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(Connection conn, String world, int x, int y, int z) throws SQLException
+ {
PreparedStatement ps = conn.prepareStatement(QueryPlayersByLocation);
ps.setString(1, world);
ps.setInt(2, x);
@@ -119,10 +133,11 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC {
return ps;
}
private static final String QueryDeleteByLocation =
- "DELETE FROM EssentialsProtect WHERE worldName = ? AND x = ? AND y = ? AND z = ?;";
+ "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(Connection conn, String world, int x, int y, int z) throws SQLException
+ {
PreparedStatement ps = conn.prepareStatement(QueryDeleteByLocation);
ps.setString(1, world);
ps.setInt(2, x);
@@ -131,10 +146,11 @@ public class ProtectedBlockMySQL extends ProtectedBlockJDBC {
return ps;
}
private static final String QueryAllBlocks =
- "SELECT worldName, x, y, z, playerName FROM EssentialsProtect;";
+ "SELECT worldName, x, y, z, playerName FROM EssentialsProtect;";
@Override
- protected PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException {
+ protected PreparedStatement getStatementAllBlocks(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 444c657eb..cf256f1ec 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockSQLite.java
@@ -5,41 +5,45 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
-public class ProtectedBlockSQLite extends ProtectedBlockJDBC {
- public ProtectedBlockSQLite(String url) throws PropertyVetoException {
+public class ProtectedBlockSQLite extends ProtectedBlockJDBC
+{
+ public ProtectedBlockSQLite(String url) throws PropertyVetoException
+ {
super("org.sqlite.JDBC", url);
}
-
private static final String QueryCreateTable =
- "CREATE TABLE IF NOT EXISTS EssentialsProtect ("
- + "worldName TEXT ,playerName TEXT, "
- + "x NUMERIC, y NUMERIC, z NUMERIC)";
+ "CREATE TABLE IF NOT EXISTS EssentialsProtect ("
+ + "worldName TEXT ,playerName TEXT, "
+ + "x NUMERIC, y NUMERIC, z NUMERIC)";
@Override
- protected PreparedStatement getStatementCreateTable(Connection conn) throws SQLException {
+ protected PreparedStatement getStatementCreateTable(Connection conn) throws SQLException
+ {
return conn.prepareStatement(QueryCreateTable);
}
-
private static final String QueryUpdateFrom2_0Table =
- "CREATE INDEX IF NOT EXISTS position ON EssentialsProtect ("
- + "worldName, x, z, y)";
+ "CREATE INDEX IF NOT EXISTS position ON EssentialsProtect ("
+ + "worldName, x, z, y)";
@Override
- protected PreparedStatement getStatementUpdateFrom2_0Table(Connection conn) throws SQLException {
+ protected PreparedStatement getStatementUpdateFrom2_0Table(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(Connection conn) throws SQLException
+ {
return conn.prepareStatement(QueryDeleteAll);
}
private static final String QueryInsert =
- "INSERT INTO EssentialsProtect (worldName, x, y, z, playerName) VALUES (?, ?, ?, ?, ?);";
+ "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(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException
+ {
PreparedStatement ps = conn.prepareStatement(QueryInsert);
ps.setString(1, world);
ps.setInt(2, x);
@@ -49,11 +53,12 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC {
return ps;
}
private static final String QueryPlayerCountByLocation =
- "SELECT COUNT(playerName), SUM(playerName = ?) FROM EssentialsProtect "
- + "WHERE worldName = ? AND x = ? AND y = ? AND z = ? GROUP BY x;";
+ "SELECT COUNT(playerName), SUM(playerName = ?) FROM EssentialsProtect "
+ + "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(Connection conn, String world, int x, int y, int z, String playerName) throws SQLException
+ {
PreparedStatement ps = conn.prepareStatement(QueryPlayerCountByLocation);
ps.setString(1, playerName);
ps.setString(2, world);
@@ -63,10 +68,11 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC {
return ps;
}
private static final String QueryPlayersByLocation =
- "SELECT playerName FROM EssentialsProtect WHERE worldname = ? AND x = ? AND y = ? AND z = ?;";
+ "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(Connection conn, String world, int x, int y, int z) throws SQLException
+ {
PreparedStatement ps = conn.prepareStatement(QueryPlayersByLocation);
ps.setString(1, world);
ps.setInt(2, x);
@@ -75,10 +81,11 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC {
return ps;
}
private static final String QueryDeleteByLocation =
- "DELETE FROM EssentialsProtect WHERE worldName = ? AND x = ? AND y = ? AND z = ?;";
+ "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(Connection conn, String world, int x, int y, int z) throws SQLException
+ {
PreparedStatement ps = conn.prepareStatement(QueryDeleteByLocation);
ps.setString(1, world);
ps.setInt(2, x);
@@ -87,10 +94,11 @@ public class ProtectedBlockSQLite extends ProtectedBlockJDBC {
return ps;
}
private static final String QueryAllBlocks =
- "SELECT worldName, x, y, z, playerName FROM EssentialsProtect;";
+ "SELECT worldName, x, y, z, playerName FROM EssentialsProtect;";
@Override
- protected PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException {
+ protected PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException
+ {
return conn.prepareStatement(QueryAllBlocks);
}
}