Fix 3-blocks chests, limits and hide class cast expressions
This commit is contained in:
parent
48e79a2d51
commit
160a9074c4
@ -1,4 +1,4 @@
|
||||
package ru.redguy.extendedpistons; //TODO: slime sides chests move, refactor
|
||||
package ru.redguy.extendedpistons;
|
||||
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -63,7 +63,12 @@ public class WorldListener implements Listener {
|
||||
Block block = e.getBlock().getRelative(face);
|
||||
BlockState state = states.get(face);
|
||||
if (state.getType().equals(Material.PISTON_STICKY_BASE)) {
|
||||
PistonBaseMaterial piston = (PistonBaseMaterial) state.getData();
|
||||
PistonBaseMaterial piston;
|
||||
try {
|
||||
piston = (PistonBaseMaterial) state.getData();
|
||||
} catch (ClassCastException ex) {
|
||||
continue;
|
||||
}
|
||||
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
|
||||
|
||||
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), false, maxBlocks);
|
||||
@ -81,7 +86,7 @@ public class WorldListener implements Listener {
|
||||
for (Block b : blocks) {
|
||||
Block b2 = b.getRelative(piston.getFacing().getOppositeFace());
|
||||
b2.setType(b.getType());
|
||||
b2.setData(b.getData());
|
||||
b2.setData(b.getData()); //Deprecated but powerful
|
||||
if (b.getType().equals(Material.CHEST)) {
|
||||
Chest oldChest = (Chest) b.getState();
|
||||
Chest newChest = (Chest) b2.getState();
|
||||
@ -133,7 +138,12 @@ public class WorldListener implements Listener {
|
||||
Block block = e.getBlock().getRelative(face);
|
||||
if (block.getType().equals(Material.PISTON_BASE) || block.getType().equals(Material.PISTON_STICKY_BASE)) {
|
||||
BlockState state = states.get(face);
|
||||
PistonBaseMaterial piston = (PistonBaseMaterial) state.getData();
|
||||
PistonBaseMaterial piston;
|
||||
try {
|
||||
piston = (PistonBaseMaterial) state.getData();
|
||||
} catch (ClassCastException ex) {
|
||||
continue;
|
||||
}
|
||||
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
|
||||
|
||||
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), true, maxBlocks);
|
||||
@ -143,6 +153,7 @@ public class WorldListener implements Listener {
|
||||
|
||||
upper:
|
||||
for (Block b : blocks) {
|
||||
if(b.getType().equals(Material.CHEST)) {
|
||||
Block b2 = b.getRelative(piston.getFacing());
|
||||
ArrayList<BlockFace> faces = new ArrayList<BlockFace>() {{
|
||||
add(BlockFace.NORTH);
|
||||
@ -176,6 +187,7 @@ public class WorldListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isMovable) {
|
||||
BlockPistonExtendedExtendEvent event = new BlockPistonExtendedExtendEvent(block, blocks, piston.getFacing());
|
||||
@ -188,7 +200,7 @@ public class WorldListener implements Listener {
|
||||
for (Block b : blocks) {
|
||||
Block b2 = b.getRelative(piston.getFacing());
|
||||
b2.setType(b.getType());
|
||||
b2.setData(b.getData());
|
||||
b2.setData(b.getData()); //Deprecated but powerful
|
||||
if (b.getType().equals(Material.CHEST)) {
|
||||
Chest oldChest = (Chest) b.getState();
|
||||
Chest newChest = (Chest) b2.getState();
|
||||
@ -237,7 +249,12 @@ public class WorldListener implements Listener {
|
||||
Block block = e.getBlock().getRelative(face);
|
||||
BlockState state = states.get(face);
|
||||
if (state.getType().equals(Material.PISTON_STICKY_BASE)) {
|
||||
PistonBaseMaterial piston = (PistonBaseMaterial) state.getData();
|
||||
PistonBaseMaterial piston;
|
||||
try {
|
||||
piston = (PistonBaseMaterial) state.getData();
|
||||
} catch (ClassCastException ex) {
|
||||
continue;
|
||||
}
|
||||
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
|
||||
|
||||
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), false, maxBlocks);
|
||||
@ -255,7 +272,7 @@ public class WorldListener implements Listener {
|
||||
for (Block b : blocks) {
|
||||
Block b2 = b.getRelative(piston.getFacing().getOppositeFace());
|
||||
b2.setType(b.getType());
|
||||
b2.setData(b.getData());
|
||||
b2.setData(b.getData()); //Deprecated but powerful
|
||||
if (b.getType().equals(Material.CHEST)) {
|
||||
Chest oldChest = (Chest) b.getState();
|
||||
Chest newChest = (Chest) b2.getState();
|
||||
@ -294,7 +311,12 @@ public class WorldListener implements Listener {
|
||||
Block block = e.getBlock().getRelative(face);
|
||||
if (block.getType().equals(Material.PISTON_BASE) || block.getType().equals(Material.PISTON_STICKY_BASE)) {
|
||||
BlockState state = states.get(face);
|
||||
PistonBaseMaterial piston = (PistonBaseMaterial) state.getData();
|
||||
PistonBaseMaterial piston;
|
||||
try {
|
||||
piston = (PistonBaseMaterial) state.getData();
|
||||
} catch (ClassCastException ex) {
|
||||
continue;
|
||||
}
|
||||
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
|
||||
|
||||
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), true, maxBlocks);
|
||||
@ -304,6 +326,7 @@ public class WorldListener implements Listener {
|
||||
|
||||
upper:
|
||||
for (Block b : blocks) {
|
||||
if(b.getType().equals(Material.CHEST)) {
|
||||
Block b2 = b.getRelative(piston.getFacing());
|
||||
ArrayList<BlockFace> faces = new ArrayList<BlockFace>() {{
|
||||
add(BlockFace.NORTH);
|
||||
@ -337,6 +360,7 @@ public class WorldListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isMovable) {
|
||||
BlockPistonExtendedExtendEvent event = new BlockPistonExtendedExtendEvent(block, blocks, piston.getFacing());
|
||||
@ -349,7 +373,7 @@ public class WorldListener implements Listener {
|
||||
for (Block b : blocks) {
|
||||
Block b2 = b.getRelative(piston.getFacing());
|
||||
b2.setType(b.getType());
|
||||
b2.setData(b.getData());
|
||||
b2.setData(b.getData()); //Deprecated but powerful
|
||||
if (b.getType().equals(Material.CHEST)) {
|
||||
Chest oldChest = (Chest) b.getState();
|
||||
Chest newChest = (Chest) b2.getState();
|
||||
@ -374,9 +398,9 @@ public class WorldListener implements Listener {
|
||||
Optional<? extends Player> op = Bukkit.getOnlinePlayers().stream().min(Comparator.comparingDouble(p -> p.getLocation().distance(location)));
|
||||
if (op.isPresent()) {
|
||||
String[] groups = ExtendedPistons.INSTANCE.permsService.getPlayerGroups(op.get());
|
||||
for (String group : groups) {
|
||||
if (ExtendedPistons.INSTANCE.conf.isSet("piston-move-limitations." + group) && ExtendedPistons.INSTANCE.conf.isInt("piston-move-limitations." + group))
|
||||
return ExtendedPistons.INSTANCE.conf.getInt("piston-move-limitations." + group);
|
||||
Optional<Integer> intOp = Arrays.stream(groups).map(group -> (ExtendedPistons.INSTANCE.conf.isSet("piston-move-limitations." + group) && ExtendedPistons.INSTANCE.conf.isInt("piston-move-limitations." + group))?ExtendedPistons.INSTANCE.conf.getInt("piston-move-limitations." + group):0).max(Comparator.comparingInt(i -> i));
|
||||
if(intOp.isPresent()) {
|
||||
return intOp.get()==0?12:intOp.get();
|
||||
}
|
||||
}
|
||||
return 12;
|
||||
|
Reference in New Issue
Block a user