HomeJavaModsGunAPI
GunAPI

GunAPI is under MIT license, you can find sources there: https://github.com/wordnice/GunAPI

GunAPI provides simple, low-level oriented API for getting blocks and entities on cursor. Simple example is implemented in Library, and you can try it:


Example

Code (Java):

    @EventHandler
    public void onPlayerSneak (PlayerToggleSneakEvent event ) {
        Player p = event. getPlayer ( ) ;
        if (event. isSneaking ( ) && p. isOp ( ) && p. getGameMode ( ) == GameMode. CREATIVE ) {
            ItemStack item = p. getItemInHand ( ) ;
            if (item != null && item. getType ( ) == Material. PORK && item. getAmount ( ) == 33 ) {
                Location loc = p. getEyeLocation ( ) ; //!!! It is NOT getLocation()
                Vector direct = loc. getDirection ( ) ;
               
                Set <ShootedEntity > ents = new HashSet <ShootedEntity > ( ) ; //There will be cached all living entities from world
                GunAPI. cacheLivingEntities (ents, loc. getWorld ( ). getEntities ( ) ) ; //Load living entities
               
                double [ ] location = new double [ ] {loc. getX ( ), loc. getY ( ), loc. getZ ( ) } ; //double[3] location
                double [ ] vector = new double [ ] {direct. getX ( ), direct. getY ( ), direct. getZ ( ) } ; //double[3] direction
                GunAPI. maximize (vector, 0.1 ) ; //For better search (smaller = better)
               
                int radius = 50 ;
                int cycles = GunAPI. cyclesFromRadius (vector, radius ) ;
               
                Set <ShootedEntity > shoted = new HashSet <ShootedEntity > ( ) ; //There will be saved shoted entities
                GunAPI. getShootedEntities (shoted, ents, location, vector, cycles, true ) ;
               
                boolean shootSomeone = false ;
               
                Iterator <ShootedEntity > it = shoted. iterator ( ) ;
                LivingEntity first = null ;
                while (it. hasNext ( ) ) {
                    ShootedEntity se = it. next ( ) ;
                    LivingEntity le = (LivingEntity ) se. ent ;
                    if (le. equals (p ) ) {
                        continue ;
                    }
                    shootSomeone = true ;
                    if (first == null ) {
                        first = le ;
                    }
                    if (le instanceof Player ) {
                        Player sp = (Player ) le ;
                        p. sendMessage (ChatColor. YELLOW + "You shoot player " + sp. getName ( ) + ", headshot: " + se. wasHeadshot ) ;
                    } else {
                        p. sendMessage (ChatColor. YELLOW + "You shoot entity " + le. getType ( ). toString ( ) + ", headshot: " + se. wasHeadshot ) ;
                    }
                    if (se. wasHeadshot ) {
                        le. damage ( 10.01 ) ;
                    } else {
                        le. damage ( 3.01 ) ;
                    }
                }
                if ( !shootSomeone ) {
                    p. sendMessage (ChatColor. GREEN + "Uf, you didn't hurt anyone!" ) ;
                }
            }
        }
    }

Screenshots from example

[​IMG]
[​IMG]
[​IMG]
[​IMG]
[​IMG]
[​IMG]
[​IMG]
[​IMG]
[​IMG]
[​IMG]

Plugin details

Read from the plugin's own plugin.yml.

Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

GunAPI is a free Minecraft Java mod. Downloaded 600 times (via Spigot). Download it and open it directly in the game.

Explore more