SteamWar/BauSystem2.0
Archiviert
12
0

Add BlockCounter
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-12-01 18:05:09 +01:00
Ursprung a82fbf9de9
Commit dd77187ad8
6 geänderte Dateien mit 240 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -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

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Region> 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<Block> blocks) {
count += blocks.size();
lastUpdate = TPSUtils.currentTick.get();
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Region, BlockCount> 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;
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Block> 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);
}
}

Datei anzeigen

@ -128,5 +128,4 @@ public class Depth {
maxVector.setY(Math.max(maxVector.getY(), block.getY()));
maxVector.setZ(Math.max(maxVector.getZ(), block.getZ()));
}
}