2018-08-12 14:03:07 +00:00
|
|
|
package com.boydti.fawe.bukkit.regions;
|
|
|
|
|
|
|
|
import com.boydti.fawe.bukkit.filter.GriefPreventionFilter;
|
|
|
|
import com.boydti.fawe.object.FawePlayer;
|
2019-06-21 23:58:40 +00:00
|
|
|
import com.boydti.fawe.regions.FaweMask;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.regions.general.RegionFilter;
|
2019-06-21 23:58:40 +00:00
|
|
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
2019-08-06 15:28:12 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2018-08-12 14:03:07 +00:00
|
|
|
import me.ryanhamshire.GriefPrevention.Claim;
|
|
|
|
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
|
|
|
public class GriefPreventionFeature extends BukkitMaskManager implements Listener {
|
|
|
|
|
2019-06-21 23:58:40 +00:00
|
|
|
public GriefPreventionFeature(final Plugin griefpreventionPlugin) {
|
2018-08-12 14:03:07 +00:00
|
|
|
super(griefpreventionPlugin.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAllowed(Player player, Claim claim, MaskType type) {
|
2019-08-06 15:28:12 +00:00
|
|
|
return claim != null && (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim.getOwnerName().equals(player.getUniqueId()) ||
|
|
|
|
type == MaskType.MEMBER && claim.allowBuild(player, Material.AIR) == null);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-21 23:58:40 +00:00
|
|
|
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) {
|
2019-08-06 15:28:12 +00:00
|
|
|
final Player player = BukkitAdapter.adapt(fp.toWorldEditPlayer());
|
|
|
|
final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(BukkitAdapter.adapt(fp.getLocation()), true, null);
|
2018-08-12 14:03:07 +00:00
|
|
|
if (claim != null) {
|
|
|
|
if (isAllowed(player, claim, type)) {
|
|
|
|
claim.getGreaterBoundaryCorner().getBlockX();
|
2019-08-06 15:28:12 +00:00
|
|
|
final BlockVector3 pos1 = BlockVector3.at(claim.getLesserBoundaryCorner().getBlockX(), 0, claim.getLesserBoundaryCorner().getBlockZ());
|
|
|
|
final BlockVector3 pos2 = BlockVector3.at(claim.getGreaterBoundaryCorner().getBlockX(), 256, claim.getGreaterBoundaryCorner().getBlockZ());
|
|
|
|
return new FaweMask(pos1, pos2) {
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
@Override
|
2019-08-06 15:28:12 +00:00
|
|
|
public boolean isValid(FawePlayer fp, MaskType type) {
|
|
|
|
return isAllowed(player, claim, type);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RegionFilter getFilter(String world) {
|
|
|
|
return new GriefPreventionFilter(Bukkit.getWorld(world));
|
|
|
|
}
|
|
|
|
}
|