Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. package com.aidan.coordinateheads;
  2.  
  3. import org.bukkit.ChatColor;
  4. import org.bukkit.Material;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandExecutor;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.block.Action;
  12. import org.bukkit.event.player.PlayerInteractEvent;
  13.  
  14. public class CoordinateListener implements Listener, CommandExecutor{
  15.     int[] blockCoords = new int [3];
  16.     @EventHandler
  17.     public void listener(PlayerInteractEvent e) {
  18.         onPlayerInteract(e, blockCoords);
  19.     }
  20.     public void onPlayerInteract(PlayerInteractEvent event, int[] chosenBlock) {
  21.         if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
  22.             int x = event.getClickedBlock().getX();
  23.             int y = event.getClickedBlock().getY();
  24.             int z = event.getClickedBlock().getZ();
  25.             if (chosenBlock[0] == x && chosenBlock[1] == y && chosenBlock[2] == z) {
  26.                 event.getPlayer().sendMessage("you found the block");
  27.             } else {
  28.                 event.getPlayer().sendMessage("rip " + x + ", " + y + ", " + z);
  29.                 event.getPlayer().sendMessage("you gotta find " + chosenBlock[0] + ", " + chosenBlock[1] + ", " + chosenBlock[2]);
  30.             }
  31.         }
  32.     }
  33.    
  34.      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  35.             if (sender instanceof Player) {
  36.                 if (args[0].length() == 0 || args[1].length() == 0 || args[2].length() == 0) {
  37.                     sender.sendMessage(ChatColor.RED + "Invalid Arguments!");
  38.                    
  39.                 } else {
  40.                     int x1 = Integer.parseInt(args[0]);
  41.                     int y1 = Integer.parseInt(args[1]);
  42.                     int z1 = Integer.parseInt(args[2]);
  43.                     //sender.sendMessage(" Blockz" + x1 + y1 + z1);
  44.                     blockCoords[0] = x1;
  45.                     blockCoords[1] = y1;
  46.                     blockCoords[2] = z1;
  47.                     //sender.sendMessage("Chosen Blockz" + chosenBlock[0] + chosenBlock[1] + chosenBlock[2]);
  48.                     sender.sendMessage(ChatColor.BOLD + "Selected block at " + x1 + ", " + y1 + ", " + z1);
  49.                 }
  50.             }
  51.             return true;
  52.         }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement