diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 5e5149b8..ed25a20d 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -510,6 +510,14 @@ SMART_PLACE_INFO = §7Plaziert rotierbare Blöcke beim §esneaken§7 von dir §e SMART_PLACE_ENABLE = §aSmartPlace aktiviert SMART_PLACE_DISABLE = §cSmartPlace deaktiviert +# BlockCounter +BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus +BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an +BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Schalte den BlockCounter aus +BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke Schaden am Testblock +BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht +BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht + # Trace TRACE_RECORD=§aan TRACE_RECORD-AUTO=§aan diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java new file mode 100644 index 00000000..503ea661 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java @@ -0,0 +1,74 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.testblock.blockcounter; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; +import lombok.ToString; +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.scheduler.BukkitTask; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@ToString +public class BlockCount { + + private static BukkitTask bukkitTask = null; + + private Region region; + private int count = 0; + + private long lastUpdate = TPSUtils.currentTick.get(); + + public BlockCount(Region region) { + this.region = region; + + if (bukkitTask == null) { + bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + Set toRemove = new HashSet<>(); + for (BlockCount blockCount : BlockCounter.blockCountMap.values()) { + if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 20) { + continue; + } + toRemove.add(region); + + if (count > 10) { + RegionUtils.message(blockCount.region, player -> BlockCounter.getMessage(player, blockCount.count)); + } + } + toRemove.forEach(BlockCounter.blockCountMap::remove); + if (BlockCounter.blockCountMap.isEmpty()) { + bukkitTask.cancel(); + bukkitTask = null; + } + }, 2, 2); + } + } + + public void update(List blocks) { + count += blocks.size(); + lastUpdate = TPSUtils.currentTick.get(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java new file mode 100644 index 00000000..b0a7cb0f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java @@ -0,0 +1,55 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.testblock.blockcounter; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.configplayer.Config; +import de.steamwar.bausystem.region.Region; +import lombok.experimental.UtilityClass; +import org.bukkit.entity.Player; +import yapion.hierarchy.types.YAPIONValue; + +import java.util.HashMap; +import java.util.Map; + +@UtilityClass +public class BlockCounter { + + public final Map blockCountMap = new HashMap<>(); + + public boolean isActive(final Player p) { + return (boolean) Config.getInstance().get(p).getYAPIONValueOrSetDefault("blockCounter", new YAPIONValue<>(false)).get(); + } + + public void enable(final Player p) { + Config.getInstance().get(p).put("blockCounter", true); + } + + public void disable(final Player p) { + Config.getInstance().get(p).put("blockCounter", false); + } + + public String getMessage(Player player, int count) { + if (isActive(player)) { + return BauSystem.MESSAGE.parse("BLOCK_COUNTER_MESSAGE", player, count); + } + return null; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterCommand.java new file mode 100644 index 00000000..6d997edd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterCommand.java @@ -0,0 +1,55 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.testblock.blockcounter; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; + +@Linked(LinkageType.COMMAND) +public class BlockCounterCommand extends SWCommand { + + public BlockCounterCommand() { + super("blockcounter", "blockcount", "bcounter", "bcount"); + } + + @Register(description = "BLOCK_COUNTER_HELP_TOGGLE") + public void defaultCommand(Player p) { + if (BlockCounter.isActive(p)) { + disableCommand(p); + } else { + enableCommand(p); + } + } + + @Register(value = "enable", description = "BLOCK_COUNTER_HELP_ENABLE") + public void enableCommand(Player p) { + BlockCounter.enable(p); + BauSystem.MESSAGE.send("BLOCK_COUNTER_ENABLE", p); + } + + @Register(value = "disable", description = "BLOCK_COUNTER_HELP_DISABLE") + public void disableCommand(Player p) { + BlockCounter.disable(p); + BauSystem.MESSAGE.send("BLOCK_COUNTER_DISABLE", p); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java new file mode 100644 index 00000000..d4ab3412 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java @@ -0,0 +1,48 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.testblock.blockcounter; + +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +import java.util.List; +import java.util.stream.Collectors; + +@Linked(LinkageType.LISTENER) +public class BlockCounterListener implements Listener { + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + Region region = Region.getRegion(event.getLocation()); + List blockList = event.blockList(); + blockList = blockList.stream().filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)).collect(Collectors.toList()); + if (blockList.isEmpty()) { + return; + } + BlockCounter.blockCountMap.computeIfAbsent(region, BlockCount::new).update(blockList); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java index 1c6e1514..52999a45 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java @@ -128,5 +128,4 @@ public class Depth { maxVector.setY(Math.max(maxVector.getY(), block.getY())); maxVector.setZ(Math.max(maxVector.getZ(), block.getZ())); } - }