Hey,
today I tried to place some blocks with sponge.
Example:
Location location = new Location(world, block.getX(), block.getY(), block.getZ());
location.setBlock(Sponge.getRegistry().getType(BlockType.class, "minecraft:air").get().getDefaultState());
this code sets a new minecraft:air block in at x,y,z cords → works fine.
An unwanted effect is, that the root / cause of this action is a player. How can I change this? I don’t want to fire following method / event when I do this:
public void onBlockBreak(ChangeBlockEvent event, @Root Player player)
Edit: I don’t know, if it’s important, but setBlock() gets called when a player executes a command. Is the player the cause because of this?
That’s probably why. Sponge makes the assumption that because a player ran a command then actions that occur during the command execution is caused due to the player running the command (which makes sense right?).
Don’t know why, but it seems like there is a little problem:
[16:34:31] [Normalize User Plot (Hitzk0pf)/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.IllegalArgumentException: PluginContainer must be at the ROOT of a cause!
[16:34:31] [Normalize User Plot (Hitzk0pf)/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at com.google.common.base.Preconditions.checkArgument(Preconditions.java:125)
[16:34:31] [Normalize User Plot (Hitzk0pf)/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraft.world.World.setBlock(World.java:1706)
[16:34:31] [Normalize User Plot (Hitzk0pf)/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at me.Hitzk0pf.CaveCore.UserPlotRollbackTool.(UserPlotRollbackTool.java:69)
[16:34:31] [Normalize User Plot (Hitzk0pf)/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at me.Hitzk0pf.CaveCore.commands.Cave.BlockInfo$1.run(BlockInfo.java:87)
[16:34:31] [Normalize User Plot (Hitzk0pf)/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at java.lang.Thread.run(Thread.java:745)
Line: location.getExtent().setBlock(x, y, z, Sponge.getRegistry().getType(BlockType.class, "minecraft:air").get().getDefaultState(), false, Cause.of(Sponge.getServer().getConsole()));
It doesn’t work like that. PluginContainer is not a service, it’s the object that houses your plugin.
The easiest way to get it is to put @Inject private PluginContainer container; in your main plugin class, then pass that instance around.