2020-04-30 18:23:18 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-30 18:23:18 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-30 18:23:18 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-30 18:23:18 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-30 18:23:18 +02:00
|
|
|
*/
|
|
|
|
package com.plotsquared.bukkit.listener;
|
|
|
|
|
2022-09-05 20:06:37 +02:00
|
|
|
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
|
2020-04-30 18:50:52 +02:00
|
|
|
import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
|
2020-04-30 18:50:52 +02:00
|
|
|
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
|
2020-04-30 18:50:52 +02:00
|
|
|
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
2020-05-19 00:28:52 +02:00
|
|
|
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
2020-07-10 22:12:37 +02:00
|
|
|
import com.google.inject.Inject;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
2020-05-19 00:28:52 +02:00
|
|
|
import com.plotsquared.core.command.Command;
|
|
|
|
import com.plotsquared.core.command.MainCommand;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-08-07 18:52:45 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.plotsquared.core.location.Location;
|
2021-12-17 22:06:56 +01:00
|
|
|
import com.plotsquared.core.permissions.Permission;
|
2020-04-30 18:50:52 +02:00
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.plotsquared.core.plot.Plot;
|
|
|
|
import com.plotsquared.core.plot.PlotArea;
|
2022-09-05 20:06:37 +02:00
|
|
|
import com.plotsquared.core.plot.flag.FlagContainer;
|
|
|
|
import com.plotsquared.core.plot.flag.implementations.BeaconEffectsFlag;
|
2020-04-30 18:23:18 +02:00
|
|
|
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
2024-03-02 13:43:16 +01:00
|
|
|
import com.plotsquared.core.plot.flag.implementations.FishingFlag;
|
2022-05-04 23:21:24 +02:00
|
|
|
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
|
2022-09-05 20:06:37 +02:00
|
|
|
import com.plotsquared.core.plot.flag.types.BooleanFlag;
|
2020-07-10 17:32:07 +02:00
|
|
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
2023-03-06 11:38:30 +01:00
|
|
|
import com.plotsquared.core.util.PlotFlagUtil;
|
2022-05-14 17:05:28 +02:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.minimessage.tag.Tag;
|
|
|
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
2020-04-30 18:23:18 +02:00
|
|
|
import org.bukkit.Chunk;
|
2020-05-10 13:18:55 +02:00
|
|
|
import org.bukkit.block.Block;
|
2020-05-12 23:01:14 +02:00
|
|
|
import org.bukkit.block.TileState;
|
2020-04-30 18:23:18 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
2020-04-30 18:50:52 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.Projectile;
|
2020-05-10 13:18:55 +02:00
|
|
|
import org.bukkit.entity.Slime;
|
2020-04-30 18:23:18 +02:00
|
|
|
import org.bukkit.event.EventHandler;
|
2020-05-12 23:01:14 +02:00
|
|
|
import org.bukkit.event.EventPriority;
|
2020-04-30 18:23:18 +02:00
|
|
|
import org.bukkit.event.Listener;
|
2020-05-12 23:01:14 +02:00
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
2020-04-30 18:23:18 +02:00
|
|
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
2020-04-30 18:50:52 +02:00
|
|
|
import org.bukkit.projectiles.ProjectileSource;
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
2020-04-30 18:23:18 +02:00
|
|
|
|
2020-05-19 00:28:52 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2020-04-30 18:23:18 +02:00
|
|
|
/**
|
|
|
|
* Events specific to Paper. Some toit nups here
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public class PaperListener implements Listener {
|
|
|
|
|
2020-07-10 17:32:07 +02:00
|
|
|
private final PlotAreaManager plotAreaManager;
|
2020-04-30 18:23:18 +02:00
|
|
|
private Chunk lastChunk;
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Inject
|
|
|
|
public PaperListener(final @NonNull PlotAreaManager plotAreaManager) {
|
2020-07-10 17:32:07 +02:00
|
|
|
this.plotAreaManager = plotAreaManager;
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onEntityPathfind(EntityPathfindEvent event) {
|
2020-04-30 18:23:18 +02:00
|
|
|
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-17 22:58:10 +02:00
|
|
|
Location toLoc = BukkitUtil.adapt(event.getLoc());
|
|
|
|
Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
|
2020-04-30 18:23:18 +02:00
|
|
|
PlotArea tarea = toLoc.getPlotArea();
|
|
|
|
if (tarea == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PlotArea farea = fromLoc.getPlotArea();
|
|
|
|
if (farea == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tarea != farea) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Plot tplot = toLoc.getPlot();
|
|
|
|
Plot fplot = fromLoc.getPlot();
|
|
|
|
if (tplot == null ^ fplot == null) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2020-05-10 13:18:55 +02:00
|
|
|
if (tplot == null || tplot.getId().hashCode() == fplot.getId().hashCode()) {
|
2020-04-30 18:23:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fplot.isMerged() && fplot.getConnectedPlots().contains(fplot)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@EventHandler
|
|
|
|
public void onEntityPathfind(SlimePathfindEvent event) {
|
2020-04-30 18:23:18 +02:00
|
|
|
if (!Settings.Paper_Components.ENTITY_PATHING) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-10 13:18:55 +02:00
|
|
|
Slime slime = event.getEntity();
|
2020-04-30 18:23:18 +02:00
|
|
|
|
2023-11-25 21:30:48 +01:00
|
|
|
Block b = slime.getTargetBlockExact(4);
|
2020-05-10 13:18:55 +02:00
|
|
|
if (b == null) {
|
2020-04-30 18:23:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-17 22:58:10 +02:00
|
|
|
Location toLoc = BukkitUtil.adapt(b.getLocation());
|
|
|
|
Location fromLoc = BukkitUtil.adapt(event.getEntity().getLocation());
|
2020-04-30 18:23:18 +02:00
|
|
|
PlotArea tarea = toLoc.getPlotArea();
|
|
|
|
if (tarea == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PlotArea farea = fromLoc.getPlotArea();
|
|
|
|
if (farea == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-10 13:18:55 +02:00
|
|
|
|
2020-04-30 18:23:18 +02:00
|
|
|
if (tarea != farea) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Plot tplot = toLoc.getPlot();
|
|
|
|
Plot fplot = fromLoc.getPlot();
|
|
|
|
if (tplot == null ^ fplot == null) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2020-05-10 13:18:55 +02:00
|
|
|
if (tplot == null || tplot.getId().hashCode() == fplot.getId().hashCode()) {
|
2020-04-30 18:23:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fplot.isMerged() && fplot.getConnectedPlots().contains(fplot)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@EventHandler
|
|
|
|
public void onPreCreatureSpawnEvent(PreCreatureSpawnEvent event) {
|
2020-05-01 11:54:19 +02:00
|
|
|
if (!Settings.Paper_Components.CREATURE_SPAWN) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-17 22:58:10 +02:00
|
|
|
Location location = BukkitUtil.adapt(event.getSpawnLocation());
|
2020-04-30 18:23:18 +02:00
|
|
|
PlotArea area = location.getPlotArea();
|
2023-11-25 21:30:48 +01:00
|
|
|
if (area == null) {
|
2020-04-30 18:23:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-11-25 21:30:48 +01:00
|
|
|
// Armour-stands are handled elsewhere and should not be handled by area-wide entity-spawn options
|
|
|
|
if (event.getType() == EntityType.ARMOR_STAND) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If entities are spawning... the chunk should be loaded?
|
2020-04-30 18:23:18 +02:00
|
|
|
Entity[] entities = event.getSpawnLocation().getChunk().getEntities();
|
2023-11-25 21:30:48 +01:00
|
|
|
if (entities.length >= Settings.Chunk_Processor.MAX_ENTITIES) {
|
2020-04-30 18:50:52 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
2020-04-30 18:23:18 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CreatureSpawnEvent.SpawnReason reason = event.getReason();
|
2020-05-02 13:13:00 +02:00
|
|
|
switch (reason.toString()) {
|
2023-03-06 10:25:02 +01:00
|
|
|
case "DISPENSE_EGG", "EGG", "OCELOT_BABY", "SPAWNER_EGG" -> {
|
2020-04-30 18:23:18 +02:00
|
|
|
if (!area.isSpawnEggs()) {
|
2020-04-30 18:50:52 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
2020-04-30 18:23:18 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-06 10:25:02 +01:00
|
|
|
}
|
|
|
|
case "REINFORCEMENTS", "NATURAL", "MOUNT", "PATROL", "RAID", "SHEARED", "SILVERFISH_BLOCK", "ENDER_PEARL", "TRAP", "VILLAGE_DEFENSE", "VILLAGE_INVASION", "BEEHIVE", "CHUNK_GEN" -> {
|
2020-04-30 18:23:18 +02:00
|
|
|
if (!area.isMobSpawning()) {
|
2020-04-30 18:50:52 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
2020-04-30 18:23:18 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-06 10:25:02 +01:00
|
|
|
}
|
|
|
|
case "BREEDING" -> {
|
2020-04-30 18:23:18 +02:00
|
|
|
if (!area.isSpawnBreeding()) {
|
2020-04-30 18:50:52 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
2020-04-30 18:23:18 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-06 10:25:02 +01:00
|
|
|
}
|
|
|
|
case "BUILD_IRONGOLEM", "BUILD_SNOWMAN", "BUILD_WITHER", "CUSTOM" -> {
|
2023-11-25 21:30:48 +01:00
|
|
|
if (!area.isSpawnCustom()) {
|
2020-04-30 18:50:52 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
2020-04-30 18:23:18 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-06 10:25:02 +01:00
|
|
|
}
|
|
|
|
case "SPAWNER" -> {
|
2020-04-30 18:23:18 +02:00
|
|
|
if (!area.isMobSpawnerSpawning()) {
|
2020-04-30 18:50:52 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
2020-04-30 18:23:18 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-06 10:25:02 +01:00
|
|
|
}
|
2020-04-30 18:23:18 +02:00
|
|
|
}
|
|
|
|
Plot plot = location.getOwnedPlotAbs();
|
|
|
|
if (plot == null) {
|
2020-09-29 16:53:23 +02:00
|
|
|
EntityType type = event.getType();
|
2022-08-10 10:22:19 +02:00
|
|
|
// PreCreatureSpawnEvent **should** not be called for DROPPED_ITEM, just for the sake of consistency
|
|
|
|
if (type == EntityType.DROPPED_ITEM) {
|
|
|
|
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-04-30 18:23:18 +02:00
|
|
|
if (!area.isMobSpawning()) {
|
2022-06-19 01:59:43 +02:00
|
|
|
if (type == EntityType.PLAYER) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-29 16:53:23 +02:00
|
|
|
if (type.isAlive()) {
|
2020-09-29 16:55:08 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
2020-09-29 16:53:23 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!area.isMiscSpawnUnowned() && !type.isAlive()) {
|
2020-04-30 18:50:52 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
2020-04-30 18:23:18 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
2020-04-30 18:50:52 +02:00
|
|
|
event.setShouldAbortSpawn(true);
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onPlayerNaturallySpawnCreaturesEvent(PlayerNaturallySpawnCreaturesEvent event) {
|
|
|
|
if (Settings.Paper_Components.CANCEL_CHUNK_SPAWN) {
|
2020-07-17 22:58:10 +02:00
|
|
|
Location location = BukkitUtil.adapt(event.getPlayer().getLocation());
|
2020-04-30 18:50:52 +02:00
|
|
|
PlotArea area = location.getPlotArea();
|
|
|
|
if (area != null && !area.isMobSpawning()) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@EventHandler
|
|
|
|
public void onPreSpawnerSpawnEvent(PreSpawnerSpawnEvent event) {
|
2020-05-01 11:54:19 +02:00
|
|
|
if (Settings.Paper_Components.SPAWNER_SPAWN) {
|
2020-07-17 22:58:10 +02:00
|
|
|
Location location = BukkitUtil.adapt(event.getSpawnerLocation());
|
2020-05-01 11:54:19 +02:00
|
|
|
PlotArea area = location.getPlotArea();
|
|
|
|
if (area != null && !area.isMobSpawnerSpawning()) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
event.setShouldAbortSpawn(true);
|
|
|
|
}
|
2020-04-30 18:50:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@EventHandler(priority = EventPriority.HIGHEST)
|
|
|
|
public void onBlockPlace(BlockPlaceEvent event) {
|
2020-05-13 12:25:48 +02:00
|
|
|
if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
|
2020-05-12 23:01:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(event.getBlock().getState(false) instanceof TileState)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-17 22:58:10 +02:00
|
|
|
final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
|
2020-05-12 23:01:14 +02:00
|
|
|
final PlotArea plotArea = location.getPlotArea();
|
|
|
|
if (plotArea == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
|
|
|
|
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
|
2020-07-17 22:58:10 +02:00
|
|
|
final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
|
2020-08-07 18:52:45 +02:00
|
|
|
plotPlayer.sendMessage(
|
|
|
|
TranslatableCaption.of("errors.tile_entity_cap_reached"),
|
2022-05-14 17:05:28 +02:00
|
|
|
TagResolver.resolver("amount", Tag.inserting(Component.text(Settings.Chunk_Processor.MAX_TILES)))
|
2020-08-07 18:52:45 +02:00
|
|
|
);
|
2020-05-12 23:01:14 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
event.setBuild(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 18:50:52 +02:00
|
|
|
/**
|
|
|
|
* Unsure if this will be any performance improvement over the spigot version,
|
|
|
|
* but here it is anyway :)
|
|
|
|
*
|
|
|
|
* @param event Paper's PlayerLaunchProjectileEvent
|
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
@EventHandler
|
|
|
|
public void onProjectileLaunch(PlayerLaunchProjectileEvent event) {
|
2020-05-01 11:54:19 +02:00
|
|
|
if (!Settings.Paper_Components.PLAYER_PROJECTILE) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-30 18:50:52 +02:00
|
|
|
Projectile entity = event.getProjectile();
|
|
|
|
ProjectileSource shooter = entity.getShooter();
|
|
|
|
if (!(shooter instanceof Player)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-17 22:58:10 +02:00
|
|
|
Location location = BukkitUtil.adapt(entity.getLocation());
|
2022-11-15 19:07:38 +01:00
|
|
|
PlotArea area = location.getPlotArea();
|
|
|
|
if (area == null) {
|
2020-04-30 18:50:52 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-12-17 22:06:56 +01:00
|
|
|
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
|
2020-04-30 18:50:52 +02:00
|
|
|
Plot plot = location.getOwnedPlot();
|
2021-12-17 22:06:56 +01:00
|
|
|
|
|
|
|
if (plot == null) {
|
2023-01-15 14:08:59 +01:00
|
|
|
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !pp.hasPermission(
|
2022-11-15 19:07:38 +01:00
|
|
|
Permission.PERMISSION_ADMIN_PROJECTILE_ROAD
|
|
|
|
)) {
|
2021-12-17 22:06:56 +01:00
|
|
|
pp.sendMessage(
|
|
|
|
TranslatableCaption.of("permission.no_permission_event"),
|
2022-05-14 17:05:28 +02:00
|
|
|
TagResolver.resolver(
|
|
|
|
"node",
|
|
|
|
Tag.inserting(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)
|
|
|
|
)
|
2021-12-17 22:06:56 +01:00
|
|
|
);
|
|
|
|
entity.remove();
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
} else if (!plot.hasOwner()) {
|
2023-01-15 14:08:59 +01:00
|
|
|
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
|
2021-12-17 22:06:56 +01:00
|
|
|
pp.sendMessage(
|
|
|
|
TranslatableCaption.of("permission.no_permission_event"),
|
2022-05-14 17:05:28 +02:00
|
|
|
TagResolver.resolver(
|
|
|
|
"node",
|
|
|
|
Tag.inserting(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)
|
|
|
|
)
|
2021-12-17 22:06:56 +01:00
|
|
|
);
|
|
|
|
entity.remove();
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
} else if (!plot.isAdded(pp.getUUID())) {
|
2024-03-02 13:43:16 +01:00
|
|
|
if (entity.getType().equals(EntityType.FISHING_HOOK)) {
|
|
|
|
if (plot.getFlag(FishingFlag.class)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-05-04 23:21:24 +02:00
|
|
|
if (!plot.getFlag(ProjectilesFlag.class)) {
|
2023-01-15 14:08:59 +01:00
|
|
|
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
|
2022-05-04 23:21:24 +02:00
|
|
|
pp.sendMessage(
|
|
|
|
TranslatableCaption.of("permission.no_permission_event"),
|
2022-05-14 17:05:28 +02:00
|
|
|
TagResolver.resolver(
|
|
|
|
"node",
|
|
|
|
Tag.inserting(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)
|
|
|
|
)
|
2022-05-04 23:21:24 +02:00
|
|
|
);
|
|
|
|
entity.remove();
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2021-12-17 22:06:56 +01:00
|
|
|
}
|
2020-04-30 18:23:18 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 00:28:52 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@EventHandler
|
|
|
|
public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
|
2020-05-23 17:20:09 +02:00
|
|
|
if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-19 00:28:52 +02:00
|
|
|
String buffer = event.getBuffer();
|
|
|
|
if (!(event.getSender() instanceof Player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((!event.isCommand() && !buffer.startsWith("/")) || buffer.indexOf(' ') == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (buffer.startsWith("/")) {
|
|
|
|
buffer = buffer.substring(1);
|
|
|
|
}
|
|
|
|
final String[] unprocessedArgs = buffer.split(Pattern.quote(" "));
|
|
|
|
if (unprocessedArgs.length == 1) {
|
|
|
|
return; // We don't do anything in this case
|
2020-06-23 11:39:45 +02:00
|
|
|
} else if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES
|
2021-01-09 22:28:41 +01:00
|
|
|
.contains(unprocessedArgs[0].toLowerCase(Locale.ENGLISH))) {
|
2020-05-19 00:28:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
final String[] args = new String[unprocessedArgs.length - 1];
|
|
|
|
System.arraycopy(unprocessedArgs, 1, args, 0, args.length);
|
|
|
|
try {
|
2020-07-17 22:58:10 +02:00
|
|
|
final PlotPlayer<?> player = BukkitUtil.adapt((Player) event.getSender());
|
2020-05-19 00:28:52 +02:00
|
|
|
final Collection<Command> objects = MainCommand.getInstance().tab(player, args, buffer.endsWith(" "));
|
|
|
|
if (objects == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final List<String> result = new ArrayList<>();
|
|
|
|
for (final com.plotsquared.core.command.Command o : objects) {
|
|
|
|
result.add(o.toString());
|
|
|
|
}
|
|
|
|
event.setCompletions(result);
|
|
|
|
event.setHandled(true);
|
2021-01-09 22:28:41 +01:00
|
|
|
} catch (final Exception ignored) {
|
|
|
|
}
|
2020-05-19 00:28:52 +02:00
|
|
|
}
|
|
|
|
|
2022-09-05 20:06:37 +02:00
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
public void onBeaconEffect(final BeaconEffectEvent event) {
|
|
|
|
Block block = event.getBlock();
|
|
|
|
Location beaconLocation = BukkitUtil.adapt(block.getLocation());
|
|
|
|
Plot beaconPlot = beaconLocation.getPlot();
|
|
|
|
|
|
|
|
PlotArea area = beaconLocation.getPlotArea();
|
|
|
|
if (area == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
Location playerLocation = BukkitUtil.adapt(player.getLocation());
|
|
|
|
|
|
|
|
PlotPlayer<Player> plotPlayer = BukkitUtil.adapt(player);
|
|
|
|
Plot playerStandingPlot = playerLocation.getPlot();
|
|
|
|
if (playerStandingPlot == null) {
|
|
|
|
FlagContainer container = area.getRoadFlagContainer();
|
|
|
|
if (!getBooleanFlagValue(container, BeaconEffectsFlag.class, true) ||
|
|
|
|
(beaconPlot != null && Settings.Enabled_Components.DISABLE_BEACON_EFFECT_OVERFLOW)) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FlagContainer container = playerStandingPlot.getFlagContainer();
|
|
|
|
boolean plotBeaconEffects = getBooleanFlagValue(container, BeaconEffectsFlag.class, true);
|
|
|
|
if (playerStandingPlot.equals(beaconPlot)) {
|
|
|
|
if (!plotBeaconEffects) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!plotBeaconEffects || Settings.Enabled_Components.DISABLE_BEACON_EFFECT_OVERFLOW) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 11:38:30 +01:00
|
|
|
private boolean getBooleanFlagValue(
|
|
|
|
@NonNull FlagContainer container,
|
|
|
|
@NonNull Class<? extends BooleanFlag<?>> flagClass,
|
|
|
|
boolean defaultValue
|
|
|
|
) {
|
2022-09-05 20:06:37 +02:00
|
|
|
BooleanFlag<?> flag = container.getFlag(flagClass);
|
|
|
|
return flag == null ? defaultValue : flag.getValue();
|
|
|
|
}
|
|
|
|
|
2020-04-30 18:23:18 +02:00
|
|
|
}
|