Skip to content

Example code

pixelrider2000 edited this page Nov 5, 2021 · 3 revisions
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
        //Checks if the damager is a bullet and then returns the name of the player who fired it
        
	BulletHandler bHandler = new BulletHandler();
	String owner = bHandler.getBulletOwner(e.getDamager().getUniqueId().toString());
        if(owner == null) return;
	
	//Do stuff...
}

Example two

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
	if(sender instanceof Player) {
		Player p = (Player) sender;
		if(args.length == 1) {
			if(args[0].equalsIgnoreCase("test")) {
				if(p.hasPermission("flansapi.test")) {
					VehicleHandler vHandler = new VehicleHandler();
					
					//The player is standing on a chest thus these coordinates are of the chest
					int cx = p.getLocation().getBlock().getX(),
					cy = p.getLocation().getBlock().getY(),
					cz = p.getLocation().getBlock().getZ();
					
					vHandler.spawnDriveable(p.getLocation().getWorld().getName(), cx, cy, cz, "vehicle", (cx+15), (cy+10), cz, 0);
					p.sendMessage("§6You successfully spawned a vehicle!");
				}
			}
		} 
	} 
	return false;
}

Example three

    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
	if(sender instanceof Player) {
		Player p = (Player) sender;
		if(args.length == 1) {
			if(args[0].equalsIgnoreCase("test")) {
				if(p.hasPermission("flansapi.test")) {
					VehicleHandler vHandler = new VehicleHandler();
					
					//Coordinates where to spawn the vehicle (inside the player)
					int sx = p.getLocation().getBlock().getX(),
					sy = p.getLocation().getBlock().getY(),
					sz = p.getLocation().getBlock().getZ();
					
                                            //Spawning the vehicle which returns the UUID of it
					String vUUID = vHandler.spawnDriveable(4279, p.getLocation().getWorld().getName(), sx, sy, sz, 0.0f);
                                            //Getting the UUID of the drivers seat to use methods below
                                            String sUUID = vHandler.seatFromDriveable(vUUID);

                                            //3d array {{{ID, NBT, AMOUNT}}}
                                            //This array contains 64 stone blocks and 32 lime stained glass
                                            int[][][] ids = {{{1, 0, 64}}, {{95, 5, 32}}};

                                            //The InventorySection is an enum and is used to tell the method which inventory to put items into
                                            //It's either .CARGO, .AMMO, .SHELLS or .MINES
                                            InventorySection inventorySection = InventorySection.CARGO;
                                            
                                            //Either skip items that exist in the inventory or replace them
                                            boolean replaceExistingItems = false;

                                            //Puts 64 stone blocks and 32 lime stained glass into the cargo inventory of the newly spawned tank
                                            vHandler.putItemsInDriveable(sUUID, ids, inventorySection, replaceExistingItems);
				}
			}
		} 
	} 
	return false;
}
Clone this wiki locally