CBWrapper
CBWrapper
Concept
Have you ever wanted to be able to use WorldEdit from command blocks? Or other plugins, too, whose commands won't work from command blocks. Well, this is the plugin for you! When the command /cw is run from a command block, it will create a dummy player where the command block is and run the command specified in the command parameters!
News
Some people (everybody) were getting issues between CBW 1.8_alpha, Essentials, and a few other plugins. These conflicts are a side effect of how CBW 1.8_alpha works and is what I hoped wouldn't happen. Avyge1l came up with a solution, which I have now implemented. The plugin now works almost exactly the same way it did in 1.7, but it works for 1.8 still.
Installation
Standard bukkit plugin installation; download the CBWrapper.jar and stick it in your plugins folder
Source Code
Version | Source Link |
Development Version | https://github.com/misson20000/CBWrapper |
Version 1.8.3 (current) | https://github.com/misson20000/CBWrapper/tree/v1.8.3 |
Version 1.8 | https://github.com/misson20000/CBWrapper/tree/v1.8 |
Version 1.8_alpha | https://github.com/misson20000/CBWrapper/tree/v1.8-playerlist |
Usage
If anything doesn't make sense, you might want to consult this page, which I think is a bit more friendly but less clear.
Just tell me how to use the plugin as fast as you can
Put /cw
in front of your commands and remove the first slash. WorldEdit commands will have one slash left and other commands will have no slashes left. Use commands just like you would as a player. Look at the examples for complicated things
That was great but didn't make much sense
That's what this section is for. Here I'll explain everything in more detail
CBWrapper adds one command, /cw for use in command blocks. The general usage is as follows:
/cw [-u username] [-w world] [ -o x y z] <command> [arguments]
For many purposes, however, simply
/cw <command> [arguments]
is sufficient.
The /cw command create a fake player and runs the command as it. This allows you to use commands from plugins that would usually only work for players. The best example of this would be WorldEdit. WorldEdit is usually meant for only players to use, and has no support for command blocks. Using the /cw command, you can trick WorldEdit into thinking that a player is using it and allow the operation.
Say you wanted a command block system to reset a spleef arena every time a new round starts.
You could put a command block at each corner to run the WorldEdit selection commands //pos1
and //pos2
and another
command block to replace the empty blocks with snow or whatever material you are using.
What if I want to have the command blocks far away? No problem. Use the -o option. -o originally stood for offset, but now it would make more sense as -p for position. Oh well. You give it 3 numbers, which are interpreted as coordinates. And numbers starting with a ~
will be interpreted as relative, so -o 5 ~0 -4
would mean run the command at X coordinate 5, use the command block's Y coordinate, and Z coordinate -4.
How about selecting regions in different worlds? Use the -w for world option. It takes one parameter: the name of the world to run the command in. Usually this would be "world", "world_nether", or "world_the_end." If you have Multiverse or something installed, the name of the multiverse world should work too. The -w option is best used with -o, because otherwise your command will be run in the same position, but in the nether or whatever world you specify.
That's great, but how can I prevent my selections from colliding? Pretend to be different players with the -u option. It takes one parameter: the username it pretends to have. WorldEdit thinks it's different players, but it actually isn't any players at all. It's just command blocks.
Examples
Select corner 1 of a WorldEdit selection: /cw /pos1
Select corner 2 of a WorldEdit selection: /cw /pos2
Replace blocks in selection: /cw /replace air snow
Make sure you don't use /set or /wall, as those might delete your command blocks!
Ban whoever dares approach the command block and pretend that someone else did it: /cw -u @r ban @p
Select a corner 2 blocks above the command block /cw -o ~0 ~2 ~0 /pos1
Select the coordinates (0, 0, 0) in the nether: /cw -w world_nether -o 0 0 0 /pos1
Stop the server: /cw stop
Help me it still doesn't make sense!
Leave a comment below. Post the commands you tried, what you're trying to do, and anything else you think would be helpful.
Be careful with the wiki formatting, it can mess things up. Usually putting {{{
and }}}
around your commands helps
Permissions
There is only one permission node, "cbwrapper.cb", for the /cw command
Other Notes
- The dummy player's username, by default, is "@"
- The dummy player's position is the position of the command block it was run from, unless you use the -o flag
- The dummy players isn't actually registered as a player, so you can't teleport people to it or anything
- The dummy player is an op with all permissions. The only bit of security is that the dummy player is only created by command blocks, which can only be edited by ops in creative mode
If you comment anywhere other than this page, I probably won't see it for at least a few months. PMs are fine, too
@misson20000
Well, the region isn't being selected by the fake player. I expect rg select to load a region as the new WorldEdit selection for the fake player, but that doesn't seem to be the case. This is how it works as a regular player.
I would like the 3rd step to work for cbwrapper, so I don't need to have command blocks poking out all over the place. This is especially useful for selections that are polygons, so I don't also need to have like 30 command blocks for one simple thing.
@misson20000
So, is it not possible to select regions using the "/rg select regionname" command? Because I can't seem to get it to work. Basically, I want to select an already made region and then replace some blocks in that region.
In the version I posted in the comments, the -o option works just like the coordinates in the /tp command. They are treated as absolue (-o 0 0 0 means at the actual coordinates 0,0,0) if you don't put a ~ in front of them, but if you do put a ~ in front of them, they are treated as relative.
In your case, you want to use '-o ~-1 ~0 ~-1' and it will work with both versions.
And for your WorldEdit selections being destroyed upon world reload, that's a WorldEdit thing. If you try selecting something with your WorldEdit wand, and restart the server I'm fairly sure it won't be selected anymore. (I know it's annoying, but there are ways to work around it, such as reselecting the area every time you need it)
Sorry for writing again, kind of feel like I am pestering. I have two problems though. The first problem is that -o doesn't seem to work. I put in -o -1 0 -1 to make the command block only set one block negative x, no blocks move on y and one block negative y. The second problem is that the command blocks that you said to power (with a redstone torch) in the usage area (the pos1 and pos2 ones) do not work after restarting, reloading, or stopping and starting the server. I destroy the torch and replace it and it works. I downloaded the 1.6 version (not craftbook edition). Please reply, thanks! Snoopyfighter
@misson20000
Thank you so much. Just FYI, the download link on this page is apparently way out of date I think. I downloaded the file you put in the comments and that fixed my problems. You may want to make that file the new hotlink. THANKS!
@Snoopyfighter
There have been multiple dummies since pretty early on. You can do /cw -u dummy1 /pos1 and /cw -u dummy2 /pos1 and they should be seperate If you're using a version from before I added that, try renaming the command block in an anvil
The plugin works great...but I have a problem. I am using world edit and everytime I want to make another automated command block, it goes back and changes the first pos1 and pos2 i ever made. Is there any way to use muliple pos1 pos2 because I need more than 1. Thanks! Oh and btw i am using the 1.6 version not the craft book ones. Is there a new version that allows multiple dummies?
@SpanishHangover
I try to keep my code up to date with the latest devbuild of bukkit, so the API might've changed a bit since the release you're using. The annoying thing about DummyPlayer.java is that I have to update it pretty much every time the API changes, so the version numbers for CBWrapper make a difference. If you can, use the devbuild. I'll try to keep my DummyPlayer class up to date with bukkit, and if you really want, you can try to set up a git submodule to keep your DummyPlayer.java up to date
So, just compile with the devbuild Bukkit.jar when building my source code
Okay so in follow-up to my previous post; I have been able to successfully build the project (ignoring multiple errors) and I have been able to instantiate a new Player object from within ScriptCraft. I have not, however, been able to reproduce command sending functionality with the object. I even tried building your exact source code from a project that I tried duplicating the information into (while trying the import from a git uri option in eclipse - - not sure what it may or may not have done). This produced the same exact problems. In both the Bukkit console window and in Eclipse I get references to the error/warning: "The method someMethod() of type DummyPlayer must override a superclass method." Also in the Bukkit console I see "Caused by: org.bukkit.command.CommandException: Unhandled exception executing 'say test ' in org.bukkit.command.defaults.SayCommand(say)" and in Eclipse (CBWrapper.java) it says "The import org.bukkit.command.ConsoleCommandSender is never used."
Through all of this I did manage to find out that you shouldn't put the @Override in front of the code for the newDummyPlayer method, but it will require the org.bukkit.Server import. I really hope to see this implemented, and would like to thank you in advance if you do decide to make it an official implementation.
Regards, Jonathan Gray
Hi, I was wondering if you could make a small change to the source code of your plugin in order to allow me to instantiate a DummyPlayer object from within ScriptCraft. I am in the process of installing Eclipse in order to do this myself, but I think it would be a really nice official addition to this plugin.
I need this DummyPlayer object in order to perform console commands that only operator-privileged players can perform, but automatically and at set intervals (without the requirement of having an actual operator logged in, and without the use of command blocks).
I have very little Java experience, but am very experienced with JavaScript. Through the API I'm able to access the onEnable, onDisable, and onCommand methods, but unfortunately I am unable to produce my own BlockCommandSender object which is required for the onCommand function to work properly as-per the source code logic.
I haven't tested this out yet (if it's wrong, please forgive me as I have essentially no Java experience), but this addition to CBWrapper.java should do the trick:
@Override public Player newDummyPlayer(String string, Server server, World world, int x, int y, int z) { return new DummyPlayer(string, server, world, x, y, z); }
Cool, I can confirm that v1.7 is working!
Thank you.
@Steenbouwer
It ws meant to be the sign character. The new version by default uses absolute positions, but if you put a tilde () before the number it will be relative
Aha, -o stands for "offset" then.
The first character stripped, is that a bug or is it the sign character?
The new version still uses relative positions or is it now absolute?
Thanks.
@Steenbouwer
The syntax is (was) a bit strange. It treated the numbers like relative offsets and stripped off the first character. I wasn't very clear about that... I'm working on a new version that handles that better and lets you run commands in different worlds and from the console. If you really want it you can download it at http://nox.xenotoad.net:8080/job/CBWrapper/lastBuild/artifact/CBWrapper.jar but I haven't tested this build
What is the syntax of the positional parameter?
is not working in 1.6.1. !
..works well. And I've got it now working with some expand and contract commands, but would like to be able to use the positional parameter.
Thanks for making the plugin!
Just a suggestion: allow the commands to be run from the console as well. I had an error that I could've resolved by running a single command in the server, but instead I had to shut down the server, open the world in MC edit, and run a process on the world that took about 5 hrs, and did a bit more damage than I would've liked.
point is: allow the command to be run from the console, probably specifying the coords to run it from (or 0,0,0 if left out) and it would be even more useful
@jahfreak
I usually compile CBWrapper for Java 7. Looks like you're running Java 6. If you can, update your Java. If you can't, I can compile it for Java 6
Any Idea what I am doing incorrectly?
19:50:33] [Server thread/ERROR]: Could not load 'plugins/CBWrapper.jar' in folder 'plugins' org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: misson20000/plugins/cbwrapper/CBWrapper : Unsupported major.minor version 51.0 at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:137) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:313) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:236) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:350) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:312) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] Caused by: java.lang.UnsupportedClassVersionError: misson20000/plugins/cbwrapper/CBWrapper : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) [?:1.6.0_30] at java.lang.ClassLoader.defineClass(ClassLoader.java:643) [?:1.6.0_30] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [?:1.6.0_30] at java.net.URLClassLoader.defineClass(URLClassLoader.java:277) [?:1.6.0_30] at java.net.URLClassLoader.access$000(URLClassLoader.java:73) [?:1.6.0_30] at java.net.URLClassLoader$1.run(URLClassLoader.java:212) [?:1.6.0_30] at java.security.AccessController.doPrivileged(Native Method) [?:1.6.0_30] at java.net.URLClassLoader.findClass(URLClassLoader.java:205) [?:1.6.0_30] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:77) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:62) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at java.lang.ClassLoader.loadClass(ClassLoader.java:323) [?:1.6.0_30] at java.lang.ClassLoader.loadClass(ClassLoader.java:268) [?:1.6.0_30] at java.lang.Class.forName0(Native Method) [?:1.6.0_30] at java.lang.Class.forName(Class.java:270) [?:1.6.0_30] at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:40) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] ... 9 more
to show which Bukkit I am running;
[20:14:58 INFO]: This server is running CraftBukkit version git-Bukkit-1.7.2-R0.3-b3020jnks (MC: 1.7.2) (Implementing API version 1.7.2-R0.3)
This is with the most recent upload "CBWrapper 1.6.1 - CraftBook compatibility version for CB 1.7.2-R0.3 Mar 22, 2014"