I tried to modify the code, but it seems that the attack() method for event.entity, which is a LivingEntity, only accepts one argument. The attack() method for Entity seems to accept DamageSource as the first argument.
Is there any way to solve this? Thank you.
event.entity.attack(event.source.player, event.damage + Math.floor(Math.random() * 5))
[22:09:16] [Server thread/INFO] [KubeJS Server/]: weapon.js#1: Loaded Java class 'net.minecraft.world.damagesource.DamageSource'
[22:09:16] [Server thread/ERROR] [KubeJS Server/]: weapon.js#2: Java constructor for "net.minecraft.world.damagesource.DamageSource" with arguments "dev.latvian.mods.rhino.Undefined" not found.
[22:09:16] [Server thread/ERROR] [KubeJS Server/]: …rhino.EvaluatorException: Java constructor for "net.minecraft.world.damagesource.DamageSource" with arguments "…rhino.Undefined" not found. (server_scripts:weapon.js#2)