diff --git a/build.gradle b/build.gradle index df5204ec..aa473c20 100644 --- a/build.gradle +++ b/build.gradle @@ -56,7 +56,6 @@ buildscript { repositories { maven {url "https://plugins.gradle.org/m2/"} mavenCentral() - mavenLocal() } dependencies { classpath "org.apache.httpcomponents:httpmime:4.5.13" @@ -84,8 +83,8 @@ allprojects { buildSubmodules.finalizedBy build } - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = JavaVersion.VERSION_16 + targetCompatibility = JavaVersion.VERSION_16 } apply from: 'env-variables.gradle' diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index 3b2389cc..4e0e6247 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -3,13 +3,15 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.connector.containers.WorldContainer; +import com.sekwah.advancedportals.core.connector.data.BlockAxis; import com.sekwah.advancedportals.core.data.BlockLocation; import com.sekwah.advancedportals.core.data.PlayerLocation; import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.services.PortalTempDataServices; -import com.sekwah.advancedportals.core.util.Lang; + +import java.util.Objects; public class CoreListeners { @@ -68,7 +70,7 @@ public boolean liquidFlow(BlockLocation fromPos, BlockLocation toPos) { * @param blockMaterial * @return if the block is allowed to break */ - public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, String blockMaterial) { + public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, String blockMaterial, String itemInHandMaterial, String itemInHandName) { return true; } @@ -79,14 +81,15 @@ public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, String * @return if the block is allowed to be placed */ public boolean blockPlace(PlayerContainer player, BlockLocation blockPos, String blockMaterial, String itemInHandMaterial, String itemInHandName) { + System.out.println("Block placed: " + blockMaterial + " " + itemInHandMaterial + " " + itemInHandName); if(itemInHandName != null && player != null && PortalPermissions.BUILD.hasPermission(player)) { WorldContainer world = player.getWorld(); if(itemInHandName.equals("\u00A75Portal Block Placer")) { - world.setBlock(blockPos, "PORTAL"); + world.setBlock(blockPos, "NETHER_PORTAL"); return false; } else if(itemInHandName.equals("\u00A78End Portal Block Placer")) { - world.setBlock(blockPos, "ENDER_PORTAL"); + world.setBlock(blockPos, "END_PORTAL"); return false; } else if(itemInHandName.equals("\u00A78Gateway Block Placer")) { @@ -113,22 +116,29 @@ public boolean blockInteract(PlayerContainer player, BlockLocation blockPos) { * @param leftClick true = left click, false = right click * @return if player is allowed to interact with block */ - public boolean playerInteractWithBlock(PlayerContainer player, String materialName, String itemName, + public boolean playerInteractWithBlock(PlayerContainer player, String blockMaterialname, String itemMaterialName, String itemName, BlockLocation blockLoc, boolean leftClick) { + System.out.println(blockMaterialname); if(itemName != null && (player.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(player)) && - materialName.equalsIgnoreCase(this.configRepository.getSelectorMaterial()) + itemMaterialName.equalsIgnoreCase(this.configRepository.getSelectorMaterial()) && (!this.configRepository.getUseOnlySpecialAxe() || itemName.equals("\u00A7ePortal Region Selector"))) { this.portalTempDataServices.playerSelectorActivate(player, blockLoc, leftClick); return false; } - else if(itemName != null && leftClick && itemName.equals("\u00A75Portal Block Placer") && PortalPermissions.BUILD.hasPermission(player)) { + else if(itemName != null && leftClick && + Objects.equals(itemMaterialName, "PURPLE_WOOL") && + itemName.equals("\u00A75Portal Block Placer") && PortalPermissions.BUILD.hasPermission(player)) { + if(!Objects.equals(blockMaterialname, "NETHER_PORTAL")) { + return false; + } WorldContainer world = player.getWorld(); - if(world.getBlockData(blockLoc) == 1) { - world.setBlockData(blockLoc, (byte) 2); + if(world.getBlockAxis(blockLoc) == BlockAxis.X) { + world.setBlockAxis(blockLoc, BlockAxis.Z); } else { - world.setBlockData(blockLoc, (byte) 1); + world.setBlockAxis(blockLoc, BlockAxis.X); } + return false; } return true; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java index ebfaca09..fec51320 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/WorldContainer.java @@ -1,14 +1,15 @@ package com.sekwah.advancedportals.core.connector.containers; +import com.sekwah.advancedportals.core.connector.data.BlockAxis; import com.sekwah.advancedportals.core.data.BlockLocation; public interface WorldContainer { void setBlock(BlockLocation location, String material); - void setBlockData(BlockLocation location, byte data); - String getBlock(BlockLocation location); - byte getBlockData(BlockLocation location); + BlockAxis getBlockAxis(BlockLocation location); + + void setBlockAxis(BlockLocation location, BlockAxis axis); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/data/BlockAxis.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/data/BlockAxis.java new file mode 100644 index 00000000..eb976d62 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/data/BlockAxis.java @@ -0,0 +1,7 @@ +package com.sekwah.advancedportals.core.connector.data; + +public enum BlockAxis { + X, + Y, + Z +} diff --git a/spigot/build.gradle b/spigot/build.gradle index 6ca71317..9e66dc05 100644 --- a/spigot/build.gradle +++ b/spigot/build.gradle @@ -15,8 +15,10 @@ repositories { dependencies { implementation project(":core") + // For spigot api - implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT" + // We are using an older version to try and ensure that we are not using anything new older versions cant use. + implementation "org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT" implementation "net.md-5:bungeecord-api:1.16-R0.4" implementation group: 'com.google.inject', name: 'guice', version:'5.0.1' // Be careful to only use what you need to from paper, otherwise it will become incompatible with spigot. diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java index 37176a10..f707789b 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java @@ -42,7 +42,9 @@ public void onBlockPlace(BlockPlaceEvent event) { public void onItemInteract(PlayerInteractEvent event) { if (!event.isCancelled() && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) && event.getItem() != null) { Location blockloc = event.getClickedBlock().getLocation(); - boolean allowEvent = this.coreListeners.playerInteractWithBlock(new SpigotPlayerContainer(event.getPlayer()), event.getMaterial().toString(), + boolean allowEvent = this.coreListeners.playerInteractWithBlock(new SpigotPlayerContainer(event.getPlayer()), + event.getClickedBlock().getType().toString(), + event.getMaterial().toString(), event.getItem().getItemMeta().getDisplayName(), new PortalLocation(blockloc.getWorld().getName(), blockloc.getBlockX(), blockloc.getBlockY(), blockloc.getBlockZ()), event.getAction() == Action.LEFT_CLICK_BLOCK); diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java index 2cff3861..1f22a583 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotWorldContainer.java @@ -1,12 +1,13 @@ package com.sekwah.advancedportals.spigot.connector.container; import com.sekwah.advancedportals.core.connector.containers.WorldContainer; +import com.sekwah.advancedportals.core.connector.data.BlockAxis; import com.sekwah.advancedportals.core.data.BlockLocation; +import org.bukkit.Axis; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.block.BlockFace; -import org.bukkit.material.Directional; -import org.bukkit.material.MaterialData; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Orientable; public class SpigotWorldContainer implements WorldContainer { @@ -17,23 +18,35 @@ public SpigotWorldContainer(World world) { } public void setBlock(BlockLocation location, String material) { - this.world.getBlockAt(location.posX, location.posY, location.posZ).setType(Material.getMaterial(material)); - } - - public void setBlockData(BlockLocation location, byte data) { - MaterialData matData = world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData(); - if(matData instanceof Directional) { - Directional dir = (Directional) world.getBlockAt(location.posX, location.posY, location.posZ).getState().getData(); - dir.setFacingDirection(BlockFace.NORTH); - } - + Material mat = Material.getMaterial(material, false); + if(mat != null) this.world.getBlockAt(location.posX, location.posY, location.posZ).setType(mat); } public String getBlock(BlockLocation location) { return this.world.getBlockAt(location.posX, location.posY, location.posZ).getType().toString(); } - public byte getBlockData(BlockLocation location) { - return 0; + @Override + public BlockAxis getBlockAxis(BlockLocation location) { + var block = world.getBlockAt(location.posX, location.posY, location.posZ); + var matData = block.getState().getBlockData(); + if(matData instanceof Orientable rotatable) { + try { + return BlockAxis.valueOf(rotatable.getAxis().toString()); + } catch (IllegalArgumentException e) { + return null; + } + } + return null; + } + + @Override + public void setBlockAxis(BlockLocation location, BlockAxis axis) { + var block = world.getBlockAt(location.posX, location.posY, location.posZ); + var matData = block.getState().getBlockData(); + if(matData instanceof Orientable rotatable) { + rotatable.setAxis(Axis.valueOf(axis.toString())); + block.setBlockData(rotatable); + } } }