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
@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]](//proxy.spigotmc.org/d48dbda13269f6de6121da4d52aa8589b0c7ee1c?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fheadshot.png)
![[IMG]](//proxy.spigotmc.org/c9a213b4b8648765e7975aea0e7c1b812d8931cb?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fbodyshot.png)
![[IMG]](//proxy.spigotmc.org/abf6f1dde4fbf656897e795b8a339556c9a7fc30?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fnoshot.png)
![[IMG]](//proxy.spigotmc.org/f7fa9a6d2e7592244b9e648f3c9f88d03662b22c?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fmulti_headshot.png)
![[IMG]](//proxy.spigotmc.org/93b337fbb341922442ffabeacd90490a215cc484?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Flong_headshot.png)
![[IMG]](//proxy.spigotmc.org/b30d49dbad576df0b0b64b759769fce2db7c2015?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Flong_bodyshot.png)
![[IMG]](//proxy.spigotmc.org/b8bb69117676d05f2f25337a419f4360cf0f020b?url=https%3A%2F%2Fraw.githubusercontent.com%2Fwordnice%2FGunAPI%2Fmaster%2Fscreenshots%2Fminecraft_vs_gunapi.png)
![[IMG]](//proxy.spigotmc.org/e757de6c212cb16dd89f14c67eec4de37ee8f7c7?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Flong_bodyshot_blaze.png)
![[IMG]](//proxy.spigotmc.org/65381c4e38bcc61e3922013183f0544ed1c773a4?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fheadshot_horse.png)
![[IMG]](//proxy.spigotmc.org/c53a432462efaac7c9231647f45181ea1746b2c7?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fbats.png)
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:
- In `plugins/GunAPI/config.yml` change `example: false` to `example: true`
- Get OP
- Get 33 porks - /i pork 33
- Get creative gamemode
- Take a look at some entities
- Press shift
- You will get list of entities you hit in radius 50 blocks (including headshots)
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]](http://proxy.spigotmc.org/d48dbda13269f6de6121da4d52aa8589b0c7ee1c?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fheadshot.png)
![[IMG]](http://proxy.spigotmc.org/c9a213b4b8648765e7975aea0e7c1b812d8931cb?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fbodyshot.png)
![[IMG]](http://proxy.spigotmc.org/abf6f1dde4fbf656897e795b8a339556c9a7fc30?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fnoshot.png)
![[IMG]](http://proxy.spigotmc.org/f7fa9a6d2e7592244b9e648f3c9f88d03662b22c?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fmulti_headshot.png)
![[IMG]](http://proxy.spigotmc.org/93b337fbb341922442ffabeacd90490a215cc484?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Flong_headshot.png)
![[IMG]](http://proxy.spigotmc.org/b30d49dbad576df0b0b64b759769fce2db7c2015?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Flong_bodyshot.png)
![[IMG]](http://proxy.spigotmc.org/b8bb69117676d05f2f25337a419f4360cf0f020b?url=https%3A%2F%2Fraw.githubusercontent.com%2Fwordnice%2FGunAPI%2Fmaster%2Fscreenshots%2Fminecraft_vs_gunapi.png)
![[IMG]](http://proxy.spigotmc.org/e757de6c212cb16dd89f14c67eec4de37ee8f7c7?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Flong_bodyshot_blaze.png)
![[IMG]](http://proxy.spigotmc.org/65381c4e38bcc61e3922013183f0544ed1c773a4?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fheadshot_horse.png)
![[IMG]](http://proxy.spigotmc.org/c53a432462efaac7c9231647f45181ea1746b2c7?url=https%3A%2F%2Fgithub.com%2Fwordnice%2FGunAPI%2Fraw%2Fmaster%2Fscreenshots%2Fbats.png)
Quick facts
- Edition: Minecraft Java
- File type: .jar
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
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.