Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,51 @@

import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPhysicsEvent;

import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.portals.config.PortalsConfig;
import org.mvplugins.multiverse.portals.utils.PortalManager;

@Service
public class MVPBlockListener implements PortalsListener {
final class MVPBlockListener implements PortalsListener {
private final PortalManager portalManager;
private final PortalsConfig portalsConfig;

@Inject
MVPBlockListener(@NotNull PortalManager portalManager) {
MVPBlockListener(@NotNull PortalManager portalManager, @NotNull PortalsConfig portalsConfig) {
this.portalManager = portalManager;
this.portalsConfig = portalsConfig;
}

@EventHandler
public void blockPhysics(BlockPhysicsEvent event) {
if (event.isCancelled()) {
return;
}
@EventHandler(ignoreCancelled = true)
void blockPhysics(BlockPhysicsEvent event) {
if (event.getChangedType() == Material.NETHER_PORTAL || event.getBlock().getType() == Material.NETHER_PORTAL) {
if (portalManager.isPortal(event.getBlock().getLocation())) {
event.setCancelled(true);
}
}
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
void blockFromTo(BlockFromToEvent event) {
// The to block should never be null, but apparently it is sometimes...
if (event.getBlock() == null || event.getToBlock() == null) {
return;
}

// If lava/something else is trying to flow in...
if (portalManager.isPortal(event.getToBlock().getLocation())) {
event.setCancelled(true);
return;
}
// If something is trying to flow out, stop that too, unless bucketFilling has been disabled
if (portalManager.isPortal(event.getBlock().getLocation()) && portalsConfig.getBucketFilling()) {
event.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@
import org.bukkit.event.EventHandler;

import org.mvplugins.multiverse.portals.MultiversePortals;
import org.mvplugins.multiverse.portals.config.PortalsConfig;
import org.mvplugins.multiverse.portals.utils.PortalManager;

@Service
public class MVPCoreListener implements PortalsListener {
final class MVPCoreListener implements PortalsListener {
private final MultiversePortals plugin;
private final PortalsConfig config;
private final PortalManager portalManager;

@Inject
MVPCoreListener(@NotNull MultiversePortals plugin, @NotNull PortalManager portalManager) {
MVPCoreListener(@NotNull MultiversePortals plugin, @NotNull PortalManager portalManager, @NotNull PortalsConfig config) {
this.plugin = plugin;
this.portalManager = portalManager;
this.config = config;
}

/**
Expand Down Expand Up @@ -73,26 +76,27 @@ public void debugModeChange(MVDebugModeEvent event) {
public void portalTouchEvent(MVPlayerTouchedPortalEvent event) {
Logging.finer("Found The TouchedPortal event.");
Location l = event.getBlockTouched();
if (event.canUseThisPortal() && (this.portalManager.isPortal(l))) {
if (this.plugin.getPortalSession(event.getPlayer()).isDebugModeOn()) {
event.setCancelled(true);
if (!event.canUseThisPortal() || (!this.portalManager.isPortal(l))) {
return;
}
if (this.plugin.getPortalSession(event.getPlayer()).isDebugModeOn()) {
event.setCancelled(true);
return;
}
// This is a valid portal, and they can use it so far...
MVPortal p = this.portalManager.getPortal(event.getPlayer(), l);
if (p == null) {
// The player can't see this portal, and can't use it.
Logging.finer(String.format("'%s' was DENIED access to this portal event.", event.getPlayer().getName()));
event.setCanUseThisPortal(false);
} else if (p.getDestination() == null) {
if (config.getPortalsDefaultToNether()) {
Logging.finer("Allowing MVPortal to act as nether portal.");
return;
}
// This is a valid portal, and they can use it so far...
MVPortal p = this.portalManager.getPortal(event.getPlayer(), l);
if (p == null) {
// The player can't see this portal, and can't use it.
Logging.finer(String.format("'%s' was DENIED access to this portal event.", event.getPlayer().getName()));
event.setCanUseThisPortal(false);
} else if (p.getDestination() == null) {
if (this.plugin.getMainConfig().getBoolean("portalsdefaulttonether", false)) {
Logging.finer("Allowing MVPortal to act as nether portal.");
return;
}
// They can see it, is it val
event.getPlayer().sendMessage("This Multiverse Portal does not have a valid destination!");
event.setCanUseThisPortal(false);
}
// They can see it, is it val
event.getPlayer().sendMessage("This Multiverse Portal does not have a valid destination!");
event.setCanUseThisPortal(false);
}
}
}
Loading