|
1 | 1 | package world.bentobox.upgrades.listeners;
|
2 | 2 |
|
| 3 | +import org.bukkit.Material; |
| 4 | +import org.bukkit.World; |
| 5 | +import org.bukkit.entity.EntityType; |
3 | 6 | import org.bukkit.event.EventHandler;
|
4 | 7 | import org.bukkit.event.EventPriority;
|
5 | 8 | import org.bukkit.event.Listener;
|
6 | 9 |
|
7 |
| -import world.bentobox.limits.events.LimitsJoinPermCheckEvent; |
| 10 | +import world.bentobox.limits.Settings.EntityGroup; |
| 11 | +import world.bentobox.limits.events.LimitsPermCheckEvent; |
| 12 | +import world.bentobox.upgrades.UpgradesAddon; |
8 | 13 |
|
9 | 14 | public class JoinPermCheckListener implements Listener {
|
10 | 15 |
|
11 |
| - public JoinPermCheckListener() { |
| 16 | + public JoinPermCheckListener(UpgradesAddon addon) { |
| 17 | + this.addon = addon; |
12 | 18 | }
|
13 | 19 |
|
14 | 20 | @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
|
15 |
| - public void onLimitsJoinPermCheckEvent(LimitsJoinPermCheckEvent e) { |
16 |
| - // Stop LimitsJoinPermCheck else reset limits upgrades when player join |
17 |
| - e.setCancelled(true); |
| 21 | + public void onLimitsPermCheckEvent(LimitsPermCheckEvent e) { |
| 22 | + Material block = e.getMaterial(); |
| 23 | + EntityType et = e.getEntityType(); |
| 24 | + EntityGroup entgroup = e.getEntityGroup(); |
| 25 | + World world = e.getPlayer().getWorld(); |
| 26 | + |
| 27 | + if (block != null) { |
| 28 | + if (this.addon.getUpgradesManager().getAllBlockLimitsUpgradeTiers(world).containsKey(block)) { |
| 29 | + e.setCancelled(true); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + if (et != null) { |
| 34 | + if (this.addon.getUpgradesManager().getAllEntityLimitsUpgradeTiers(world).containsKey(et)) { |
| 35 | + e.setCancelled(true); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + if (entgroup != null) { |
| 40 | + if (this.addon.getUpgradesManager().getAllEntityGroupLimitsUpgradeTiers(world).containsKey(entgroup.getName())) { |
| 41 | + e.setCancelled(true); |
| 42 | + } |
| 43 | + } |
18 | 44 | }
|
19 | 45 |
|
| 46 | + UpgradesAddon addon; |
| 47 | + |
20 | 48 | }
|
0 commit comments