feat: portal placer block rotate tool

This commit is contained in:
Sekwah 2023-05-14 21:12:18 +01:00
parent d65d5dd659
commit 1c7d09469e
7 changed files with 67 additions and 33 deletions

View File

@ -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'

View File

@ -3,13 +3,15 @@ package com.sekwah.advancedportals.core;
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 class CoreListeners {
* @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 class CoreListeners {
* @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 class CoreListeners {
* @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;

View File

@ -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);
}

View File

@ -0,0 +1,7 @@
package com.sekwah.advancedportals.core.connector.data;
public enum BlockAxis {
X,
Y,
Z
}

View File

@ -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.

View File

@ -42,7 +42,9 @@ public class Listeners implements Listener {
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);

View File

@ -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 class SpigotWorldContainer implements WorldContainer {
}
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);
}
}
}