Locking chests?

yeah my gradle isn’t setup, i’ve just been importing jars

Well you’ll definately need to set up a proper workspace so you don’t run into problems. There’s at least 10 dependencies you need.
Take a look at the documentation, https://docs.spongepowered.org/en/plugin/workspace/dependencies.html

Also, this is outdated but here’s the SDK build.gradle
https://github.com/SpongePowered/SpongeForge/blob/master/sdk/build.gradle

Edit: Here’s a minimal build.gradle

So I setup gradle, got that working. Updated the spongeforge on the server to the latest (901) and I still get the AbstractMethodError on getTraitValue - here is my code

@Listener
public void onPlayerInteract(InteractBlockEvent event) {
TileEntity block = event.getTargetBlock().getLocation().get().getTileEntity().get();
if(block instanceof Chest)
{
if(event.getCause().first(Player.class).isPresent()) {
Player player = event.getCause().first(Player.class).get();
String name = player.getName();
if(name.equalsIgnoreCase(“dayaffe”))
event.setCancelled(false);
else {
event.setCancelled(true);
}
BlockState a = event.getTargetBlock().getLocation().get().getBlock();
Direction d = (Direction) a.getTraitValue(EnumTraits.CHEST_FACING).get();
player.sendMessages(Texts.of(d.toString()));
}
}
}

To quote code and keep the whitespace, encase it in triple ```-marks, like this:

```Java
public void ThisIsAFunction(DoCoolStuffEvent event) {
    # And it even keeps indentation!
    # The "Java" directly after the things gives syntax highlighting :)
}

Just tested, I was not able to get an AbstractMethodError but I got a ClassCastException:
java.lang.ClassCastException: net.minecraft.util.EnumFacing cannot be cast to org.spongepowered.api.util.Direction

I realize that you can’t cast the internal EnumFacing to Direction, I’ll find a way to do this asap

Here you go:
Change

Direction d = (Direction) block.getTraitValue(EnumTraits.CHEST_FACING).get();

To

Enum<?> dirTrait = a.getTraitValue(EnumTraits.CHEST_FACING).get();
Direction d = Direction.valueOf(dirTrait.name());

I’m still getting the same Abstract Method Error. Here is a picture of the error and my code: if(block instanceof Chest) { if(event.getCause().first(Player.class).isPresent()) { Player player = event.getCause().first(Player.class).get(); String name = player.getName(); Enum<?> dirTrait = event.getTargetBlock().getLocation().get().getBlock().getTraitValue(EnumTraits.CHEST_FACING).get(); Direction d = Direction.valueOf(dirTrait.name()); Vector3i pos = d.toVector3d().toInt().add(event.getTargetBlock().getPosition()); BlockState signBlock = world.getBlock(pos); player.sendMessages(Texts.of(signBlock.getType())); } }

also that triple quote thing didnt work for me

Oh you’re running this in an obfuscated environment, I have only tested in development
so PropertyDirection.getValueClass() is abstract, but only in obf, I’ll fix this. (I thought you were saying getTraitValue was abstract)

Oh yeah my bad, I worded it wrong when I said it was getTraitValue();

Fixed it, look out for a new spongeforge build shortly Edit: build 911
https://github.com/SpongePowered/SpongeCommon/commit/109ced88a3d0947fde7df0fa8e77fad2d637dd67

Thanks! I got that working. But I ran into yet another error that has to do I assume with the world getting the block at said position. Here is my code and a photo of the error.


Nevermind, I was being an idiot. Problem solved. I had never set my world variable to anything. I just left it as a forward reference.

It would be great if you could get this chest locking plugin working. :smile:

1 Like