From 399182c203e5aedc26f4aebea324a88972f77880 Mon Sep 17 00:00:00 2001 From: SBPrime Date: Wed, 28 Jun 2017 22:14:37 +0200 Subject: [PATCH] Add test plugin --- .gitignore | 30 +- BlocksHub-Test/build.xml | 73 + BlocksHub-Test/nbproject/build-impl.xml | 1449 +++++++++++++++++ BlocksHub-Test/nbproject/genfiles.properties | 8 + BlocksHub-Test/nbproject/project.properties | 76 + BlocksHub-Test/nbproject/project.xml | 16 + .../primesoft/blockshub/test/TestPlugin.java | 119 ++ BlocksHub-Test/src/plugin.yml | 18 + 8 files changed, 1768 insertions(+), 21 deletions(-) create mode 100644 BlocksHub-Test/build.xml create mode 100644 BlocksHub-Test/nbproject/build-impl.xml create mode 100644 BlocksHub-Test/nbproject/genfiles.properties create mode 100644 BlocksHub-Test/nbproject/project.properties create mode 100644 BlocksHub-Test/nbproject/project.xml create mode 100644 BlocksHub-Test/src/org/primesoft/blockshub/test/TestPlugin.java create mode 100644 BlocksHub-Test/src/plugin.yml diff --git a/.gitignore b/.gitignore index d00af2c..89036cb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,24 +6,12 @@ *.jar *.war *.ear -/BlocksHub/nbproject/private/ -/BlocksHub/build/ -/BlocksHub/dist/ -/BlocksHub/test/ -/BlocksHub/lib/ -/BlocksHub-CoreProtect/nbproject/private/ -/BlocksHub-GriefPrevention-7x/nbproject/private/ -/BlocksHub-GriefPrevention-8x/nbproject/private/ -/BlocksHub-HawkEye/nbproject/private/ -/BlocksHub-LogBlock/nbproject/private/ -/BlocksHub-Prism/nbproject/private/ -/BlocksHub-Residence/nbproject/private/ -/BlocksHub-WorldGuard/nbproject/private/ -/BlocksHub-CoreProtect/build/ -/BlocksHub-CoreProtect/dist/ -/BlocksHub-GriefPrevention-7x/build/ -/BlocksHub-GriefPrevention-8x/dist/ -/BlocksHub-GriefPrevention-8x/build/ -/BlocksHub-GriefPrevention/build/ -/BlocksHub-GriefPrevention/nbproject/private/ -/bin/* \ No newline at end of file +/*/nbproject/private/ +/*/build/ +/*/dist/ +/*/test/ +/*/lib/ +/bin/* +/dist/* +/lib/* +*~ diff --git a/BlocksHub-Test/build.xml b/BlocksHub-Test/build.xml new file mode 100644 index 0000000..e6df73a --- /dev/null +++ b/BlocksHub-Test/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project BlocksHub-Test. + + + diff --git a/BlocksHub-Test/nbproject/build-impl.xml b/BlocksHub-Test/nbproject/build-impl.xml new file mode 100644 index 0000000..4f768e7 --- /dev/null +++ b/BlocksHub-Test/nbproject/build-impl.xml @@ -0,0 +1,1449 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BlocksHub-Test/nbproject/genfiles.properties b/BlocksHub-Test/nbproject/genfiles.properties new file mode 100644 index 0000000..eccb9c2 --- /dev/null +++ b/BlocksHub-Test/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7d0eb547 +build.xml.script.CRC32=b42fc564 +build.xml.stylesheet.CRC32=8064a381@1.79.1.48 +# 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=7d0eb547 +nbproject/build-impl.xml.script.CRC32=90fee48b +nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 diff --git a/BlocksHub-Test/nbproject/project.properties b/BlocksHub-Test/nbproject/project.properties new file mode 100644 index 0000000..49f72fd --- /dev/null +++ b/BlocksHub-Test/nbproject/project.properties @@ -0,0 +1,76 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +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} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/BlocksHub-Test.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.BlocksHub.jar=../BlocksHub/dist/BlocksHub.jar +file.reference.craftbukkit-1.10.jar=lib/craftbukkit-1.10.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.craftbukkit-1.10.jar}:\ + ${file.reference.BlocksHub.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +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= +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=true +platform.active=JDK_1.8 +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. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/BlocksHub-Test/nbproject/project.xml b/BlocksHub-Test/nbproject/project.xml new file mode 100644 index 0000000..92fbef8 --- /dev/null +++ b/BlocksHub-Test/nbproject/project.xml @@ -0,0 +1,16 @@ + + + org.netbeans.modules.java.j2seproject + + + BlocksHub-Test + + + + + + + + + + diff --git a/BlocksHub-Test/src/org/primesoft/blockshub/test/TestPlugin.java b/BlocksHub-Test/src/org/primesoft/blockshub/test/TestPlugin.java new file mode 100644 index 0000000..0887268 --- /dev/null +++ b/BlocksHub-Test/src/org/primesoft/blockshub/test/TestPlugin.java @@ -0,0 +1,119 @@ +/* + * BlocksHub a library plugin providing easy access to block loggers + * and block access controllers. + * Copyright (c) 2017, SBPrime + * Copyright (c) BlocksHub contributors + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted free of charge provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution, + * 3. Redistributions of source code, with or without modification, in any form + * other then free of charge is not allowed, + * 4. Redistributions in binary form in any form other then free of charge is + * not allowed. + * 5. Any derived work based on or containing parts of this software must reproduce + * the above copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * derived work. + * 6. The original author of the software is allowed to change the license + * terms or the entire license of the software as he sees fit. + * 7. The original author of the software is allowed to sublicense the software + * or its parts using any license terms he sees fit. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.primesoft.blockshub.test; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; +import org.primesoft.blockshub.IBlocksHubApi; +import org.primesoft.blockshub.IBlocksHubApiProvider; +import org.primesoft.blockshub.api.BlockData; +import org.primesoft.blockshub.api.IPlayer; +import org.primesoft.blockshub.api.Vector; + +/** + * + * @author SBPPrime + */ +public class TestPlugin extends JavaPlugin { + + private IBlocksHubApi m_api; + + @Override + public void onEnable() { + super.onEnable(); + + IBlocksHubApiProvider apiProvider = (IBlocksHubApiProvider) getServer().getPluginManager().getPlugin("BlocksHub"); + + m_api = apiProvider.getApi(); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + return false; + } + + if (command == null || !command.getName().equalsIgnoreCase("bctest")) { + return false; + } + + Player player = (Player) sender; + + World world = player.getWorld(); + Location l = player.getLocation(); + int x = l.getBlockX(); + int y = l.getBlockY(); + int z = l.getBlockZ(); + + IPlayer bcPlayer = m_api.getPlayer(player.getUniqueId()); + if (y < 0 || y >= 255) { + return true; + } + + boolean hasAccess = m_api.hasAccess(bcPlayer, world.getUID(), + new Vector(x, y, z)); + + player.sendRawMessage("Has access: " + hasAccess); + + ItemStack itemStack = player.getItemOnCursor(); + + if (y < 1 || itemStack == null) { + return true; + } + + Block b = world.getBlockAt(x, y - 1, z); + hasAccess = m_api.canPlace(bcPlayer, world.getUID(), + new Vector(x, y - 1, z), + new BlockData(b.getTypeId(), b.getData()), + new BlockData(itemStack.getTypeId(), itemStack.getDurability())); + + player.sendRawMessage("Can place: " + hasAccess); + + return true; + } +} diff --git a/BlocksHub-Test/src/plugin.yml b/BlocksHub-Test/src/plugin.yml new file mode 100644 index 0000000..b850d09 --- /dev/null +++ b/BlocksHub-Test/src/plugin.yml @@ -0,0 +1,18 @@ +name: BlocksHubTest +main: org.primesoft.blockshub.test.TestPlugin +version: 2.1.0 +website: https://github.com/SBPrime/BlocksHub/ +description: Logger & Block access API. +authors: [SBPrime] +depend: [BlocksHub] +softdepend: [] +commands: + bctest: + aliases: [] + description: 'Test blocks hub access.' + permission: bctest + usage: / to test blocks hub +permissions: + bctest: + description: Grants access to BlocksHub test + default: op