|
27 | 27 |
|
28 | 28 | import in.twizmwaz.cardinal.Cardinal;
|
29 | 29 | import in.twizmwaz.cardinal.match.Match;
|
30 |
| -import in.twizmwaz.cardinal.module.AbstractModule; |
| 30 | +import in.twizmwaz.cardinal.module.AbstractListenerModule; |
31 | 31 | import in.twizmwaz.cardinal.module.ModuleEntry;
|
32 | 32 | import in.twizmwaz.cardinal.module.ModuleError;
|
33 | 33 | import in.twizmwaz.cardinal.module.repository.LoadedMap;
|
34 | 34 | import in.twizmwaz.cardinal.util.MaterialType;
|
35 | 35 | import lombok.Getter;
|
36 | 36 | import lombok.NonNull;
|
| 37 | +import org.bukkit.event.EventHandler; |
| 38 | +import org.bukkit.event.entity.ItemSpawnEvent; |
| 39 | +import org.bukkit.material.MaterialData; |
37 | 40 | import org.jdom2.Element;
|
38 | 41 | import org.jdom2.located.Located;
|
39 | 42 |
|
|
43 | 46 | import java.util.Map;
|
44 | 47 |
|
45 | 48 | @ModuleEntry
|
46 |
| -public class ItemRemoveModule extends AbstractModule { |
| 49 | +public class ItemRemoveModule extends AbstractListenerModule { |
47 | 50 |
|
48 | 51 | @Getter
|
49 | 52 | private final Map<Match, List<MaterialType>> materials = new HashMap<>();
|
50 | 53 |
|
51 |
| - public ItemRemoveModule() { |
52 |
| - Cardinal.registerEvents(new ItemRemoveModuleListener(this)); |
53 |
| - } |
54 |
| - |
55 | 54 | @Override
|
56 | 55 | public boolean loadMatch(@NonNull Match match) {
|
57 | 56 | List<MaterialType> types = new ArrayList<>();
|
@@ -85,4 +84,21 @@ public void clearMatch(@NonNull Match match) {
|
85 | 84 | materials.remove(match);
|
86 | 85 | }
|
87 | 86 |
|
| 87 | + /** |
| 88 | + * Prevent items from spawning if they are in the item-remove tag in XML. |
| 89 | + * |
| 90 | + * @param event The event. |
| 91 | + */ |
| 92 | + @EventHandler(ignoreCancelled = true) |
| 93 | + public void onItemSpawn(ItemSpawnEvent event) { |
| 94 | + Match match = Cardinal.getMatch(event.getWorld()); |
| 95 | + MaterialData data = event.getEntity().getItemStack().getData(); |
| 96 | + for (MaterialType type : materials.get(match)) { |
| 97 | + if (type.isType(data)) { |
| 98 | + event.setCancelled(true); |
| 99 | + break; |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + |
88 | 104 | }
|
0 commit comments