Search in sources :

Example 1 with InstrumentProperty

use of org.spongepowered.api.data.property.block.InstrumentProperty in project SpongeCommon by SpongePowered.

the class InstrumentTestPlugin method onUseItem.

@Listener
public void onUseItem(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    if (!enabled || !player.get(Keys.IS_SNEAKING).get()) {
        return;
    }
    final BlockSnapshot snapshot = event.getTargetBlock();
    if (snapshot.getState().getType().equals(BlockTypes.NOTEBLOCK)) {
        final InstrumentProperty instrumentProperty = player.getWorld().getBlock(snapshot.getPosition().sub(0, 1, 0)).getProperty(InstrumentProperty.class).orElse(null);
        if (instrumentProperty != null) {
            final InstrumentType instrument = instrumentProperty.getValue();
            player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a note block with instrument: ", TextColors.GREEN, instrument.getName()));
        } else {
            player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a note block that strangely did not have any instrument type."));
        }
    } else {
        final InstrumentProperty instrumentProperty = snapshot.getProperty(InstrumentProperty.class).orElse(null);
        if (instrumentProperty != null) {
            final InstrumentType instrument = instrumentProperty.getValue();
            player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a block with instrument type: ", TextColors.GREEN, instrument.getName()));
        } else {
            player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a block which had no instrument type."));
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) InstrumentType(org.spongepowered.api.data.type.InstrumentType) InstrumentProperty(org.spongepowered.api.data.property.block.InstrumentProperty) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 InstrumentProperty (org.spongepowered.api.data.property.block.InstrumentProperty)1 InstrumentType (org.spongepowered.api.data.type.InstrumentType)1 Listener (org.spongepowered.api.event.Listener)1