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,111 @@
/*
* 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.warp;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.core.Core;
import lombok.Getter;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import yapion.hierarchy.types.YAPIONObject;
import java.util.*;
@Getter
public class Warp {
private static Map<String, Warp> warpMap = new HashMap<>();
public static void enable() {
Warp worldSpawn = new Warp("WorldSpawn");
worldSpawn.setLocation(Bukkit.getWorlds().get(0).getSpawnLocation().clone().add(0.5, Core.getVersion() == 20 ? 124 : 1, 0.5));
worldSpawn.setMat(Material.NETHER_STAR);
warpMap.put("WorldSpawn", worldSpawn);
}
private String name;
private Location location;
private Material mat;
private Warp(String name) {
this.name = name;
}
public Warp(String name, Player player) {
this.name = name;
this.location = player.getLocation();
this.mat = Material.COMPASS;
warpMap.put(name, this);
}
public Warp(String name, YAPIONObject object) {
this.name = name;
double x = object.getPlainValue("x");
double y = object.getPlainValue("y");
double z = object.getPlainValue("z");
float yaw = object.getPlainValue("yaw");
float pitch = object.getPlainValue("pitch");
location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch);
mat = Material.getMaterial(object.getPlainValue("material"));
warpMap.put(name, this);
}
public YAPIONObject output() {
YAPIONObject yapionObject = new YAPIONObject();
yapionObject.add("x", location.getX());
yapionObject.add("y", location.getY());
yapionObject.add("z", location.getZ());
yapionObject.add("yaw", location.getYaw());
yapionObject.add("pitch", location.getPitch());
yapionObject.add("material", mat.toString());
return yapionObject;
}
public static Set<String> getWarpNames() {
return warpMap.keySet();
}
public static List<Warp> getWarps() {
return new ArrayList<>(warpMap.values());
}
public static Warp getWarp(String name) {
return warpMap.get(name);
}
public void setMat(Material mat) {
this.mat = mat;
}
public void setLocation(Location location) {
this.location = location;
}
public void delete() {
warpMap.remove(name);
WorldData.getWarpData().remove(name);
}
public void teleport(Player player) {
player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
}
}
@@ -0,0 +1,153 @@
/*
* 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.warp;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.utils.ListChatView;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.api.Disable;
import de.steamwar.linkage.api.Enable;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
import yapion.hierarchy.types.YAPIONObject;
import java.util.ArrayList;
@Linked
public class WarpCommand extends SWCommand implements Disable, Enable {
private static final String[] FORBIDDEN_NAMES = new String[]{
"add", "create", "delete", "list", "info", "gui"
};
public WarpCommand() {
super("warp");
}
@ClassMapper(Warp.class)
public static TypeMapper<Warp> getWarpMapper() {
return SWCommandUtils.createMapper(Warp::getWarp, (commandSender, s) -> new ArrayList<>(Warp.getWarpNames()));
}
@Register(value = "add", description = "WARP_HELP_ADD")
@Register("create")
public void addWarp(@Validator Player player, String name) {
for (String forbiddenName : FORBIDDEN_NAMES) {
if (name.equalsIgnoreCase(forbiddenName)) {
BauSystem.MESSAGE.send("WARP_NAME_RESERVED", player, name);
return;
}
}
if (Warp.getWarp(name) != null) {
BauSystem.MESSAGE.send("WARP_EXISTS", player, name);
return;
}
new Warp(name, player);
BauSystem.MESSAGE.send("WARP_CREATED", player, name);
}
@Register(description = "WARP_HELP_TELEPORT")
public void tpWarp(Player player, Warp warp) {
warp.teleport(player);
}
@Register(value = "delete", description = "WARP_HELP_DELETE")
public void deleteWarp(@Validator Player player, Warp warp) {
warp.delete();
BauSystem.MESSAGE.send("WARP_DELETED", player, warp.getName());
}
@Register(value = "gui", description = "WARP_HELP_GUI")
public void gui(Player player) {
WarpGui.openGui(player);
}
@Register(value = "list", description = "WARP_HELP_LIST")
public void listWarps(Player player) {
listWarps(player, 0);
}
@Register("list")
public void listWarps(Player player, int page) {
ListChatView.chatView(player, Warp.getWarps(), page, warp -> {
TextComponent component = new TextComponent();
component.setText(warp.getName());
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp " + warp.getName()));
component.setColor(ChatColor.YELLOW);
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("WARP_TELEPORT_HOVER", player, warp.getName()))));
return component;
}, (beforePageComponent, beforePage) -> {
beforePageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_PREVIOUS_PAGE", player)).create()));
beforePageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + beforePage));
}, (afterPageComponent, afterPage) -> {
afterPageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_NEXT_PAGE", player)).create()));
afterPageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + afterPage));
});
}
@Register(value = "info", description = "WARP_HELP_INFO")
public void warpInfo(Player player, Warp warp) {
BauSystem.MESSAGE.send("COMMAND_HELP_HEAD", player, warp.getName());
BauSystem.MESSAGE.sendPrefixless("WARP_INFO_NAME", player, warp.getName());
BauSystem.MESSAGE.sendPrefixless("WARP_LOC_X", player, warp.getLocation().getX());
BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Y", player, warp.getLocation().getY());
BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Z", player, warp.getLocation().getZ());
BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.getLocation().distance(player.getLocation()));
}
@Linked
public static class WarpsLink extends SWCommand {
public WarpsLink() {
super("warps");
}
@Register(help = true)
public void genericCommand(Player player, String... args) {
player.performCommand("warp list " + String.join(" ", args));
}
}
@Override
public void enable() {
WorldData.getWarpData().forEach((name, yapionAnyType) -> {
new Warp(name, (YAPIONObject) yapionAnyType);
});
Warp.enable();
}
@Override
public void disable() {
YAPIONObject yapionObject = WorldData.getWarpData();
for (Warp warp : Warp.getWarps()) {
yapionObject.add(warp.getName(), warp.output());
}
}
}
@@ -0,0 +1,103 @@
/*
* 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.warp;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@UtilityClass
public class WarpGui {
public static void openGui(Player player) {
List<SWListInv.SWListEntry<Warp>> entries = new ArrayList<>();
Warp.getWarps().forEach(warp -> entries.add(new SWListInv.SWListEntry<>(new SWItem(
warp.getMat(),
"§e" + warp.getName(),
Arrays.asList(
BauSystem.MESSAGE.parse("WARP_LOC_X", player, (int) warp.getLocation().getX()),
BauSystem.MESSAGE.parse("WARP_LOC_Y", player, (int) warp.getLocation().getY()),
BauSystem.MESSAGE.parse("WARP_LOC_Z", player, (int) warp.getLocation().getZ()),
BauSystem.MESSAGE.parse("WARP_GUI_DISTANCE", player, (int) warp.getLocation().distance(player.getLocation())),
"",
BauSystem.MESSAGE.parse("WARP_GUI_LCLICK", player),
BauSystem.MESSAGE.parse("WARP_GUI_RCLICK", player)
),
false,
clickType -> {
}
), warp)));
SWListInv<Warp> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("WARP_GUI_NAME", player), false, entries, (clickType, warp) -> {
if (clickType.isRightClick() && Permission.BUILD.hasPermission(player)) {
openWarpGui(player, warp);
} else {
warp.teleport(player);
}
});
if (entries.isEmpty()) {
inv.setItem(22, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("WARP_GUI_NO", player), clickType -> {
}));
}
inv.open();
}
public static void openWarpGui(Player player, Warp warp) {
SWInventory inv = new SWInventory(player, 9, warp.getName());
inv.setItem(0, new SWItem(Material.ENDER_PEARL, BauSystem.MESSAGE.parse("WARP_TELEPORT_HOVER", player, warp.getName()), clickType -> {
player.closeInventory();
warp.teleport(player);
}));
inv.setItem(2, new SWItem(warp.getMat(), "§e" + warp.getMat().name(), clickType -> changeMaterial(player, warp)));
inv.setItem(8, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("WARP_DELETE_HOVER", player, warp.getName()), clickType -> {
player.closeInventory();
warp.delete();
}));
inv.open();
}
public static void changeMaterial(Player player, Warp warp) {
List<SWListInv.SWListEntry<Material>> materials = new ArrayList<>();
for (Material value : Material.values()) {
if (value.isLegacy() || value.isAir() || !value.isBlock() || !value.isItem()) continue;
materials.add(new SWListInv.SWListEntry<>(new SWItem(value, "§e" + value.name()), value));
}
SWListInv<Material> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("WARP_MATERIAL_CHOOSE", player), materials, (clickType, material) -> {
player.closeInventory();
warp.setMat(material);
});
inv.open();
}
}
@@ -0,0 +1,150 @@
/*
* 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.warp;
import de.steamwar.bausystem.region.Region;
import de.steamwar.core.Core;
import de.steamwar.entity.RArmorStand;
import de.steamwar.entity.REntityServer;
import de.steamwar.linkage.Linked;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Linked
public class WarpListener implements Listener {
private Map<Player, REntityServer> warpEntityServer = new HashMap<>();
private Map<Player, List<Location>> selected = new HashMap<>();
@EventHandler
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
ItemStack itemStack = e.getPlayer().getInventory().getItem(e.getNewSlot());
Material material = itemStack == null ? Material.AIR : itemStack.getType();
reshow(e.getPlayer(), material, e.getPlayer().isSneaking());
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
for (Player p : Bukkit.getOnlinePlayers()) {
reshow(p, p.getInventory().getItemInMainHand().getType(), p.isSneaking());
}
}
@EventHandler
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
reshow(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand().getType(), event.isSneaking());
}
private void reshow(Player p, Material material, boolean sneaking) {
REntityServer entityServer = warpEntityServer.get(p);
if (entityServer != null) {
entityServer.close();
}
if (material != Material.COMPASS) {
warpEntityServer.remove(p);
return;
}
selected.remove(p);
entityServer = new REntityServer();
entityServer.addPlayer(p);
warpEntityServer.put(p, entityServer);
Vector current = p.getLocation().clone().add(p.getLocation().getDirection().multiply(5)).toVector();
Map<String, Location> locations = new HashMap<>();
if (sneaking) {
Bukkit.getOnlinePlayers().forEach(player -> {
locations.put(player.getName(), player.getLocation());
});
} else {
Warp.getWarps().forEach(warp -> {
locations.put(warp.getName(), warp.getLocation());
});
Region region = Region.getRegion(p.getLocation());
if (region.getCopyPoint() != null) {
locations.put("Copy", region.getCopyPoint().toLocation(p).add(0.5, 0, 0.5));
}
if (region.getTestBlockPoint() != null) {
locations.put("TestBlock", region.getTestBlockPoint().toLocation(p).add(0.5, 0, 0.5));
}
}
REntityServer finalEntityServer = entityServer;
locations.forEach((name, location) -> {
Vector vector = location.toVector().subtract(p.getLocation().toVector());
if (vector.getX() * vector.getX() + vector.getZ() * vector.getZ() < 25) {
return;
}
vector.setY(0);
Vector position = p.getLocation().toVector().clone().add(vector.normalize().multiply(5));
position.setY(p.getLocation().getY() - (Core.getVersion() >= 20 ? 0 : 1));
if ((position.getX() - current.getX()) * (position.getX() - current.getX()) + (position.getZ() - current.getZ()) * (position.getZ() - current.getZ()) < 0.1) {
name = "§a§l" + name;
selected.computeIfAbsent(p, player -> new ArrayList<>()).add(location);
}
RArmorStand armorStand = new RArmorStand(finalEntityServer, position.toLocation(p.getWorld()), RArmorStand.Size.MARKER);
armorStand.setDisplayName(name);
armorStand.setNoGravity(true);
armorStand.setInvisible(true);
});
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.COMPASS) {
return;
}
if (event.getAction() != Action.RIGHT_CLICK_AIR) {
return;
}
List<Location> locations = selected.getOrDefault(event.getPlayer(), new ArrayList<>());
if (locations.size() != 1) {
return;
}
Location location = locations.get(0);
event.getPlayer().teleport(location);
event.getPlayer().playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
event.setCancelled(true);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
warpEntityServer.computeIfPresent(event.getPlayer(), (player, rEntityServer) -> {
rEntityServer.close();
return null;
});
selected.remove(event.getPlayer());
}
}