enkacang

Untitled

Nov 21st, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.00 KB | None | 0 0
  1. package com.enkacang.smpproject.commands;
  2.  
  3. import com.enkacang.smpproject.staticThingy.Format;
  4. import com.enkacang.smpproject.staticThingy.Prefixes;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Material;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.command.TabExecutor;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.inventory.ItemStack;
  12. import org.jetbrains.annotations.NotNull;
  13.  
  14. import java.util.*;
  15.  
  16. public class LandCommand implements  TabExecutor{
  17.  
  18.     Map<String, Long> cooldowns = new HashMap<String, Long>();
  19.  
  20.     @Override
  21.     public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
  22.  
  23.         if (sender instanceof Player)
  24.         {
  25.             Player player = ((Player) sender);
  26.             if(args.length == 1)
  27.             {
  28.                 if(args[0].equalsIgnoreCase("claim"))
  29.                 {
  30.                     player.performCommand("claim");
  31.                 }
  32.                 if(args[0].equalsIgnoreCase("kit"))
  33.                 {
  34.                     if(cooldowns.containsKey(player.getName()))
  35.                     {
  36.                         //player is inside hashmap
  37.                         if(cooldowns.get(player.getName()) > System.currentTimeMillis())
  38.                         {
  39.                             long timeLeft = (cooldowns.get(player.getName()) - System.currentTimeMillis()) / 1000;
  40.                             player.sendMessage(Format.colorCode(Prefixes.SERVER_PREFIX + " You can claim this kit again at " + Format.SecondsToHHMMSS((int)timeLeft)));
  41.                             return  false;
  42.                         }
  43.                     }
  44.  
  45.                     ItemStack goldenShovel = new ItemStack(Material.GOLDEN_SHOVEL);
  46.                     goldenShovel.getItemMeta().setDisplayName(Format.colorCode("Land Claim Shovel"));
  47.                     player.getInventory().addItem(goldenShovel);
  48.  
  49.                     cooldowns.put(player.getName(), System.currentTimeMillis() + (15 * 1000));
  50.                 }
  51.             }
  52.             else
  53.             {
  54.                 player.sendMessage(Format.colorCode(Prefixes.SERVER_PREFIX + " Please use golden shovel to start claiming! Get yours at /land kit"));
  55.             }
  56.         }
  57.  
  58.  
  59.         return false;
  60.     }
  61.  
  62.     @Override
  63.     public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args){
  64.  
  65.         List<String> completion = null;
  66.  
  67.         completion = autocompleteLand(args[0]);
  68.  
  69.         return completion;
  70.     }
  71.  
  72.     // Autocomplete Commands
  73.     private List<String> autocompleteLand(String args)
  74.     {
  75.         List<String> completion = null;
  76.         List<String> land_list = Arrays.asList(
  77.                 "claim",
  78.                 "claimlist",
  79.                 "abandonedclaim",
  80.                 "claimexplosion",
  81.                 "trust",
  82.                 "untrust",
  83.                 "acesstrust",
  84.                 "trustlist",
  85.                 "subdevide",
  86.                 "basicclaims",
  87.                 "removeallclaim",
  88.                 "unclaim",
  89.                 "kit" );
  90.         String input = args.toLowerCase();
  91.  
  92.  
  93.         for(String s: land_list)
  94.         {
  95.             if(s.startsWith(input))
  96.             {
  97.                 if(completion == null)
  98.                 {
  99.                     completion = new ArrayList<>();
  100.                 }
  101.  
  102.                 completion.add(s);
  103.  
  104.             }
  105.         }
  106.  
  107.         if(completion != null)
  108.         {
  109.             Collections.sort(completion);
  110.         }
  111.  
  112.         if(input.contains("trust"))
  113.         {
  114.             if(completion == null)
  115.             {
  116.                 completion = new ArrayList<>();
  117.             }
  118.  
  119.             completion.clear();
  120.  
  121.             for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
  122.                 completion.add(onlinePlayer.getName());
  123.             }
  124.  
  125.         }
  126.  
  127.         return  completion;
  128.     }
  129. }
  130.  
Add Comment
Please, Sign In to add comment