-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBounceable.java
More file actions
36 lines (26 loc) · 1.03 KB
/
Copy pathBounceable.java
File metadata and controls
36 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ru.cwcode.cwutils.bounceable;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public interface Bounceable<T extends Entity, EVENT extends EntityEvent> {
void onExecute(EVENT event);
default double getVelocityMultiplier() {
return 1.0;
}
Class<T> getEntityClass();
default T spawnEntity(Location location, Player player, ItemStack itemStack) {
return location.getWorld().spawn(location, this.getEntityClass());
}
default void bounce(Player player, ItemStack itemStack) {
Location location = player.getEyeLocation();
Vector velocity = location.getDirection().normalize().multiply(this.getVelocityMultiplier());
T entity = this.spawnEntity(location, player, itemStack);
entity.setVelocity(velocity);
BounceableListener.addBouncedEntity(entity, this);
itemStack.subtract();
}
}