mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-05 06:07:54 +02:00
Split Ess protect into EssProtect and EssAntiBuild
New permissions: essentials.build - same as build: true essentials.build.interact.<id> - whitelist single interact block essentials.build.place.<id> - whitelist single place block essentials.build.break.<id> - whitelist single break block essentials.build.use.<id> - whitelist single use item
This commit is contained in:
83
EssentialsAntiBuild/build.xml
Normal file
83
EssentialsAntiBuild/build.xml
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE project [ <!ENTITY buildinc SYSTEM "../build.inc.xml"> ]>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="EssentialsAntiBuild" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project EssentialsAntiBuild.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="EssentialsProtect-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
<target name="-post-jar">
|
||||
<jar jarfile="${dist.dir}/EssentialsAntiBuild.jar">
|
||||
<zipfileset src="${dist.jar}" excludes="META-INF/*" />
|
||||
<manifest>
|
||||
<attribute name="Classpath" value="EssentialsAntiBuild.jar"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
1092
EssentialsAntiBuild/nbproject/build-impl.xml
Normal file
1092
EssentialsAntiBuild/nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
EssentialsAntiBuild/nbproject/genfiles.properties
Normal file
8
EssentialsAntiBuild/nbproject/genfiles.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=ff207988
|
||||
build.xml.script.CRC32=1ed11cc3
|
||||
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=ddb4519c
|
||||
nbproject/build-impl.xml.script.CRC32=cfb9443d
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.3.46
|
123
EssentialsAntiBuild/nbproject/project.properties
Normal file
123
EssentialsAntiBuild/nbproject/project.properties
Normal file
@@ -0,0 +1,123 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
application.title=EssentialsAntiBuild
|
||||
application.vendor=
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=2
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=2
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=2
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=120
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap=none
|
||||
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineAnnotationArgs=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineArrayInit=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineAssignment=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineBinaryOp=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineCallArgs=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineDisjunctiveCatchTypes=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineFor=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineImplements=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineMethodParams=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineParenthesized=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineTernaryOp=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineThrows=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineTryResources=true
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.blankLinesAfterClassHeader=0
|
||||
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
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement=NEW_LINE
|
||||
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeCatchOnNewLine=true
|
||||
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
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/original-EssentialsAntiBuild.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
file.reference.bukkit.jar=../lib/bukkit.jar
|
||||
includes=**
|
||||
jar.archive.disabled=${jnlp.enabled}
|
||||
jar.compress=true
|
||||
jar.index=${jnlp.enabled}
|
||||
javac.classpath=\
|
||||
${reference.Essentials.jar}:\
|
||||
${file.reference.bukkit.jar}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.6
|
||||
javac.target=1.6
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}:\
|
||||
${libs.junit_4.10.classpath}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
jnlp.codebase.type=no.codebase
|
||||
jnlp.descriptor=application
|
||||
jnlp.enabled=false
|
||||
jnlp.mixed.code=defaut
|
||||
jnlp.offline-allowed=false
|
||||
jnlp.signed=false
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=true
|
||||
platform.active=default_platform
|
||||
project.Essentials=../Essentials
|
||||
reference.Essentials.jar=${project.Essentials}/dist/Essentials.jar
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project
|
||||
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
|
||||
# or test-sys-prop.name=value to set system properties for unit tests):
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
28
EssentialsAntiBuild/nbproject/project.xml
Normal file
28
EssentialsAntiBuild/nbproject/project.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>EssentialsAntiBuild</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
<libraries xmlns="http://www.netbeans.org/ns/ant-project-libraries/1">
|
||||
<definitions>../lib/nblibraries.properties</definitions>
|
||||
</libraries>
|
||||
<references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
|
||||
<reference>
|
||||
<foreign-project>Essentials</foreign-project>
|
||||
<artifact-type>jar</artifact-type>
|
||||
<script>build.xml</script>
|
||||
<target>jar</target>
|
||||
<clean-target>clean</clean-target>
|
||||
<id>jar</id>
|
||||
</reference>
|
||||
</references>
|
||||
</configuration>
|
||||
</project>
|
@@ -0,0 +1,73 @@
|
||||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
|
||||
public enum AntiBuildConfig
|
||||
{
|
||||
disable_build("protect.disable.build", true),
|
||||
disable_use("protect.disable.use", true),
|
||||
alert_on_placement("protect.alert.on-placement"),
|
||||
alert_on_use("protect.alert.on-use"),
|
||||
alert_on_break("protect.alert.on-break"),
|
||||
blacklist_placement("protect.blacklist.placement"),
|
||||
blacklist_usage("protect.blacklist.usage"),
|
||||
blacklist_break("protect.blacklist.break"),
|
||||
blacklist_piston("protect.blacklist.piston");
|
||||
private final String configName;
|
||||
private final String defValueString;
|
||||
private final boolean defValueBoolean;
|
||||
private final boolean isList;
|
||||
private final boolean isString;
|
||||
|
||||
private AntiBuildConfig(final String configName)
|
||||
{
|
||||
this(configName, null, false, true, false);
|
||||
}
|
||||
|
||||
private AntiBuildConfig(final String configName, final boolean defValueBoolean)
|
||||
{
|
||||
this(configName, null, defValueBoolean, false, false);
|
||||
}
|
||||
|
||||
private AntiBuildConfig(final String configName, final String defValueString, final boolean defValueBoolean, final boolean isList, final boolean isString)
|
||||
{
|
||||
this.configName = configName;
|
||||
this.defValueString = defValueString;
|
||||
this.defValueBoolean = defValueBoolean;
|
||||
this.isList = isList;
|
||||
this.isString = isString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configName
|
||||
*/
|
||||
public String getConfigName()
|
||||
{
|
||||
return configName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default value String
|
||||
*/
|
||||
public String getDefaultValueString()
|
||||
{
|
||||
return defValueString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the default value boolean
|
||||
*/
|
||||
public boolean getDefaultValueBoolean()
|
||||
{
|
||||
return defValueBoolean;
|
||||
}
|
||||
|
||||
public boolean isString()
|
||||
{
|
||||
return isString;
|
||||
}
|
||||
|
||||
public boolean isList()
|
||||
{
|
||||
return isList;
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient Map<AntiBuildConfig, Boolean> settingsBoolean = new EnumMap<AntiBuildConfig, Boolean>(AntiBuildConfig.class);
|
||||
private final transient Map<AntiBuildConfig, List<Integer>> settingsList = new EnumMap<AntiBuildConfig, List<Integer>>(AntiBuildConfig.class);
|
||||
private transient EssentialsConnect ess = null;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
final PluginManager pm = this.getServer().getPluginManager();
|
||||
final Plugin essPlugin = pm.getPlugin("Essentials");
|
||||
if (essPlugin == null || !essPlugin.isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ess = new EssentialsConnect(essPlugin, this);
|
||||
|
||||
final EssentialsAntiBuildListener blockListener = new EssentialsAntiBuildListener(this);
|
||||
pm.registerEvents(blockListener, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkProtectionItems(final AntiBuildConfig list, final int id)
|
||||
{
|
||||
final List<Integer> itemList = settingsList.get(list);
|
||||
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EssentialsConnect getEssentialsConnect()
|
||||
{
|
||||
return ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AntiBuildConfig, Boolean> getSettingsBoolean()
|
||||
{
|
||||
return settingsBoolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<AntiBuildConfig, List<Integer>> getSettingsList()
|
||||
{
|
||||
return settingsList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSettingBool(final AntiBuildConfig protectConfig)
|
||||
{
|
||||
final Boolean bool = settingsBoolean.get(protectConfig);
|
||||
return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
|
||||
}
|
||||
}
|
@@ -0,0 +1,179 @@
|
||||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
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.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class EssentialsAntiBuildListener implements Listener
|
||||
{
|
||||
final private transient IAntiBuild prot;
|
||||
final private transient IEssentials ess;
|
||||
|
||||
public EssentialsAntiBuildListener(final IAntiBuild parent)
|
||||
{
|
||||
this.prot = parent;
|
||||
this.ess = prot.getEssentialsConnect().getEssentials();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockPlace(final BlockPlaceEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
&& (event.getBlock() != null && !user.isAuthorized("essentials.build.place." + event.getBlock().getTypeId())))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final Block blockPlaced = event.getBlockPlaced();
|
||||
final int id = blockPlaced.getTypeId();
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, id) && !user.isAuthorized("essentials.protect.exemptplacement"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.isAuthorized("essentials.protect.alerts.notrigger")
|
||||
&& prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, id))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockBreak(final BlockBreakEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")
|
||||
&& (event.getBlock() != null && !user.isAuthorized("essentials.build.break." + event.getBlock().getTypeId())))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Block block = event.getBlock();
|
||||
final int typeId = block.getTypeId();
|
||||
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, typeId)
|
||||
&& !user.isAuthorized("essentials.protect.exemptbreak"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Material type = block.getType();
|
||||
|
||||
if (!user.isAuthorized("essentials.protect.alerts.notrigger")
|
||||
&& prot.checkProtectionItems(AntiBuildConfig.alert_on_break, typeId))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockPistonExtend(BlockPistonExtendEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (Block block : event.getBlocks())
|
||||
{
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockPistonRetract(BlockPistonRetractEvent event)
|
||||
{
|
||||
if (event.isCancelled() || !event.isSticky())
|
||||
{
|
||||
return;
|
||||
}
|
||||
final Block block = event.getRetractLocation().getBlock();
|
||||
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerInteract(final PlayerInteractEvent event)
|
||||
{
|
||||
// Do not return if cancelled, because the interact event has 2 cancelled states.
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
if (event.hasItem()
|
||||
&& (event.getItem().getType() == Material.WATER_BUCKET
|
||||
|| event.getItem().getType() == Material.LAVA_BUCKET)
|
||||
&& prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("buildAlert"));
|
||||
}
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack item = event.getItem();
|
||||
if (item != null
|
||||
&& prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getTypeId())
|
||||
&& !user.isAuthorized("essentials.protect.exemptusage"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (item != null
|
||||
&& !user.isAuthorized("essentials.protect.alerts.notrigger")
|
||||
&& prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getTypeId()))
|
||||
{
|
||||
prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));
|
||||
}
|
||||
|
||||
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.interact") && !user.isAuthorized("essentials.build"))
|
||||
{
|
||||
if (event.getClickedBlock() != null && !user.isAuthorized("essentials.build.interact." + event.getClickedBlock().getTypeId()))
|
||||
{
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
if (ess.getSettings().warnOnBuildDisallow())
|
||||
{
|
||||
user.sendMessage(_("buildAlert"));
|
||||
}
|
||||
}
|
||||
if (event.hasItem() && !user.isAuthorized("essentials.build.use." + event.getMaterial().getId()))
|
||||
{
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
import com.earth2me.essentials.IConf;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
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 IAntiBuild protect;
|
||||
|
||||
public EssentialsConnect(Plugin essPlugin, Plugin essProtect)
|
||||
{
|
||||
if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion()))
|
||||
{
|
||||
LOGGER.log(Level.WARNING, _("versionMismatchAll"));
|
||||
}
|
||||
ess = (IEssentials)essPlugin;
|
||||
protect = (IAntiBuild)essProtect;
|
||||
AntiBuildReloader pr = new AntiBuildReloader();
|
||||
pr.reloadConfig();
|
||||
ess.addReloadListener(pr);
|
||||
}
|
||||
|
||||
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 AntiBuildReloader implements IConf
|
||||
{
|
||||
@Override
|
||||
public void reloadConfig()
|
||||
{
|
||||
for (AntiBuildConfig protectConfig : AntiBuildConfig.values())
|
||||
{
|
||||
if (protectConfig.isList())
|
||||
{
|
||||
protect.getSettingsList().put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
protect.getSettingsBoolean().put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package com.earth2me.essentials.antibuild;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public interface IAntiBuild extends Plugin
|
||||
{
|
||||
boolean checkProtectionItems(final AntiBuildConfig list, final int id);
|
||||
|
||||
boolean getSettingBool(final AntiBuildConfig protectConfig);
|
||||
|
||||
EssentialsConnect getEssentialsConnect();
|
||||
|
||||
Map<AntiBuildConfig, Boolean> getSettingsBoolean();
|
||||
|
||||
Map<AntiBuildConfig, List<Integer>> getSettingsList();
|
||||
}
|
9
EssentialsAntiBuild/src/plugin.yml
Normal file
9
EssentialsAntiBuild/src/plugin.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
# This determines the command prefix when there are conflicts (/name:home, /name:help, etc.)
|
||||
name: EssentialsAntiBuild
|
||||
main: com.earth2me.essentials.antibuild.EssentialsAntiBuild
|
||||
# Note to developers: This next line cannot change, or the automatic versioning system will break.
|
||||
version: TeamCity
|
||||
website: http://www.earth2me.net:8001/
|
||||
description: Provides build protection.
|
||||
authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits]
|
||||
softdepend: [Essentials]
|
Reference in New Issue
Block a user