From 1dc78b8eb866ffabdb5bba2c55f4e677b3258b73 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 31 May 2026 00:44:56 +0200 Subject: [PATCH] Add RedstoneEngineCommand --- .../RedstoneEngineCommand.java | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/experimental/redstone_engine/RedstoneEngineCommand.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/experimental/redstone_engine/RedstoneEngineCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/experimental/redstone_engine/RedstoneEngineCommand.java new file mode 100644 index 00000000..40c8ff08 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/experimental/redstone_engine/RedstoneEngineCommand.java @@ -0,0 +1,130 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2026 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 . + */ + +package de.steamwar.bausystem.features.experimental.redstone_engine; + +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import io.papermc.paper.configuration.WorldConfiguration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.title.TitlePart; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.Collection; +import java.util.List; + +@Linked +public class RedstoneEngineCommand extends SWCommand implements Listener, ScoreboardElement { + + public RedstoneEngineCommand() { + super("redstoneengine"); + } + + private WorldConfiguration.Misc getConfig() { + return ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle().paperConfig().misc; + } + + @Register + public void setRedstoneEngine(Player player, @StaticValue("alternate_current") String __, WorldConfiguration.Misc.AlternateCurrentUpdateOrder updateOrder) { + WorldConfiguration.Misc misc = getConfig(); + misc.redstoneImplementation = WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT; + misc.alternateCurrentUpdateOrder = updateOrder; + broadcastTitle(Bukkit.getOnlinePlayers()); + } + + @Register + public void setRedstoneEngine(Player player, WorldConfiguration.Misc.RedstoneImplementation implementation) { + getConfig().redstoneImplementation = implementation; + broadcastTitle(Bukkit.getOnlinePlayers()); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + WorldConfiguration.Misc misc = getConfig(); + if (misc.redstoneImplementation != WorldConfiguration.Misc.RedstoneImplementation.EIGENCRAFT) { + broadcastTitle(List.of(event.getPlayer())); + } + } + + private void broadcastTitle(Collection players) { + WorldConfiguration.Misc misc = getConfig(); + Component title = switch (misc.redstoneImplementation) { + case VANILLA -> Component.text("⚠").color(NamedTextColor.RED).append(Component.text(" Redstone: Vanilla ").color(NamedTextColor.WHITE)).append(Component.text("⚠").color(NamedTextColor.RED)); + case EIGENCRAFT -> Component.text("Redstone: Eigencraft"); + case ALTERNATE_CURRENT -> Component.text("⚠").color(NamedTextColor.RED).append(Component.text(" Redstone: AC ").color(NamedTextColor.WHITE)).append(Component.text("⚠").color(NamedTextColor.RED)); + }; + Component subtitle; + if (misc.redstoneImplementation != WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) { + subtitle = Component.text().build(); + } else { + subtitle = switch (misc.alternateCurrentUpdateOrder) { + case VERTICAL_FIRST_INWARD -> Component.text("Y first inwards"); // Y before XZ + case VERTICAL_FIRST_OUTWARD -> Component.text("Y first outwards"); // XZ before Y + case HORIZONTAL_FIRST_INWARD -> Component.text("XZ first inwards"); // Y before XZ + case HORIZONTAL_FIRST_OUTWARD -> Component.text("XZ first outwards"); // XZ before Y + }; + } + players.forEach(player -> { + player.sendTitlePart(TitlePart.TITLE, title); + player.sendTitlePart(TitlePart.SUBTITLE, subtitle); + }); + } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.FOOTER; + } + + @Override + public int order() { + return Integer.MAX_VALUE; + } + + @Override + public String get(Region region, Player p) { + WorldConfiguration.Misc misc = getConfig(); + switch (misc.redstoneImplementation) { + case ALTERNATE_CURRENT: + switch (misc.alternateCurrentUpdateOrder) { + case VERTICAL_FIRST_INWARD: + return "§eRedstone§8: §cAC §8(§7Y in§8)"; + case VERTICAL_FIRST_OUTWARD: + return "§eRedstone§8: §cAC §8(§7Y out§8)"; + case HORIZONTAL_FIRST_INWARD: + return "§eRedstone§8: §cAC §8(§7XZ in§8)"; + case HORIZONTAL_FIRST_OUTWARD: + return "§eRedstone§8: §cAC §8(§7XZ out§8)"; + } + return "§eRedstone§8: §cAC"; + case EIGENCRAFT: + return null; + case VANILLA: + default: + return "§eRedstone§8: §cVanilla"; + } + } +}