mirror of
https://github.com/TotalFreedomMC/TF-WorldGuardExtraFlagsPlugin.git
synced 2024-05-21 20:11:22 +00:00
Disable block specifig flags on WG 7, fixes #152
This commit is contained in:
parent
146505dd96
commit
4572780827
|
@ -8,6 +8,7 @@ import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import net.goldtreeservers.worldguardextraflags.listeners.*;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
@ -23,13 +24,6 @@ import lombok.Getter;
|
||||||
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsHelper;
|
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsHelper;
|
||||||
import net.goldtreeservers.worldguardextraflags.fawe.FAWEHelper;
|
import net.goldtreeservers.worldguardextraflags.fawe.FAWEHelper;
|
||||||
import net.goldtreeservers.worldguardextraflags.flags.Flags;
|
import net.goldtreeservers.worldguardextraflags.flags.Flags;
|
||||||
import net.goldtreeservers.worldguardextraflags.listeners.BlockListener;
|
|
||||||
import net.goldtreeservers.worldguardextraflags.listeners.EntityListener;
|
|
||||||
import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePointNine;
|
|
||||||
import net.goldtreeservers.worldguardextraflags.listeners.EntityPotionEffectEventListener;
|
|
||||||
import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener;
|
|
||||||
import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener;
|
|
||||||
import net.goldtreeservers.worldguardextraflags.listeners.WorldListener;
|
|
||||||
import net.goldtreeservers.worldguardextraflags.protocollib.ProtocolLibHelper;
|
import net.goldtreeservers.worldguardextraflags.protocollib.ProtocolLibHelper;
|
||||||
import net.goldtreeservers.worldguardextraflags.utils.SupportedFeatures;
|
import net.goldtreeservers.worldguardextraflags.utils.SupportedFeatures;
|
||||||
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
|
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
|
||||||
|
@ -143,6 +137,11 @@ public class WorldGuardExtraFlagsPlugin extends AbstractWorldGuardExtraFlagsPlug
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new BlockListener(this), this);
|
this.getServer().getPluginManager().registerEvents(new BlockListener(this), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new WorldListener(this), this);
|
this.getServer().getPluginManager().registerEvents(new WorldListener(this), this);
|
||||||
|
|
||||||
|
if (this.worldGuardCommunicator.isLegacy())
|
||||||
|
{
|
||||||
|
this.getServer().getPluginManager().registerEvents(new BlockListenerWG(this), this);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,86 +59,4 @@ public class BlockListener implements Listener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Figure out something better for this
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
|
|
||||||
public void onBlockPlaceEvent(PlaceBlockEvent event)
|
|
||||||
{
|
|
||||||
Result originalResult = event.getResult();
|
|
||||||
Object cause = event.getCause().getRootCause();
|
|
||||||
|
|
||||||
if (cause instanceof Player)
|
|
||||||
{
|
|
||||||
Player player = (Player)cause;
|
|
||||||
|
|
||||||
for(Block block : event.getBlocks())
|
|
||||||
{
|
|
||||||
Material type = block.getType();
|
|
||||||
if (type == Material.AIR) //Workaround for https://github.com/aromaa/WorldGuardExtraFlagsPlugin/issues/12
|
|
||||||
{
|
|
||||||
type = event.getEffectiveMaterial();
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
|
|
||||||
|
|
||||||
Set<Material> state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.ALLOW_BLOCK_PLACE);
|
|
||||||
if (state != null && state.contains(type))
|
|
||||||
{
|
|
||||||
event.setResult(Result.ALLOW);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Set<Material> state2 = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.DENY_BLOCK_PLACE);
|
|
||||||
if (state2 != null && state2.contains(type))
|
|
||||||
{
|
|
||||||
event.setResult(Result.DENY);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
event.setResult(originalResult);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Figure out something better for this
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
|
|
||||||
public void onBlockBreakEvent(BreakBlockEvent event)
|
|
||||||
{
|
|
||||||
Result originalResult = event.getResult();
|
|
||||||
Object cause = event.getCause().getRootCause();
|
|
||||||
|
|
||||||
if (cause instanceof Player)
|
|
||||||
{
|
|
||||||
Player player = (Player)cause;
|
|
||||||
|
|
||||||
for(Block block : event.getBlocks())
|
|
||||||
{
|
|
||||||
ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
|
|
||||||
|
|
||||||
Set<Material> state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.ALLOW_BLOCK_BREAK);
|
|
||||||
if (state != null && state.contains(block.getType()))
|
|
||||||
{
|
|
||||||
event.setResult(Result.ALLOW);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Set<Material> state2 = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.DENY_BLOCK_BREAK);
|
|
||||||
if (state2 != null && state2.contains(block.getType()))
|
|
||||||
{
|
|
||||||
event.setResult(Result.DENY);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
event.setResult(originalResult);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,14 +54,18 @@ public interface WorldGuardCommunicator
|
||||||
flagRegistry.register(Flags.MYTHICMOB_EGGS);
|
flagRegistry.register(Flags.MYTHICMOB_EGGS);
|
||||||
flagRegistry.register(Flags.FROSTWALKER);
|
flagRegistry.register(Flags.FROSTWALKER);
|
||||||
flagRegistry.register(Flags.NETHER_PORTALS);
|
flagRegistry.register(Flags.NETHER_PORTALS);
|
||||||
flagRegistry.register(Flags.ALLOW_BLOCK_PLACE);
|
|
||||||
flagRegistry.register(Flags.DENY_BLOCK_PLACE);
|
|
||||||
flagRegistry.register(Flags.ALLOW_BLOCK_BREAK);
|
|
||||||
flagRegistry.register(Flags.DENY_BLOCK_BREAK);
|
|
||||||
flagRegistry.register(Flags.GLIDE);
|
flagRegistry.register(Flags.GLIDE);
|
||||||
flagRegistry.register(Flags.CHUNK_UNLOAD);
|
flagRegistry.register(Flags.CHUNK_UNLOAD);
|
||||||
flagRegistry.register(Flags.ITEM_DURABILITY);
|
flagRegistry.register(Flags.ITEM_DURABILITY);
|
||||||
flagRegistry.register(Flags.JOIN_LOCATION);
|
flagRegistry.register(Flags.JOIN_LOCATION);
|
||||||
|
|
||||||
|
if (this.isLegacy())
|
||||||
|
{
|
||||||
|
flagRegistry.register(Flags.ALLOW_BLOCK_PLACE);
|
||||||
|
flagRegistry.register(Flags.DENY_BLOCK_PLACE);
|
||||||
|
flagRegistry.register(Flags.ALLOW_BLOCK_BREAK);
|
||||||
|
flagRegistry.register(Flags.DENY_BLOCK_BREAK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default public void onEnable(Plugin plugin) throws Exception
|
default public void onEnable(Plugin plugin) throws Exception
|
||||||
|
@ -82,6 +86,8 @@ public interface WorldGuardCommunicator
|
||||||
sessionManager.registerHandler(PlaySoundsFlagHandler.FACTORY(plugin));
|
sessionManager.registerHandler(PlaySoundsFlagHandler.FACTORY(plugin));
|
||||||
sessionManager.registerHandler(GlideFlagHandler.FACTORY(plugin));
|
sessionManager.registerHandler(GlideFlagHandler.FACTORY(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLegacy();
|
||||||
|
|
||||||
public FlagRegistry getFlagRegistry();
|
public FlagRegistry getFlagRegistry();
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,12 @@ public class WorldGuardSixCommunicator implements WorldGuardCommunicator
|
||||||
WorldGuardCommunicator.super.onEnable(plugin);
|
WorldGuardCommunicator.super.onEnable(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLegacy()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FlagRegistry getFlagRegistry()
|
public FlagRegistry getFlagRegistry()
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,12 @@ public class WorldGuardSevenCommunicator implements WorldGuardCommunicator
|
||||||
WorldGuardCommunicator.super.onEnable(plugin);
|
WorldGuardCommunicator.super.onEnable(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLegacy()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FlagRegistry getFlagRegistry()
|
public FlagRegistry getFlagRegistry()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue