Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.enkacang.smpproject.commands;
- import com.enkacang.smpproject.staticThingy.Format;
- import com.enkacang.smpproject.staticThingy.Prefixes;
- import org.bukkit.Bukkit;
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.TabExecutor;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.jetbrains.annotations.NotNull;
- import java.util.*;
- public class LandCommand implements TabExecutor{
- Map<String, Long> cooldowns = new HashMap<String, Long>();
- @Override
- public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
- if (sender instanceof Player)
- {
- Player player = ((Player) sender);
- if(args.length == 1)
- {
- if(args[0].equalsIgnoreCase("claim"))
- {
- player.performCommand("claim");
- }
- if(args[0].equalsIgnoreCase("kit"))
- {
- if(cooldowns.containsKey(player.getName()))
- {
- //player is inside hashmap
- if(cooldowns.get(player.getName()) > System.currentTimeMillis())
- {
- long timeLeft = (cooldowns.get(player.getName()) - System.currentTimeMillis()) / 1000;
- player.sendMessage(Format.colorCode(Prefixes.SERVER_PREFIX + " You can claim this kit again at " + Format.SecondsToHHMMSS((int)timeLeft)));
- return false;
- }
- }
- ItemStack goldenShovel = new ItemStack(Material.GOLDEN_SHOVEL);
- goldenShovel.getItemMeta().setDisplayName(Format.colorCode("Land Claim Shovel"));
- player.getInventory().addItem(goldenShovel);
- cooldowns.put(player.getName(), System.currentTimeMillis() + (15 * 1000));
- }
- }
- else
- {
- player.sendMessage(Format.colorCode(Prefixes.SERVER_PREFIX + " Please use golden shovel to start claiming! Get yours at /land kit"));
- }
- }
- return false;
- }
- @Override
- public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args){
- List<String> completion = null;
- completion = autocompleteLand(args[0]);
- return completion;
- }
- // Autocomplete Commands
- private List<String> autocompleteLand(String args)
- {
- List<String> completion = null;
- List<String> land_list = Arrays.asList(
- "claim",
- "claimlist",
- "abandonedclaim",
- "claimexplosion",
- "trust",
- "untrust",
- "acesstrust",
- "trustlist",
- "subdevide",
- "basicclaims",
- "removeallclaim",
- "unclaim",
- "kit" );
- String input = args.toLowerCase();
- for(String s: land_list)
- {
- if(s.startsWith(input))
- {
- if(completion == null)
- {
- completion = new ArrayList<>();
- }
- completion.add(s);
- }
- }
- if(completion != null)
- {
- Collections.sort(completion);
- }
- if(input.contains("trust"))
- {
- if(completion == null)
- {
- completion = new ArrayList<>();
- }
- completion.clear();
- for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
- completion.add(onlinePlayer.getName());
- }
- }
- return completion;
- }
- }
Add Comment
Please, Sign In to add comment