feat: block physics updates inside portal protection zones

This commit is contained in:
Sekwah 2024-09-01 01:46:09 +02:00
parent 901b4a9989
commit bba14185eb
7 changed files with 29 additions and 12 deletions

View File

@ -194,4 +194,8 @@ public class CoreListeners {
pos.addY((int) entity.getHeight()), 1);
return !(feetInPortal || headInPortal);
}
public boolean physicsEvent(BlockLocation blockLocation, String string) {
return !configRepository.getDisablePhysicsEvents() || !portalServices.inPortalRegionProtected(blockLocation);
}
}

View File

@ -100,7 +100,7 @@ public class ShowDestiSubCommand
if (Objects.equals(pos.getWorldName(),
player.getWorldName())
&& pos.distanceTo(player.getLoc())
< config.getVisibleRange()) {
< config.getShowVisibleRange()) {
Debug.addMarker(player, pos.toBlockPos(),
destination.getArgValues("name")[0],
new Color(100, 100, 100, 100), 1300);

View File

@ -138,7 +138,7 @@ public class ShowPortalSubCommand
if (Objects.equals(portal.getMinLoc().getWorldName(),
player.getWorldName())
&& portal.isLocationInPortal(
player.getLoc(), config.getVisibleRange())) {
player.getLoc(), config.getShowVisibleRange())) {
BlockLocation minLoc = portal.getMinLoc();
BlockLocation maxLoc = portal.getMaxLoc();
int midX = (minLoc.getPosX() + maxLoc.getPosX()) / 2;

View File

@ -12,7 +12,7 @@ public interface ConfigRepository {
void loadConfig(DataStorage dataStorage);
int getVisibleRange();
int getShowVisibleRange();
int getMaxTriggerVisualisationSize();
@ -34,5 +34,7 @@ public interface ConfigRepository {
void storeConfig();
boolean getDisablePhysicsEvents();
CommandPortalConfig getCommandPortals();
}

View File

@ -41,8 +41,8 @@ public class ConfigRepositoryImpl implements ConfigRepository {
}
@Override
public int getVisibleRange() {
return this.config.visibleRange;
public int getShowVisibleRange() {
return this.config.showVisibleRange;
}
@Override
@ -96,6 +96,11 @@ public class ConfigRepositoryImpl implements ConfigRepository {
return this.config.playFailSound;
}
@Override
public boolean getDisablePhysicsEvents() {
return this.config.disablePhysicsEvents;
}
@Override
public CommandPortalConfig getCommandPortals() {
return this.config.commandPortals;

View File

@ -22,11 +22,11 @@ public class Config {
public String warpSound = "ENDER";
public String selectionBlock = "RED_STAINED_GLASS";
public String translationFile = "en_GB";
public int visibleRange = 50;
public int showVisibleRange = 50;
public boolean disablePhysicsEvents = true;
public int maxTriggerVisualisationSize = 1000;

View File

@ -10,10 +10,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.player.*;
@ -52,6 +49,15 @@ public class Listeners implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPhysicsEvent(BlockPhysicsEvent event) {
if (!coreListeners.physicsEvent(ContainerHelpers.toBlockLocation(
event.getBlock().getLocation()),
event.getBlock().getType().toString())) {
event.setCancelled(true);
}
}
@EventHandler
public void onWorldChangeEvent(PlayerChangedWorldEvent event) {
coreListeners.worldChange(new SpigotPlayerContainer(event.getPlayer()));