Really fixed block-break flags

This commit is contained in:
isokissa3 2017-01-26 01:12:03 +02:00
parent 190ece604b
commit ee37c705c2
3 changed files with 26 additions and 29 deletions

View file

@ -22,7 +22,7 @@ public class MaterialFlag extends Flag<Material>
@Override @Override
public Material parseInput(FlagContext context) throws InvalidFlagFormat public Material parseInput(FlagContext context) throws InvalidFlagFormat
{ {
return Material.getMaterial(context.getUserInput().trim()); return Material.getMaterial(context.getUserInput().trim().toUpperCase());
} }
@Override @Override

View file

@ -49,41 +49,39 @@ public class BlockListener implements Listener
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onBlockPlaceEvent(PlaceBlockEvent event) public void onBlockPlaceEvent(PlaceBlockEvent event)
{ {
if (event.getResult() == Result.DEFAULT) Result originalResult = event.getResult();
Object cause = event.getCause().getRootCause();
if (cause instanceof Player)
{ {
Object cause = event.getCause().getRootCause(); Player player = (Player)cause;
if (cause instanceof Player) if (!WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass(player, player.getWorld()))
{ {
Player player = (Player)cause; for(Block block : event.getBlocks())
if (!WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass(player, player.getWorld()))
{ {
for(Block block : event.getBlocks()) ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
Set<Material> state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockPlace); Set<Material> state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockPlace);
if (state != null && state.contains(block.getType())) if (state != null && state.contains(block.getType()))
{
event.setResult(Result.ALLOW);
}
else
{
Set<Material> state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockPlace);
if (state2 != null && state2.contains(block.getType()))
{ {
event.setResult(Result.ALLOW); event.setResult(Result.DENY);
return;
} }
else else
{ {
Set<Material> state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockPlace); event.setResult(originalResult);
if (state2 != null && state2.contains(block.getType())) return;
{
event.setResult(Result.DENY);
return;
}
else
{
event.setResult(Result.DEFAULT);
return;
}
} }
} }
} }
} }
} }
} }

View file

@ -30,7 +30,6 @@ import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
import com.sk89q.worldedit.Location; import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.bukkit.BukkitUtil;