Search in sources :

Example 1 with UseFlag

use of com.plotsquared.core.plot.flag.implementations.UseFlag 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 UseFlag

use of com.plotsquared.core.plot.flag.implementations.UseFlag 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)

Aggregations

Location (com.plotsquared.core.location.Location)2 Plot (com.plotsquared.core.plot.Plot)2 PlotArea (com.plotsquared.core.plot.PlotArea)2 UseFlag (com.plotsquared.core.plot.flag.implementations.UseFlag)2 BlockTypeWrapper (com.plotsquared.core.plot.flag.types.BlockTypeWrapper)2 List (java.util.List)2 EventHandler (org.bukkit.event.EventHandler)2 PlotPlayer (com.plotsquared.core.player.PlotPlayer)1