Gliding is Glichy / Derpy [Glide Plugin]

Discussion in 'Plugin Development' started by sickray34s, Nov 5, 2018.

  1. OK So My Problem Is That Every Time I Glide; My Code Seems To Glitch Where as I Start To Walk Mid Air. I Tried To Fix The Problem But I Cannot Seem To Find A Way Around The Bug.
    I Get No Error Messages At All. Im Wondering if It Has Something To Do With My Velocity Or Server Ticks.

    Here Is A Example Of My Source:
    Code:
    package com.sickray.FlyBy;
    
    import java.util.HashMap;
    import java.util.Map;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerVelocityEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    
    public class FlyByMain extends JavaPlugin implements Listener, CommandExecutor {
        private Map<String, Boolean> canFly = new HashMap<String, Boolean>();
    
        @Override
        public void onEnable() {
            Logger l = Bukkit.getLogger();
            l.info("[" + ChatColor.GOLD + "FlyBy" + ChatColor.RESET + "] Has Been " + ChatColor.GREEN + "Enabled");
    
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            Bukkit.getPluginCommand("FlyBy").setExecutor(this);
        }
    
        @Override
        public void onDisable() {
    
        }
    
        public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
            if (command.getName().equalsIgnoreCase("FlyBy")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    if (args[0].toString() == null) {
                        player.sendMessage(ChatColor.GOLD + "+-------------Help---------------+");
                        player.sendMessage(ChatColor.GREEN + " /FlyBy {Enable / Disable}");
                        player.sendMessage(ChatColor.GREEN + " Enables or Disables Flying");
                        player.sendMessage(ChatColor.GREEN + " /FlyBy info {Page Number}");
                        player.sendMessage(ChatColor.GREEN + " Displays info Page");
                        player.sendMessage(ChatColor.GREEN + " /FlyBy Help");
                        player.sendMessage(ChatColor.GREEN + " Displays Help Page");
                        return true;
    
                    } else if (args[0].equalsIgnoreCase("Enable")) {
                        canFly.put(player.getName(), true);
    
                        return true;
                    } else if (args[0].equalsIgnoreCase("Disable")) {
                        canFly.put(player.getName(), false);
    
                        return true;
                    } else if (args[0].equalsIgnoreCase("info")) {
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                        player.sendMessage(ChatColor.BLUE + "|        " + ChatColor.RED + "Author: sickray34s"
                                + ChatColor.BLUE + "                  |");
                        player.sendMessage(ChatColor.BLUE + "|              " + ChatColor.GOLD + "V1.02" + ChatColor.BLUE
                                + "                          |");
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                        player.sendMessage(ChatColor.BLUE + "|           Page 1 / 3                 |");
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                        return true;
                    }
                    if (args[1].equalsIgnoreCase("2")) {
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                        player.sendMessage(ChatColor.BLUE + "|                                |");
                        player.sendMessage(ChatColor.BLUE + "|                                |");
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                        player.sendMessage(ChatColor.BLUE + "|           Page 2 / 3           |");
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                    }
                    if (args[1].equalsIgnoreCase("3")) {
    
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                        player.sendMessage(ChatColor.BLUE + "|                                |");
                        player.sendMessage(ChatColor.BLUE + "|                                |");
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                        player.sendMessage(ChatColor.BLUE + "|           Page 3 / 3           |");
                        player.sendMessage(ChatColor.BLUE + "+--------------------------------+");
                    } else if (args[0].equalsIgnoreCase("Help")) {
                        player.sendMessage(ChatColor.GOLD + "+-------------Help---------------+");
                        player.sendMessage(ChatColor.GREEN + " /FlyBy {Enable / Disable}");
                        player.sendMessage(ChatColor.GREEN + " Enables or Disables Flying");
                        player.sendMessage(ChatColor.GREEN + " /FlyBy info {Page Number}");
                        player.sendMessage(ChatColor.GREEN + " Displays info Page");
                        player.sendMessage(ChatColor.GREEN + " /FlyBy Help");
                        player.sendMessage(ChatColor.GREEN + " Displays Help Page");
                    }
                } else {
                    Bukkit.getLogger().info("[" + ChatColor.GOLD + "FlyBy" + ChatColor.RESET + "] " + ChatColor.RED
                            + "ERROR: MUST BE PLAYER");
    
                    return true;
    
                }
                return false;
    
            }
            return false;
        }
    
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
    
            Player player = event.getPlayer();
            if (canFly.containsKey(player.getName())) {
                if (canFly.containsValue(true)) {
                    if (!player.isOnGround()) {
                        if (!player.isSwimming()) {
                            if (!player.isGliding()) {
                                player.setGliding(true);
                            }
                            Vector v = player.getVelocity().clone();
                            Vector d = player.getLocation().getDirection().clone().multiply(0.05 + 0.10);
                            Vector hor = new Vector(d.getX(), 0, d.getZ());
                            Vector horV = new Vector(v.getX(), 0, v.getZ());
                            Vector vert = new Vector(0, d.getY(), 0);
                            Vector use = hor.add(vert);
                            if (hor.clone().add(horV).lengthSquared() >= 1) {
                                use = vert;
                            }
                            player.setVelocity(v.add(use));
                        }
                    }
                }
            }
        }
    
        @EventHandler
        public void onVelEvent(PlayerVelocityEvent event) {
            Player player = event.getPlayer();
            if (canFly.containsKey(player.getName())) {
                if (canFly.containsValue(true)) {
                    if (!player.isOnGround()) {
                        if (!player.isGliding()) {
                            if (!player.isSwimming())
                                player.setGliding(true);
    
                        }
                    }
                }
            }
    
        }
    
    }
    
    Also A Short Video Showing My Problem:



    If Anyone Could Help Solve This Issue That Would Be Great -sickray34s
     
    Last edited: Nov 5, 2018
  2. Offline

    KarimAKL

    @sickray34s Maybe it could have something to do with this?
    Code:
    player.setGliding(true);
     
  3. I Know That It May Already Might Be That But I Think it Might Be Something To Do With My Velocity
    Code:
    player.setVelocity(v.add(use));
     
  4. Offline

    KarimAKL

    @sickray34s Have you tried commenting some of the stuff out and see how it works?
     
  5. Yeah It Seems to work when I'm wearing the Elytra But Dose Not Work When To Well Without it
    is: .setGliding deprecated somehow I never used it But Im Currently on 1.13.2
     
  6. Offline

    The_Spaceman

    that like should probably be '(canFly.get(player.getName()) == true)', when another player can and another can't both are able to.
     
  7. That Would of been the case but a String and Boolean Are Incompatible Types, That's Why It Checks For The Player First;
    Code:
    if (canFly.containsKey(player.getName())) {
                if (canFly.containsValue(true)) {
    It May Be The Case That both players Could Use it's Regardless because of a "true" value but it seems your fix wont work. Ill Address That As A side Issue.
     
  8. Offline

    The_Spaceman

    I did not say it fixes your problem, just said it seems like a bug where you could ran into later...
     

Share This Page