-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPetListener.java
More file actions
39 lines (34 loc) · 992 Bytes
/
PetListener.java
File metadata and controls
39 lines (34 loc) · 992 Bytes
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
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Hashtable;
import java.lang.reflect.*;
import java.util.Random;
public class PetListener extends PluginListener {
private static final Hashtable <Player, Pet> petsByPlayer = new Hashtable<Player, Pet>();
public boolean onCommand(Player player, String[] split) {
if(!player.canUseCommand(split[0]))
return false;
if(split[0].equalsIgnoreCase("/petcreate")) {
if(split[1] == null) {
player.sendMessage("Usage: /petcreate petname");
return false;
}
Pet pet = petsByPlayer.get(player);
if(pet != null) {
player.sendMessage("You already have a pet!");
return false;
}
pet = new Pet(player, split[1]);
petsByPlayer.put(player, pet);
pet.start();
return true;
}
return false;
}
public void onPlayerMove(Player player, Location from, Location to) {
Pet pet = petsByPlayer.get(player);
if (pet != null)
pet.onPlayerMove(from, to);
}
}