001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.bukkit.listener;
020
021import com.google.inject.Inject;
022import com.plotsquared.bukkit.util.BukkitUtil;
023import com.plotsquared.core.configuration.Settings;
024import com.plotsquared.core.configuration.caption.TranslatableCaption;
025import com.plotsquared.core.location.Location;
026import com.plotsquared.core.player.PlotPlayer;
027import com.plotsquared.core.plot.PlotArea;
028import com.plotsquared.core.plot.world.PlotAreaManager;
029import net.kyori.adventure.text.minimessage.Template;
030import org.bukkit.block.Banner;
031import org.bukkit.block.Beacon;
032import org.bukkit.block.BlockState;
033import org.bukkit.block.CommandBlock;
034import org.bukkit.block.Comparator;
035import org.bukkit.block.Conduit;
036import org.bukkit.block.Container;
037import org.bukkit.block.CreatureSpawner;
038import org.bukkit.block.DaylightDetector;
039import org.bukkit.block.EnchantingTable;
040import org.bukkit.block.EndGateway;
041import org.bukkit.block.EnderChest;
042import org.bukkit.block.Jukebox;
043import org.bukkit.block.Sign;
044import org.bukkit.block.Skull;
045import org.bukkit.block.Structure;
046import org.bukkit.block.data.type.Bed;
047import org.bukkit.event.EventHandler;
048import org.bukkit.event.block.BlockPlaceEvent;
049import org.checkerframework.checker.nullness.qual.NonNull;
050
051/**
052 * @deprecated P2 effectively no longer supports 1.13
053 */
054@Deprecated(forRemoval = true, since = "6.10.4")
055public class PaperListener113 extends PaperListener {
056
057    @Inject
058    public PaperListener113(@NonNull PlotAreaManager plotAreaManager) {
059        super(plotAreaManager);
060    }
061
062    @EventHandler
063    public void onBlockPlace(BlockPlaceEvent event) {
064        if (!Settings.Paper_Components.TILE_ENTITY_CHECK || !Settings.Enabled_Components.CHUNK_PROCESSOR) {
065            return;
066        }
067        BlockState state = event.getBlock().getState(false);
068        if (!(state instanceof Banner || state instanceof Beacon || state instanceof Bed || state instanceof CommandBlock
069                || state instanceof Comparator || state instanceof Conduit || state instanceof Container || state instanceof CreatureSpawner
070                || state instanceof DaylightDetector || state instanceof EnchantingTable || state instanceof EnderChest || state instanceof EndGateway
071                || state instanceof Jukebox || state instanceof Sign || state instanceof Skull || state instanceof Structure)) {
072            return;
073        }
074        final Location location = BukkitUtil.adapt(event.getBlock().getLocation());
075        final PlotArea plotArea = location.getPlotArea();
076        if (plotArea == null) {
077            return;
078        }
079        final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
080        if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
081            final PlotPlayer<?> plotPlayer = BukkitUtil.adapt(event.getPlayer());
082            plotPlayer.sendMessage(
083                    TranslatableCaption.of("errors.tile_entity_cap_reached"),
084                    Template.of("amount", String.valueOf(Settings.Chunk_Processor.MAX_TILES))
085            );
086            event.setCancelled(true);
087            event.setBuild(false);
088        }
089    }
090
091}