use of com.plotsquared.core.plot.flag.types.BlockTypeWrapper in project Bookshelf by LOOHP.
the class PlotSquared6Events method onPlotSquaredCheck.
@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.LOWEST)
public void onPlotSquaredCheck(PlayerOpenBookshelfEvent event) {
if (!Bookshelf.plotSquaredHook) {
return;
}
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(event.getLocation().getWorld().getName())) {
return;
}
org.bukkit.entity.Player bukkitPlayer = event.getPlayer();
PlotPlayer<?> player = PlotPlayer.from(bukkitPlayer);
if (player.hasPermission("plots.admin.interact.other")) {
return;
}
org.bukkit.Location bukkitLocation = event.getLocation();
Location location = Location.at(bukkitLocation.getWorld().getName(), bukkitLocation.getBlockX(), bukkitLocation.getBlockY(), bukkitLocation.getBlockZ());
PlotArea plotarea = PlotSquared.get().getPlotAreaManager().getApplicablePlotArea(location);
if (plotarea == null) {
return;
}
Plot plot = plotarea.getPlot(location);
if (plot == null) {
return;
}
for (PlotFlag<?, ?> flag : plot.getFlags()) {
if (flag instanceof UseFlag) {
for (BlockTypeWrapper blockTypeWarpper : (List<BlockTypeWrapper>) flag.getValue()) {
if (blockTypeWarpper.accepts(ADAPTED_BOOKSHELF_TYPE)) {
return;
}
}
}
}
if (plot.getOwners().contains(player.getUUID())) {
return;
}
if (plot.getTrusted().contains(player.getUUID())) {
return;
}
if (plot.getOwners().stream().anyMatch(each -> Bukkit.getPlayer(each) != null)) {
if (plot.getMembers().contains(player.getUUID())) {
return;
}
}
try {
plotPlayerSendMessageMethod.invoke(player, TranslatableCaption.of("permission.no_permission_event"), Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_OTHER)));
} catch (Exception ignore) {
}
event.setCancelled(true);
}
use of com.plotsquared.core.plot.flag.types.BlockTypeWrapper in project Bookshelf by LOOHP.
the class PlotSquared5Events method onPlotSquaredCheck.
@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.LOWEST)
public void onPlotSquaredCheck(PlayerOpenBookshelfEvent event) {
try {
if (!Bookshelf.plotSquaredHook) {
return;
}
if (!(boolean) hasPlotAreaMethod.invoke(PlotSquared.get(), event.getLocation().getWorld().getName())) {
return;
}
org.bukkit.entity.Player bukkitPlayer = event.getPlayer();
PlotPlayer<?> player = (PlotPlayer<?>) wrap.invoke(null, bukkitPlayer);
if (player.hasPermission("plots.admin.interact.other")) {
return;
}
org.bukkit.Location bukkitLocation = event.getLocation();
Location location = locationConstructor.newInstance(bukkitLocation.getWorld().getName(), bukkitLocation.getBlockX(), bukkitLocation.getBlockY(), bukkitLocation.getBlockZ());
PlotArea plotarea = (PlotArea) getApplicablePlotAreaMethod.invoke(PlotSquared.get(), location);
if (plotarea == null) {
return;
}
Plot plot = plotarea.getPlot(location);
if (plot == null) {
return;
}
for (PlotFlag<?, ?> flag : plot.getFlags()) {
if (flag instanceof UseFlag) {
for (BlockTypeWrapper blockTypeWarpper : (List<BlockTypeWrapper>) flag.getValue()) {
if (blockTypeWarpper.accepts(ADAPTED_BOOKSHELF_TYPE)) {
return;
}
}
}
}
if (plot.getOwners().contains(player.getUUID())) {
return;
}
if (plot.getTrusted().contains(player.getUUID())) {
return;
}
if (plot.getOwners().stream().anyMatch(each -> Bukkit.getPlayer(each) != null)) {
if (plot.getMembers().contains(player.getUUID())) {
return;
}
}
try {
sendMessage.invoke(null, player, FLAG_TUTORIAL_USAGE, FLAG_USE);
} catch (Exception ignore) {
}
event.setCancelled(true);
} catch (Exception e) {
event.setCancelled(true);
}
}
use of com.plotsquared.core.plot.flag.types.BlockTypeWrapper in project PlotSquared by IntellectualSites.
the class EventDispatcher method checkPlayerBlockEvent.
public boolean checkPlayerBlockEvent(PlotPlayer<?> player, @NonNull PlayerBlockEventType type, Location location, BlockType blockType, boolean notifyPerms) {
PlotArea area = location.getPlotArea();
assert area != null;
Plot plot = area.getPlot(location);
if (plot != null) {
if (plot.isAdded(player.getUUID())) {
return true;
}
}
switch(type) {
case TELEPORT_OBJECT:
return false;
case READ:
return true;
case INTERACT_BLOCK:
{
if (plot == null) {
final List<BlockTypeWrapper> use = area.getRoadFlag(UseFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : use) {
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper.accepts(blockType)) {
return true;
}
}
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED.toString(), notifyPerms);
}
final List<BlockTypeWrapper> use = plot.getFlag(UseFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : use) {
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper.accepts(blockType)) {
return true;
}
}
if (Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_OTHER.toString(), false)) {
return true;
}
if (notifyPerms) {
player.sendMessage(TranslatableCaption.of("commandconfig.flag_tutorial_usage"), Template.of("flag", PlaceFlag.getFlagName(UseFlag.class)));
}
return false;
}
case TRIGGER_PHYSICAL:
{
if (plot == null) {
final List<BlockTypeWrapper> use = area.getRoadFlag(UseFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : use) {
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper.accepts(blockType)) {
return true;
}
}
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), false);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED.toString(), false);
}
if (plot.getFlag(DeviceInteractFlag.class)) {
return true;
}
List<BlockTypeWrapper> use = plot.getFlag(UseFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : use) {
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper.accepts(blockType)) {
return true;
}
}
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_OTHER.toString(), false);
}
case SPAWN_MOB:
{
if (plot == null) {
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED.toString(), notifyPerms);
}
if (plot.getFlag(MobPlaceFlag.class)) {
return true;
}
List<BlockTypeWrapper> place = plot.getFlag(PlaceFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : place) {
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper.accepts(blockType)) {
return true;
}
}
if (Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_OTHER.toString(), false)) {
return true;
}
if (notifyPerms) {
player.sendMessage(TranslatableCaption.of("commandconfig.flag_tutorial_usage"), Template.of("flag", PlotFlag.getFlagName(MobPlaceFlag.class) + '/' + PlotFlag.getFlagName(PlaceFlag.class)));
}
return false;
}
case PLACE_MISC:
{
if (plot == null) {
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED.toString(), notifyPerms);
}
if (plot.getFlag(MiscPlaceFlag.class)) {
return true;
}
List<BlockTypeWrapper> place = plot.getFlag(PlaceFlag.class);
for (final BlockTypeWrapper blockTypeWrapper : place) {
if (blockTypeWrapper.accepts(BlockTypes.AIR) || blockTypeWrapper.accepts(blockType)) {
return true;
}
}
if (Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_OTHER.toString(), false)) {
return true;
}
if (notifyPerms) {
player.sendMessage(TranslatableCaption.of("commandconfig.flag_tutorial_usage"), Template.of("flag", PlotFlag.getFlagName(MiscPlaceFlag.class) + '/' + PlotFlag.getFlagName(PlaceFlag.class)));
}
return false;
}
case PLACE_VEHICLE:
if (plot == null) {
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_ROAD.toString(), notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_INTERACT_UNOWNED.toString(), notifyPerms);
}
return plot.getFlag(VehiclePlaceFlag.class);
default:
break;
}
return true;
}
Aggregations