Skip to content

Commit

Permalink
feat: block physics updates inside portal protection zones
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Aug 31, 2024
1 parent 21a0985 commit 2bfb9d6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,8 @@ public boolean entityPortalEvent(EntityContainer entity) {
pos.addY((int) entity.getHeight()), 1);
return !(feetInPortal || headInPortal);
}

public boolean physicsEvent(BlockLocation blockLocation, String string) {
return !configRepository.getDisablePhysicsEvents() || !portalServices.inPortalRegionProtected(blockLocation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void registered() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void registered() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface ConfigRepository {

void loadConfig(DataStorage dataStorage);

int getVisibleRange();
int getShowVisibleRange();

int getMaxTriggerVisualisationSize();

Expand All @@ -34,5 +34,7 @@ public interface ConfigRepository {

void storeConfig();

boolean getDisablePhysicsEvents();

CommandPortalConfig getCommandPortals();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public String getSelectorMaterial() {
}

@Override
public int getVisibleRange() {
return this.config.visibleRange;
public int getShowVisibleRange() {
return this.config.showVisibleRange;
}

@Override
Expand Down Expand Up @@ -96,6 +96,11 @@ public boolean playFailSound() {
return this.config.playFailSound;
}

@Override
public boolean getDisablePhysicsEvents() {
return this.config.disablePhysicsEvents;
}

@Override
public CommandPortalConfig getCommandPortals() {
return this.config.commandPortals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
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.*;

Expand Down Expand Up @@ -109,6 +106,15 @@ public void onBlockPlace(BlockPlaceEvent event) {
}
}

@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()));
Expand Down

0 comments on commit 2bfb9d6

Please sign in to comment.