mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-02-20 14:32:29 +01:00
Fixed Sign Placement Bug!
Signs were able to be placed on the sides of storages. And some checks were missing!
This commit is contained in:
parent
a709d85917
commit
554c43b3fc
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||||
<artifactId>ChestsPlusPlus-Master</artifactId>
|
<artifactId>ChestsPlusPlus-Master</artifactId>
|
||||||
<version>1.5-BETA-5</version>
|
<version>1.5-BETA-7</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
@ -6,6 +6,7 @@ import com.jamesdpeters.minecraft.chests.runnables.ChestLinkVerifier;
|
|||||||
import com.jamesdpeters.minecraft.chests.storage.abstracts.AbstractStorage;
|
import com.jamesdpeters.minecraft.chests.storage.abstracts.AbstractStorage;
|
||||||
import com.jamesdpeters.minecraft.chests.serialize.Config;
|
import com.jamesdpeters.minecraft.chests.serialize.Config;
|
||||||
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
|
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -23,6 +24,8 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
|||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class StorageListener implements Listener {
|
public class StorageListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -35,23 +38,23 @@ public class StorageListener implements Listener {
|
|||||||
if (event.getBlockPlaced().getLocation().equals(signChangeEvent.getBlock().getLocation())) {
|
if (event.getBlockPlaced().getLocation().equals(signChangeEvent.getBlock().getLocation())) {
|
||||||
Sign sign = (Sign) signChangeEvent.getBlock().getState();
|
Sign sign = (Sign) signChangeEvent.getBlock().getState();
|
||||||
|
|
||||||
for (StorageType storageType : Config.getStorageTypes()) {
|
for (StorageType storageType : Config.getStorageTypes().stream().filter(storageType -> storageType.isValidBlockType(event.getBlockAgainst())).collect(Collectors.toList())) {
|
||||||
if(storageType.hasPermissionToAdd(event.getPlayer())) {
|
if(storageType.hasPermissionToAdd(event.getPlayer())) {
|
||||||
StorageInfo info = storageType.getStorageUtils().getStorageInfo(sign, signChangeEvent.getLines(), event.getPlayer().getUniqueId());
|
|
||||||
if (info != null) {
|
|
||||||
Location signLocation = event.getBlockPlaced().getLocation();
|
Location signLocation = event.getBlockPlaced().getLocation();
|
||||||
if (storageType.getStorageUtils().isValidSignPosition(signLocation)) {
|
if (storageType.getStorageUtils().isValidSignPosition(signLocation)) {
|
||||||
if(!storageType.add(event.getPlayer(), info.getGroup(), event.getBlockAgainst().getLocation(), info.getPlayer())){
|
StorageInfo info = storageType.getStorageUtils().getStorageInfo(sign, signChangeEvent.getLines(), event.getPlayer().getUniqueId());
|
||||||
|
if (info != null) {
|
||||||
|
if (!storageType.add(event.getPlayer(), info.getGroup(), event.getBlockAgainst().getLocation(), info.getPlayer())) {
|
||||||
sign.getBlock().breakNaturally();
|
sign.getBlock().breakNaturally();
|
||||||
done();
|
done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
storageType.getMessages().storageAdded(event.getPlayer(), signChangeEvent.getLine(1), info.getPlayer().getName());
|
storageType.getMessages().storageAdded(event.getPlayer(), signChangeEvent.getLine(1), info.getPlayer().getName());
|
||||||
signChange(sign,signChangeEvent,info.getPlayer(),event.getPlayer());
|
signChange(sign, signChangeEvent, info.getPlayer(), event.getPlayer());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
storageType.getMessages().invalidSignPlacement(event.getPlayer());
|
storageType.getMessages().invalidSignPlacement(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Messages.NO_PERMISSION(event.getPlayer());
|
Messages.NO_PERMISSION(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ public class StorageUtils<T extends StorageInfo<S>, S extends AbstractStorage> {
|
|||||||
String playerUUID = sign.getPersistentDataContainer().get(Values.playerUUID, PersistentDataType.STRING);
|
String playerUUID = sign.getPersistentDataContainer().get(Values.playerUUID, PersistentDataType.STRING);
|
||||||
String group = ChatColor.stripColor(StringUtils.substringBetween(lines[1], "[", "]"));
|
String group = ChatColor.stripColor(StringUtils.substringBetween(lines[1], "[", "]"));
|
||||||
if(playerUUID == null){
|
if(playerUUID == null){
|
||||||
|
if(uuid == null) return null;
|
||||||
playerUUID = uuid.toString();
|
playerUUID = uuid.toString();
|
||||||
if(lines[2] != null){
|
if(lines[2] != null){
|
||||||
OfflinePlayer owner = Config.getOfflinePlayer(lines[2]);
|
OfflinePlayer owner = Config.getOfflinePlayer(lines[2]);
|
||||||
@ -93,14 +94,16 @@ public class StorageUtils<T extends StorageInfo<S>, S extends AbstractStorage> {
|
|||||||
BlockFace facing = sign.getFacing().getOppositeFace();
|
BlockFace facing = sign.getFacing().getOppositeFace();
|
||||||
Block toTest = block.getRelative(facing);
|
Block toTest = block.getRelative(facing);
|
||||||
|
|
||||||
//Return if block isn't valid
|
//Check if block face is a valid place for a sign!
|
||||||
return storageType.isValidBlockType(toTest);
|
if(!storageType.getValidBlockFaces(toTest).contains(sign.getFacing())) return false;
|
||||||
|
|
||||||
// //Check if block placed against is already part of this group.
|
//Return if block isn't valid
|
||||||
// if(block.getState() instanceof Sign) {
|
if (!storageType.isValidBlockType(toTest)) return false;
|
||||||
// StorageInfo info = getStorageInfo((Sign) block.getState());
|
|
||||||
// return (info == null);
|
//Check if block placed against is already part of this group.
|
||||||
// }
|
StorageInfo info = getStorageInfo(toTest.getLocation());
|
||||||
|
System.out.println(info);
|
||||||
|
return (info == null);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,11 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
|
|||||||
public abstract String getIdentifier();
|
public abstract String getIdentifier();
|
||||||
public abstract boolean shouldDisplayArmourStands();
|
public abstract boolean shouldDisplayArmourStands();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether to drop the inventory of this storage when it's removed.
|
||||||
|
*/
|
||||||
|
public abstract boolean dropInventory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the distance from a full block to the size of the storage block. (e.g Chest is smaller than a regular block.)
|
* This is the distance from a full block to the size of the storage block. (e.g Chest is smaller than a regular block.)
|
||||||
* @return
|
* @return
|
||||||
|
@ -81,6 +81,12 @@ public abstract class StorageType<T extends AbstractStorage> {
|
|||||||
*/
|
*/
|
||||||
public abstract BlockFace getStorageFacing(Block block);
|
public abstract BlockFace getStorageFacing(Block block);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param block - the block being tested.
|
||||||
|
* @return A list of @{@link BlockFace} that are valid to place a sign on this type of storage.
|
||||||
|
*/
|
||||||
|
public abstract List<BlockFace> getValidBlockFaces(Block block);
|
||||||
|
|
||||||
public abstract StorageMessages getMessages();
|
public abstract StorageMessages getMessages();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -251,7 +257,6 @@ public abstract class StorageType<T extends AbstractStorage> {
|
|||||||
/* HELPER UTILS */
|
/* HELPER UTILS */
|
||||||
|
|
||||||
protected void placeSign(Block placedAgainst, Block toReplace, BlockFace facing, Player player, String identifier, String linkTag){
|
protected void placeSign(Block placedAgainst, Block toReplace, BlockFace facing, Player player, String identifier, String linkTag){
|
||||||
Bukkit.broadcastMessage("Placing Sign!");
|
|
||||||
if(toReplace.getType() == Material.AIR){
|
if(toReplace.getType() == Material.AIR){
|
||||||
BlockState replacedBlockState = toReplace.getState();
|
BlockState replacedBlockState = toReplace.getState();
|
||||||
|
|
||||||
|
@ -88,6 +88,11 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio
|
|||||||
return Settings.isShouldDisplayAutoCraftStand();
|
return Settings.isShouldDisplayAutoCraftStand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dropInventory() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBlockOffset() {
|
public double getBlockOffset() {
|
||||||
return -0.07;
|
return -0.07;
|
||||||
|
@ -18,10 +18,14 @@ import org.bukkit.block.BlockFace;
|
|||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class AutoCraftingStorageType extends StorageType<AutoCraftingStorage> {
|
public class AutoCraftingStorageType extends StorageType<AutoCraftingStorage> {
|
||||||
|
|
||||||
|
private static final List<BlockFace> blockfaces = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);
|
||||||
|
|
||||||
public AutoCraftingStorageType(ConfigStorage store) {
|
public AutoCraftingStorageType(ConfigStorage store) {
|
||||||
super(store);
|
super(store);
|
||||||
}
|
}
|
||||||
@ -74,8 +78,6 @@ public class AutoCraftingStorageType extends StorageType<AutoCraftingStorage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final BlockFace[] blockfaces = new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockFace getStorageFacing(Block block) {
|
public BlockFace getStorageFacing(Block block) {
|
||||||
for(BlockFace face : blockfaces){
|
for(BlockFace face : blockfaces){
|
||||||
@ -88,6 +90,11 @@ public class AutoCraftingStorageType extends StorageType<AutoCraftingStorage> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BlockFace> getValidBlockFaces(Block block) {
|
||||||
|
return blockfaces;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StorageMessages getMessages() {
|
public StorageMessages getMessages() {
|
||||||
return messages;
|
return messages;
|
||||||
|
@ -192,6 +192,11 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
|
|||||||
return Settings.isShouldDisplayChestLinkStand();
|
return Settings.isShouldDisplayChestLinkStand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dropInventory() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBlockOffset() {
|
public double getBlockOffset() {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -16,7 +16,9 @@ import org.bukkit.block.Chest;
|
|||||||
import org.bukkit.block.data.Directional;
|
import org.bukkit.block.data.Directional;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
|
public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
|
||||||
|
|
||||||
@ -79,6 +81,11 @@ public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BlockFace> getValidBlockFaces(Block block) {
|
||||||
|
return Collections.singletonList(getStorageFacing(block));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StorageMessages getMessages() {
|
public StorageMessages getMessages() {
|
||||||
return messages;
|
return messages;
|
||||||
|
Loading…
Reference in New Issue
Block a user