SteamWar/BauSystem2.0
Archiviert
12
0
Dieser Commit ist enthalten in:
Zeanon 2021-05-01 16:24:31 +02:00
Ursprung c425350139
Commit 688ba52968
7 geänderte Dateien mit 313 neuen und 101 gelöschten Zeilen

Datei anzeigen

@ -1,101 +0,0 @@
/*
* 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;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.DoubleBinaryOperator;
@Linked(LinkageType.LISTENER)
public class DepthCounter implements Listener {
private final Set<Region> current = new HashSet<>();
private final Map<Region, Vector> minVectors = new HashMap<>();
private final Map<Region, Vector> maxVectors = new HashMap<>();
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
Region region = Region.getRegion(event.getLocation());
boolean testblock = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.NORMAL));
if (!testblock) {
return;
}
Vector minVector = blockVector(event.getEntity().getLocation().toVector());
Vector maxVector = blockVector(event.getEntity().getLocation().toVector());
event.blockList().forEach(block -> {
if (block.getType() == Material.AIR) {
return;
}
minVector.setX(Math.min(minVector.getX(), block.getX()));
minVector.setY(Math.min(minVector.getY(), block.getY()));
minVector.setZ(Math.min(minVector.getZ(), block.getZ()));
maxVector.setX(Math.max(maxVector.getX(), block.getX()));
maxVector.setY(Math.max(maxVector.getY(), block.getY()));
maxVector.setZ(Math.max(maxVector.getZ(), block.getZ()));
});
compute(minVectors.computeIfAbsent(region, region1 -> minVector), minVector, Math::min);
compute(maxVectors.computeIfAbsent(region, region1 -> maxVector), maxVector, Math::max);
if (!current.contains(region)) {
current.add(region);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
Vector minVectorRemoved = minVectors.remove(region);
Vector maxVectorRemoved = maxVectors.remove(region);
Vector dimensions = maxVectorRemoved.subtract(minVectorRemoved);
dimensions.setX(Math.abs(dimensions.getX()));
dimensions.setY(Math.abs(dimensions.getY()));
dimensions.setZ(Math.abs(dimensions.getZ()));
RegionUtils.message(region, BauSystem.PREFIX + "X: " + dimensions.getBlockX() + " Y: " + dimensions.getBlockY() + " Z: " + dimensions.getBlockZ());
current.remove(region);
}, 10);
}
}
private Vector blockVector(Vector vector) {
return new Vector(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}
private void compute(Vector v1, Vector v2, DoubleBinaryOperator function) {
v1.setX(function.applyAsDouble(v1.getX(), v2.getX()));
v1.setY(function.applyAsDouble(v1.getY(), v2.getY()));
v1.setZ(function.applyAsDouble(v1.getZ(), v2.getZ()));
}
}

Datei anzeigen

@ -0,0 +1,34 @@
/*
* 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.depthcounter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public enum CountMode {
X,
Y,
Z;
public static final Set<CountMode> ALL = new HashSet<>(Arrays.asList(values()));
}

Datei anzeigen

@ -0,0 +1,109 @@
/*
* 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.depthcounter;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.util.Vector;
import java.util.function.DoubleBinaryOperator;
@UtilityClass
public class DepthCounter {
public final Set<Region> current = new HashSet<>();
public final Map<Region, Vector> minVectors = new HashMap<>();
public final Map<Region, Vector> maxVectors = new HashMap<>();
public final Map<Player, Set<CountMode>> playerSettings = new HashMap<>();
public void toggleMode(final Player p, final CountMode countMode) {
if (isActive(p, countMode)) {
removeMode(p, countMode);
} else {
addMode(p, countMode);
}
}
public boolean isActive(final Player p, final CountMode countMode) {
final Set<CountMode> countModes = playerSettings.get(p);
return countModes != null && countModes.contains(countMode);
}
public void addMode(final Player p, final CountMode countMode) {
final Set<CountMode> countModes = playerSettings.get(p);
if (countModes != null) {
countModes.add(countMode);
} else {
playerSettings.put(p, new HashSet<>(Collections.singletonList(countMode)));
}
}
public void removeMode(final Player p, final CountMode countMode) {
final Set<CountMode> countModes = playerSettings.get(p);
if (countModes != null) {
countModes.remove(countMode);
if (countModes.isEmpty()) {
removePlayer(p);
}
}
}
public void setModes(final Player p, final Set<CountMode> countModes) {
playerSettings.put(p, countModes);
}
public void removePlayer(final Player p) {
playerSettings.remove(p);
}
public Vector blockVector(Vector vector) {
return new Vector(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
}
public Set<CountMode> getModes(Player p) {
final Set<CountMode> countModes = playerSettings.get(p);
return countModes == null ? Collections.emptySet() : countModes;
}
public boolean hasModes(Player p) {
return !getModes(p).isEmpty();
}
public void compute(Vector v1, Vector v2, DoubleBinaryOperator function) {
v1.setX(function.applyAsDouble(v1.getX(), v2.getX()));
v1.setY(function.applyAsDouble(v1.getY(), v2.getY()));
v1.setZ(function.applyAsDouble(v1.getZ(), v2.getZ()));
}
}

Datei anzeigen

@ -0,0 +1,65 @@
/*
* 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.depthcounter;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ColorConfig;
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 DepthCounterCommand extends SWCommand {
public DepthCounterCommand() {
super("depthcounter", "depthcount", "dcounter", "dcount");
}
@Register
public void genericHelp(Player p, String... args) {
//TODO
}
@Register("toggle")
public void toggleCommand(Player p, CountMode countMode) {
DepthCounter.toggleMode(p, countMode);
p.sendMessage(BauSystem.PREFIX + "Aktive Zählmodi: " + ColorConfig.HIGHLIGHT + DepthCounter.getModes(p) + ColorConfig.BASE + ".");
}
@Register("enable")
public void enableCommand(Player p) {
DepthCounter.setModes(p, CountMode.ALL);
p.sendMessage(BauSystem.PREFIX + "Du hast den Tiefenzähler aktiviert.");
p.sendMessage(BauSystem.PREFIX + "Aktive Zählmodi: " + ColorConfig.HIGHLIGHT + DepthCounter.getModes(p) + ColorConfig.BASE + ".");
}
@Register("disable")
public void disableCommand(Player p) {
DepthCounter.removePlayer(p);
p.sendMessage(BauSystem.PREFIX + "Du hast den Tiefenzähler deaktiviert.");
}
@Register("info")
public void infoCommand(Player p) {
p.sendMessage(BauSystem.PREFIX + "Aktive Zählmodi: " + ColorConfig.HIGHLIGHT + DepthCounter.getModes(p) + ColorConfig.BASE + ".");
}
}

Datei anzeigen

@ -0,0 +1,91 @@
/*
* 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.depthcounter;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.config.ColorConfig;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.util.Vector;
@Linked(LinkageType.LISTENER)
public class DepthCounterListener implements Listener {
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
Region region = Region.getRegion(event.getLocation());
boolean testblock = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.NORMAL));
if (!testblock) {
return;
}
Vector minVector = DepthCounter.blockVector(event.getEntity().getLocation().toVector());
Vector maxVector = DepthCounter.blockVector(event.getEntity().getLocation().toVector());
event.blockList().forEach(block -> {
if (block.getType() == Material.AIR) {
return;
}
minVector.setX(Math.min(minVector.getX(), block.getX()));
minVector.setY(Math.min(minVector.getY(), block.getY()));
minVector.setZ(Math.min(minVector.getZ(), block.getZ()));
maxVector.setX(Math.max(maxVector.getX(), block.getX()));
maxVector.setY(Math.max(maxVector.getY(), block.getY()));
maxVector.setZ(Math.max(maxVector.getZ(), block.getZ()));
});
DepthCounter.compute(DepthCounter.minVectors.computeIfAbsent(region, region1 -> minVector), minVector, Math::min);
DepthCounter.compute(DepthCounter.maxVectors.computeIfAbsent(region, region1 -> maxVector), maxVector, Math::max);
if (!DepthCounter.current.contains(region)) {
DepthCounter.current.add(region);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
Vector minVectorRemoved = DepthCounter.minVectors.remove(region);
Vector maxVectorRemoved = DepthCounter.maxVectors.remove(region);
Vector dimensions = maxVectorRemoved.subtract(minVectorRemoved);
dimensions.setX(Math.abs(dimensions.getX()));
dimensions.setY(Math.abs(dimensions.getY()));
dimensions.setZ(Math.abs(dimensions.getZ()));
RegionUtils.message(region, player -> !DepthCounter.hasModes(player) ? null : (BauSystem.PREFIX
+ (DepthCounter.isActive(player, CountMode.X) ? "X: " + dimensions.getBlockX() + " " : "")
+ (DepthCounter.isActive(player, CountMode.Y) ? "Y: " + dimensions.getBlockY() + " " : "")
+ (DepthCounter.isActive(player, CountMode.Z) ? "Z: " + dimensions.getBlockZ() + " " : "")));
DepthCounter.current.remove(region);
}, 10);
}
}
@EventHandler
public void onLeave(PlayerQuitEvent event) {
DepthCounter.removePlayer(event.getPlayer());
}
}

Datei anzeigen

@ -6,12 +6,15 @@ import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.core.VersionedCallable;
import java.util.function.Function;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import java.io.File;
import org.bukkit.entity.Player;
@UtilityClass
public class RegionUtils {
@ -24,6 +27,17 @@ public class RegionUtils {
Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)).forEach(player -> player.sendMessage(s));
}
public static void message(Region region, Function<Player, String> function) {
Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)).forEach(player -> {
String message = function.apply(player);
if (message == null) {
return;
}
player.sendMessage(message);
});
}
static EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.paste(file, pastePoint, pasteOptions), 15));
}