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);
}
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);
}
}
Aggregations