|
22 | 22 | import org.bukkit.event.EventHandler; |
23 | 23 |
|
24 | 24 | import org.mvplugins.multiverse.portals.MultiversePortals; |
| 25 | +import org.mvplugins.multiverse.portals.config.PortalsConfig; |
25 | 26 | import org.mvplugins.multiverse.portals.utils.PortalManager; |
26 | 27 |
|
27 | 28 | @Service |
28 | | -public class MVPCoreListener implements PortalsListener { |
| 29 | +final class MVPCoreListener implements PortalsListener { |
29 | 30 | private final MultiversePortals plugin; |
| 31 | + private final PortalsConfig config; |
30 | 32 | private final PortalManager portalManager; |
31 | 33 |
|
32 | 34 | @Inject |
33 | | - MVPCoreListener(@NotNull MultiversePortals plugin, @NotNull PortalManager portalManager) { |
| 35 | + MVPCoreListener(@NotNull MultiversePortals plugin, @NotNull PortalManager portalManager, @NotNull PortalsConfig config) { |
34 | 36 | this.plugin = plugin; |
35 | 37 | this.portalManager = portalManager; |
| 38 | + this.config = config; |
36 | 39 | } |
37 | 40 |
|
38 | 41 | /** |
@@ -73,26 +76,27 @@ public void debugModeChange(MVDebugModeEvent event) { |
73 | 76 | public void portalTouchEvent(MVPlayerTouchedPortalEvent event) { |
74 | 77 | Logging.finer("Found The TouchedPortal event."); |
75 | 78 | Location l = event.getBlockTouched(); |
76 | | - if (event.canUseThisPortal() && (this.portalManager.isPortal(l))) { |
77 | | - if (this.plugin.getPortalSession(event.getPlayer()).isDebugModeOn()) { |
78 | | - event.setCancelled(true); |
| 79 | + if (!event.canUseThisPortal() || (!this.portalManager.isPortal(l))) { |
| 80 | + return; |
| 81 | + } |
| 82 | + if (this.plugin.getPortalSession(event.getPlayer()).isDebugModeOn()) { |
| 83 | + event.setCancelled(true); |
| 84 | + return; |
| 85 | + } |
| 86 | + // This is a valid portal, and they can use it so far... |
| 87 | + MVPortal p = this.portalManager.getPortal(event.getPlayer(), l); |
| 88 | + if (p == null) { |
| 89 | + // The player can't see this portal, and can't use it. |
| 90 | + Logging.finer(String.format("'%s' was DENIED access to this portal event.", event.getPlayer().getName())); |
| 91 | + event.setCanUseThisPortal(false); |
| 92 | + } else if (p.getDestination() == null) { |
| 93 | + if (config.getPortalsDefaultToNether()) { |
| 94 | + Logging.finer("Allowing MVPortal to act as nether portal."); |
79 | 95 | return; |
80 | 96 | } |
81 | | - // This is a valid portal, and they can use it so far... |
82 | | - MVPortal p = this.portalManager.getPortal(event.getPlayer(), l); |
83 | | - if (p == null) { |
84 | | - // The player can't see this portal, and can't use it. |
85 | | - Logging.finer(String.format("'%s' was DENIED access to this portal event.", event.getPlayer().getName())); |
86 | | - event.setCanUseThisPortal(false); |
87 | | - } else if (p.getDestination() == null) { |
88 | | - if (this.plugin.getMainConfig().getBoolean("portalsdefaulttonether", false)) { |
89 | | - Logging.finer("Allowing MVPortal to act as nether portal."); |
90 | | - return; |
91 | | - } |
92 | | - // They can see it, is it val |
93 | | - event.getPlayer().sendMessage("This Multiverse Portal does not have a valid destination!"); |
94 | | - event.setCanUseThisPortal(false); |
95 | | - } |
| 97 | + // They can see it, is it val |
| 98 | + event.getPlayer().sendMessage("This Multiverse Portal does not have a valid destination!"); |
| 99 | + event.setCanUseThisPortal(false); |
96 | 100 | } |
97 | 101 | } |
98 | 102 | } |
0 commit comments