Solved How do no fall damage for 20 seconds After player enter a special command

Discussion in 'Plugin Development' started by OrnomaS, Nov 24, 2017.

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

    OrnomaS

    Hello I want your help for my random teleport plugin because the plugin teleport player on x:x y:256 z:x so after player was teleport he die . I want know how to render player invincible for 20 seconds
     
    Last edited: Nov 24, 2017
  2. Offline

    CraftCreeper6

    @OrnomaS
    When you teleport them, add them to a list.
    Check for Entity Damage Event and check the Entity is a player
    If said player is in that list then use event#setcancelled();
    Then remove the player after the allotted 20 seconds.
     
  3. Offline

    OrnomaS

    you can give the code
     
  4. Offline

    timtower Administrator Administrator Moderator

    @OrnomaS Spoonfeedimg is not something that we do on bere.
     
  5. Offline

    OrnomaS

    je haven't idea how to do it because i'm bigineer
     
  6. Offline

    timtower Administrator Administrator Moderator

    @OrnomaS Do you know basic Java already?
     
  7. Offline

    OrnomaS

    yes variables condition
    board loop fonction arraylist
     
  8. Offline

    timtower Administrator Administrator Moderator

    @OrnomaS Make a list that contains players that should not receive damage.
    Add the players to the list in the command.
    Make a BukkitRunnable that removes them 20 seconds later.

    Start with that.
     
  9. Offline

    OrnomaS

    ok thanks i go to try it

    how to make BukkitRunnable

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 24, 2017
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    OrnomaS

    paquet fr.ornomas.plugin.commands;

    import java.util.ArrayList;
    import java.util.Random;

    import org.bukkit.Location;
    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.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.scheduler.BukkitRunnable;

    classe publique CommandRtp implémente CommandExecutor
    {

    @Passer outre
    public boolean onCommand (CommandSender expéditeur, Command cmd, String msg, String [] args)
    {
    if (instance de l'expéditeur du lecteur)
    {
    Random random = nouveau Random ();
    Joueur joueur = (joueur) expéditeur;
    Emplacement ploc = player.getLocation ();
    Emplacement rtp = new Emplacement (player.getWorld (), ploc.getX () + random.nextInt (5000), 256, ploc.getZ () - random.nextInt (5000), 0f, 0f);

    ArrayList list = new ArrayList ();
    list.add (expéditeur);

    player.sendMessage ("§bTeleportation aleatoire ...");
    player.teleport (rtp);
    }
    return false;
    }

    @Gestionnaire d'événements
    public void onCancelFallDamage (EntityDamageEvent e)
    {
    nouveau BukkitRunnable ()
    {

    @Passer outre
    run void publique ()
    {
    if (e.getEntity () instance de Player)
    {// Vérifie si l'entité qui subit les dégâts est un joueur
    if (e.getCause () == DamageCause.FALL)
    {// Si la cause du dommage est un dommage de chute
    e.setCancelled (true); // vous annulez l'événement.
    }
    }

    }
    } .runTaskLater (plugin, 400);
    }
    }

    est bon ?
     
  12. Offline

    timtower Administrator Administrator Moderator

    @OrnomaS 1. English please
    2. Your translator messes everything up.
    3. Please use this: [code]<actual code here>[/code]
     
  13. Offline

    Blares

    as tim said make a timer with bukkit runnable.

    Code:
    
    //bukkit runnable times etc.
    
    
    make a boolean. Make an Event Handler onDamage Event if the boolean is true e.setCancelled(true);
    after your bukkit time you will set the boolean to false;
     
  14. Offline

    timtower Administrator Administrator Moderator

    Boolean is a bad idea when you have multiple players on the server.
    A list with uuids is a better way.
     
  15. Offline

    OrnomaS

    I have find the best solution World.getHighestBlockYAt(rtp) so thats give it.

    Code:
    <
    package fr.ornomas.plugin.commands;
    
    
    import java.util.Random;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class CommandRtp implements CommandExecutor 
    {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args) 
        {
            if (sender instanceof Player)
            {
                Player player = (Player)sender;
                World World = player.getWorld();
                Random random = new Random();
                Location ploc = player.getLocation();
                int x = (int) (ploc.getX() + random.nextInt(5000));
                int z = (int) (ploc.getZ() - random.nextInt(5000));
                Location rtp = new Location(player.getWorld(), x, 50, z, 0f, 0f);
                Location rtp1 = new Location(player.getWorld(), rtp.getX(), World.getHighestBlockYAt(rtp), rtp.getZ(), 0f, 0f);
                player.sendMessage(ChatColor.DARK_GRAY +  "Teleportation aleatoire...");
                player.teleport(rtp1);
            }
           
            else 
            {
                System.out.println(ChatColor.DARK_GRAY + "Seul les joueurs peuvent executer cette commande");
            }
            return false;
        }
       
    }
    >
     
Thread Status:
Not open for further replies.

Share This Page