Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.esinia.server.events;
- import org.spongepowered.api.block.BlockTypes;
- import org.spongepowered.api.data.type.HandTypes;
- import org.spongepowered.api.entity.living.player.Player;
- import org.spongepowered.api.event.Listener;
- import org.spongepowered.api.event.block.InteractBlockEvent;
- import org.spongepowered.api.text.Text;
- //Class name and main method
- public class EventRightClick {
- //listener for following event
- @Listener
- //event for interacting with a right click event using main hand
- public void onRightClickMainHand(InteractBlockEvent.Secondary.MainHand event){
- //player variable with title player is set to the last object in the event cause which is Player.class and then getting it if it exists
- Player player = event.getCause().last(Player.class).get();
- //if the variable player is not null
- if (player != null){
- //checks if the block that was interacted with during the event is the block type crafting table
- if (event.getTargetBlock().getState().getType() == BlockTypes.CRAFTING_TABLE){
- }
- //Same as above only it checks if it is an block type anvil
- if (event.getTargetBlock().getState().getType() == BlockTypes.ANVIL){
- //checking an item is not present in the players main hand
- if (!player.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
- //canceling the event
- event.setCancelled(true);
- //sending the player a message
- player.sendMessage(Text.of("You need a hammer to use an anvil."));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment