Fix WG
This commit is contained in:
parent
160a9074c4
commit
14afabd37d
@ -24,6 +24,7 @@ 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'
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 8
|
def targetJavaVersion = 8
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package ru.redguy.extendedpistons;
|
package ru.redguy.extendedpistons;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.bukkit.WGBukkit;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.apache.commons.lang3.event.EventUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -20,6 +24,7 @@ public final class ExtendedPistons extends JavaPlugin {
|
|||||||
public SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
public SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||||
public SimpleDateFormat dayOfWeek = new SimpleDateFormat("EEE",Locale.ENGLISH);
|
public SimpleDateFormat dayOfWeek = new SimpleDateFormat("EEE",Locale.ENGLISH);
|
||||||
public HashMap<String,ArrayList<Period>> weekPeriods;
|
public HashMap<String,ArrayList<Period>> weekPeriods;
|
||||||
|
public WorldGuardPlugin wg;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -62,6 +67,7 @@ public final class ExtendedPistons extends JavaPlugin {
|
|||||||
|
|
||||||
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
permsService = rsp.getProvider();
|
permsService = rsp.getProvider();
|
||||||
|
wg = WGBukkit.getPlugin();
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new WorldListener(), this);
|
Bukkit.getPluginManager().registerEvents(new WorldListener(), this);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package ru.redguy.extendedpistons;
|
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.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -77,9 +82,7 @@ public class WorldListener implements Listener {
|
|||||||
List<Block> toBreak = checker.getBrokenBlocksObjects();
|
List<Block> toBreak = checker.getBrokenBlocksObjects();
|
||||||
|
|
||||||
if (isMovable) {
|
if (isMovable) {
|
||||||
BlockPistonRetractEvent ev = new BlockPistonRetractEvent(block, blocks, piston.getFacing());
|
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) continue;
|
||||||
Bukkit.getPluginManager().callEvent(ev);
|
|
||||||
if (ev.isCancelled()) continue;
|
|
||||||
for (Block block1 : toBreak) {
|
for (Block block1 : toBreak) {
|
||||||
block1.breakNaturally();
|
block1.breakNaturally();
|
||||||
}
|
}
|
||||||
@ -190,9 +193,7 @@ public class WorldListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isMovable) {
|
if (isMovable) {
|
||||||
BlockPistonExtendedExtendEvent event = new BlockPistonExtendedExtendEvent(block, blocks, piston.getFacing());
|
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) return;
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if (event.isCancelled()) return;
|
|
||||||
Collections.reverse(blocks);
|
Collections.reverse(blocks);
|
||||||
for (Block block1 : toBreak) {
|
for (Block block1 : toBreak) {
|
||||||
block1.breakNaturally();
|
block1.breakNaturally();
|
||||||
@ -263,9 +264,7 @@ public class WorldListener implements Listener {
|
|||||||
List<Block> toBreak = checker.getBrokenBlocksObjects();
|
List<Block> toBreak = checker.getBrokenBlocksObjects();
|
||||||
|
|
||||||
if (isMovable) {
|
if (isMovable) {
|
||||||
BlockPistonRetractEvent ev = new BlockPistonRetractEvent(block, blocks, piston.getFacing());
|
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) continue;
|
||||||
Bukkit.getPluginManager().callEvent(ev);
|
|
||||||
if (ev.isCancelled()) continue;
|
|
||||||
for (Block block1 : toBreak) {
|
for (Block block1 : toBreak) {
|
||||||
block1.breakNaturally();
|
block1.breakNaturally();
|
||||||
}
|
}
|
||||||
@ -363,9 +362,7 @@ public class WorldListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isMovable) {
|
if (isMovable) {
|
||||||
BlockPistonExtendedExtendEvent event = new BlockPistonExtendedExtendEvent(block, blocks, piston.getFacing());
|
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) return;
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
if (event.isCancelled()) return;
|
|
||||||
Collections.reverse(blocks);
|
Collections.reverse(blocks);
|
||||||
for (Block block1 : toBreak) {
|
for (Block block1 : toBreak) {
|
||||||
block1.breakNaturally();
|
block1.breakNaturally();
|
||||||
@ -405,4 +402,22 @@ public class WorldListener implements Listener {
|
|||||||
}
|
}
|
||||||
return 12;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,5 @@ authors: [ Redguy ]
|
|||||||
description: Plugin for very cool pistions
|
description: Plugin for very cool pistions
|
||||||
website: https://redguy.ru
|
website: https://redguy.ru
|
||||||
depend:
|
depend:
|
||||||
- Vault
|
- Vault
|
||||||
|
- WorldGuard
|
Reference in New Issue
Block a user