Freeze a player on an event?

Discussion in 'Plugin Development' started by alf980103, May 1, 2013.

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

    alf980103

    Hi guys, i have this code, and i have a question, how to freeze a player on an event?
    for example, when this happen:


    Code:
    @EventHandler
      public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
      {
        Entity plr = event.getPlayer();
        Entity target = event.getRightClicked();
        if (((plr instanceof Player)) &&
          (((Player)plr).hasPermission("pm.policia")))
            if (((Player)plr).getInventory().contains(Material.STICK, 1))
                     
                if ((target instanceof Player)) {   
                  String nombre = ((Player)target).getDisplayName();
                  String policia = ((Player)plr).getDisplayName();
                    ((Player)target).sendMessage("§cHas sido arrestado por "  + policia + ", puedes resistirte usando el comando §a/resistirme.");
                    ((Player)plr).sendMessage("§cHas arrestado a:§e " + nombre);
                 
                  }
                }
    I want to freeze the target player (event.getRightClicked();
    how can i do this?



    My code:
    Code:
    package PM;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Server;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class PM extends JavaPlugin
      implements Listener
    {
      public void onDisable()
      {
      }
     
      public void onEnable()
      {
        PluginManager pm = getServer().getPluginManager();
        pm.registerEvents(this, this);
     
      }
     
      @EventHandler
      public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
      {
        Entity plr = event.getPlayer();
        Entity target = event.getRightClicked();
        if (((plr instanceof Player)) &&
          (((Player)plr).hasPermission("pm.policia")))
            if (((Player)plr).getInventory().contains(Material.STICK, 1))
                     
                if ((target instanceof Player)) {   
                  String nombre = ((Player)target).getDisplayName();
                  String policia = ((Player)plr).getDisplayName();
                    ((Player)target).sendMessage("§cHas sido arrestado por "  + policia + ", puedes resistirte usando el comando §a/resistirme.");
                    ((Player)plr).sendMessage("§cHas arrestado a:§e " + nombre);
                 
                  }
                }
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
      {
        if ((sender instanceof Player)) {
          if (cmd.getName().equalsIgnoreCase("polimaniaca")) {
            if (args.length == 1) {
              if (args[0].equalsIgnoreCase("lista")) {
                sender.sendMessage("§a§lPolicias en linea:");
                for (Player players : getServer().getOnlinePlayers()) {
                  if (players.hasPermission("pm.policia"))
                    sender.sendMessage(ChatColor.YELLOW + "- " + players.getDisplayName() + "");
                }
              }
            }
          }
     
        }
        return false;
      }
    }
    Regards
     
  2. Offline

    Chinwe

    If it's a player, you can use PlayerMoveEvent to iterate through a Map that holds the player name and the Location they will be frozen at, and teleport them to that position every time they move.
    If it's a mob/another entity, use a scheduler to do the same thing: teleport every few ticks to their location from the Map.
     
  3. Offline

    alf980103

    Where can i place that?

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    chasechocolate

    Create a new PlayerMoveEvent EventHandler method.
     
  5. Offline

    ZeusAllMighty11

    You can freeze a player with a potioneffect! ;)
     
  6. Offline

    Chinwe

    Ah yes of course, but then players can teleport away using /spawn /kill /home etc. and be frozen there instead :<
     
  7. Offline

    fromgate

    Hmm which effect will do it?
     
  8. Offline

    techboy291

  9. Offline

    Chinwe

  10. Offline

    ZeusAllMighty11

    I did speed with that max value of the 'Integer' class, which reverses the speed and actually makes it so the person can't move.
     
    fromgate likes this.
  11. Offline

    alf980103

    Have done the freeze, i used this:

    PHP:
    @EventHandler(priority EventPriority.HIGHEST)
    public 
    void onPlayerInteractEntity(PlayerInteractEntityEvent event )
    {
    final 
    Player player event.getPlayer();
    Entity plr event.getPlayer();
    Entity target event.getRightClicked();
    if (((
    plr instanceof Player)) &&
    (((
    Player)plr).hasPermission("pm.policia")))
    if (((
    Player)plr).getItemInHand().getType()== Material.STICK
    && (player.isSneaking()))
    if ((
    target instanceof Player)) {
    ((
    Playertarget).addPotionEffect(new PotionEffect(PotionEffectType.SLOW500030000));
    Thanks everybody for the support
     
    fromgate likes this.
Thread Status:
Not open for further replies.

Share This Page