/freeze plugin

Discussion in 'Archived: Plugin Requests' started by Lupus, Jun 11, 2012.

  1. Offline

    Lupus

    Need help. Trying to make it so if you do /freeze [Player] that player will not be able to move, place blocks, and destroy blocks. But as I am new to this, I am unaware of how to do it. Help please? Below is what i have so far.
    package us.lupusbikkit.Freeze;
    Code:
    package us.lupusbikkit.Freeze;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Freeze extends JavaPlugin implements Listener {
    public void onDisable(){
       
            System.out.println(this + " is now disabled!");
    }
         @Override
             public void onEnable(){
       getServer().getPluginManager().registerEvents(this, this);
         }
         public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
       if(cmd.getName().equalsIgnoreCase("freeze"))
       if(args.length == 0){
       sender.sendMessage(ChatColor.RED + "Use: /freeze [player]" );
       return true;
       }
        
           getServer().getPlayer(args[0])
        
       return true;
         }
         public ArrayList<>
    }
    
     
  2. Offline

    np98765

    Sorry, I don't understand... What are you requesting? This is the "plugin requests" forum. Are you requesting a freeze plugin, but already have some code written up?

    If you're trying to write it and need help, I'd suggest the Bukkit Help forum or some other forum.
     
  3. Offline

    Lupus

    I am requesting someone complete it for me. I would also like the source code, for the future
     
  4. Offline

    JxAxVxAx

    Heres A Help For You By TheBcBroz From Youtube --> HERE

    The Video Teaches You How To Freeze People But As For What I Know , He Teached How To Freeze Everybody But Not A Specific Person , Not So Sure But Maybe You Can Know How To Freeze Specific People From There !
     
  5. Offline

    JazzaG

    I'll give you the concepts..you type the code:
    1. on command, get the player you want to freeze as an argument
    2. add them to a boolean valued hash map
    3. with an PlayerMoveEvent, cancel the event if their hashmap value is not true. It is important you compare the hashmap to not true, as opposed to false as if it can't be found, it would be null, not false.

    I'll post some code when I get back home, unless someone beats me to it :p

    ..or I'll do it here, but it may be wrong because eclipse isnt here to help me :p

    Code:
    public Map <Player, boolean> freeze =new HashMap<Player, boolean>();
     
    public boolean onCommand(....) {
        // add your argument checks here
        Player player = null;
        if(sender instanceof Player) {
            player = (Player) sender;
            if(freeze.get(player) != true) {
                // set freeze to true
                freeze.put(player, true);
                return true;
            } else { // set freeze to false
                freeze.put(player, false);
                return true;
            }
        }
        return false;
    }
     
    @EventHandler
    public void onMove(PlayerMoveEvent event) {
        Player player = event.getPlayer();
        if(freeze.get(player) == true)
        event.setCancelled(true); // I don't know the proper code to do this..you'll have to get this :p
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  6. Offline

    Tezlastorme

    Cancelling PlayerMoveEvent turns out horribly! :O
     
  7. Offline

    JazzaG

    you could move them back to their player.getLocation().getFrom().. or whatever that method is, instead of cancelling
     
  8. Offline

    Tezlastorme

    Code:
    public void onPlayerMove(PlayerMoveEvent event){
            if(!main.WhateverHashSet.contains(event.getPlayer())){
                Location from=event.getFrom();
                Location to=event.getTo();
                double x=Math.floor(from.getX());
                double z=Math.floor(from.getZ());
                if(Math.floor(to.getX())!=x||Math.floor(to.getZ())!=z){
                    x+=.5;
                    z+=.5;
                    event.getPlayer().teleport(new Location(from.getWorld(),x,from.getY(),z,from.getYaw(),from.getPitch()));
                }
            }
        }
    And just make a simple command to add a player to the HashSet :)
     

Share This Page