feat: portal block placing checks surrounding blocks for orientation

Also moved data to be serializeddata
This commit is contained in:
Sekwah 2023-05-14 21:31:17 +01:00
parent 1c7d09469e
commit ad1ef6cc40
32 changed files with 87 additions and 56 deletions

View File

@ -6,7 +6,7 @@ import com.sekwah.advancedportals.core.commands.CommandWithSubCommands;
import com.sekwah.advancedportals.core.commands.subcommands.desti.CreateDestiSubCommand;
import com.sekwah.advancedportals.core.commands.subcommands.portal.*;
import com.sekwah.advancedportals.core.connector.commands.CommandRegister;
import com.sekwah.advancedportals.core.data.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.module.AdvancedPortalsModule;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.util.InfoLogger;

View File

@ -3,9 +3,10 @@ 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.data.BlockAxis;
import com.sekwah.advancedportals.core.data.Direction;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.services.PortalServices;
@ -81,11 +82,17 @@ 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, "NETHER_PORTAL");
for (Direction direction : Direction.values()) {
var checkLoc = new BlockLocation(blockPos, direction);
if (world.getBlock(checkLoc).equals("NETHER_PORTAL")) {
world.setBlockAxis(blockPos, world.getBlockAxis(checkLoc));
break;
}
}
return false;
}
else if(itemInHandName.equals("\u00A78End Portal Block Placer")) {
@ -118,7 +125,6 @@ public class CoreListeners {
*/
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)) &&
itemMaterialName.equalsIgnoreCase(this.configRepository.getSelectorMaterial())
&& (!this.configRepository.getUseOnlySpecialAxe() || itemName.equals("\u00A7ePortal Region Selector"))) {

View File

@ -3,7 +3,7 @@ package com.sekwah.advancedportals.core.commands.subcommands.desti;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.util.TagReader;

View File

@ -4,7 +4,7 @@ import com.google.inject.Inject;
import com.sekwah.advancedportals.core.commands.SubCommand;
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import com.sekwah.advancedportals.core.services.PortalServices;

View File

@ -1,7 +1,7 @@
package com.sekwah.advancedportals.core.connector.containers;
import com.sekwah.advancedportals.core.data.BlockLocation;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import java.util.UUID;

View File

@ -1,7 +1,7 @@
package com.sekwah.advancedportals.core.connector.containers;
import com.sekwah.advancedportals.core.connector.data.BlockAxis;
import com.sekwah.advancedportals.core.data.BlockLocation;
import com.sekwah.advancedportals.core.data.BlockAxis;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
public interface WorldContainer {

View File

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

View File

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

View File

@ -0,0 +1,22 @@
package com.sekwah.advancedportals.core.data;
public enum Direction {
NORTH(0, 0, -1),
EAST(1, 0, 0),
SOUTH(0, 0, 1),
WEST(-1, 0, 0),
UP(0, 1, 0),
DOWN(0, -1, 0)
;
public final int x;
public final int y;
public final int z;
Direction(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}

View File

@ -2,10 +2,9 @@ package com.sekwah.advancedportals.core.destination;
import com.google.gson.annotations.SerializedName;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.TagHandler;

View File

@ -2,7 +2,7 @@ package com.sekwah.advancedportals.core.effect;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.WorldLocation;
import com.sekwah.advancedportals.core.serializeddata.WorldLocation;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
/**

View File

@ -4,7 +4,7 @@ import com.google.inject.*;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.config.Config;
import com.sekwah.advancedportals.core.config.ConfigProvider;
import com.sekwah.advancedportals.core.data.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
import com.sekwah.advancedportals.core.repository.IPortalRepository;

View File

@ -2,11 +2,9 @@ package com.sekwah.advancedportals.core.portal;
import com.google.gson.annotations.SerializedName;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.WorldLocation;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.serializeddata.WorldLocation;
import com.sekwah.advancedportals.core.registry.TagRegistry;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.TagHandler;

View File

@ -1,6 +1,6 @@
package com.sekwah.advancedportals.core.repository;
import com.sekwah.advancedportals.core.data.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
public interface ConfigRepository {

View File

@ -1,6 +1,6 @@
package com.sekwah.advancedportals.core.repository;
import com.sekwah.advancedportals.core.data.WorldLocation;
import com.sekwah.advancedportals.core.serializeddata.WorldLocation;
public interface IPortalRepository extends IJsonRepository<WorldLocation> {

View File

@ -1,8 +1,8 @@
package com.sekwah.advancedportals.core.repository;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.BlockLocation;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import java.util.UUID;

View File

@ -2,7 +2,7 @@ package com.sekwah.advancedportals.core.repository.impl;
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.config.Config;
import com.sekwah.advancedportals.core.data.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import java.util.HashMap;

View File

@ -2,7 +2,7 @@ package com.sekwah.advancedportals.core.repository.impl;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.data.WorldLocation;
import com.sekwah.advancedportals.core.serializeddata.WorldLocation;
import com.sekwah.advancedportals.core.repository.IPortalRepository;
import java.util.UUID;

View File

@ -1,6 +1,7 @@
package com.sekwah.advancedportals.core.data;
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.annotations.SerializedName;
import com.sekwah.advancedportals.core.data.Direction;
public class BlockLocation {
@ -22,4 +23,12 @@ public class BlockLocation {
this.posY = posY;
this.posZ = posZ;
}
public BlockLocation(BlockLocation location, Direction direction) {
this.worldName = location.worldName;
this.posX = location.posX + direction.x;
this.posY = location.posY + direction.y;
this.posZ = location.posZ + direction.z;
}
}

View File

@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.data;
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

View File

@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.data;
package com.sekwah.advancedportals.core.serializeddata;
public class DataTag {

View File

@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.data;
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.annotations.SerializedName;

View File

@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.data;
package com.sekwah.advancedportals.core.serializeddata;
/**
* Possibly one of the only files in this package not designed to be serialised.

View File

@ -1,4 +1,4 @@
package com.sekwah.advancedportals.core.data;
package com.sekwah.advancedportals.core.serializeddata;
import com.google.gson.annotations.SerializedName;

View File

@ -5,8 +5,8 @@ import com.google.common.collect.ImmutableMap;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.destination.Destination;
import com.sekwah.advancedportals.core.repository.IDestinationRepository;
import com.sekwah.advancedportals.core.util.Lang;

View File

@ -2,8 +2,8 @@ package com.sekwah.advancedportals.core.services;
import com.google.common.collect.ImmutableList;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import com.sekwah.advancedportals.core.portal.AdvancedPortal;
import javax.inject.Singleton;

View File

@ -1,8 +1,8 @@
package com.sekwah.advancedportals.core.services;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.data.BlockLocation;
import com.sekwah.advancedportals.core.data.PlayerTempData;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerTempData;
import javax.inject.Singleton;
import java.util.HashMap;

View File

@ -1,7 +1,7 @@
package com.sekwah.advancedportals.core.util;
import com.google.inject.Inject;
import com.sekwah.advancedportals.core.data.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import java.io.IOException;
import java.io.InputStream;

View File

@ -1,6 +1,6 @@
package com.sekwah.advancedportals.core.util;
import com.sekwah.advancedportals.core.data.DataTag;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
import java.util.ArrayList;

View File

@ -1,7 +1,7 @@
package com.sekwah.advancedportals.core.warphandler;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
/**
* Created by on 30/07/2016.

View File

@ -4,16 +4,14 @@ import com.google.inject.Inject;
import com.sekwah.advancedportals.core.AdvancedPortalsCore;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
import com.sekwah.advancedportals.core.data.BlockLocation;
import com.sekwah.advancedportals.core.data.PlayerLocation;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import com.sekwah.advancedportals.core.serializeddata.PlayerLocation;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.Wool;
import java.util.Arrays;
import java.util.UUID;

View File

@ -1,12 +1,11 @@
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 com.sekwah.advancedportals.core.data.BlockAxis;
import com.sekwah.advancedportals.core.serializeddata.BlockLocation;
import org.bukkit.Axis;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Orientable;
public class SpigotWorldContainer implements WorldContainer {