Minecart Elevator Help!

Discussion in 'Spigot Plugin Development' started by Anmol, Jun 18, 2016.

  1. Code (Text):
    package memes;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Minecart;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.vehicle.VehicleEnterEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class MC extends JavaPlugin implements Listener {
       
    MC plugin;
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
        public void onDisable() {
            plugin = null;
        }

        @EventHandler
          public void onMinecart(VehicleEnterEvent event) {
            if (((event.getVehicle() instanceof Minecart)) && ((event.getEntered() instanceof Player))) {
              Player p = (Player)event.getEntered();
              Location l = event.getVehicle().getLocation();
              Location loc = new Location(p.getWorld(), l.getBlockX(), l.getBlockY(), l.getBlockZ());
              Material m = loc.getBlock().getType();
              if ((m.equals(Material.FENCE_GATE)) || (m.equals(Material.SIGN_POST))) {
                event.setCancelled(true);
                if(!p.isInsideVehicle() && (!p.isSneaking())) {
                    return;
                }
               
                    if(event.getVehicle() instanceof Minecart && (p.isSneaking()) && (p.isBanned())) {    
                p.teleport(teleportSpot(loc, loc.getBlockY(), 254));        
                    }
              }
             
             
            }
            else {}
          }
         
          public Location teleportSpot(Location loc, int min, int max) {
            for (int k = min; k < max; k++) {
              Material m1 = new Location(loc.getWorld(), loc.getBlockX(), k, loc.getBlockZ()).getBlock().getType();
              Material m2 = new Location(loc.getWorld(), loc.getBlockX(), k + 1, loc.getBlockZ()).getBlock().getType();
              if ((m1.equals(Material.AIR)) && (m2.equals(Material.AIR))) {
                return new Location(loc.getWorld(), loc.getBlockX(), k, loc.getBlockZ());
              }
            }
            return new Location(loc.getWorld(), loc.getBlockX(),
              loc.getWorld().getHighestBlockYAt(loc.getBlockX(), loc.getBlockZ()), loc.getBlockZ());
          }
    }
    So I'm trying to let the player enter the elevator and then teleport. Should i make the object editable?
     
  2. What do you mean 'make the object editable'?
     
  3. So edible so like make it behave eatable? I want it to let them in while their is two fence gates inbetween like hcteams, then they get to choose.
     
  4. your sentence make 0 sense :D
     
  5. You want them to eat the object?
     
  6. no but when it is in the middle of the fence gates they cant get in it. So i want them tobe able to get in it while it is in the middle of the feence gates
     
  7. I tried it out on my server! It still doesn't do what it wants! Our plugins do u the same thing, we can't get into our minecarts without shiftingt.