diff options
Diffstat (limited to 'EssentialsProtect')
20 files changed, 519 insertions, 292 deletions
diff --git a/EssentialsProtect/MANIFEST.MF b/EssentialsProtect/MANIFEST.MF index db70a3fda..9d885be53 100644 --- a/EssentialsProtect/MANIFEST.MF +++ b/EssentialsProtect/MANIFEST.MF @@ -1,2 +1 @@ Manifest-Version: 1.0 -Class-Path: ../lib/mysql.jar ../lib/sqlite.jar diff --git a/EssentialsProtect/nbproject/build-impl.xml b/EssentialsProtect/nbproject/build-impl.xml index 1c9bf07bf..8cfd93877 100644 --- a/EssentialsProtect/nbproject/build-impl.xml +++ b/EssentialsProtect/nbproject/build-impl.xml @@ -20,10 +20,10 @@ is divided into following sections: --> <project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="EssentialsProtect-impl"> - <fail message="Please build using Ant 1.7.1 or higher."> + <fail message="Please build using Ant 1.8.0 or higher."> <condition> <not> - <antversion atleast="1.7.1"/> + <antversion atleast="1.8.0"/> </not> </condition> </fail> @@ -223,6 +223,7 @@ is divided into following sections: <property name="javac.fork" value="${jdkBug6558476}"/> <property name="jar.index" value="false"/> <property name="jar.index.metainf" value="${jar.index}"/> + <property name="copylibs.rebase" value="true"/> <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/> </target> <target name="-post-init"> @@ -409,6 +410,7 @@ is divided into following sections: <property environment="env"/> <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/> <java classname="@{classname}" dir="${profiler.info.dir}" fork="true" jvm="${profiler.info.jvm}"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> <jvmarg value="${profiler.info.jvmargs.agent}"/> <jvmarg line="${profiler.info.jvmargs}"/> <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/> @@ -539,7 +541,7 @@ is divided into following sections: </chainedmapper> </pathconvert> <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/> - <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" runtimeclasspath="${run.classpath.without.build.classes.dir}"> + <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}"> <fileset dir="${build.classes.dir}"/> <manifest> <attribute name="Class-Path" value="${jar.classpath}"/> @@ -871,6 +873,14 @@ is divided into following sections: --> <target depends="init" if="have.sources" name="-javadoc-build"> <mkdir dir="${dist.javadoc.dir}"/> + <condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}"> + <and> + <isset property="endorsed.classpath.cmd.line.arg"/> + <not> + <equals arg1="${endorsed.classpath.cmd.line.arg}" arg2=""/> + </not> + </and> + </condition> <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}"> <classpath> <path path="${javac.classpath}"/> @@ -882,6 +892,7 @@ is divided into following sections: <include name="**/*.java"/> <exclude name="*.java"/> </fileset> + <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/> </javadoc> <copy todir="${dist.javadoc.dir}"> <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}"> diff --git a/EssentialsProtect/nbproject/genfiles.properties b/EssentialsProtect/nbproject/genfiles.properties index 728aaf424..fe9ffd1a1 100644 --- a/EssentialsProtect/nbproject/genfiles.properties +++ b/EssentialsProtect/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.3.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=40644caa -nbproject/build-impl.xml.script.CRC32=0e9dab07 -nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45 +nbproject/build-impl.xml.script.CRC32=cdb3fc6f +nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.1.46 diff --git a/EssentialsProtect/nbproject/project.properties b/EssentialsProtect/nbproject/project.properties index dd5d0fd22..77c12c248 100644 --- a/EssentialsProtect/nbproject/project.properties +++ b/EssentialsProtect/nbproject/project.properties @@ -28,6 +28,7 @@ auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blank auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blankLinesBeforeClass=2 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement=NEW_LINE auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.expand-tabs=false +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.importGroupsOrder=* auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indent-shift-width=4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.indentCasesFromSwitch=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement=NEW_LINE @@ -36,6 +37,7 @@ auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.place auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeElseOnNewLine=true auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeFinallyOnNewLine=true auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeWhileOnNewLine=true +auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.separateImportGroups=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceAfterTypeCast=false auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaces-per-tab=4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.tab-size=4 @@ -61,16 +63,16 @@ dist.jar=${dist.dir}/original-EssentialsProtect.jar 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 -file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar includes=** jar.archive.disabled=${jnlp.enabled} jar.compress=true jar.index=${jnlp.enabled} javac.classpath=\ ${reference.Essentials.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}:\ + ${file.reference.bukkit.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false @@ -81,8 +83,7 @@ javac.target=1.6 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir}:\ - ${libs.junit.classpath}:\ - ${libs.junit_4.classpath} + ${libs.junit_4.10.classpath} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyBlockListener.java new file mode 100644 index 000000000..479d2eda6 --- /dev/null +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyBlockListener.java @@ -0,0 +1,36 @@ +package com.earth2me.essentials.protect; + +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; + + +public class EmergencyBlockListener extends BlockListener +{ + + @Override + public void onBlockBurn(final BlockBurnEvent event) + { + event.setCancelled(true); + } + + @Override + public void onBlockIgnite(final BlockIgniteEvent event) + { + event.setCancelled(true); + } + + @Override + public void onBlockFromTo(final BlockFromToEvent event) + { + event.setCancelled(true); + } + + @Override + public void onBlockBreak(final BlockBreakEvent event) + { + event.setCancelled(true); + } +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyEntityListener.java new file mode 100644 index 000000000..a220f07d5 --- /dev/null +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyEntityListener.java @@ -0,0 +1,22 @@ +package com.earth2me.essentials.protect; + +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityListener; + + +public class EmergencyEntityListener extends EntityListener +{ + + @Override + public void onEntityExplode(final EntityExplodeEvent event) + { + event.setCancelled(true); + } + + @Override + public void onEntityDamage(final EntityDamageEvent event) + { + event.setCancelled(true); + } +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyPlayerListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyPlayerListener.java new file mode 100644 index 000000000..e92325946 --- /dev/null +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyPlayerListener.java @@ -0,0 +1,16 @@ +package com.earth2me.essentials.protect; + +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerListener; + + +public class EmergencyPlayerListener extends PlayerListener +{ + + @Override + public void onPlayerJoin(PlayerJoinEvent event) + { + event.getPlayer().sendMessage("Essentials Protect is in emergency mode. Check your log for errors."); + } + +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java new file mode 100644 index 000000000..569123cd5 --- /dev/null +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java @@ -0,0 +1,124 @@ +package com.earth2me.essentials.protect; + +import com.earth2me.essentials.IConf; +import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.User; +import com.earth2me.essentials.protect.data.ProtectedBlockMemory; +import com.earth2me.essentials.protect.data.ProtectedBlockMySQL; +import com.earth2me.essentials.protect.data.ProtectedBlockSQLite; +import java.beans.PropertyVetoException; +import static com.earth2me.essentials.I18n._; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + + +public class EssentialsConnect +{ + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private final transient IEssentials ess; + private final transient IProtect protect; + + public EssentialsConnect(Plugin essPlugin, Plugin essProtect) + { + if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion())) + { + LOGGER.log(Level.WARNING, _("versionMismatchAll")); + } + ess = (IEssentials)essPlugin; + protect = (IProtect)essProtect; + ProtectReloader pr = new ProtectReloader(); + pr.reloadConfig(); + ess.addReloadListener(pr); + LOGGER.info(_("loadinfo", essProtect.getDescription().getName(), essProtect.getDescription().getVersion(), "essentials team")); + + } + + public void onDisable() + { + } + + public IEssentials getEssentials() + { + return ess; + } + + public void alert(final User user, final String item, final String type) + { + final Location loc = user.getLocation(); + 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 : ess.getServer().getOnlinePlayers()) + { + final User alertUser = ess.getUser(p); + if (alertUser.isAuthorized("essentials.protect.alerts")) + { + alertUser.sendMessage(warnMessage); + } + } + } + + + private class ProtectReloader implements IConf + { + @Override + public void reloadConfig() + { + if (protect.getStorage() != null) + { + protect.getStorage().onPluginDeactivation(); + } + for (ProtectConfig protectConfig : ProtectConfig.values()) + { + if (protectConfig.isList()) + { + protect.getSettingsList().put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName())); + } + else if (protectConfig.isString()) + { + protect.getSettingsString().put(protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName())); + } + else + { + protect.getSettingsBoolean().put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean())); + } + + } + + if (protect.getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql")) + { + try + { + protect.setStorage(new ProtectedBlockMySQL( + protect.getSettingString(ProtectConfig.mysqlDB), + protect.getSettingString(ProtectConfig.dbUsername), + protect.getSettingString(ProtectConfig.dbPassword))); + } + catch (PropertyVetoException ex) + { + LOGGER.log(Level.SEVERE, null, ex); + } + } + else + { + try + { + protect.setStorage(new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db")); + } + catch (PropertyVetoException ex) + { + LOGGER.log(Level.SEVERE, null, ex); + } + } + if (protect.getSettingBool(ProtectConfig.memstore)) + { + protect.setStorage(new ProtectedBlockMemory(protect.getStorage(), protect)); + } + + } + } +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index 98daf26cb..e313298cd 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -1,14 +1,6 @@ package com.earth2me.essentials.protect; -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; -import com.earth2me.essentials.protect.data.ProtectedBlockSQLite; -import java.beans.PropertyVetoException; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -16,15 +8,15 @@ import java.util.logging.Filter; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; -import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -public class EssentialsProtect extends JavaPlugin implements IConf, IProtect +public class EssentialsProtect extends JavaPlugin implements IProtect { private static final Logger LOGGER = Logger.getLogger("Minecraft"); private static com.mchange.v2.log.MLogger C3P0logger; @@ -32,7 +24,7 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect private final transient Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class); private final transient Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class); private transient IProtectedBlock storage = null; - public transient IEssentials ess = null; + private transient EssentialsConnect ess = null; @Override public void onLoad() @@ -50,7 +42,13 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect public void onEnable() { final PluginManager pm = this.getServer().getPluginManager(); - ess = (IEssentials)pm.getPlugin("Essentials"); + final Plugin essPlugin = pm.getPlugin("Essentials"); + if (essPlugin == null || !essPlugin.isEnabled()) + { + enableEmergencyMode(pm); + return; + } + ess = new EssentialsConnect(essPlugin, this); final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this); pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this); @@ -76,14 +74,25 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this); pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this); pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this); + } - reloadConfig(); - ess.addReloadListener(this); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) + private void enableEmergencyMode(final PluginManager pm) + { + final EmergencyBlockListener emBlockListener = new EmergencyBlockListener(); + final EmergencyEntityListener emEntityListener = new EmergencyEntityListener(); + final EmergencyPlayerListener emPlayerListener = new EmergencyPlayerListener(); + pm.registerEvent(Type.PLAYER_JOIN, emPlayerListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_BURN, emBlockListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_IGNITE, emBlockListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_FROMTO, emBlockListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_BREAK, emBlockListener, Priority.Low, this); + pm.registerEvent(Type.ENTITY_DAMAGE, emEntityListener, Priority.Low, this); + pm.registerEvent(Type.ENTITY_EXPLODE, emEntityListener, Priority.Low, this); + for (Player player : getServer().getOnlinePlayers()) { - LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll")); + player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors."); } - LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); + LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now."); } @Override @@ -94,81 +103,35 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect } @Override - public void alert(final User user, final String item, final String type) + public IProtectedBlock getStorage() { - final Location loc = user.getLocation(); - final String warnMessage = Util.format("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()) - { - final User alertUser = ess.getUser(p); - if (alertUser.isAuthorized("essentials.protect.alerts")) - { - alertUser.sendMessage(warnMessage); - } - } + return storage; } - public void reloadConfig() + @Override + public void setStorage(IProtectedBlock pb) { - if (storage != null) - { - storage.onPluginDeactivation(); - } - for (ProtectConfig protectConfig : ProtectConfig.values()) - { - if (protectConfig.isList()) - { - settingsList.put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName())); - } - else if (protectConfig.isString()) - { - settingsString.put(protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName())); - } - else - { - settingsBoolean.put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean())); - } + storage = pb; + } - } + public EssentialsConnect getEssentialsConnect() + { + return ess; + } + + public Map<ProtectConfig, Boolean> getSettingsBoolean() + { + return settingsBoolean; + } - if (getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql")) - { - try - { - storage = new ProtectedBlockMySQL( - getSettingString(ProtectConfig.mysqlDB), - getSettingString(ProtectConfig.dbUsername), - getSettingString(ProtectConfig.dbPassword)); - } - catch (PropertyVetoException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - } - else - { - try - { - storage = new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db"); - } - catch (PropertyVetoException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - } - if (getSettingBool(ProtectConfig.memstore)) - { - storage = new ProtectedBlockMemory(storage, this); - } + public Map<ProtectConfig, String> getSettingsString() + { + return settingsString; } - @Override - public IProtectedBlock getStorage() + public Map<ProtectConfig, List<Integer>> getSettingsList() { - return storage; + return settingsList; } @Override @@ -200,9 +163,4 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect { } } - - public IEssentials getEssentials() - { - return ess; - } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index 8717825b3..a1d16af25 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 @@ -27,7 +20,7 @@ public class EssentialsProtectBlockListener extends BlockListener public EssentialsProtectBlockListener(final IProtect parent) { this.prot = parent; - this.ess = prot.getEssentials(); + this.ess = prot.getEssentialsConnect().getEssentials(); } @Override @@ -57,13 +50,13 @@ public class EssentialsProtectBlockListener extends BlockListener if (prot.checkProtectionItems(ProtectConfig.alert_on_placement, id)) { - prot.alert(user, blockPlaced.getType().toString(), Util.i18n("alertPlaced")); + prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced")); } final Block below = blockPlaced.getRelative(BlockFace.DOWN); if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL) && prot.getSettingBool(ProtectConfig.prevent_block_on_rail) - && prot.getStorage().isProtected(below, user.getName())) + && isProtected(below, user)) { event.setCancelled(true); return; @@ -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) + && !isProtected(blockPlaced.getRelative(BlockFace.DOWN), user)) { 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 + && !isProtected(event.getBlockAgainst(), user)) { 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.getEssentialsConnect().alert(user, type.toString(), _("alertBroke")); } final IProtectedBlock storage = prot.getStorage(); @@ -286,7 +283,7 @@ public class EssentialsProtectBlockListener extends BlockListener else { - final boolean isProtected = storage.isProtected(block, user.getName()); + final boolean isProtected = isProtected(block, user); if (isProtected) { event.setCancelled(true); @@ -425,4 +422,58 @@ public class EssentialsProtectBlockListener extends BlockListener } } } + + private boolean isProtected(final Block block, final User user) + { + final Material type = block.getType(); + if (prot.getSettingBool(ProtectConfig.protect_signs)) + { + if (type == Material.WALL_SIGN || type == Material.SIGN_POST) + { + return prot.getStorage().isProtected(block, user.getName()); + } + if (prot.getSettingBool(ProtectConfig.protect_against_signs)) + { + final Block up = block.getRelative(BlockFace.UP); + if (up != null && up.getType() == Material.SIGN_POST) + { + return prot.getStorage().isProtected(block, user.getName()); + } + final BlockFace[] directions = new BlockFace[] + { + BlockFace.NORTH, + BlockFace.EAST, + BlockFace.SOUTH, + BlockFace.WEST + }; + for (BlockFace blockFace : directions) + { + final Block signblock = block.getRelative(blockFace); + if (signblock.getType() == Material.WALL_SIGN) + { + final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign)signblock.getState().getData(); + if (signMat != null && signMat.getFacing() == blockFace) + { + return prot.getStorage().isProtected(block, user.getName()); + } + } + } + } + } + if (prot.getSettingBool(ProtectConfig.protect_rails)) { + if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL) + { + return prot.getStorage().isProtected(block, user.getName()); + } + if (prot.getSettingBool(ProtectConfig.protect_below_rails)) + { + final Block up = block.getRelative(BlockFace.UP); + if (up != null && (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)) + { + return prot.getStorage().isProtected(block, user.getName()); + } + } + } + return false; + } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index c0e568578..89167b2b9 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(); + this.ess = prot.getEssentialsConnect().getEssentials(); } - + @Override public void onEntityDamage(final EntityDamageEvent event) { @@ -53,11 +32,18 @@ public class EssentialsProtectEntityListener extends EntityListener return; } final Entity target = event.getEntity(); + + if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death)) + { + event.setCancelled(true); + return; + } + final User user = ess.getUser(target); if (event instanceof EntityDamageByBlockEvent) { final DamageCause cause = event.getCause(); - + if (prot.getSettingBool(ProtectConfig.disable_contactdmg) && cause == DamageCause.CONTACT && !(target instanceof Player @@ -86,7 +72,7 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } - + if (event instanceof EntityDamageByEntityEvent) { final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; @@ -111,7 +97,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 +106,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 +116,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 +125,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 +140,7 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } - + final DamageCause cause = event.getCause(); if (target instanceof Player) { @@ -165,7 +152,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 +188,7 @@ public class EssentialsProtectEntityListener extends EntityListener } } } - + @Override public void onEntityExplode(final EntityExplodeEvent event) { @@ -210,56 +197,34 @@ public class EssentialsProtectEntityListener extends EntityListener return; } final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight(); - //Nicccccccccce plaaacccccccccce.. - if (event.getEntity() instanceof LivingEntity - && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) - || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) - || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) + + if (event.getEntity() instanceof EnderDragon + && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg)) { - 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) + if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions)) { - Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); + FakeExplosion.createExplosion(event, ess.getServer(), ess.getServer().getOnlinePlayers()); } event.setCancelled(true); return; } + else if (event.getEntity() instanceof Creeper + && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion) + || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) + || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) + { + //Nicccccccccce plaaacccccccccce.. + FakeExplosion.createExplosion(event, ess.getServer(), ess.getServer().getOnlinePlayers()); + event.setCancelled(true); + return; + } else if (event.getEntity() instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) { 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 +260,7 @@ public class EssentialsProtectEntityListener extends EntityListener } } } - + @Override public void onCreatureSpawn(final CreatureSpawnEvent event) { @@ -307,7 +272,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 +287,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); } } - + @Override public void onEntityTarget(final EntityTargetEvent event) { @@ -343,11 +313,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 +327,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..ad7831a53 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 @@ -19,16 +19,13 @@ public class EssentialsProtectPlayerListener extends PlayerListener public EssentialsProtectPlayerListener(final IProtect prot) { this.prot = prot; - this.ess = prot.getEssentials(); + this.ess = prot.getEssentialsConnect().getEssentials(); } @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.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed")); } } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/IProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/IProtect.java index ac095e33d..afcb6e8ce 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/IProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/IProtect.java @@ -1,14 +1,13 @@ package com.earth2me.essentials.protect; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; import com.earth2me.essentials.protect.data.IProtectedBlock; +import java.util.List; +import java.util.Map; +import org.bukkit.plugin.Plugin; -public interface IProtect +public interface IProtect extends Plugin { - void alert(final User user, final String item, final String type); - boolean checkProtectionItems(final ProtectConfig list, final int id); boolean getSettingBool(final ProtectConfig protectConfig); @@ -17,5 +16,13 @@ public interface IProtect IProtectedBlock getStorage(); - IEssentials getEssentials(); + void setStorage(IProtectedBlock pb); + + EssentialsConnect getEssentialsConnect(); + + Map<ProtectConfig, Boolean> getSettingsBoolean(); + + Map<ProtectConfig, String> getSettingsString(); + + Map<ProtectConfig, List<Integer>> getSettingsList(); } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java index 5d93fe0ea..bee8d0f4d 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java @@ -40,11 +40,14 @@ public enum ProtectConfig prevent_creeper_playerdmg("protect.prevent.creeper-playerdamage", false), prevent_creeper_blockdmg("protect.prevent.creeper-blockdamage", false), prevent_enderman_pickup("protect.prevent.enderman-pickup", false), + prevent_villager_death("protect.prevent.villager-death", false), + prevent_enderdragon_blockdmg("protect.prevent.enderdragon-blockdamage", true), prevent_entitytarget("protect.prevent.entitytarget", false), protect_rails("protect.protect.rails", true), protect_below_rails("protect.protect.block-below", true), protect_signs("protect.protect.signs", true), protect_against_signs("protect.protect.block-below", true), + enderdragon_fakeexplosions("protect.enderdragon-fakeexplosions", false), alert_on_placement("protect.alert.on-placement"), alert_on_use("protect.alert.on-use"), alert_on_break("protect.alert.on-break"), @@ -62,7 +65,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 +113,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); } } diff --git a/EssentialsProtect/src/plugin.yml b/EssentialsProtect/src/plugin.yml index 31fc1ae99..6407c45ee 100644 --- a/EssentialsProtect/src/plugin.yml +++ b/EssentialsProtect/src/plugin.yml @@ -5,5 +5,5 @@ main: com.earth2me.essentials.protect.EssentialsProtect version: TeamCity website: http://www.earth2me.net:8001/ description: Provides protection for various parts of the world. -authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology] -depend: [Essentials]
\ No newline at end of file +authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits] +softdepend: [Essentials]
\ No newline at end of file |