-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeadsManager.java
More file actions
51 lines (44 loc) · 1.5 KB
/
HeadsManager.java
File metadata and controls
51 lines (44 loc) · 1.5 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
46
47
48
49
50
51
package fr.iglee42.customheads;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.Plugin;
/*
* @author iglee42
*/
public class HeadsManager implements Listener {
public static Map<String,CustomHead> customHead = new HashMap<>();
public static Map<Player,CustomHead> activatedHead = new HashMap<>();
private Plugin plugin;
private void register(Plugin plugin) {
this.plugin = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin);
}
public void addHead(CustomHead head) {
Bukkit.getPluginManager().registerEvents(head, plugin);
}
@EventHandler
public void onInteract(PlayerInteractEvent event) {
if (event.getAction() == null && event.getItem() == null) return;
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) return;
if (!event.getItem().hasItemMeta()) return;
if (!event.getItem().getItemMeta().hasDisplayName()) return;
if (event.getItem().getType() == Material.SKULL_ITEM) {
CustomHead h = null;
for (CustomHead head : customHead.values()) {
String hn = head.getName().replaceAll("&", "§");
if (event.getItem().getItemMeta().getDisplayName().equals(hn)) {
h = head;
}
}
if (h == null) return;
h.activate(event.getPlayer());
}
}
}