Solved Jump and Run Plugin

Discussion in 'Plugin Development' started by Zettos, Feb 17, 2021.

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

    Zettos

    Hey, im trying to code an Jump and Run Plugin. The Idea is that you go on a stone Plate to start the game. After that you will be teleported 20 block above and a block generates 3 blocks away from you. If you jump on it than the old one will be deleted and a new one will be created. I tried a bit but it doesnt work. Hope you can help.


    Main:
    Code:
    public class Main extends JavaPlugin{
       
       
    
        @Override
        public void onEnable() {
            register();
        }
        @Override
        public void onDisable() {
           
        }
        public void register() {
            PluginManager pm = Bukkit.getPluginManager();
            pm.registerEvents(new InteractWIthPlateEvent(), this);
        }
    }
    Methode:
    Code:
    public class JumpAndRun {
    
        public static Map<UUID, JumpAndRun> jumpAndRuns = new HashMap<UUID, JumpAndRun>();
        private Player player; //soon
        private Location spawnloc;
        private Location currentloc;
        private Location nextloc;
        private Random random;
        private int blockCounter; //soon
       
        private boolean isBlock(Location location) {
            return (location.getBlock().getType() != Material.AIR);
        }
       
        public Location getCurrentLocation() {
            return this.currentloc;
        }
        public Location getNextLocation() {
            return this.nextloc;
        }
       
        public JumpAndRun(Player player) {
            this.player = player;
            this.spawnloc = player.getLocation();
        }
        public void start(Player player) {
            Location newloc;
           
            double x = this.random.nextInt(3);
            double y = this.random.nextInt(20);
            double z = this.random.nextInt(3);
           
            try {
                do {
                    x = this.random.nextInt(3);
                    y = this.random.nextInt(20);
                    z = this.random.nextInt(3);
                   
                    newloc = new Location(this.spawnloc.getWorld(), this.spawnloc.getX() +x, this.spawnloc.getY() +y, this.spawnloc.getZ() +z);
                } while (isBlock(newloc));
            } catch (Exception e) {
                newloc = new Location(this.spawnloc.getWorld(), this.spawnloc.getX() +x, this.spawnloc.getY() +y, this.spawnloc.getZ() +z);
            }
           
            addBlock(newloc);
            this.currentloc = newloc;
            player.teleport(this.currentloc.add(0.0D,1D,0.0D));
            this.currentloc.subtract(0.0D, 1.0D, 0.0D);
           
        }
           
           
            private void addBlock(Location location) {
                location.subtract(0.0D, 1.0D, 0.0D).getBlock().setType(Material.STAINED_CLAY);
               
           
        }
            public void stop(Player player) {
                this.currentloc.getBlock().setType(Material.AIR);
                this.nextloc.getBlock().setType(Material.AIR);
                jumpAndRuns.remove(player.getUniqueId());
            }
       
    }
    Event:
    public class InteractWIthPlateEvent implements Listener{

    //Prefix
    private static String prefix = Cache.getPrefix();


    @EventHandler
    public void onIteract(PlayerInteractEvent event) {
    Player player = (Player) event.getPlayer();
    if(event.getAction().equals(Action.PHYSICAL) && event.getClickedBlock().getType().equals(Material.STONE_PLATE)) {
    if(player.getWorld().getName().equalsIgnoreCase("world")) {
    player.sendMessage("Debug");
    JumpAndRun jumpAndRun = new JumpAndRun(player);
    jumpAndRun.start(player);
    JumpAndRun.jumpAndRuns.put(player.getUniqueId(), jumpAndRun);
    player.sendMessage(prefix+"§aJump and Run Gestartet!");
    }
    }
    }
    @EventHandler
    public void onMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();;
    }
    }

    Exeption:
    Exeption.PNG
     
Thread Status:
Not open for further replies.

Share This Page