|
| 1 | +package github.aixoio.easyguard.commands; |
| 2 | + |
| 3 | +import com.sk89q.worldedit.math.BlockVector3; |
| 4 | +import com.sk89q.worldguard.LocalPlayer; |
| 5 | +import com.sk89q.worldguard.WorldGuard; |
| 6 | +import com.sk89q.worldguard.protection.ApplicableRegionSet; |
| 7 | +import com.sk89q.worldguard.protection.regions.ProtectedRegion; |
| 8 | +import github.aixoio.easyguard.EasyGuard; |
| 9 | +import org.bukkit.ChatColor; |
| 10 | +import org.bukkit.Location; |
| 11 | +import org.bukkit.command.Command; |
| 12 | +import org.bukkit.command.CommandExecutor; |
| 13 | +import org.bukkit.command.CommandSender; |
| 14 | +import org.bukkit.entity.Player; |
| 15 | + |
| 16 | +public class WhereClaimCommand implements CommandExecutor { |
| 17 | + |
| 18 | + @Override |
| 19 | + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { |
| 20 | + |
| 21 | + if (!sender.hasPermission("easyguard.where-claim")) { |
| 22 | + |
| 23 | + sender.sendMessage(ChatColor.DARK_RED + "You do not have the needed permission to use this command!"); |
| 24 | + return true; |
| 25 | + |
| 26 | + } |
| 27 | + |
| 28 | + if (!(sender instanceof Player)) { |
| 29 | + |
| 30 | + sender.sendMessage(ChatColor.RED + "You have to be a player to use this command!"); |
| 31 | + return true; |
| 32 | + |
| 33 | + } |
| 34 | + |
| 35 | + if (args.length < 1) return false; |
| 36 | + |
| 37 | + String location = args[0]; |
| 38 | + |
| 39 | + Player player = (Player) sender; |
| 40 | + |
| 41 | + LocalPlayer localPlayer = EasyGuard.getWorldGuard().wrapPlayer(player); |
| 42 | + |
| 43 | + try { |
| 44 | + |
| 45 | + Location targetLocaiton = EasyGuard.getPlugin().getConfig().getLocation(String.format("data.%s.%s.location", player.getDisplayName(), location)); |
| 46 | + |
| 47 | + if (targetLocaiton == null) { |
| 48 | + |
| 49 | + sender.sendMessage(ChatColor.RED + "Not found!"); |
| 50 | + return true; |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + BlockVector3 targetLocaitonAsVector = BlockVector3.at(targetLocaiton.getX(), targetLocaiton.getY(), targetLocaiton.getZ()); |
| 56 | + |
| 57 | + ApplicableRegionSet applicableRegionSet = WorldGuard |
| 58 | + .getInstance() |
| 59 | + .getPlatform() |
| 60 | + .getRegionContainer() |
| 61 | + .get(localPlayer.getWorld()) |
| 62 | + .getApplicableRegions( |
| 63 | + targetLocaitonAsVector |
| 64 | + ); |
| 65 | + |
| 66 | + for (ProtectedRegion region : applicableRegionSet) { |
| 67 | + |
| 68 | + sender.sendMessage(ChatColor.GREEN + "The location of " + region.getId() + " is X: " + region.getMaximumPoint().getX() + |
| 69 | + ", Y: " + region.getMaximumPoint().getY() + ", Z: " + region.getMaximumPoint().getZ()); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + } catch (Exception e) { |
| 74 | + |
| 75 | + sender.sendMessage(ChatColor.RED + "Not found!"); |
| 76 | + |
| 77 | + EasyGuard.getPlugin().getLogger().info(e.toString()); |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + return true; |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments