Disabled piston pulls
This commit is contained in:
parent
38e9c458e9
commit
716bc7c9a6
@ -46,6 +46,8 @@ public final class ExtendedPistons extends JavaPlugin {
|
|||||||
conf.set("enabled-times.Sat",new ArrayList<String>() {{add("14:00-18:00");}});
|
conf.set("enabled-times.Sat",new ArrayList<String>() {{add("14:00-18:00");}});
|
||||||
if(!conf.isSet("enabled-times.Sun"))
|
if(!conf.isSet("enabled-times.Sun"))
|
||||||
conf.set("enabled-times.Sun",new ArrayList<String>() {{add("14:00-18:00");}});
|
conf.set("enabled-times.Sun",new ArrayList<String>() {{add("14:00-18:00");}});
|
||||||
|
if(!conf.isSet("sticky-piston-pulls-chest"))
|
||||||
|
conf.set("sticky-piston-pulls-chest",true);
|
||||||
|
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
@ -88,6 +90,10 @@ public final class ExtendedPistons extends JavaPlugin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isStickyPistonPulls() {
|
||||||
|
return conf.getBoolean("sticky-piston-pulls-chest");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.*;
|
import org.bukkit.block.*;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -19,16 +18,15 @@ import java.util.Comparator;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class WorldListener implements Listener {
|
public class WorldListener implements Listener {
|
||||||
@EventHandler(priority = EventPriority.LOW,ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
public void onPistonChanged(BlockPistonExtendEvent e) {
|
public void onPistonChanged(BlockPistonExtendEvent e) {
|
||||||
if(e instanceof BlockPistonExtendedExtendEvent) return;
|
if (e instanceof BlockPistonExtendedExtendEvent) return;
|
||||||
Block block = e.getBlock();
|
Block block = e.getBlock();
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
PistonBaseMaterial piston = (PistonBaseMaterial) state.getData();
|
PistonBaseMaterial piston = (PistonBaseMaterial) state.getData();
|
||||||
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
|
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
|
||||||
|
|
||||||
ArrayList<Block> blocks = new ArrayList<>();
|
ArrayList<Block> blocks = new ArrayList<>();
|
||||||
Block toBreak = null;
|
|
||||||
boolean isMovable = true;
|
boolean isMovable = true;
|
||||||
Block firstBlock = block.getRelative(piston.getFacing());
|
Block firstBlock = block.getRelative(piston.getFacing());
|
||||||
if (firstBlock.isLiquid() || firstBlock.isEmpty()) {
|
if (firstBlock.isLiquid() || firstBlock.isEmpty()) {
|
||||||
@ -38,12 +36,12 @@ public class WorldListener implements Listener {
|
|||||||
if (b.isLiquid() || b.isEmpty()) break;
|
if (b.isLiquid() || b.isEmpty()) break;
|
||||||
if (b.getPistonMoveReaction().equals(PistonMoveReaction.IGNORE) || b.getPistonMoveReaction().equals(PistonMoveReaction.BLOCK)) {
|
if (b.getPistonMoveReaction().equals(PistonMoveReaction.IGNORE) || b.getPistonMoveReaction().equals(PistonMoveReaction.BLOCK)) {
|
||||||
if (!(b.getType() == Material.CHEST || b.getType() == Material.FURNACE || b.getType() == Material.BURNING_FURNACE)) {
|
if (!(b.getType() == Material.CHEST || b.getType() == Material.FURNACE || b.getType() == Material.BURNING_FURNACE)) {
|
||||||
isMovable = false;
|
if (ExtendedPistons.INSTANCE.isAllowedTime())
|
||||||
|
isMovable = false;
|
||||||
} else {
|
} else {
|
||||||
blocks.add(b);
|
blocks.add(b);
|
||||||
}
|
}
|
||||||
} else if(b.getPistonMoveReaction().equals(PistonMoveReaction.BREAK)) {
|
} else if (b.getPistonMoveReaction().equals(PistonMoveReaction.BREAK)) {
|
||||||
toBreak = b;
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
blocks.add(b);
|
blocks.add(b);
|
||||||
@ -61,40 +59,41 @@ public class WorldListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onRedstone(BlockRedstoneEvent e) {
|
public void onRedstone(BlockRedstoneEvent e) {
|
||||||
HashMap<BlockFace,BlockState> states = new HashMap<>();
|
HashMap<BlockFace, BlockState> states = new HashMap<>();
|
||||||
for (BlockFace face : new BlockFace[]{BlockFace.SELF, BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
|
for (BlockFace face : new BlockFace[]{BlockFace.SELF, BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
|
||||||
states.put(face,e.getBlock().getRelative(face).getState());
|
states.put(face, e.getBlock().getRelative(face).getState());
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().runTask(ExtendedPistons.INSTANCE,() -> {
|
Bukkit.getScheduler().runTask(ExtendedPistons.INSTANCE, () -> {
|
||||||
if (e.getOldCurrent() != 0 && e.getNewCurrent() == 0) {
|
if (e.getOldCurrent() != 0 && e.getNewCurrent() == 0) {
|
||||||
ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{
|
if (ExtendedPistons.INSTANCE.isStickyPistonPulls()) {
|
||||||
add(BlockFace.SELF);
|
ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{
|
||||||
add(BlockFace.UP);
|
add(BlockFace.SELF);
|
||||||
add(BlockFace.DOWN);
|
add(BlockFace.UP);
|
||||||
}};
|
add(BlockFace.DOWN);
|
||||||
if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) {
|
}};
|
||||||
for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
|
if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) {
|
||||||
Block block = e.getBlock().getRelative(blockFace);
|
for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
|
||||||
if (block.getBlockPower() == 0) checkedBlockFaces.add(blockFace);
|
Block block = e.getBlock().getRelative(blockFace);
|
||||||
|
if (block.getBlockPower() == 0) checkedBlockFaces.add(blockFace);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
checkedBlockFaces.add(BlockFace.NORTH);
|
||||||
|
checkedBlockFaces.add(BlockFace.SOUTH);
|
||||||
|
checkedBlockFaces.add(BlockFace.EAST);
|
||||||
|
checkedBlockFaces.add(BlockFace.WEST);
|
||||||
}
|
}
|
||||||
} else {
|
for (BlockFace face : checkedBlockFaces) {
|
||||||
checkedBlockFaces.add(BlockFace.NORTH);
|
Block block = e.getBlock().getRelative(face);
|
||||||
checkedBlockFaces.add(BlockFace.SOUTH);
|
BlockState state = states.get(face);
|
||||||
checkedBlockFaces.add(BlockFace.EAST);
|
if (state.getType().equals(Material.PISTON_STICKY_BASE)) {
|
||||||
checkedBlockFaces.add(BlockFace.WEST);
|
PistonBaseMaterial piston = (PistonBaseMaterial) state.getData();
|
||||||
}
|
|
||||||
for (BlockFace face : checkedBlockFaces) {
|
|
||||||
Block block = e.getBlock().getRelative(face);
|
|
||||||
BlockState state = states.get(face);
|
|
||||||
if (state.getType().equals(Material.PISTON_STICKY_BASE)) {
|
|
||||||
PistonBaseMaterial piston = (PistonBaseMaterial) state.getData();
|
|
||||||
|
|
||||||
Block b = block.getRelative(piston.getFacing(),2);
|
Block b = block.getRelative(piston.getFacing(), 2);
|
||||||
if(b.getType().equals(Material.CHEST)||b.getType().equals(Material.FURNACE)||b.getType().equals(Material.BURNING_FURNACE)) {
|
if (ExtendedPistons.INSTANCE.isAllowedTime() && (b.getType().equals(Material.CHEST) || b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE))) {
|
||||||
Block b2 = block.getRelative(piston.getFacing());
|
Block b2 = block.getRelative(piston.getFacing());
|
||||||
BlockPistonRetractEvent ev = new BlockPistonRetractEvent(block, Lists.newArrayList(b2),piston.getFacing());
|
BlockPistonRetractEvent ev = new BlockPistonRetractEvent(block, Lists.newArrayList(b2), piston.getFacing());
|
||||||
Bukkit.getPluginManager().callEvent(ev);
|
Bukkit.getPluginManager().callEvent(ev);
|
||||||
if(ev.isCancelled()) continue;
|
if (ev.isCancelled()) continue;
|
||||||
b2.setType(b.getType());
|
b2.setType(b.getType());
|
||||||
b2.setData(b.getData());
|
b2.setData(b.getData());
|
||||||
if (b.getType().equals(Material.CHEST)) {
|
if (b.getType().equals(Material.CHEST)) {
|
||||||
@ -109,6 +108,7 @@ public class WorldListener implements Listener {
|
|||||||
oldFurnace.getInventory().clear();
|
oldFurnace.getInventory().clear();
|
||||||
}
|
}
|
||||||
b.setType(Material.AIR);
|
b.setType(Material.AIR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +147,8 @@ public class WorldListener implements Listener {
|
|||||||
if (b.isLiquid() || b.isEmpty()) break;
|
if (b.isLiquid() || b.isEmpty()) break;
|
||||||
if (b.getPistonMoveReaction().equals(PistonMoveReaction.IGNORE) || b.getPistonMoveReaction().equals(PistonMoveReaction.BLOCK)) {
|
if (b.getPistonMoveReaction().equals(PistonMoveReaction.IGNORE) || b.getPistonMoveReaction().equals(PistonMoveReaction.BLOCK)) {
|
||||||
if (!(b.getType() == Material.CHEST || b.getType() == Material.FURNACE || b.getType() == Material.BURNING_FURNACE)) {
|
if (!(b.getType() == Material.CHEST || b.getType() == Material.FURNACE || b.getType() == Material.BURNING_FURNACE)) {
|
||||||
isMovable = false;
|
if (ExtendedPistons.INSTANCE.isAllowedTime())
|
||||||
|
isMovable = false;
|
||||||
} else {
|
} else {
|
||||||
blocks.add(b);
|
blocks.add(b);
|
||||||
}
|
}
|
||||||
@ -196,11 +197,11 @@ public class WorldListener implements Listener {
|
|||||||
|
|
||||||
public int findNearbyPlayerMaxBlocks(Location location) {
|
public int findNearbyPlayerMaxBlocks(Location location) {
|
||||||
Optional<? extends Player> op = Bukkit.getOnlinePlayers().stream().min(Comparator.comparingDouble(p -> p.getLocation().distance(location)));
|
Optional<? extends Player> op = Bukkit.getOnlinePlayers().stream().min(Comparator.comparingDouble(p -> p.getLocation().distance(location)));
|
||||||
if(op.isPresent()) {
|
if (op.isPresent()) {
|
||||||
String[] groups = ExtendedPistons.INSTANCE.permsService.getPlayerGroups(op.get());
|
String[] groups = ExtendedPistons.INSTANCE.permsService.getPlayerGroups(op.get());
|
||||||
for (String group : groups) {
|
for (String group : groups) {
|
||||||
if(ExtendedPistons.INSTANCE.conf.isSet("piston-move-limitations."+group)&&ExtendedPistons.INSTANCE.conf.isInt("piston-move-limitations."+group))
|
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);
|
return ExtendedPistons.INSTANCE.conf.getInt("piston-move-limitations." + group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 12;
|
return 12;
|
||||||
|
Reference in New Issue
Block a user