Compass arrow spinning in circles

Discussion in 'Plugin Development' started by jstN0body, Oct 20, 2020.

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

    jstN0body

    any idea what's going on here? The compass won't locate the structure and instead just spins in circles, when you open your inventory the compass returns to a normal state pointing towards your respawn location.

    Code:
    import org.bukkit.*;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.CompassMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        @Override
        public void onEnable() {
            new CustomCompass();
        }
    
        static class CustomCompass implements CommandExecutor {
    
            public CustomCompass() {
                Bukkit.getPluginCommand("compass").setExecutor(this);
            }
    
            @Override
            public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
                if (args.length == 2) {
                    Player player = Bukkit.getPlayer(args[0]);
                    World world = player.getWorld();
                    getCompass(player,
                            world.locateNearestStructure(player.getLocation(), StructureType.DESERT_PYRAMID, 1000, true),
                            args[1]);
                    return true;
                }
                return false;
            }
    
            public void getCompass(Player player, Location location, String name) {
                ItemStack compass = new ItemStack(Material.COMPASS);
                CompassMeta meta = (CompassMeta) compass.getItemMeta();
                meta.setLodestone(location);
                meta.setDisplayName(name);
                compass.setItemMeta(meta);
                player.getInventory().addItem(compass);
            }
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page