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."));
}
}
}
Aggregations