Fixes underwater signs and buttons being replaced with AIR instead of water
This commit is contained in:
parent
9c963c9e8c
commit
4db6274dc3
@ -389,6 +389,7 @@ bungeeSign=Teleport to
|
|||||||
- Adds another default gate to show that it's possible to use any number of materials for a stargate's border
|
- Adds another default gate to show that it's possible to use any number of materials for a stargate's border
|
||||||
- Adds an option for stargates without a sign. Right-clicking such a stargate will display gate information
|
- Adds an option for stargates without a sign. Right-clicking such a stargate will display gate information
|
||||||
- Fixes a bug causing signs to be re-drawn after they're broken
|
- Fixes a bug causing signs to be re-drawn after they're broken
|
||||||
|
- Makes buttons and signs be replaced by water instead of air when underwater
|
||||||
|
|
||||||
#### \[Version 0.9.0.5] EpicKnarvik97 fork
|
#### \[Version 0.9.0.5] EpicKnarvik97 fork
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import net.knarcraft.stargate.portal.PortalRegistry;
|
|||||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
|
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.type.WallSign;
|
import org.bukkit.block.data.type.WallSign;
|
||||||
@ -84,7 +85,8 @@ public class BlockEventListener implements Listener {
|
|||||||
|
|
||||||
//Remove the sign if the no sign option is enabled
|
//Remove the sign if the no sign option is enabled
|
||||||
if (portal.getOptions().hasNoSign()) {
|
if (portal.getOptions().hasNoSign()) {
|
||||||
BlockChangeRequest request = new BlockChangeRequest(portal.getSignLocation(), Material.AIR, null);
|
Material replaceMaterial = PortalFileHelper.decideRemovalMaterial(portal.getSignLocation(), portal);
|
||||||
|
BlockChangeRequest request = new BlockChangeRequest(portal.getSignLocation(), replaceMaterial, null);
|
||||||
Stargate.addBlockChangeRequest(request);
|
Stargate.addBlockChangeRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,13 @@ import net.knarcraft.stargate.portal.property.PortalOwner;
|
|||||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Directional;
|
import org.bukkit.block.data.Directional;
|
||||||
|
import org.bukkit.block.data.Waterlogged;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -292,9 +294,10 @@ public final class PortalFileHelper {
|
|||||||
BlockLocation buttonLocation = getButtonLocation(portal);
|
BlockLocation buttonLocation = getButtonLocation(portal);
|
||||||
BlockData buttonData = buttonLocation.getBlock().getBlockData();
|
BlockData buttonData = buttonLocation.getBlock().getBlockData();
|
||||||
if (portal.getOptions().isAlwaysOn()) {
|
if (portal.getOptions().isAlwaysOn()) {
|
||||||
//Clear button if not already air
|
//Clear button if not already air or water
|
||||||
if (buttonData.getMaterial() != Material.AIR) {
|
if (buttonData.getMaterial() != Material.AIR && buttonData.getMaterial() != Material.WATER) {
|
||||||
Stargate.addBlockChangeRequest(new BlockChangeRequest(buttonLocation, Material.AIR, null));
|
Material newMaterial = decideRemovalMaterial(buttonLocation, portal);
|
||||||
|
Stargate.addBlockChangeRequest(new BlockChangeRequest(buttonLocation, newMaterial, null));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Replace button if the material does not match
|
//Replace button if the material does not match
|
||||||
@ -304,6 +307,40 @@ public final class PortalFileHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decides the material to use for removing a portal's button/sign
|
||||||
|
*
|
||||||
|
* @param location <p>The location of the button/sign to replace</p>
|
||||||
|
* @param portal <p>The portal the button/sign belongs to</p>
|
||||||
|
* @return <p>The material to use for removing the button/sign</p>
|
||||||
|
*/
|
||||||
|
public static Material decideRemovalMaterial(BlockLocation location, Portal portal) {
|
||||||
|
//Get the blocks to each side of the location
|
||||||
|
Location leftLocation = location.getRelativeLocation(-1, 0, 0, portal.getYaw());
|
||||||
|
Location rightLocation = location.getRelativeLocation(1, 0, 0, portal.getYaw());
|
||||||
|
|
||||||
|
//If the block is water or is waterlogged, assume the portal is underwater
|
||||||
|
if (isUnderwater(leftLocation) || isUnderwater(rightLocation)) {
|
||||||
|
return Material.WATER;
|
||||||
|
} else {
|
||||||
|
return Material.AIR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the given location is underwater
|
||||||
|
*
|
||||||
|
* <p>If the location has a water block, or a block which is waterlogged, it will be considered underwater.</p>
|
||||||
|
*
|
||||||
|
* @param location <p>The location to check</p>
|
||||||
|
* @return <p>True if the location is underwater</p>
|
||||||
|
*/
|
||||||
|
private static boolean isUnderwater(Location location) {
|
||||||
|
BlockData blockData = location.getBlock().getBlockData();
|
||||||
|
return blockData.getMaterial() == Material.WATER ||
|
||||||
|
(blockData instanceof Waterlogged waterlogged && waterlogged.isWaterlogged());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the button vector for the given portal
|
* Updates the button vector for the given portal
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user