Solved Place carpet when player hits ground

Discussion in 'Plugin Development' started by notdew, Oct 31, 2021.

  1. Offline

    notdew

    I have been trying to figure out how to make it so when a player hits the ground after jumping they get carpet underneath. This is a minecraft football plugin and when you hit 3 times it counts as a tackle but its where you land. I need help placing the block where they land.
    Code:
    package me.notdew.com.roboref;
    
    import me.notdew.com.roboref.Events.ArrowHit;
    import me.notdew.com.roboref.Events.PlayerHit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.logging.Logger;
    
    public final class RoboRef extends JavaPlugin {
        public Plugin plugin = this;
        private static final Logger log = Logger.getLogger("Minecraft");
        private static List<Player> hitlist = new ArrayList<>();
        private static List<Player> OneHitList = new ArrayList<Player>();
        private static List<Player> TwoHitList = new ArrayList<Player>();
    
        public static List<Player> getHitList() {
            return hitlist;
        }
    
        public static List<Player> getOneHitList() {
            return OneHitList;
        }
        public static List<Player> getTwoHitList() {
            return TwoHitList;
        }
    
    
    
    
    
        @Override
        public void onEnable() {
            // Plugin startup logic
    
            log.severe(String.format("RoboRef is enabling!"));
            getServer().getPluginManager().registerEvents(new ArrowHit(), this);
            getServer().getPluginManager().registerEvents(new PlayerHit(), this);
    
        }
    
        @Override
        public void onDisable() {
            // Plugin shutdown logic
        }
    }
    
    Code:
    package me.notdew.com.roboref.Events;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import me.notdew.com.roboref.RoboRef;
    
    import java.util.ArrayList;
    import java.util.List;
    
    
    public class ArrowHit implements Listener {
        private RoboRef roboref;
    
        @EventHandler
        public void onProjectileHit(ProjectileHitEvent e){
            if (e.getHitEntity() instanceof Player){
                Player damageTaker = (Player)e.getHitEntity();
                RoboRef.getHitList().add(damageTaker);
            }
            else {
            }
    
    
    
        }
    
    }
    
    Code:
    package me.notdew.com.roboref.Events;
    
    import me.notdew.com.roboref.RoboRef;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    
    public class PlayerHit implements Listener {
        private RoboRef plugin;
    
    
        @EventHandler
        public void onPlayerHit(EntityDamageByEntityEvent e){
    
            if ((e.getDamager() instanceof Player && e.getEntity() instanceof Player)){
    
                Player player = (Player) e.getEntity();
    
    
    
                if (RoboRef.getHitList().contains(player)){
                    RoboRef.getOneHitList().add(player);
                    RoboRef.getHitList().remove(player);
                    return;
                }
                if(RoboRef.getOneHitList().contains(player)) {
                    RoboRef.getOneHitList().remove(player);
                    RoboRef.getTwoHitList().add(player);
                    return;
    
                }
                if(RoboRef.getTwoHitList().contains(player)) {
                    RoboRef.getTwoHitList().remove(player);
                    World world = player.getWorld();
                    Player p = player;
    
                    Location l = player.getLocation();
                    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                        public void run(){
                            if(!p.isFlying() && !p.isOnGround() && p.getVelocity().getY() < 0){
                                double x, y, z;
                                Location loc = player.getLocation();
                                //check if persons y block - 1 is not null, if it is not, place a block beneath them.
                                x = loc.getX();
                                y = loc.getY();
                                z = loc.getZ();
                                loc = new Location(world, x, y, z);
    
                                loc.getBlock().setType(Material.CARPET);
                            }
                        }
                    }, 5L, 5L);
    
    
                }
    
    
    
    
    
            }
    
    
    
    
    
        }
    }
    
    roboref is the main class. Thanks!
     
  2. Offline

    Kars

  3. Offline

    notdew

    Yes but how do I see when they land?
     
  4. Offline

    Kars

    A repeating task every tick and this
    PHP:
    if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR) {
        
    //do something
    }
     
  5. Offline

    notdew

    Thanks so much I’ll try this soon
     
  6. Offline

    KarimAKL

    @Kars @notdew I believe Material#isAir() would be better because it checks for AIR, CAVE_AIR, and VOID_AIR.
     
    Kars likes this.

Share This Page