Fixed DoubleChest not being converted when placing a sign.
Pistons can no longer push a CraftingTable that's apart of a group.
When creating a storage the type of sign the player is holding is now used.
Removed Print statements!
This commit is contained in:
jameslfc19 2020-07-08 12:26:21 +01:00
parent 554c43b3fc
commit 090d2cbaa2
6 changed files with 53 additions and 9 deletions

View File

@ -12,10 +12,6 @@ import org.bukkit.craftbukkit.v1_16_R1.block.CraftChest;
public class ChestOpener_1_16 implements ChestOpener {
public ChestOpener_1_16(){
System.out.println("Created ChestOpener v1.16!!");
}
@Override
public void setLidOpen(Chest chest, boolean open) {
CraftChest craftChest = (CraftChest) chest;

View File

@ -1,10 +1,11 @@
package com.jamesdpeters.minecraft.chests.listeners;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageInfo;
import com.jamesdpeters.minecraft.chests.misc.*;
import com.jamesdpeters.minecraft.chests.misc.Messages;
import com.jamesdpeters.minecraft.chests.misc.Values;
import com.jamesdpeters.minecraft.chests.runnables.ChestLinkVerifier;
import com.jamesdpeters.minecraft.chests.storage.abstracts.AbstractStorage;
import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.storage.abstracts.AbstractStorage;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageInfo;
import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -20,6 +21,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.persistence.PersistentDataType;
@ -49,6 +52,7 @@ public class StorageListener implements Listener {
done();
return;
}
storageType.validate(event.getBlockAgainst());
storageType.getMessages().storageAdded(event.getPlayer(), signChangeEvent.getLine(1), info.getPlayer().getName());
signChange(sign, signChangeEvent, info.getPlayer(), event.getPlayer());
}
@ -119,6 +123,32 @@ public class StorageListener implements Listener {
}
}
@EventHandler
public void onPistonMove(BlockPistonExtendEvent event){
event.getBlocks().forEach(block -> {
for(StorageType storageType : Config.getStorageTypes()){
if(storageType.isValidBlockType(block)){
Location blockLoc = block.getLocation();
AbstractStorage storage = storageType.getStorage(blockLoc);
if(storage != null) event.setCancelled(true);
}
}
});
}
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent event){
event.getBlocks().forEach(block -> {
for(StorageType storageType : Config.getStorageTypes()){
if(storageType.isValidBlockType(block)){
Location blockLoc = block.getLocation();
AbstractStorage storage = storageType.getStorage(blockLoc);
if(storage != null) event.setCancelled(true);
}
}
});
}
private void setLine(Sign sign, SignChangeEvent signChangeEvent, int i, String s){
sign.setLine(i,s);
signChangeEvent.setLine(i,s);

View File

@ -102,7 +102,6 @@ public class StorageUtils<T extends StorageInfo<S>, S extends AbstractStorage> {
//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;

View File

@ -87,6 +87,12 @@ public abstract class StorageType<T extends AbstractStorage> {
*/
public abstract List<BlockFace> getValidBlockFaces(Block block);
/**
* Used to validate the block type/data when a new storage has been added.
* For example, converting DoubleChests into a Chest.
*/
public abstract void validate(Block block);
public abstract StorageMessages getMessages();
/*
@ -260,12 +266,14 @@ public abstract class StorageType<T extends AbstractStorage> {
if(toReplace.getType() == Material.AIR){
BlockState replacedBlockState = toReplace.getState();
Material signMaterial = Material.OAK_WALL_SIGN;
if(player.getGameMode() != GameMode.CREATIVE) {
if (player.getEquipment() != null) {
if (!Tag.SIGNS.isTagged(player.getEquipment().getItemInMainHand().getType())) {
Messages.MUST_HOLD_SIGN(player);
return;
}
signMaterial = player.getEquipment().getItemInMainHand().getType();
player.getEquipment().getItemInMainHand().setAmount(player.getEquipment().getItemInMainHand().getAmount() - 1);
} else {
Messages.MUST_HOLD_SIGN(player);
@ -298,7 +306,8 @@ public abstract class StorageType<T extends AbstractStorage> {
lines[2] = owner;
}
toReplace.setType(Material.OAK_WALL_SIGN);
Material wallSign = Material.getMaterial(signMaterial.name().replace("SIGN", "WALL_SIGN"));
toReplace.setType(wallSign != null ? wallSign : Material.OAK_WALL_SIGN);
Sign sign = (Sign) toReplace.getState();
WallSign signBlockData = (WallSign) sign.getBlockData();
signBlockData.setFacing(facing);

View File

@ -95,6 +95,11 @@ public class AutoCraftingStorageType extends StorageType<AutoCraftingStorage> {
return blockfaces;
}
@Override
public void validate(Block block) {
//Doesn't do any validation.
}
@Override
public StorageMessages getMessages() {
return messages;

View File

@ -86,6 +86,11 @@ public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
return Collections.singletonList(getStorageFacing(block));
}
@Override
public void validate(Block block) {
if(block.getState() instanceof Chest) new ChestLinkVerifier(block).withDelay(0).check();
}
@Override
public StorageMessages getMessages() {
return messages;