Add BauSystem module

Fix ci java version
Fix LinkageProcessor
This commit is contained in:
2024-08-05 13:28:50 +02:00
parent 41d31e6c9c
commit 3366a30b0c
526 changed files with 43550 additions and 149479 deletions
@@ -0,0 +1,195 @@
/*
* 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.team;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.team.boundary.BoundaryViewer;
import de.steamwar.bausystem.region.Prototype;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.linkage.Linked;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import yapion.hierarchy.output.StringOutput;
import yapion.hierarchy.types.YAPIONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Linked
public class SkinCommand extends SWCommand {
public SkinCommand() {
super("skin");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
if (!user.hasPerm(UserPerm.ADMINISTRATION)) {
return;
}
BauSystem.MESSAGE.send("SKIN_HELP", p);
}
@Register
public void createCommand(Player p, @OptionalValue("") @Mapper("force") String force, @Mapper("kuerzel") String typeKuerzel, @Mapper("creator") String creator, String... names) {
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
if (!user.hasPerm(UserPerm.ADMINISTRATION)) {
return;
}
Region region = Region.getRegion(p.getLocation());
if (region.isGlobal()) {
BauSystem.MESSAGE.send("SKIN_NO_REGION", p);
return;
}
String name = String.join(" ", names);
File arenaFile = new File("sections19/" + name + "/" + typeKuerzel + "Arena.schem");
File testblockFile = region.hasType(RegionType.TESTBLOCK) ? new File("sections19/" + name + "/" + typeKuerzel + "Testblock.schem") : null;
arenaFile.getParentFile().mkdirs();
if (testblockFile != null) {
testblockFile.getParentFile().mkdirs();
}
if (arenaFile.exists() && force.equals("")) {
BauSystem.MESSAGE.send("SKIN_ALREADY_EXISTS", p);
return;
}
if (testblockFile != null && testblockFile.exists() && force.equals("")) {
BauSystem.MESSAGE.send("SKIN_ALREADY_EXISTS", p);
return;
}
Region.copy(region.getMinPoint(), region.getMaxPoint(), arenaFile);
if (testblockFile != null) {
Region.copy(region.getMinPointTestblock(), region.getMaxPointTestblock(), testblockFile);
}
YAPIONObject yapionObject = new YAPIONObject();
yapionObject.add("name", name);
if (!creator.equals("public")) {
yapionObject.add("creator", creator);
}
yapionObject.add("type", typeKuerzel);
yapionObject.add("schematic", arenaFile.getPath());
if (testblockFile != null) {
yapionObject.add("testblockSchematic", testblockFile.getPath());
}
BauSystem.MESSAGE.send("SKIN_MESSAGE", p, BauSystem.MESSAGE.parse("SKIN_MESSAGE_HOVER", p), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yapionObject.toYAPION(new StringOutput(true)).getResult()));
}
@Register("boundary")
public void showRegionBoundaries(Player p) {
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
if (!user.hasPerm(UserPerm.ADMINISTRATION)) {
return;
}
if (BoundaryViewer.viewers.contains(p)) {
BoundaryViewer.viewers.remove(p);
} else {
BoundaryViewer.viewers.add(p);
}
}
@Mapper(value = "kuerzel", local = true)
public static TypeMapper<String> kurzelMapper() {
return new TypeMapper<String>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
List<String> current = new ArrayList<>();
Prototype.getPrototypes().forEach(p -> {
current.add(p.getName().toUpperCase().replace("_", ""));
});
return current;
}
@Override
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
return s;
}
};
}
@Mapper(value = "force", local = true)
public static TypeMapper<String> forceMapper() {
return new TypeMapper<String>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
List<String> current = new ArrayList<>();
current.add("-f");
return current;
}
@Override
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
if (s.equals("-f")) {
return s;
}
if (s.equals("")) {
return "";
}
return null;
}
};
}
@Mapper(value = "creator", local = true)
public static TypeMapper<String> creatorMapper() {
return new TypeMapper<String>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
List<String> current = new ArrayList<>();
current.add("public");
Bukkit.getOnlinePlayers().forEach(player -> {
current.add(player.getName());
});
return current;
}
@Override
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
Set<String> current = new HashSet<>();
current.add("public");
Bukkit.getOnlinePlayers().forEach(player -> {
current.add(player.getName());
});
if (current.contains(s)) {
return s;
}
return null;
}
};
}
}
@@ -0,0 +1,99 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.team.boundary;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashSet;
import java.util.Set;
@Linked
public class BoundaryViewer implements Listener {
public static Set<Player> viewers = new HashSet<>();
{
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
if (viewers.isEmpty()) {
return;
}
viewers.forEach(player -> {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) return;
showRegion(region, player);
if (region.getLinkedRegion() != null) {
showRegion(region.getLinkedRegion(), player);
}
});
}, 20, 20);
}
private void showRegion(Region region, Player player) {
drawCuboid(player, Particle.VILLAGER_HAPPY, region.getMinPoint(), region.getMaxPoint());
if (region.hasType(RegionType.TESTBLOCK)) {
drawCuboid(player, Particle.END_ROD, region.getMinPointTestblockExtension(), region.getMaxPointTestblockExtension());
}
if (region.hasType(RegionType.BUILD)) {
drawCuboid(player, Particle.END_ROD, region.getMinPointBuildExtension(), region.getMaxPointBuildExtension());
}
}
private void drawCuboid(Player player, Particle particle, Point min, Point max) {
for (int z = min.getZ(); z <= max.getZ() + 1; z++) {
player.spawnParticle(particle, min.getX(), min.getY(), z, 1, 0, 0, 0, 0);
player.spawnParticle(particle, min.getX(), max.getY() + 1, z, 1, 0, 0, 0, 0);
player.spawnParticle(particle, max.getX() + 1, min.getY(), z, 1, 0, 0, 0, 0);
player.spawnParticle(particle, max.getX() + 1, max.getY() + 1, z, 1, 0, 0, 0, 0);
}
for (int x = min.getX(); x <= max.getX() + 1; x++) {
player.spawnParticle(particle, x, min.getY(), min.getZ(), 1, 0, 0, 0, 0);
player.spawnParticle(particle, x, min.getY(), max.getZ() + 1, 1, 0, 0, 0, 0);
player.spawnParticle(particle, x, max.getY() + 1, min.getZ(), 1, 0, 0, 0, 0);
player.spawnParticle(particle, x, max.getY() + 1, max.getZ() + 1, 1, 0, 0, 0, 0);
}
for (int y = min.getY(); y <= max.getY() + 1; y++) {
player.spawnParticle(particle, min.getX(), y, min.getZ(), 1, 0, 0, 0, 0);
player.spawnParticle(particle, min.getX(), y, max.getZ() + 1, 1, 0, 0, 0, 0);
player.spawnParticle(particle, max.getX() + 1, y, min.getZ(), 1, 0, 0, 0, 0);
player.spawnParticle(particle, max.getX() + 1, y, max.getZ() + 1, 1, 0, 0, 0, 0);
}
}
private void drawPoints(Player player, Particle particle, Point... points) {
for (Point point : points) {
player.spawnParticle(particle, point.toLocation(player), 1, 0, 0, 0, 0);
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
viewers.remove(event.getPlayer());
}
}