Freeze Command Not Working

Discussion in 'Plugin Development' started by MCJoshua345, Mar 8, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    MCJoshua345

    Hey guys! I've been workin' on this command, but when I use it, it just returns the command back to me! It just says "/freeze". (This is my return false way of saying you failed lol.) Well this is the code, I have the class and command in the Main class, and the command in the plugin.yml, but alas, it doesn't work. Here's the code!
    Code:
    package com.infinity.lobby.commands;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import com.infinity.lobby.main.Main;
    
    import org.bukkit.ChatColor;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    
    public class FreezeCommand implements CommandExecutor, Listener
    {
      public final HashMap<Player, ArrayList<Block>> hm = new HashMap<Player, ArrayList<Block>>();
       
      Main plugin;
      public FreezeCommand(Main instance)
     
      {
         
        this.plugin = instance;
       
      }
     
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
      {
        if(!(sender instanceof Player)){
            sender.sendMessage(ChatColor.DARK_RED + "You must be a player to use this command.");
            return true;
        }
        Player p = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("freeze")){
            if(p.hasPermission("lobby.fun")){
                if(args.length == 0){
                    if(hm.containsKey(p)){
                        hm.remove(p);
                        p.sendMessage(ChatColor.GOLD + "You unfroze yourself.");
                    }else {
                        hm.put((Player) p, null);
                        p.sendMessage(ChatColor.GOLD + "You froze yourself!");
                    }
                }else if (args.length == 1){
                    if(p.getServer().getPlayer(args[0]) != null) {
                        Player target = p.getServer().getPlayer(args[0]);
                        if(!hm.containsKey(target)){
                            String tname = target.getName();
                            String sname = p.getName();
                            hm.put(target, null);
                            p.sendMessage(ChatColor.GOLD + "You froze " + ChatColor.AQUA + ChatColor.BOLD + tname + ChatColor.RESET + ChatColor.GOLD + ".");
                            target.sendMessage(ChatColor.GOLD + "You were frozen by " + ChatColor.AQUA + ChatColor.BOLD + sname + ChatColor.RESET + ChatColor.GOLD + ".");
                        }else if(hm.containsKey(target)){
                            String tname = target.getName();
                            String sname = p.getName();
                            hm.remove(target);
                            p.sendMessage(ChatColor.GOLD + "You unfroze " + ChatColor.AQUA + ChatColor.BOLD + tname + ChatColor.RESET + ChatColor.GOLD + ".");
                            target.sendMessage(ChatColor.GOLD + "You were unfrozen by " + ChatColor.AQUA + ChatColor.BOLD + sname + ChatColor.RESET + ChatColor.GOLD + ".");
                        }
                    }else {
                        sender.sendMessage(ChatColor.DARK_RED + args[0] + " was not found.");
                    }
                }
            }else if(!(p.hasPermission("lobby.fun"))){
                p.sendMessage(ChatColor.RED + "You must be rank Minor God or higher to use this command.");
            }
        }
       
        return false; 
      }
    
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent e){
        if(hm.containsKey(e.getPlayer())){
            e.getPlayer().teleport(e.getPlayer());
        }
    }
     
    }
    Thanks for the help! Byeeeeeeeeeeeeeeeeeeeeeeee!
     
  2. because you return false; at the end (return false = show usage of command, return true = show nothing)

    wouldnt be just a List<Player> better and cancel the PlayerMoveEvent?

    Aaaaaaand you can't teleport to a block which doesn't exist (you stored player, null in the hashmap)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
Thread Status:
Not open for further replies.

Share This Page