Lock changes

This commit is contained in:
Ilya 2022-11-08 23:15:21 +03:00
parent 53854664fd
commit 36e52df8a6
6 changed files with 917 additions and 917 deletions

View File

@ -1,59 +1,59 @@
plugins { plugins {
id 'java' id 'java'
} }
group = 'ru.redguy' group = 'ru.redguy'
version = '1.0.0' version = '1.0.1'
repositories { repositories {
mavenCentral() mavenCentral()
maven { maven {
name = 'papermc-repo' name = 'papermc-repo'
url = 'https://papermc.io/repo/repository/maven-public/' url = 'https://papermc.io/repo/repository/maven-public/'
} }
maven { maven {
name = 'sonatype' name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/' url = 'https://oss.sonatype.org/content/groups/public/'
} }
maven { maven {
url = 'https://repo.redguy.ru/repository/maven-public/' url = 'https://repo.redguy.ru/repository/maven-public/'
} }
} }
dependencies { dependencies {
compileOnly 'com.destroystokyo.paper:paper-api:1.12.2-R0.1-SNAPSHOT' compileOnly 'com.destroystokyo.paper:paper-api:1.12.2-R0.1-SNAPSHOT'
compileOnly 'org.bukkit:craftbukkit:1.12.2-R0.1-20190527.155144-32' compileOnly 'org.bukkit:craftbukkit:1.12.2-R0.1-20190527.155144-32'
compileOnly "com.github.MilkBowl:VaultAPI:1.7" compileOnly "com.github.MilkBowl:VaultAPI:1.7"
compileOnly 'com.sk89q.worldguard:worldguard-legacy:6.2' compileOnly 'com.sk89q.worldguard:worldguard-legacy:6.2'
} }
def targetJavaVersion = 8 def targetJavaVersion = 8
java { java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion) def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion sourceCompatibility = javaVersion
targetCompatibility = javaVersion targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) { if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
} }
} }
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile).configureEach {
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release = targetJavaVersion options.release = targetJavaVersion
} }
} }
processResources { processResources {
def props = [version: version] def props = [version: version]
inputs.properties props inputs.properties props
filteringCharset 'UTF-8' filteringCharset 'UTF-8'
filesMatching('plugin.yml') { filesMatching('plugin.yml') {
expand props expand props
} }
} }
task copytorun(type: Copy) { task copytorun(type: Copy) {
delete file("$projectDir/Server/plugins/Extended*") delete file("$projectDir/Server/plugins/Extended*")
from file("$projectDir/build/libs/ExtendedPistons-${version}.jar") from file("$projectDir/build/libs/ExtendedPistons-${version}.jar")
into file("$projectDir/Server/plugins/") into file("$projectDir/Server/plugins/")
} }

178
gradlew.bat vendored
View File

@ -1,89 +1,89 @@
@rem @rem
@rem Copyright 2015 the original author or authors. @rem Copyright 2015 the original author or authors.
@rem @rem
@rem Licensed under the Apache License, Version 2.0 (the "License"); @rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License. @rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at @rem You may obtain a copy of the License at
@rem @rem
@rem https://www.apache.org/licenses/LICENSE-2.0 @rem https://www.apache.org/licenses/LICENSE-2.0
@rem @rem
@rem Unless required by applicable law or agreed to in writing, software @rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS, @rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter. @rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute if "%ERRORLEVEL%" == "0" goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1 exit /b 1
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal
:omega :omega

View File

@ -1,17 +1,17 @@
package ru.redguy.extendedpistons; package ru.redguy.extendedpistons;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import java.util.List; import java.util.List;
public class BlockPistonExtendedExtendEvent extends BlockPistonExtendEvent { public class BlockPistonExtendedExtendEvent extends BlockPistonExtendEvent {
public BlockPistonExtendedExtendEvent(Block block, int length, BlockFace direction) { public BlockPistonExtendedExtendEvent(Block block, int length, BlockFace direction) {
super(block, length, direction); super(block, length, direction);
} }
public BlockPistonExtendedExtendEvent(Block block, List<Block> blocks, BlockFace direction) { public BlockPistonExtendedExtendEvent(Block block, List<Block> blocks, BlockFace direction) {
super(block, blocks, direction); super(block, blocks, direction);
} }
} }

View File

@ -1,30 +1,30 @@
package ru.redguy.extendedpistons; package ru.redguy.extendedpistons;
import java.time.Instant; import java.time.Instant;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
public class Period { public class Period {
private final Instant from; private final Instant from;
private final Instant to; private final Instant to;
public Period(Date from, Date to) { public Period(Date from, Date to) {
this.from = nowtifyDate(from); this.from = nowtifyDate(from);
this.to = nowtifyDate(to); this.to = nowtifyDate(to);
} }
public boolean isBehind(Instant date) { public boolean isBehind(Instant date) {
return from.isBefore(date)&&to.isAfter(date); return from.isBefore(date)&&to.isAfter(date);
} }
public Instant nowtifyDate(Date ins) { public Instant nowtifyDate(Date ins) {
Calendar now = GregorianCalendar.getInstance(); Calendar now = GregorianCalendar.getInstance();
Calendar cal = GregorianCalendar.getInstance(); Calendar cal = GregorianCalendar.getInstance();
cal.setTime(ins); cal.setTime(ins);
cal.set(Calendar.YEAR, now.get(Calendar.YEAR)); cal.set(Calendar.YEAR, now.get(Calendar.YEAR));
cal.set(Calendar.MONTH, now.get(Calendar.MONTH)); cal.set(Calendar.MONTH, now.get(Calendar.MONTH));
cal.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH)); cal.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
return cal.getTime().toInstant(); return cal.getTime().toInstant();
} }
} }

View File

@ -1,265 +1,265 @@
package ru.redguy.extendedpistons; package ru.redguy.extendedpistons;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.minecraft.server.v1_12_R1.*; import net.minecraft.server.v1_12_R1.*;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class PistonExtendsChecker { public class PistonExtendsChecker {
private final net.minecraft.server.v1_12_R1.World a; private final net.minecraft.server.v1_12_R1.World a;
private final BlockPosition b; private final BlockPosition b;
private final BlockPosition c; private final BlockPosition c;
private final EnumDirection d; private final EnumDirection d;
private final List<BlockPosition> e = Lists.newArrayList(); private final List<BlockPosition> e = Lists.newArrayList();
private final List<BlockPosition> f = Lists.newArrayList(); private final List<BlockPosition> f = Lists.newArrayList();
private org.bukkit.World bw; private org.bukkit.World bw;
private int maxLength; private int maxLength;
private PistonExtendsChecker(World var1, BlockPosition var2, EnumDirection var3, boolean var4) { private PistonExtendsChecker(World var1, BlockPosition var2, EnumDirection var3, boolean var4) {
this.a = var1; this.a = var1;
this.b = var2; this.b = var2;
if (var4) { if (var4) {
this.d = var3; this.d = var3;
this.c = var2.shift(var3); this.c = var2.shift(var3);
} else { } else {
this.d = var3.opposite(); this.d = var3.opposite();
this.c = var2.shift(var3, 2); this.c = var2.shift(var3, 2);
} }
} }
public PistonExtendsChecker(org.bukkit.World var1, Location var2, BlockFace var3, boolean var4, int maxLength) { public PistonExtendsChecker(org.bukkit.World var1, Location var2, BlockFace var3, boolean var4, int maxLength) {
this(((CraftWorld)var1).getHandle(),new BlockPosition(var2.getBlockX(),var2.getBlockY(),var2.getBlockZ()),cast(var3),var4); this(((CraftWorld)var1).getHandle(),new BlockPosition(var2.getBlockX(),var2.getBlockY(),var2.getBlockZ()),cast(var3),var4);
this.bw = var1; this.bw = var1;
this.maxLength = maxLength; this.maxLength = maxLength;
} }
public boolean a() { public boolean a() {
this.e.clear(); this.e.clear();
this.f.clear(); this.f.clear();
IBlockData var1 = this.a.getType(this.c); IBlockData var1 = this.a.getType(this.c);
if (!BlockPiston.a(var1, this.a, this.c, this.d, false, this.d)) { if (!BlockPiston.a(var1, this.a, this.c, this.d, false, this.d)) {
if (var1.o() == EnumPistonReaction.DESTROY) { if (var1.o() == EnumPistonReaction.DESTROY) {
this.f.add(this.c); this.f.add(this.c);
return true; return true;
} else { } else {
return false; return false;
} }
} else if (!this.a(this.c, this.d)) { } else if (!this.a(this.c, this.d)) {
return false; return false;
} else { } else {
for(int var2 = 0; var2 < this.e.size(); ++var2) { for(int var2 = 0; var2 < this.e.size(); ++var2) {
BlockPosition var3 = (BlockPosition)this.e.get(var2); BlockPosition var3 = (BlockPosition)this.e.get(var2);
if (this.a.getType(var3).getBlock() == Blocks.SLIME && !this.a(var3)) { if (this.a.getType(var3).getBlock() == Blocks.SLIME && !this.a(var3)) {
return false; return false;
} }
} }
return true; return true;
} }
} }
private boolean a(BlockPosition var1, EnumDirection var2) { private boolean a(BlockPosition var1, EnumDirection var2) {
IBlockData var3 = this.a.getType(var1); IBlockData var3 = this.a.getType(var1);
Block var4 = var3.getBlock(); Block var4 = var3.getBlock();
if (var3.getMaterial() == Material.AIR) { if (var3.getMaterial() == Material.AIR) {
return true; return true;
} else if (!BlockPiston.a(var3, this.a, var1, this.d, false, var2)) { } else if (!BlockPiston.a(var3, this.a, var1, this.d, false, var2)) {
return true; return true;
} else if (var1.equals(this.b)) { } else if (var1.equals(this.b)) {
return true; return true;
} else if (this.e.contains(var1)) { } else if (this.e.contains(var1)) {
return true; return true;
} else { } else {
int var5 = 1; int var5 = 1;
if (var5 + this.e.size() > maxLength) { if (var5 + this.e.size() > maxLength) {
return false; return false;
} else { } else {
while(var4 == Blocks.SLIME) { while(var4 == Blocks.SLIME) {
BlockPosition var6 = var1.shift(this.d.opposite(), var5); BlockPosition var6 = var1.shift(this.d.opposite(), var5);
var3 = this.a.getType(var6); var3 = this.a.getType(var6);
var4 = var3.getBlock(); var4 = var3.getBlock();
if (var3.getMaterial() == Material.AIR || !BlockPiston.a(var3, this.a, var6, this.d, false, this.d.opposite()) || var6.equals(this.b)) { if (var3.getMaterial() == Material.AIR || !BlockPiston.a(var3, this.a, var6, this.d, false, this.d.opposite()) || var6.equals(this.b)) {
break; break;
} }
++var5; ++var5;
if (var5 + this.e.size() > maxLength) { if (var5 + this.e.size() > maxLength) {
return false; return false;
} }
} }
int var12 = 0; int var12 = 0;
int var7; int var7;
for(var7 = var5 - 1; var7 >= 0; --var7) { for(var7 = var5 - 1; var7 >= 0; --var7) {
this.e.add(var1.shift(this.d.opposite(), var7)); this.e.add(var1.shift(this.d.opposite(), var7));
++var12; ++var12;
} }
var7 = 1; var7 = 1;
while(true) { while(true) {
BlockPosition var8 = var1.shift(this.d, var7); BlockPosition var8 = var1.shift(this.d, var7);
int var9 = this.e.indexOf(var8); int var9 = this.e.indexOf(var8);
if (var9 > -1) { if (var9 > -1) {
this.a(var12, var9); this.a(var12, var9);
for(int var10 = 0; var10 <= var9 + var12; ++var10) { for(int var10 = 0; var10 <= var9 + var12; ++var10) {
BlockPosition var11 = (BlockPosition)this.e.get(var10); BlockPosition var11 = (BlockPosition)this.e.get(var10);
if (this.a.getType(var11).getBlock() == Blocks.SLIME && !this.a(var11)) { if (this.a.getType(var11).getBlock() == Blocks.SLIME && !this.a(var11)) {
return false; return false;
} }
} }
return true; return true;
} }
var3 = this.a.getType(var8); var3 = this.a.getType(var8);
if (var3.getMaterial() == Material.AIR) { if (var3.getMaterial() == Material.AIR) {
return true; return true;
} }
if (!BlockPiston.a(var3, this.a, var8, this.d, true, this.d) || var8.equals(this.b)) { if (!BlockPiston.a(var3, this.a, var8, this.d, true, this.d) || var8.equals(this.b)) {
return false; return false;
} }
if (var3.o() == EnumPistonReaction.DESTROY) { if (var3.o() == EnumPistonReaction.DESTROY) {
this.f.add(var8); this.f.add(var8);
return true; return true;
} }
if (this.e.size() >= maxLength) { if (this.e.size() >= maxLength) {
return false; return false;
} }
this.e.add(var8); this.e.add(var8);
++var12; ++var12;
++var7; ++var7;
} }
} }
} }
} }
private void a(int var1, int var2) { private void a(int var1, int var2) {
ArrayList var3 = Lists.newArrayList(); ArrayList var3 = Lists.newArrayList();
ArrayList var4 = Lists.newArrayList(); ArrayList var4 = Lists.newArrayList();
ArrayList var5 = Lists.newArrayList(); ArrayList var5 = Lists.newArrayList();
var3.addAll(this.e.subList(0, var2)); var3.addAll(this.e.subList(0, var2));
var4.addAll(this.e.subList(this.e.size() - var1, this.e.size())); var4.addAll(this.e.subList(this.e.size() - var1, this.e.size()));
var5.addAll(this.e.subList(var2, this.e.size() - var1)); var5.addAll(this.e.subList(var2, this.e.size() - var1));
this.e.clear(); this.e.clear();
this.e.addAll(var3); this.e.addAll(var3);
this.e.addAll(var4); this.e.addAll(var4);
this.e.addAll(var5); this.e.addAll(var5);
} }
private boolean a(BlockPosition var1) { private boolean a(BlockPosition var1) {
EnumDirection[] var2 = EnumDirection.values(); EnumDirection[] var2 = EnumDirection.values();
int var3 = var2.length; int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) { for(int var4 = 0; var4 < var3; ++var4) {
EnumDirection var5 = var2[var4]; EnumDirection var5 = var2[var4];
if (var5.k() != this.d.k() && !this.a(var1.shift(var5), var5)) { if (var5.k() != this.d.k() && !this.a(var1.shift(var5), var5)) {
return false; return false;
} }
} }
return true; return true;
} }
public List<BlockPosition> getMovedBlocks() { public List<BlockPosition> getMovedBlocks() {
return this.e; return this.e;
} }
public List<BlockPosition> getBrokenBlocks() { public List<BlockPosition> getBrokenBlocks() {
return this.f; return this.f;
} }
public List<Location> getMovedBlocksLocations() { public List<Location> getMovedBlocksLocations() {
return this.e.stream().map(bp -> new Location(bw,bp.getX(),bp.getY(),bp.getZ())).collect(Collectors.toList()); return this.e.stream().map(bp -> new Location(bw,bp.getX(),bp.getY(),bp.getZ())).collect(Collectors.toList());
} }
public List<Location> getBrokenBlocksLocations() { public List<Location> getBrokenBlocksLocations() {
return this.f.stream().map(bp -> new Location(bw,bp.getX(),bp.getY(),bp.getZ())).collect(Collectors.toList()); return this.f.stream().map(bp -> new Location(bw,bp.getX(),bp.getY(),bp.getZ())).collect(Collectors.toList());
} }
public List<org.bukkit.block.Block> getMovedBlocksObjects() { public List<org.bukkit.block.Block> getMovedBlocksObjects() {
return this.e.stream().map(bp -> bw.getBlockAt(bp.getX(),bp.getY(),bp.getZ())).collect(Collectors.toList()); return this.e.stream().map(bp -> bw.getBlockAt(bp.getX(),bp.getY(),bp.getZ())).collect(Collectors.toList());
} }
public List<org.bukkit.block.Block> getBrokenBlocksObjects() { public List<org.bukkit.block.Block> getBrokenBlocksObjects() {
return this.f.stream().map(bp -> bw.getBlockAt(bp.getX(),bp.getY(),bp.getZ())).collect(Collectors.toList()); return this.f.stream().map(bp -> bw.getBlockAt(bp.getX(),bp.getY(),bp.getZ())).collect(Collectors.toList());
} }
public static EnumDirection cast(BlockFace face) { public static EnumDirection cast(BlockFace face) {
switch (face) { switch (face) {
case UP: case UP:
return EnumDirection.UP; return EnumDirection.UP;
case DOWN: case DOWN:
return EnumDirection.DOWN; return EnumDirection.DOWN;
case WEST: case WEST:
return EnumDirection.WEST; return EnumDirection.WEST;
case SOUTH: case SOUTH:
return EnumDirection.SOUTH; return EnumDirection.SOUTH;
case NORTH: case NORTH:
return EnumDirection.NORTH; return EnumDirection.NORTH;
case EAST: case EAST:
return EnumDirection.EAST; return EnumDirection.EAST;
} }
return null; return null;
} }
public static class BlockPiston { public static class BlockPiston {
public static boolean a(IBlockData iblockdata, World world, BlockPosition blockposition, EnumDirection enumdirection, boolean flag, EnumDirection enumdirection1) { public static boolean a(IBlockData iblockdata, World world, BlockPosition blockposition, EnumDirection enumdirection, boolean flag, EnumDirection enumdirection1) {
Block block = iblockdata.getBlock(); Block block = iblockdata.getBlock();
if (block == Blocks.OBSIDIAN) { if (block == Blocks.OBSIDIAN) {
return false; return false;
} else if (!world.getWorldBorder().a(blockposition)) { } else if (!world.getWorldBorder().a(blockposition)) {
return false; return false;
} else if (blockposition.getY() < 0 || enumdirection == EnumDirection.DOWN && blockposition.getY() == 0) { } else if (blockposition.getY() < 0 || enumdirection == EnumDirection.DOWN && blockposition.getY() == 0) {
return false; return false;
} else if (blockposition.getY() > world.getHeight() - 1 || enumdirection == EnumDirection.UP && blockposition.getY() == world.getHeight() - 1) { } else if (blockposition.getY() > world.getHeight() - 1 || enumdirection == EnumDirection.UP && blockposition.getY() == world.getHeight() - 1) {
return false; return false;
} else { } else {
if (block != Blocks.PISTON && block != Blocks.STICKY_PISTON) { if (block != Blocks.PISTON && block != Blocks.STICKY_PISTON) {
if (iblockdata.b(world, blockposition) == -1.0F) { if (iblockdata.b(world, blockposition) == -1.0F) {
return false; return false;
} }
switch(iblockdata.o().ordinal()) { switch(iblockdata.o().ordinal()) {
case 2: case 2:
return flag; return flag;
case 3: case 3:
return false; return false;
case 4: case 4:
default: default:
break; break;
case 5: case 5:
if (enumdirection == enumdirection1) { if (enumdirection == enumdirection1) {
return true; return true;
} }
return false; return false;
} }
} else if ((Boolean)iblockdata.get(net.minecraft.server.v1_12_R1.BlockPiston.EXTENDED)) { } else if ((Boolean)iblockdata.get(net.minecraft.server.v1_12_R1.BlockPiston.EXTENDED)) {
return false; return false;
} }
if(block.isTileEntity()) { if(block.isTileEntity()) {
if(block == Blocks.CHEST || block == Blocks.FURNACE || block == Blocks.LIT_FURNACE) { if(block == Blocks.CHEST || block == Blocks.FURNACE || block == Blocks.LIT_FURNACE) {
return ExtendedPistons.INSTANCE.isAllowedTime(); return ExtendedPistons.INSTANCE.isAllowedTime();
} else { } else {
return false; return false;
} }
} else { } else {
return true; return true;
} }
} }
} }
} }
} }

View File

@ -1,458 +1,458 @@
package ru.redguy.extendedpistons; package ru.redguy.extendedpistons;
import com.sk89q.worldguard.bukkit.RegionContainer; import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.RegionQuery; import com.sk89q.worldguard.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.DefaultFlag;
import org.bukkit.Bukkit; 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.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;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.*; import org.bukkit.event.block.*;
import org.bukkit.inventory.DoubleChestInventory; import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.material.PistonBaseMaterial; import org.bukkit.material.PistonBaseMaterial;
import java.util.Comparator; 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.getBlocks().size()>0) e.setCancelled(true); if(e.getBlocks().size()>0) e.setCancelled(true);
/*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());
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), e.getBlock().getLocation(), piston.getFacing(), true, maxBlocks); PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), e.getBlock().getLocation(), piston.getFacing(), true, maxBlocks);
if (!checker.a()) { if (!checker.a()) {
e.setCancelled(true); e.setCancelled(true);
}*/ }*/
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPistonChanged(BlockPistonRetractEvent e) { public void onPistonChanged(BlockPistonRetractEvent e) {
if(e.getBlocks().size()>0) e.setCancelled(true); if(e.getBlocks().size()>0) e.setCancelled(true);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) { public void onBlockBreak(BlockBreakEvent e) {
Material blockType = e.getBlock().getType(); Material blockType = e.getBlock().getType();
if (!(blockType.equals(Material.REDSTONE_BLOCK) || blockType.equals(Material.REDSTONE_TORCH_ON))) return; if (!(blockType.equals(Material.REDSTONE_BLOCK) || blockType.equals(Material.REDSTONE_TORCH_ON))) return;
HashMap<BlockFace, BlockState> states = new HashMap<>(); HashMap<BlockFace, BlockState> states = new HashMap<>();
HashMap<BlockFace, Integer> powers = new HashMap<>(); HashMap<BlockFace, Integer> powers = 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());
powers.put(face, e.getBlock().getRelative(face).getBlockPower()); powers.put(face, e.getBlock().getRelative(face).getBlockPower());
} }
Bukkit.getScheduler().runTask(ExtendedPistons.INSTANCE, () -> { Bukkit.getScheduler().runTask(ExtendedPistons.INSTANCE, () -> {
if (ExtendedPistons.INSTANCE.isStickyPistonPulls()) { if (ExtendedPistons.INSTANCE.isStickyPistonPulls()) {
ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{ ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{
add(BlockFace.SELF); add(BlockFace.SELF);
add(BlockFace.UP); add(BlockFace.UP);
add(BlockFace.DOWN); add(BlockFace.DOWN);
}}; }};
if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) { if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) {
for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) { for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
Block block = e.getBlock().getRelative(blockFace); Block block = e.getBlock().getRelative(blockFace);
if (block.getBlockPower() == 0 && powers.get(blockFace) != 0) checkedBlockFaces.add(blockFace); if (block.getBlockPower() == 0 && powers.get(blockFace) != 0) checkedBlockFaces.add(blockFace);
} }
} else { } else {
checkedBlockFaces.add(BlockFace.NORTH); checkedBlockFaces.add(BlockFace.NORTH);
checkedBlockFaces.add(BlockFace.SOUTH); checkedBlockFaces.add(BlockFace.SOUTH);
checkedBlockFaces.add(BlockFace.EAST); checkedBlockFaces.add(BlockFace.EAST);
checkedBlockFaces.add(BlockFace.WEST); checkedBlockFaces.add(BlockFace.WEST);
} }
for (BlockFace face : checkedBlockFaces) { for (BlockFace face : checkedBlockFaces) {
Block block = e.getBlock().getRelative(face); Block block = e.getBlock().getRelative(face);
BlockState state = states.get(face); BlockState state = states.get(face);
if (state.getType().equals(Material.PISTON_STICKY_BASE)) { if (state.getType().equals(Material.PISTON_STICKY_BASE)) {
PistonBaseMaterial piston; PistonBaseMaterial piston;
try { try {
piston = (PistonBaseMaterial) state.getData(); piston = (PistonBaseMaterial) state.getData();
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
continue; continue;
} }
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation()); int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), false, maxBlocks); PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), false, maxBlocks);
boolean isMovable = checker.a(); boolean isMovable = checker.a();
List<Block> blocks = checker.getMovedBlocksObjects(); List<Block> blocks = checker.getMovedBlocksObjects();
List<Block> toBreak = checker.getBrokenBlocksObjects(); List<Block> toBreak = checker.getBrokenBlocksObjects();
if (isMovable) { if (isMovable) {
if (!isBlocksAllowedToInteract(copyWithAdd(blocks, toBreak), piston.getFacing())) continue; if (!isBlocksAllowedToInteract(copyWithAdd(blocks, toBreak), piston.getFacing())) continue;
Collections.reverse(blocks); Collections.reverse(blocks);
for (Block block1 : toBreak) { for (Block block1 : toBreak) {
block1.breakNaturally(); block1.breakNaturally();
} }
for (Block b : blocks) { for (Block b : blocks) {
Block b2 = b.getRelative(piston.getFacing().getOppositeFace()); Block b2 = b.getRelative(piston.getFacing().getOppositeFace());
b2.setType(b.getType()); b2.setType(b.getType());
b2.setData(b.getData()); //Deprecated but powerful b2.setData(b.getData()); //Deprecated but powerful
if (b.getType().equals(Material.CHEST)) { if (b.getType().equals(Material.CHEST)) {
Chest oldChest = (Chest) b.getState(); Chest oldChest = (Chest) b.getState();
Chest newChest = (Chest) b2.getState(); Chest newChest = (Chest) b2.getState();
newChest.getBlockInventory().setContents(oldChest.getBlockInventory().getContents()); newChest.getBlockInventory().setContents(oldChest.getBlockInventory().getContents());
oldChest.getBlockInventory().clear(); oldChest.getBlockInventory().clear();
} else if (b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE)) { } else if (b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE)) {
Furnace oldFurnace = (Furnace) b.getState(); Furnace oldFurnace = (Furnace) b.getState();
Furnace newFurnace = (Furnace) b2.getState(); Furnace newFurnace = (Furnace) b2.getState();
newFurnace.getInventory().setContents(oldFurnace.getInventory().getContents()); newFurnace.getInventory().setContents(oldFurnace.getInventory().getContents());
oldFurnace.getInventory().clear(); oldFurnace.getInventory().clear();
} }
b.setType(Material.AIR); b.setType(Material.AIR);
} }
} }
} }
} }
} }
}); });
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) { public void onBlockPlace(BlockPlaceEvent e) {
Material blockType = e.getBlock().getType(); Material blockType = e.getBlock().getType();
if (!(blockType.equals(Material.REDSTONE_BLOCK) || blockType.equals(Material.REDSTONE_TORCH_ON))) return; if (!(blockType.equals(Material.REDSTONE_BLOCK) || blockType.equals(Material.REDSTONE_TORCH_ON))) return;
HashMap<BlockFace, BlockState> states = new HashMap<>(); HashMap<BlockFace, BlockState> states = new HashMap<>();
HashMap<BlockFace, Integer> powers = new HashMap<>(); HashMap<BlockFace, Integer> powers = 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());
powers.put(face, e.getBlock().getRelative(face).getBlockPower()); powers.put(face, e.getBlock().getRelative(face).getBlockPower());
} }
Bukkit.getScheduler().runTask(ExtendedPistons.INSTANCE, () -> { Bukkit.getScheduler().runTask(ExtendedPistons.INSTANCE, () -> {
ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{ ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{
add(BlockFace.SELF); add(BlockFace.SELF);
add(BlockFace.UP); add(BlockFace.UP);
add(BlockFace.DOWN); add(BlockFace.DOWN);
}}; }};
if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) { if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) {
for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) { for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
Block block = e.getBlock().getRelative(blockFace); Block block = e.getBlock().getRelative(blockFace);
if (block.getBlockPower() != 0 && powers.get(blockFace) == 0) checkedBlockFaces.add(blockFace); if (block.getBlockPower() != 0 && powers.get(blockFace) == 0) checkedBlockFaces.add(blockFace);
} }
} else { } else {
checkedBlockFaces.add(BlockFace.NORTH); checkedBlockFaces.add(BlockFace.NORTH);
checkedBlockFaces.add(BlockFace.SOUTH); checkedBlockFaces.add(BlockFace.SOUTH);
checkedBlockFaces.add(BlockFace.EAST); checkedBlockFaces.add(BlockFace.EAST);
checkedBlockFaces.add(BlockFace.WEST); checkedBlockFaces.add(BlockFace.WEST);
} }
for (BlockFace face : checkedBlockFaces) { for (BlockFace face : checkedBlockFaces) {
Block block = e.getBlock().getRelative(face); Block block = e.getBlock().getRelative(face);
if (block.getType().equals(Material.PISTON_BASE) || block.getType().equals(Material.PISTON_STICKY_BASE)) { if (block.getType().equals(Material.PISTON_BASE) || block.getType().equals(Material.PISTON_STICKY_BASE)) {
BlockState state = states.get(face); BlockState state = states.get(face);
PistonBaseMaterial piston; PistonBaseMaterial piston;
try { try {
piston = (PistonBaseMaterial) state.getData(); piston = (PistonBaseMaterial) state.getData();
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
continue; continue;
} }
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation()); int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), true, maxBlocks); PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), true, maxBlocks);
boolean isMovable = checker.a(); boolean isMovable = checker.a();
List<Block> blocks = checker.getMovedBlocksObjects(); List<Block> blocks = checker.getMovedBlocksObjects();
List<Block> toBreak = checker.getBrokenBlocksObjects(); List<Block> toBreak = checker.getBrokenBlocksObjects();
upper: upper:
for (Block b : blocks) { for (Block b : blocks) {
if (b.getType().equals(Material.CHEST)) { if (b.getType().equals(Material.CHEST)) {
Block b2 = b.getRelative(piston.getFacing()); Block b2 = b.getRelative(piston.getFacing());
ArrayList<BlockFace> faces = new ArrayList<BlockFace>() {{ ArrayList<BlockFace> faces = new ArrayList<BlockFace>() {{
add(BlockFace.NORTH); add(BlockFace.NORTH);
add(BlockFace.SOUTH); add(BlockFace.SOUTH);
add(BlockFace.WEST); add(BlockFace.WEST);
add(BlockFace.EAST); add(BlockFace.EAST);
}}; }};
faces.remove(piston.getFacing().getOppositeFace()); faces.remove(piston.getFacing().getOppositeFace());
int chests = 0; int chests = 0;
for (BlockFace blockFace : faces) { for (BlockFace blockFace : faces) {
Block b3 = b2.getRelative(blockFace); Block b3 = b2.getRelative(blockFace);
if (b3.getType() == Material.CHEST) { if (b3.getType() == Material.CHEST) {
chests++; chests++;
Chest chest = (Chest) b3.getState(); Chest chest = (Chest) b3.getState();
if (chest.getInventory() instanceof DoubleChestInventory) { if (chest.getInventory() instanceof DoubleChestInventory) {
isMovable = false; isMovable = false;
break upper; break upper;
} }
} }
} }
if (chests > 1) { if (chests > 1) {
isMovable = false; isMovable = false;
break; break;
} else if (chests == 1) { } else if (chests == 1) {
if (b.getType() == Material.CHEST) { if (b.getType() == Material.CHEST) {
Chest chest = (Chest) b.getState(); Chest chest = (Chest) b.getState();
if (chest.getInventory() instanceof DoubleChestInventory) { if (chest.getInventory() instanceof DoubleChestInventory) {
isMovable = false; isMovable = false;
break; break;
} }
} }
} }
} }
} }
if (isMovable) { if (isMovable) {
if (!isBlocksAllowedToInteract(copyWithAdd(blocks, toBreak), piston.getFacing())) return; if (!isBlocksAllowedToInteract(copyWithAdd(blocks, toBreak), piston.getFacing())) return;
Collections.reverse(blocks); Collections.reverse(blocks);
for (Block block1 : toBreak) { for (Block block1 : toBreak) {
block1.breakNaturally(); block1.breakNaturally();
} }
for (Block b : blocks) { for (Block b : blocks) {
Block b2 = b.getRelative(piston.getFacing()); Block b2 = b.getRelative(piston.getFacing());
b2.setType(b.getType()); b2.setType(b.getType());
b2.setData(b.getData()); //Deprecated but powerful b2.setData(b.getData()); //Deprecated but powerful
if (b.getType().equals(Material.CHEST)) { if (b.getType().equals(Material.CHEST)) {
Chest oldChest = (Chest) b.getState(); Chest oldChest = (Chest) b.getState();
Chest newChest = (Chest) b2.getState(); Chest newChest = (Chest) b2.getState();
newChest.getBlockInventory().setContents(oldChest.getBlockInventory().getContents()); newChest.getBlockInventory().setContents(oldChest.getBlockInventory().getContents());
oldChest.getBlockInventory().clear(); oldChest.getBlockInventory().clear();
} else if (b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE)) { } else if (b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE)) {
Furnace oldFurnace = (Furnace) b.getState(); Furnace oldFurnace = (Furnace) b.getState();
Furnace newFurnace = (Furnace) b2.getState(); Furnace newFurnace = (Furnace) b2.getState();
newFurnace.getInventory().setContents(oldFurnace.getInventory().getContents()); newFurnace.getInventory().setContents(oldFurnace.getInventory().getContents());
oldFurnace.getInventory().clear(); oldFurnace.getInventory().clear();
} }
b.setType(Material.AIR); b.setType(Material.AIR);
} }
} }
} }
} }
}); });
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onRedstone(BlockRedstoneEvent e) { public void onRedstone(BlockRedstoneEvent e) {
HashMap<BlockFace, HashMap<BlockFace,BlockState>> states = new HashMap<>(); HashMap<BlockFace, 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, new HashMap<>()); states.put(face, new HashMap<>());
for (BlockFace blockFace : new BlockFace[]{BlockFace.UP, BlockFace.SELF, BlockFace.DOWN}) { for (BlockFace blockFace : new BlockFace[]{BlockFace.UP, BlockFace.SELF, BlockFace.DOWN}) {
states.get(face).put(blockFace,e.getBlock().getRelative(face).getRelative(blockFace).getState()); states.get(face).put(blockFace,e.getBlock().getRelative(face).getRelative(blockFace).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) {
if (ExtendedPistons.INSTANCE.isStickyPistonPulls()) { if (ExtendedPistons.INSTANCE.isStickyPistonPulls()) {
ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{ ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{
add(BlockFace.SELF); add(BlockFace.SELF);
add(BlockFace.UP); add(BlockFace.UP);
add(BlockFace.DOWN); add(BlockFace.DOWN);
}}; }};
if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) { if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) {
for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) { for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
Block block = e.getBlock().getRelative(blockFace); Block block = e.getBlock().getRelative(blockFace);
if (block.getBlockPower() == 0) checkedBlockFaces.add(blockFace); if (block.getBlockPower() == 0) checkedBlockFaces.add(blockFace);
} }
} else { } else {
checkedBlockFaces.add(BlockFace.NORTH); checkedBlockFaces.add(BlockFace.NORTH);
checkedBlockFaces.add(BlockFace.SOUTH); checkedBlockFaces.add(BlockFace.SOUTH);
checkedBlockFaces.add(BlockFace.EAST); checkedBlockFaces.add(BlockFace.EAST);
checkedBlockFaces.add(BlockFace.WEST); checkedBlockFaces.add(BlockFace.WEST);
} }
for (BlockFace face : checkedBlockFaces) { for (BlockFace face : checkedBlockFaces) {
ArrayList<BlockFace> subs = new ArrayList<BlockFace>() {{ ArrayList<BlockFace> subs = new ArrayList<BlockFace>() {{
add(BlockFace.SELF); add(BlockFace.SELF);
}}; }};
if (e.getBlock().getType().equals(Material.LEVER)) { if (e.getBlock().getType().equals(Material.LEVER)) {
subs.add(BlockFace.UP); subs.add(BlockFace.UP);
subs.add(BlockFace.DOWN); subs.add(BlockFace.DOWN);
} }
for (BlockFace sub : subs) { for (BlockFace sub : subs) {
Block block = e.getBlock().getRelative(face); Block block = e.getBlock().getRelative(face);
block = block.getRelative(sub); block = block.getRelative(sub);
BlockState state = states.get(face).get(sub); BlockState state = states.get(face).get(sub);
if (state.getType().equals(Material.PISTON_STICKY_BASE)) { if (state.getType().equals(Material.PISTON_STICKY_BASE)) {
PistonBaseMaterial piston; PistonBaseMaterial piston;
try { try {
piston = (PistonBaseMaterial) state.getData(); piston = (PistonBaseMaterial) state.getData();
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
continue; continue;
} }
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation()); int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), false, maxBlocks); PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), false, maxBlocks);
boolean isMovable = checker.a(); boolean isMovable = checker.a();
List<Block> blocks = checker.getMovedBlocksObjects(); List<Block> blocks = checker.getMovedBlocksObjects();
List<Block> toBreak = checker.getBrokenBlocksObjects(); List<Block> toBreak = checker.getBrokenBlocksObjects();
if (isMovable) { if (isMovable) {
Collections.reverse(blocks); Collections.reverse(blocks);
if (!isBlocksAllowedToInteract(copyWithAdd(blocks, toBreak), piston.getFacing())) if (!isBlocksAllowedToInteract(copyWithAdd(blocks, toBreak), piston.getFacing()))
continue; continue;
for (Block block1 : toBreak) { for (Block block1 : toBreak) {
block1.breakNaturally(); block1.breakNaturally();
} }
for (Block b : blocks) { for (Block b : blocks) {
Block b2 = b.getRelative(piston.getFacing().getOppositeFace()); Block b2 = b.getRelative(piston.getFacing().getOppositeFace());
b2.setType(b.getType()); b2.setType(b.getType());
b2.setData(b.getData()); //Deprecated but powerful b2.setData(b.getData()); //Deprecated but powerful
if (b.getType().equals(Material.CHEST)) { if (b.getType().equals(Material.CHEST)) {
Chest oldChest = (Chest) b.getState(); Chest oldChest = (Chest) b.getState();
Chest newChest = (Chest) b2.getState(); Chest newChest = (Chest) b2.getState();
newChest.getBlockInventory().setContents(oldChest.getBlockInventory().getContents()); newChest.getBlockInventory().setContents(oldChest.getBlockInventory().getContents());
oldChest.getBlockInventory().clear(); oldChest.getBlockInventory().clear();
} else if (b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE)) { } else if (b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE)) {
Furnace oldFurnace = (Furnace) b.getState(); Furnace oldFurnace = (Furnace) b.getState();
Furnace newFurnace = (Furnace) b2.getState(); Furnace newFurnace = (Furnace) b2.getState();
newFurnace.getInventory().setContents(oldFurnace.getInventory().getContents()); newFurnace.getInventory().setContents(oldFurnace.getInventory().getContents());
oldFurnace.getInventory().clear(); oldFurnace.getInventory().clear();
} }
b.setType(Material.AIR); b.setType(Material.AIR);
} }
} }
} }
} }
} }
} }
} else { } else {
ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{ ArrayList<BlockFace> checkedBlockFaces = new ArrayList<BlockFace>() {{
add(BlockFace.SELF); add(BlockFace.SELF);
add(BlockFace.UP); add(BlockFace.UP);
add(BlockFace.DOWN); add(BlockFace.DOWN);
}}; }};
if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) { if (e.getBlock().getType().equals(Material.REDSTONE_WIRE)) {
for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) { for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
Block block = e.getBlock().getRelative(blockFace); Block block = e.getBlock().getRelative(blockFace);
if (block.getBlockPower() != 0) checkedBlockFaces.add(blockFace); if (block.getBlockPower() != 0) checkedBlockFaces.add(blockFace);
} }
} else { } else {
checkedBlockFaces.add(BlockFace.NORTH); checkedBlockFaces.add(BlockFace.NORTH);
checkedBlockFaces.add(BlockFace.SOUTH); checkedBlockFaces.add(BlockFace.SOUTH);
checkedBlockFaces.add(BlockFace.EAST); checkedBlockFaces.add(BlockFace.EAST);
checkedBlockFaces.add(BlockFace.WEST); checkedBlockFaces.add(BlockFace.WEST);
} }
for (BlockFace face : checkedBlockFaces) { for (BlockFace face : checkedBlockFaces) {
ArrayList<BlockFace> subs = new ArrayList<BlockFace>() {{ ArrayList<BlockFace> subs = new ArrayList<BlockFace>() {{
add(BlockFace.SELF); add(BlockFace.SELF);
}}; }};
if (e.getBlock().getType().equals(Material.LEVER)) { if (e.getBlock().getType().equals(Material.LEVER)) {
subs.add(BlockFace.UP); subs.add(BlockFace.UP);
subs.add(BlockFace.DOWN); subs.add(BlockFace.DOWN);
} }
for (BlockFace sub : subs) { for (BlockFace sub : subs) {
Block block = e.getBlock().getRelative(face); Block block = e.getBlock().getRelative(face);
block = block.getRelative(sub); block = block.getRelative(sub);
if (block.getType().equals(Material.PISTON_BASE) || block.getType().equals(Material.PISTON_STICKY_BASE)) { if (block.getType().equals(Material.PISTON_BASE) || block.getType().equals(Material.PISTON_STICKY_BASE)) {
BlockState state = states.get(face).get(sub); BlockState state = states.get(face).get(sub);
PistonBaseMaterial piston; PistonBaseMaterial piston;
try { try {
piston = (PistonBaseMaterial) state.getData(); piston = (PistonBaseMaterial) state.getData();
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
continue; continue;
} }
int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation()); int maxBlocks = findNearbyPlayerMaxBlocks(block.getLocation());
PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), true, maxBlocks); PistonExtendsChecker checker = new PistonExtendsChecker(e.getBlock().getWorld(), block.getLocation(), piston.getFacing(), true, maxBlocks);
boolean isMovable = checker.a(); boolean isMovable = checker.a();
List<Block> blocks = checker.getMovedBlocksObjects(); List<Block> blocks = checker.getMovedBlocksObjects();
List<Block> toBreak = checker.getBrokenBlocksObjects(); List<Block> toBreak = checker.getBrokenBlocksObjects();
upper: upper:
for (Block b : blocks) { for (Block b : blocks) {
if (b.getType().equals(Material.CHEST)) { if (b.getType().equals(Material.CHEST)) {
Block b2 = b.getRelative(piston.getFacing()); Block b2 = b.getRelative(piston.getFacing());
ArrayList<BlockFace> faces = new ArrayList<BlockFace>() {{ ArrayList<BlockFace> faces = new ArrayList<BlockFace>() {{
add(BlockFace.NORTH); add(BlockFace.NORTH);
add(BlockFace.SOUTH); add(BlockFace.SOUTH);
add(BlockFace.WEST); add(BlockFace.WEST);
add(BlockFace.EAST); add(BlockFace.EAST);
}}; }};
faces.remove(piston.getFacing().getOppositeFace()); faces.remove(piston.getFacing().getOppositeFace());
int chests = 0; int chests = 0;
for (BlockFace blockFace : faces) { for (BlockFace blockFace : faces) {
Block b3 = b2.getRelative(blockFace); Block b3 = b2.getRelative(blockFace);
if (b3.getType() == Material.CHEST) { if (b3.getType() == Material.CHEST) {
chests++; chests++;
Chest chest = (Chest) b3.getState(); Chest chest = (Chest) b3.getState();
if (chest.getInventory() instanceof DoubleChestInventory) { if (chest.getInventory() instanceof DoubleChestInventory) {
isMovable = false; isMovable = false;
break upper; break upper;
} }
} }
} }
if (chests > 1) { if (chests > 1) {
isMovable = false; isMovable = false;
break; break;
} else if (chests == 1) { } else if (chests == 1) {
if (b.getType() == Material.CHEST) { if (b.getType() == Material.CHEST) {
Chest chest = (Chest) b.getState(); Chest chest = (Chest) b.getState();
if (chest.getInventory() instanceof DoubleChestInventory) { if (chest.getInventory() instanceof DoubleChestInventory) {
isMovable = false; isMovable = false;
break; break;
} }
} }
} }
} }
} }
if (isMovable) { if (isMovable) {
if (!isBlocksAllowedToInteract(copyWithAdd(blocks, toBreak), piston.getFacing())) if (!isBlocksAllowedToInteract(copyWithAdd(blocks, toBreak), piston.getFacing()))
return; return;
Collections.reverse(blocks); Collections.reverse(blocks);
for (Block block1 : toBreak) { for (Block block1 : toBreak) {
block1.breakNaturally(); block1.breakNaturally();
} }
for (Block b : blocks) { for (Block b : blocks) {
Block b2 = b.getRelative(piston.getFacing()); Block b2 = b.getRelative(piston.getFacing());
b2.setType(b.getType()); b2.setType(b.getType());
b2.setData(b.getData()); //Deprecated but powerful b2.setData(b.getData()); //Deprecated but powerful
if (b.getType().equals(Material.CHEST)) { if (b.getType().equals(Material.CHEST)) {
Chest oldChest = (Chest) b.getState(); Chest oldChest = (Chest) b.getState();
Chest newChest = (Chest) b2.getState(); Chest newChest = (Chest) b2.getState();
newChest.getBlockInventory().setContents(oldChest.getBlockInventory().getContents()); newChest.getBlockInventory().setContents(oldChest.getBlockInventory().getContents());
oldChest.getBlockInventory().clear(); oldChest.getBlockInventory().clear();
} else if (b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE)) { } else if (b.getType().equals(Material.FURNACE) || b.getType().equals(Material.BURNING_FURNACE)) {
Furnace oldFurnace = (Furnace) b.getState(); Furnace oldFurnace = (Furnace) b.getState();
Furnace newFurnace = (Furnace) b2.getState(); Furnace newFurnace = (Furnace) b2.getState();
newFurnace.getInventory().setContents(oldFurnace.getInventory().getContents()); newFurnace.getInventory().setContents(oldFurnace.getInventory().getContents());
oldFurnace.getInventory().clear(); oldFurnace.getInventory().clear();
} }
b.setType(Material.AIR); b.setType(Material.AIR);
} }
} }
} }
} }
} }
} }
}); });
} }
public int findNearbyPlayerMaxBlocks(Location location) { public int findNearbyPlayerMaxBlocks(Location location) {
Optional<? extends Player> op = Bukkit.getOnlinePlayers().stream().filter(p -> p.getLocation().getWorld().equals(location.getWorld())).min(Comparator.comparingDouble(p -> p.getLocation().distance(location))); Optional<? extends Player> op = Bukkit.getOnlinePlayers().stream().filter(p -> p.getLocation().getWorld().equals(location.getWorld())).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());
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)); 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()) { if (intOp.isPresent()) {
return intOp.get() == 0 ? 12 : intOp.get(); return intOp.get() == 0 ? 12 : intOp.get();
} }
} }
return 12; return 12;
} }
public boolean isBlocksAllowedToInteract(List<Block> blocks, BlockFace bf) { public boolean isBlocksAllowedToInteract(List<Block> blocks, BlockFace bf) {
WorldGuardPlugin wg = ExtendedPistons.INSTANCE.wg; WorldGuardPlugin wg = ExtendedPistons.INSTANCE.wg;
RegionContainer container = wg.getRegionContainer(); RegionContainer container = wg.getRegionContainer();
RegionQuery query = container.createQuery(); RegionQuery query = container.createQuery();
for (Block block : blocks) { for (Block block : blocks) {
boolean state = query.testState(block.getLocation(), (Player) null, DefaultFlag.PISTONS); boolean state = query.testState(block.getLocation(), (Player) null, DefaultFlag.PISTONS);
if (!state) if (!state)
return false; return false;
state = query.testState(block.getRelative(bf).getLocation(), (Player) null, DefaultFlag.PISTONS); state = query.testState(block.getRelative(bf).getLocation(), (Player) null, DefaultFlag.PISTONS);
if (!state) if (!state)
return false; return false;
} }
return true; return true;
} }
public <T> List<T> copyWithAdd(List<T> original, List<T> add) { public <T> List<T> copyWithAdd(List<T> original, List<T> add) {
List<T> copy = new ArrayList<>(original); List<T> copy = new ArrayList<>(original);
copy.addAll(add); copy.addAll(add);
return copy; return copy;
} }
} }