Search in sources :

Example 1 with BlockTypeWrapper

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);
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) UseFlag(com.plotsquared.core.plot.flag.implementations.UseFlag) BlockTypeWrapper(com.plotsquared.core.plot.flag.types.BlockTypeWrapper) List(java.util.List) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BlockTypeWrapper

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);
    }
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) PlotPlayer(com.plotsquared.core.player.PlotPlayer) UseFlag(com.plotsquared.core.plot.flag.implementations.UseFlag) BlockTypeWrapper(com.plotsquared.core.plot.flag.types.BlockTypeWrapper) List(java.util.List) Location(com.plotsquared.core.location.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with BlockTypeWrapper

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;
}
Also used : BlockTypeWrapper(com.plotsquared.core.plot.flag.types.BlockTypeWrapper) MiscPlaceFlag(com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag) SinglePlotArea(com.plotsquared.core.plot.world.SinglePlotArea) PlotArea(com.plotsquared.core.plot.PlotArea) Plot(com.plotsquared.core.plot.Plot) MobPlaceFlag(com.plotsquared.core.plot.flag.implementations.MobPlaceFlag) DeviceInteractFlag(com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag) List(java.util.List) ArrayList(java.util.ArrayList) UseFlag(com.plotsquared.core.plot.flag.implementations.UseFlag) VehiclePlaceFlag(com.plotsquared.core.plot.flag.implementations.VehiclePlaceFlag) PlaceFlag(com.plotsquared.core.plot.flag.implementations.PlaceFlag) MobPlaceFlag(com.plotsquared.core.plot.flag.implementations.MobPlaceFlag) MiscPlaceFlag(com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag)

Aggregations

Plot (com.plotsquared.core.plot.Plot)3 PlotArea (com.plotsquared.core.plot.PlotArea)3 UseFlag (com.plotsquared.core.plot.flag.implementations.UseFlag)3 BlockTypeWrapper (com.plotsquared.core.plot.flag.types.BlockTypeWrapper)3 List (java.util.List)3 Location (com.plotsquared.core.location.Location)2 EventHandler (org.bukkit.event.EventHandler)2 PlotPlayer (com.plotsquared.core.player.PlotPlayer)1 DeviceInteractFlag (com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag)1 MiscPlaceFlag (com.plotsquared.core.plot.flag.implementations.MiscPlaceFlag)1 MobPlaceFlag (com.plotsquared.core.plot.flag.implementations.MobPlaceFlag)1 PlaceFlag (com.plotsquared.core.plot.flag.implementations.PlaceFlag)1 VehiclePlaceFlag (com.plotsquared.core.plot.flag.implementations.VehiclePlaceFlag)1 SinglePlotArea (com.plotsquared.core.plot.world.SinglePlotArea)1 ArrayList (java.util.ArrayList)1