Advertisement
JackOUT

Untitled

Jan 8th, 2022
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package games.coob.core.block;
  2.  
  3. import lombok.AccessLevel;
  4. import lombok.Getter;
  5. import lombok.NoArgsConstructor;
  6. import org.bukkit.Location;
  7. import org.bukkit.block.Block;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.inventory.ClickType;
  10. import org.bukkit.inventory.ItemStack;
  11. import org.mineacademy.fo.Common;
  12. import org.mineacademy.fo.Messenger;
  13. import org.mineacademy.fo.menu.model.ItemCreator;
  14. import org.mineacademy.fo.menu.tool.Tool;
  15. import org.mineacademy.fo.remain.CompMaterial;
  16. import org.mineacademy.fo.visual.VisualTool;
  17.  
  18. import java.util.List;
  19.  
  20. /**
  21.  * An automatically registered tool you can use in the game
  22.  */
  23. @NoArgsConstructor(access = AccessLevel.PRIVATE)
  24. public class BlockTool extends VisualTool {
  25.  
  26.     /**
  27.      * The singular tool instance
  28.      */
  29.     @Getter
  30.     private static final Tool instance = new BlockTool();
  31.  
  32.     /**
  33.      * The actual item stored here for maximum performance
  34.      */
  35.     private ItemStack item;
  36.  
  37.     /**
  38.      * @see Tool#getItem()
  39.      */
  40.     @Override
  41.     public ItemStack getItem() {
  42.  
  43.         if (item == null)
  44.             item = ItemCreator.of(
  45.                             CompMaterial.NETHER_STAR,
  46.                             "Block Tool",
  47.                             "",
  48.                             "Click blocks to",
  49.                             "un/register them.")
  50.                     .build().make();
  51.  
  52.         return item;
  53.     }
  54.  
  55.  
  56.     /**
  57.      * Cancel the event so that we don't destroy blocks when selecting them
  58.      *
  59.      * @see Tool#autoCancel()
  60.      */
  61.     @Override
  62.     protected boolean autoCancel() {
  63.         return true;
  64.     }
  65.  
  66.     @Override
  67.     protected void handleBlockClick(final Player player, final ClickType click, final Block block) {
  68.         final BlockRegistry registry = BlockRegistry.getInstance();
  69.         final boolean isRegistered = registry.isRegistered(block);
  70.  
  71.         if (isRegistered)
  72.             registry.unregister(block);
  73.         else
  74.             registry.register(block);
  75.  
  76.         Messenger.success(player, "Successfully " + (isRegistered ? "&cun" : "&a") + "registered &7the block at " + Common.shortLocation(block.getLocation()) + ".");
  77.     }
  78.  
  79.     @Override
  80.     protected List<Location> getVisualizedPoints(final Player player) {
  81.         return BlockRegistry.getInstance().getLocations();
  82.     }
  83.  
  84.     @Override
  85.     protected String getBlockName(final Block block, final Player player) {
  86.         return "Registered Block";
  87.     }
  88.  
  89.     @Override
  90.     protected CompMaterial getBlockMask(final Block block, final Player player) {
  91.         return CompMaterial.IRON_BLOCK;
  92.     }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement