This commit is contained in:
Ilya 2022-02-14 21:23:23 +03:00
parent 160a9074c4
commit 14afabd37d
4 changed files with 36 additions and 13 deletions

View File

@ -24,6 +24,7 @@ dependencies {
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 "com.github.MilkBowl:VaultAPI:1.7"
compileOnly 'com.sk89q.worldguard:worldguard-legacy:6.2'
}
def targetJavaVersion = 8

View File

@ -1,10 +1,14 @@
package ru.redguy.extendedpistons;
import com.sk89q.worldguard.bukkit.WGBukkit;
import net.milkbowl.vault.permission.Permission;
import org.apache.commons.lang3.event.EventUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.plugin.Plugin;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -20,6 +24,7 @@ public final class ExtendedPistons extends JavaPlugin {
public SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
public SimpleDateFormat dayOfWeek = new SimpleDateFormat("EEE",Locale.ENGLISH);
public HashMap<String,ArrayList<Period>> weekPeriods;
public WorldGuardPlugin wg;
@Override
public void onEnable() {
@ -62,6 +67,7 @@ public final class ExtendedPistons extends JavaPlugin {
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
permsService = rsp.getProvider();
wg = WGBukkit.getPlugin();
Bukkit.getPluginManager().registerEvents(new WorldListener(), this);
}

View File

@ -1,5 +1,10 @@
package ru.redguy.extendedpistons;
import com.google.common.collect.Sets;
import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -77,9 +82,7 @@ public class WorldListener implements Listener {
List<Block> toBreak = checker.getBrokenBlocksObjects();
if (isMovable) {
BlockPistonRetractEvent ev = new BlockPistonRetractEvent(block, blocks, piston.getFacing());
Bukkit.getPluginManager().callEvent(ev);
if (ev.isCancelled()) continue;
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) continue;
for (Block block1 : toBreak) {
block1.breakNaturally();
}
@ -190,9 +193,7 @@ public class WorldListener implements Listener {
}
if (isMovable) {
BlockPistonExtendedExtendEvent event = new BlockPistonExtendedExtendEvent(block, blocks, piston.getFacing());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) return;
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) return;
Collections.reverse(blocks);
for (Block block1 : toBreak) {
block1.breakNaturally();
@ -263,9 +264,7 @@ public class WorldListener implements Listener {
List<Block> toBreak = checker.getBrokenBlocksObjects();
if (isMovable) {
BlockPistonRetractEvent ev = new BlockPistonRetractEvent(block, blocks, piston.getFacing());
Bukkit.getPluginManager().callEvent(ev);
if (ev.isCancelled()) continue;
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) continue;
for (Block block1 : toBreak) {
block1.breakNaturally();
}
@ -363,9 +362,7 @@ public class WorldListener implements Listener {
}
if (isMovable) {
BlockPistonExtendedExtendEvent event = new BlockPistonExtendedExtendEvent(block, blocks, piston.getFacing());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) return;
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) return;
Collections.reverse(blocks);
for (Block block1 : toBreak) {
block1.breakNaturally();
@ -405,4 +402,22 @@ public class WorldListener implements Listener {
}
return 12;
}
public boolean isBlocksAllowedToInteract(List<Block> blocks) {
WorldGuardPlugin wg = ExtendedPistons.INSTANCE.wg;
RegionContainer container = wg.getRegionContainer();
RegionQuery query = container.createQuery();
for (Block block : blocks) {
boolean state = query.testState(block.getLocation(),(Player)null, DefaultFlag.PISTONS);
if(!state)
return false;
}
return true;
}
public <T> List<T> copyWithAdd(List<T> original, List<T> add) {
List<T> copy = new ArrayList<>(original);
copy.addAll(add);
return copy;
}
}

View File

@ -6,4 +6,5 @@ authors: [ Redguy ]
description: Plugin for very cool pistions
website: https://redguy.ru
depend:
- Vault
- Vault
- WorldGuard