Ghaz-ranka

Untitled

May 19th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package com.esinia.server.events;
  2.  
  3. import org.spongepowered.api.block.BlockTypes;
  4. import org.spongepowered.api.data.type.HandTypes;
  5. import org.spongepowered.api.entity.living.player.Player;
  6. import org.spongepowered.api.event.Listener;
  7. import org.spongepowered.api.event.block.InteractBlockEvent;
  8. import org.spongepowered.api.text.Text;
  9. //Class name and main method
  10. public class EventRightClick {
  11. //listener for following event
  12. @Listener
  13. //event for interacting with a right click event using main hand
  14. public void onRightClickMainHand(InteractBlockEvent.Secondary.MainHand event){
  15. //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
  16. Player player = event.getCause().last(Player.class).get();
  17. //if the variable player is not null
  18. if (player != null){
  19. //checks if the block that was interacted with during the event is the block type crafting table
  20. if (event.getTargetBlock().getState().getType() == BlockTypes.CRAFTING_TABLE){
  21.  
  22. }
  23. //Same as above only it checks if it is an block type anvil
  24. if (event.getTargetBlock().getState().getType() == BlockTypes.ANVIL){
  25. //checking an item is not present in the players main hand
  26. if (!player.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
  27. //canceling the event
  28. event.setCancelled(true);
  29. //sending the player a message
  30. player.sendMessage(Text.of("You need a hammer to use an anvil."));
  31. }
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment