-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPet.java
More file actions
45 lines (39 loc) · 1.04 KB
/
Pet.java
File metadata and controls
45 lines (39 loc) · 1.04 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
37
38
39
40
41
42
43
44
45
public class Pet {
private Mob pet;
private final Player player;
private static final int MAX_DISTANCE = 5;
private String name;
private int health;
public Pet(Player player, String petname) {
this.player = player;
this.name = petname;
}
public void start() {
pet = new Mob("Chicken", player.getLocation());
pet.spawn();
this.health = pet.getHealth();
player.sendMessage("You spawned a pet named " + name + "!");
onPlayerMove(null,null);
}
public void kill() {
pet.setHealth(-1);
player.sendMessage("Your pet has died.");
}
public void put_away() {
this.health = pet.getHealth();
pet.setHealth(-1);
player.sendMessage("You put away " + name + ".");
}
public void take_out() {
pet.spawn();
pet.setHealth(health);
onPlayerMove(null, null);
player.sendMessage("You took out " + name + ".");
}
public void onPlayerMove(Location from, Location to) {
Location loc = player.getLocation();
if (Utils.distance(pet.getX(), pet.getY(), pet.getZ(), loc.x, loc.y, loc.z) > MAX_DISTANCE) {
pet.teleportTo(loc);
}
}
}