Make a variable outside the command method like Villager villager; Then use villager = ...; Where you want it
@Kolia1_1 Villager villager; public boolean onCommand(<arguments>){ if(cmd.getName().equalsIgnoreCase("villager"){ villager = (Villager) p.getWorld().spawnEntity(p.getLocation(), EntityType.VILLAGER); } }
@Kolia1_1 make it public and connect the classes using OtherClass class = new OtherClass(); Villager villager = class.villager;
Just for information you dont need to use Code: if(command is idk) { //do } else { if(comand is idk2) { //do } } but you can do Code: if(command is idk) { //do } else if(command is idk2) { } you will save some lines