forked from SteamWar/SteamWar
Add BauSystem module
Fix ci java version Fix LinkageProcessor
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 int tntCount = 0;
|
||||
private final long tick = TPSUtils.currentRealTick.get();
|
||||
|
||||
private long lastUpdate = TPSUtils.currentRealTick.get();
|
||||
|
||||
public BlockCount(Region region) {
|
||||
this.region = region;
|
||||
|
||||
if (bukkitTask == null) {
|
||||
bukkitTask = BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
Set<Region> toRemove = new HashSet<>();
|
||||
for (BlockCount blockCount : BlockCounter.blockCountMap.values()) {
|
||||
if (TPSUtils.currentRealTick.get() - blockCount.lastUpdate < 60) {
|
||||
continue;
|
||||
}
|
||||
toRemove.add(blockCount.region);
|
||||
|
||||
if (count > 10) {
|
||||
RegionUtils.message(blockCount.region, player -> {
|
||||
return BlockCounter.getMessage(player, blockCount.count, blockCount.tntCount, blockCount.tick, blockCount.lastUpdate);
|
||||
});
|
||||
}
|
||||
}
|
||||
toRemove.forEach(BlockCounter.blockCountMap::remove);
|
||||
if (BlockCounter.blockCountMap.isEmpty()) {
|
||||
bukkitTask.cancel();
|
||||
bukkitTask = null;
|
||||
}
|
||||
}, 2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(List<Block> blocks) {
|
||||
count += blocks.size();
|
||||
tntCount++;
|
||||
lastUpdate = TPSUtils.currentRealTick.get();
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.Permission;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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) {
|
||||
if (!Config.getInstance().get(p).containsKey("blockCounter")) {
|
||||
return false;
|
||||
}
|
||||
return Config.getInstance().get(p).getPlainValue("blockCounter");
|
||||
}
|
||||
|
||||
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, int tntCount, long tick, long lastTick) {
|
||||
if(!Permission.BUILD.hasPermission(player)) return null;
|
||||
|
||||
double countPerTNT = (double) count / tntCount;
|
||||
double countPerTick = (double) count / Math.max((lastTick - tick), 1);
|
||||
if (isActive(player)) {
|
||||
if (countPerTick < 100) {
|
||||
return BauSystem.MESSAGE.parse("BLOCK_COUNTER_MESSAGE_SECOND", player, count, tntCount, (int) (countPerTNT * 10) / 10.0, (int) (countPerTick * 100) / 100.0 * 20);
|
||||
} else {
|
||||
return BauSystem.MESSAGE.parse("BLOCK_COUNTER_MESSAGE", player, count, tntCount, (int) (countPerTNT * 10) / 10.0, (int) (countPerTick * 100) / 100.0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Linked
|
||||
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);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.region.Region;
|
||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
||||
import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.linkage.Linked;
|
||||
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
|
||||
public class BlockCounterListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
Region region = Region.getRegion(event.getLocation());
|
||||
if (region.isGlobal()) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user